Skip to content

Commit

Permalink
fix: there is a map rewrite that the display does not follow
Browse files Browse the repository at this point in the history
  • Loading branch information
progre committed Aug 16, 2024
1 parent eb068df commit 55c6ddc
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
2 changes: 2 additions & 0 deletions src-tauri/src/script/editor/objects_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use crate::script::{
},
};

pub use object_factory::map_rewrite_with_flags_replaced;

pub fn to_object_for_shutter(old_obj: &Object, open_flag: u16, item: Item) -> Object {
match item {
Item::MainWeapon(item) => Object::MainWeapon(main_weapon(old_obj, item)),
Expand Down
33 changes: 33 additions & 0 deletions src-tauri/src/script/editor/objects_factory/object_factory.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use std::collections::HashMap;

use anyhow::Result;
use log::warn;

use crate::script::{
Expand Down Expand Up @@ -168,3 +171,33 @@ pub fn memo(old_obj: &RomObject, set_flag: u16, done_flag: u16) -> UnknownObject
starts,
}
}

pub fn map_rewrite_with_flags_replaced(
base_obj: &UnknownObject,
replace_flag_map: &HashMap<u16, u16>,
) -> Result<UnknownObject> {
// Flag of item may be op3 or starts
let op3 = u16::try_from(base_obj.op3)?;
Ok(UnknownObject {
number: base_obj.number,
x: base_obj.x,
y: base_obj.y,
op1: base_obj.op1,
op2: base_obj.op2,
op3: replace_flag_map.get(&op3).copied().unwrap_or(op3) as i32,
op4: base_obj.op4,
starts: base_obj
.starts
.iter()
.map(|start| {
replace_flag_map.get(&(start.flag as u16)).map_or_else(
|| start.clone(),
|&new_flag| Start {
flag: new_flag as u32,
run_when: start.run_when,
},
)
})
.collect(),
})
}
21 changes: 6 additions & 15 deletions src-tauri/src/script/editor/script_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use crate::{
};

use super::objects_factory::{
to_object_for_shutter, to_object_for_special_chest, to_objects_for_chest,
to_objects_for_hand_scanner,
map_rewrite_with_flags_replaced, to_object_for_shutter, to_object_for_special_chest,
to_objects_for_chest, to_objects_for_hand_scanner,
};

fn fix_trap_of_mausoleum_of_the_giants(
Expand Down Expand Up @@ -239,19 +239,10 @@ fn new_objs(
1 | 13 | 14 | 32 | 71 | 77 => unreachable!(),
// 59: Map rewrite
// apply ROMs replacement
59 => Ok(vec![Object::Unknown(UnknownObject {
number: obj.number(),
x: obj.x(),
y: obj.y(),
op1: obj.op1(),
op2: obj.op2(),
op3: replace_flag_map
.get(&u16::try_from(obj.op3())?)
.copied()
.unwrap_or(obj.op3() as u16) as i32,
op4: obj.op4(),
starts: obj.starts().to_vec(),
})]),
59 => Ok(vec![Object::Unknown(map_rewrite_with_flags_replaced(
unknown_obj,
replace_flag_map,
)?)]),
// Trap object for the Ankh Jewel Treasure Chest in Mausoleum of the Giants.
// It is made to work correctly when acquiring items.
140 if unknown_obj.x == 49152 && unknown_obj.y == 16384 => {
Expand Down

0 comments on commit 55c6ddc

Please sign in to comment.