From 4c958373bafff2c30f457cc642c866009ae3b6dd Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Wed, 4 Nov 2020 16:11:44 +0000 Subject: [PATCH] tweaks --- index.pug | 6 +-- script.js | 8 +--- src/lib.rs | 123 ++++++++--------------------------------------------- 3 files changed, 22 insertions(+), 115 deletions(-) diff --git a/index.pug b/index.pug index c9d6fc0..ff5a50c 100644 --- a/index.pug +++ b/index.pug @@ -7,9 +7,9 @@ html(lang="en-gb") body h1 | pixsy - //img(alt="tilesy" src="includes/tilesy.png") - p - span.background convert images to Bitsy rooms + //img(alt="pixsy" src="includes/pixsy.png") + p convert images to Bitsy rooms + p looking for the #[a(href="./old/") old version]? .pages .page#start button.normal.pagination.next#new create a new bitsy game diff --git a/script.js b/script.js index d292584..5c3a844 100644 --- a/script.js +++ b/script.js @@ -1,14 +1,10 @@ import init, { - add_tiles, + add_room, load_image, load_game, load_default_game, output, - set_prefix, - set_invert, - set_flip, - set_mirror, - set_rotate + set_room_name, } from './pkg/pixsy.js'; if (typeof WebAssembly !== "object") { diff --git a/src/lib.rs b/src/lib.rs index f060e5f..11225c8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,31 +9,25 @@ use wasm_bindgen::prelude::*; const SD: u32 = 8; struct State { - game: Option, - image: Option, - prefix: String, - invert: bool, - flip: bool, - mirror: bool, - rotate: bool, + game: Option, + image: Option, + room_name: Option, + palette: Option, } lazy_static! { static ref STATE: Mutex = Mutex::new( State { - game: None, - image: None, - prefix: "".to_string(), - invert: false, - flip: false, - mirror: false, - rotate: false, + game: None, + image: None, + room_name: None, + palette: None, } ); } -fn tile_name(prefix: &str, index: &u32) -> Option { - if prefix.len() > 0 { +fn tile_name(prefix: &Option, index: &u32) -> Option { + if let Some(prefix) = prefix { Some(format!("{} {}", prefix, index)) } else { None @@ -91,43 +85,17 @@ pub fn load_image(image_base64: String) -> String { } #[wasm_bindgen] -pub fn set_prefix(prefix: String) { +pub fn set_room_name(room_name: String) { let mut state = STATE.lock().unwrap(); - state.prefix = prefix; + match room_name.is_empty() { + true => { state.room_name = None }, + false => { state.room_name = Some(room_name) }, + } } #[wasm_bindgen] -pub fn set_invert(invert: bool) { - let mut state = STATE.lock().unwrap(); - - state.invert = invert; -} - -#[wasm_bindgen] -pub fn set_flip(flip: bool) { - let mut state = STATE.lock().unwrap(); - - state.flip = flip; -} - -#[wasm_bindgen] -pub fn set_mirror(mirror: bool) { - let mut state = STATE.lock().unwrap(); - - state.mirror = mirror; -} - -#[wasm_bindgen] -pub fn set_rotate(rotate: bool) { - let mut state = STATE.lock().unwrap(); - - state.rotate = rotate; -} - -/// prefix will be ignored if empty -#[wasm_bindgen] -pub fn add_tiles() -> String { +pub fn add_room() -> String { let mut state = STATE.lock().expect("Couldn't lock application state"); if state.game.is_none() { @@ -163,7 +131,7 @@ pub fn add_tiles() -> String { let tile = Tile { // "0" will get overwritten to a new, safe tile ID id: "0".to_string(), - name: tile_name(&state.prefix, &tile_index), + name: tile_name(&state.room_name, &tile_index), wall: None, animation_frames: vec![Image { pixels }], colour_id: None @@ -174,63 +142,6 @@ pub fn add_tiles() -> String { tile_index += 1; } - - if state.invert { - let mut inverted = tile.clone(); - inverted.invert(); - - if inverted.name.is_some() { - inverted.name = Some(format!("{} inverted", inverted.name.unwrap())); - } - - if !game.tiles.contains(&inverted) { - game.add_tile(inverted); - } - } - - if state.flip { - let mut flipped = tile.clone(); - flipped.flip(); - - if flipped.name.is_some() { - flipped.name = Some(format!("{} flipped", flipped.name.unwrap())); - } - - if !game.tiles.contains(&flipped) { - game.add_tile(flipped); - } - } - - if state.mirror { - let mut mirrored = tile.clone(); - mirrored.mirror(); - - if mirrored.name.is_some() { - mirrored.name = Some(format!("{} mirrored", mirrored.name.unwrap())); - } - - if !game.tiles.contains(&mirrored) { - game.add_tile(mirrored); - } - } - - if state.rotate { - for i in 1..4 { - let mut rotated = tile.clone(); - - for _ in 0..i { - rotated.rotate(); - } - - if rotated.name.is_some() { - rotated.name = Some(format!("{} {}°", rotated.name.unwrap(), i * 90)); - } - - if !game.tiles.contains(&rotated) { - game.add_tile(rotated); - } - } - } } }