From ecd7c87e29857540b0a34b9ebb16bf171bd5eff4 Mon Sep 17 00:00:00 2001 From: Alex Page Date: Fri, 4 Feb 2022 19:28:31 -0500 Subject: [PATCH] Add lib target for wasm --- .gitignore | 1 + Cargo.toml | 8 ++++++++ src/lib.rs | 32 ++++++++++++++++++++++++++++++++ src/main.rs | 23 +---------------------- 4 files changed, 42 insertions(+), 22 deletions(-) create mode 100644 src/lib.rs diff --git a/.gitignore b/.gitignore index b959261..7b9be68 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /extern /target .vscode +/pkg diff --git a/Cargo.toml b/Cargo.toml index 75207ec..c4635f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" } diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..5a25dab --- /dev/null +++ b/src/lib.rs @@ -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)) +} diff --git a/src/main.rs b/src/main.rs index 705f45f..3183b92 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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) }