Difference between revisions of "Composed Value Registry"
Line 1: | Line 1: | ||
− | The '''composed value registry''' is a global available registry for numbers which have various components modifying the value (eg. Bottle Caps). A single '''composed value''' provides an API with a | + | The '''composed value registry''' is a global available registry for numbers which have various components modifying the value (eg. Bottle Caps). A single '''composed value''' provides an API with a chainable interface to attach additional multipliers to the value or to trigger a recalculation of the value. An example for the usage of composed values is the Beer Blender Bar. The ingredients hook into the composed values (eg. Bottle Caps) and modify their multiplier to change their current influence. |
Get a composed value:<syntaxhighlight lang="javascript" line="1"> | Get a composed value:<syntaxhighlight lang="javascript" line="1"> |
Revision as of 19:25, 11 December 2019
The composed value registry is a global available registry for numbers which have various components modifying the value (eg. Bottle Caps). A single composed value provides an API with a chainable interface to attach additional multipliers to the value or to trigger a recalculation of the value. An example for the usage of composed values is the Beer Blender Bar. The ingredients hook into the composed values (eg. Bottle Caps) and modify their multiplier to change their current influence.
Get a composed value:
1 let composedValue = ComposedValueRegistry.getComposedValue(CV_BOTTLE_CAP);
Key | Description |
---|---|
CV_MANUAL_PLOP | The manually produced plops |
CV_BOTTLE_CAP | Produced Bottle Caps |
CV_MANA | Produced Mana in Beerwarts |
A composed value holds multiple modifiers. Each modifier is identified via a modifierKey. Each modifier must provide a callback function returning the current influence on the value. By default the returned values are cached inside the composed value.
Method | Parameters | Returns | Description |
---|---|---|---|
getValue | - | number | Get the current value including all registered modifiers. |
getValueExcludingModifier | excludeModifier (array) | number | Get the current value. excludeModifier contains a list of modifierKeys which shall not be included in the returned value. |
triggerModifierChange | modifierKey (string) | ComposedValue | Notify the composed value about a change for the given modifierKey. deletes the internal cache and updates the current influence of the modifier on the next call of getValue or getValueExcludingModifier. |
recalculate | - | ComposedValue | Force a recalculation of all internal caches |
addModifier | modifierKey (string),
modifierCallback (function), cache (bool, optional, default true) |
ComposedValue | Add an additional modifier to the composed value. The callback function provided will be executed on the next call of getValue or getValueExcludingModifier. By default the value returned by the callback will be cached. Set cache to false to fetch the value on each call of getValue via the callback function (for values which change on each tick so the values must not manually trigger a modifier change on each tick) |
removeModifier | modifierKey (string) | ComposedValue | Remove the given modifier from the composed value. |
onValueChange | callback
(function) |
ComposedValue | Execute a callback function if the composed value changes |
debug | - | - | Get a debug log with all modifiers |
Example usage:
1 ComposedValueRegistry.getComposedValue(CV_MANA)
2 .onValueChange(() => this._updateBeerwartsView())
3 .addModifier('Beerwarts_BaseProduction', () => this._getBaseManaProduction())
4 .addModifier('Beerwarts_GameSpeed', () => this.gameState.getGameSpeed());