Skip to content

Commit

Permalink
feat: random fight backgrounds
Browse files Browse the repository at this point in the history
  • Loading branch information
markisha64 committed Nov 6, 2024
1 parent 8c3d1b1 commit 9117d0c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/gui/maps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub fn maps() -> Element {

let color = read_state.randomizer.maps.color;
let backgrounds = read_state.randomizer.maps.backgrounds;
let fight_backgrounds = read_state.randomizer.maps.fight_backgrounds;
let item_boxes = read_state.randomizer.maps.item_boxes;
let selected = read_state.randomizer.maps.item_boxes_items_only.clone();

Expand Down Expand Up @@ -59,6 +60,21 @@ pub fn maps() -> Element {
},
}
},
div {
div {
class: "left",
checkbox::checkbox {
label: "Fight Backgrounds",
id: "maps.fight_backgrounds",
checked: fight_backgrounds,
disabled: !enabled,
tooltip: "Randomize fight backgrounds",
onchange: move |x: bool| {
state.write().randomizer.maps.fight_backgrounds = x;
}
},
}
},
div {
class: "left",
checkbox::checkbox {
Expand Down
2 changes: 2 additions & 0 deletions src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ pub struct Maps {
pub item_boxes: bool,
#[serde(default = "ShopItems::default")]
pub item_boxes_items_only: ShopItems,
#[serde(default = "default_bool_true")]
pub fight_backgrounds: bool,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion src/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ async fn read_map_objects(

let ptr = area.original.teams[0];

if ptr.is_valid() {
if !ptr.is_valid() {
return None;
}

Expand Down
20 changes: 19 additions & 1 deletion src/rand/maps.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::BTreeSet;
use std::collections::{BTreeSet, HashSet};

use crate::{rand::Objects, util};
use anyhow::Context;
Expand Down Expand Up @@ -57,9 +57,27 @@ pub fn patch(
item_boxes(preset, objects, rng)?;
}

if maps.fight_backgrounds {
random_fight_backgrounds(objects, rng);
}

Ok(())
}

fn random_fight_backgrounds(objects: &mut Objects, rng: &mut Xoshiro256StarStar) {
for map in &mut objects.map_objects {
if let Some(se_obj) = &mut map.stage_encounters {
for opt in &mut se_obj.stage_encounters {
if let Some(encounters_obj) = opt {
for encounter in &mut encounters_obj.modified {
encounter.stage = rng.next_u32() % 0x39;
}
}
}
}
}
}

fn color(objects: &mut Objects, rng: &mut Xoshiro256StarStar) {
for map in &mut objects.map_objects {
if let Some(color_object) = &mut map.map_color {
Expand Down

0 comments on commit 9117d0c

Please sign in to comment.