tarinai/js/item_lifecycle_pipeline.js

34 lines
1.1 KiB
JavaScript

"use strict";
// Layer: entity-runtime/items/pipeline
// Owns the ordered item lifecycle pipeline. There is no monolithic fallback path:
// every item update must be handled by the explicit lifecycle steps below.
(function (global) {
const CONCRETE_STEP_NAMES = Object.freeze([
"TarinaiItemFrameLifecycleStep",
"TarinaiItemDecayLifecycleStep",
"TarinaiItemDynamicLifecycleStep",
"TarinaiItemGrowthLifecycleStep",
]);
let cachedSteps = null;
function concreteSteps() {
if (!cachedSteps) cachedSteps = CONCRETE_STEP_NAMES.map(name => global[name]);
return cachedSteps;
}
function updateOne(item, dt, worldRef, options = {}) {
if (!item || item.dead) return false;
const steps = concreteSteps();
if (steps.length !== CONCRETE_STEP_NAMES.length) return false;
const context = options.context || {};
for (const step of steps) {
const result = step.update(item, dt, worldRef, context) || {};
if (result.done) return result.ok !== false;
}
return true;
}
global.TarinaiItemLifecyclePipeline = Object.freeze({ updateOne });
})(typeof window !== "undefined" ? window : globalThis);