Mercurial > touhou
changeset 665:965ecdbf0316
Make rank user-defined in eclrenderer.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 11 Aug 2019 20:14:20 +0200 |
parents | f08e8e3c6196 |
children | 838d9402b12f |
files | examples/eclrenderer.rs src/th06/ecl.rs src/th06/ecl_vm.rs src/th06/enemy.rs |
diffstat | 4 files changed, 24 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/examples/eclrenderer.rs +++ b/examples/eclrenderer.rs @@ -91,14 +91,15 @@ struct ShaderInterface { fn main() { // Parse arguments. let args: Vec<_> = env::args().collect(); - if args.len() != 5 { - eprintln!("Usage: {} <ECL file> <sub number> <ANM file> <PNG file>", args[0]); + if args.len() != 6 { + eprintln!("Usage: {} <ECL file> <ANM file> <PNG file> <easy|normal|hard|lunatic> <sub number>", args[0]); return; } let ecl_filename = &args[1]; - let sub: u8 = args[2].parse().expect("number"); - let anm_filename = &args[3]; - let png_filename = &args[4]; + let anm_filename = &args[2]; + let png_filename = &args[3]; + let rank: Rank = args[4].parse().expect("rank"); + let sub: u8 = args[5].parse().expect("number"); // Open the ECL file. let file = File::open(ecl_filename).unwrap();
--- a/src/th06/ecl.rs +++ b/src/th06/ecl.rs @@ -28,6 +28,20 @@ bitflags! { } } +impl std::str::FromStr for Rank { + type Err = String; + + fn from_str(s: &str) -> Result<Rank, Self::Err> { + Ok(match s { + "easy" => Rank::Easy, + "normal" => Rank::Normal, + "hard" => Rank::Hard, + "lunatic" => Rank::Lunatic, + _ => return Err(format!("unknown rank {}", s)) + }) + } +} + /// A single instruction, part of a `Script`. #[derive(Debug, Clone)] pub struct CallSub {
--- a/src/th06/ecl_vm.rs +++ b/src/th06/ecl_vm.rs @@ -1,6 +1,6 @@ //! ECL runner. -use crate::th06::ecl::{Ecl, SubInstruction, Rank}; +use crate::th06::ecl::{Ecl, SubInstruction}; use crate::th06::enemy::Enemy; use crate::util::prng::Prng; use std::cell::RefCell;
--- a/src/th06/enemy.rs +++ b/src/th06/enemy.rs @@ -303,9 +303,10 @@ mod tests { let anm0 = Anm0::from_slice(&buf).unwrap(); let anm0 = Rc::new(RefCell::new(anm0)); let prng = Rc::new(RefCell::new(Prng::new(0))); - let game = Game::new(prng); + let game = Game::new(prng, Rank::Easy); let game = Rc::new(RefCell::new(game)); - let mut enemy = Enemy::new(Position::new(0., 0.), 500, 0, 640, Rc::downgrade(&anm0), Rc::downgrade(&game)); + let enemy = Enemy::new(Position::new(0., 0.), 500, 0, 640, Rc::downgrade(&anm0), Rc::downgrade(&game)); + let mut enemy = enemy.borrow_mut(); assert!(enemy.anmrunner.upgrade().is_none()); enemy.set_anim(0); assert!(enemy.anmrunner.upgrade().is_some());