2019-09-13 21:18:11 +00:00
|
|
|
extern crate serde;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate serde_derive;
|
|
|
|
extern crate serde_json;
|
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
extern crate lazy_static;
|
|
|
|
|
|
|
|
use std::sync::{Arc, Mutex};
|
|
|
|
|
2019-09-13 20:54:21 +00:00
|
|
|
mod utils;
|
2019-09-13 21:18:11 +00:00
|
|
|
mod types;
|
2019-09-13 20:54:21 +00:00
|
|
|
|
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
|
|
|
|
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
|
|
|
|
// allocator.
|
|
|
|
#[cfg(feature = "wee_alloc")]
|
|
|
|
#[global_allocator]
|
|
|
|
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
|
|
|
|
|
2019-09-13 21:18:11 +00:00
|
|
|
lazy_static! {
|
|
|
|
static ref STATE: Mutex<Box<types::State>> = Mutex::new(Box::new(types::State {
|
|
|
|
planets: Vec::new(),
|
|
|
|
expeditions: Vec::new(),
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2019-09-13 20:54:21 +00:00
|
|
|
#[wasm_bindgen]
|
|
|
|
extern {
|
|
|
|
fn alert(s: &str);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen]
|
2019-09-13 21:18:11 +00:00
|
|
|
pub fn set_state(state: &str) {
|
|
|
|
let deserialized: types::State = serde_json::from_str(state).unwrap();
|
|
|
|
*STATE.lock().unwrap() = Box::new(deserialized);
|
2019-09-13 20:54:21 +00:00
|
|
|
}
|