State

TEMPLATE NAME: State
CORE VERSION: 1.0.291
TEMPLATE VERSION: 1.0.0

TEMPLATE DESCRIPTION:

"The complexity of your game is limited by your ability to manage state."

Flexible micro-framework for managing focus across overlapping UI layers.

Based upon the concepts in Descendent's Framework Architecture, for easy integration and customization with other code.

TEMPLATE ROADMAP:

  • No-code Handlers for common use-cases

TEMPLATE VERSION NOTES:

Version 1.0.0

  • First stable release.

ADDITIONAL INFO:

  • Community Content — "State"
  • Community Project (example) — "State"

Getting Started

Import

  1. In Community Content, search for "descendent".
  2. Browse to the listing for "State", and click "Import"; then click "Yes".
  3. In Core Content, under the "Community Content" category, select the "Imported Content > State" group.
  4. Add the "State" template to the Hierarchy (in Default Context).

Set Up

  1. In Project Content, select the "Imported Content > State > Dependent Scripts" group.
  2. Add the "State_StateConfigurationStatic" script to the Hierarchy, in Static Context.
  3. Add the "State_StateStartClient" script to the Hierarchy, in Client Context.
  4. In the Hierarchy, select the "State_StateStartClient" script instance; then drag the "State_StateConfigurationStatic" script instance (from the Hierarchy) into the "State_StateStartClient" script instance's "Configuration" custom property (in the Properties panel).
  5. Add a Layer Catalog data table and script. (See "Create a Catalog".)
  6. Add Handler scripts. (See "Create a Handler".)

How-To Guides

Use this Service in a Script

  1. In Project Content, browse to the script that will be using the Service, and select it.
  2. In the Properties panel, add a custom property of type "Asset Reference", and name it "StateService"; then set its default value to reference the "State_StateService" script.
  3. Edit the script that will be using the Service; at or near the top of the code, add…
    local StateService = require(script:GetCustomProperty("StateService"))
    
    local _stateService = StateService.Use()
    
  4. Use this Service's singleton instance via the _stateService variable. (See "StateService" API reference.)

Create a Catalog

Use a Catalog to register templates, game objects, or ID's with this Service, and associate each entry with static game data.

  1. In Project Content, select the "My Tables" group.
  2. At the top of the right frame (where the "Search" field is), click the :open_file_folder: ("Create Folder") button; enter "Example", and press Enter.
  3. In Project Content, select the "Imported Content > State > Dependent Data Tables" group, then browse to the "Example" folder.
  4. Right-click an example Catalog data table, and select "Duplicate Asset"; then rename the new copy to an appropriate name, and move it to an appropriate folder.
    • The new copy will initially be placed in the "My Tables" group, in the "Example" folder, and have " - Copy" appended to its name; if the "Example" folder or the new copy doesn't appear in Project Content, save, close, and re-open the project.
  5. In Project Content, select the "Imported Content > State > Dependent Scripts" group.
  6. Add the matching Catalog script to the Hierarchy, as a child of the "State_StateStartClient" script instance.
  7. If the new Catalog script instance has a "GroupId" custom property, configure that custom property.
  8. In Project Content, select the "My Tables" group, then browse to the new Catalog data table.
  9. In the Hierarchy, select the new Catalog script instance; then drag the new Catalog data table (from Project Content) into the new Catalog script instance's "Table" custom property (in the Properties panel).
  10. Edit the new Catalog data table, to add relevant game data. (See "Catalogs" data table reference.)

Create a Handler

Use a Handler to customize this Service with game-specific game logic.

  1. In Project Content, select the "My Scripts" group.
  2. At the top of the right frame (where the "Search" field is), click the :open_file_folder: ("Create Folder") button; enter "Example", and press Enter.
  3. In Project Content, select the "Imported Content > State > Dependent Scripts" group, then browse to the "Example" folder.
  4. Right-click an example Handler script, and select "Duplicate Asset"; then rename the new copy to an appropriate name, and move it to an appropriate folder.
    • The new copy will initially be placed in the "My Scripts" group, in the "Example" folder, and have " - Copy" appended to its name; if the "Example" folder or the new copy doesn't appear in Project Content, save, close, and re-open the project.
  5. Add custom properties to the new Handler script (if applicable), and configure their default values.
  6. Add the new Handler script to the Hierarchy, as a child of the "State_StateStartClient" script instance.
  7. Configure the new Handler script instance's "GroupId" custom property.
  8. Edit the new Handler script, to implement its relevant hook functions. (See "Handlers" API reference.)

Use an Existing Handler

Use a Handler to customize this Service with game-specific game logic.

  1. In Project Content, browse to the existing Handler script.
  2. Add the existing Handler script to the Hierarchy, as a child of the "State_StateStartClient" script instance.
  3. Configure the new Handler script instance's "StateService" custom property to reference the "State_StateService" script.
  4. Configure the new Handler script instance's "GroupId" custom property.

Share an Adapter, Handler, or Binding with Other Projects or Creators

  1. In Project Content, browse to the Adapter, Handler, or Binding script that will be shared with other projects or creators, and select it.
  2. In the Properties panel, for each custom property of type "Asset Reference", "Core Object Reference", or "Net Reference": right-click the large icon in the custom property's value (or the custom property's value itself), and select "Clear Value".
    • Custom properties referencing assets or objects that shouldn't be duplicated in other projects must be cleared, to prevent the assets or objects from being packaged together with the Adapter, Handler, or Binding script when shared. These custom properties will need to be re-configured on each script instance (in the Hierarchy) in each project.
  3. Right-click the Adapter, Handler, or Binding script, and select ":rocket: Publish to Community Content"; then complete the process to publish as a public or private Community Content package.

Update

  1. In Project Content, right-click the "Imported Content > State" group, and select "Download Latest"; then click "Yes"; then click "Continue with save: I accept the risk".

Delete

  1. In Project Content, right-click the "Imported Content > State" group, and select "Delete Assets"; then, if asked, click "Delete All and Save" each time; then click "Delete All" each time.
  2. In Core Content, under the "Community Content" category, right-click the "Imported Content > State" group, and select "Delete Assets"; then click "Delete All" each time.

Custom Properties Reference

State_StateStartClient

Custom Properties

AssetReference StateService

"State_StateService" script.

string Await

Field in each tracked script's context that's expected to be assigned a truthy value, once the tracked script has finished loading.
Default: "ready"

float AwaitTimer

Amount of time (in seconds) to wait for each of this script instance's tracked scripts to finish loading, before logging a warning. This script instance will wait forever if the field specified by its "Await" custom property couldn't be found in a tracked script's context.
Default: 60

CoreObjectReference Configuration

"State_StateConfigurationStatic" script instance.

Catalogs

State_StateLayerCatalogClient

Custom Properties

AssetReference StateService

"State_StateService" script.

AssetReference Table

Data Table that provides the entities and game data for this Catalog to register.

string GetId

Data Table column for unique ID's for Layers.
Default: "Id"

string GetIndex

Data Table column for Layers' priority levels.
Default: "Index"

Handlers

State_ExampleStateHandlerClient

Custom Properties

AssetReference StateService

"State_StateService" script.

string GroupId

ID of Group this Handler provides game logic for. A Group can have at most one Handler of each type.

Data Table Reference

Catalogs

State_ExampleStateLayerCatalog

Columns

string Id

Unique ID for the Layer.

integer Index

The Layer's priority level. Among presented Handlers, the Handler that's presented in the Layer with the greatest index value is considered the "topmost" Handler. Whenever a Handler becomes the topmost Handler, its Restore hook method will be called; whenever a Handler ceases being the topmost Handler, its Suspend hook method will be called. Multiple Layer ID's can share the same index; however, at most one Handler can be presented at each index.

API Reference

StateService

Static Methods

StateService Use()

Returns the singleton instance of this Service.

Methods (Accessors)

Configuration GetConfiguration()

Returns this Service's Configuration instance.

Methods

nil AwaitConfiguration()

Blocks execution until this Service's Configuration instance is initialized.

nil AwaitSetup()

Blocks execution until all scripts tracked by this Service's "State_StateSetupClient" script instance have finished loading.

nil AwaitStart()

Blocks execution until all scripts tracked by this Service's "State_StateStartClient" script instance have finished loading.

nil AfterConfiguration(function thunk)

Schedules function thunk to be called after this Service's Configuration instance is initialized.

nil AfterSetup(function thunk)

Schedules function thunk to be called after all scripts tracked by this Service's "State_StateSetupClient" script instance have finished loading.

nil AfterStart(function thunk)

Schedules function thunk to be called after all scripts tracked by this Service's "State_StateStartClient" script instance have finished loading.

LayerCatalog AddLayerCatalog()

Creates, registers, and returns a new LayerCatalog instance for this Service. This Service can have at most one LayerCatalog instance.

Binding AddHandler(string groupId)

Creates, registers, and returns a new Handler instance for Group groupId, for this Service. A Group can have at most one Handler instance.

nil Present(string groupId, string layerId)

Presents the Handler for Group groupId, in Layer layerId.

nil Dismiss(string groupId)

Dismisses the Handler for Group groupId.

nil DismissLayer(string layerId)

Dismisses the Handler that's presented in Layer layerId.

Catalogs

LayerCatalog

Methods

nil Add(string key, integer value)

Adds Layer with ID key, and index value to this LayerCatalog instance. key must be unique within this LayerCatalog instance.

Handlers

Handler

Methods (Hook)

nil Present(...)

Called by the Service when this Handler instance is presented. If extra arguments were given to the Service's Present method, those arguments will also be passed along as arguments to this method.

nil Dismiss()

Called by the Service when this Handler instance is dismissed.

nil Restore()

Called by the Service when this Handler instance becomes the topmost Handler.

nil Suspend()

Called by the Service when this Handler instance ceases being the topmost Handler.

Examples

See "State" by Descendent in Community Projects.