Skip to content

Commit

Permalink
feat: party_exp_bits
Browse files Browse the repository at this point in the history
  • Loading branch information
markisha64 committed Jan 10, 2025
1 parent d508988 commit 0afb5d4
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mod models;
mod number_field;
mod number_field_float;
mod parties;
mod party_exp_bits;
mod preset;
mod randomize;
mod scaling;
Expand Down Expand Up @@ -188,13 +189,14 @@ fn app() -> Element {
class: "column",
parties::parties {},
scaling::scaling {},
models::models {},
},
div {
class: "column",
shops::shops {},
encounters::encounters {},
maps::maps {},
models::models {}
party_exp_bits::party_exp_bits {},
},
}
}
Expand Down
88 changes: 88 additions & 0 deletions src/gui/party_exp_bits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
use crate::gui::number_field_float;
use crate::{gui::checkbox, json::Preset};

use dioxus::prelude::*;

#[component]
pub fn party_exp_bits() -> Element {
let mut preset_state = use_context::<Signal<Preset>>();
let read_state = preset_state.read();

let enabled = read_state.party_exp_bits.enabled;

let dv_exp_modifier = read_state.party_exp_bits.dv_exp_modifier;
let exp_modifier = read_state.party_exp_bits.exp_modifier;
let bits_modifier = read_state.party_exp_bits.bits_modifier;

rsx! {
div {
class: "segment",
div {
class: "left",
div {
class: "tooltip",
span {
class: "tooltiptext",
style: "width: 350px",
"Total stats = Base stats + Stat modifier * level ± [0, Stat range]",
br {},
"Total res = Base res + Res modifier * level ± [0, Stat range]"
},
checkbox::checkbox {
label: "Party DV Exp/Exp/Bits",
id: "party_exp_bits.enabled",
checked: enabled,
onchange: move |x: bool| {
preset_state.write().party_exp_bits.enabled = x;
}
},
},
}
div {
class: "left",
number_field_float::number_field {
min: 0.00,
max: 100.00,
id: "party_exp_bits.dv_exp_modifier",
label: "DV Exp modifer",
disabled: !enabled,
tooltip: "Multiply DV Exp by",
onchange: move |x: f64| {
preset_state.write().party_exp_bits.dv_exp_modifier = x;
},
value: dv_exp_modifier
}
}
div {
class: "left",
number_field_float::number_field {
min: 0.00,
max: 100.00,
id: "party_exp_bits.exp_modifier",
label: "Exp modifer",
disabled: !enabled,
tooltip: "Multiply Exp by",
onchange: move |x: f64| {
preset_state.write().party_exp_bits.exp_modifier = x;
},
value: exp_modifier
}
}
div {
class: "left",
number_field_float::number_field {
min: 0.00,
max: 100.00,
id: "party_exp_bits.bits_modifier",
label: "Bits modifer",
disabled: !enabled,
tooltip: "Multiply Bits by",
onchange: move |x: f64| {
preset_state.write().party_exp_bits.bits_modifier = x;
},
value: bits_modifier
}
}
}
}
}
23 changes: 21 additions & 2 deletions src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ pub struct Preset {
pub fixes: Fixes,
#[serde(default = "default_scaling")]
pub scaling: Scaling,
#[serde(default = "default_party_exp_bits")]
pub party_exp_bits: PartyExpBits,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
Expand All @@ -32,6 +34,19 @@ pub struct Randomizer {
pub models: Models,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct PartyExpBits {
#[serde(default = "default_bool_true")]
pub enabled: bool,
#[serde(default = "default_f64")]
pub dv_exp_modifier: f64,
#[serde(default = "default_f64")]
pub exp_modifier: f64,
#[serde(default = "default_f64")]
pub bits_modifier: f64,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Models {
Expand Down Expand Up @@ -177,7 +192,7 @@ pub struct Scaling {
pub stat_modifier: i32,
#[serde(default = "default_res_modifier")]
pub res_modifier: i32,
#[serde(default = "default_hp_modifier")]
#[serde(default = "default_f64")]
pub hp_modifier: f64,
#[serde(default = "default_bool_true")]
pub natural_scaling: bool,
Expand Down Expand Up @@ -219,6 +234,10 @@ fn default_models() -> Models {
serde_json::from_str("{}").unwrap()
}

fn default_party_exp_bits() -> PartyExpBits {
serde_json::from_str("{}").unwrap()
}

fn default_seed() -> u64 {
Utc::now().timestamp() as u64
}
Expand Down Expand Up @@ -255,7 +274,7 @@ fn default_res_modifier() -> i32 {
15
}

fn default_hp_modifier() -> f64 {
fn default_f64() -> f64 {
1.0
}

Expand Down
6 changes: 6 additions & 0 deletions src/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ mod fixes;
mod maps;
mod models;
mod parties;
mod party_exp_bits;
mod scaling;
mod shops;

use dmw3_structs::{
DigivolutionConditions, DigivolutionData, EncounterData, EnemyStats, EntityData, EntityLogic,
Environmental, ItemShopData, MapColor, MoveData, PartyData, Pointer, Shop, StageLoadData,
Expand Down Expand Up @@ -1607,6 +1609,10 @@ pub async fn patch(path: &PathBuf, preset: &Preset) -> anyhow::Result<Objects> {
models::patch(&preset.randomizer, &mut objects, &mut rng)?;
}

if preset.party_exp_bits.enabled {
party_exp_bits::patch(&preset.party_exp_bits, &mut objects)?;
}

write_objects(path, &mut objects).await?;

Ok(objects)
Expand Down
11 changes: 11 additions & 0 deletions src/rand/party_exp_bits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use crate::{json::PartyExpBits, rand::Objects};

pub fn patch(preset: &PartyExpBits, objects: &mut Objects) -> anyhow::Result<()> {
for party_exp_bits in objects.party_exp_bits.modified.iter_mut() {
party_exp_bits.dv_exp = ((party_exp_bits.dv_exp as f64) * preset.dv_exp_modifier) as u32;
party_exp_bits.exp = ((party_exp_bits.exp as f64) * preset.exp_modifier) as u32;
party_exp_bits.bits = ((party_exp_bits.bits as f64) * preset.bits_modifier) as u32;
}

Ok(())
}

0 comments on commit 0afb5d4

Please sign in to comment.