2020-04-11 15:08:57 +00:00
|
|
|
# bitsy-parser
|
2020-04-05 17:58:04 +00:00
|
|
|
|
2020-04-18 16:00:03 +00:00
|
|
|
![Rust](https://github.com/synth-ruiner/bitsy-parser/workflows/Rust/badge.svg)
|
2020-04-18 16:05:37 +00:00
|
|
|
![](https://img.shields.io/badge/license-MIT-blueviolet.svg)
|
|
|
|
[![Crates.io](https://img.shields.io/crates/v/bitsy-parser.svg)](https://crates.io/crates/bitsy-parser)
|
2020-04-18 16:00:03 +00:00
|
|
|
|
2020-04-05 17:58:04 +00:00
|
|
|
a library for parsing Bitsy game data.
|
|
|
|
|
2020-04-30 21:18:43 +00:00
|
|
|
the version number follows Bitsy itself, so version 0.70.* targets Bitsy 7.0.
|
2020-04-12 13:48:43 +00:00
|
|
|
|
2020-04-12 16:13:08 +00:00
|
|
|
## how to use
|
|
|
|
|
2020-04-13 18:28:22 +00:00
|
|
|
a simple example program:
|
|
|
|
|
2020-04-12 16:13:08 +00:00
|
|
|
```rust
|
|
|
|
extern crate bitsy_parser;
|
|
|
|
use std::{env, fs};
|
|
|
|
use bitsy_parser::game::Game;
|
|
|
|
use bitsy_parser::image::Image;
|
|
|
|
|
|
|
|
/// replaces the player avatar with a smiley face.
|
|
|
|
fn main() {
|
|
|
|
let input_file = env::args().nth(1)
|
2020-04-12 16:17:39 +00:00
|
|
|
.expect("No input path specified. Usage: `smiley infile outfile`");
|
2020-04-12 16:13:08 +00:00
|
|
|
let output_file = env::args().nth(2)
|
2020-04-12 16:17:39 +00:00
|
|
|
.expect("No output path specified. Usage: `smiley infile outfile`");
|
2020-04-12 16:13:08 +00:00
|
|
|
|
2020-04-19 06:28:52 +00:00
|
|
|
let mut game = Game::from(fs::read_to_string(input_file).unwrap()).unwrap();
|
2020-04-12 16:13:08 +00:00
|
|
|
|
|
|
|
game.avatar.animation_frames = vec![
|
|
|
|
Image {
|
|
|
|
pixels: vec![
|
|
|
|
0,0,1,1,1,1,0,0,
|
|
|
|
0,1,1,1,1,1,1,0,
|
|
|
|
1,1,0,1,1,0,1,1,
|
|
|
|
1,1,0,1,1,0,1,1,
|
|
|
|
1,1,1,1,1,1,1,1,
|
|
|
|
1,1,0,1,1,0,1,1,
|
|
|
|
0,1,1,0,0,1,1,0,
|
|
|
|
0,0,1,1,1,1,0,0,
|
|
|
|
]
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
fs::write(output_file, &game.to_string())
|
|
|
|
.expect("Failed to write to output file");
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
some more practical uses would be things like:
|
|
|
|
|
|
|
|
* remove duplicate tiles
|
|
|
|
* merge two Bitsy games together
|
|
|
|
* programmatically create Bitsy games
|
|
|
|
* a Bitsy game editor
|
|
|
|
|
2020-04-05 17:58:04 +00:00
|
|
|
## todo
|
|
|
|
|
2020-04-13 23:41:28 +00:00
|
|
|
* implement Result return types on ::from functions so we can handle errors
|
2020-04-29 07:27:35 +00:00
|
|
|
* replace Image with Vec<u8> or something. seems like a pointless abstraction
|
2020-06-18 16:48:25 +00:00
|
|
|
* replace game avatar with helper functions to get and set the sprite with an ID of A
|
2020-04-13 23:41:28 +00:00
|
|
|
|
2020-04-05 18:04:17 +00:00
|
|
|
### tidy up
|
|
|
|
|
2020-04-12 13:38:07 +00:00
|
|
|
* refactor the more shonky bits to idiomatic rust
|