Skip to content

Commit

Permalink
refactor: organize packages
Browse files Browse the repository at this point in the history
  • Loading branch information
progre committed Aug 1, 2024
1 parent c23bfa3 commit 2573e3d
Show file tree
Hide file tree
Showing 18 changed files with 98 additions and 99 deletions.
4 changes: 0 additions & 4 deletions src-tauri/src/dataset.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
mod assertions;
pub mod create_source;
pub mod game_structure;
pub mod item;
pub mod spot;
pub mod storage;

pub const NIGHT_SURFACE_SUB_WEAPON_COUNT: usize = 1;
pub const NIGHT_SURFACE_CHEST_COUNT: usize = 3;
Expand Down
18 changes: 10 additions & 8 deletions src-tauri/src/dataset/game_structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@ use crate::{
script::data::items::{Equipment, MainWeapon, Rom, Seal, SubWeapon},
};

use super::{
item::StrategyFlag,
spot::{
AllRequirements, AnyOfAllRequirements, ChestSpot, FieldId, MainWeaponSpot, RequirementFlag,
RomSpot, SealSpot, ShopSpot, SubWeaponSpot,
},
storage::Event,
use super::spot::{
AllRequirements, AnyOfAllRequirements, ChestSpot, FieldId, MainWeaponSpot, RequirementFlag,
RomSpot, SealSpot, ShopSpot, SubWeaponSpot,
};

pub struct GameStructureFiles {
Expand Down Expand Up @@ -96,7 +92,7 @@ fn parse_event_requirements(items: BTreeMap<String, Vec<String>>) -> Result<Vec<
.into_iter()
.map(|(name, requirements)| {
Ok(Event {
name: StrategyFlag(name),
name: SpotName::new(name),
requirements: to_any_of_all_requirements(requirements)?.unwrap(),
})
})
Expand All @@ -111,6 +107,12 @@ fn to_pascal_case(camel_case: &str) -> String {
.collect()
}

#[derive(Clone, Debug)]
pub struct Event {
pub name: SpotName,
pub requirements: AnyOfAllRequirements,
}

pub struct GameStructure {
pub main_weapon_shutters: Vec<MainWeaponSpot>,
pub sub_weapon_shutters: Vec<SubWeaponSpot>,
Expand Down
17 changes: 0 additions & 17 deletions src-tauri/src/dataset/spot/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use vec1::Vec1;

use crate::script::data::items::{self, MainWeapon, Rom, Seal, SubWeapon};

use super::super::item::StrategyFlag;

#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, num_derive::FromPrimitive)]
pub enum FieldId {
Surface = 0,
Expand Down Expand Up @@ -80,12 +78,6 @@ impl RequirementFlag {
}
}

impl PartialEq<StrategyFlag> for RequirementFlag {
fn eq(&self, other: &StrategyFlag) -> bool {
self.0 == other.0
}
}

#[derive(Clone, Debug, PartialEq)]
pub struct AllRequirements(pub Vec1<RequirementFlag>);

Expand Down Expand Up @@ -352,15 +344,6 @@ impl ShopSpot {
pub fn requirements(&self) -> Option<&AnyOfAllRequirements> {
self.0.requirements.as_ref()
}

pub fn to_strategy_flags(&self) -> (StrategyFlag, StrategyFlag, StrategyFlag) {
let mut names = self.0.name.0.split(',').map(|x| x.trim());
(
StrategyFlag::new(names.next().unwrap().to_string()),
StrategyFlag::new(names.next().unwrap().to_string()),
StrategyFlag::new(names.next().unwrap().to_string()),
)
}
}

impl fmt::Display for ShopSpot {
Expand Down
7 changes: 2 additions & 5 deletions src-tauri/src/randomizer.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
mod items_pool;
mod items_spots;
mod randomize_items;
mod sphere;
mod spoiler;
mod spoiler_log;
pub mod storage;

use anyhow::Result;
use log::trace;
use randomize_items::randomize_items;
pub use spoiler_log::SpoilerLog;
use storage::{create_source::create_source, Storage};

use crate::{
dataset::{
create_source::create_source,
game_structure::{GameStructure, GameStructureFiles},
storage::Storage,
NIGHT_SURFACE_CHEST_COUNT, NIGHT_SURFACE_SEAL_COUNT, NIGHT_SURFACE_SUB_WEAPON_COUNT,
TRUE_SHRINE_OF_THE_MOTHER_SEAL_COUNT, WARE_NO_MISE_COUNT,
},
Expand Down
8 changes: 4 additions & 4 deletions src-tauri/src/randomizer/randomize_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ use log::{info, trace};
use rand::Rng;

use crate::{
dataset::{item::StrategyFlag, storage::Storage},
randomizer::spoiler::items_spots::{Items, Spots},
script::data::script::Script,
};

use super::{
items_spots::{Items, Spots},
spoiler::{make_rng, spoiler},
spoiler_log::{CheckpointRef, SpoilerLogRef},
storage::{item::StrategyFlag, Storage},
RandomizeOptions,
};

Expand Down Expand Up @@ -176,8 +176,8 @@ mod tests {
use sha3::Digest;

use crate::{
app::read_game_structure_files_debug,
dataset::{create_source::create_source, game_structure::GameStructure},
app::read_game_structure_files_debug, dataset::game_structure::GameStructure,
randomizer::storage::create_source::create_source,
};

use super::*;
Expand Down
17 changes: 11 additions & 6 deletions src-tauri/src/randomizer/spoiler.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
mod items_pool;
pub mod items_spots;
mod sphere;

use std::{
collections::{BTreeMap, HashSet},
hash::Hash,
Expand All @@ -10,18 +14,19 @@ use rand::{seq::SliceRandom, Rng};
use rand_seeder::Seeder;
use rand_xoshiro::Xoshiro256PlusPlus;

use crate::dataset::{
item::{Item, StrategyFlag},
spot::{FieldId, SpotRef},
};
use crate::dataset::spot::{FieldId, SpotRef};

use super::{
items_spots::{Items, Spots},
sphere::sphere,
spoiler_log::{CheckpointRef, SpoilerLogRef},
storage::item::{Item, StrategyFlag},
RandomizeOptions,
};

use {
items_spots::{Items, Spots},
sphere::sphere,
};

static GLITCH: LazyLock<StrategyFlag> = LazyLock::new(|| StrategyFlag::new("option:glitch".into()));

pub fn make_rng<H: Hash>(seed: H) -> Xoshiro256PlusPlus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::mem::take;

use rand::{seq::SliceRandom, Rng};

use crate::dataset::{item::Item, spot::SpotRef};
use crate::{dataset::spot::SpotRef, randomizer::storage::item::Item};

use super::items_spots::Spots;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ use std::collections::BTreeMap;

use rand::Rng;

use crate::dataset::{
item::Item,
spot::{FieldId, SpotRef},
storage::{Event, Storage},
use crate::{
dataset::spot::{FieldId, SpotRef},
randomizer::storage::{item::Item, Event, Storage},
};

use super::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@ use std::{

use rand::Rng;

use crate::dataset::{
item::StrategyFlag,
spot::{AnyOfAllRequirements, ShopSpot},
storage::{Event, ShopRef},
use crate::{
dataset::spot::{AnyOfAllRequirements, ShopSpot},
randomizer::{
spoiler_log::{CheckpointRef, SphereRef},
storage::{
item::StrategyFlag,
{Event, ShopRef},
},
},
};

use super::{
items_pool::{ItemsPool, ShuffledItems},
items_spots::Spots,
spoiler_log::{CheckpointRef, SphereRef},
};

#[derive(Clone)]
Expand Down
11 changes: 5 additions & 6 deletions src-tauri/src/randomizer/spoiler_log.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use std::fmt;

use crate::dataset::{
use crate::dataset::spot::{ChestItem, FieldId, SpotRef};

use super::storage::{
item::{Item, StrategyFlag},
spot::{ChestItem, FieldId, SpotRef},
storage::{
Chest, ChestRef, MainWeapon, MainWeaponRef, Rom, RomRef, Seal, SealRef, Shop, ShopRef,
SubWeapon, SubWeaponRef,
},
Chest, ChestRef, MainWeapon, MainWeaponRef, Rom, RomRef, Seal, SealRef, Shop, ShopRef,
SubWeapon, SubWeaponRef,
};

fn compare_key_for_spoiler_log(field_id: FieldId) -> u8 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
mod assertions;
pub mod create_source;
pub mod item;

use std::collections::BTreeMap;

use anyhow::Result;

use crate::script::data::items;

use super::{
assertions::ware_missing_requirements,
item::{Item, StrategyFlag},
spot::{
use crate::{
dataset::spot::{
AnyOfAllRequirements, ChestItem, ChestSpot, FieldId, MainWeaponSpot, RomSpot, SealSpot,
ShopSpot, SubWeaponSpot,
},
script::data::items,
};

use {
assertions::ware_missing_requirements,
item::{Item, StrategyFlag},
};

#[derive(Clone, Debug)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ use std::collections::HashSet;

use anyhow::bail;

use super::{
item::StrategyFlag,
spot::{AnyOfAllRequirements, RequirementFlag},
storage::Storage,
};
use crate::dataset::spot::{AnyOfAllRequirements, RequirementFlag};

use super::{item::StrategyFlag, Storage};

fn append<'a>(
set: &mut HashSet<RequirementFlag>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@ use std::{

use anyhow::{bail, Result};

use crate::{
dataset::{
game_structure::GameStructure,
item::Item,
storage::{Chest, MainWeapon, Rom, Seal, Shop, Storage, SubWeapon},
},
randomizer::RandomizeOptions,
};
use crate::{dataset::game_structure::GameStructure, randomizer::RandomizeOptions};

use super::{item::StrategyFlag, storage::Event};
use super::{
item::{Item, StrategyFlag},
Chest, Event, MainWeapon, Rom, Seal, Shop, Storage, SubWeapon,
};

pub fn create_source(
game_structure: &GameStructure,
Expand Down Expand Up @@ -78,7 +74,14 @@ pub fn create_source(
);
shops.push(Shop { spot, items });
}
let mut events = game_structure.events.clone();
let mut events: Vec<_> = game_structure
.events
.iter()
.map(|x| Event {
name: x.name.clone().into(),
requirements: x.requirements.clone(),
})
.collect();
log::trace!(
"options.shuffle_secret_roms: {:?}",
options.shuffle_secret_roms
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::script::data::items;

use super::spot::{ChestItem, FieldId, RequirementFlag, ShopItem, SpotName, SpotRef};
use crate::{
dataset::spot::{ChestItem, FieldId, RequirementFlag, ShopItem, SpotName, SpotRef},
script::data::items,
};

#[derive(Clone, Debug, Hash, Eq, Ord, PartialEq, PartialOrd)]
pub struct StrategyFlag(pub String);
Expand Down Expand Up @@ -48,6 +49,12 @@ impl PartialEq<RequirementFlag> for StrategyFlag {
}
}

impl PartialEq<StrategyFlag> for RequirementFlag {
fn eq(&self, other: &StrategyFlag) -> bool {
self.get() == other.0
}
}

impl From<SpotName> for StrategyFlag {
fn from(x: SpotName) -> Self {
Self::new(x.into_inner())
Expand Down
9 changes: 4 additions & 5 deletions src-tauri/src/script/data/item.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use anyhow::{bail, Result};

use crate::dataset::{
self,
item::ItemSource,
spot::{self, FieldId},
use crate::{
dataset::spot::{self, FieldId},
randomizer::{self, storage::item::ItemSource},
};

use super::{items, object::Shop, script::Script, shop_items_data::ShopItem};
Expand Down Expand Up @@ -103,7 +102,7 @@ impl Item {
);
}

pub fn from_dataset(item: &dataset::item::Item, script: &Script) -> Result<Self> {
pub fn from_dataset(item: &randomizer::storage::item::Item, script: &Script) -> Result<Self> {
Ok(match &item.src {
ItemSource::MainWeapon(main_weapon) => {
let Some(item) = script
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/script/data/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::mem::take;
use anyhow::Result;

use crate::{
dataset::storage::Storage,
randomizer::storage::Storage,
script::file::scripttxtparser::{parse_script_txt, stringify_script_txt},
};

Expand Down
6 changes: 3 additions & 3 deletions src-tauri/src/script/data/scripteditor.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use anyhow::{anyhow, bail, Result};
use log::debug;

use crate::dataset::{
spot::{self, FieldId},
storage::Storage,
use crate::{
dataset::spot::{self, FieldId},
randomizer::storage::Storage,
};

use super::{
Expand Down
Loading

0 comments on commit 2573e3d

Please sign in to comment.