Skip to content

Commit

Permalink
Move command db to data crate to avoid cyclic dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
melody-rs committed Feb 1, 2025
1 parent f5f2245 commit 181568b
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 34 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ rand = "0.8.5" # Random number generators and other randomness functionality
lexical-sort = "0.3.1" # Functions that compare and sort strings lexicographically
indexmap = "2.2.6" # A hash table with consistent order and fast iteration

indextree = "4.7.2" # A general tree structure which stores nodes in an arena

# Fast and performant.
[profile.release]
opt-level = 3
Expand Down
1 change: 0 additions & 1 deletion crates/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// You should have received a copy of the GNU General Public License
// along with Luminol. If not, see <http://www.gnu.org/licenses/>.

pub mod command_db;
pub mod global;
pub mod project;
#[cfg(not(target_arch = "wasm32"))]
Expand Down
28 changes: 24 additions & 4 deletions crates/config/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
// it with Steamworks API by Valve Corporation, containing parts covered by
// terms of the Steamworks API by Valve Corporation, the licensors of this
// Program grant you additional permission to convey the resulting work.
use super::{DataFormat, RGSSVer, RMVer, VolumeScale};
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};

use super::{command_db, DataFormat, RGSSVer, RMVer, VolumeScale};

#[derive(Debug, Clone)]
#[allow(clippy::large_enum_variant)]
pub struct Config {
pub project: Project,
pub command_db: command_db::CommandDB,
pub command_db: luminol_data::CommandDB,
pub game_ini: ini::Ini,
}

Expand Down Expand Up @@ -65,6 +65,21 @@ impl Default for Project {
}
}

static XP_COMMANDS: Lazy<luminol_data::CommandSet> = Lazy::new(|| {
let dir = luminol_macros::include_asset_dir_ids!("assets/commands/XP");
dir.into_iter()
.map(|(id, data)| {
let str = std::str::from_utf8(data).unwrap();
let cmd = ron::from_str(str).unwrap();
(id, cmd)
})
.collect()
});

static VX_COMMANDS: Lazy<luminol_data::CommandSet> = Lazy::new(|| todo!());

static ACE_COMMANDS: Lazy<luminol_data::CommandSet> = Lazy::new(|| todo!());

impl Config {
pub fn from_project(project: Project) -> Self {
let mut game_ini = ini::Ini::new();
Expand All @@ -77,7 +92,12 @@ impl Config {
.set("RTP2", "")
.set("RTP3", "");

let command_db = command_db::CommandDB::new(project.editor_ver);
let default = match project.editor_ver {
RMVer::XP => &*XP_COMMANDS,
RMVer::VX => &*VX_COMMANDS,
RMVer::Ace => &*ACE_COMMANDS,
};
let command_db = luminol_data::CommandDB::from_defaults(default.clone());

Self {
project,
Expand Down
1 change: 1 addition & 0 deletions crates/data/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ egui.workspace = true
# * Misc * #
rand.workspace = true
flate2 = "1.0" # DEFLATE compression and decompression exposed as Read/BufRead/Write streams
indextree.workspace = true
34 changes: 5 additions & 29 deletions crates/config/src/command_db.rs → crates/data/src/command_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,10 @@
// terms of the Steamworks API by Valve Corporation, the licensors of this
// Program grant you additional permission to convey the resulting work.

use luminol_data::commands::Command;
use once_cell::sync::Lazy;
use std::collections::HashMap;

use crate::commands::Command;
use serde::{Deserialize, Serialize};

use super::RMVer;

type CommandSet = HashMap<u16, Command>;
static XP_DEFAULT: Lazy<CommandSet> = Lazy::new(|| {
let dir = luminol_macros::include_asset_dir_ids!("assets/commands/XP");
dir.into_iter()
.map(|(id, data)| {
let str = std::str::from_utf8(data).unwrap();
let cmd = ron::from_str(str).unwrap();
(id, cmd)
})
.collect()
});

static VX_DEFAULT: Lazy<CommandSet> = Lazy::new(|| todo!());

static ACE_DEFAULT: Lazy<CommandSet> = Lazy::new(|| todo!());
pub type CommandSet = std::collections::HashMap<u16, Command>;

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct CommandDB {
Expand All @@ -56,15 +37,10 @@ pub struct CommandDB {
}

impl CommandDB {
pub fn new(ver: RMVer) -> Self {
pub fn from_defaults(default: CommandSet) -> Self {
Self {
default: match ver {
RMVer::XP => &*XP_DEFAULT,
RMVer::VX => &*VX_DEFAULT,
RMVer::Ace => &*ACE_DEFAULT,
}
.clone(),
user: HashMap::new(),
default,
user: CommandSet::new(),
}
}

Expand Down
2 changes: 2 additions & 0 deletions crates/data/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ mod rgss_structs;

pub mod helpers;

mod command_db;
pub mod commands;

pub use command_db::{CommandDB, CommandSet};
pub use helpers::*;
pub use option_vec::OptionVec;
pub use rgss_structs::{Color, Table1, Table2, Table3, Tone};
Expand Down
4 changes: 4 additions & 0 deletions crates/data/src/rmxp/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ pub struct Map {
#[serde(skip)]
pub modified: bool,
}

pub struct MapDeserializer<'de> {
command_db: &'de crate::CommandDB,
}

0 comments on commit 181568b

Please sign in to comment.