mirror of
https://github.com/pmret/papermario.git
synced 2024-11-09 12:32:38 +01:00
SPEED
This commit is contained in:
parent
f558d0faa6
commit
ec96845074
@ -374,13 +374,13 @@ class N64SegPaperMarioMessages(N64Segment):
|
||||
|
||||
path = Path(base_path, self.name, name + ".msg")
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
with open(path, "w") as f:
|
||||
with open(path, "w") as self.f:
|
||||
for j, msg_offset in enumerate(msg_offsets):
|
||||
if j != 0:
|
||||
f.write("\n")
|
||||
f.write(f"[message section=0x{i:02X} index={j}]\n")
|
||||
self.write_message_markup(data[msg_offset:], f)
|
||||
f.write("\n[/message]\n")
|
||||
self.f.write("\n")
|
||||
self.f.write(f"[message section=0x{i:02X} index={j}]\n")
|
||||
self.write_message_markup(data[msg_offset:])
|
||||
self.f.write("\n[/message]\n")
|
||||
#vmprof.disable()
|
||||
log.close()
|
||||
|
||||
@ -391,51 +391,44 @@ class N64SegPaperMarioMessages(N64Segment):
|
||||
def get_default_name(addr):
|
||||
return "msg"
|
||||
|
||||
def write_message_markup(self, data, f):
|
||||
def write_message_markup(self, data):
|
||||
pos = 0
|
||||
font = CHARSET
|
||||
|
||||
while data[pos] != 0xFD:
|
||||
markup, delta = self.char_to_markup(data[pos:], charset=font)
|
||||
self.charset = CHARSET
|
||||
|
||||
f.write(markup)
|
||||
pos += delta
|
||||
while True:
|
||||
char = data[pos]
|
||||
|
||||
if markup == "[font=title]\n" or markup == "[font=subtitle]\n":
|
||||
font = CHARSET_CREDITS
|
||||
elif markup == "[font=normal]":
|
||||
font = CHARSET
|
||||
if char in self.charset:
|
||||
value = self.charset[char]
|
||||
elif None in self.charset:
|
||||
value = self.charset[None]
|
||||
|
||||
def char_to_markup(self, data, charset=CHARSET):
|
||||
pos = 0
|
||||
markup = []
|
||||
if value is None:
|
||||
value = fallback
|
||||
|
||||
while True:
|
||||
char = data[pos]
|
||||
if isinstance(value, str):
|
||||
self.write_markup(value)
|
||||
pos += 1
|
||||
break
|
||||
elif callable(value):
|
||||
markup, delta = value(data[1:])
|
||||
self.write_markup(markup)
|
||||
pos += delta
|
||||
break
|
||||
elif isinstance(value, dict):
|
||||
if None in self.charset:
|
||||
fallback = self.charset[None]
|
||||
self.charset = value
|
||||
pos += 1
|
||||
else:
|
||||
raise ValueError(value)
|
||||
|
||||
if char in charset:
|
||||
value = charset[char]
|
||||
elif None in charset:
|
||||
value = charset[None]
|
||||
def write_markup(self, markup):
|
||||
self.f.write(markup)
|
||||
|
||||
if value is None:
|
||||
value = fallback
|
||||
|
||||
if isinstance(value, str):
|
||||
markup.append(value)
|
||||
pos += 1
|
||||
break
|
||||
elif callable(value):
|
||||
more_markup, delta = value(data[1:])
|
||||
markup.append(more_markup)
|
||||
pos += delta
|
||||
break
|
||||
elif isinstance(value, dict):
|
||||
if None in charset:
|
||||
fallback = charset[None]
|
||||
charset = value
|
||||
pos += 1
|
||||
else:
|
||||
raise ValueError(value)
|
||||
|
||||
return "".join(markup), pos # this is quicker than string appends
|
||||
if markup == "[font=title]\n" or markup == "[font=subtitle]\n":
|
||||
self.charset = CHARSET_CREDITS
|
||||
elif markup == "[font=normal]":
|
||||
self.charset = CHARSET
|
||||
|
Loading…
Reference in New Issue
Block a user