tarinai/js/item_dynamic_tool_system.js

81 lines
2.8 KiB
JavaScript
Raw Normal View History

2026-06-26 12:46:32 +09:00
"use strict";
// Layer: entity-runtime/items/dynamic-system
2026-06-26 19:04:32 +09:00
// Owns dynamic tool behavior for rotator, reciprocator, firecracker, genkotsu,
// links, and static gate-fence ticking. Item.prototype methods delegate here for
// direct Item.prototype calls; lifecycle dispatch also calls this boundary directly.
2026-06-26 12:46:32 +09:00
(function (global) {
function support() {
return global.TarinaiItemLifecycleRuntimeSupport || {};
}
function updateFirecracker(item, dt, worldRef) {
item.fuseTimer = Math.max(0, (item.fuseTimer ?? 5) - dt);
if (item.fuseTimer <= 0) {
if (worldRef?.explodeFirecracker) worldRef.explodeFirecracker(item);
else item.amount = 0;
}
}
function updateGenkotsu(item, dt) {
item.impactFlash = Math.max(0, (item.impactFlash || 0) - dt);
if (item.dropImpactDone) {
item.lingerTimer = Math.max(0, (item.lingerTimer || 0) - dt);
if ((item.lingerTimer || 0) <= 0) item.amount = 0;
} else {
item.amount = Math.max(item.amount || 0, 100);
}
}
2026-06-26 19:04:32 +09:00
function updateRotator(item, dt, worldRef) {
return Boolean(global.TarinaiMechanicalSystem?.updateRotator?.(item, dt, worldRef));
2026-06-26 12:46:32 +09:00
}
2026-06-26 19:04:32 +09:00
function updateReciprocator(item, dt, worldRef) {
return Boolean(global.TarinaiMechanicalSystem?.updateReciprocator?.(item, dt, worldRef));
2026-06-26 12:46:32 +09:00
}
2026-06-26 19:04:32 +09:00
function resolveMechanicalInteractions(item, dt, worldRef) {
return Boolean(global.TarinaiMechanicalSystem?.resolveInteractions?.(item, dt, worldRef));
}
function updateFlexibleLink(item, dt, worldRef) {
return Boolean(global.TarinaiConstraintSystem?.updateFlexibleLink?.(item, dt, worldRef));
}
function updateRigidLink(item, dt, worldRef) {
return Boolean(global.TarinaiConstraintSystem?.updateRigidLink?.(item, dt, worldRef));
2026-06-26 12:46:32 +09:00
}
2026-06-26 19:04:32 +09:00
2026-06-26 12:46:32 +09:00
function updateGateFence(item) {
if (item) item.amount = 999;
return Boolean(item);
}
function update(item, dt, worldRef) {
if (!item || item.dead) return false;
if (item.type === "firecracker") return updateFirecracker(item, dt, worldRef);
if (item.type === "genkotsu") return updateGenkotsu(item, dt, worldRef);
if (item.type === "rotator") return updateRotator(item, dt, worldRef);
2026-06-26 19:04:32 +09:00
if (item.type === "reciprocator") return updateReciprocator(item, dt, worldRef);
2026-06-26 12:46:32 +09:00
if (item.type === "gate_fence") return updateGateFence(item, dt, worldRef);
2026-06-26 19:04:32 +09:00
if (item.type === "rope") return updateFlexibleLink(item, dt, worldRef);
if (item.type === "rod") return updateRigidLink(item, dt, worldRef);
2026-06-26 12:46:32 +09:00
return false;
}
global.TarinaiItemDynamicToolSystem = Object.freeze({
update,
updateFirecracker,
updateGenkotsu,
updateRotator,
2026-06-26 19:04:32 +09:00
updateReciprocator,
updateFlexibleLink,
updateRigidLink,
resolveMechanicalInteractions,
2026-06-26 12:46:32 +09:00
updateGateFence,
});
})(typeof window !== "undefined" ? window : globalThis);