You've already forked PythonLib
mirror of
https://github.com/lifebottle/PythonLib.git
synced 2026-02-13 15:25:50 -08:00
Creating text_to_bytes function
This commit is contained in:
58
ToolsTOPX.py
58
ToolsTOPX.py
@@ -475,7 +475,63 @@ class ToolsTOPX(ToolsTales):
|
||||
return final_text, pos
|
||||
|
||||
|
||||
|
||||
def text_to_bytes(self, text):
|
||||
|
||||
splitLineBreak = text.split('\x0A')
|
||||
nb = len(splitLineBreak)
|
||||
bytesFinal = b''
|
||||
i=0
|
||||
|
||||
for line in splitLineBreak:
|
||||
string_hex = re.split(self.HEX_TAG, line)
|
||||
string_hex = [sh for sh in string_hex if sh]
|
||||
#print(string_hex)
|
||||
for s in string_hex:
|
||||
if re.match(self.HEX_TAG, s):
|
||||
bytesFinal += struct.pack("B", int(s[1:3], 16))
|
||||
else:
|
||||
s_com = re.split(self.COMMON_TAG, s)
|
||||
s_com = [sc for sc in s_com if sc]
|
||||
|
||||
for c in s_com:
|
||||
|
||||
if re.match(self.COMMON_TAG, c):
|
||||
if ":" in c:
|
||||
split = c.split(":")
|
||||
|
||||
if split[0][1:] in self.itags.keys():
|
||||
bytesFinal += struct.pack("B", self.itags[split[0][1:]])
|
||||
bytesFinal += struct.pack("<I", int(split[1][:-1], 16))
|
||||
elif split[0][1:4] == "Unk":
|
||||
bytesFinal += struct.pack("B", int(split[0][4:], 16))
|
||||
for j in [split[1][j:j+2] for j in range(0, len(split[1]) - 2, 2)]:
|
||||
bytesFinal += struct.pack("B", int(j, 16))
|
||||
bytesFinal += struct.pack("B", 0x80)
|
||||
else:
|
||||
bytesFinal += struct.pack("B", int(split[0][1:], 16))
|
||||
bytesFinal += struct.pack("<I", int(split[1][:8], 16))
|
||||
|
||||
if c in self.jsonTblTags['NAME']:
|
||||
bytesFinal += struct.pack("B", 0x4)
|
||||
c = '(' + c.replace("<","").replace(">","") + ")"
|
||||
bytesFinal += c.encode("cp932")
|
||||
|
||||
if c in self.icolors:
|
||||
bytesFinal += struct.pack("B", 0x5)
|
||||
bytesFinal += struct.pack("<I", self.icolors[c])
|
||||
else:
|
||||
for c2 in c:
|
||||
if c2 in self.itable.keys():
|
||||
bytesFinal += self.itable[c2]
|
||||
else:
|
||||
|
||||
bytesFinal += c2.encode("cp932")
|
||||
|
||||
i=i+1
|
||||
if (nb >=2 and i<nb):
|
||||
bytesFinal += b'\x01'
|
||||
|
||||
return bytesFinal
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user