commit f950836ad4db11dd9f779fb18b59d159a8d15153 Author: Max Bradbury Date: Fri Jul 3 14:57:07 2020 +0100 initial diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9495428 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/.idea/ +/index.html +/target/ diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..28e1f14 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,282 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "ansi_term" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +dependencies = [ + "winapi", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "bitflags" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" + +[[package]] +name = "bitsy-merge" +version = "0.71.0" +dependencies = [ + "bitsy-parser", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "bitsy-parser" +version = "0.71.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1879d407b47c06139b76612a7305324252f164795572e7e0e16acae84a9bd664" +dependencies = [ + "loe", + "radix_fmt", +] + +[[package]] +name = "bumpalo" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820" + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "clap" +version = "2.33.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdfa80d47f954d53a35a64987ca1422f495b8d6483c0fe9f7117b36c2a792129" +dependencies = [ + "ansi_term", + "atty", + "bitflags", + "strsim", + "textwrap", + "unicode-width", + "vec_map", +] + +[[package]] +name = "hermit-abi" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9586eedd4ce6b3c498bc3b4dd92fc9f11166aa908a914071953768066c67909" +dependencies = [ + "libc", +] + +[[package]] +name = "js-sys" +version = "0.3.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4b9172132a62451e56142bff9afc91c8e4a4500aa5b847da36815b63bfda916" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49" + +[[package]] +name = "loe" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eb4727946c98c595647b6d3b490af357a0fcc3863d4311551056cb3589e546a" +dependencies = [ + "clap", + "yansi", +] + +[[package]] +name = "log" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "proc-macro2" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radix_fmt" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce082a9940a7ace2ad4a8b7d0b1eac6aa378895f18be598230c5f2284ac05426" + +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + +[[package]] +name = "syn" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8d5d96e8cbb005d6959f119f773bfaebb5684296108fb32600c00cde305b2cd" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "unicode-width" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" + +[[package]] +name = "unicode-xid" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" + +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + +[[package]] +name = "wasm-bindgen" +version = "0.2.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a634620115e4a229108b71bde263bb4220c483b3f07f5ba514ee8d15064c4c2" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e53963b583d18a5aa3aaae4b4c1cb535218246131ba22a71f05b518098571df" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fcfd5ef6eec85623b4c6e844293d4516470d8f19cd72d0d12246017eb9060b8" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9adff9ee0e94b926ca81b57f57f86d5545cdcb1d259e21ec9bdd95b901754c75" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f7b90ea6c632dd06fd765d44542e234d5e63d9bb917ecd64d79778a13bd79ae" + +[[package]] +name = "web-sys" +version = "0.3.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "863539788676619aac1a23e2df3655e96b32b0e05eb72ca34ba045ad573c625d" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "yansi" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d60c3b48c9cdec42fb06b3b84b5b087405e1fa1c644a1af3930e4dfafe93de48" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..bf377a3 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "bitsy-merge" +version = "0.71.0" +authors = ["Max Bradbury "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +crate-type = ["cdylib"] + +[dependencies] +"bitsy-parser" = "^0.71.1" +"wasm-bindgen" = "^0.2.64" + +[dependencies.web-sys] +version = "0.3.4" +features = [ + 'Document', + 'Element', + 'HtmlElement', + 'Node', + 'Window', +] diff --git a/README.md b/README.md new file mode 100644 index 0000000..3efeff9 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# mixsy + +blah blah blah diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..a968646 --- /dev/null +++ b/build.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +pug index.pug +set -ex +wasm-pack build --target web +python3 -m http.server diff --git a/index.js b/index.js new file mode 100644 index 0000000..8190e31 --- /dev/null +++ b/index.js @@ -0,0 +1,13 @@ +import init, {merge} from './pkg/bitsy_merge.js'; + +async function run() { + await init(); + + document.getElementById('merge').addEventListener('click', () => { + let a = document.getElementById('a').value; + let b = document.getElementById('b').value; + document.getElementById('c').value = merge(a, b); + }) +} + +run(); diff --git a/index.pug b/index.pug new file mode 100644 index 0000000..00991e6 --- /dev/null +++ b/index.pug @@ -0,0 +1,105 @@ +doctype html +html(lang="en-gb") + head + meta(content="text/html;charset=utf-8" http-equiv="Content-Type") + title mixsy + style. + :root { + --bg: #ed9f96; + --alt: #dc4c6b; + --inverse: #444; + --text: #7be5b3; + } + + * { + box-sizing: border-box; + color: var(--text); + font-family: sans-serif; + } + + html, body { + background-color: var(--bg); + margin: 0; + padding: 0; + } + + button { + background-color: var(--text); + border: 0; + border-radius: 2.5vmin; + color: var(--alt); + cursor: pointer; + display: block; + font-size: 5vmin; + } + + h1, p { + margin: 0; + text-align: center; + } + + h1 { + font-size: 10vmin; + } + + h2 { + font-size: 5vmin; + margin: 0; + text-align: center; + } + + textarea { + background-color: var(--inverse); + border: 0; + color: var(--text); + font-family: monospace; + height: 17vmin; + width: 100%; + } + + #container { + background-color: var(--alt); + border-radius: 5vmin; + height: 100vmin; + width: 100vmin; + } + + .centre { + margin: 0 auto; + } + + .left { + float: left; + } + + .row { + width: 100%; + height: calc(82vmin / 3); + } + + .square { + width: 50vmin; + height: 100%; + padding: 0.5em; + } + body + #container.centre + h1 mixsy + p combine #[a(href="https://ledoux.itch.io/bitsy") bitsy] games + .row.top + #main.square.left + h2 main + textarea#a + #additional.square.left + h2 additional + textarea#b + .row.middle + // todo have some kind of arrow here + button#merge.centre mix! + .row.bottom + .square.centre + h2 output + textarea#c + //- Note the usage of `type=module` here as this is an ES6 module --> + script(type="module") + include index.js diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..fdb7c19 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,41 @@ +use wasm_bindgen::prelude::*; +use bitsy_parser::game::Game; + +// Called when the wasm module is instantiated +#[wasm_bindgen(start)] +pub fn main() -> Result<(), JsValue> { + // Use `web_sys`'s global `window` function to get a handle on the global + // window object. + let window = web_sys::window().expect("no global `window` exists"); + let document = window.document().expect("should have a document on window"); + let body = document.body().expect("document should have a body"); + + // Manufacture the element we're gonna append + let val = document.create_element("p")?; + val.set_inner_html("Hello from Rust!"); + + body.append_child(&val)?; + + Ok(()) +} + +#[wasm_bindgen] +pub fn merge(a: String, b: String) -> String { + let main = Game::from(a); + let additional = Game::from(b); + + if main.is_err() { + return "Couldn't parse main game.".to_string(); + } + + if additional.is_err() { + return "Couldn't parse additional game.".to_string(); + } + + let mut main = main.unwrap(); + let additional = additional.unwrap(); + + main.merge(additional); + main.dedupe_tiles(); + main.to_string() +}