Skip to content

Commit

Permalink
add new gmd format support
Browse files Browse the repository at this point in the history
  • Loading branch information
qimiko committed Feb 7, 2024
1 parent 63fd7d5 commit 30c3a00
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions gdlevelconverter/gjobjects/gjdictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ def from_dict_str(cls, string: str):
Parses a dictionary string (as plist) into a dictionary
"""
root = xml.etree.ElementTree.fromstring(string)

# correct new gmd files into old gmd format
if root.tag == "plist":
root = root[0]
if root.tag == "dict":
root.tag = "d"

if not root.tag == "d":
raise ValueError("input is not in plist format")

Expand Down
1 change: 1 addition & 0 deletions tests/kanpyo_roll.gmd

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions tests/testgjgamelevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class TestGJGameLevel(unittest.TestCase):
"""

TEST_GMD_FILE_NAME = "maki_roll.gmd"
TEST_GMDV2_FILE_NAME = "kanpyo_roll.gmd"

def test_from_gmd(self):
"""
Expand All @@ -29,6 +30,22 @@ def test_from_gmd(self):
self.assertEqual(level.name, "maki roll")
self.assertEqual(len(level.level_string.objects), 19999)

def test_from_gmdv2(self):
"""
Test loading from the gmdv2 format.
This format wraps everything in an additional plist tag
"""

file_path = pathlib.Path(__file__).parent / self.TEST_GMDV2_FILE_NAME

gmd_string = ""
with open(file_path, "r", encoding="utf8") as gmd:
gmd_string = gmd.read()

level = GJGameLevel.from_gmd(gmd_string)
self.assertEqual(level.name, "Kanpyo Roll")
self.assertEqual(len(level.level_string.objects), 19604)

def test_to_gmd(self):
"""
Test saving level to gmd file
Expand Down

0 comments on commit 30c3a00

Please sign in to comment.