From e5acbcf81be2d314828626cdf6da23dca76f62e0 Mon Sep 17 00:00:00 2001 From: Candoran2 <45334438+Candoran2@users.noreply.github.com> Date: Tue, 28 Sep 2021 22:06:38 +0200 Subject: [PATCH] Changed expression evaluation on cond/vercond to be in line with issue 73 of nifxml spec: cond is for local variables, vercond for global variables. Updated source xmls accordingly, should not result in a change of generated code (except for nif.xml). --- codegen/Union.py | 2 +- codegen/expression.py | 21 ++++++----- source/formats/fgm/fgm.xml | 4 +-- source/formats/manis/manis.xml | 28 +++++++-------- source/formats/matcol/matcol.xml | 4 +-- source/formats/ms2/ms2.xml | 46 ++++++++++++------------ source/formats/ovl/ovl.xml | 4 +-- source/formats/tex/tex.xml | 4 +-- source/formats/voxelskirt/voxelskirt.xml | 4 +-- 9 files changed, 58 insertions(+), 59 deletions(-) diff --git a/codegen/Union.py b/codegen/Union.py index 790836354..f9edff089 100644 --- a/codegen/Union.py +++ b/codegen/Union.py @@ -38,7 +38,7 @@ def get_conditions(field): elif ver2: conditionals.append(f"{VER} <= {ver2}") if vercond: - vercond = Expression(vercond) + vercond = Expression(vercond, g_vars=True) conditionals.append(f"{vercond}") if versions: conditionals.append(f"({' or '.join([f'is_{version}(self.context)' for version in versions])})") diff --git a/codegen/expression.py b/codegen/expression.py index a8fb8c1de..9b25c91a8 100644 --- a/codegen/expression.py +++ b/codegen/expression.py @@ -60,11 +60,11 @@ class Expression(object): operators = {'==', '!=', '>=', '<=', '&&', '||', '&', '|', '-', '!', '<', '>', '/', '*', '+', '%'} - def __init__(self, expr_str, name_filter=None): + def __init__(self, expr_str, name_filter=None, g_vars=False): try: left, self._op, right = self._partition(expr_str) - self._left = self._parse(left, name_filter) - self._right = self._parse(right, name_filter) + self._left = self._parse(left, name_filter, g_vars) + self._right = self._parse(right, name_filter, g_vars) except: print("error while parsing expression '%s'" % expr_str) raise @@ -163,7 +163,7 @@ def __str__(self): return f"{left} {op} {right}".strip() @classmethod - def _parse(cls, expr_str, name_filter=None): + def _parse(cls, expr_str, name_filter=None, g_vars=False): """Returns an Expression, string, or int, depending on the contents of .""" if not expr_str: @@ -171,10 +171,10 @@ def _parse(cls, expr_str, name_filter=None): return None # brackets or operators => expression if ("(" in expr_str) or (")" in expr_str): - return Expression(expr_str, name_filter) + return Expression(expr_str, name_filter, g_vars) for op in cls.operators: if expr_str.find(op) != -1: - return Expression(expr_str, name_filter) + return Expression(expr_str, name_filter, g_vars) # try to convert it to one of the following classes for create_cls in (int, Version): try: @@ -188,12 +188,11 @@ def _parse(cls, expr_str, name_filter=None): if name_filter is None: def name_filter(x): return convention.name_attribute(x) - prefix = "self." - # globals are stored on the stream - # it is only a global if the leftmost member has version in it - # ie. general_info.ms2_version is not a global - if "version" in expr_str.split(".")[0].lower(): + if g_vars: + # globals are stored on the context prefix = "self.context." + else: + prefix = "self." return prefix + ('.'.join(name_filter(comp) for comp in expr_str.split("."))) @classmethod diff --git a/source/formats/fgm/fgm.xml b/source/formats/fgm/fgm.xml index 55871d7a7..7d3beab20 100644 --- a/source/formats/fgm/fgm.xml +++ b/source/formats/fgm/fgm.xml @@ -9,7 +9,7 @@ Planet Zoo 1.6 Jurassic World Evolution - + Commonly used version expressions. Disneyland Adventure ZTUAC @@ -19,7 +19,7 @@ JWE, 25108 is JWE on switch - + Global Tokens. NOTE: These must be listed after the above tokens so that they replace last. For example, `verexpr` uses these tokens. diff --git a/source/formats/manis/manis.xml b/source/formats/manis/manis.xml index 212293e9d..62e0e3de7 100644 --- a/source/formats/manis/manis.xml +++ b/source/formats/manis/manis.xml @@ -4,7 +4,7 @@ - + Commonly used version expressions. PZ PZ @@ -12,7 +12,7 @@ PC - + Global Tokens. NOTE: These must be listed after the above tokens so that they replace last. For example, `verexpr` uses these tokens. @@ -224,10 +224,10 @@ always FF FF always FF FF - + rest 228 bytes - rest 14 bytes + rest 14 bytes always FF @@ -241,17 +241,17 @@ - - + + - - + + - - + + - - + + @@ -259,10 +259,10 @@ - + - + diff --git a/source/formats/matcol/matcol.xml b/source/formats/matcol/matcol.xml index 1ae254856..1d19a561b 100644 --- a/source/formats/matcol/matcol.xml +++ b/source/formats/matcol/matcol.xml @@ -2,13 +2,13 @@ - + Commonly used version expressions. PZ JWE - + Global Tokens. NOTE: These must be listed after the above tokens so that they replace last. For example, `verexpr` uses these tokens. diff --git a/source/formats/ms2/ms2.xml b/source/formats/ms2/ms2.xml index cbfd4c91c..a11d18f3b 100644 --- a/source/formats/ms2/ms2.xml +++ b/source/formats/ms2/ms2.xml @@ -4,7 +4,7 @@ Old - + Commonly used version expressions. Disneyland Adventure ZTUAC @@ -15,7 +15,7 @@ JWE, 25108 is JWE on switch - + Global Tokens. NOTE: These must be listed after the above tokens so that they replace last. For example, `verexpr` uses these tokens. @@ -323,18 +323,18 @@ used to find bone info name of ms2 - gives relevant info on the mdl, including counts and pack base - name pointers for each material - lod info for each level - material links for each model - model data blocks for this mdl2 + gives relevant info on the mdl, including counts and pack base + name pointers for each material + lod info for each level + material links for each model + model data blocks for this mdl2 - index into ms2 names array - index into ms2 names array - unknown, nonzero in PZ flamingo juvenile, might be junk (padding) - unknown, nonzero in PZ flamingo juvenile, might be junk (padding) + index into ms2 names array + index into ms2 names array + unknown, nonzero in PZ flamingo juvenile, might be junk (padding) + unknown, nonzero in PZ flamingo juvenile, might be junk (padding) @@ -522,7 +522,7 @@ index count 7 zero joint count - unnk 78 count + unnk 78 count jwe only, everything is shifted a bit due to extra uint 0 index into ms2 string table for bones used here @@ -597,28 +597,28 @@ small number small number small number - 0s, might be related to count 7 in PC + 0s, might be related to count 7 in PC size of the name buffer below, including trailing zeros 0s 0 or 1 0s - 0s + 0s 1, 1 matches bone count from bone info 0 usually 0s corresponds to bone transforms - might be pointers - - used by ptero, 16 bytes per entry - - + might be pointers + + used by ptero, 16 bytes per entry + + - ? - 1FAA FFAAFF00 000000 - counts hitchecks for pz - 0 + ? + 1FAA FFAAFF00 000000 + counts hitchecks for pz + 0 sometimes an array of floats index into bone info bones for each joint; bone that the joint is attached to diff --git a/source/formats/ovl/ovl.xml b/source/formats/ovl/ovl.xml index 21c92b760..1acff727e 100644 --- a/source/formats/ovl/ovl.xml +++ b/source/formats/ovl/ovl.xml @@ -9,7 +9,7 @@ Planet Zoo 1.6+ Jurassic World Evolution - + Commonly used version expressions. Disneyland Adventure ZTUAC @@ -19,7 +19,7 @@ JWE, 25108 is JWE on switch - + Global Tokens. NOTE: These must be listed after the above tokens so that they replace last. For example, `verexpr` uses these tokens. diff --git a/source/formats/tex/tex.xml b/source/formats/tex/tex.xml index e2c071331..ac510424e 100644 --- a/source/formats/tex/tex.xml +++ b/source/formats/tex/tex.xml @@ -9,7 +9,7 @@ Planet Zoo 1.6 Jurassic World Evolution - + Commonly used version expressions. Disneyland Adventure ZTUAC @@ -19,7 +19,7 @@ JWE, 25108 is JWE on switch - + Global Tokens. NOTE: These must be listed after the above tokens so that they replace last. For example, `verexpr` uses these tokens. diff --git a/source/formats/voxelskirt/voxelskirt.xml b/source/formats/voxelskirt/voxelskirt.xml index ca1700c3d..3facceb63 100644 --- a/source/formats/voxelskirt/voxelskirt.xml +++ b/source/formats/voxelskirt/voxelskirt.xml @@ -7,7 +7,7 @@ Planet Zoo Jurassic World Evolution - + Commonly used version expressions. ZTUAC PC @@ -15,7 +15,7 @@ JWE, 25108 is JWE on switch - + Global Tokens. NOTE: These must be listed after the above tokens so that they replace last. For example, `verexpr` uses these tokens.