tarinai/js/tarinai_runtime.js

61 lines
2.1 KiB
JavaScript
Raw Normal View History

2026-06-26 12:46:32 +09:00
"use strict";
// Layer: entity-runtime/tarinai
// Owns the public Tarinai update boundary. Tarinai.prototype.update remains a
// compatibility facade; concrete behavior now routes through TarinaiUpdatePipeline
// when available, with the captured legacy update kept as a fallback.
(function (global) {
let legacyUpdate = null;
function preferredLegacyUpdate(proto) {
const systemLegacy = global.TarinaiLegacyUpdateSystem?.updateWithThis;
if (typeof systemLegacy === "function") return systemLegacy;
return proto?.update || legacyUpdate;
}
function installPrototypeBoundary() {
const proto = global.Tarinai?.prototype;
if (!proto || proto._tarinaiCreatureRuntimeInstalled) return false;
legacyUpdate = preferredLegacyUpdate(proto);
if (typeof legacyUpdate === "function" && !proto._tarinaiLegacyUpdate) {
Object.defineProperty(proto, "_tarinaiLegacyUpdate", {
value: legacyUpdate,
configurable: true,
writable: true,
});
}
proto.update = function update(dt) {
return global.TarinaiCreatureRuntime.updateOne(this, dt);
};
Object.defineProperty(proto, "_tarinaiCreatureRuntimeInstalled", {
value: true,
configurable: true,
writable: true,
});
return true;
}
function updateOne(tarinai, dt) {
const fn = tarinai?._tarinaiLegacyUpdate || legacyUpdate || global.TarinaiLegacyUpdateSystem?.updateWithThis;
if (!tarinai || tarinai.dead || typeof fn !== "function") return false;
if (global.TarinaiUpdatePipeline?.updateOne) {
return global.TarinaiUpdatePipeline.updateOne(tarinai, dt, { legacyUpdate: fn }) !== false;
}
fn.call(tarinai, dt);
return true;
}
function updateBatch(tarinaiList, dt) {
if (!Array.isArray(tarinaiList)) return 0;
let ran = 0;
for (const t of tarinaiList) if (updateOne(t, dt)) ran += 1;
return ran;
}
global.TarinaiCreatureRuntime = Object.freeze({
installPrototypeBoundary,
updateOne,
updateBatch,
});
installPrototypeBoundary();
})(typeof window !== "undefined" ? window : globalThis);