Fix empty combat view on load and null state crash
Game div now starts hidden so map screen is the first thing visible. Combat event handlers guard against null state.
This commit is contained in:
parent
8ae3252a9c
commit
90c2aca72e
4 changed files with 27 additions and 1 deletions
|
|
@ -7,7 +7,7 @@
|
||||||
<link rel="stylesheet" href="style.css">
|
<link rel="stylesheet" href="style.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="game">
|
<div id="game" hidden>
|
||||||
<section id="enemy-zone">
|
<section id="enemy-zone">
|
||||||
<div id="enemy-info">
|
<div id="enemy-info">
|
||||||
<span id="enemy-name"></span>
|
<span id="enemy-name"></span>
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,7 @@ function checkEnd() {
|
||||||
function bindEvents() {
|
function bindEvents() {
|
||||||
document.getElementById("hand").addEventListener("click", (e) => {
|
document.getElementById("hand").addEventListener("click", (e) => {
|
||||||
const cardEl = e.target.closest(".card");
|
const cardEl = e.target.closest(".card");
|
||||||
|
if (!state) return;
|
||||||
if (!cardEl || state.combat.phase !== "player_turn") return;
|
if (!cardEl || state.combat.phase !== "player_turn") return;
|
||||||
const index = Number(cardEl.dataset.index);
|
const index = Number(cardEl.dataset.index);
|
||||||
|
|
||||||
|
|
@ -142,6 +143,7 @@ function bindEvents() {
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById("enemy-zone").addEventListener("click", () => {
|
document.getElementById("enemy-zone").addEventListener("click", () => {
|
||||||
|
if (!state) return;
|
||||||
if (state.combat.selectedCard === null) return;
|
if (state.combat.selectedCard === null) return;
|
||||||
if (state.combat.phase !== "player_turn") return;
|
if (state.combat.phase !== "player_turn") return;
|
||||||
|
|
||||||
|
|
@ -159,6 +161,7 @@ function bindEvents() {
|
||||||
document
|
document
|
||||||
.getElementById("end-turn-btn")
|
.getElementById("end-turn-btn")
|
||||||
.addEventListener("click", async () => {
|
.addEventListener("click", async () => {
|
||||||
|
if (!state) return;
|
||||||
if (state.combat.phase !== "player_turn") return;
|
if (state.combat.phase !== "player_turn") return;
|
||||||
|
|
||||||
state = endTurn(state);
|
state = endTurn(state);
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ function formatIntent(action, enemy) {
|
||||||
if (e.type === "strength") return `str +${e.value}`;
|
if (e.type === "strength") return `str +${e.value}`;
|
||||||
return e.type;
|
return e.type;
|
||||||
});
|
});
|
||||||
|
if (parts.length === 0) return "zzz";
|
||||||
return parts.join(", ");
|
return parts.join(", ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
22
style.css
22
style.css
|
|
@ -12,6 +12,10 @@
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#game[hidden] {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
#enemy-zone {
|
#enemy-zone {
|
||||||
flex: 4;
|
flex: 4;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|
@ -56,8 +60,10 @@
|
||||||
inset: 0;
|
inset: 0;
|
||||||
background: rgba(0, 0, 0, 0.7);
|
background: rgba(0, 0, 0, 0.7);
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
gap: 16px;
|
||||||
color: white;
|
color: white;
|
||||||
font-size: 2rem;
|
font-size: 2rem;
|
||||||
}
|
}
|
||||||
|
|
@ -65,3 +71,19 @@
|
||||||
#overlay[hidden] {
|
#overlay[hidden] {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#reward-cards {
|
||||||
|
display: flex;
|
||||||
|
gap: 12px;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
#reward-cards .reward-card {
|
||||||
|
width: 120px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: transform 0.15s;
|
||||||
|
}
|
||||||
|
|
||||||
|
#reward-cards .reward-card:hover {
|
||||||
|
transform: scale(1.1);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue