diff --git a/Cargo.lock b/Cargo.lock index 1c7ecad..10be5f7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2314,6 +2314,7 @@ name = "rukaidata_website" version = "0.1.0" dependencies = [ "axum", + "base64 0.21.5", "bincode", "brawllib_rs", "clap", diff --git a/fighter_renderer/Cargo.lock b/fighter_renderer/Cargo.lock index a27c59d..97f0435 100644 --- a/fighter_renderer/Cargo.lock +++ b/fighter_renderer/Cargo.lock @@ -166,6 +166,12 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.21.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" + [[package]] name = "bincode" version = "1.3.3" @@ -583,11 +589,11 @@ dependencies = [ name = "fighter_renderer" version = "0.1.0" dependencies = [ + "base64", "bincode", "brawllib_rs", "console_error_panic_hook", "console_log", - "js-sys", "log", "wasm-bindgen", "wasm-bindgen-futures", diff --git a/fighter_renderer/Cargo.toml b/fighter_renderer/Cargo.toml index f479086..c01bd0c 100644 --- a/fighter_renderer/Cargo.toml +++ b/fighter_renderer/Cargo.toml @@ -15,7 +15,7 @@ console_log = "1.0" console_error_panic_hook = "0.1" wasm-bindgen = "0.2" wasm-bindgen-futures = "0.4" -js-sys = "0.3.55" +base64 = "0.21.5" [dependencies.web-sys] version = "0.3.4" @@ -27,10 +27,6 @@ features = [ 'HtmlCollection', 'HtmlInputElement', 'HtmlSelectElement', - 'Request', - 'RequestInit', - 'RequestMode', - 'Response', 'Window', ] diff --git a/fighter_renderer/src/lib.rs b/fighter_renderer/src/lib.rs index 1f52d57..af01ddd 100644 --- a/fighter_renderer/src/lib.rs +++ b/fighter_renderer/src/lib.rs @@ -1,57 +1,35 @@ #![allow(clippy::unused_unit)] // the wasm_bindgen macro is expanding to code that clippy doesnt like +use base64::{engine::general_purpose, Engine as _}; use brawllib_rs::high_level_fighter::HighLevelSubaction; use brawllib_rs::renderer::app::App; - -use js_sys::Uint8Array; use log::Level; use wasm_bindgen::prelude::*; -use wasm_bindgen::JsCast; -use wasm_bindgen_futures::JsFuture; use web_sys::Document; -use web_sys::{Request, RequestInit, RequestMode, Response}; mod dom_ui; mod hitbox_table_angles; #[wasm_bindgen] -pub fn run(subaction_bin_path: String) { +pub fn run(subaction_bincode: String) { std::panic::set_hook(Box::new(console_error_panic_hook::hook)); console_log::init_with_level(Level::Warn).expect("could not initialize logger"); - wasm_bindgen_futures::spawn_local(run_async(subaction_bin_path)); + wasm_bindgen_futures::spawn_local(run_async(subaction_bincode)); } -async fn run_async(subaction_bin_path: String) { +async fn run_async(subaction_bincode: String) { let document = web_sys::window().unwrap().document().unwrap(); hitbox_table_angles::draw_hitbox_table_angles(&document); - let subaction = get_subaction(&subaction_bin_path).await; + let subaction = get_subaction(&subaction_bincode).await; run_renderer(document, subaction).await; } -async fn get_subaction(subaction_bin_path: &str) -> HighLevelSubaction { - let mut opts = RequestInit::new(); - opts.method("GET"); - opts.mode(RequestMode::Cors); - - let request = Request::new_with_str_and_init(subaction_bin_path, &opts).unwrap(); - - let window = web_sys::window().unwrap(); - let resp_value = JsFuture::from(window.fetch_with_request(&request)) - .await - .unwrap(); - - // `resp_value` is a `Response` object. - assert!(resp_value.is_instance_of::()); - let resp: Response = resp_value.dyn_into().unwrap(); - - // Convert this other `Promise` into a rust `Future`. - let js_value = JsFuture::from(resp.array_buffer().unwrap()).await.unwrap(); - let data = Uint8Array::new(&js_value).to_vec(); - - bincode::deserialize_from(&*data).unwrap() +async fn get_subaction(subaction_bincode: &str) -> HighLevelSubaction { + let data = general_purpose::STANDARD.decode(subaction_bincode).unwrap(); + bincode::deserialize_from(data.as_slice()).unwrap() } pub async fn run_renderer(document: Document, subaction: HighLevelSubaction) { diff --git a/website/Cargo.toml b/website/Cargo.toml index 35e0478..ea69073 100644 --- a/website/Cargo.toml +++ b/website/Cargo.toml @@ -27,3 +27,4 @@ tokio = { version = "1.35.1", features = ["full"] } axum = "0.7.3" tower-http = { version = "0.5.0", features = ["fs"], git = "https://github.com/rukai/tower-http", branch = "servedir_compress_in_place_hack" } clap = { version = "4.4.12", features = ["derive"] } +base64 = "0.21.5" diff --git a/website/src/page/subaction.rs b/website/src/page/subaction.rs index b925a0c..bd00841 100644 --- a/website/src/page/subaction.rs +++ b/website/src/page/subaction.rs @@ -3,6 +3,7 @@ use crate::brawl_data::{BrawlMods, SubactionLinks}; use crate::output::OutDir; use crate::page::{NavLink, Preload}; use crate::process_scripts; +use base64::{engine::general_purpose, Engine as _}; use brawllib_rs::high_level_fighter::CollisionBoxValues; use brawllib_rs::script_ast::{AngleFlip, GrabTarget, HitBoxEffect}; use handlebars::Handlebars; @@ -973,10 +974,6 @@ pub fn generate( path: assets.fighter_renderer_js.clone(), as_: "script".to_string(), }, - Preload { - path: format!("{}.bin", subaction.name), - as_: "fetch".to_string(), - }, ]; let preload = if wasm_mode { @@ -985,10 +982,12 @@ pub fn generate( &[] as &[Preload] }; - if wasm_mode { + let subaction_bincode = if wasm_mode { let bin = bincode::serialize(&subaction).unwrap(); - dir.create_compressed_file(&format!("{}.bin",subaction.name), &bin); - } + general_purpose::STANDARD.encode(bin) + } else { + String::new() + }; let page = SubactionPage { assets, @@ -997,9 +996,9 @@ pub fn generate( mod_links: &mod_links, title: format!("{} - {} - Subaction - {}", brawl_mod.name, fighter_name, subaction.name), subaction_links: brawl_mod.gen_subaction_links(&fighter.fighter, subaction.name.clone()), - subaction_bin_path: format!("{}.bin", subaction.name), subaction: serde_json::to_string(&subaction).unwrap(), subaction_extent: serde_json::to_string(&subaction_extent).unwrap(), + subaction_bincode, attributes, throw_table, hitbox_tables, @@ -1078,7 +1077,7 @@ pub struct SubactionPage<'a> { attributes: Vec, throw_table: Option, hitbox_tables: Vec, - subaction_bin_path: String, + subaction_bincode: String, subaction: String, subaction_extent: String, script_main: String, diff --git a/website/templates/subaction.html.hbs b/website/templates/subaction.html.hbs index 48c6d3a..8285154 100644 --- a/website/templates/subaction.html.hbs +++ b/website/templates/subaction.html.hbs @@ -454,10 +454,11 @@ {{#if wasm_mode}} {{else}} @@ -467,4 +468,4 @@ {{/inline}} -{{~> base ~}} +{{~> base ~}} \ No newline at end of file