Skip to content

Commit

Permalink
Add encoding option to decode unit name
Browse files Browse the repository at this point in the history
  • Loading branch information
armoha committed Jan 27, 2021
1 parent 6b65433 commit 962c70e
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions eudplib/core/mapdata/tblformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
from ... import utils as ut
from ...localize import _

unit_name_encoding = "cp949"


def DecodeUnitNameAs(e):
global unit_name_encoding
" ".encode(e)
unit_name_encoding = e


def IgnoreColor(s):
return bytes(filter(lambda x: not (0x01 <= x <= 0x1F or x == 0x7F), s))
Expand Down Expand Up @@ -203,10 +211,10 @@ def LoadTBLWithChk(self, content, init_chkt):
if nextstring != b"":
if j in unitdict:
try:
nextstring = (nextstring.decode("cp949")).encode(
"utf-8"
)
except (UnicodeDecodeError):
nextstring = (
nextstring.decode(unit_name_encoding)
).encode("utf-8")
except UnicodeDecodeError:
pass
self._emptystring.append((i - 1, nextstring))
break
Expand All @@ -216,8 +224,8 @@ def LoadTBLWithChk(self, content, init_chkt):
if string:
if i in unitdict:
try:
string = (string.decode("cp949")).encode("utf-8")
except (UnicodeDecodeError):
string = (string.decode(unit_name_encoding)).encode("utf-8")
except UnicodeDecodeError:
pass
unitmap.AddItem(string, unitdict[i])
if string != IgnoreColor(string):
Expand Down

0 comments on commit 962c70e

Please sign in to comment.