Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions assets/main.bitsy
Original file line number Diff line number Diff line change
@@ -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

29 changes: 25 additions & 4 deletions src/commands/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand All @@ -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")?;
Expand All @@ -77,7 +89,7 @@ fn init_git(name: &str) -> Result<()> {
fn parse_lang(lang: &str) -> Result<Lang> {
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,
Expand All @@ -86,6 +98,7 @@ fn parse_lang(lang: &str) -> Result<Lang> {
"python" | "py" => Lang::Python,
"moon" | "moonbit" | "mbt" => Lang::Moon,
"lua" => Lang::Lua,
"bitsy" => Lang::Bitsy,
_ => bail!("unsupported language: {lang}"),
};
Ok(result)
Expand Down Expand Up @@ -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")?;
Expand Down
21 changes: 11 additions & 10 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, // 🐈‍⬛
}
19 changes: 18 additions & 1 deletion src/langs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -94,6 +95,12 @@ fn detect_lang(root: &Path) -> anyhow::Result<Lang> {
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);
}
Expand Down Expand Up @@ -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();
Expand Down