better example program

This commit is contained in:
Max Bradbury 2020-04-19 07:34:11 +01:00
parent ffed88429b
commit dacccdc100
2 changed files with 14 additions and 26 deletions

14
src/bin/bitsy-validate.rs Normal file
View File

@ -0,0 +1,14 @@
extern crate bitsy_parser;
use bitsy_parser::game::Game;
use bitsy_parser::image::Image;
use std::{env, fs};
fn main() {
let input_file = env::args()
.nth(1)
.expect("No input path specified. Usage: `smiley infile outfile`");
Game::from(fs::read_to_string(input_file).unwrap()).unwrap();
println!("OK!");
}

View File

@ -1,26 +0,0 @@
extern crate bitsy_parser;
use bitsy_parser::game::Game;
use bitsy_parser::image::Image;
use std::{env, fs};
/// replaces the player avatar with a smiley face.
fn main() {
let input_file = env::args()
.nth(1)
.expect("No input path specified. Usage: `smiley infile outfile`");
let output_file = env::args()
.nth(2)
.expect("No output path specified. Usage: `smiley infile outfile`");
let mut game = Game::from(fs::read_to_string(input_file).unwrap()).unwrap();
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");
}