Skip to content

Commit

Permalink
panic
Browse files Browse the repository at this point in the history
  • Loading branch information
coilysiren committed Nov 24, 2023
1 parent 51981ea commit 80a3f4e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/js/lib/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,31 @@ export function Interface() {
</div>
)

const handleSeedClick = () => {
const handleInitClick = () => {
if (wasmModule === null) {
console.error("wasm not yet loaded");
} else {
galaxyFrontend = new galaxy.Frontend(galaxySize);
}
};

const initButton = (
<button type="button" className="btn btn-primary" onClick={handleInitClick}>
init new galaxy
</button>
)

const handleSeedClick = () => {
if (wasmModule === null) {
console.error("wasm not yet loaded");
} else {
galaxyFrontend.seed();
}
};

const seedButton = (
<button type="button" className="btn btn-primary" onClick={handleSeedClick}>
seed new galaxy
seed the galaxy
</button>
)

Expand All @@ -60,6 +73,7 @@ export function Interface() {
<h2><small className="text-muted">( rust =&gt; wasm =&gt; js ) galaxy generation simulation</small></h2>
{galaxySizeInput}
<div className="d-flex justify-content-between">
{initButton}
{seedButton}
{tickButton}
</div>
Expand Down
3 changes: 3 additions & 0 deletions src/rust/galaxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use cell::*;
use rand::Rng;
use wasm_bindgen::prelude::*;

use crate::utils;

// types
#[wasm_bindgen]
pub struct Galaxy {
Expand All @@ -14,6 +16,7 @@ pub struct Galaxy {
impl Galaxy {
#[wasm_bindgen(constructor)]
pub fn new(size: u16, mass: u16) -> Galaxy {
utils::set_panic_hook();
return Galaxy {
size,
cells: vec![
Expand Down

0 comments on commit 80a3f4e

Please sign in to comment.