tarinai/js/world_event_effects.js

55 lines
2.2 KiB
JavaScript
Raw Normal View History

2026-06-25 14:51:58 +09:00
"use strict";
(function (global) {
const events = global.TarinaiEvents;
2026-06-29 16:21:58 +09:00
if (!events) return;
2026-06-25 14:51:58 +09:00
events.on("world:phase", () => {
2026-07-29 20:52:11 +09:00
global.TarinaiAudio?.phase?.();
2026-06-25 14:51:58 +09:00
});
function playLogSoundForEntry(entry = {}) {
if (!entry || entry.hiddenFromObservation || entry.sound === false || entry.silentAudio) return;
2026-07-29 20:52:11 +09:00
const audio = global.TarinaiAudio;
2026-06-25 14:51:58 +09:00
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?.();
2026-06-28 13:40:41 +09:00
if (kind === "fight") return /\u6c7a\u7740|\u52dd|\u8ca0|\u899a\u3048/.test(text) ? audio.fightFinish?.() : audio.fight?.();
2026-06-25 14:51:58 +09:00
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") {
2026-06-28 13:40:41 +09:00
if (/\u914d\u7f6e|\u7f6e\u3044\u305f|\u8a2d\u7f6e/.test(text)) return audio.place?.(/\u7206\u7af9/.test(text) ? "firecracker" : "");
if (/\u3052\u3093\u3053\u3064/.test(text)) return audio.genkotsuImpact?.();
if (/\u7206\u7af9|\u7206\u767a/.test(text)) return audio.explode?.();
if (/\u77f3/.test(text)) return audio.stoneImpact?.();
if (/\u30dc\u30fc\u30eb/.test(text)) return audio.ballHit?.();
2026-06-25 14:51:58 +09:00
return audio.damage?.(18);
}
if (kind === "event") {
2026-06-28 13:40:41 +09:00
if (/\u5973\u738b\u30a2\u30ea/.test(text)) return audio.queenAnt?.();
if (/\u30a2\u30ea|\u5de3/.test(text)) return audio.antNest?.();
if (/\u75c5|\u767a\u75c5/.test(text)) return audio.disease?.();
if (/\u56de\u5fa9|\u6cbb/.test(text)) return audio.heal?.();
2026-06-25 14:51:58 +09:00
}
}
events.on("log:entry", (event) => {
const detail = event.detail || {};
const worldRef = detail.world || global.world;
const entry = detail.entry;
if (!entry) return;
playLogSoundForEntry(entry);
2026-06-29 16:21:58 +09:00
renderLog(worldRef?.logs || []);
pushLogNotification(entry);
2026-06-25 14:51:58 +09:00
});
events.on("tool:placed", (event) => {
const detail = event.detail || {};
2026-07-29 20:52:11 +09:00
if (detail.dropped) global.TarinaiAudio?.place?.(detail.type || detail.item?.type || "");
2026-06-25 14:51:58 +09:00
});
})(typeof window !== "undefined" ? window : globalThis);