Skip to content

Commit

Permalink
#381: Clarify monster spawn field names
Browse files Browse the repository at this point in the history
  • Loading branch information
theCapypara committed Jul 31, 2023
1 parent 7098a02 commit efbc5eb
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 39 deletions.
24 changes: 15 additions & 9 deletions skytemple_files/dungeon_data/mappa_bin/_python_impl/monster.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,20 @@

class MappaMonster(MappaMonsterProtocol, AutoString):
level: u8
weight: u16
weight2: u16
main_spawn_weight: u16
monster_house_spawn_weight: u16
md_index: u16

def __init__(self, level: u8, weight: u16, weight2: u16, md_index: u16):
def __init__(
self,
level: u8,
main_spawn_weight: u16,
monster_house_spawn_weight: u16,
md_index: u16,
):
self.level = level
self.weight = weight
self.weight2 = weight2
self.main_spawn_weight = main_spawn_weight
self.monster_house_spawn_weight = monster_house_spawn_weight
self.md_index = md_index

@classmethod
Expand All @@ -68,8 +74,8 @@ def list_from_mappa(
def to_mappa(self):
data = bytearray(8)
write_u16(data, u16(self.level * LEVEL_MULTIPLIER), 0x00)
write_u16(data, self.weight, 0x02)
write_u16(data, self.weight2, 0x04)
write_u16(data, self.main_spawn_weight, 0x02)
write_u16(data, self.monster_house_spawn_weight, 0x04)
write_u16(data, self.md_index, 0x06)
return data

Expand All @@ -83,6 +89,6 @@ def __eq__(self, other: object) -> bool:
return (
self.md_index == other.md_index
and self.level == other.level
and self.weight == other.weight
and self.weight2 == other.weight2
and self.main_spawn_weight == other.main_spawn_weight
and self.monster_house_spawn_weight == other.monster_house_spawn_weight
)
4 changes: 2 additions & 2 deletions skytemple_files/dungeon_data/mappa_bin/mappa_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,8 +667,8 @@ def mappa_monster_to_xml(monster: MappaMonsterProtocol) -> Element:
XML_MONSTER,
{
XML_MONSTER__LEVEL: str(monster.level),
XML_MONSTER__WEIGHT: str(monster.weight),
XML_MONSTER__WEIGHT2: str(monster.weight2),
XML_MONSTER__WEIGHT: str(monster.main_spawn_weight),
XML_MONSTER__WEIGHT2: str(monster.monster_house_spawn_weight),
XML_MONSTER__MD_INDEX: str(monster.md_index),
},
)
Expand Down
16 changes: 11 additions & 5 deletions skytemple_files/dungeon_data/mappa_bin/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,21 @@ def __eq__(self, other: object) -> bool:

class MappaMonsterProtocol(Protocol):
level: u8
weight: u16
weight2: u16
main_spawn_weight: u16
monster_house_spawn_weight: u16
md_index: u16

@abstractmethod
def __init__(self, level: u8, weight: u16, weight2: u16, md_index: u16):
def __init__(
self,
level: u8,
main_spawn_weight: u16,
monster_house_spawn_weight: u16,
md_index: u16,
):
self.level = level
self.weight = weight
self.weight2 = weight2
self.main_spawn_weight = main_spawn_weight
self.monster_house_spawn_weight = monster_house_spawn_weight
self.md_index = md_index

@abstractmethod
Expand Down
14 changes: 7 additions & 7 deletions test/skytemple_files_test/dungeon_data/mappa_bin/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,22 @@ def eq_mappa_monster_list_protocol(one: Sequence[MappaMonsterProtocol], two: Seq
def eq_mappa_monster_protocol(one: MappaMonsterProtocol, two: MappaMonsterProtocol) -> bool:
return (
one.level == two.level and
one.weight == two.weight and
one.weight2 == two.weight2 and
one.main_spawn_weight == two.main_spawn_weight and
one.monster_house_spawn_weight == two.monster_house_spawn_weight and
one.md_index == two.md_index
)


class MappaMonsterStub(MappaMonsterProtocol, AutoString):
level: u8
weight: u16
weight2: u16
main_spawn_weight: u16
monster_house_spawn_weight: u16
md_index: u16

def __init__(self, level: u8, weight: u16, weight2: u16, md_index: u16):
def __init__(self, level: u8, main_spawn_weight: u16, monster_house_spawn_weight: u16, md_index: u16):
self.level = level
self.weight = weight
self.weight2 = weight2
self.main_spawn_weight = main_spawn_weight
self.monster_house_spawn_weight = monster_house_spawn_weight
self.md_index = md_index

def __eq__(self, other: object) -> bool:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ def p_floor_terrain_settings(settings: MappaFloorTerrainSettings):

def p_monster(monster: MappaMonster) -> str:
return f"""{monster.level},
{monster.weight},
{monster.weight2},
{monster.main_spawn_weight},
{monster.monster_house_spawn_weight},
{monster.md_index}
""".replace(
"\n", ""
Expand Down
28 changes: 14 additions & 14 deletions test/skytemple_files_test/dungeon_data/mappa_bin/mappa_bin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@ def test_mappa_monster__init__(self):
for expected in expected_list:
subject = self.handler.get_monster_model()(
expected.level,
expected.weight,
expected.weight2,
expected.main_spawn_weight,
expected.monster_house_spawn_weight,
expected.md_index,
)

Expand All @@ -478,23 +478,23 @@ def test_mappa_monster__init__(self):
def test_mappa_monster__eq__(self):
subject_not_same = self.handler.get_monster_model()(
FIX_MONSTER_LISTS[0][0].level,
FIX_MONSTER_LISTS[0][0].weight,
FIX_MONSTER_LISTS[0][0].weight2,
FIX_MONSTER_LISTS[0][0].main_spawn_weight,
FIX_MONSTER_LISTS[0][0].monster_house_spawn_weight,
FIX_MONSTER_LISTS[0][0].md_index,
)

for expected_list in FIX_MONSTER_LISTS[1:]:
for expected in expected_list:
subject1 = self.handler.get_monster_model()(
expected.level,
expected.weight,
expected.weight2,
expected.main_spawn_weight,
expected.monster_house_spawn_weight,
expected.md_index
)
subject2 = self.handler.get_monster_model()(
expected.level,
expected.weight,
expected.weight2,
expected.main_spawn_weight,
expected.monster_house_spawn_weight,
expected.md_index
)

Expand All @@ -509,13 +509,13 @@ def test_mappa_monster_attrs(self):
)

e.level = u8(123)
e.weight = u16(0xFFF)
e.weight2 = u16(0x1FFF)
e.main_spawn_weight = u16(0xFFF)
e.monster_house_spawn_weight = u16(0x1FFF)
e.md_index = u16(1234)

self.assertEqual(e.level, u8(123))
self.assertEqual(e.weight, u16(0xFFF))
self.assertEqual(e.weight2, u16(0x1FFF))
self.assertEqual(e.main_spawn_weight, u16(0xFFF))
self.assertEqual(e.monster_house_spawn_weight, u16(0x1FFF))
self.assertEqual(e.md_index, u16(1234))

def test_mappa_trap_list__init__(self):
Expand Down Expand Up @@ -1225,8 +1225,8 @@ def _make_floor_model_params(
[
self.handler.get_monster_model()(
monster.level,
monster.weight,
monster.weight2,
monster.main_spawn_weight,
monster.monster_house_spawn_weight,
monster.md_index,
)
for monster in monsters
Expand Down

0 comments on commit efbc5eb

Please sign in to comment.