Rolled string preprocessing into make_string_img_large as it's not needed for anything else
This commit is contained in:
parent
af0361f91b
commit
dda90f1544
2
const.py
2
const.py
|
@ -47,7 +47,7 @@ Glyphs_Kanji1 = ( # TODO: finish this
|
||||||
'人','見','魔','物', '大',' ',' ','何', ' ',' ',' ','手', '言',' ',' ',' ', # 0x010
|
'人','見','魔','物', '大',' ',' ','何', ' ',' ',' ','手', '言',' ',' ',' ', # 0x010
|
||||||
' ','心','間',' ', '風',' ',' ',' ', ' ',' ',' ','兵', '火',' ',' ',' ', # 0x020
|
' ','心','間',' ', '風',' ',' ',' ', ' ',' ',' ','兵', '火',' ',' ',' ', # 0x020
|
||||||
' ',' ',' ',' ', ' ','女',' ',' ', '地',' ',' ',' ', ' ',' ',' ',' ', # 0x030
|
' ',' ',' ',' ', ' ','女',' ',' ', '地',' ',' ',' ', ' ',' ',' ',' ', # 0x030
|
||||||
' ',' ',' ',' ', ' ',' ',' ',' ', ' ',' ',' ',' ', ' ','一',' ',' ', # 0x040
|
' ',' ',' ','水', ' ',' ',' ',' ', ' ',' ',' ',' ', ' ','一',' ',' ', # 0x040
|
||||||
' ',' ','神',' ', ' ',' ','殿',' ', ' ',' ',' ',' ', ' ','子',' ',' ', # 0x050
|
' ',' ','神',' ', ' ',' ','殿',' ', ' ',' ',' ',' ', ' ','子',' ',' ', # 0x050
|
||||||
' ',' ','書',' ', ' ',' ',' ',' ', ' ',' ',' ',' ', ' ',' ',' ',' ', # 0x060
|
' ',' ','書',' ', ' ',' ',' ',' ', ' ',' ',' ',' ', ' ',' ',' ',' ', # 0x060
|
||||||
' ',' ','階',' ', ' ',' ',' ',' ', ' ',' ','土',' ', ' ',' ',' ',' ', # 0x070
|
' ',' ','階',' ', ' ',' ',' ',' ', ' ',' ','土',' ', ' ',' ',' ',' ', # 0x070
|
||||||
|
|
47
ff5reader.py
47
ff5reader.py
|
@ -244,34 +244,28 @@ def make_string_img_small(bytestring, jp=False):
|
||||||
del painter
|
del painter
|
||||||
return string, QPixmap.fromImage(img)
|
return string, QPixmap.fromImage(img)
|
||||||
|
|
||||||
def string_preprocess(bytestring, macros=None):
|
def make_string_img_large(bytestring, macros=None, jp=False):
|
||||||
'''
|
'''
|
||||||
This deals with pesky control codes that lump in the following byte.
|
This is how we decipher dialogue data, which has multiple lines, macro expansions and kanji.
|
||||||
Additionally, it can expand the macros used in JP dialogue.
|
|
||||||
Only really needed for stuff that uses the large set of glyphs.
|
|
||||||
'''
|
|
||||||
out = []
|
|
||||||
bytes = iter(bytestring)
|
|
||||||
for b in bytes:
|
|
||||||
if b in const.DoubleChars:
|
|
||||||
b2 = next(bytes)
|
|
||||||
out.append((b<<8) + b2)
|
|
||||||
elif macros and b in macros:
|
|
||||||
out.extend(macros[b])
|
|
||||||
else:
|
|
||||||
out.append(b)
|
|
||||||
return out
|
|
||||||
|
|
||||||
def make_string_img_large(bytestring, jp=False):
|
|
||||||
'''
|
|
||||||
This is how we decipher dialogue data, which has multiple lines among other things.
|
|
||||||
English characters have varying widths. In the japanese version, everything is fullwidth (16px)
|
English characters have varying widths. In the japanese version, everything is fullwidth (16px)
|
||||||
Kanji aren't used in English dialogue but the cost is likely the same in checking either way.
|
Kanji aren't used in English dialogue but the cost is likely the same in checking either way.
|
||||||
'''
|
'''
|
||||||
if len(bytestring) < 1:
|
if len(bytestring) < 1:
|
||||||
raise ValueError('Empty bytestring was passed')
|
raise ValueError('Empty bytestring was passed')
|
||||||
|
|
||||||
|
newstring = []
|
||||||
|
bytes = iter(bytestring)
|
||||||
|
for b in bytes:
|
||||||
|
if b in const.DoubleChars:
|
||||||
|
b2 = next(bytes)
|
||||||
|
newstring.append((b<<8) + b2)
|
||||||
|
elif macros and b in macros:
|
||||||
|
newstring.extend(macros[b])
|
||||||
|
else:
|
||||||
|
newstring.append(b)
|
||||||
|
|
||||||
string = ""
|
string = ""
|
||||||
|
# Because the length of the input has little bearing on the size of the image thanks to linebreaks and macros, we overprovision then clip away.
|
||||||
max_width = 256 # This seems to check out, but the EN dialogue has linebreaks virtually everywhere anyway
|
max_width = 256 # This seems to check out, but the EN dialogue has linebreaks virtually everywhere anyway
|
||||||
max_height = 512 # I've seen up to 58 rows in EN, 36 in JP. Stay safe.
|
max_height = 512 # I've seen up to 58 rows in EN, 36 in JP. Stay safe.
|
||||||
img = QImage(max_width, max_height, QImage.Format_RGB16)
|
img = QImage(max_width, max_height, QImage.Format_RGB16)
|
||||||
|
@ -279,7 +273,7 @@ def make_string_img_large(bytestring, jp=False):
|
||||||
painter = QtGui.QPainter(img)
|
painter = QtGui.QPainter(img)
|
||||||
|
|
||||||
x = xmax = y = 0
|
x = xmax = y = 0
|
||||||
for j in bytestring:
|
for j in newstring:
|
||||||
if x >= max_width: # Wrap on long line
|
if x >= max_width: # Wrap on long line
|
||||||
string += '[wr]\n'
|
string += '[wr]\n'
|
||||||
xmax = max_width # Can't go higher than this anyway
|
xmax = max_width # Can't go higher than this anyway
|
||||||
|
@ -335,7 +329,7 @@ def make_string_img_list(start, length, num, start_jp=None, len_jp=None, start_s
|
||||||
try:
|
try:
|
||||||
if en_end > en_start:
|
if en_end > en_start:
|
||||||
if large:
|
if large:
|
||||||
str_en, img_en = make_string_img_large(string_preprocess(ROM_en[en_start:en_end], macros_en))
|
str_en, img_en = make_string_img_large(ROM_en[en_start:en_end], macros_en)
|
||||||
else:
|
else:
|
||||||
str_en, img_en = make_string_img_small(ROM_en[en_start:en_end])
|
str_en, img_en = make_string_img_small(ROM_en[en_start:en_end])
|
||||||
else:
|
else:
|
||||||
|
@ -343,11 +337,10 @@ def make_string_img_list(start, length, num, start_jp=None, len_jp=None, start_s
|
||||||
img_en = None
|
img_en = None
|
||||||
|
|
||||||
if jp_end > jp_start:
|
if jp_end > jp_start:
|
||||||
bytestring = string_preprocess(ROM_jp[jp_start:jp_end], macros_jp)
|
|
||||||
if large:
|
if large:
|
||||||
str_jp, img_jp = make_string_img_large(bytestring, jp=True)
|
str_jp, img_jp = make_string_img_large(ROM_jp[jp_start:jp_end], macros_jp, jp=True)
|
||||||
else:
|
else:
|
||||||
str_jp, img_jp = make_string_img_small(bytestring, jp=True)
|
str_jp, img_jp = make_string_img_small(ROM_jp[jp_start:jp_end], jp=True)
|
||||||
else:
|
else:
|
||||||
str_jp = ''
|
str_jp = ''
|
||||||
img_jp = None
|
img_jp = None
|
||||||
|
@ -360,8 +353,8 @@ def make_string_img_list(start, length, num, start_jp=None, len_jp=None, start_s
|
||||||
j1 = start + (id*length)
|
j1 = start + (id*length)
|
||||||
j2 = start_jp + (id*len_jp)
|
j2 = start_jp + (id*len_jp)
|
||||||
if large:
|
if large:
|
||||||
str_en, img_en = make_string_img_large(string_preprocess(ROM_en[j1:j1+length], macros_en))
|
str_en, img_en = make_string_img_large(ROM_en[j1:j1+length], macros_en)
|
||||||
str_jp, img_jp = make_string_img_large(string_preprocess(ROM_jp[j2:j2+len_jp], macros_jp), jp=True)
|
str_jp, img_jp = make_string_img_large(ROM_jp[j2:j2+len_jp], macros_jp, jp=True)
|
||||||
else:
|
else:
|
||||||
str_en, img_en = make_string_img_small(ROM_en[j1:j1+length])
|
str_en, img_en = make_string_img_small(ROM_en[j1:j1+length])
|
||||||
str_jp, img_jp = make_string_img_small(ROM_jp[j2:j2+len_jp], jp=True)
|
str_jp, img_jp = make_string_img_small(ROM_jp[j2:j2+len_jp], jp=True)
|
||||||
|
|
Loading…
Reference in New Issue