Spaces:
Running
Running
Upload 7 files
Browse files- game_logic.js +33 -25
- index.html +21 -3
game_logic.js
CHANGED
@@ -176,31 +176,39 @@ async function submitAdvice(adviceText) {
|
|
176 |
}
|
177 |
|
178 |
function fetchGameState() {
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
}
|
203 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
204 |
// Event listeners
|
205 |
let isProcessing = false;
|
206 |
|
|
|
176 |
}
|
177 |
|
178 |
function fetchGameState() {
|
179 |
+
const formData = new FormData();
|
180 |
+
formData.append('player_name', playerName);
|
181 |
+
|
182 |
+
fetch('https://lemot.online/player/play/', {
|
183 |
+
method: 'POST',
|
184 |
+
body: formData
|
185 |
+
})
|
186 |
+
.then(res => res.json())
|
187 |
+
.then(data => {
|
188 |
+
if (data.error) {
|
189 |
+
statusEl.textContent = data.message;
|
190 |
+
statusEl.classList.add('text-red-600');
|
191 |
+
addStreamMessage(data.message, 'system');
|
192 |
+
} else {
|
193 |
+
statusEl.classList.remove('text-red-600');
|
194 |
+
updateGameState(data);
|
195 |
+
|
196 |
+
// Process current messages from the game session
|
197 |
+
if (data.current_messages && Array.isArray(data.current_messages)) {
|
198 |
+
data.current_messages.forEach(message => {
|
199 |
+
const formattedMessage = `${message.player_name}: "${message.guess_text}" - Score: ${message.similarity_score}/10`;
|
200 |
+
addStreamMessage(formattedMessage, 'player');
|
201 |
+
});
|
202 |
+
}
|
203 |
+
}
|
204 |
+
})
|
205 |
+
.catch(err => {
|
206 |
+
console.error(err);
|
207 |
+
statusEl.textContent = "Error fetching game state.";
|
208 |
+
addStreamMessage("Error fetching game state", 'system');
|
209 |
+
});
|
210 |
+
}
|
211 |
+
|
212 |
// Event listeners
|
213 |
let isProcessing = false;
|
214 |
|
index.html
CHANGED
@@ -78,7 +78,8 @@
|
|
78 |
</div>
|
79 |
|
80 |
<!-- Dev Interface (Bottom Left) -->
|
81 |
-
|
|
|
82 |
<div id="status" class="text-xs mb-2"></div>
|
83 |
<div id="timer" class="text-sm font-bold mb-2"></div>
|
84 |
<div id="game-info" class="text-xs"></div>
|
@@ -110,6 +111,23 @@
|
|
110 |
<script src="./personality_allocation.js"></script>
|
111 |
<script src="./populate_interface.js"></script>
|
112 |
|
113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
</body>
|
115 |
-
</html>
|
|
|
78 |
</div>
|
79 |
|
80 |
<!-- Dev Interface (Bottom Left) -->
|
81 |
+
|
82 |
+
<div id="dev_dbug"class="fixed bottom-4 left-4 w-64 bg-white shadow-lg rounded-lg p-4 text-sm">
|
83 |
<div id="status" class="text-xs mb-2"></div>
|
84 |
<div id="timer" class="text-sm font-bold mb-2"></div>
|
85 |
<div id="game-info" class="text-xs"></div>
|
|
|
111 |
<script src="./personality_allocation.js"></script>
|
112 |
<script src="./populate_interface.js"></script>
|
113 |
|
114 |
+
|
115 |
+
<script>
|
116 |
+
const toggleBtn = document.createElement('button');
|
117 |
+
toggleBtn.innerHTML = 'ποΈ';
|
118 |
+
toggleBtn.style.cssText = 'position: fixed; bottom: 16px; left: 16px; background: #1f2937; border: none; border-radius: 50%; padding: 8px; cursor: pointer; color: white;';
|
119 |
+
|
120 |
+
let isVisible = true;
|
121 |
+
toggleBtn.onclick = () => {
|
122 |
+
const debugEl = document.getElementById('dev_dbug');
|
123 |
+
if (debugEl) {
|
124 |
+
isVisible = !isVisible;
|
125 |
+
debugEl.style.opacity = isVisible ? '1' : '0';
|
126 |
+
toggleBtn.innerHTML = isVisible ? 'ποΈ' : 'ποΈβπ¨οΈ';
|
127 |
+
}
|
128 |
+
};
|
129 |
+
|
130 |
+
document.body.appendChild(toggleBtn);
|
131 |
+
</script>
|
132 |
</body>
|
133 |
+
</html>
|