attempt to move state to wasm
This commit is contained in:
parent
4d2330b8fd
commit
35af495f51
16
Cargo.toml
16
Cargo.toml
|
@ -1,27 +1,19 @@
|
||||||
[package]
|
[package]
|
||||||
name = "tilesy"
|
name = "tilesy"
|
||||||
version = "0.1.0"
|
version = "0.72.0"
|
||||||
description = "a tilesheet importer for the Bitsy game engine"
|
description = "a tilesheet importer for the Bitsy game engine"
|
||||||
authors = ["Max Bradbury <max@tinybird.info>"]
|
authors = ["Max Bradbury <max@tinybird.info>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
repository = "https://tinybird.dev/max/tilesy"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["cdylib", "rlib"]
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
"base64" = "^0.12.3"
|
"base64" = "^0.12.3"
|
||||||
"bitsy-parser" = "^0.72.0"
|
"bitsy-parser" = "^0.72.0"
|
||||||
"image" = "^0.23.7"
|
"image" = "^0.23.7"
|
||||||
|
"lazy_static" = "^1.4.0"
|
||||||
"wasm-bindgen" = "^0.2.64"
|
"wasm-bindgen" = "^0.2.64"
|
||||||
|
|
||||||
[dependencies.web-sys]
|
|
||||||
version = "^0.3.4"
|
|
||||||
features = [
|
|
||||||
'Document',
|
|
||||||
'Element',
|
|
||||||
'HtmlElement',
|
|
||||||
'Node',
|
|
||||||
'Window',
|
|
||||||
]
|
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
import init, {load_default_game_data, add_tiles} from './pkg/bitsy_tiles.js';
|
import init, {load_default_game_data, add_tiles} from './pkg/tilesy.js';
|
||||||
|
|
||||||
|
// if (typeof WebAssembly !== "object") {
|
||||||
|
// document.getElementById("start").innerText = "Sorry - your browser does not support WebAssembly";
|
||||||
|
// }
|
||||||
|
|
||||||
// stolen from https://ourcodeworld.com/articles/read/189/how-to-create-a-file-and-generate-a-download-with-javascript-in-the-browser-without-a-server
|
// stolen from https://ourcodeworld.com/articles/read/189/how-to-create-a-file-and-generate-a-download-with-javascript-in-the-browser-without-a-server
|
||||||
function download(filename, text) {
|
function download(filename, text) {
|
||||||
|
|
29
src/lib.rs
29
src/lib.rs
|
@ -2,9 +2,35 @@ use bitsy_parser::game::Game;
|
||||||
use bitsy_parser::image::Image;
|
use bitsy_parser::image::Image;
|
||||||
use bitsy_parser::tile::Tile;
|
use bitsy_parser::tile::Tile;
|
||||||
use image::{GenericImageView, Pixel};
|
use image::{GenericImageView, Pixel};
|
||||||
|
// use lazy_static::lazy_static;
|
||||||
|
// use std::sync::Mutex;
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
const SD: u32 = 8;
|
const SD: u32 = 8;
|
||||||
|
//
|
||||||
|
// struct State {
|
||||||
|
// game: Option<Game>,
|
||||||
|
// image: Option<Image>,
|
||||||
|
// prefix: String,
|
||||||
|
// invert: bool,
|
||||||
|
// flip: bool,
|
||||||
|
// mirror: bool,
|
||||||
|
// rotate: bool,
|
||||||
|
// }
|
||||||
|
|
||||||
|
// lazy_static! {
|
||||||
|
// static ref STATE: Mutex<State> = Mutex::new(
|
||||||
|
// State {
|
||||||
|
// game: None,
|
||||||
|
// image: None,
|
||||||
|
// prefix: "".to_string(),
|
||||||
|
// invert: false,
|
||||||
|
// flip: false,
|
||||||
|
// mirror: false,
|
||||||
|
// rotate: false,
|
||||||
|
// }
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn load_default_game_data() -> String {
|
pub fn load_default_game_data() -> String {
|
||||||
|
@ -146,6 +172,9 @@ pub fn add_tiles(
|
||||||
}
|
}
|
||||||
|
|
||||||
game.dedupe_tiles();
|
game.dedupe_tiles();
|
||||||
|
|
||||||
|
let game = game;
|
||||||
|
|
||||||
game.to_string()
|
game.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue