diff --git a/import.rs b/import.rs deleted file mode 100644 index b029839..0000000 --- a/import.rs +++ /dev/null @@ -1,237 +0,0 @@ -// Parses data files into their respective enums -// and functions -// TODO: parse response from https://m.bulbapedia.bulbagarden.net/wiki/List_of_Pok%C3%A9mon_by_effort_value_yield_(Generation_IX) in order to gather experience abd effort value constants - -#![allow(unused_must_use)] -#![allow(unused_mut)] - -use std::fs; -use std::io::prelude::*; -use std::iter::Iterator; -use std::*; - -fn main() { - // real names in English - let mut real_names = fs::read_to_string("realnames.txt") - .unwrap_or_else(|_| { - panic!("`realnames.txt` does not exist in directory."); - }) - .lines() - .map(String::from) - .collect::>(); - - // Simplified names without problematic characters - let mut enum_names = fs::read_to_string("enumnames.txt") - .unwrap_or_else(|_| { - panic!("`enumnames.txt` does not exist in directory."); - }) - .lines() - .map(String::from) - .collect::>(); - - // Type 1, Type 2 (if any) - let mut battle_types = fs::read_to_string("types.txt") - .unwrap_or_else(|_| { - panic!("`types.txt` does not exist in directory."); - }) - .lines() - .map(String::from) - .collect::>(); - - // HP,Attack,Defense,Sp.Attack,Sp.Defense,Speed - let mut base_stats = fs::read_to_string("stats.txt") - .unwrap_or_else(|_| { - panic!("`stats.txt` does not exist in directory."); - }) - .lines() - .map(String::from) - .collect::>(); - - let mut pimpl = fs::File::create("mons_impl.part").unwrap(); - let mut penum = fs::File::create("mons_enum.part").unwrap(); - let mut pfuncs = fs::File::create("mons_funcs.part").unwrap(); - - pimpl.set_len(0); - penum.set_len(0); - pfuncs.set_len(0); - - let mut dex: Vec = Vec::new(); - let mut rname_vec = Vec::new(); - rname_vec.push("None".to_string()); - let mut ename_vec = Vec::new(); - ename_vec.push("None".to_string()); - let mut types_vec = Vec::new(); - - // Gather real names and type names - let mut curvec: Vec; - let mut curnamevec: Vec; - for i in 0..real_names.len() { - let rline = real_names[i].clone().chars().collect::>(); - let eline_chars = enum_names[i].clone().chars().collect::>(); - let mut e_idx = 0; - curvec = Vec::new(); - curnamevec = Vec::new(); - for (i, rchar) in rline.clone().iter().enumerate() { - let echar = match i > eline_chars.len() - 1 { - true => ' ', - false => eline_chars[e_idx], - }; - - if echar as u8 >= b'0' && echar as u8 <= b'9' && i < 6 { - curvec.push(echar); - } else if echar == ',' { - dex.push( - curvec - .clone() - .into_iter() - .skip_while(|&ch| ch == '0') - .collect::() - .parse() - .unwrap(), - ); - curvec = Vec::new(); - } else { - curvec.push(echar.clone()); - curnamevec.push(rchar.clone()); - } - - e_idx += 1; - } - - ename_vec.push(curvec.iter().collect::()); - rname_vec.push(curnamevec.iter().collect::()); - } - - // populate types - for i in 0..battle_types.len() { - types_vec.push( - battle_types[i] - .split(',') - .map(String::from) - .collect::>() - .iter() - .map(|word| { - if word.len() > 1 { - format!("BattleType::{}", word).clone() - } else { - "BattleType::None".to_string() - } - }) - .collect::>(), - ); - } - - let mut code = String::new(); - - // |Start| source file - code.push_str("#![allow(snake_case)]\n"); - code.push_str("#![allow(non_camel_case_types)]\n"); - code.push_str("#![allow(unused_variables)]\n"); - code.push_str("#![allow(non_upper_case_globals)]\n"); - code.push_str("#![allow(unused_variables)]\n\n"); - - code.push_str("\n\nuse crate::types::BattleType;\n"); - - code.push_str("\n\n#[derive(Debug, Clone, Copy)]\n"); - code.push_str("pub enum Pokemon {\n"); - for word in ename_vec.iter() { - code.push_str(format!("\t{},\n", word).as_str()); - } - code.push_str("}\n\n"); - - code.push_str("pub const Pokemon: [Pokemon; 1026] = [\n"); - for word in ename_vec.iter() { - code.push_str(format!("\tcrate::Pokemon::{},\n", word).as_str()); - } - code.push_str("];\n\n"); - - penum.write(code.as_bytes()); - - code = String::new(); - - // impl block - code.push_str("impl Pokemon {\n"); - - // get dex number ( just cast it to a primitive lol ) - code.push_str("\tpub fn dex(&self) -> u16 {\n"); - code.push_str("\t\t*self as u16\n"); - code.push_str("\t}\n\n"); - - // get name string - code.push_str("\t\tpub fn name(&self) -> String {\n"); - code.push_str("\t\tmatch self {\n"); - for i in 0..ename_vec.len() { - code.push_str( - format!( - "\t\t\tSelf::{} => \"{}\".to_string(),\n", - ename_vec[i], rname_vec[i] - ) - .as_str(), - ); - } - code.push_str("\t\t\t_ => String::new(),\n"); - code.push_str("\t\t}\n"); - code.push_str("\t}\n\n"); - - // get base stats - code.push_str("\tpub fn base_stats(&self) -> [u8; 6] {\n"); - code.push_str("\t\tmatch self {\n"); - for i in 0..ename_vec.len() { - if i == 0 { - code.push_str("\t\t\tSelf::None => [0u8,0u8,0u8,0u8,0u8,0u8],\n"); - continue; - } - code.push_str( - format!("\t\t\tSelf::{} => [{}],\n", ename_vec[i], base_stats[i - 1]).as_str(), - ); - } - code.push_str("\t\t\t_ => [0u8,0u8,0u8,0u8,0u8,0u8],\n"); - code.push_str("\t\t}\n"); - code.push_str("\t}\n\n"); - - // get type(s) of pokemon - code.push_str("\t\tpub fn types(&self) -> [BattleType; 2] {\n"); - code.push_str("\t\tmatch self {\n"); - for i in 0..ename_vec.len() { - if i == 0 { - code.push_str("\t\t\tSelf::None => [BattleType::None, BattleType::None],\n"); - continue; - } - code.push_str( - format!( - "\t\t\tSelf::{} => [{}, {}],\n", - ename_vec[i], - types_vec[i - 1][0], - types_vec[i - 1][1] - ) - .as_str(), - ); - } - code.push_str("\t\t\t_ => { println!(\"Unknown Pokémon ID. \"); [BattleType::None, BattleType::None] },\n"); - code.push_str("\t\t}\n"); - code.push_str("\t}\n\n"); - - // code.push_str("\tpub fn body_type - - // close impl - code.push_str("}\n\n"); - - pimpl.write(code.as_bytes()); - code = String::new(); - - // get Pokemon from dex number (made obsolete by `pub const Pokemon: [Pokemon; 1026] = ...` - code.push_str("pub fn mon_at_dex(dex: usize) -> Pokemon {\n"); - code.push_str("\tmatch dex as u16 {\n"); - for i in 0..dex.len() + 1 { - if i == 0 { - code.push_str("\t\t0u16 => Pokemon::None,\n"); - continue; - } - code.push_str(format!("\t\t{} => Pokemon::{},\n", dex[i - 1], ename_vec[i]).as_str()); - } - code.push_str("\t\t_ => { println!(\"Invalid dex number. \"); Pokemon::Bulbasaur },\n"); - code.push_str("\t}\n}\n\n"); - - pfuncs.write(code.as_bytes()); - println!("End of code generation."); -} diff --git a/import.sh b/import.sh deleted file mode 100755 index 6784e02..0000000 --- a/import.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -rustc import.rs -o import && \ -./import && \ -cat mons_enum.part mons_impl.part mons_funcs.part > src/mons.rs && \ -echo "Import successful." diff --git a/src/main.rs b/src/main.rs index c08197c..30dea13 100644 --- a/src/main.rs +++ b/src/main.rs @@ -54,6 +54,7 @@ use std::path::{Path, PathBuf}; #[allow(unused_imports)] use ratatui::{ + symbols::border::Set, backend::CrosstermBackend, layout::{Constraint, Direction, Layout, Rect}, style::{Color::{self, *}, Style}, @@ -94,7 +95,7 @@ use std::result::Result; #[derive(Debug, Clone)] struct Options { frame_color: Color, - frame_style: BorderType, + frame_style: ratatui::symbols::border::Set, text_speed: u8, } @@ -301,7 +302,7 @@ pub fn main_menu( let mut options_state = Options { frame_color: Color::White, - frame_style: BorderType::Plain, + frame_style: BorderType::Plain.to_border_set(), text_speed: 0, }; @@ -414,7 +415,7 @@ pub fn main_menu( .title("MENU (Press 'c'/End to exit)") .title_bottom("--ENTER key to select--") .borders(Borders::ALL) - .border_type(options_state.frame_style.clone()) + .border_set(options_state.frame_style.clone()) .style(Style::default().fg(options_state.frame_color.clone())), ); @@ -445,12 +446,14 @@ pub fn options_menu( let mut options = options_state.clone(); let borders = vec![ - BorderType::Plain, - BorderType::Rounded, - BorderType::Double, - BorderType::Thick, - BorderType::QuadrantInside, - BorderType::QuadrantOutside, + BorderType::Plain.to_border_set(), + BorderType::Rounded.to_border_set(), + BorderType::Double.to_border_set(), + BorderType::Thick.to_border_set(), + BorderType::QuadrantInside.to_border_set(), + BorderType::QuadrantOutside.to_border_set(), + CUSTOM_BORDER1.clone(), + CUSTOM_BORDER2.clone(), ]; let colors = vec![ @@ -633,7 +636,7 @@ pub fn options_menu( .title("OPTIONS (Press 'c'/End to go back)") .title_bottom("--ENTER key to confirm--") .borders(Borders::ALL) - .border_type(borders[border_index]) + .border_set(borders[border_index]) .style(Style::default().fg(colors[color_index])), ); @@ -656,8 +659,26 @@ pub fn options_menu( options } - - +const CUSTOM_BORDER1: Set = Set { + top_left: r"\", + top_right: r"/", + bottom_left: r"/", + bottom_right: r"\", + vertical_left: r"│", + vertical_right: r"│", + horizontal_top: r"─", + horizontal_bottom: r"─", +}; +const CUSTOM_BORDER2: Set = Set { + top_left: r"o", + top_right: r"o", + bottom_left: r"°", + bottom_right: r"°", + vertical_left: r"│", + vertical_right: r"│", + horizontal_top: r"─", + horizontal_bottom: r"─", +}; // COPYRIGHT MESSAGE @@ -710,7 +731,8 @@ fn main() -> Result<(), io::Error> { .unwrap(); let timeout: u64 = 17; //60 fps - let limit = (2000/17); //5 seconds ( accounting for msg_pause ) + let pause_time = 3000; + let limit = ((5000 - pause_time)/timeout); let mut msg_pause: u64 = 0; let start_time = Instant::now(); @@ -724,7 +746,7 @@ fn main() -> Result<(), io::Error> { if step == (limit/2) { - msg_pause += 3000; + msg_pause += pause_time; message_sound.resume(); if poll(Duration::from_millis(0))? {