Module: game/layers
Interfaces
BaseLayer
• BaseLayer: Object
The properties that are added onto a processed LayerOptions to create a Layer
Name | Type | Description |
---|---|---|
emit | <K>(...args : [K , ...Parameters<LayerEvents[K]>[]]) => void | A function to emit a LayerEvents event to this layer. |
emitter | Emitter <LayerEvents > | An emitter for sending LayerEvents events for this layer. |
id | string | The ID of the layer. Populated from the createLayer parameters. Used for saving and tracking open tabs. |
minimized | Persistent <boolean > | A persistent ref tracking if the tab is minimized or not. |
nodes | Ref <Record <string , undefined | FeatureNode >> | A map of FeatureNodes present in this layer's ContextComponent component. |
on | (...args : [event: keyof LayerEvents, cb: Function | Function | Function]) => Unsubscribe | A function to register an event listener on emitter. |
Defined in
profectus/src/game/layers.tsx:148
FeatureNode
• FeatureNode: Object
A feature's node in the DOM that has its size tracked.
Name | Type |
---|---|
element | HTMLElement |
observer | MutationObserver |
rect | DOMRect |
Defined in
profectus/src/game/layers.tsx:28
LayerEvents
• LayerEvents: Object
All types of events able to be sent or emitted from a layer's emitter.
Name | Type |
---|---|
postUpdate | (diff : number ) => void |
preUpdate | (diff : number ) => void |
update | (diff : number ) => void |
Defined in
profectus/src/game/layers.tsx:55
LayerOptions
• LayerOptions: Object
An object that configures a Layer. Even moreso than features, the developer is expected to include extra properties in this object. All Persistent refs must be included somewhere within the layer object.
Name | Type | Description |
---|---|---|
classes? | Computable <Record <string , boolean >> | An object of classes that should be applied to the display. |
color? | Computable <string > | The color of the layer, used to theme the entire layer's display. |
display | Computable <CoercableComponent > | The layout of this layer's features. When the layer is open in game/player.PlayerData.tabs, this is the content that is displayed. |
forceHideGoBack? | Computable <boolean > | Whether or not to force the go back button to be hidden. If true, go back will be hidden regardless of data/projInfo.allowGoBack. |
minWidth? | Computable <string | number > | A CSS min-width value that is applied to the layer. Can be a number, in which case the unit is assumed to be px. Defaults to 600px. |
minimizable? | Computable <boolean > | Whether or not the layer can be minimized. Defaults to true. |
minimizedDisplay? | Computable <CoercableComponent > | The layout of this layer's features. When the layer is open in game/player.PlayerData.tabs, but the tab is Layer.minimized this is the content that is displayed. |
name? | Computable <string > | The name of the layer, used on minimized tabs. Defaults to id. |
style? | Computable <StyleValue > | Styles that should be applied to the display. |
Defined in
profectus/src/game/layers.tsx:107
Position
• Position: Object
An object representing the position of some entity.
Name | Type | Description |
---|---|---|
x | number | The X component of the entity's position. |
y | number | The Y component of the entity's position. |
Defined in
profectus/src/game/layers.tsx:95
Type Aliases
GenericLayer
Ƭ GenericLayer: Replace
<Layer
<LayerOptions
>, { minWidth
: ProcessedComputable
<number
> ; minimizable
: ProcessedComputable
<boolean
> ; name
: ProcessedComputable
<string
> }>
A type that matches any valid Layer object.
Defined in
profectus/src/game/layers.tsx:184
Layer
Ƭ Layer<T
>: Replace
<T
& BaseLayer
, { classes
: GetComputableType
<T
["classes"
]> ; color
: GetComputableType
<T
["color"
]> ; display
: GetComputableType
<T
["display"
]> ; forceHideGoBack
: GetComputableType
<T
["forceHideGoBack"
]> ; minWidth
: GetComputableTypeWithDefault
<T
["minWidth"
], 600
> ; minimizable
: GetComputableTypeWithDefault
<T
["minimizable"
], true
> ; minimizedDisplay
: GetComputableType
<T
["minimizedDisplay"
]> ; name
: GetComputableTypeWithDefault
<T
["name"
], string
> ; style
: GetComputableType
<T
["style"
]> }>
An unit of game content. Displayed to the user as a tab or modal.
Type parameters
Name | Type |
---|---|
T | extends LayerOptions |
Defined in
profectus/src/game/layers.tsx:168
Variables
BoundsInjectionKey
• Const
BoundsInjectionKey: InjectionKey
<Ref
<DOMRect
| undefined
>>
An injection key that a ContextComponent will use to provide a ref to a bounding rect of the Context.
Defined in
profectus/src/game/layers.tsx:52
NodesInjectionKey
• Const
NodesInjectionKey: InjectionKey
<Ref
<Record
<string
, FeatureNode
| undefined
>>>
An injection key that a ContextComponent will use to provide a ref to a map of all currently registered FeatureNodes.
Defined in
profectus/src/game/layers.tsx:47
RegisterNodeInjectionKey
• Const
RegisterNodeInjectionKey: InjectionKey
<(id
: string
, element
: HTMLElement
) => void
>
An injection key that a ContextComponent will use to provide a function that registers a FeatureNode with the given id and HTML element.
Defined in
profectus/src/game/layers.tsx:37
UnregisterNodeInjectionKey
• Const
UnregisterNodeInjectionKey: InjectionKey
<(id
: string
) => void
>
An injection key that a ContextComponent will use to provide a function that unregisters a FeatureNode with the given id.
Defined in
profectus/src/game/layers.tsx:42
addingLayers
• Const
addingLayers: string
[] = []
When creating layers, this array stores the layers currently being created, as a stack.
Defined in
profectus/src/game/layers.tsx:200
layers
• Const
layers: Record
<string
, Readonly
<GenericLayer
> | undefined
>
A reference to all the current layers. It is shallow reactive so it will update when layers are added or removed, but not interfere with the existing refs within each layer.
Defined in
profectus/src/game/layers.tsx:77
persistentRefs
• Const
persistentRefs: Record
<string
, Set
<Persistent
>> = {}
When creating layers, this object a map of layer ID to a set of any created persistent refs in order to check they're all included in the final layer object.
Defined in
profectus/src/game/layers.tsx:196
Functions
addLayer
▸ addLayer(layer
, player
): void
Enables a layer object, so it will be updated every tick. Note that accessing a layer/its properties does NOT require it to be enabled. For dynamic layers you can call this function and removeLayer as necessary. Just make sure getInitialLayers will provide an accurate list of layers based on the player data object. For static layers just make getInitialLayers return all the layers.
Parameters
Name | Type | Description |
---|---|---|
layer | GenericLayer | The layer to add. |
player | Object | The player data object, which will have a data object for this layer. |
player.layers? | Record <string , Record <string , unknown >> | - |
Returns
void
Defined in
profectus/src/game/layers.tsx:286
createLayer
▸ createLayer<T
>(id
, optionsFunc
): Layer
<T
>
Lazily creates a layer with the given options.
Type parameters
Name | Type |
---|---|
T | extends LayerOptions |
Parameters
Name | Type | Description |
---|---|---|
id | string | The ID this layer will have. See id. |
optionsFunc | OptionsFunc <T , BaseLayer > | Layer options. |
Returns
Layer
<T
>
Defined in
profectus/src/game/layers.tsx:206
getLayer
▸ getLayer<T
>(layerID
): T
Convenience method for getting a layer by its ID with correct typing.
Type parameters
Name | Type |
---|---|
T | extends GenericLayer |
Parameters
Name | Type | Description |
---|---|---|
layerID | string | The ID of the layer to get. |
Returns
T
Defined in
profectus/src/game/layers.tsx:313
reloadLayer
▸ reloadLayer(layer
): void
Convenience method for removing and immediately re-adding a layer. This is useful for layers with dynamic content, to ensure persistent refs are correctly configured.
Parameters
Name | Type | Description |
---|---|---|
layer | GenericLayer | Layer to remove and then re-add |
Returns
void
Defined in
profectus/src/game/layers.tsx:334
removeLayer
▸ removeLayer(layer
): void
Disables a layer, so it will no longer be updated every tick. Note that accessing a layer/its properties does NOT require it to be enabled.
Parameters
Name | Type | Description |
---|---|---|
layer | GenericLayer | The layer to remove. |
Returns
void
Defined in
profectus/src/game/layers.tsx:322
setupLayerModal
▸ setupLayerModal(layer
): Object
Utility function for creating a modal that display's a display. Returns the modal itself, which can be rendered anywhere you need, as well as a function to open the modal.
Parameters
Name | Type | Description |
---|---|---|
layer | GenericLayer | The layer to display in the modal. |
Returns
Object
Name | Type |
---|---|
modal | JSXFunction |
openModal | VoidFunction |