From 9b4919ef13441ba2c524c6f86727a0ea958d4215 Mon Sep 17 00:00:00 2001 From: Lila Date: Sun, 22 Sep 2024 17:41:49 +0100 Subject: [PATCH] Update importing.py --- fast64_internal/sm64/animation/importing.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/fast64_internal/sm64/animation/importing.py b/fast64_internal/sm64/animation/importing.py index 32557ad72..0adecc299 100644 --- a/fast64_internal/sm64/animation/importing.py +++ b/fast64_internal/sm64/animation/importing.py @@ -11,8 +11,10 @@ from bpy.types import Object, Action, Context, PoseBone from mathutils import Quaternion +from ...f3d.f3d_parser import math_eval from ...utility import PluginError, decodeSegmentedAddr, filepath_checks, path_checks, intToHex, removeComments from ...utility_anim import create_basic_action + from ..sm64_constants import level_pointers from ..sm64_level_parser import parseLevelAtPointer from ..sm64_utility import import_rom_checks @@ -480,6 +482,7 @@ def import_tables( def find_decls(c_data: str, path: Path, decl_list: dict[str, list[CArrayDeclaration]]): + """At this point a generilized c parser would be better""" matches = DECL_PATTERN.findall(c_data) for decl_type, name, value_text in matches: values = [] @@ -487,11 +490,17 @@ def find_decls(c_data: str, path: Path, decl_list: dict[str, list[CArrayDeclarat var, designator, val = match.group("var"), match.group("designator"), match.group("val") assert val is not None if designator is not None: - if isinstance(values, dict): - raise PluginError("Invalid mix of designated initializers") designator = math_eval(designator, object()) - first_val = values[0] if values else "0" - values.extend([first_val] * (len(values) - designator)) + if isinstance(designator, int): + if isinstance(values, dict): + raise PluginError("Invalid mix of designated initializers") + first_val = values[0] if values else "0" + values.extend([first_val] * (designator + 1 - len(values))) + else: + if not values: + values = {} + elif isinstance(values, list): + raise PluginError("Invalid mix of designated initializers") values[designator] = val elif var is not None: if not values: