diff --git a/assets/main.bitsy b/assets/main.bitsy new file mode 100644 index 0000000..c24d9e6 --- /dev/null +++ b/assets/main.bitsy @@ -0,0 +1,127 @@ +Write your game's title here + +# BITSY VERSION 8.14 + +! VER_MAJ 8 +! VER_MIN 14 +! ROOM_FORMAT 1 +! DLG_COMPAT 0 +! TXT_MODE 0 + +PAL 0 +51,44,80 +226,243,228 +148,227,68 +NAME blueprint + +ROOM 0 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +0,a,a,a,a,a,a,a,a,a,a,a,a,a,a,0 +0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0 +0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0 +0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0 +0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0 +0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0 +0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0 +0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0 +0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0 +0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0 +0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0 +0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0 +0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0 +0,a,a,a,a,a,a,a,a,a,a,a,a,a,a,0 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +NAME example room +PAL 0 + +TIL a +11111111 +10000001 +10000001 +10011001 +10011001 +10000001 +10000001 +11111111 +NAME block +WAL true + +SPR A +00011000 +00011000 +00011000 +00111100 +01111110 +10111101 +00100100 +00100100 +POS 0 4,4 + +SPR a +00000000 +00000000 +01010001 +01110001 +01110010 +01111100 +00111100 +00100100 +NAME cat +DLG 0 +POS 0 8,12 +BLIP 1 + +ITM 0 +00000000 +00000000 +00000000 +00111100 +01100100 +00100100 +00011000 +00000000 +NAME tea +DLG 1 + +ITM 1 +00000000 +00111100 +00100100 +00111100 +00010000 +00011000 +00010000 +00011000 +NAME key +DLG 2 +BLIP 2 + +DLG 0 +I'm a cat +NAME cat dialog + +DLG 1 +You found a nice warm cup of tea +NAME tea dialog + +DLG 2 +A key! {wvy}What does it open?{wvy} +NAME key dialog + +VAR a +42 + +BLIP 1 +E5,B5,B5 +NAME meow +ENV 40 99 4 185 138 +BEAT 61 115 +SQR P2 + +BLIP 2 +D5,E5,D5 +NAME pick up key +ENV 99 65 6 96 152 +BEAT 95 0 +SQR P4 + diff --git a/src/commands/new.rs b/src/commands/new.rs index f7491b4..9550f9b 100644 --- a/src/commands/new.rs +++ b/src/commands/new.rs @@ -31,6 +31,7 @@ pub fn cmd_new(args: &NewArgs) -> Result<()> { Lang::Python => bail!("Python is not supported yet"), Lang::Lua => new_lua(&args.name).context("new Lua project")?, Lang::Moon => new_moon(&args.name).context("new Moon project")?, + Lang::Bitsy => new_bitsy(&args.name).context("new Bitsy project")?, } write_config(&lang, &args.name)?; init_git(&args.name)?; @@ -52,9 +53,20 @@ fn write_config(lang: &Lang, name: &str) -> Result<()> { _ = writeln!(config, "author_name = \"{}\"", to_titlecase(&username)); _ = writeln!(config, "app_name = \"{}\"", to_titlecase(name)); - if matches!(lang, Lang::Lua) { - _ = writeln!(config, "\n[files]"); - _ = writeln!(config, r#"main = {{ path = "main.lua", copy = true }}"#); + match lang { + Lang::Lua => { + _ = writeln!(config, "\n[files]"); + _ = writeln!(config, r#"main = {{ path = "main.lua", copy = true }}"#); + } + Lang::Bitsy => { + _ = writeln!(config, "\n[files]"); + _ = writeln!(config, r#"main = {{ path = "main.bitsy", copy = true }}"#); + _ = writeln!( + config, + r#"font = {{ path = "eg_6x9.fff", url = "https://fonts.fireflyzero.com/fonts/ascii/eg_6x9.fff" }}"# + ); + } + _ => {} } std::fs::write(config_path, config).context("write config")?; @@ -77,7 +89,7 @@ fn init_git(name: &str) -> Result<()> { fn parse_lang(lang: &str) -> Result { let result = match lang.to_lowercase().as_str() { "c" => Lang::C, - "go" | "golang" => Lang::Go, + "go" | "golang" | "tinygo" => Lang::Go, "rust" | "rs" => Lang::Rust, "zig" => Lang::Zig, "as" | "assemblyscript" => Lang::AS, @@ -86,6 +98,7 @@ fn parse_lang(lang: &str) -> Result { "python" | "py" => Lang::Python, "moon" | "moonbit" | "mbt" => Lang::Moon, "lua" => Lang::Lua, + "bitsy" => Lang::Bitsy, _ => bail!("unsupported language: {lang}"), }; Ok(result) @@ -162,6 +175,14 @@ fn new_lua(name: &str) -> Result<()> { Ok(()) } +/// Create a new Bitsy project. +fn new_bitsy(name: &str) -> Result<()> { + let mut c = Commander::default(); + c.cd(name)?; + c.copy_asset(&["main.bitsy"], "main.bitsy")?; + Ok(()) +} + /// Create a new Moon project. fn new_moon(name: &str) -> Result<()> { check_installed("Moon", "moon", "version")?; diff --git a/src/config.rs b/src/config.rs index 10bde2d..ff386bf 100644 --- a/src/config.rs +++ b/src/config.rs @@ -182,14 +182,15 @@ pub struct BoardConfig { #[derive(Deserialize, Debug, Clone)] #[serde(rename_all = "lowercase")] pub enum Lang { - Go, - Rust, - Zig, - AS, - TS, - C, - Cpp, - Python, - Moon, - Lua, + Go, // 🏃 + Rust, // 🦀 + Zig, // ⚡️ + AS, // 🟦 + TS, // 🟦 + C, // 🐀 + Cpp, // 🐀 + Python, // 🐍 + Moon, // 🐰 + Lua, // 🌙 + Bitsy, // 🐈‍⬛ } diff --git a/src/langs.rs b/src/langs.rs index 41b02d4..4798070 100644 --- a/src/langs.rs +++ b/src/langs.rs @@ -30,6 +30,7 @@ pub fn build_bin(config: &Config, args: &BuildArgs) -> anyhow::Result<()> { Lang::Cpp => build_cpp(config), Lang::Python => build_python(config), Lang::Lua => build_lua(config), + Lang::Bitsy => build_bitsy(config), Lang::Moon => build_moon(config), }?; let bin_path = config.rom_path.join(BIN); @@ -94,6 +95,12 @@ fn detect_lang(root: &Path) -> anyhow::Result { if root.join("main.lua").exists() { return Ok(Lang::Lua); } + if root.join("main.bitsy").exists() { + return Ok(Lang::Bitsy); + } + if root.join("main.bitsy.txt").exists() { + return Ok(Lang::Bitsy); + } if root.join("src").join("main.c").exists() { return Ok(Lang::C); } @@ -386,9 +393,19 @@ fn build_moon(config: &Config) -> anyhow::Result<()> { // Build Lua project. fn build_lua(config: &Config) -> anyhow::Result<()> { + let url = "https://github.com/firefly-zero/firefly-lua/releases/latest/download/main.wasm"; + build_interpreted(config, url) +} + +// Build Bitsy project. +fn build_bitsy(config: &Config) -> anyhow::Result<()> { + let url = "https://github.com/firefly-zero/firefly-bitsy/releases/latest/download/main.wasm"; + build_interpreted(config, url) +} + +fn build_interpreted(config: &Config, url: &str) -> anyhow::Result<()> { let from_path = config.root_path.join("main.wasm"); if !from_path.is_file() { - let url = "https://github.com/firefly-zero/firefly-lua/releases/latest/download/main.wasm"; let resp = ureq::get(url).call().context("send request")?; let mut file = std::fs::File::create(&from_path).context("open main.wasm")?; let mut body = resp.into_body();