tarinai/js/world_event_effects.js

56 lines
2.3 KiB
JavaScript
Raw Normal View History

2026-06-25 14:51:58 +09:00
"use strict";
(function (global) {
const events = global.TarinaiEvents;
if (!events || events.__worldEventEffectsBound) return;
events.__worldEventEffectsBound = true;
events.on("world:phase", () => {
global.audio?.phase?.();
});
function playLogSoundForEntry(entry = {}) {
if (!entry || entry.hiddenFromObservation || entry.sound === false || entry.silentAudio) return;
const audio = global.audio;
if (!audio) return;
const kind = entry.kind || "note";
const text = String(entry.text || "");
if (kind === "death") return audio.death?.();
if (kind === "birth") return audio.birth?.();
if (kind === "fight") return /決着|勝|負|覚え/.test(text) ? audio.fightFinish?.() : audio.fight?.();
if (kind === "food") return audio.eat?.();
if (kind === "grass") return audio.play?.("sfx_grass", { category: "ops", minGap: 0.25 });
if (kind === "weather") return audio.phase?.();
if (kind === "relation") return audio.notify?.();
if (kind === "accident") {
if (/配置|置いた|設置/.test(text)) return audio.place?.(/爆竹/.test(text) ? "firecracker" : "");
if (/げんこつ/.test(text)) return audio.genkotsuImpact?.();
if (/爆竹|爆発/.test(text)) return audio.explode?.();
if (/石/.test(text)) return audio.stoneImpact?.();
if (/ボール/.test(text)) return audio.ballHit?.();
return audio.damage?.(18);
}
if (kind === "event") {
if (/女王アリ/.test(text)) return audio.queenAnt?.();
if (/アリ|巣/.test(text)) return audio.antNest?.();
if (/病|発病/.test(text)) return audio.disease?.();
if (/回復|治/.test(text)) return audio.heal?.();
}
}
events.on("log:entry", (event) => {
const detail = event.detail || {};
const worldRef = detail.world || global.world;
const entry = detail.entry;
if (!entry) return;
playLogSoundForEntry(entry);
if (typeof renderLog === "function") renderLog(worldRef?.logs || []);
if (typeof pushLogNotification === "function") pushLogNotification(entry);
});
events.on("tool:placed", (event) => {
const detail = event.detail || {};
if (detail.dropped) global.audio?.place?.(detail.type || detail.item?.type || "");
});
})(typeof window !== "undefined" ? window : globalThis);