tarinai/js/ui_selected.js
2026-07-16 22:12:03 +09:00

394 lines
22 KiB
JavaScript

"use strict";
function escapeHtml(value) { return window.TarinaiUIHelpers.htmlEscape(value); }
function quoteNameInRecordText(text, name) {
const raw = String(text || "");
const n = String(name || "").trim();
if (!n) return raw;
const parts = raw.split(n);
if (parts.length <= 1) return raw;
let out = "";
for (let i = 0; i < parts.length - 1; i++) {
const before = parts[i].slice(-1);
const after = parts[i + 1].charAt(0);
out += parts[i] + ((before === "\u300c" && after === "\u300d") ? n : `\u300c${n}\u300d`);
}
return out + parts[parts.length - 1];
}
function renameSelectedTarinai(rawName) {
const t = world.selected;
if (!t || t.dead || !world.tarinai.includes(t)) return false;
const next = String(rawName || "").replace(/\s+/g, " ").trim().slice(0, 18);
if (!next) {
uiCache.selectedSnapshot = "";
renderSelected();
return false;
}
if (next === t.name) return false;
const oldName = t.name;
t.name = next;
if (t.isZunchiSlave) t.formerName = next;
world.recordFamily?.(t);
world.markFamilyTreeDirty?.("rename");
uiCache.archiveFamilyVersion = null;
uiCache.selectedSnapshot = "";
renderSelected();
renderArchive?.();
render?.();
showToast(`\u300c${oldName}\u300d\u3092\u300c${next}\u300d\u306b\u6539\u540d\u3057\u307e\u3057\u305f\u3002`);
return true;
}
function personalityValueText(value) {
const n = clamp(Number(value) || 0, -1, 1);
return `${n >= 0 ? "+" : ""}${n.toFixed(2)}`;
}
function personalityRowsHtml(personality = {}) {
const p = normalizePersonality(personality);
return PERSONALITY_KEYS.map(key => `<span>${escapeHtml(PERSONALITY_LABELS[key]?.label || key)}: ${personalityValueText(p[key])}</span>`).join("");
}
function personalityShortLabel(key) {
return ({
aggression: "\u653b\u6483",
openness: "\u958b\u653e",
sociability: "\u793e\u4ea4",
neuroticism: "\u795e\u7d4c",
})[key] || (PERSONALITY_LABELS[key]?.label || key);
}
function personalityDisplayCauseText(cause = "") {
return String(cause || "").replace(/(?:\u306e)?\u5f71\u97ff\u3067$/g, "").trim();
}
function geneticPercentText(t, key = "") {
const ratio = t?.geneticStatRatio ? t.geneticStatRatio(key) : 1;
const pct = Math.round((ratio - 1) * 100);
return `${pct >= 0 ? "+" : ""}${pct}%`;
}
function geneticSizeText(t) {
const adult = Number.isFinite(t?.adultScale) ? t.adultScale : (t?.scale || 0.28);
const now = Number.isFinite(t?.scale) ? t.scale : adult;
const growth = Math.round((t?.growth ?? 1) * 100);
return `${geneticPercentText(t, "size")} / ${now.toFixed(2)}\u2192${adult.toFixed(2)} (${growth}%)`;
}
function geneticComfortTemperatureText(t) {
const raw = t?.genetics?.temperatureOffset;
const offset = Number.isFinite(Number(raw)) ? Number(raw) : 0;
const min = (CONFIG.temperatureComfortMin ?? 10) + offset;
const max = (CONFIG.temperatureComfortMax ?? 25) + offset;
const sign = offset >= 0 ? "+" : "";
return `${min.toFixed(1)}\u301C${max.toFixed(1)}\u2103 <small>(${sign}${offset.toFixed(1)}\u2103)</small>`;
}
function personalityDailyChangeHtml(t) {
const state = typeof personalityDailyState === "function" ? personalityDailyState(t) : (t?.personalityDaily || { day: world?.day || 1, byKey: {}, byCause: {} });
const dayLabel = `D${state.day || world?.day || 1}`;
const causeMap = new Map();
const addCauseChange = (cause, key, up, down) => {
const cleanCause = personalityDisplayCauseText(cause || "") || "\u8981\u56e0\u4e0d\u660e";
if (!causeMap.has(cleanCause)) causeMap.set(cleanCause, new Map());
const byKey = causeMap.get(cleanCause);
const current = byKey.get(key) || { up: 0, down: 0 };
current.up += Math.max(0, Number(up) || 0);
current.down += Math.max(0, Number(down) || 0);
byKey.set(key, current);
};
for (const [cause, entry] of Object.entries(state.byCause || {})) {
for (const key of PERSONALITY_KEYS) {
const v = entry?.byKey?.[key] || {};
const up = Math.max(0, Number(v.up) || 0);
const down = Math.max(0, Number(v.down) || 0);
if (up > 0.0001 || down > 0.0001) addCauseChange(cause, key, up, down);
}
}
if (!causeMap.size) {
for (const key of PERSONALITY_KEYS) {
const entry = state.byKey?.[key] || {};
const up = Math.max(0, Number(entry.up) || 0);
const down = Math.max(0, Number(entry.down) || 0);
if (up <= 0.0001 && down <= 0.0001) continue;
const causes = Array.isArray(entry.causes) ? [...new Set(entry.causes.map(c => personalityDisplayCauseText(c)).filter(Boolean))].slice(0, 4) : [];
for (const cause of causes.length ? causes : ["\u8981\u56e0\u4e0d\u660e"]) addCauseChange(cause, key, up, down);
}
}
const rows = [];
for (const [cause, byKey] of causeMap.entries()) {
const parts = [];
for (const key of PERSONALITY_KEYS) {
const entry = byKey.get(key);
if (!entry) continue;
const up = Math.max(0, Number(entry.up) || 0);
const down = Math.max(0, Number(entry.down) || 0);
if (up > 0.0001) parts.push(`${personalityShortLabel(key)} +${up.toFixed(3)}`);
if (down > 0.0001) parts.push(`${personalityShortLabel(key)} -${down.toFixed(3)}`);
}
if (parts.length) rows.push(`<li><span>${escapeHtml(cause)}</span><strong>${escapeHtml(parts.join(" / "))}</strong><em>${escapeHtml(dayLabel)}</em></li>`);
}
return rows.join("") || `<li><span>\u8981\u56e0</span><strong>\u5909\u5316\u306a\u3057</strong><em>${escapeHtml(dayLabel)}</em></li>`;
}
function personalityDailySnapshot(t) {
const state = typeof personalityDailyState === "function" ? personalityDailyState(t) : (t?.personalityDaily || {});
const keyPart = PERSONALITY_KEYS.map(key => {
const entry = state.byKey?.[key] || {};
const causes = Array.isArray(entry.causes) ? entry.causes.join("/") : "";
return `${key}:${Number(entry.up || 0).toFixed(4)}:${Number(entry.down || 0).toFixed(4)}:${causes}`;
}).join(",");
const causePart = Object.entries(state.byCause || {}).map(([cause, entry]) => {
const values = PERSONALITY_KEYS.map(key => {
const v = entry?.byKey?.[key] || {};
return `${key}:${Number(v.up || 0).toFixed(4)}:${Number(v.down || 0).toFixed(4)}`;
}).join(";");
return `${cause}=${values}`;
}).join("|");
return `${keyPart}#${causePart}`;
}
function selectedDataCategoryHtml(id, label, bodyHtml) {
if (!uiCache.selectedCollapsedCategories) uiCache.selectedCollapsedCategories = new Set();
const collapsed = uiCache.selectedCollapsedCategories.has(id);
return `<section class="selected-category${collapsed ? " collapsed" : ""}" data-selected-category="${escapeHtml(id)}">
<button class="selected-category-toggle" type="button" aria-expanded="${collapsed ? "false" : "true"}">${escapeHtml(label)}</button>
<div class="selected-category-body">${bodyHtml}</div>
</section>`;
}
function selectedInfoRowHtml(label, valueHtml, metric = "") {
const metricAttr = metric ? ` data-metric="${escapeHtml(metric)}"` : "";
return `<div class="info-row"${metricAttr}><span>${escapeHtml(label)}</span><strong>${valueHtml}</strong></div>`;
}
function selectedInventoryItems(t) {
const worldRef = t?.world || world;
const labels = { grass_bed: "\u304b\u3093\u305f\u3093\u30d9\u30c3\u30c9", plushie: "\u306c\u3044\u3050\u308b\u307f" };
const items = (worldRef?.ownedItemsFor?.(t?.id) || worldRef?.items || []).filter(it => it && !it.dead && it.isStructure && it.ownerId === t?.id);
const counts = new Map();
for (const it of items) {
const label = labels[it.type] || toolLabel(it.type) || it.type;
counts.set(label, (counts.get(label) || 0) + 1);
}
return Array.from(counts.entries()).map(([label, count]) => count > 1 ? `${label} \u00d7${count}` : label);
}
function selectedInventoryHtml(t) {
const entries = selectedInventoryItems(t);
if (!entries.length) return `<div class="info-row"><span>\u6240\u6301\u54c1</span><strong>\u306a\u3057</strong></div>`;
return `<div class="info-row"><span>\u6240\u6301\u54c1</span><strong>${entries.map(v => `<span class="personality-tag">${escapeHtml(v)}</span>`).join("")}</strong></div>`;
}
function renderSelected() {
const t = world.selected;
if (!t || t.dead || !world.tarinai.includes(t)) {
const showEmpty = Boolean(uiCache.showSelectedEmpty);
ui.selectedCard?.classList.toggle("hidden", !showEmpty);
if (uiCache.selectedEmpty && uiCache.selectedEmptyVisible === showEmpty) return;
uiCache.selectedSnapshot = "";
uiCache.selectedEmpty = true;
uiCache.selectedEmptyVisible = showEmpty;
ui.selectedInfo.className = "selected-info empty";
ui.selectedInfo.textContent = "\u305f\u308a\u306a\u3044\u3092\u9078\u629e\u3057\u3066\u304f\u3060\u3055\u3044";
return;
}
uiCache.showSelectedEmpty = false;
ui.selectedCard?.classList.remove("hidden");
uiCache.selectedEmpty = false;
uiCache.selectedEmptyVisible = false;
const activeNameInput = document.activeElement?.matches?.("[data-selected-name]") && document.activeElement?.dataset?.selectedId === t.id;
if (activeNameInput) return;
const rel = t.relationSummary ? t.relationSummary() : {};
const generationDisplay = t.displayGeneration ? t.displayGeneration() : ((t.hasPaired || t.parents?.length || t.children?.length) ? t.generation : "");
ensurePersonality(t);
const personalityTags = t.personalityTags ? t.personalityTags() : getPersonalityTraitTags(t);
const personalitySnapshot = [
...PERSONALITY_KEYS.map(key => personalityValueText(t.birthPersonality?.[key])),
...PERSONALITY_KEYS.map(key => personalityValueText(t.currentPersonality?.[key])),
personalityTags.join(",")
].join(",");
const itemEffectSummary = t.activeItemEffectSummary ? t.activeItemEffectSummary() : [];
const needKeys = typeof TARINAI_NEED_KEYS !== "undefined" ? TARINAI_NEED_KEYS : ["food", "sleep", "health", "safety", "social", "fulfill"];
const behaviorState = currentTarinaiBehavior(t);
const snapshot = [
t.id, world?.groundType || "soil", t.type, t.name, generationDisplay, t.state, t.thought, targetLabel(t.target), fmt(Math.max(0, Number(t.electricShockUntil || 0) - Number(world?.time || 0))),
behaviorState?.need || "", behaviorState?.actionId || "", behaviorState?.label || "", behaviorState?.reason || "", behaviorState?.source || "", behaviorState?.text || "", needKeys.map(key => `${key}:${t.needs?.[key] ?? 0}`).join(","),
fmt(t.age), fmt(t.lifeSpan), fmt(t.hunger), fmt(t.loneliness),
fmt(t.energy), fmt(t.stress), fmt(t.mood),
t.parentNames?.join("+") || "", t.children?.length || 0, fmt(t.lack),
relationEntries(t, "friend").map(r => `${r.id}:${fmt(r.score)}:${r.name}`).join(","), relationEntries(t, "enemy").map(r => `${r.id}:${fmt(r.score)}:${r.name}`).join(","), fightWinRateLabel(t),
t.isZunchiSlave ? 1 : 0, t.isTarinaiChampion ? 1 : 0, fmt(t.totalFightWins || 0), fmt(t.totalFightLosses || 0), fmt(t.loveMochiTimer || 0), fmt(t.fightMochiTimer || 0),
t.zunchiDisease ? 1 : 0, fmt(t.zunchiDiseaseSeverity || 0), fmt(t.zunchiStain || 0),
t.sleepDisease ? 1 : 0, t.explosionDisease ? 1 : 0, fmt(t.explosionDiseaseTimer || 0), t.fightDisease ? 1 : 0, t.favorite ? 1 : 0,
personalitySnapshot, personalityDailySnapshot(t),
["life", "attack", "speed", "size"].map(key => geneticPercentText(t, key)).join(","), geneticComfortTemperatureText(t), fmt((t.growth || 0) * 100),
itemEffectSummary.map(e => `${e.id}:${e.detail}`).join(","),
selectedInventoryItems(t).join(","),
(t.records || []).slice(0, 7).map(r => `${Math.round(r.time || 0)}:${r.kind || ""}:${r.text || ""}`).join("~")
].join("|");
if (uiCache.selectedSnapshot === snapshot) return;
uiCache.selectedSnapshot = snapshot;
ui.selectedInfo.className = "selected-info";
const effectBadges = [];
if (t.isZunchiSlave) effectBadges.push(`<span class="badge">\u305a\u3093\u3061\u3069\u308c\u3044</span>`);
if (t.isTarinaiChampion) effectBadges.push(`<span class="badge">\u265b \u305f\u308a\u306a\u3044\u738b\u8005</span>`);
if (t.favorite) effectBadges.push(`<span class="badge">\u2605</span>`);
if (t.zunchiDisease) effectBadges.push(`<span class="badge">\u305a\u3093\u3061\u75c5 ${fmt((t.zunchiDiseaseSeverity || 0) * 100)}</span>`);
if (t.sleepDisease) effectBadges.push(`<span class="badge">\u306d\u3080\u308a\u75c5</span>`);
if (t.explosionDisease) effectBadges.push(`<span class="badge">\u7206\u767a\u75c5 ${fmt(t.explosionDiseaseTimer || 0)}</span>`);
if (t.fightDisease) effectBadges.push(`<span class="badge">\u304d\u305a\u3064\u304d\u75c5</span>`);
if ((t.loveMochiTimer || 0) > 0.1) effectBadges.push(`<span class="badge">\u3078\u3053\u9905 ${fmt(t.loveMochiTimer)}</span>`);
if ((t.fightMochiTimer || 0) > 0.1) effectBadges.push(`<span class="badge">\u3051\u3093\u304b\u9905 ${fmt(t.fightMochiTimer)}</span>`);
const personalityTagHtml = personalityTags.length
? personalityTags.map(tag => `<span class="personality-tag">${escapeHtml(tag)}</span>`).join("")
: `<span class="personality-tag neutral">\u4e2d\u7acb</span>`;
const recentChangeHtml = personalityDailyChangeHtml(t);
const personalityHtml = `
<div class="info-row personality-values"><span>\u6027\u683c\u30bf\u30b0</span><strong>${personalityTagHtml}</strong></div>
<div class="info-row personality-values"><span>\u8a95\u751f\u6642\u6027\u683c</span><strong>${personalityRowsHtml(t.birthPersonality)}</strong></div>
<div class="info-row personality-values"><span>\u73fe\u5728\u6027\u683c</span><strong>${personalityRowsHtml(t.currentPersonality)}</strong></div>
<div class="info-row selected-personality-changes"><span>\u4eca\u65e5\u306e\u5909\u5316</span><strong><ol class="selected-change-list">${recentChangeHtml}</ol></strong></div>
`;
const recentMemoryHtml = (t.records || []).slice(0, 7).map(r => {
const timeText = world.clockString ? (world.clockStringFromTime ? world.clockStringFromTime(r.time || 0) : formatRecordTime(r.time || 0)) : formatRecordTime(r.time || 0);
const recordText = quoteNameInRecordText(r.text || "", t.name);
return `<li><span>${escapeHtml(timeText)}</span><strong>${escapeHtml(recordText)}</strong></li>`;
}).join("") || `<li><span>-</span><strong>\u307e\u3060\u8a18\u61b6\u304c\u3042\u308a\u307e\u305b\u3093</strong></li>`;
const basicHtml = `
<div class="info-row"><span>\u4e16\u4ee3</span><strong>${escapeHtml(generationDisplay || "\u4e0d\u660e")}</strong></div>
<div class="info-row"><span>\u5e74\u9f62</span><strong>${fmt(t.age)} / ${fmt(t.lifeSpan)}</strong></div>
<div class="info-row"><span>\u6700\u5927\u5bff\u547d</span><strong>${geneticPercentText(t, "life")}</strong></div>
<div class="info-row"><span>\u653b\u6483\u529b</span><strong>${geneticPercentText(t, "attack")}</strong></div>
<div class="info-row"><span>\u79fb\u52d5\u901f\u5ea6</span><strong>${geneticPercentText(t, "speed")}</strong></div>
<div class="info-row"><span>\u30b5\u30a4\u30ba</span><strong>${geneticSizeText(t)}</strong></div>
<div class="info-row"><span>\u5FEB\u9069\u6E29\u5EA6</span><strong>${geneticComfortTemperatureText(t)}</strong></div>
`;
const needRowsHtml = needKeys.map(key => {
const label = (typeof TARINAI_NEED_LABELS !== "undefined" && TARINAI_NEED_LABELS[key]) || key;
const value = typeof getNeedDisplayValue === "function" ? getNeedDisplayValue(t.needs?.[key] || 0) : Math.round((t.needs?.[key] || 0) / 10);
const chosen = behaviorState?.need === key ? ` data-chosen-need="true"` : "";
return `<div class="need-cell"${chosen}><span>${escapeHtml(label)}</span><strong>${escapeHtml(value)}</strong></div>`;
}).join("");
const healthHtml = [
`<div class="info-row action-reason-row"><span>\u884c\u52d5</span><strong>${escapeHtml(reasonLabel(t))}</strong></div>`,
`<div class="need-grid">${needRowsHtml}</div>`,
selectedInfoRowHtml("\u4f53\u529b", `${fmt(t.energy)} / ${fmt(typeof tarinaiMaxEnergy === "function" ? tarinaiMaxEnergy(t) : (Number(t.maxEnergy) || 100))}`, "energy"),
selectedInfoRowHtml("\u30b9\u30c8\u30ec\u30b9", fmt(t.stress), "stress"),
selectedInfoRowHtml("\u4F53\u611F\u6C17\u6E29", `${(world.feltTemperatureFor?.(t) ?? world.temperatureAt?.(t.x, t.y, t) ?? t.feltTemperature ?? CONFIG.standardTemperature ?? 15).toFixed(1)}\u2103`, "temperature"),
selectedInfoRowHtml("\u6e80\u8179\u5ea6", fmt(Math.max(0, Math.min(100, 100 - (Number(t.hunger) || 0)))), "fullness"),
].join("");
const itemEffectHtml = itemEffectSummary.length
? itemEffectSummary.map(e => `<div class="info-row"><span>${escapeHtml(e.label)}</span><strong>${escapeHtml(e.detail)}</strong></div>`).join("")
: `<div class="info-row"><span>\u30a2\u30a4\u30c6\u30e0\u52b9\u679c</span><strong>\u306a\u3057</strong></div>`;
const relationHtml = `
<div class="info-row relation-row relation-list-row"><span>\u53cb\u9054</span><strong>${relationListHtml(t, "friend")}</strong></div>
<div class="info-row relation-row relation-list-row"><span>\u6575\u5bfe</span><strong>${relationListHtml(t, "enemy")}</strong></div>
<div class="info-row"><span>\u89aa</span><strong>${escapeHtml(t.parentNames?.length ? t.parentNames.join(" + ") : "\u4e0d\u660e")}</strong></div>
<div class="info-row"><span>\u5b50</span><strong>${t.children?.length || 0}</strong></div>
<div class="info-row"><span>\u3051\u3093\u304b\u52dd\u7387</span><strong>${escapeHtml(fightWinRateLabel(t))}</strong></div>
<div class="info-row"><span>\u79f0\u53f7</span><strong>${t.isTarinaiChampion ? "\u305f\u308a\u306a\u3044\u738b\u8005" : "\u306a\u3057"}</strong></div>
`;
ui.selectedInfo.innerHTML = `
<div class="selected-name-editor">
<input class="selected-name-input" data-selected-name data-selected-id="${escapeHtml(t.id)}" value="${escapeHtml(t.name)}" maxlength="18" aria-label="\u305f\u308a\u306a\u3044\u306e\u540d\u524d" title="\u540d\u524d\u3092\u7de8\u96c6">
</div>
${effectBadges.length ? `<div class="selected-effects">${effectBadges.join("")}</div>` : ""}
<div class="selected-data-groups">
${selectedDataCategoryHtml("basic", "\u57fa\u672c", basicHtml)}
${selectedDataCategoryHtml("health", "\u6b32\u6c42", healthHtml)}
${selectedDataCategoryHtml("effects", "\u30a2\u30a4\u30c6\u30e0\u52b9\u679c", itemEffectHtml)}
${selectedDataCategoryHtml("personality", "\u6027\u683c", personalityHtml)}
${selectedDataCategoryHtml("relation", "\u95a2\u4fc2\u3068\u5bb6\u65cf", relationHtml)}
${selectedDataCategoryHtml("inventory", "\u6240\u6301\u54c1", selectedInventoryHtml(t))}
${selectedDataCategoryHtml("memories", "\u6700\u8fd1\u306e\u8a18\u61b6", `<div class="selected-records selected-memories"><ol>${recentMemoryHtml}</ol></div>`)}
</div>
<div class="selected-actions"><button type="button" class="favorite-toggle ${t.favorite ? "active" : ""}" data-selected-action="favorite">${t.favorite ? "\u2605 \u304a\u6c17\u306b\u5165\u308a\u89e3\u9664" : "\u2606 \u304a\u6c17\u306b\u5165\u308a"}</button></div>
`;
}
function formatRecordTime(time) {
const totalMinutes = Math.floor(((time || 0) % (CONFIG.dayLength || 120)) / (CONFIG.dayLength || 120) * 24 * 60);
const hh = String(Math.floor(totalMinutes / 60)).padStart(2, "0");
const mm = String(totalMinutes % 60).padStart(2, "0");
return `${hh}:${mm}`;
}
function stateLabel(s) {
return window.TEXT_CATALOG?.stateLabel?.(s) || s || "";
}
function groundAwareIdleText(t) {
return window.TEXT_CATALOG?.idleGroundText?.(t) || "\u307c\u30fc\u3063\u3068\u3057\u3066\u3044\u308b\u3002";
}
function isIdleDisplayText(value = "") {
return ["\u5f85\u6a5f", "\u5f85\u3063\u3066\u3044\u308b", "\u5f85\u3063\u3066\u3044\u308b\u3002", "\u307c\u30fc\u3063\u3068\u3057\u3066\u3044\u308b", "\u307c\u30fc\u3063\u3068\u3057\u3066\u3044\u308b\u3002", "\u5468\u56f2\u3092\u898b\u3066\u3044\u308b"].includes(String(value || "").trim());
}
function reasonLabel(t) {
if (!t) return "\u306a\u3057";
if (Number(t.electricShockUntil || 0) > Number(t.world?.time || world?.time || 0)) return "\u611f\u96fb\u3057\u3066\u3044\u308b\u3002";
if (t.state === "play_seesaw" && globalThis.TarinaiSeesawSystem?.isPlaying?.(t, t.world || world)) return "\u30b7\u30fc\u30bd\u30fc\u3092\u3057\u3066\u3044\u308b\u3002";
const behavior = behaviorText(t);
if (behavior) {
const normalized = window.TEXT_CATALOG?.cleanBehaviorText?.(behavior, t.state || "") || behavior;
if (isIdleDisplayText(normalized)) return window.TEXT_CATALOG?.temperatureEndureText?.(t) || groundAwareIdleText(t);
return normalized;
}
const state = String(t.state || "");
const live = window.TEXT_CATALOG?.reasonLabel?.(t) || "";
const liveStates = new Set(["birth_ritual", "eat", "sleep", "panic", "fight", "intimidate", "ant_attack", "ant_intimidate", "frozen"]);
if (live && (liveStates.has(state) || (t.birthRitualTimer || 0) > 0.04 || (t.eatTimer || 0) > 0.04 || (t.fightTimer || 0) > 0.04 || (t.intimidateTimer || 0) > 0.04)) return live;
const behaviorState = currentTarinaiBehavior(t);
if (behaviorState?.reason || behaviorState?.text) {
const raw = behaviorState.reason || behaviorState.text;
const normalized = window.TEXT_CATALOG?.cleanBehaviorText?.(raw, behaviorState?.actionId || t.state || "") || raw;
if (isIdleDisplayText(normalized)) return window.TEXT_CATALOG?.temperatureEndureText?.(t) || groundAwareIdleText(t);
return normalized;
}
if (isIdleDisplayText(live)) return window.TEXT_CATALOG?.temperatureEndureText?.(t) || groundAwareIdleText(t);
if ((!live || live === "\u306a\u3057") && (String(t.state || "") === "idle" || !t.state)) return window.TEXT_CATALOG?.temperatureEndureText?.(t) || groundAwareIdleText(t);
return live || "\u306a\u3057";
}
function targetLabel(target) {
return window.TEXT_CATALOG?.targetLabel?.(target) || "\u306a\u3057";
}
function fightWinRateLabel(t) {
const won = Number(t.totalFightWins || 0);
const lost = Number(t.totalFightLosses || 0);
const total = won + lost;
if (!total) return "\u306a\u3057";
return `${Math.round((won / total) * 100)}% (${won}\u52dd${lost}\u6557)`;
}
function setTextIfChanged(el, key, value) {
if (!el) return;
const next = String(value);
if (uiCache.stats[key] === next) return;
uiCache.stats[key] = next;
el.textContent = next;
}
function escapeRegExp(value) {
return String(value ?? "").replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
function formatLogDisplayText(text) {
let out = String(text ?? "");
const names = new Set();
for (const t of world?.tarinai || []) if (t?.name) names.add(t.name);
for (const n of Object.values(world?.family || {})) if (n?.name) names.add(n.name);
const sorted = [...names].filter(Boolean).sort((a, b) => b.length - a.length);
for (const name of sorted) {
const re = new RegExp(`(^|[^\u300c])(${escapeRegExp(name)})(?=[\u3068\u306f\u304c\u3092\u306b\u306e\u3082\u3078\u304b\u3089\u3067\u3001\u3002]|$)`, "g");
out = out.replace(re, (m, prefix, found) => `${prefix}\u300c${found}\u300d`);
}
return out;
}