mirror of
https://github.com/doukutsu-rs/doukutsu-rs
synced 2025-11-29 15:56:53 +00:00
refactor stuff to make code cleaner
This commit is contained in:
parent
0c33795356
commit
657b73aefc
|
|
@ -1,7 +1,7 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::io::{BufRead, BufReader, Cursor, Read};
|
use std::io::{BufRead, BufReader, Cursor, Read};
|
||||||
|
|
||||||
use byteorder::{LE, ReadBytesExt};
|
use byteorder::{ReadBytesExt, LE};
|
||||||
use case_insensitive_hashmap::CaseInsensitiveHashMap;
|
use case_insensitive_hashmap::CaseInsensitiveHashMap;
|
||||||
use xmltree::Element;
|
use xmltree::Element;
|
||||||
|
|
||||||
|
|
@ -303,6 +303,7 @@ pub struct EngineConstants {
|
||||||
pub credit_illustration_paths: Vec<String>,
|
pub credit_illustration_paths: Vec<String>,
|
||||||
pub animated_face_table: Vec<AnimatedFace>,
|
pub animated_face_table: Vec<AnimatedFace>,
|
||||||
pub string_table: HashMap<String, String>,
|
pub string_table: HashMap<String, String>,
|
||||||
|
pub missile_flags: Vec<u16>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clone for EngineConstants {
|
impl Clone for EngineConstants {
|
||||||
|
|
@ -332,6 +333,7 @@ impl Clone for EngineConstants {
|
||||||
credit_illustration_paths: self.credit_illustration_paths.clone(),
|
credit_illustration_paths: self.credit_illustration_paths.clone(),
|
||||||
animated_face_table: self.animated_face_table.clone(),
|
animated_face_table: self.animated_face_table.clone(),
|
||||||
string_table: self.string_table.clone(),
|
string_table: self.string_table.clone(),
|
||||||
|
missile_flags: self.missile_flags.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1606,6 +1608,7 @@ impl EngineConstants {
|
||||||
],
|
],
|
||||||
animated_face_table: vec![AnimatedFace { face_id: 0, anim_id: 0, anim_frames: vec![(0, 0)] }],
|
animated_face_table: vec![AnimatedFace { face_id: 0, anim_id: 0, anim_frames: vec![(0, 0)] }],
|
||||||
string_table: HashMap::new(),
|
string_table: HashMap::new(),
|
||||||
|
missile_flags: vec![200, 201, 202, 218, 550, 766, 880, 920, 1551],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -437,18 +437,13 @@ impl Menu {
|
||||||
|
|
||||||
// Difficulty
|
// Difficulty
|
||||||
if state.constants.is_cs_plus && !state.settings.original_textures {
|
if state.constants.is_cs_plus && !state.settings.original_textures {
|
||||||
let difficulty = GameDifficulty::from_save_value(save.difficulty);
|
let difficulty = GameDifficulty::from_primitive(save.difficulty);
|
||||||
|
|
||||||
let batch = state.texture_set.get_or_load_batch(ctx, &state.constants, "MyChar")?;
|
let batch = state.texture_set.get_or_load_batch(ctx, &state.constants, "MyChar")?;
|
||||||
batch.add_rect(
|
batch.add_rect(
|
||||||
self.x as f32 + 20.0,
|
self.x as f32 + 20.0,
|
||||||
y + 10.0,
|
y + 10.0,
|
||||||
&Rect::new_size(
|
&Rect::new_size(0, (difficulty as u16).saturating_mul(2 * 16), 16, 16),
|
||||||
0,
|
|
||||||
GameDifficulty::get_skinsheet_offset(difficulty).saturating_mul(4 * 16),
|
|
||||||
16,
|
|
||||||
16,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
batch.draw(ctx)?;
|
batch.draw(ctx)?;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -149,8 +149,18 @@ impl SaveSelectMenu {
|
||||||
MenuSelectionResult::Selected(4, _) | MenuSelectionResult::Canceled => {
|
MenuSelectionResult::Selected(4, _) | MenuSelectionResult::Canceled => {
|
||||||
self.current_menu = CurrentMenu::SaveMenu;
|
self.current_menu = CurrentMenu::SaveMenu;
|
||||||
}
|
}
|
||||||
MenuSelectionResult::Selected(item, _) => {
|
MenuSelectionResult::Selected(1, _) => {
|
||||||
state.difficulty = GameDifficulty::from_index(item - 1);
|
state.difficulty = GameDifficulty::Easy;
|
||||||
|
state.reload_resources(ctx)?;
|
||||||
|
state.load_or_start_game(ctx)?;
|
||||||
|
}
|
||||||
|
MenuSelectionResult::Selected(2, _) => {
|
||||||
|
state.difficulty = GameDifficulty::Normal;
|
||||||
|
state.reload_resources(ctx)?;
|
||||||
|
state.load_or_start_game(ctx)?;
|
||||||
|
}
|
||||||
|
MenuSelectionResult::Selected(3, _) => {
|
||||||
|
state.difficulty = GameDifficulty::Hard;
|
||||||
state.reload_resources(ctx)?;
|
state.reload_resources(ctx)?;
|
||||||
state.load_or_start_game(ctx)?;
|
state.load_or_start_game(ctx)?;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ impl NPC {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn tick_n015_chest_closed(&mut self, state: &mut SharedGameState, npc_list: &NPCList) -> GameResult {
|
pub(crate) fn tick_n015_chest_closed(&mut self, state: &mut SharedGameState, npc_list: &NPCList) -> GameResult {
|
||||||
if state.difficulty == GameDifficulty::Hard && self.chest_has_missile_flag() {
|
if state.difficulty == GameDifficulty::Hard && state.constants.missile_flags.contains(&self.flag_num) {
|
||||||
self.cond.set_alive(false);
|
self.cond.set_alive(false);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
@ -337,7 +337,7 @@ impl NPC {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn tick_n021_chest_open(&mut self, state: &mut SharedGameState) -> GameResult {
|
pub(crate) fn tick_n021_chest_open(&mut self, state: &mut SharedGameState) -> GameResult {
|
||||||
if state.difficulty == GameDifficulty::Hard && self.chest_has_missile_flag() {
|
if state.difficulty == GameDifficulty::Hard && state.constants.missile_flags.contains(&self.flag_num) {
|
||||||
self.cond.set_alive(false);
|
self.cond.set_alive(false);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
@ -2624,9 +2624,4 @@ impl NPC {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn chest_has_missile_flag(&self) -> bool {
|
|
||||||
let missile_flags: [u16; 9] = [200, 201, 202, 218, 550, 766, 880, 920, 1551];
|
|
||||||
missile_flags.contains(&self.flag_num)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,7 @@ impl BasicPlayerSkin {
|
||||||
fn get_y_offset_by(&self, y: u16) -> u16 {
|
fn get_y_offset_by(&self, y: u16) -> u16 {
|
||||||
return self
|
return self
|
||||||
.skinsheet_offset
|
.skinsheet_offset
|
||||||
.saturating_mul(self.metadata.frame_size_height.saturating_mul(4))
|
.saturating_mul(self.metadata.frame_size_height.saturating_mul(2))
|
||||||
.saturating_add(y);
|
.saturating_add(y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@ impl GameProfile {
|
||||||
|
|
||||||
game_scene.player1.cond.0 = 0x80;
|
game_scene.player1.cond.0 = 0x80;
|
||||||
|
|
||||||
state.difficulty = GameDifficulty::from_save_value(self.difficulty);
|
state.difficulty = GameDifficulty::from_primitive(self.difficulty);
|
||||||
|
|
||||||
game_scene.player1.skin.apply_gamestate(state);
|
game_scene.player1.skin.apply_gamestate(state);
|
||||||
game_scene.player2.skin.apply_gamestate(state);
|
game_scene.player2.skin.apply_gamestate(state);
|
||||||
|
|
@ -236,7 +236,7 @@ impl GameProfile {
|
||||||
}
|
}
|
||||||
|
|
||||||
let timestamp = get_timestamp();
|
let timestamp = get_timestamp();
|
||||||
let difficulty = state.difficulty.to_save_value();
|
let difficulty = state.difficulty as u8;
|
||||||
|
|
||||||
GameProfile {
|
GameProfile {
|
||||||
current_map,
|
current_map,
|
||||||
|
|
|
||||||
|
|
@ -67,46 +67,16 @@ impl TimingMode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Copy, Clone)]
|
#[derive(PartialEq, Eq, Copy, Clone, num_derive::FromPrimitive)]
|
||||||
pub enum GameDifficulty {
|
pub enum GameDifficulty {
|
||||||
Easy,
|
Normal = 0,
|
||||||
Normal,
|
Easy = 2,
|
||||||
Hard,
|
Hard = 4,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GameDifficulty {
|
impl GameDifficulty {
|
||||||
pub fn from_index(index: usize) -> GameDifficulty {
|
pub fn from_primitive(val: u8) -> GameDifficulty {
|
||||||
match index {
|
return num_traits::FromPrimitive::from_u8(val).unwrap_or(GameDifficulty::Normal);
|
||||||
0 => GameDifficulty::Easy,
|
|
||||||
1 => GameDifficulty::Normal,
|
|
||||||
2 => GameDifficulty::Hard,
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn from_save_value(val: u8) -> GameDifficulty {
|
|
||||||
match val {
|
|
||||||
0 => GameDifficulty::Normal,
|
|
||||||
2 => GameDifficulty::Easy,
|
|
||||||
4 => GameDifficulty::Hard,
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_save_value(self) -> u8 {
|
|
||||||
match self {
|
|
||||||
GameDifficulty::Normal => 0,
|
|
||||||
GameDifficulty::Easy => 2,
|
|
||||||
GameDifficulty::Hard => 4,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_skinsheet_offset(difficulty: GameDifficulty) -> u16 {
|
|
||||||
match difficulty {
|
|
||||||
GameDifficulty::Easy => 1, // Yellow Quote
|
|
||||||
GameDifficulty::Normal => 0, // Good Quote
|
|
||||||
GameDifficulty::Hard => 2, // Human Quote
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -654,6 +624,6 @@ impl SharedGameState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GameDifficulty::get_skinsheet_offset(self.difficulty)
|
return self.difficulty as u16;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue