tweaks
This commit is contained in:
parent
65257b3886
commit
4c958373ba
|
@ -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
|
||||
|
|
|
@ -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") {
|
||||
|
|
115
src/lib.rs
115
src/lib.rs
|
@ -11,11 +11,8 @@ const SD: u32 = 8;
|
|||
struct State {
|
||||
game: Option<Game>,
|
||||
image: Option<DynamicImage>,
|
||||
prefix: String,
|
||||
invert: bool,
|
||||
flip: bool,
|
||||
mirror: bool,
|
||||
rotate: bool,
|
||||
room_name: Option<String>,
|
||||
palette: Option<String>,
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
|
@ -23,17 +20,14 @@ lazy_static! {
|
|||
State {
|
||||
game: None,
|
||||
image: None,
|
||||
prefix: "".to_string(),
|
||||
invert: false,
|
||||
flip: false,
|
||||
mirror: false,
|
||||
rotate: false,
|
||||
room_name: None,
|
||||
palette: None,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
fn tile_name(prefix: &str, index: &u32) -> Option<String> {
|
||||
if prefix.len() > 0 {
|
||||
fn tile_name(prefix: &Option<String>, index: &u32) -> Option<String> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue