mirror of
https://github.com/zeldaret/oot.git
synced 2025-05-10 11:03:46 +00:00
Move {} to in-source
This commit is contained in:
parent
6e9b4d1a59
commit
b1fc3f2495
6 changed files with 87 additions and 29 deletions
|
@ -33,8 +33,6 @@ int main(int argc, char** argv) {
|
|||
FILE* in_bin = stdin;
|
||||
FILE* out_c = stdout;
|
||||
|
||||
fprintf(out_c, "{\n");
|
||||
|
||||
int cur_line_nelems = 0;
|
||||
|
||||
while (true) {
|
||||
|
@ -80,7 +78,5 @@ int main(int argc, char** argv) {
|
|||
fprintf(out_c, "\n");
|
||||
}
|
||||
|
||||
fprintf(out_c, "}\n");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -749,6 +749,8 @@ class Resource(abc.ABC):
|
|||
- an array of data, such as a display list Gfx[], or a texture u64[]
|
||||
"""
|
||||
|
||||
braces_in_source = True
|
||||
|
||||
def __init_subclass__(cls, /, can_size_be_unknown=False, **kwargs):
|
||||
super().__init_subclass__(**kwargs)
|
||||
cls.can_size_be_unknown = can_size_be_unknown
|
||||
|
@ -956,10 +958,16 @@ class Resource(abc.ABC):
|
|||
if hasattr(self, "HACK_IS_STATIC_ON"):
|
||||
c.write("static ")
|
||||
c.write(self.get_c_declaration_base())
|
||||
c.write(" =\n")
|
||||
if self.braces_in_source:
|
||||
c.write(" = {\n")
|
||||
else:
|
||||
c.write(" =\n")
|
||||
|
||||
c.write(f'#include "{self.inc_c_path}"\n')
|
||||
c.write(";\n")
|
||||
if self.braces_in_source:
|
||||
c.write("};\n")
|
||||
else:
|
||||
c.write(";\n")
|
||||
|
||||
return True
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ from .repr_c_struct import (
|
|||
class CDataExtWriteContext:
|
||||
f: io.TextIOBase
|
||||
line_prefix: str
|
||||
inhibit_top_braces: bool
|
||||
|
||||
|
||||
class CDataExt(CData, abc.ABC):
|
||||
|
@ -66,6 +67,8 @@ class CDataExt(CData, abc.ABC):
|
|||
v: Any,
|
||||
f: io.TextIOBase,
|
||||
line_prefix: str,
|
||||
*,
|
||||
inhibit_top_braces: bool,
|
||||
) -> bool: ...
|
||||
|
||||
def report(
|
||||
|
@ -88,6 +91,8 @@ class CDataExt(CData, abc.ABC):
|
|||
v: Any,
|
||||
f: io.TextIOBase,
|
||||
line_prefix: str,
|
||||
*,
|
||||
inhibit_top_braces: bool,
|
||||
) -> bool:
|
||||
"""
|
||||
Returns True if something has been written
|
||||
|
@ -95,13 +100,23 @@ class CDataExt(CData, abc.ABC):
|
|||
"""
|
||||
if self.write_f:
|
||||
ret = self.write_f(
|
||||
resource, memory_context, v, CDataExtWriteContext(f, line_prefix)
|
||||
resource,
|
||||
memory_context,
|
||||
v,
|
||||
CDataExtWriteContext(f, line_prefix, inhibit_top_braces),
|
||||
)
|
||||
# This assert is meant to ensure the function returns a value at all,
|
||||
# since it's easy to forget to return a value (typically True)
|
||||
assert isinstance(ret, bool), ("must return a bool", self.write_f)
|
||||
else:
|
||||
ret = self.write_default(resource, memory_context, v, f, line_prefix)
|
||||
ret = self.write_default(
|
||||
resource,
|
||||
memory_context,
|
||||
v,
|
||||
f,
|
||||
line_prefix,
|
||||
inhibit_top_braces=inhibit_top_braces,
|
||||
)
|
||||
assert isinstance(ret, bool), self
|
||||
return ret
|
||||
|
||||
|
@ -139,7 +154,12 @@ class CDataExt_Value(CData_Value, CDataExt):
|
|||
if v != 0:
|
||||
raise Exception("non-0 padding")
|
||||
|
||||
def write_default(self, resource, memory_context, v, f, line_prefix):
|
||||
def write_default(
|
||||
self, resource, memory_context, v, f, line_prefix, *, inhibit_top_braces
|
||||
):
|
||||
assert (
|
||||
not inhibit_top_braces
|
||||
), "CDataExt_Value can't inhibit top braces, it doesn't have any"
|
||||
if not self.is_padding:
|
||||
f.write(line_prefix)
|
||||
f.write(str(v))
|
||||
|
@ -177,18 +197,27 @@ class CDataExt_Array(CData_Array, CDataExt):
|
|||
for elem in v:
|
||||
self.element_cdata_ext.report(resource, memory_context, elem)
|
||||
|
||||
def write_default(self, resource, memory_context, v, f, line_prefix):
|
||||
def write_default(
|
||||
self, resource, memory_context, v, f, line_prefix, *, inhibit_top_braces
|
||||
):
|
||||
assert isinstance(v, list)
|
||||
f.write(line_prefix)
|
||||
f.write("{\n")
|
||||
if not inhibit_top_braces:
|
||||
f.write(line_prefix)
|
||||
f.write("{\n")
|
||||
for i, elem in enumerate(v):
|
||||
ret = self.element_cdata_ext.write(
|
||||
resource, memory_context, elem, f, line_prefix + INDENT
|
||||
resource,
|
||||
memory_context,
|
||||
elem,
|
||||
f,
|
||||
line_prefix + INDENT,
|
||||
inhibit_top_braces=False,
|
||||
)
|
||||
assert ret
|
||||
f.write(f", // {i}\n")
|
||||
f.write(line_prefix)
|
||||
f.write("}")
|
||||
if not inhibit_top_braces:
|
||||
f.write(line_prefix)
|
||||
f.write("}")
|
||||
return True
|
||||
|
||||
|
||||
|
@ -203,17 +232,26 @@ class CDataExt_Struct(CData_Struct, CDataExt):
|
|||
for member_name, member_cdata_ext in self.members_ext:
|
||||
member_cdata_ext.report(resource, memory_context, v[member_name])
|
||||
|
||||
def write_default(self, resource, memory_context, v, f, line_prefix):
|
||||
def write_default(
|
||||
self, resource, memory_context, v, f, line_prefix, *, inhibit_top_braces
|
||||
):
|
||||
assert isinstance(v, dict)
|
||||
f.write(line_prefix)
|
||||
f.write("{\n")
|
||||
if not inhibit_top_braces:
|
||||
f.write(line_prefix)
|
||||
f.write("{\n")
|
||||
for member_name, member_cdata_ext in self.members_ext:
|
||||
if member_cdata_ext.write(
|
||||
resource, memory_context, v[member_name], f, line_prefix + INDENT
|
||||
resource,
|
||||
memory_context,
|
||||
v[member_name],
|
||||
f,
|
||||
line_prefix + INDENT,
|
||||
inhibit_top_braces=False,
|
||||
):
|
||||
f.write(f", // {member_name}\n")
|
||||
f.write(line_prefix)
|
||||
f.write("}")
|
||||
if not inhibit_top_braces:
|
||||
f.write(line_prefix)
|
||||
f.write("}")
|
||||
return True
|
||||
|
||||
|
||||
|
@ -268,7 +306,14 @@ class CDataResource(Resource):
|
|||
|
||||
def write_extracted(self, memory_context):
|
||||
with self.extract_to_path.open("w") as f:
|
||||
self.cdata_ext.write(self, memory_context, self.cdata_unpacked, f, "")
|
||||
self.cdata_ext.write(
|
||||
self,
|
||||
memory_context,
|
||||
self.cdata_unpacked,
|
||||
f,
|
||||
"",
|
||||
inhibit_top_braces=self.braces_in_source,
|
||||
)
|
||||
f.write("\n")
|
||||
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@ VERBOSE_BEST_EFFORT_TLUT_NO_REAL_USER = True
|
|||
|
||||
|
||||
class MtxResource(CDataResource):
|
||||
braces_in_source = False
|
||||
|
||||
def write_mtx(resource, memory_context, v, wctx: CDataExtWriteContext):
|
||||
assert isinstance(v, dict)
|
||||
|
@ -1258,6 +1259,7 @@ class DListResource(Resource, can_size_be_unknown=True):
|
|||
|
||||
def write_extracted(self, memory_context):
|
||||
def macro_fn():
|
||||
pygfxd.gfxd_puts(INDENT)
|
||||
ret = pygfxd.gfxd_macro_dflt()
|
||||
pygfxd.gfxd_puts(",\n")
|
||||
return ret
|
||||
|
@ -1421,7 +1423,8 @@ class DListResource(Resource, can_size_be_unknown=True):
|
|||
return 1
|
||||
|
||||
with self.extract_to_path.open("wb") as f:
|
||||
f.write(b"{\n")
|
||||
if not self.braces_in_source:
|
||||
f.write(b"{\n")
|
||||
|
||||
out_string_wrapper = StringWrapper(b"", 120, f.write)
|
||||
|
||||
|
@ -1444,7 +1447,8 @@ class DListResource(Resource, can_size_be_unknown=True):
|
|||
|
||||
out_string_wrapper.flush()
|
||||
|
||||
f.write(b"}\n")
|
||||
if not self.braces_in_source:
|
||||
f.write(b"}\n")
|
||||
|
||||
|
||||
def report_gfx_segmented(resource: Resource, memory_context: "MemoryContext", v):
|
||||
|
@ -1467,7 +1471,7 @@ def write_gfx_segmented(
|
|||
resource: Resource,
|
||||
memory_context: "MemoryContext",
|
||||
v,
|
||||
wctx:CDataExtWriteContext,
|
||||
wctx: CDataExtWriteContext,
|
||||
):
|
||||
assert isinstance(v, int)
|
||||
address = v
|
||||
|
|
|
@ -41,9 +41,11 @@ class CutsceneResource(Resource, can_size_be_unknown=True):
|
|||
def write_extracted(self, memory_context):
|
||||
with self.extract_to_path.open("w") as f:
|
||||
f.write('#include "z64cutscene_commands.h"\n')
|
||||
f.write("{\n")
|
||||
if not self.braces_in_source:
|
||||
f.write("{\n")
|
||||
f.write(self.cs_source)
|
||||
f.write("}\n")
|
||||
if not self.braces_in_source:
|
||||
f.write("}\n")
|
||||
|
||||
def get_c_declaration_base(self):
|
||||
return f"CutsceneData {self.symbol_name}[]"
|
||||
|
|
|
@ -426,7 +426,8 @@ class SceneCommandsResource(Resource, can_size_be_unknown=True):
|
|||
def write_extracted(self, memory_context):
|
||||
data = self.file.data[self.range_start : self.range_end]
|
||||
with self.extract_to_path.open("w") as f:
|
||||
f.write("{\n")
|
||||
if not self.braces_in_source:
|
||||
f.write("{\n")
|
||||
for offset in range(0, len(data), 8):
|
||||
(cmd_id_int, data1, pad2, data2_I) = struct.unpack_from(
|
||||
">BBHI", data, offset
|
||||
|
@ -615,7 +616,9 @@ class SceneCommandsResource(Resource, can_size_be_unknown=True):
|
|||
f.write(f"{sceneCamType_name}, {worldMapLocation}")
|
||||
|
||||
f.write("),\n")
|
||||
f.write("}\n")
|
||||
|
||||
if not self.braces_in_source:
|
||||
f.write("}\n")
|
||||
|
||||
def get_c_reference(self, resource_offset: int):
|
||||
if resource_offset == 0:
|
||||
|
|
Loading…
Add table
Reference in a new issue