@crosswalk-game/menu-handler

0.1.0 • Public • Published

checks version GitHub top language license npm

MenuHandler

A crosswalk client module to handle UI menus using tagged instances (built with the tag-effect library).

Installation

Add @crosswalk-game/menu-handler in your dependencies:

yarn add @crosswalk-game/menu-handler

Or if you are using npm:

npm install @crosswalk-game/menu-handler

API

open(menuId: string)

  • Description: Opens the menu with the specified ID. Closes any menu that are not explicitly marked as compatible with the ID.

  • Parameters:

    • menuId: The unique identifier of the menu to open.

close(menuId: string)

  • Description: Closes the menu with the specified ID.

  • Parameters:

    • menuId: The unique identifier of the menu to close.

toggle(menuId: string)

  • Description: Toggles the state (open/close) of the menu with the specified ID.

  • Parameters:

    • menuId: The unique identifier of the menu to toggle.

whileOpened(menuId: string, effect: () -> Teardown): () -> ()

  • Description: Executes the specified effect while the menu with the specified ID is open. The effect will automatically be cleaned up when the menu is closed.

  • Parameters:

    • menuId: The unique identifier of the menu to target.
    • effect: The effect to execute while the menu is open. This function return any kind of teardown object (for example: nil, a cleanup function or event connections) that will automatically get cleaned up when the menu is closed.
  • Returns: A function to remove the effect.

Tag Effects

This module defines a series of tag-effects to define menus (that can be opened or closed) or buttons to open, close or toggle those menus.

MenuInstance or MenuExtension

Allowed instance class: GuiObject, LayerCollector, ProximityPrompt

Those two tag-effects are used to define a new menu with the given id. The difference between a MenuInstance and a MenuExtension is how they influence other menus:

  • when a MenuInstance is opened, all other MenuInstance will be closed (except other MenuInstance objects explicitly marked as compatible with the opened menu id)
  • when a MenuExtension is opened, it does not change other MenuInstance or MenuExtension objects

Both tag-effects have the same base configuration:

Configuration:

  • id (string): identifier for the menu

Optional:

  • defaultState (boolean): define if the menu is visible (or not) by default

Optionally, the MenuInstance tag effect can also be configured to mark other menus as compatible with itself, by adding string attributes set to other compatible menu id. For example, one could add an attribute compatibleWithStore = "Store", where Store would be another MenuInstance id.

OpenMenu, CloseMenu or ToggleMenu

These tag-effects can be used bind a signal to open, close or toggle a menu. They can be applied to any kind of instances:

  • GuiButton: which will trigger on the Activated event
  • ClickDetector: which will trigger on the MouseClick event
  • ProximityPrompt: which will trigger on the Triggered event
  • Any other instance, if the eventName attribute is set to an appropriate event name

Configuration:

  • id (string): identifier of the menu that needs to be opened

Optional:

  • eventName (string): specify which signal to use to bind the behavior

License

This project is available under the MIT license. See LICENSE.txt for details.

Readme

Keywords

Package Sidebar

Install

npm i @crosswalk-game/menu-handler

Weekly Downloads

3

Version

0.1.0

License

MIT

Unpacked Size

18 kB

Total Files

8

Last publish

Collaborators

  • jeparlefrancais