This commit is contained in:
2026-01-21 22:13:49 -07:00
parent ae7f57d3df
commit 7da834de0b
23 changed files with 885 additions and 132 deletions

20
protossbot/web/Cargo.toml Normal file
View File

@@ -0,0 +1,20 @@
[package]
name = "protoss-bot-web"
version = "0.1.0"
edition = "2021"
[dependencies]
leptos = { version = "0.6", features = ["csr"] }
leptos_axum = { version = "0.6" }
leptos_meta = { version = "0.6" }
leptos_router = { version = "0.6" }
axum = "0.7"
tokio = { version = "1", features = ["full"] }
tower = "0.4"
tower-http = { version = "0.5", features = ["fs"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
lazy_static = "1.4"
[lib]
crate-type = ["cdylib", "rlib"]

View File

@@ -0,0 +1,20 @@
# Leptos configuration file
[package]
name = "protoss-bot-web"
version = "0.1.0"
[leptos]
output-name = "protoss-bot-web"
site-root = "target/site"
site-pkg-dir = "pkg"
style-file = "style/main.css"
assets-dir = "public"
site-addr = "127.0.0.1:3000"
reload-port = 3001
browserquery = "defaults"
watch = false
env = "DEV"
bin-features = ["ssr"]
bin-default-features = false
lib-features = ["hydrate"]
lib-default-features = false

32
protossbot/web/README.md Normal file
View File

@@ -0,0 +1,32 @@
# Protoss Bot Web Control Panel
A Leptos web interface to control the Protoss bot in real-time.
## Setup
1. Install cargo-leptos:
```bash
cargo install cargo-leptos
```
2. Run the development server:
```bash
cd web
cargo leptos watch
```
3. Open your browser to `http://localhost:3000`
## Features
- **Game Speed Control**: Set the desired game speed with convenient buttons
- Real-time updates via server functions
- Dark theme matching StarCraft aesthetics
## Integration with Bot
The web server exposes a global `GAME_SPEED` variable that can be read by the bot. To integrate:
1. Add the web crate as a dependency in your bot's `Cargo.toml`
2. Read the speed value: `protoss_bot_web::GAME_SPEED.read().unwrap()`
3. Apply it to the game using BWAPI's setLocalSpeed() or setFrameSkip()

66
protossbot/web/src/lib.rs Normal file
View File

@@ -0,0 +1,66 @@
use leptos::*;
use leptos_meta::*;
use leptos_router::*;
use std::sync::{Arc, RwLock};
// Global static for game speed (shared with the bot)
lazy_static::lazy_static! {
pub static ref GAME_SPEED: Arc<RwLock<i32>> = Arc::new(RwLock::new(20));
}
#[component]
pub fn App() -> impl IntoView {
provide_meta_context();
view! {
<Stylesheet id="leptos" href="/pkg/protoss-bot-web.css"/>
<Title text="Protoss Bot Control"/>
<Router>
<main>
<Routes>
<Route path="" view=HomePage/>
</Routes>
</main>
</Router>
}
}
#[component]
fn HomePage() -> impl IntoView {
let (game_speed, set_game_speed) = create_signal(20);
let set_speed = move |speed: i32| {
set_game_speed.set(speed);
spawn_local(async move {
let _ = set_game_speed_server(speed).await;
});
};
view! {
<div class="container">
<h1>"Protoss Bot Control Panel"</h1>
<div class="speed-control">
<h2>"Game Speed Control"</h2>
<p>"Current Speed: " {game_speed}</p>
<div class="button-group">
<button on:click=move |_| set_speed(0)>"Slowest (0)"</button>
<button on:click=move |_| set_speed(10)>"Slower (10)"</button>
<button on:click=move |_| set_speed(20)>"Normal (20)"</button>
<button on:click=move |_| set_speed(30)>"Fast (30)"</button>
<button on:click=move |_| set_speed(42)>"Fastest (42)"</button>
</div>
</div>
</div>
}
}
#[server(SetGameSpeed, "/api")]
pub async fn set_game_speed_server(speed: i32) -> Result<(), ServerFnError> {
if let Ok(mut game_speed) = GAME_SPEED.write() {
*game_speed = speed;
println!("Game speed set to: {}", speed);
}
Ok(())
}

View File

@@ -0,0 +1,27 @@
use axum::{
routing::get,
Router,
};
use leptos::*;
use leptos_axum::{generate_route_list, LeptosRoutes};
use protoss_bot_web::App;
use tower_http::services::ServeDir;
#[tokio::main]
async fn main() {
let conf = get_configuration(None).await.unwrap();
let leptos_options = conf.leptos_options;
let addr = leptos_options.site_addr;
let routes = generate_route_list(App);
let app = Router::new()
.leptos_routes(&leptos_options, routes, App)
.fallback(leptos_axum::file_and_error_handler(App))
.with_state(leptos_options);
println!("Listening on http://{}", &addr);
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
axum::serve(listener, app.into_make_service())
.await
.unwrap();
}

View File

@@ -0,0 +1,62 @@
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
margin: 0;
padding: 20px;
background-color: #1a1a1a;
color: #ffffff;
}
.container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
h1 {
color: #4a9eff;
margin-bottom: 30px;
}
h2 {
color: #ffffff;
margin-bottom: 15px;
}
.speed-control {
background-color: #2a2a2a;
padding: 20px;
border-radius: 8px;
margin-bottom: 20px;
}
.button-group {
display: flex;
gap: 10px;
flex-wrap: wrap;
margin-top: 15px;
}
button {
background-color: #4a9eff;
color: white;
border: none;
padding: 12px 24px;
border-radius: 6px;
cursor: pointer;
font-size: 14px;
font-weight: 500;
transition: background-color 0.2s;
}
button:hover {
background-color: #357abd;
}
button:active {
background-color: #2a5f9a;
}
p {
color: #cccccc;
margin: 10px 0;
}