def __init__(self, name: str, index: int, vtype: Union[VariantType, str, int]): self.is_inherited = False self.name = name self.index = index self.vtype = VariantType.get(vtype) self.address = GDScriptAddress.create(ADDRESS_MODE_MEMBER, index)
def __init__(self, name: str, vtype: Union[VariantType, int], index: int): self.name = name self.vtype = VariantType.get(vtype) self.index = index self.is_assigned = False self.address = GDScriptAddress.create(ADDRESS_MODE_STACKVARIABLE, index) self.is_optional = False
def __init__(self, index: int, vtype: Union[VariantType, str, int], data: bytes, declaration: str): self.index = index self.vtype = VariantType.get(vtype) self.data = data self.declaration = declaration self.address = GDScriptAddress.create(ADDRESS_MODE_LOCALCONSTANT, index)
def __init__(self, index: int, name: str, original_name: str, vtype: int, kind_code: int, value: str, source: Union[str, int]): self.index = index self.original_name = original_name self.vtype = VariantType.get(vtype) self.kind_code = kind_code self.value = value self.address = GDScriptAddress.create(ADDRESS_MODE_GLOBAL, index) if isinstance(source, str): if source == "GlobalConstants": self.source = GDScriptGlobal.SOURCE_CONSTANT elif source == "hard-coded": self.source = GDScriptGlobal.SOURCE_HARDCODED elif source == "ClassDB": self.source = GDScriptGlobal.SOURCE_CLASSDB elif source == "Singleton": self.source = GDScriptGlobal.SOURCE_SINGLETON elif isinstance(source, int): assert source in ( \ GDScriptGlobal.SOURCE_CONSTANT, \ GDScriptGlobal.SOURCE_HARDCODED, \ GDScriptGlobal.SOURCE_CLASSDB, \ GDScriptGlobal.SOURCE_SINGLETON) self.source = source
def __init__(self, name: str, vtype: Union[VariantType, str, int], data: bytes, declaration: str): self.name = name self.vtype = VariantType.get(vtype) self.data = data self.declaration = declaration
def _build_class(self, physical_path: Path, data) -> GDScriptClass: cls = GDScriptClass( self._project.to_resource_path(str(physical_path)), data.get("name", None) or self._project.generate_unique_class_name( to_camel_case(physical_path.with_suffix('').stem)), self._project.generate_unique_class_type_id()) cls.base_resource_path = data["base_type"] cls.built_in_type = data["type"] for index, entry in enumerate(data["global_constants"]): glob = GDScriptGlobal(index, entry["name"], entry["original_name"], entry["type_code"], entry["kind_code"], entry["value"], entry["source"]) cls.globals[glob.index] = glob for signal in data["signals"]: cls.add_signal(signal) for entry in data["members"]: member = GDScriptMember(entry["name"], int(entry["index"]), entry["type"]) cls.add_member(member) for index, entry in enumerate(data["constants"]): cconst = GDScriptClassConstant(entry["name"], int(entry["type"]), bytes(list(entry["data"])), entry["declaration"]) cls.add_constant(cconst) for index, entry in enumerate(data["methods"]): func = GDScriptFunction(entry["name"], GDScriptFunction.TYPE_METHOD) func.stack_size = int(entry["stack_size"]) func.default_arguments_jump_table = list( map(lambda x: int(x), entry["default_arguments"])) func.return_vtype = VariantType.get( int(entry["return_type"]["type"])) func.global_names = entry["global_names"] num_parameters = len(entry["parameters"]) len_jump_table = len(func.default_arguments_jump_table) for pindex, pentry in enumerate(entry["parameters"]): param = GDScriptFunctionParameter( pentry["name"], VariantType.get(pentry["type"]), pindex) param.is_optional = pindex >= num_parameters - len_jump_table func.add_parameter(param) for centry in entry["constants"]: mconst = GDScriptFunctionConstant( int(centry["index"]), centry["type"], bytes(list(map(lambda x: int(x), centry["data"]))), centry["declaration"]) func.add_constant(mconst) ip = 0 while ip < len(entry["bytecode"]): op = extract(func, entry["bytecode"], ip) func.add_op(ip, op) ip += op.stride cls.add_function(func) return cls