diff --git a/.gitignore b/.gitignore index 0aeb57f..d466ca6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -/target/ +target/ /.task/ diff --git a/Cargo.lock b/Cargo.lock index 305944f..a1e3157 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,14 +17,45 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + [[package]] name = "firefly-rust" version = "0.12.0" dependencies = [ + "firefly_toml", "nalgebra", "talc", ] +[[package]] +name = "firefly_toml" +version = "0.1.0" +dependencies = [ + "serde", + "toml", +] + +[[package]] +name = "hashbrown" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" + +[[package]] +name = "indexmap" +version = "2.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" +dependencies = [ + "equivalent", + "hashbrown", +] + [[package]] name = "lock_api" version = "0.4.12" @@ -93,12 +124,69 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4" +dependencies = [ + "proc-macro2", +] + [[package]] name = "scopeguard" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_spanned" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8bbf91e5a4d6315eee45e704372590b30e260ee83af6639d64557f51b067776" +dependencies = [ + "serde_core", +] + [[package]] name = "simba" version = "0.9.0" @@ -111,6 +199,17 @@ dependencies = [ "paste", ] +[[package]] +name = "syn" +version = "2.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "talc" version = "4.4.3" @@ -120,8 +219,59 @@ dependencies = [ "lock_api", ] +[[package]] +name = "toml" +version = "0.9.12+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf92845e79fc2e2def6a5d828f0801e29a2f8acc037becc5ab08595c7d5e9863" +dependencies = [ + "indexmap", + "serde_core", + "serde_spanned", + "toml_datetime", + "toml_parser", + "toml_writer", + "winnow", +] + +[[package]] +name = "toml_datetime" +version = "0.7.5+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92e1cfed4a3038bc5a127e35a2d360f145e1f4b971b551a2ba5fd7aedf7e1347" +dependencies = [ + "serde_core", +] + +[[package]] +name = "toml_parser" +version = "1.0.9+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "702d4415e08923e7e1ef96cd5727c0dfed80b4d2fa25db9647fe5eb6f7c5a4c4" +dependencies = [ + "winnow", +] + +[[package]] +name = "toml_writer" +version = "1.0.6+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab16f14aed21ee8bfd8ec22513f7287cd4a91aa92e44edfe2c17ddd004e92607" + [[package]] name = "typenum" version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "winnow" +version = "0.7.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5364e9d77fcdeeaa6062ced926ee3381faa2ee02d3eb83a5c27a8825540829" diff --git a/Cargo.toml b/Cargo.toml index 1f7c34d..b5cd406 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ keywords = ["gamedev", "firefly-zero"] categories = ["game-development", "no-std", "rendering", "api-bindings", "wasm"] [features] -default = [] +default = ["macros"] # If disabled, the crate uses no_std. std = ["alloc"] # Enable support for allocating functions, like load_file_buf. @@ -26,12 +26,15 @@ panic_info = ["alloc"] sudo = [] # Enable support for casting graphic primitives to and from nalgebra crate primitives. nalgebra = ["dep:nalgebra"] +# Enable support for convenience macros +macros = ["dep:firefly_toml"] [dependencies] nalgebra = { version = "0.34.1", optional = true, default-features = false } talc = { version = "4.4.3", optional = true, default-features = false, features = [ "lock_api", ] } +firefly_toml = { version = "0.1", optional = true, path = "firefly_toml" } # https://docs.rs/about/metadata # https://github.com/firefly-zero/firefly-rust/issues/17 diff --git a/firefly_toml/Cargo.lock b/firefly_toml/Cargo.lock new file mode 100644 index 0000000..aff8496 --- /dev/null +++ b/firefly_toml/Cargo.lock @@ -0,0 +1,290 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "console" +version = "0.15.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "054ccb5b10f9f2cbf51eb355ca1d05c2d279ce1804688d0db74b4733a5aeafd8" +dependencies = [ + "encode_unicode", + "libc", + "once_cell", + "windows-sys", +] + +[[package]] +name = "encode_unicode" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0" + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "firefly-rust" +version = "0.12.0" +dependencies = [ + "firefly_toml", +] + +[[package]] +name = "firefly_toml" +version = "0.1.0" +dependencies = [ + "firefly-rust", + "serde", + "snapshot-testing", + "toml", +] + +[[package]] +name = "hashbrown" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" + +[[package]] +name = "indexmap" +version = "2.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "libc" +version = "0.2.182" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112" + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_spanned" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8bbf91e5a4d6315eee45e704372590b30e260ee83af6639d64557f51b067776" +dependencies = [ + "serde_core", +] + +[[package]] +name = "similar" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbbb5d9659141646ae647b42fe094daf6c6192d1620870b449d9557f748b2daa" + +[[package]] +name = "similar-asserts" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b441962c817e33508847a22bd82f03a30cff43642dc2fae8b050566121eb9a" +dependencies = [ + "console", + "similar", +] + +[[package]] +name = "snapshot-testing" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bebf2194b9611339d00b28260cf6bd640073c60179ce7dd1e47badef1eb606e7" +dependencies = [ + "console", + "similar-asserts", +] + +[[package]] +name = "syn" +version = "2.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "toml" +version = "0.9.12+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf92845e79fc2e2def6a5d828f0801e29a2f8acc037becc5ab08595c7d5e9863" +dependencies = [ + "indexmap", + "serde_core", + "serde_spanned", + "toml_datetime", + "toml_parser", + "toml_writer", + "winnow", +] + +[[package]] +name = "toml_datetime" +version = "0.7.5+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92e1cfed4a3038bc5a127e35a2d360f145e1f4b971b551a2ba5fd7aedf7e1347" +dependencies = [ + "serde_core", +] + +[[package]] +name = "toml_parser" +version = "1.0.9+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "702d4415e08923e7e1ef96cd5727c0dfed80b4d2fa25db9647fe5eb6f7c5a4c4" +dependencies = [ + "winnow", +] + +[[package]] +name = "toml_writer" +version = "1.0.6+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab16f14aed21ee8bfd8ec22513f7287cd4a91aa92e44edfe2c17ddd004e92607" + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winnow" +version = "0.7.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5364e9d77fcdeeaa6062ced926ee3381faa2ee02d3eb83a5c27a8825540829" diff --git a/firefly_toml/Cargo.toml b/firefly_toml/Cargo.toml new file mode 100644 index 0000000..becb671 --- /dev/null +++ b/firefly_toml/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "firefly_toml" +version = "0.1.0" +edition = "2024" +rust-version = "1.89.0" +authors = ["Firefly Zero team"] +description = "Rust SDK helper macros for making Firefly Zero games" +repository = "https://github.com/firefly-zero/firefly-rust" +license = "MIT" +keywords = ["gamedev", "firefly-zero"] +categories = ["game-development", "no-std", "rendering", "api-bindings", "wasm"] + +[lib] +proc-macro = true + +[dependencies] +toml = "0.9" +serde = { version = "1", features = ["serde_derive"] } + +[dev-dependencies] +snapshot-testing = "0.1.8" +firefly-rust = { path = ".." } diff --git a/firefly_toml/README.md b/firefly_toml/README.md new file mode 100644 index 0000000..b8c8ea6 --- /dev/null +++ b/firefly_toml/README.md @@ -0,0 +1,5 @@ +To update the test fixtures if the output changes, you need to set the `UPDATE_SNAPSHOTS` environment variable to `yes`: + +```bash +env UPDATE_SNAPSHOTS=yes cargo test +``` diff --git a/firefly_toml/src/lib.rs b/firefly_toml/src/lib.rs new file mode 100644 index 0000000..bb47733 --- /dev/null +++ b/firefly_toml/src/lib.rs @@ -0,0 +1,144 @@ +use proc_macro::TokenStream; +use serde::Deserialize; +use std::collections::HashMap; +use std::{fmt::Write as _, str::FromStr as _}; + +#[proc_macro] +pub fn import(item: TokenStream) -> TokenStream { + if !item.is_empty() { + return r##"compile_error!("firefly_import_toml does not take any arguments");"## + .parse() + .unwrap(); + } + let Config { + cheats, + badges, + boards, + } = match load_config() { + Ok(value) => value, + Err(err) => return err, + }; + let mut s = String::new(); + write_badges(badges.unwrap_or_default(), &mut s); + write_cheats(cheats.unwrap_or_default(), &mut s); + write_boards(boards.unwrap_or_default(), &mut s); + + s.parse().unwrap() +} + +#[derive(Deserialize, Debug)] +struct BoardConfig { + /// Human-readable board name. + pub name: String, +} + +fn write_boards(boards: HashMap, s: &mut String) { + if boards.is_empty() { + return; + } + writeln!(s, "mod boards {{").unwrap(); + writeln!(s, "use firefly_rust::{{Peer, add_score, Progress, Board}};").unwrap(); + for (id, board) in boards { + let name = board.name.replace(' ', "_"); + writeln!( + s, + "pub fn {name}(peer: Peer, score: i16) -> i16 {{ add_score(peer, Board({id}), score) }}", + ) + .unwrap(); + } + s.push_str("}"); +} + +fn write_cheats(cheats: HashMap, s: &mut String) { + if cheats.is_empty() { + return; + } + writeln!(s, "enum Cheats {{").unwrap(); + for (name, id) in &cheats { + let name = name.replace('-', "_"); + writeln!(s, "{name} = {id},",).unwrap(); + } + s.push_str("}"); + writeln!( + s, + "impl Cheats {{ fn from_id(id: i32) -> Self {{ match id {{" + ) + .unwrap(); + for (name, id) in cheats { + let name = name.replace('-', "_"); + writeln!(s, "{id} => Self::{name},",).unwrap(); + } + writeln!(s, "_ => unreachable!(),").unwrap(); + writeln!(s, "}} }} }}").unwrap(); +} + +#[derive(Deserialize, Debug)] +struct BadgeConfig { + /// Human-readable achievement name. + pub name: String, + + /// Human-readable achievement description. Typically, a hint on how to earn it. + #[serde(default)] + pub descr: String, + + /// How many steps there are to earn the badge. + /// + /// Defaults to 1. + pub steps: Option, +} + +fn write_badges(badges: HashMap, s: &mut String) { + if badges.is_empty() { + return; + } + writeln!(s, "mod badges {{").unwrap(); + writeln!( + s, + "use firefly_rust::{{Badge, Peer, add_progress, Progress, Board}};" + ) + .unwrap(); + for (id, badge) in badges { + writeln!(s, "/// {}", badge.descr).unwrap(); + let name = badge.name.replace(' ', "_"); + let (arg, n) = match badge.steps { + Some(1) | None => ("", "1"), + Some(_) => ("arg: u32", "arg"), + }; + writeln!( + s, + "pub fn {name}(peer: Peer, {arg}) -> Progress {{ add_progress(peer, Badge({id}), {n}) }}", + ) + .unwrap(); + } + s.push_str("}"); +} + +#[derive(Deserialize, Debug)] +struct Config { + /// Mapping of cheat commands to their integer representation. + pub cheats: Option>, + + /// Mapping of badge IDs to badges. + pub badges: Option>, + + /// Mapping of board IDs to boards. + pub boards: Option>, +} + +fn load_config() -> Result { + let file = std::fs::read("firefly.toml").map_err(|e| { + TokenStream::from_str(&format!( + r####"compile_error!(r##"could not load firefly.toml: {e}"##);"#### + )) + .unwrap() + })?; + toml::from_slice(&file).map_err(|e| { + TokenStream::from_str(&format!( + r####"compile_error!(r##"firefly.toml is not valid toml: {e}"##);"#### + )) + .unwrap() + }) +} + +#[cfg(test)] +mod tests; diff --git a/firefly_toml/src/tests.rs b/firefly_toml/src/tests.rs new file mode 100644 index 0000000..029a594 --- /dev/null +++ b/firefly_toml/src/tests.rs @@ -0,0 +1,25 @@ +use crate::{Config, write_badges, write_boards, write_cheats}; + +#[test] +fn end_to_end() { + run("end_to_end"); +} + +#[test] +fn empty() { + run("empty") +} + +fn run(name: &str) { + let input = std::fs::read_to_string(format!("tests/{name}.toml")).unwrap(); + let Config { + cheats, + badges, + boards, + } = toml::from_str(&input).unwrap(); + let mut s = String::new(); + write_badges(badges.unwrap_or_default(), &mut s); + write_cheats(cheats.unwrap_or_default(), &mut s); + write_boards(boards.unwrap_or_default(), &mut s); + snapshot_testing::assert_eq_or_update(s, format!("tests/{name}.rs")); +} diff --git a/firefly_toml/tests/empty.rs b/firefly_toml/tests/empty.rs new file mode 100644 index 0000000..e69de29 diff --git a/firefly_toml/tests/empty.toml b/firefly_toml/tests/empty.toml new file mode 100644 index 0000000..e69de29 diff --git a/firefly_toml/tests/end_to_end.rs b/firefly_toml/tests/end_to_end.rs new file mode 100644 index 0000000..2c90c22 --- /dev/null +++ b/firefly_toml/tests/end_to_end.rs @@ -0,0 +1,18 @@ +mod badges { +use firefly_rust::{Badge, Peer, add_progress, Progress, Board}; +/// caused an unsoundness without unsafe code +pub fn segfault(peer: Peer, ) -> Progress { add_progress(peer, Badge(1), 1) } +/// found a secret +pub fn secret(peer: Peer, ) -> Progress { add_progress(peer, Badge(2), 1) } +}enum Cheats { +goto_level = 1, +}impl Cheats { fn from_id(id: i32) -> Self { match id { +1 => Self::goto_level, +_ => unreachable!(), +} } } +mod boards { +use firefly_rust::{Peer, add_score, Progress, Board}; +pub fn speedrun(peer: Peer, score: i16) -> i16 { add_score(peer, Board(3), score) } +pub fn level_1(peer: Peer, score: i16) -> i16 { add_score(peer, Board(1), score) } +pub fn level_2(peer: Peer, score: i16) -> i16 { add_score(peer, Board(2), score) } +} \ No newline at end of file diff --git a/firefly_toml/tests/end_to_end.toml b/firefly_toml/tests/end_to_end.toml new file mode 100644 index 0000000..a7e49ae --- /dev/null +++ b/firefly_toml/tests/end_to_end.toml @@ -0,0 +1,18 @@ +author_id = "ferris" +app_id = "crabtopia" +author_name = "Ferris" +app_name = "Crabtopia" +lang = "rust" + +[cheats] +goto-level = 1 + +[badges] +1 = { name = "segfault", descr = "caused an unsoundness without unsafe code" } +2 = { name = "secret", descr = "found a secret", hidden = 1 } + +[boards] +1 = { name = "level 1", min = -10000, max = 0, decimals = 3 } +2 = { name = "level 2", max = 10, time = true } + +3 = { name = "speedrun", min = -10000, max = 0 } diff --git a/src/lib.rs b/src/lib.rs index c80e4a7..39c71a8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -56,3 +56,6 @@ fn handle_panic(info: &core::panic::PanicInfo) -> ! { } core::arch::wasm32::unreachable() } + +#[cfg(feature = "macros")] +pub use firefly_toml::import;