not bad
This commit is contained in:
parent
2741b93dea
commit
434f07cc4e
103 changed files with 8387 additions and 8152 deletions
57
js/ui_ground.js
Normal file
57
js/ui_ground.js
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
"use strict";
|
||||
|
||||
(function (global) {
|
||||
function groundDef(worldRef = global.world) {
|
||||
const id = worldRef?.groundType || "soil";
|
||||
return global.TarinaiGround?.definition?.(id) || (typeof GROUND_TYPES !== "undefined" ? GROUND_TYPES[id] || GROUND_TYPES.soil : { id: "soil", label: "土", description: "いつものじめん" });
|
||||
}
|
||||
|
||||
function groundTip(worldRef = global.world) {
|
||||
const def = groundDef(worldRef);
|
||||
if (global.TarinaiGround?.tooltipText) return global.TarinaiGround.tooltipText(def.id);
|
||||
return `${def.label || "じめん"}\n${def.description || "クリックで切り替え"}`;
|
||||
}
|
||||
|
||||
function updateGroundUI(worldRef = global.world) {
|
||||
const uiRef = global.ui || {};
|
||||
const def = groundDef(worldRef);
|
||||
const label = def.label || "土";
|
||||
if (uiRef.statGroundType) setTextIfChanged(uiRef.statGroundType, "groundType", label);
|
||||
if (uiRef.groundTypeBtn) {
|
||||
const desc = def.description || "クリックで切り替え";
|
||||
uiRef.groundTypeBtn.dataset.tip = desc;
|
||||
uiRef.groundTypeBtn.removeAttribute("title");
|
||||
uiRef.groundTypeBtn.setAttribute("aria-label", desc ? `地面を切り替える。現在は${label}。${desc}` : `地面を切り替える。現在は${label}`);
|
||||
}
|
||||
}
|
||||
|
||||
function bindGroundUI(worldRef = global.world) {
|
||||
const btn = global.ui?.groundTypeBtn;
|
||||
if (!btn) return;
|
||||
if (btn.dataset.groundBound !== "1") {
|
||||
btn.dataset.groundBound = "1";
|
||||
btn.addEventListener("click", (event) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
const currentWorld = global.world || worldRef;
|
||||
audio.uiClick?.();
|
||||
currentWorld?.cycleGroundType?.();
|
||||
if (global.uiCache) {
|
||||
global.uiCache.lastStatsGroundType = "";
|
||||
if (global.uiCache.stats) global.uiCache.stats.groundType = "";
|
||||
}
|
||||
updateGroundUI(currentWorld);
|
||||
global.renderStats?.();
|
||||
});
|
||||
}
|
||||
global.TarinaiTooltips?.bind?.(btn, () => groundTip(worldRef));
|
||||
updateGroundUI(worldRef);
|
||||
}
|
||||
|
||||
global.TarinaiGroundUI = Object.freeze({
|
||||
bind: bindGroundUI,
|
||||
update: updateGroundUI,
|
||||
tip: groundTip,
|
||||
});
|
||||
global.bindGroundUI = bindGroundUI;
|
||||
})(window);
|
||||
Loading…
Add table
Add a link
Reference in a new issue