tarinai/js/item_dynamic_tool_system.js

103 lines
4.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) {
2026-07-01 14:41:05 +09:00
function fireApi() {
const api = global.TarinaiFireRuntimeSystem;
if (!api) throw new Error("TarinaiFireRuntimeSystem must be loaded before fire item behavior is used");
return api;
2026-06-30 22:30:37 +09:00
}
2026-07-01 14:41:05 +09:00
function robotApi() {
const api = global.TarinaiRobotCleanerSystem;
if (!api) throw new Error("TarinaiRobotCleanerSystem must be loaded before robot cleaner behavior is used");
return api;
2026-06-30 22:30:37 +09:00
}
2026-06-26 12:46:32 +09:00
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) {
2026-06-29 16:21:58 +09:00
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) {
2026-06-29 16:21:58 +09:00
return Boolean(global.TarinaiMechanicalSystem.updateReciprocator(item, dt, worldRef));
2026-06-26 12:46:32 +09:00
}
2026-06-27 19:22:38 +09:00
function updatePoisonBlock(item, dt, worldRef) {
2026-06-29 16:21:58 +09:00
return Boolean(global.TarinaiMechanicalSystem.updatePoisonBlock(item, dt, worldRef));
2026-06-26 19:04:32 +09:00
}
function updateFlexibleLink(item, dt, worldRef) {
2026-06-29 16:21:58 +09:00
return Boolean(global.TarinaiConstraintSystem.updateFlexibleLink(item, dt, worldRef));
2026-06-26 19:04:32 +09:00
}
function updateRigidLink(item, dt, worldRef) {
2026-06-29 16:21:58 +09:00
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-28 13:40:41 +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;
2026-07-01 14:41:05 +09:00
if (item.type === "firecracker") return fireApi().updateFirecracker(item, dt, worldRef);
if (item.type === "flame_firecracker") return fireApi().updateFlameFirecracker(item, dt, worldRef);
if (item.type === "fire") return fireApi().updateFire(item, dt, worldRef);
2026-06-26 12:46:32 +09:00
if (item.type === "genkotsu") return updateGenkotsu(item, dt, worldRef);
if (item.type === "rotator") return updateRotator(item, dt, worldRef);
2026-06-27 19:22:38 +09:00
if (item.type === "poison_block") return updatePoisonBlock(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-07-01 14:41:05 +09:00
if (item.type === "robot_cleaner") return robotApi().updateRobotCleaner(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,
2026-07-01 14:41:05 +09:00
robotCleanerDefaultMask: (...args) => robotApi().robotCleanerDefaultMask(...args),
robotCleanerMask: (...args) => robotApi().robotCleanerMask(...args),
setRobotCleanerMask: (...args) => robotApi().setRobotCleanerMask(...args),
robotCleanerHasTarget: (...args) => robotApi().robotCleanerHasTarget(...args),
robotCleanerHighSpeed: (...args) => robotApi().robotCleanerHighSpeed(...args),
setRobotCleanerHighSpeed: (...args) => robotApi().setRobotCleanerHighSpeed(...args),
robotCleanerEffectiveSpeed: (...args) => robotApi().robotCleanerEffectiveSpeed(...args),
robotTargetLabel: (...args) => robotApi().robotTargetLabel(...args),
get robotCleanerTargetBits() { return robotApi().robotCleanerTargetBits; },
get robotCleanerTargetOrder() { return robotApi().robotCleanerTargetOrder; },
get robotCleanerMoveSpeed() { return robotApi().robotCleanerMoveSpeed; },
get robotCleanerHighMoveSpeed() { return robotApi().robotCleanerHighMoveSpeed; },
get fireBurningText() { return fireApi().fireBurningText; },
get fireSeenText() { return fireApi().fireSeenText; },
fireTempMultiplier: (...args) => fireApi().fireTempMultiplier(...args),
contactWaterDrop: (...args) => fireApi().contactWaterDrop(...args),
consumeWaterForFire: (...args) => fireApi().consumeWaterForFire(...args),
igniteTarinaiByFire: (...args) => fireApi().igniteTarinaiByFire(...args),
panicTarinaiFromFire: (...args) => fireApi().panicTarinaiFromFire(...args),
igniteAntByFire: (...args) => fireApi().igniteAntByFire(...args),
igniteGrassByFire: (...args) => fireApi().igniteGrassByFire(...args),
spawnFireAt: (...args) => fireApi().spawnFireAt(...args),
scatterFireFrom: (...args) => fireApi().scatterFireFrom(...args),
compactWorldFires: (...args) => fireApi().compactWorldFires(...args),
updateFire: (...args) => fireApi().updateFire(...args),
2026-06-26 12:46:32 +09:00
});
})(typeof window !== "undefined" ? window : globalThis);