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	Sun Aug 11 19:55:45 2019 +0200
+++ b/examples/eclrenderer.rs	Sun Aug 11 20:14:20 2019 +0200
@@ -91,14 +91,15 @@
 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	Sun Aug 11 19:55:45 2019 +0200
+++ b/src/th06/ecl.rs	Sun Aug 11 20:14:20 2019 +0200
@@ -28,6 +28,20 @@
     }
 }
 
+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	Sun Aug 11 19:55:45 2019 +0200
+++ b/src/th06/ecl_vm.rs	Sun Aug 11 20:14:20 2019 +0200
@@ -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	Sun Aug 11 19:55:45 2019 +0200
+++ b/src/th06/enemy.rs	Sun Aug 11 20:14:20 2019 +0200
@@ -303,9 +303,10 @@
         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());