stable
This commit is contained in:
parent
fbdac9ebf1
commit
86226ccc94
97 changed files with 5790 additions and 2307 deletions
52
js/item_lifecycle_pipeline.js
Normal file
52
js/item_lifecycle_pipeline.js
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
"use strict";
|
||||
|
||||
// Layer: entity-runtime/items/pipeline
|
||||
// Owns the ordered item lifecycle pipeline. Runtime calls this before falling
|
||||
// back to the monolithic legacy Item.prototype.update body. Type-specific item
|
||||
// methods still live on Item.prototype for compatibility while dispatch is moved
|
||||
// into explicit lifecycle steps.
|
||||
(function (global) {
|
||||
const CONCRETE_STEP_NAMES = Object.freeze([
|
||||
"TarinaiItemFrameLifecycleStep",
|
||||
"TarinaiItemDecayLifecycleStep",
|
||||
"TarinaiItemDynamicLifecycleStep",
|
||||
"TarinaiItemGrowthLifecycleStep",
|
||||
]);
|
||||
|
||||
function concreteSteps() {
|
||||
return CONCRETE_STEP_NAMES.map(name => global[name]).filter(step => step && typeof step.update === "function");
|
||||
}
|
||||
|
||||
function canRunConcretePipeline() {
|
||||
return concreteSteps().length === CONCRETE_STEP_NAMES.length;
|
||||
}
|
||||
|
||||
function runConcrete(item, dt, worldRef, context) {
|
||||
for (const step of concreteSteps()) {
|
||||
const result = step.update(item, dt, worldRef, context) || {};
|
||||
if (result.done) return result.ok !== false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function runLegacy(item, dt, worldRef, context) {
|
||||
const step = global.TarinaiItemLegacyLifecycleStep;
|
||||
if (step && typeof step.update === "function") return step.update(item, dt, worldRef, context).ok !== false;
|
||||
const legacyUpdate = context.legacyUpdate;
|
||||
if (typeof legacyUpdate !== "function") return false;
|
||||
legacyUpdate.call(item, dt, worldRef);
|
||||
return true;
|
||||
}
|
||||
|
||||
function updateOne(item, dt, worldRef, options = {}) {
|
||||
if (!item || item.dead) return false;
|
||||
const context = { legacyUpdate: options.legacyUpdate };
|
||||
return canRunConcretePipeline() ? runConcrete(item, dt, worldRef, context) : runLegacy(item, dt, worldRef, context);
|
||||
}
|
||||
|
||||
global.TarinaiItemLifecyclePipeline = Object.freeze({
|
||||
stepNames: CONCRETE_STEP_NAMES,
|
||||
canRunConcretePipeline,
|
||||
updateOne,
|
||||
});
|
||||
})(typeof window !== "undefined" ? window : globalThis);
|
||||
Loading…
Add table
Add a link
Reference in a new issue