Skip to content

Commit b2dd7e6

Browse files
authored
Merge pull request #60 from firefly-zero/bitsy
Bitsy
2 parents ef52a65 + 05eba91 commit b2dd7e6

4 files changed

Lines changed: 181 additions & 15 deletions

File tree

assets/main.bitsy

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
Write your game's title here
2+
3+
# BITSY VERSION 8.14
4+
5+
! VER_MAJ 8
6+
! VER_MIN 14
7+
! ROOM_FORMAT 1
8+
! DLG_COMPAT 0
9+
! TXT_MODE 0
10+
11+
PAL 0
12+
51,44,80
13+
226,243,228
14+
148,227,68
15+
NAME blueprint
16+
17+
ROOM 0
18+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
19+
0,a,a,a,a,a,a,a,a,a,a,a,a,a,a,0
20+
0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0
21+
0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0
22+
0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0
23+
0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0
24+
0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0
25+
0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0
26+
0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0
27+
0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0
28+
0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0
29+
0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0
30+
0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0
31+
0,a,0,0,0,0,0,0,0,0,0,0,0,0,a,0
32+
0,a,a,a,a,a,a,a,a,a,a,a,a,a,a,0
33+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
34+
NAME example room
35+
PAL 0
36+
37+
TIL a
38+
11111111
39+
10000001
40+
10000001
41+
10011001
42+
10011001
43+
10000001
44+
10000001
45+
11111111
46+
NAME block
47+
WAL true
48+
49+
SPR A
50+
00011000
51+
00011000
52+
00011000
53+
00111100
54+
01111110
55+
10111101
56+
00100100
57+
00100100
58+
POS 0 4,4
59+
60+
SPR a
61+
00000000
62+
00000000
63+
01010001
64+
01110001
65+
01110010
66+
01111100
67+
00111100
68+
00100100
69+
NAME cat
70+
DLG 0
71+
POS 0 8,12
72+
BLIP 1
73+
74+
ITM 0
75+
00000000
76+
00000000
77+
00000000
78+
00111100
79+
01100100
80+
00100100
81+
00011000
82+
00000000
83+
NAME tea
84+
DLG 1
85+
86+
ITM 1
87+
00000000
88+
00111100
89+
00100100
90+
00111100
91+
00010000
92+
00011000
93+
00010000
94+
00011000
95+
NAME key
96+
DLG 2
97+
BLIP 2
98+
99+
DLG 0
100+
I'm a cat
101+
NAME cat dialog
102+
103+
DLG 1
104+
You found a nice warm cup of tea
105+
NAME tea dialog
106+
107+
DLG 2
108+
A key! {wvy}What does it open?{wvy}
109+
NAME key dialog
110+
111+
VAR a
112+
42
113+
114+
BLIP 1
115+
E5,B5,B5
116+
NAME meow
117+
ENV 40 99 4 185 138
118+
BEAT 61 115
119+
SQR P2
120+
121+
BLIP 2
122+
D5,E5,D5
123+
NAME pick up key
124+
ENV 99 65 6 96 152
125+
BEAT 95 0
126+
SQR P4
127+

src/commands/new.rs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub fn cmd_new(args: &NewArgs) -> Result<()> {
3131
Lang::Python => bail!("Python is not supported yet"),
3232
Lang::Lua => new_lua(&args.name).context("new Lua project")?,
3333
Lang::Moon => new_moon(&args.name).context("new Moon project")?,
34+
Lang::Bitsy => new_bitsy(&args.name).context("new Bitsy project")?,
3435
}
3536
write_config(&lang, &args.name)?;
3637
init_git(&args.name)?;
@@ -52,9 +53,20 @@ fn write_config(lang: &Lang, name: &str) -> Result<()> {
5253
_ = writeln!(config, "author_name = \"{}\"", to_titlecase(&username));
5354
_ = writeln!(config, "app_name = \"{}\"", to_titlecase(name));
5455

55-
if matches!(lang, Lang::Lua) {
56-
_ = writeln!(config, "\n[files]");
57-
_ = writeln!(config, r#"main = {{ path = "main.lua", copy = true }}"#);
56+
match lang {
57+
Lang::Lua => {
58+
_ = writeln!(config, "\n[files]");
59+
_ = writeln!(config, r#"main = {{ path = "main.lua", copy = true }}"#);
60+
}
61+
Lang::Bitsy => {
62+
_ = writeln!(config, "\n[files]");
63+
_ = writeln!(config, r#"main = {{ path = "main.bitsy", copy = true }}"#);
64+
_ = writeln!(
65+
config,
66+
r#"font = {{ path = "eg_6x9.fff", url = "https://fonts.fireflyzero.com/fonts/ascii/eg_6x9.fff" }}"#
67+
);
68+
}
69+
_ => {}
5870
}
5971

6072
std::fs::write(config_path, config).context("write config")?;
@@ -77,7 +89,7 @@ fn init_git(name: &str) -> Result<()> {
7789
fn parse_lang(lang: &str) -> Result<Lang> {
7890
let result = match lang.to_lowercase().as_str() {
7991
"c" => Lang::C,
80-
"go" | "golang" => Lang::Go,
92+
"go" | "golang" | "tinygo" => Lang::Go,
8193
"rust" | "rs" => Lang::Rust,
8294
"zig" => Lang::Zig,
8395
"as" | "assemblyscript" => Lang::AS,
@@ -86,6 +98,7 @@ fn parse_lang(lang: &str) -> Result<Lang> {
8698
"python" | "py" => Lang::Python,
8799
"moon" | "moonbit" | "mbt" => Lang::Moon,
88100
"lua" => Lang::Lua,
101+
"bitsy" => Lang::Bitsy,
89102
_ => bail!("unsupported language: {lang}"),
90103
};
91104
Ok(result)
@@ -162,6 +175,14 @@ fn new_lua(name: &str) -> Result<()> {
162175
Ok(())
163176
}
164177

178+
/// Create a new Bitsy project.
179+
fn new_bitsy(name: &str) -> Result<()> {
180+
let mut c = Commander::default();
181+
c.cd(name)?;
182+
c.copy_asset(&["main.bitsy"], "main.bitsy")?;
183+
Ok(())
184+
}
185+
165186
/// Create a new Moon project.
166187
fn new_moon(name: &str) -> Result<()> {
167188
check_installed("Moon", "moon", "version")?;

src/config.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,15 @@ pub struct BoardConfig {
182182
#[derive(Deserialize, Debug, Clone)]
183183
#[serde(rename_all = "lowercase")]
184184
pub enum Lang {
185-
Go,
186-
Rust,
187-
Zig,
188-
AS,
189-
TS,
190-
C,
191-
Cpp,
192-
Python,
193-
Moon,
194-
Lua,
185+
Go, // 🏃
186+
Rust, // 🦀
187+
Zig, // ⚡️
188+
AS, // 🟦
189+
TS, // 🟦
190+
C, // 🐀
191+
Cpp, // 🐀
192+
Python, // 🐍
193+
Moon, // 🐰
194+
Lua, // 🌙
195+
Bitsy, // 🐈‍⬛
195196
}

src/langs.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub fn build_bin(config: &Config, args: &BuildArgs) -> anyhow::Result<()> {
3030
Lang::Cpp => build_cpp(config),
3131
Lang::Python => build_python(config),
3232
Lang::Lua => build_lua(config),
33+
Lang::Bitsy => build_bitsy(config),
3334
Lang::Moon => build_moon(config),
3435
}?;
3536
let bin_path = config.rom_path.join(BIN);
@@ -94,6 +95,12 @@ fn detect_lang(root: &Path) -> anyhow::Result<Lang> {
9495
if root.join("main.lua").exists() {
9596
return Ok(Lang::Lua);
9697
}
98+
if root.join("main.bitsy").exists() {
99+
return Ok(Lang::Bitsy);
100+
}
101+
if root.join("main.bitsy.txt").exists() {
102+
return Ok(Lang::Bitsy);
103+
}
97104
if root.join("src").join("main.c").exists() {
98105
return Ok(Lang::C);
99106
}
@@ -386,9 +393,19 @@ fn build_moon(config: &Config) -> anyhow::Result<()> {
386393

387394
// Build Lua project.
388395
fn build_lua(config: &Config) -> anyhow::Result<()> {
396+
let url = "https://github.com/firefly-zero/firefly-lua/releases/latest/download/main.wasm";
397+
build_interpreted(config, url)
398+
}
399+
400+
// Build Bitsy project.
401+
fn build_bitsy(config: &Config) -> anyhow::Result<()> {
402+
let url = "https://github.com/firefly-zero/firefly-bitsy/releases/latest/download/main.wasm";
403+
build_interpreted(config, url)
404+
}
405+
406+
fn build_interpreted(config: &Config, url: &str) -> anyhow::Result<()> {
389407
let from_path = config.root_path.join("main.wasm");
390408
if !from_path.is_file() {
391-
let url = "https://github.com/firefly-zero/firefly-lua/releases/latest/download/main.wasm";
392409
let resp = ureq::get(url).call().context("send request")?;
393410
let mut file = std::fs::File::create(&from_path).context("open main.wasm")?;
394411
let mut body = resp.into_body();

0 commit comments

Comments
 (0)