Generalize onEnded callbacks
This commit is contained in:
parent
893f4f3ed6
commit
8b9afff30d
|
@ -351,19 +351,19 @@ class WorldInfoTimedEffects {
|
||||||
#entryHashCache = new WeakMap();
|
#entryHashCache = new WeakMap();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Array of chat messages
|
* Array of chat messages.
|
||||||
* @type {string[]}
|
* @type {string[]}
|
||||||
*/
|
*/
|
||||||
#chat = [];
|
#chat = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Array of entries
|
* Array of entries.
|
||||||
* @type {WIScanEntry[]}
|
* @type {WIScanEntry[]}
|
||||||
*/
|
*/
|
||||||
#entries = [];
|
#entries = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Buffer for active timed effects
|
* Buffer for active timed effects.
|
||||||
* @type {Record<TimedEffectType, WIScanEntry[]>}
|
* @type {Record<TimedEffectType, WIScanEntry[]>}
|
||||||
*/
|
*/
|
||||||
#buffer = {
|
#buffer = {
|
||||||
|
@ -371,6 +371,39 @@ class WorldInfoTimedEffects {
|
||||||
'cooldown': [],
|
'cooldown': [],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callbacks for effect types ending.
|
||||||
|
* @type {Record<TimedEffectType, (entry: WIScanEntry) => void>}
|
||||||
|
*/
|
||||||
|
#onEnded = {
|
||||||
|
/**
|
||||||
|
* Callback for when a sticky entry ends.
|
||||||
|
* Sets an entry on cooldown immediately if it has a cooldown.
|
||||||
|
* @param {WIScanEntry} entry Entry that ended sticky
|
||||||
|
*/
|
||||||
|
'sticky': (entry) => {
|
||||||
|
if (!entry.cooldown) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const key = this.#getEntryKey(entry);
|
||||||
|
const effect = this.#getEntryTimedEffect(entry, 'cooldown');
|
||||||
|
chat_metadata.timedWorldInfo.cooldown[key] = effect;
|
||||||
|
console.log(`Adding cooldown entry ${key} on ended sticky: start=${effect.start}, end=${effect.end}`);
|
||||||
|
// Set the cooldown immediately for this evaluation
|
||||||
|
this.#buffer['cooldown'].push(entry);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback for when a cooldown entry ends.
|
||||||
|
* No-op, essentially.
|
||||||
|
* @param {WIScanEntry} entry Entry that ended cooldown
|
||||||
|
*/
|
||||||
|
'cooldown': (entry) => {
|
||||||
|
console.debug('Cooldown ended for entry', entry.uid);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the timed effects with the given messages.
|
* Initialize the timed effects with the given messages.
|
||||||
* @param {string[]} chat Array of chat messages
|
* @param {string[]} chat Array of chat messages
|
||||||
|
@ -443,33 +476,6 @@ class WorldInfoTimedEffects {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Callback for when a sticky entry ends.
|
|
||||||
* Sets an entry on cooldown immediately if it has a cooldown.
|
|
||||||
* @param {WIScanEntry} entry Entry that ended sticky
|
|
||||||
*/
|
|
||||||
#onStickyEndedCallback(entry) {
|
|
||||||
if (!entry.cooldown) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const key = this.#getEntryKey(entry);
|
|
||||||
const effect = this.#getEntryTimedEffect(entry, 'cooldown');
|
|
||||||
chat_metadata.timedWorldInfo.cooldown[key] = effect;
|
|
||||||
console.log(`Adding cooldown entry ${key} on ended sticky: start=${effect.start}, end=${effect.end}`);
|
|
||||||
// Set the cooldown immediately for this evaluation
|
|
||||||
this.#buffer['cooldown'].push(entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Callback for when a cooldown entry ends.
|
|
||||||
* No-op, essentially.
|
|
||||||
* @param {WIScanEntry} entry Entry that ended cooldown
|
|
||||||
*/
|
|
||||||
#onCooldownEndedCallback(entry) {
|
|
||||||
console.debug('Cooldown ended for entry', entry.uid);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes entries for a given type of timed effect.
|
* Processes entries for a given type of timed effect.
|
||||||
* @param {TimedEffectType} type Identifier for the type of timed effect
|
* @param {TimedEffectType} type Identifier for the type of timed effect
|
||||||
|
@ -523,8 +529,8 @@ class WorldInfoTimedEffects {
|
||||||
* Checks for timed effects on chat messages.
|
* Checks for timed effects on chat messages.
|
||||||
*/
|
*/
|
||||||
checkTimedEffects() {
|
checkTimedEffects() {
|
||||||
this.#checkTimedEffectOfType('sticky', this.#buffer['sticky'], this.#onStickyEndedCallback.bind(this));
|
this.#checkTimedEffectOfType('sticky', this.#buffer.sticky, this.#onEnded.sticky.bind(this));
|
||||||
this.#checkTimedEffectOfType('cooldown', this.#buffer['cooldown'], this.#onCooldownEndedCallback.bind(this));
|
this.#checkTimedEffectOfType('cooldown', this.#buffer.cooldown, this.#onEnded.cooldown.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue