Add lib target for wasm

This commit is contained in:
Alex Page 2022-02-04 19:28:31 -05:00
parent cbcda28719
commit ecd7c87e29
4 changed files with 42 additions and 22 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
/extern
/target
.vscode
/pkg

View file

@ -4,6 +4,14 @@ version = "0.1.0"
edition = "2021"
build = "build.rs"
[lib]
name = "libkroz"
crate-type = ["cdylib", "rlib"]
[[bin]]
name = "kroz"
path = "src/main.rs"
[dependencies]
# bracket-lib = { path = "extern/bracket-lib" }
bracket-lib = { git = "https://github.com/amethyst/bracket-lib" }

32
src/lib.rs Normal file
View file

@ -0,0 +1,32 @@
use std::panic;
use bracket_lib::prelude::*;
use state::State;
use wasm_bindgen::prelude::*;
pub mod components;
pub mod constants;
mod graphics;
pub mod input;
pub mod levels;
pub mod resources;
mod state;
pub mod systems;
pub mod tile_data;
#[wasm_bindgen(start)]
pub fn main_js() -> Result<(), JsValue> {
panic::set_hook(Box::new(console_error_panic_hook::hook));
let _ = main_common(false);
Ok(())
}
pub fn main_common(initialize_sound: bool) -> BError {
let context = BTermBuilder::vga(80, 25)
.with_fps_cap(60.0)
.with_title("Kroz")
.build()
.unwrap();
main_loop(context, State::new(initialize_sound))
}

View file

@ -10,29 +10,8 @@ mod state;
pub mod systems;
pub mod tile_data;
use std::panic;
use bracket_lib::prelude::*;
use state::State;
use wasm_bindgen::{prelude::wasm_bindgen, JsValue};
#[wasm_bindgen(start)]
pub fn main_js() -> Result<(), JsValue> {
panic::set_hook(Box::new(console_error_panic_hook::hook));
let _ = main_common(false);
Ok(())
}
fn main() -> BError {
main_common(true)
}
fn main_common(initialize_sound: bool) -> BError {
let context = BTermBuilder::vga(80, 25)
.with_fps_cap(60.0)
.with_title("Kroz")
.build()
.unwrap();
main_loop(context, State::new(initialize_sound))
libkroz::main_common(true)
}