Mercurial > touhou
view examples/dump_ecl.rs @ 756:4d91790cf8ab
Fix dump_ecl example.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Tue, 05 Jan 2021 01:14:52 +0100 |
parents | eea03c9ca604 |
children |
line wrap: on
line source
use touhou::th06::ecl::{Ecl, CallMain, CallSub, Rank}; use std::env; use std::path::Path; #[path = "common.rs"] mod common; use common::{load_file_into_vec}; fn format_rank(rank: &Rank) -> String { format!("{}{}{}{}", if rank.contains(Rank::EASY) { 'E' } else { ' ' }, if rank.contains(Rank::NORMAL) { 'N' } else { ' ' }, if rank.contains(Rank::HARD) { 'H' } else { ' ' }, if rank.contains(Rank::LUNATIC) { 'L' } else { ' ' }) } fn print_sub_instruction(call: &CallSub) { let CallSub { time, rank_mask, param_mask: _, instr } = call; println!(" {:>5}: {}: {:?}", time, format_rank(rank_mask), instr); } fn print_main_instruction(call: &CallMain) { let CallMain { time, sub, instr } = call; println!(" {:>5}: sub {:>2}: {:?}", time, sub, instr); } fn main() { // Parse arguments. let args: Vec<_> = env::args().collect(); if args.len() != 2 { eprintln!("Usage: {} <ECL file>", args[0]); return; } let ecl_filename = Path::new(&args[1]); // Open the ECL file. let buf = load_file_into_vec(ecl_filename).unwrap(); let (_, ecl) = Ecl::from_slice(&buf).unwrap(); for (i, main) in ecl.mains.iter().enumerate() { println!("Main {} {{", i); for call in main.instructions.iter() { print_main_instruction(call); } println!("}}"); println!(); } for (i, sub) in ecl.subs.iter().enumerate() { println!("Sub {} {{", i); for call in sub.instructions.iter() { print_sub_instruction(call); } println!("}}"); println!(); } }