Spaces:
Running
Running
Add accusation feature and update tool cost display in game interface
Browse files- app.py +13 -0
- ui/static/css/noir.css +13 -0
- ui/static/js/game_logic.js +72 -0
- ui/templates/game_interface.html +4 -0
app.py
CHANGED
|
@@ -94,6 +94,16 @@ class GameSession:
|
|
| 94 |
tool_name = payload.get("tool")
|
| 95 |
arg = payload.get("input") # Default for single-input tools
|
| 96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
kwargs = {}
|
| 98 |
if tool_name == "get_location":
|
| 99 |
kwargs = {"phone_number": arg}
|
|
@@ -123,6 +133,9 @@ class GameSession:
|
|
| 123 |
# Format the result nicely
|
| 124 |
evidence_data = format_tool_response(tool_name, arg, result, self.game.scenario)
|
| 125 |
|
|
|
|
|
|
|
|
|
|
| 126 |
return {
|
| 127 |
"action": "add_evidence",
|
| 128 |
"data": evidence_data
|
|
|
|
| 94 |
tool_name = payload.get("tool")
|
| 95 |
arg = payload.get("input") # Default for single-input tools
|
| 96 |
|
| 97 |
+
if tool_name == "accuse":
|
| 98 |
+
result_msg = self.game.make_accusation(payload.get("suspect_id"))
|
| 99 |
+
return {
|
| 100 |
+
"action": "game_over",
|
| 101 |
+
"data": {
|
| 102 |
+
"message": result_msg,
|
| 103 |
+
"verdict": self.game.verdict_correct
|
| 104 |
+
}
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
kwargs = {}
|
| 108 |
if tool_name == "get_location":
|
| 109 |
kwargs = {"phone_number": arg}
|
|
|
|
| 133 |
# Format the result nicely
|
| 134 |
evidence_data = format_tool_response(tool_name, arg, result, self.game.scenario)
|
| 135 |
|
| 136 |
+
# Include updated points in response
|
| 137 |
+
evidence_data["updated_points"] = self.game.points
|
| 138 |
+
|
| 139 |
return {
|
| 140 |
"action": "add_evidence",
|
| 141 |
"data": evidence_data
|
ui/static/css/noir.css
CHANGED
|
@@ -284,6 +284,19 @@ body, html {
|
|
| 284 |
font-size: 1.5rem;
|
| 285 |
}
|
| 286 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
/* --- Bottom Panel: Chat / Log --- */
|
| 288 |
#chat-panel {
|
| 289 |
grid-column: 1 / -1;
|
|
|
|
| 284 |
font-size: 1.5rem;
|
| 285 |
}
|
| 286 |
|
| 287 |
+
.tool-cost {
|
| 288 |
+
font-size: 0.7rem;
|
| 289 |
+
color: #888;
|
| 290 |
+
margin-top: 2px;
|
| 291 |
+
border-top: 1px solid #444;
|
| 292 |
+
padding-top: 2px;
|
| 293 |
+
width: 100%;
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
.tool-btn:hover .tool-cost {
|
| 297 |
+
color: #aaa;
|
| 298 |
+
}
|
| 299 |
+
|
| 300 |
/* --- Bottom Panel: Chat / Log --- */
|
| 301 |
#chat-panel {
|
| 302 |
grid-column: 1 / -1;
|
ui/static/js/game_logic.js
CHANGED
|
@@ -60,6 +60,9 @@ function handleServerMessage(message) {
|
|
| 60 |
addChatMessage(data.role, data.content, data.name);
|
| 61 |
break;
|
| 62 |
case 'add_evidence':
|
|
|
|
|
|
|
|
|
|
| 63 |
addEvidenceToBoard(data);
|
| 64 |
break;
|
| 65 |
case 'tool_error':
|
|
@@ -114,6 +117,55 @@ function renderCaseFile(scenario) {
|
|
| 114 |
}, 20, 20);
|
| 115 |
}
|
| 116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
// --- UI Rendering: Suspects ---
|
| 118 |
|
| 119 |
function renderSuspects() {
|
|
@@ -375,6 +427,15 @@ function useTool(toolName) {
|
|
| 375 |
promptText.innerText = "Enter Evidence ID:";
|
| 376 |
} else if (toolName === 'get_footage') {
|
| 377 |
promptText.innerText = "Enter Camera Location:";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 378 |
}
|
| 379 |
|
| 380 |
modal.classList.add('active');
|
|
@@ -404,6 +465,16 @@ function submitTool() {
|
|
| 404 |
showModalError("Both fields are required.");
|
| 405 |
return;
|
| 406 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 407 |
} else {
|
| 408 |
if (value) {
|
| 409 |
payload = { tool: pendingTool, input: value };
|
|
@@ -470,6 +541,7 @@ document.getElementById('tool-map').onclick = () => useTool('get_location');
|
|
| 470 |
document.getElementById('tool-camera').onclick = () => useTool('get_footage');
|
| 471 |
document.getElementById('tool-phone').onclick = () => useTool('call_alibi');
|
| 472 |
document.getElementById('tool-dna').onclick = () => useTool('get_dna_test');
|
|
|
|
| 473 |
|
| 474 |
// Notify Parent that we are ready (Retry loop)
|
| 475 |
console.log("π‘ Attempting to connect to game server...");
|
|
|
|
| 60 |
addChatMessage(data.role, data.content, data.name);
|
| 61 |
break;
|
| 62 |
case 'add_evidence':
|
| 63 |
+
if (data.updated_points !== undefined) {
|
| 64 |
+
document.getElementById('points-display').innerText = data.updated_points;
|
| 65 |
+
}
|
| 66 |
addEvidenceToBoard(data);
|
| 67 |
break;
|
| 68 |
case 'tool_error':
|
|
|
|
| 117 |
}, 20, 20);
|
| 118 |
}
|
| 119 |
|
| 120 |
+
function triggerGameOver(data) {
|
| 121 |
+
const overlay = document.createElement('div');
|
| 122 |
+
overlay.id = 'game-over-overlay';
|
| 123 |
+
overlay.style.position = 'fixed';
|
| 124 |
+
overlay.style.top = '0';
|
| 125 |
+
overlay.style.left = '0';
|
| 126 |
+
overlay.style.width = '100%';
|
| 127 |
+
overlay.style.height = '100%';
|
| 128 |
+
overlay.style.backgroundColor = 'rgba(0,0,0,0.9)';
|
| 129 |
+
overlay.style.color = 'white';
|
| 130 |
+
overlay.style.display = 'flex';
|
| 131 |
+
overlay.style.flexDirection = 'column';
|
| 132 |
+
overlay.style.alignItems = 'center';
|
| 133 |
+
overlay.style.justifyContent = 'center';
|
| 134 |
+
overlay.style.zIndex = '1000';
|
| 135 |
+
overlay.style.fontFamily = "'Special Elite', cursive";
|
| 136 |
+
|
| 137 |
+
const title = document.createElement('div');
|
| 138 |
+
title.style.fontSize = '3rem';
|
| 139 |
+
title.style.marginBottom = '20px';
|
| 140 |
+
|
| 141 |
+
if (data.verdict) {
|
| 142 |
+
title.innerText = "CASE SOLVED";
|
| 143 |
+
title.style.color = "#4caf50";
|
| 144 |
+
} else {
|
| 145 |
+
title.innerText = "WRONG ACCUSATION";
|
| 146 |
+
title.style.color = "#f44336";
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
const msg = document.createElement('div');
|
| 150 |
+
msg.innerText = data.message;
|
| 151 |
+
msg.style.fontSize = '1.5rem';
|
| 152 |
+
msg.style.maxWidth = '600px';
|
| 153 |
+
msg.style.textAlign = 'center';
|
| 154 |
+
msg.style.marginBottom = '40px';
|
| 155 |
+
|
| 156 |
+
const btn = document.createElement('button');
|
| 157 |
+
btn.innerText = "PLAY AGAIN";
|
| 158 |
+
btn.className = "modal-btn confirm";
|
| 159 |
+
btn.style.fontSize = "1.5rem";
|
| 160 |
+
btn.onclick = () => location.reload();
|
| 161 |
+
|
| 162 |
+
overlay.appendChild(title);
|
| 163 |
+
overlay.appendChild(msg);
|
| 164 |
+
overlay.appendChild(btn);
|
| 165 |
+
|
| 166 |
+
document.body.appendChild(overlay);
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
// --- UI Rendering: Suspects ---
|
| 170 |
|
| 171 |
function renderSuspects() {
|
|
|
|
| 427 |
promptText.innerText = "Enter Evidence ID:";
|
| 428 |
} else if (toolName === 'get_footage') {
|
| 429 |
promptText.innerText = "Enter Camera Location:";
|
| 430 |
+
} else if (toolName === 'accuse') {
|
| 431 |
+
if (!gameState.currentSuspect) {
|
| 432 |
+
showNotification("β οΈ Select a suspect to accuse!");
|
| 433 |
+
closeModal();
|
| 434 |
+
return;
|
| 435 |
+
}
|
| 436 |
+
const suspect = gameState.scenario.suspects.find(s => s.id === gameState.currentSuspect);
|
| 437 |
+
promptText.innerText = `ACCUSE ${suspect.name.toUpperCase()}?`;
|
| 438 |
+
input.placeholder = "Type 'GUILTY' to confirm";
|
| 439 |
}
|
| 440 |
|
| 441 |
modal.classList.add('active');
|
|
|
|
| 465 |
showModalError("Both fields are required.");
|
| 466 |
return;
|
| 467 |
}
|
| 468 |
+
} else if (pendingTool === 'accuse') {
|
| 469 |
+
if (value.toUpperCase() === 'GUILTY') {
|
| 470 |
+
payload = {
|
| 471 |
+
tool: 'accuse',
|
| 472 |
+
suspect_id: gameState.currentSuspect
|
| 473 |
+
};
|
| 474 |
+
} else {
|
| 475 |
+
showModalError("Type 'GUILTY' to confirm accusation.");
|
| 476 |
+
return;
|
| 477 |
+
}
|
| 478 |
} else {
|
| 479 |
if (value) {
|
| 480 |
payload = { tool: pendingTool, input: value };
|
|
|
|
| 541 |
document.getElementById('tool-camera').onclick = () => useTool('get_footage');
|
| 542 |
document.getElementById('tool-phone').onclick = () => useTool('call_alibi');
|
| 543 |
document.getElementById('tool-dna').onclick = () => useTool('get_dna_test');
|
| 544 |
+
document.getElementById('tool-accuse').onclick = () => useTool('accuse');
|
| 545 |
|
| 546 |
// Notify Parent that we are ready (Retry loop)
|
| 547 |
console.log("π‘ Attempting to connect to game server...");
|
ui/templates/game_interface.html
CHANGED
|
@@ -42,18 +42,22 @@
|
|
| 42 |
<div class="tool-btn" id="tool-map">
|
| 43 |
<span class="tool-icon">πΊοΈ</span>
|
| 44 |
<span>Location</span>
|
|
|
|
| 45 |
</div>
|
| 46 |
<div class="tool-btn" id="tool-camera">
|
| 47 |
<span class="tool-icon">πΉ</span>
|
| 48 |
<span>Footage</span>
|
|
|
|
| 49 |
</div>
|
| 50 |
<div class="tool-btn" id="tool-phone">
|
| 51 |
<span class="tool-icon">π</span>
|
| 52 |
<span>Call Alibi</span>
|
|
|
|
| 53 |
</div>
|
| 54 |
<div class="tool-btn" id="tool-dna">
|
| 55 |
<span class="tool-icon">π¬</span>
|
| 56 |
<span>DNA Test</span>
|
|
|
|
| 57 |
</div>
|
| 58 |
<div class="tool-btn" id="tool-accuse" style="margin-top: auto; border-color: red; color: red;">
|
| 59 |
<span class="tool-icon">βοΈ</span>
|
|
|
|
| 42 |
<div class="tool-btn" id="tool-map">
|
| 43 |
<span class="tool-icon">πΊοΈ</span>
|
| 44 |
<span>Location</span>
|
| 45 |
+
<span class="tool-cost">2 pts</span>
|
| 46 |
</div>
|
| 47 |
<div class="tool-btn" id="tool-camera">
|
| 48 |
<span class="tool-icon">πΉ</span>
|
| 49 |
<span>Footage</span>
|
| 50 |
+
<span class="tool-cost">2 pts</span>
|
| 51 |
</div>
|
| 52 |
<div class="tool-btn" id="tool-phone">
|
| 53 |
<span class="tool-icon">π</span>
|
| 54 |
<span>Call Alibi</span>
|
| 55 |
+
<span class="tool-cost">1 pt</span>
|
| 56 |
</div>
|
| 57 |
<div class="tool-btn" id="tool-dna">
|
| 58 |
<span class="tool-icon">π¬</span>
|
| 59 |
<span>DNA Test</span>
|
| 60 |
+
<span class="tool-cost">3 pts</span>
|
| 61 |
</div>
|
| 62 |
<div class="tool-btn" id="tool-accuse" style="margin-top: auto; border-color: red; color: red;">
|
| 63 |
<span class="tool-icon">βοΈ</span>
|