initial
This commit is contained in:
41
src/lib.rs
Normal file
41
src/lib.rs
Normal file
@@ -0,0 +1,41 @@
|
||||
use wasm_bindgen::prelude::*;
|
||||
use bitsy_parser::game::Game;
|
||||
|
||||
// Called when the wasm module is instantiated
|
||||
#[wasm_bindgen(start)]
|
||||
pub fn main() -> Result<(), JsValue> {
|
||||
// Use `web_sys`'s global `window` function to get a handle on the global
|
||||
// window object.
|
||||
let window = web_sys::window().expect("no global `window` exists");
|
||||
let document = window.document().expect("should have a document on window");
|
||||
let body = document.body().expect("document should have a body");
|
||||
|
||||
// Manufacture the element we're gonna append
|
||||
let val = document.create_element("p")?;
|
||||
val.set_inner_html("Hello from Rust!");
|
||||
|
||||
body.append_child(&val)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn merge(a: String, b: String) -> String {
|
||||
let main = Game::from(a);
|
||||
let additional = Game::from(b);
|
||||
|
||||
if main.is_err() {
|
||||
return "Couldn't parse main game.".to_string();
|
||||
}
|
||||
|
||||
if additional.is_err() {
|
||||
return "Couldn't parse additional game.".to_string();
|
||||
}
|
||||
|
||||
let mut main = main.unwrap();
|
||||
let additional = additional.unwrap();
|
||||
|
||||
main.merge(additional);
|
||||
main.dedupe_tiles();
|
||||
main.to_string()
|
||||
}
|
||||
Reference in New Issue
Block a user