Skip to content

Commit

Permalink
add encoding support for room render
Browse files Browse the repository at this point in the history
  • Loading branch information
cff29546 committed Jan 6, 2023
1 parent 6ecf5ef commit 19398b4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions pzmap2dzi/lotheader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def calc_room_bound(room):
def read_room(data, pos):
room = {}
name, pos = util.read_line(data, pos)
room['name'] = name.decode('utf8')
room['name'] = name
room['layer'], pos = util.read_uint32(data, pos)
rect_num, pos = util.read_uint32(data, pos)
rects = []
Expand Down Expand Up @@ -107,7 +107,7 @@ def print_header(header):
name = room['name']
rmap[name] = rmap.get(name, 0) + 1
for k, v in rmap.items():
print(' {}: {}'.format(k.decode('utf8'), v))
print(' {}: {}'.format(k, v))

level = [' ', '\u2591'*2, '\u2592'*2, '\u2593', '\u2588']
for y in range(30):
Expand Down
15 changes: 8 additions & 7 deletions render_room.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def render_edge(draw, x, y, color, width, border_flags):
for edge in edges:
draw.line(edge, fill=color, width=width)

def render_tile(dzi, tx, ty, in_path, out_path, save_empty):
def render_tile(dzi, tx, ty, in_path, out_path, save_empty, encoding):
flag_path = os.path.join(out_path, 'layer0_files', str(dzi.base_level))
util.set_wip(flag_path, tx, ty)
for layer in range(dzi.layers):
Expand Down Expand Up @@ -137,12 +137,12 @@ def render_tile(dzi, tx, ty, in_path, out_path, save_empty):
drawing = []
if (layer, subx, suby) in cell.label:
name = cell.label[layer, subx, suby]
color = COLOR_MAP.get(name, DEFAULT_COLOR)
drawing.append((render_text, (name, color, ROOM_FONT)))
color = COLOR_MAP.get(name.decode(encoding, errors='ignore'), DEFAULT_COLOR)
drawing.append((render_text, (name.decode(encoding, errors='ignore'), color, ROOM_FONT)))
if (layer, subx, suby) in cell.edge:
idx, flag = cell.edge[layer, subx, suby]
name = cell.name[idx]
color = COLOR_MAP.get(name, DEFAULT_COLOR)
color = COLOR_MAP.get(name.decode(encoding,errors='ignore'), DEFAULT_COLOR)
drawing.append((render_edge, (color, 3, flag)))

if drawing:
Expand All @@ -161,9 +161,9 @@ def render_tile(dzi, tx, ty, in_path, out_path, save_empty):
return True

def room_work(conf, tiles):
dzi, in_path, out_path, save_empty = conf
dzi, in_path, out_path, save_empty, encoding = conf
for tx, ty in tiles:
render_tile(dzi, tx, ty, in_path, out_path, save_empty)
render_tile(dzi, tx, ty, in_path, out_path, save_empty, encoding)

def process(args):
util.ensure_folder(args.output)
Expand All @@ -180,7 +180,7 @@ def process(args):
layer0_path = os.path.join(args.output, 'layer0_files', str(dzi.base_level))
groups = dzi.get_tile_groups(layer0_path, 'png', args.group_size, skip_cells)

conf = (dzi, args.input, args.output, args.save_empty_tile)
conf = (dzi, args.input, args.output, args.save_empty_tile, args.encoding)
t = mp.Task(room_work, conf, args.mp)
if not t.run(groups, args.verbose, args.stop_key):
return False
Expand All @@ -206,6 +206,7 @@ def process(args):
parser.add_argument('-v', '--verbose', action='store_true')
parser.add_argument('-e', '--save-empty-tile', action='store_true')
parser.add_argument('-s', '--stop-key', type=str, default='')
parser.add_argument('--encoding', type=str, default='utf8')
parser.add_argument('input', type=str)
args = parser.parse_args()

Expand Down

0 comments on commit 19398b4

Please sign in to comment.