tarinai/js/tarinai_runtime.js

41 lines
1.5 KiB
JavaScript
Raw Normal View History

2026-06-26 12:46:32 +09:00
"use strict";
// Layer: entity-runtime/tarinai
2026-06-26 19:04:32 +09:00
// Owns the public Tarinai update boundary. Tarinai.prototype.update routes
// directly through the explicit creature update pipeline.
2026-06-26 12:46:32 +09:00
(function (global) {
function installPrototypeBoundary() {
const proto = global.Tarinai?.prototype;
if (!proto || proto._tarinaiCreatureRuntimeInstalled) return false;
proto.update = function update(dt) {
return global.TarinaiCreatureRuntime.updateOne(this, dt);
};
Object.defineProperty(proto, "_tarinaiCreatureRuntimeInstalled", {
value: true,
configurable: true,
writable: true,
});
return true;
}
2026-06-27 19:22:38 +09:00
function updateOne(tarinai, dt, options = {}) {
2026-06-29 16:21:58 +09:00
if (!tarinai || tarinai.dead || !global.TarinaiUpdatePipeline.updateOne) return false;
2026-06-27 19:22:38 +09:00
return global.TarinaiUpdatePipeline.updateOne(tarinai, dt, options) !== false;
}
function updateMotionOnly(tarinai, dt, options = {}) {
2026-06-29 16:21:58 +09:00
if (!tarinai || tarinai.dead || !global.TarinaiMovementUpdateStep.update) return false;
2026-06-27 19:22:38 +09:00
tarinai.prevX = tarinai.x;
tarinai.prevY = tarinai.y;
const motionDt = Math.max(0.001, Math.min(0.05, Number(options.context?.motionDt ?? dt) || 0.016));
return global.TarinaiMovementUpdateStep.update(tarinai, motionDt, {
...(options.context || {}),
motionOnly: true,
motionDt,
})?.done !== true || !tarinai.dead;
2026-06-26 12:46:32 +09:00
}
2026-06-29 16:21:58 +09:00
global.TarinaiCreatureRuntime = Object.freeze({ updateOne, updateMotionOnly });
2026-06-26 12:46:32 +09:00
installPrototypeBoundary();
})(typeof window !== "undefined" ? window : globalThis);