Skip to content

Library

The Library class is the internal base class for libraries in Epip. It offers general-purpose utility methods, such as logging, debug flags, event systems, as well as integrations with some core Epip libraries to simplify the registration of resources.

Epip.InitializeLibrary() is meant to be used to define libraries, though you are not intended to do so in your own mod - use Features instead.

Library contains integrations with the following core Epip libraries:

  • Text (for TSK registration and organizing TSKs by library/feature within the localization sheet)
  • UserVars (for namespacing)
  • OOP (for containing related subclasses)

Perceptive readers will realize that these integrations indeed create circular dependencies. This concern is however pretty low on the list.

The class includes some methods to filter out unwanted logging, however the recommended way to filter it is to use the "control panel" UI (Feature_DebugMenu, defaults to Left Ctrl+B) to set the logging level instead of calling the methods yourself anywhere.

Library Class

Inherits from Class.

Methods

AddProfilingStep
function Library:AddProfilingStep(stepID)

Adds a step to the current profiling session.

Does nothing outside of Debug mode.

@param stepID string

AddSubscribableEvent
function Library:AddSubscribableEvent(evName, preventable)
   -> Event

Registers a new event.

@param evName string

@param preventable boolean? Defaults to false.

AddSubscribableHook
function Library:AddSubscribableHook(evName, preventable)
   -> Event

Registers a new hook.

@param evName string

@param preventable boolean? Defaults to false.

Create
function Library.Create(modTable, id, data)
   -> Library

Initializes a table as a Library.

@param modTable string

@param id string

@param data Library

Debug
function Library:Debug()

Show debug-level logging from this library.

Only works in Developer mode.

DebugLog
function Library:DebugLog()

Log a value in Debug mode.

Dump
function Library:Dump(msg)

Dump a value to the console, in Debug mode.

@param msg any

EndProfiling
function Library:EndProfiling()

Ends the current profiling session.

Does nothing outside of Debug mode.

GetClass
function Library:GetClass(className)
   -> `T`

Returns a class's base table.

@param className `T`

GetModVariable
function Library:GetModVariable(modGUID, name)
   -> any

Returns the value of a mod variable.

@param modGUID GUID

@param name string

GetPackagePrefix
function Library:GetPackagePrefix()
   -> string

Returns the package prefix for this library's subclasses.

GetTranslatedStringHandleForKey
function Library:GetTranslatedStringHandleForKey(localKey)
   -> TranslatedStringHandle?

@param localKey string

GetUserVariable
function Library:GetUserVariable(component, variable)
   -> any

Gets the value of a user variable on an entity component.

@param component UserVarsLib_CompatibleComponent

@param variable string|UserVarsLib_UserVar

IsDebug
function Library:IsDebug()
   -> boolean

Returns whether :Debug() has been ran successfully.

LogMethod
function Library:LogMethod(method, ...)

Log a message in the format "[MODULE] method(): msg"

@param method any

@param ... any

Mute
function Library:Mute()

Stop all non-error, non-warning logging from this feature.

RegisterClass
function Library:RegisterClass(className, class, parentClasses)
   -> `T`

Registers a class.

@param className `T`

@param class table Class table.

@param parentClasses string[]? Classes this one inherits from.

RegisterModVariable
function Library:RegisterModVariable(modGUID, name, data)

Registers a mod variable.

@param modGUID GUID

@param name string

@param data UserVarsLib_ModVar

RegisterTranslatedString
function Library:RegisterTranslatedString(handle, tsk)
   -> Library_TranslatedString

Registers a TSK.

@param handle TranslatedStringHandle

@param tsk Library_TranslatedString ModTable, FeatureID and Handle fields are auto-initialized.

RegisterTranslatedString
function Library:RegisterTranslatedString(tsk)
   -> Library_TranslatedString

Table-only overload.

@param tsk Library_TranslatedString ModTable, FeatureID and Handle fields are auto-initialized.

RegisterUserVariable
function Library:RegisterUserVariable(name, data)

Registers a user variable.

@param name string

@param data UserVarsLib_UserVar?

SetModVariable
function Library:SetModVariable(modGUID, name, value)

Sets the value of a mod variable.

@param modGUID GUID

@param name string

@param value any

SetUserVariable
function Library:SetUserVariable(component, variable, value)

Sets the value of a user variable.

@param component UserVarsLib_CompatibleComponent

@param variable string|UserVarsLib_UserVar

@param value any

ShutUp
function Library:ShutUp()

Stop all non-error logging.

StartProfiling
function Library:StartProfiling(id)

Starts a profiling session.

Does nothing outside of Debug mode.

@param id string Session ID.

__Setup
---@protected
function Library:__Setup()

Invoked on SessionLoaded if the feature is not disabled.

Override to run initialization routines.

@virtual

__Test
---@protected
function Library:__Test()

Invoked on a small delay after SessionLoaded if Epip.IsDeveloperMode(true) is true and the feature is being debugged.

@virtual