updates
This commit is contained in:
66
protossbot/web/src/lib.rs
Normal file
66
protossbot/web/src/lib.rs
Normal 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(())
|
||||
}
|
||||
27
protossbot/web/src/main.rs
Normal file
27
protossbot/web/src/main.rs
Normal 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();
|
||||
}
|
||||
Reference in New Issue
Block a user