updates
This commit is contained in:
@@ -11,11 +11,15 @@ fn main() {
|
|||||||
|
|
||||||
let game_state = Arc::new(Mutex::new(GameState::default()));
|
let game_state = Arc::new(Mutex::new(GameState::default()));
|
||||||
|
|
||||||
// // Start the webserver in a separate thread
|
// Start the webserver in a separate thread
|
||||||
// std::thread::spawn(|| {
|
std::thread::spawn(|| {
|
||||||
// let rt = tokio::runtime::Runtime::new().unwrap();
|
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||||
// rt.block_on(start_webserver());
|
rt.block_on(async {
|
||||||
// });
|
start_webserver().await;
|
||||||
|
// Keep the runtime alive indefinitely to prevent TLS cleanup issues
|
||||||
|
std::future::pending::<()>().await;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
rsbwapi::start(move |_game| ProtosBot::new(game_state.clone()));
|
rsbwapi::start(move |_game| ProtosBot::new(game_state.clone()));
|
||||||
}
|
}
|
||||||
@@ -25,19 +29,40 @@ async fn start_webserver() {
|
|||||||
use leptos::*;
|
use leptos::*;
|
||||||
use leptos_axum::{generate_route_list, LeptosRoutes};
|
use leptos_axum::{generate_route_list, LeptosRoutes};
|
||||||
use protoss_bot_web::App;
|
use protoss_bot_web::App;
|
||||||
|
use tower_http::services::ServeDir;
|
||||||
|
|
||||||
let conf = get_configuration(None).await.unwrap();
|
let leptos_options = LeptosOptions {
|
||||||
let leptos_options = conf.leptos_options;
|
output_name: "protoss-bot-web".to_string(),
|
||||||
|
site_root: "target/site".to_string(),
|
||||||
|
site_pkg_dir: "pkg".to_string(),
|
||||||
|
env: leptos_config::Env::DEV,
|
||||||
|
site_addr: "127.0.0.1:3333".parse().unwrap(),
|
||||||
|
reload_port: 3001,
|
||||||
|
hash_file: "".to_string(),
|
||||||
|
hash_files: false,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
let addr = leptos_options.site_addr;
|
let addr = leptos_options.site_addr;
|
||||||
let routes = generate_route_list(App);
|
let routes = generate_route_list(App);
|
||||||
|
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.leptos_routes(&leptos_options, routes, App)
|
.leptos_routes(&leptos_options, routes, App)
|
||||||
|
.nest_service("/pkg", ServeDir::new("web/style"))
|
||||||
.with_state(leptos_options);
|
.with_state(leptos_options);
|
||||||
|
|
||||||
println!("Web server listening on http://{}", &addr);
|
match tokio::net::TcpListener::bind(&addr).await {
|
||||||
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
|
Ok(listener) => {
|
||||||
axum::serve(listener, app.into_make_service())
|
println!("Web server listening on http://{}", &addr);
|
||||||
.await
|
if let Err(e) = axum::serve(listener, app.into_make_service()).await {
|
||||||
.unwrap();
|
eprintln!("Web server error: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!(
|
||||||
|
"Failed to bind to {}: {}. Is the port already in use?",
|
||||||
|
&addr, e
|
||||||
|
);
|
||||||
|
eprintln!("Skipping web server startup.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ version = "0.1.0"
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
leptos = { version = "0.6", features = ["csr"] }
|
leptos = { version = "0.6", default-features = false, features = ["ssr"] }
|
||||||
leptos_axum = { version = "0.6" }
|
leptos_axum = { version = "0.6", default-features = false }
|
||||||
leptos_meta = { version = "0.6" }
|
leptos_meta = { version = "0.6", default-features = false, features = ["ssr"] }
|
||||||
leptos_router = { version = "0.6" }
|
leptos_router = { version = "0.6", default-features = false, features = ["ssr"] }
|
||||||
axum = "0.7"
|
axum = "0.7"
|
||||||
tokio = { version = "1", features = ["full"] }
|
tokio = { version = "1", features = ["full"] }
|
||||||
tower = "0.4"
|
tower = "0.4"
|
||||||
@@ -16,5 +16,9 @@ serde = { version = "1", features = ["derive"] }
|
|||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
lazy_static = "1.4"
|
lazy_static = "1.4"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["ssr"]
|
||||||
|
ssr = ["leptos/ssr", "leptos_meta/ssr", "leptos_router/ssr"]
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["cdylib", "rlib"]
|
crate-type = ["cdylib", "rlib"]
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ site-root = "target/site"
|
|||||||
site-pkg-dir = "pkg"
|
site-pkg-dir = "pkg"
|
||||||
style-file = "style/main.css"
|
style-file = "style/main.css"
|
||||||
assets-dir = "public"
|
assets-dir = "public"
|
||||||
site-addr = "127.0.0.1:3000"
|
site-addr = "127.0.0.1:3001"
|
||||||
reload-port = 3001
|
reload-port = 3001
|
||||||
browserquery = "defaults"
|
browserquery = "defaults"
|
||||||
watch = false
|
watch = false
|
||||||
|
|||||||
@@ -10,57 +10,73 @@ lazy_static::lazy_static! {
|
|||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn App() -> impl IntoView {
|
pub fn App() -> impl IntoView {
|
||||||
provide_meta_context();
|
provide_meta_context();
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
<Stylesheet id="leptos" href="/pkg/protoss-bot-web.css"/>
|
<Stylesheet id="leptos" href="/pkg/main.css"/>
|
||||||
<Title text="Protoss Bot Control"/>
|
<Title text="Protoss Bot Control"/>
|
||||||
<Router>
|
<Router>
|
||||||
<main>
|
<main>
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route path="" view=HomePage/>
|
<Route path="" view=HomePage/>
|
||||||
</Routes>
|
</Routes>
|
||||||
</main>
|
</main>
|
||||||
</Router>
|
</Router>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
fn HomePage() -> impl IntoView {
|
fn HomePage() -> impl IntoView {
|
||||||
let (game_speed, set_game_speed) = create_signal(20);
|
let (game_speed, set_game_speed) = create_signal(0);
|
||||||
|
|
||||||
let set_speed = move |speed: i32| {
|
let set_speed = create_action(move |speed: &i32| {
|
||||||
set_game_speed.set(speed);
|
let speed = *speed;
|
||||||
spawn_local(async move {
|
async move {
|
||||||
let _ = set_game_speed_server(speed).await;
|
set_game_speed.set(speed);
|
||||||
});
|
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>
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
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
|
||||||
|
class:selected=move || game_speed.get() == -1
|
||||||
|
on:click=move |_| set_speed.dispatch(-1)>
|
||||||
|
"Fastest (-1)"
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
class:selected=move || game_speed.get() == 0
|
||||||
|
on:click=move |_| set_speed.dispatch(0)>
|
||||||
|
"Fast (0)"
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
class:selected=move || game_speed.get() == 1
|
||||||
|
on:click=move |_| set_speed.dispatch(1)>
|
||||||
|
"Normal (1)"
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
class:selected=move || game_speed.get() == 42
|
||||||
|
on:click=move |_| set_speed.dispatch(42)>
|
||||||
|
"Slowest (42)"
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[server(SetGameSpeed, "/api")]
|
#[server(SetGameSpeed, "/api")]
|
||||||
pub async fn set_game_speed_server(speed: i32) -> Result<(), ServerFnError> {
|
pub async fn set_game_speed_server(speed: i32) -> Result<(), ServerFnError> {
|
||||||
if let Ok(mut game_speed) = GAME_SPEED.write() {
|
if let Ok(mut game_speed) = GAME_SPEED.write() {
|
||||||
*game_speed = speed;
|
*game_speed = speed;
|
||||||
println!("Game speed set to: {}", speed);
|
println!("Game speed set to: {}", speed);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,62 +1,74 @@
|
|||||||
body {
|
body {
|
||||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
font-family:
|
||||||
margin: 0;
|
-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu,
|
||||||
padding: 20px;
|
Cantarell, sans-serif;
|
||||||
background-color: #1a1a1a;
|
margin: 0;
|
||||||
color: #ffffff;
|
padding: 20px;
|
||||||
|
background-color: #1a1a1a;
|
||||||
|
color: #ffffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
.container {
|
.container {
|
||||||
max-width: 800px;
|
max-width: 800px;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
color: #4a9eff;
|
color: #4a9eff;
|
||||||
margin-bottom: 30px;
|
margin-bottom: 30px;
|
||||||
}
|
}
|
||||||
|
|
||||||
h2 {
|
h2 {
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
margin-bottom: 15px;
|
margin-bottom: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.speed-control {
|
.speed-control {
|
||||||
background-color: #2a2a2a;
|
background-color: #2a2a2a;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.button-group {
|
.button-group {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
margin-top: 15px;
|
margin-top: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
button {
|
button {
|
||||||
background-color: #4a9eff;
|
background-color: #4a9eff;
|
||||||
color: white;
|
color: white;
|
||||||
border: none;
|
border: none;
|
||||||
padding: 12px 24px;
|
padding: 12px 24px;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
transition: background-color 0.2s;
|
transition: all 0.2s;
|
||||||
}
|
}
|
||||||
|
|
||||||
button:hover {
|
button:hover {
|
||||||
background-color: #357abd;
|
background-color: #357abd;
|
||||||
}
|
}
|
||||||
|
|
||||||
button:active {
|
button:active {
|
||||||
background-color: #2a5f9a;
|
background-color: #2a5f9a;
|
||||||
|
}
|
||||||
|
|
||||||
|
button.selected {
|
||||||
|
background-color: #28a745;
|
||||||
|
box-shadow: 0 0 10px rgba(40, 167, 69, 0.5);
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
button.selected:hover {
|
||||||
|
background-color: #218838;
|
||||||
}
|
}
|
||||||
|
|
||||||
p {
|
p {
|
||||||
color: #cccccc;
|
color: #cccccc;
|
||||||
margin: 10px 0;
|
margin: 10px 0;
|
||||||
}
|
}
|
||||||
|
|||||||
5
protossbot/web/style/protoss-bot-web.js
Normal file
5
protossbot/web/style/protoss-bot-web.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
// Dummy module for SSR-only mode
|
||||||
|
export default function () {
|
||||||
|
console.log("SSR-only mode - no client-side hydration");
|
||||||
|
return Promise.resolve({});
|
||||||
|
}
|
||||||
0
protossbot/web/style/protoss-bot-web_bg.wasm
Normal file
0
protossbot/web/style/protoss-bot-web_bg.wasm
Normal file
Reference in New Issue
Block a user