tarinai/js/tarinai_item_interaction_system.js

35 lines
1.3 KiB
JavaScript
Raw Normal View History

2026-06-26 12:46:32 +09:00
"use strict";
// Tarinai item interaction system.
// Orchestrates food/medicine consumption and non-eating item contact effects.
2026-06-26 19:04:32 +09:00
// The candidate loop intentionally preserves the established order: for each nearby
2026-06-26 12:46:32 +09:00
// candidate, try eating first; if nothing was consumed, apply contact effects
// for that same candidate before advancing to the next one.
(function (global) {
function interactWithItems(dt = 0) {
2026-06-29 16:21:58 +09:00
const ctx = global.TarinaiItemInteractionContext.create(this, dt);
2026-06-26 12:46:32 +09:00
if (!ctx) return false;
for (const item of ctx.foodCandidates || []) {
2026-06-29 16:21:58 +09:00
const consumed = Boolean(global.TarinaiFoodInteractionSystem.updateCandidate(this, ctx, item, dt));
2026-06-26 12:46:32 +09:00
if (consumed) {
2026-06-29 16:21:58 +09:00
global.TarinaiItemInteractionContext.finalize(this);
2026-06-26 12:46:32 +09:00
return true;
}
2026-06-29 16:21:58 +09:00
global.TarinaiContactItemSystem.updateCandidate(this, ctx, item, dt);
2026-06-26 12:46:32 +09:00
}
2026-07-20 14:36:59 +09:00
global.TarinaiContactItemSystem.updateResidues?.(this, dt);
2026-06-29 16:21:58 +09:00
global.TarinaiItemInteractionContext.finalize(this);
2026-06-26 12:46:32 +09:00
return true;
}
function updateOne(tarinai, dt = 0) {
if (!tarinai || tarinai.dead) return false;
return interactWithItems.call(tarinai, dt);
}
global.TarinaiItemInteractionSystem = Object.freeze({
updateOne,
});
})(typeof window !== "undefined" ? window : globalThis);