Skip to content

Commit

Permalink
configurable font
Browse files Browse the repository at this point in the history
  • Loading branch information
cff29546 committed Jul 26, 2023
1 parent dcf0380 commit f806ccf
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 20 deletions.
14 changes: 13 additions & 1 deletion conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,23 @@ render_conf:
# carto-zed: Carto-Zed like color theme
top_view_color_mode: avg

# font settings
default_font: arial.ttf
default_font_size: 20
# room font settings, using default font if omitted
# room_font: arial.ttf
# room_font_size: 20

# zombie heatmap
zombie_count: true
# zombie count font settings, using default font if omitted
# zombie_count_font: arial.ttf
zombie_count_font_size: 40

# objects areas
vehicle: true
special_zombie: true
stroy: true

# objects font settings, using default font if omitted
# objects_font: arial.ttf
# objects_font_size: 20
14 changes: 13 additions & 1 deletion docs/examples/conf(mod_maps).yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,23 @@ render_conf:
# carto-zed: Carto-Zed like color theme
top_view_color_mode: avg

# font settings
default_font: arial.ttf
default_font_size: 20
# room font settings, using default font if omitted
# room_font: arial.ttf
# room_font_size: 20

# zombie heatmap
zombie_count: true
# zombie count font settings, using default font if omitted
# zombie_count_font: arial.ttf
zombie_count_font_size: 40

# objects areas
vehicle: true
special_zombie: true
stroy: true

# objects font settings, using default font if omitted
# objects_font: arial.ttf
# objects_font_size: 20
14 changes: 13 additions & 1 deletion docs/examples/conf(no_base_map).yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,23 @@ render_conf:
# carto-zed: Carto-Zed like color theme
top_view_color_mode: avg

# font settings
default_font: arial.ttf
default_font_size: 20
# room font settings, using default font if omitted
# room_font: arial.ttf
# room_font_size: 20

# zombie heatmap
zombie_count: true
# zombie count font settings, using default font if omitted
# zombie_count_font: arial.ttf
zombie_count_font_size: 40

# objects areas
vehicle: true
special_zombie: true
stroy: true

# objects font settings, using default font if omitted
# objects_font: arial.ttf
# objects_font_size: 20
14 changes: 13 additions & 1 deletion docs/examples/conf(omit_2_bottom_levels).yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,23 @@ render_conf:
# carto-zed: Carto-Zed like color theme
top_view_color_mode: avg

# font settings
default_font: arial.ttf
default_font_size: 20
# room font settings, using default font if omitted
# room_font: arial.ttf
# room_font_size: 20

# zombie heatmap
zombie_count: true
# zombie count font settings, using default font if omitted
# zombie_count_font: arial.ttf
zombie_count_font_size: 40

# objects areas
vehicle: true
special_zombie: true
stroy: true

# objects font settings, using default font if omitted
# objects_font: arial.ttf
# objects_font_size: 20
14 changes: 13 additions & 1 deletion docs/examples/conf(stop_with_f9).yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,23 @@ render_conf:
# carto-zed: Carto-Zed like color theme
top_view_color_mode: avg

# font settings
default_font: arial.ttf
default_font_size: 20
# room font settings, using default font if omitted
# room_font: arial.ttf
# room_font_size: 20

# zombie heatmap
zombie_count: true
# zombie count font settings, using default font if omitted
# zombie_count_font: arial.ttf
zombie_count_font_size: 40

# objects areas
vehicle: true
special_zombie: true
stroy: true

# objects font settings, using default font if omitted
# objects_font: arial.ttf
# objects_font_size: 20
6 changes: 1 addition & 5 deletions install_requirements.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
pushd %~dp0
for /f "delims=" %%x in (config.txt) do set %%x

%python% -m pip install -r "%~dp0requirements.txt"
popd
python -m pip install -r "%~dp0requirements.txt"
10 changes: 8 additions & 2 deletions pzmap2dzi/render_impl/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,17 @@ def tile(self, im_getter, cx, cy, layer, size):
'ZoneStory': 'yellow',
}
DEFAULT_COLOR = 'white'
OBJ_FONT = ImageFont.truetype("arial.ttf", 20)

class ObjectsRender(object):
def __init__(self, **options):
self.input = options.get('input')
font_name = options.get('objects_font')
if not font_name:
font_name = options.get('default_font', 'arial.tff')
font_size = options.get('objects_font_size')
if not font_size:
font_size = options.get('default_font_size', 20)
self.font = ImageFont.truetype(font_name, int(font_size))
objects_path = os.path.join(self.input, 'objects.lua')
types = set()
if not options.get('no_car_spawn', False):
Expand Down Expand Up @@ -120,7 +126,7 @@ def square(self, im_getter, ox, oy, sx, sy, layer):
if (sx, sy) in label[layer]:
for t, name in label[layer][sx, sy]:
color = COLOR_MAP.get(t, DEFAULT_COLOR)
drawing.append((render_long_text, (name, color, OBJ_FONT)))
drawing.append((render_long_text, (name, color, self.font)))
if drawing:
im = im_getter.get()
draw = ImageDraw.Draw(im)
Expand Down
10 changes: 8 additions & 2 deletions pzmap2dzi/render_impl/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,18 @@ def load_cell_room(path, cx, cy):
'emptyoutside': 'silver',
}
DEFAULT_COLOR = 'cyan'
ROOM_FONT = ImageFont.truetype("arial.ttf", 20)

class RoomRender(object):
def __init__(self, **options):
self.input = options.get('input')
self.encoding = options.get('encoding')
font_name = options.get('room_font')
if not font_name:
font_name = options.get('default_font', 'arial.tff')
font_size = options.get('room_font_size')
if not font_size:
font_size = options.get('default_font_size', 20)
self.font = ImageFont.truetype(font_name, int(font_size))

def square(self, im_getter, ox, oy, sx, sy, layer):
cx, subx = divmod(sx, pzdzi.CELL_SIZE)
Expand All @@ -81,7 +87,7 @@ def square(self, im_getter, ox, oy, sx, sy, layer):
raw_name = room.label[layer, subx, suby]
name = raw_name.decode(self.encoding, errors='ignore')
color = COLOR_MAP.get(name, DEFAULT_COLOR)
drawing.append((render_long_text, (name, color, ROOM_FONT)))
drawing.append((render_long_text, (name, color, self.font)))
if (layer, subx, suby) in room.edge:
idx, flag = room.edge[layer, subx, suby]
raw_name = room.name[idx]
Expand Down
13 changes: 9 additions & 4 deletions pzmap2dzi/render_impl/zombie.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,17 @@ def get_color(zombie, alpha):
b = 255 - g
return (r, g, b, alpha)

ZOMBIE_FONT = ImageFont.truetype("arial.ttf", 40)

class ZombieRender(object):
def __init__(self, **options):
self.input = options.get('input')
self.zombie_count = options.get('zombie_count', False)
font_name = options.get('zombie_count_font')
if not font_name:
font_name = options.get('default_font', 'arial.tff')
font_size = options.get('zombie_count_font_size')
if not font_size:
font_size = options.get('default_font_size', 40)
self.font = ImageFont.truetype(font_name, int(font_size))

def update_options(self, options):
options['layers'] = 1
Expand Down Expand Up @@ -70,7 +75,7 @@ def tile(self, im_getter, gx0, gy0, gl, gr, gt, gb, layer):
if self.zombie_count and x == 9 and y == 0:
color = get_color(zombie, 255)
t = 'z:{}'.format(zombie)
text.append((render_text, (ox, oy, t, color, ZOMBIE_FONT)))
text.append((render_text, (ox, oy, t, color, self.font)))

if drawing or text:
im = im_getter.get()
Expand All @@ -97,7 +102,7 @@ def square(self, im_getter, ox, oy, sx, sy, layer):
draw_square(draw, ox, oy, color)
if self.zombie_count and x == 9 and y == 0:
color = get_color(zombie, 255)
render_text(draw, ox, oy, str(zombie), color, ZOMBIE_FONT)
render_text(draw, ox, oy, str(zombie), color, self.font)

class ZombieTopRender(object):
def __init__(self, **options):
Expand Down
14 changes: 13 additions & 1 deletion test/conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,23 @@ render_conf:
# carto-zed: Carto-Zed like color theme
top_view_color_mode: carto-zed

# font settings
default_font: arial.ttf
default_font_size: 20
# room font settings, using default font if omitted
# room_font: arial.ttf
# room_font_size: 20

# zombie heatmap
zombie_count: true
# zombie count font settings, using default font if omitted
# zombie_count_font: arial.ttf
zombie_count_font_size: 40

# objects areas
vehicle: true
special_zombie: true
stroy: true

# objects font settings, using default font if omitted
# objects_font: arial.ttf
# objects_font_size: 20
5 changes: 4 additions & 1 deletion test/setup_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ def copy(dst, src, name):
shutil.copy(source, target)

def copy_map(dst, src, cells):
os.makedirs(dst, exist_ok=True)
try:
os.makedirs(dst)
except:
pass
copy(dst, src, 'objects.lua')
for x, y in cells:
copy(dst, src, 'world_{}_{}.lotpack'.format(x, y))
Expand Down

0 comments on commit f806ccf

Please sign in to comment.