real messages from backend to frontend
This commit is contained in:
@@ -1,220 +1,345 @@
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Protoss Bot - Game Speed Control</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Protoss Bot - Game Speed Control</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 20px;
|
||||
}
|
||||
body {
|
||||
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
|
||||
background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.container {
|
||||
background: #1e1e1e;
|
||||
border: 2px solid #d4af37;
|
||||
border-radius: 20px;
|
||||
box-shadow: 0 20px 60px rgba(212, 175, 55, 0.3);
|
||||
padding: 40px;
|
||||
max-width: 500px;
|
||||
width: 100%;
|
||||
}
|
||||
.container {
|
||||
background: #1e1e1e;
|
||||
border: 2px solid #d4af37;
|
||||
border-radius: 20px;
|
||||
box-shadow: 0 20px 60px rgba(212, 175, 55, 0.3);
|
||||
padding: 40px;
|
||||
max-width: 500px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #d4af37;
|
||||
margin-bottom: 30px;
|
||||
font-size: 28px;
|
||||
text-align: center;
|
||||
}
|
||||
h1 {
|
||||
color: #d4af37;
|
||||
margin-bottom: 30px;
|
||||
font-size: 28px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.control-group {
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
.control-group {
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
color: #d4af37;
|
||||
font-weight: 600;
|
||||
margin-bottom: 10px;
|
||||
font-size: 14px;
|
||||
}
|
||||
label {
|
||||
display: block;
|
||||
color: #d4af37;
|
||||
font-weight: 600;
|
||||
margin-bottom: 10px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.speed-display {
|
||||
text-align: center;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.speed-display {
|
||||
text-align: center;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.speed-value {
|
||||
font-size: 48px;
|
||||
font-weight: bold;
|
||||
color: #d4af37;
|
||||
display: block;
|
||||
}
|
||||
.speed-value {
|
||||
font-size: 48px;
|
||||
font-weight: bold;
|
||||
color: #d4af37;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.speed-label {
|
||||
color: #999;
|
||||
font-size: 12px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
.speed-label {
|
||||
color: #999;
|
||||
font-size: 12px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
|
||||
.preset-buttons {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
gap: 10px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.preset-buttons {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
gap: 10px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
button {
|
||||
padding: 20px 12px;
|
||||
border: 2px solid #d4af37;
|
||||
border-radius: 8px;
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
background: #2d2d2d;
|
||||
color: #d4af37;
|
||||
}
|
||||
button {
|
||||
padding: 20px 12px;
|
||||
border: 2px solid #d4af37;
|
||||
border-radius: 8px;
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
background: #2d2d2d;
|
||||
color: #d4af37;
|
||||
}
|
||||
|
||||
button small {
|
||||
display: block;
|
||||
font-size: 11px;
|
||||
font-weight: normal;
|
||||
margin-top: 4px;
|
||||
opacity: 0.7;
|
||||
}
|
||||
button small {
|
||||
display: block;
|
||||
font-size: 11px;
|
||||
font-weight: normal;
|
||||
margin-top: 4px;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background: #d4af37;
|
||||
color: #1e1e1e;
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 12px rgba(212, 175, 55, 0.4);
|
||||
}
|
||||
button:hover {
|
||||
background: #d4af37;
|
||||
color: #1e1e1e;
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 12px rgba(212, 175, 55, 0.4);
|
||||
}
|
||||
|
||||
button:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
button:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.status {
|
||||
padding: 12px;
|
||||
border-radius: 8px;
|
||||
text-align: center;
|
||||
font-size: 13px;
|
||||
margin-top: 20px;
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s ease;
|
||||
}
|
||||
.status {
|
||||
padding: 12px;
|
||||
border-radius: 8px;
|
||||
text-align: center;
|
||||
font-size: 13px;
|
||||
margin-top: 20px;
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s ease;
|
||||
}
|
||||
|
||||
.status.visible {
|
||||
opacity: 1;
|
||||
}
|
||||
.status.visible {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.status.success {
|
||||
background: rgba(34, 197, 94, 0.2);
|
||||
color: #4ade80;
|
||||
border: 1px solid #22c55e;
|
||||
}
|
||||
.status.success {
|
||||
background: rgba(34, 197, 94, 0.2);
|
||||
color: #4ade80;
|
||||
border: 1px solid #22c55e;
|
||||
}
|
||||
|
||||
.status.error {
|
||||
background: rgba(239, 68, 68, 0.2);
|
||||
color: #f87171;
|
||||
border: 1px solid #ef4444;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>⚡ Game Speed Control</h1>
|
||||
.status.error {
|
||||
background: rgba(239, 68, 68, 0.2);
|
||||
color: #f87171;
|
||||
border: 1px solid #ef4444;
|
||||
}
|
||||
|
||||
<div class="speed-display">
|
||||
<span class="speed-value" id="currentSpeed">42</span>
|
||||
<span class="speed-label">Current Speed</span>
|
||||
</div>
|
||||
.build-status-section {
|
||||
margin-top: 30px;
|
||||
padding-top: 30px;
|
||||
border-top: 2px solid #333;
|
||||
}
|
||||
|
||||
<div class="control-group">
|
||||
<label>Select Speed</label>
|
||||
<div class="preset-buttons">
|
||||
<button onclick="setSpeed(42)">42<br><small>Slowest</small></button>
|
||||
<button onclick="setSpeed(1)">1<br><small>Fast</small></button>
|
||||
<button onclick="setSpeed(0)">0<br><small>Fastest</small></button>
|
||||
<button onclick="setSpeed(-1)">-1<br><small>Max</small></button>
|
||||
.build-status-section h2 {
|
||||
color: #d4af37;
|
||||
font-size: 20px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.stage-info {
|
||||
background: #2d2d2d;
|
||||
padding: 15px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 15px;
|
||||
border: 1px solid #444;
|
||||
}
|
||||
|
||||
.stage-name {
|
||||
color: #d4af37;
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.build-items {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.build-item {
|
||||
padding: 8px 10px;
|
||||
margin: 5px 0;
|
||||
background: #1e1e1e;
|
||||
border-radius: 4px;
|
||||
border-left: 3px solid #d4af37;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.build-item.ready {
|
||||
border-left-color: #22c55e;
|
||||
}
|
||||
|
||||
.build-item.complete {
|
||||
border-left-color: #3b82f6;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.build-item.waiting {
|
||||
border-left-color: #f59e0b;
|
||||
}
|
||||
|
||||
.unit-name {
|
||||
color: #d4af37;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.unit-status {
|
||||
color: #999;
|
||||
font-size: 13px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>⚡ Game Speed Control</h1>
|
||||
|
||||
<div class="speed-display">
|
||||
<span class="speed-value" id="currentSpeed">42</span>
|
||||
<span class="speed-label">Current Speed</span>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label>Select Speed</label>
|
||||
<div class="preset-buttons">
|
||||
<button onclick="setSpeed(42)">42<br /><small>Slowest</small></button>
|
||||
<button onclick="setSpeed(1)">1<br /><small>Fast</small></button>
|
||||
<button onclick="setSpeed(0)">0<br /><small>Fastest</small></button>
|
||||
<button onclick="setSpeed(-1)">-1<br /><small>Max</small></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="status" class="status"></div>
|
||||
|
||||
<div class="build-status-section">
|
||||
<h2>📋 Build Status</h2>
|
||||
<div class="stage-info">
|
||||
<div class="stage-name" id="stageName">Loading...</div>
|
||||
<ul class="build-items" id="buildItems">
|
||||
<li class="build-item">Connecting to bot...</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="status" class="status"></div>
|
||||
</div>
|
||||
<script id="game-speed-script">
|
||||
const currentSpeedDisplay = document.getElementById("currentSpeed");
|
||||
const statusDiv = document.getElementById("status");
|
||||
|
||||
<script>
|
||||
const currentSpeedDisplay = document.getElementById('currentSpeed');
|
||||
const statusDiv = document.getElementById('status');
|
||||
|
||||
// Fetch current speed on load
|
||||
async function fetchCurrentSpeed() {
|
||||
try {
|
||||
const response = await fetch('http://127.0.0.1:3333/api/speed');
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
updateSpeedDisplay(data.speed);
|
||||
async function fetchCurrentSpeed() {
|
||||
try {
|
||||
const response = await fetch("http://127.0.0.1:3333/api/speed");
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
updateSpeedDisplay(data.speed);
|
||||
}
|
||||
} catch (error) {
|
||||
showStatus("Unable to connect to bot", "error");
|
||||
}
|
||||
} catch (error) {
|
||||
showStatus('Unable to connect to bot', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// Update speed display
|
||||
function updateSpeedDisplay(speed) {
|
||||
currentSpeedDisplay.textContent = speed;
|
||||
}
|
||||
function updateSpeedDisplay(speed) {
|
||||
currentSpeedDisplay.textContent = speed;
|
||||
}
|
||||
|
||||
// Set speed via API
|
||||
async function setSpeed(speed) {
|
||||
try {
|
||||
const response = await fetch('http://127.0.0.1:3333/api/speed', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ speed: speed }),
|
||||
});
|
||||
async function setSpeed(speed) {
|
||||
try {
|
||||
const response = await fetch("http://127.0.0.1:3333/api/speed", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ speed: speed }),
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
updateSpeedDisplay(data.speed);
|
||||
showStatus(`Speed set to ${data.speed}`, 'success');
|
||||
} else {
|
||||
showStatus('Failed to update speed', 'error');
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
updateSpeedDisplay(data.speed);
|
||||
showStatus(`Speed set to ${data.speed}`, "success");
|
||||
} else {
|
||||
showStatus("Failed to update speed", "error");
|
||||
}
|
||||
} catch (error) {
|
||||
showStatus("Connection error", "error");
|
||||
}
|
||||
} catch (error) {
|
||||
showStatus('Connection error', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// Show status message
|
||||
function showStatus(message, type) {
|
||||
statusDiv.textContent = message;
|
||||
statusDiv.className = `status ${type} visible`;
|
||||
setTimeout(() => {
|
||||
statusDiv.classList.remove('visible');
|
||||
}, 3000);
|
||||
}
|
||||
function showStatus(message, type) {
|
||||
statusDiv.textContent = message;
|
||||
statusDiv.className = `status ${type} visible`;
|
||||
setTimeout(() => {
|
||||
statusDiv.classList.remove("visible");
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
// Fetch current speed on page load
|
||||
fetchCurrentSpeed();
|
||||
fetchCurrentSpeed();
|
||||
setInterval(fetchCurrentSpeed, 1000);
|
||||
</script>
|
||||
|
||||
// Poll for speed changes every 2 seconds
|
||||
setInterval(fetchCurrentSpeed, 2000);
|
||||
</script>
|
||||
</body>
|
||||
<script id="build-status-script">
|
||||
const stageNameEl = document.getElementById("stageName");
|
||||
const buildItemsEl = document.getElementById("buildItems");
|
||||
|
||||
async function fetchBuildStatus() {
|
||||
try {
|
||||
const response = await fetch(
|
||||
"http://127.0.0.1:3333/api/build-status",
|
||||
);
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
updateBuildStatus(data);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch build status:", error);
|
||||
}
|
||||
}
|
||||
|
||||
function updateBuildStatus(data) {
|
||||
stageNameEl.textContent = `Stage ${data.stage_index + 1}: ${data.stage_name}`;
|
||||
|
||||
if (data.items.length === 0) {
|
||||
buildItemsEl.innerHTML =
|
||||
'<li class="build-item">No build items in current stage</li>';
|
||||
return;
|
||||
}
|
||||
|
||||
// Sort items alphabetically by unit name
|
||||
const sortedItems = [...data.items].sort((a, b) =>
|
||||
a.unit_name.localeCompare(b.unit_name),
|
||||
);
|
||||
|
||||
buildItemsEl.innerHTML = sortedItems
|
||||
.map((item) => {
|
||||
let itemClass = "build-item";
|
||||
if (item.status.includes("Complete")) {
|
||||
itemClass += " complete";
|
||||
} else if (item.status.includes("Ready to build")) {
|
||||
itemClass += " ready";
|
||||
} else {
|
||||
itemClass += " waiting";
|
||||
}
|
||||
|
||||
return `
|
||||
<li class="${itemClass}">
|
||||
<span class="unit-name">${item.unit_name}</span>
|
||||
<span class="unit-status">${item.status}</span>
|
||||
</li>
|
||||
`;
|
||||
})
|
||||
.join("");
|
||||
}
|
||||
|
||||
fetchBuildStatus();
|
||||
setInterval(fetchBuildStatus, 1000);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user