Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved SCLYObject wrapper and MlvlWrapper::MlvlArea wrapper #28

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/mlvl_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,26 @@ impl<'r, 'mlvl, 'cursor, 'list> MlvlArea<'r, 'mlvl, 'cursor, 'list>
layer_id.unwrap()
}

pub fn object_id_from_layer_name(&mut self, layer_name: &str, internal_idx: usize) -> u32
{
let layer_id = self.get_layer_id_from_name(layer_name);
return self.object_id_from_layer_id(layer_id, internal_idx);
}

pub fn object_id_from_layer_id(&mut self, layer_id: usize, internal_idx: usize) -> u32
{
// initialize with the internal id
let mut obj_id = internal_idx;

// add the area id to the object id
obj_id |= self.mrea_index << 16;

// add the layer id to the object id
obj_id |= layer_id << 26;

obj_id as u32
}

pub fn new_object_id_from_layer_name(&mut self, layer_name: &str) -> u32
{
let layer_id = self.get_layer_id_from_name(layer_name);
Expand Down
18 changes: 18 additions & 0 deletions structs/src/scly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,24 @@ pub struct SclyObject<'r>
pub property_data: SclyProperty<'r>,
}

impl<'r> SclyObject<'r>
{
pub fn get_layer_idx(self) -> usize
{
((self.instance_id >> 26) & 0x3F) as usize
}

pub fn get_area_idx(self) -> usize
{
((self.instance_id >> 16) & 0xFF) as usize
}
toasterparty marked this conversation as resolved.
Show resolved Hide resolved

pub fn get_object_idx(self) -> usize
{
(self.instance_id & 0xFFFF) as usize
}
}

macro_rules! build_scly_property {
($($name:ident, $is_check:ident, $accessor:ident, $accessor_mut:ident,)*) => {

Expand Down
Loading