tarinai/js/item_lifecycle_pipeline.js

34 lines
1.1 KiB
JavaScript
Raw Normal View History

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