File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed
openage/convert/value_object/read Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change 77
88from enum import Enum
99
10+ from ....log import warn
11+
1012
1113if typing .TYPE_CHECKING :
1214 from openage .convert .value_object .read .genie_structure import GenieStructure
@@ -286,7 +288,8 @@ def __init__(
286288 self ,
287289 type_name : str ,
288290 lookup_dict : dict [int , str ],
289- raw_type : str
291+ raw_type : str ,
292+ unknown_lookup_prefix : str = None ,
290293 ):
291294 super ().__init__ (
292295 type_name ,
@@ -295,14 +298,24 @@ def __init__(
295298 self .lookup_dict = lookup_dict
296299 self .raw_type = raw_type
297300
301+ self .unknown_lookup_prefix = unknown_lookup_prefix
302+
298303 def entry_hook (self , data : int ) -> str :
299304 """
300305 perform lookup of raw data -> enum member name
306+
307+ Throws an error if the lookup fails and no unknown lookup prefix is defined.
301308 """
302- try :
309+ if data in self . lookup_dict :
303310 return self .lookup_dict [data ]
304311
305- except KeyError :
312+ elif self .unknown_lookup_prefix is not None :
313+ unknown_string = f"{ self .unknown_lookup_prefix } _{ data :#X} "
314+ warn ("Could not find enum string for value %s, using '%s'" ,
315+ str (data ), unknown_string )
316+ return unknown_string
317+
318+ else :
306319 try :
307320 h = f" = { hex (data )} "
308321
You can’t perform that action at this time.
0 commit comments