Every component class extends Monogatari.Component, Monogatari.ShadowComponent, Monogatari.ScreenComponent or Monogatari.MenuComponent (see the base classes). This page lists what they all have; the methods you write to hook into the life cycle are on Component Life Cycle.
The element’s name. Set it with static tag = 'my-tag';
engine
engine
The engine, set by monogatari.registerComponent() (the built-in components have it from the start). Inside a static method it’s this.engine.
_configuration
object
{}
Settings for the component, read and written with configuration(). Declare static _configuration = {}; in your class so it doesn’t share the base class’s object.
_experimental
boolean
false
When true, the engine leaves the component out of monogatari.components(), and so never defines it, unless the ExperimentalFeatures setting is true.
_priority
number
0
Declared on the base class and never read: components are set up in the order they were registered. Deprecated.
Merges object into the component’s settings. configuration('key', value) sets one, configuration('key') returns one, configuration() returns all of them.
template(template)
Sets the component’s template: a string, or a function that receives the element and returns a string. Elements already on the page render again.
template()
Returns the template’s result, or undefined when there’s none.
instances(callback)
Calls callback with every element of the component on the page. Without a callback, returns them as an Artemis DOM object.
all()
Every element of the component on the page, as an Artemis DOM object.
get('id')
The elements of the component whose data-instance attribute is id, as an Artemis DOM object.
The game hooks (setup(), shouldProceed(), onReset() and the others) are on Component Life Cycle.
<main-menu> and <quick-menu> extend MenuComponent, which keeps their buttons in the engine’s configuration, under the menu’s tag, and has these static methods. They work anywhere in your game’s files; the buttons the engine adds or removes when the game starts (Credits, Gallery, Log, and Back and Skip when they’re turned off) are in the list only inside monogatari.init()’s .then(…):
Method
What it does
addButton(button)
Adds a button at the end.
addButtonAfter('Settings', button)
Adds a button after the one whose string is 'Settings'. Nothing happens when there’s none.
addButtonBefore('Settings', button)
Adds a button before that one.
removeButton('Settings')
Removes that button.
buttons()
Returns the list of buttons.
button('Settings')
Returns that button.
configuration('buttons', list)
Replaces the whole list. configuration({ buttons: list }) does the same.
configuration('buttons')
The list, like buttons(). configuration() returns the menu’s settings with the list as buttons.
Each change renders every element of the menu again, through its template when it has one. A button is an object:
Key
What it is
string
The key of the button’s text in the interface translations. It also identifies the button for the methods above.
icon
Optional. Font Awesome classes for the button’s icon, like 'fas fa-save'. Without one, the button has only its label.
The props. Read-only: change them with setProps(). A prop that was never set falls back to the attribute of the same name, with "5" read as 5 and "true" and "false" as booleans.
this.state
The state. Read-only once the element is on the page: change it with setState().
this.slotContent
The HTML that was written between the element’s tags, kept the first time it went on the page.
this.isReady
true once the element has rendered and until it’s taken off the page.
this.isFirstMount
true until the element has been on the page once.
this.width, this.height
The element’s size in pixels, as the browser computes it. Assigning a number or a CSS length sets its style.
Merge object into the state or the props and run the update methods. They don’t render again.
setStyle(css, replace)
Adds CSS for the component, given as text. In a ShadowComponent it applies inside the shadow root. true as the second argument replaces what was set before.
ready(callback)
Calls callback once the element has rendered, or right away when it already has.