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

Add actors sorted by CRC in Bmsld entity groups #88

Merged
merged 2 commits into from
Oct 19, 2023
Merged
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
18 changes: 17 additions & 1 deletion src/mercury_engine_data_structures/formats/bmsld.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from mercury_engine_data_structures.common_types import CVector3D, Float, StrId, make_dict, make_vector
from mercury_engine_data_structures.construct_extensions.misc import ErrorWithMessage
from mercury_engine_data_structures.crc import crc32
from mercury_engine_data_structures.formats import BaseResource
from mercury_engine_data_structures.formats.collision import collision_formats
from mercury_engine_data_structures.game_check import Game
Expand Down Expand Up @@ -187,6 +188,16 @@ def remove_actor_from_all_groups(self, actor_name: str):
self.remove_actor_from_group(group_name, actor_name)

def add_actor_to_entity_groups(self, collision_camera_name: str, actor_name: str, all_groups: bool = False):
"""
Adds an actor to either all entity groups or one entity group, which follow the name pattern of eg_SubArea_NAME.
In case an actor needs to be added to an entity group not following this name pattern
use `insert_into_sub_area`.

collision_camera_name: Name of the collision camera to find the entity groups for
actor_name: Actor name to add to the entity group
all_groups: A boolean which defines if the actor should be added to all entity groups starting with the name
pattern or just to one entity group matching the name pattern exactly
"""
def compare_func(first: str, second: str) -> bool:
if all_groups:
return first.startswith(f"eg_SubArea_{second}")
Expand All @@ -199,4 +210,9 @@ def compare_func(first: str, second: str) -> bool:
raise Exception(f"No entity group found for {collision_camera_name}")
for group in collision_camera_groups:
logger.debug("Add actor %s to group %s", actor_name, group.name)
group.names.append(actor_name)
self.insert_into_entity_group(group, actor_name)

def insert_into_entity_group(self, sub_area: Container, name_to_add: str) -> None:
# MSR requires to have the names in the sub area list sorted by their crc32 value
sub_area.names.append(name_to_add)
sub_area.names.sort(key=crc32)