Skip to content

Commit

Permalink
Merge pull request #11 from sdasda7777/sdasda7777_pages11
Browse files Browse the repository at this point in the history
Fixed issues with WASM main variant
  • Loading branch information
sdasda7777 authored Nov 24, 2023
2 parents 8e53d09 + ddd01e5 commit 9fd1ecd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "minesweeper6d"
version = "0.1.2"
edition = "2021"

[dependencies]
eframe = "0.24"
Expand Down
22 changes: 22 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ impl Shortcuts {
}
}

// When compiling natively:
#[cfg(not(target_arch = "wasm32"))]
fn main() -> Result<(), eframe::Error> {
let options = eframe::NativeOptions {
..Default::default()
Expand All @@ -85,6 +87,26 @@ fn main() -> Result<(), eframe::Error> {
)
}

// When compiling to web using trunk:
#[cfg(target_arch = "wasm32")]
fn main() {
// Redirect `log` message to `console.log` and friends:
eframe::WebLogger::init(log::LevelFilter::Debug).ok();

let web_options = eframe::WebOptions::default();

wasm_bindgen_futures::spawn_local(async {
eframe::WebRunner::new()
.start(
"the_canvas_id", // hardcode it
web_options,
Box::new(|cc| Box::<MinesweeperViewController>::default()),
)
.await
.expect("failed to start eframe");
});
}

struct MinesweeperViewController {
current_initial_settings: InitialGameSettings,
next_initial_settings: InitialGameSettings,
Expand Down
2 changes: 1 addition & 1 deletion src/minesweeper_model.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

extern crate rand;
use bwi::BWI;
use crate::bwi::BWI;
use rand_chacha::{ChaCha8Rng, rand_core::SeedableRng};
use self::rand::Rng;
use std::collections::VecDeque;
Expand Down

0 comments on commit 9fd1ecd

Please sign in to comment.