mirror of
https://github.com/enzet/map-machine.git
synced 2025-05-22 21:46:24 +02:00
Remove grid generation from test.
This commit is contained in:
parent
2cd9199891
commit
95822e5cd5
1 changed files with 38 additions and 93 deletions
73
test.py
73
test.py
|
@ -7,45 +7,21 @@ import random
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
from roentgen import extract_icon
|
from roentgen import extract_icon
|
||||||
from roentgen import svg
|
from roentgen.flinger import map_
|
||||||
|
|
||||||
|
|
||||||
|
def test_flinger_map():
|
||||||
|
assert map_(5, 0, 10, 0, 20) == 10
|
||||||
|
|
||||||
|
|
||||||
|
def test_icons():
|
||||||
tags_file_name = 'data/tags.yml'
|
tags_file_name = 'data/tags.yml'
|
||||||
|
icons_file_name = 'icons/icons.svg'
|
||||||
|
|
||||||
scheme = yaml.load(open(tags_file_name))
|
scheme = yaml.load(open(tags_file_name))
|
||||||
|
|
||||||
icons_file_name = 'icons/icons.svg'
|
|
||||||
icon_grid_file_name = 'icon_grid.svg'
|
|
||||||
icon_colors_file_name = 'data/icon_colors'
|
|
||||||
|
|
||||||
|
|
||||||
def draw_icon(icon, x, y, color='444444'):
|
|
||||||
output_file.write('<path d="' + icon['path'] + '" ' + \
|
|
||||||
'style="fill:#' + color + ';stroke:none;' + \
|
|
||||||
'stroke-width:3;stroke-linejoin:round;" ' + \
|
|
||||||
'transform="translate(' + str(icon['x'] + x) + ',' + str(icon['y'] + y) + ')" />\n')
|
|
||||||
|
|
||||||
|
|
||||||
# Actions
|
|
||||||
|
|
||||||
icon_colors = [('FFFFFF', '444444')]
|
|
||||||
if os.path.isfile(icon_colors_file_name):
|
|
||||||
icon_colors_file = open(icon_colors_file_name)
|
|
||||||
for line in icon_colors_file.read().split('\n'):
|
|
||||||
background_color = hex(int(line[0:3]))[2:] + hex(int(line[3:6]))[2:] + \
|
|
||||||
hex(int(line[6:9]))[2:]
|
|
||||||
foreground_color = hex(int(line[10:13]))[2:] + hex(int(line[13:16]))[2:] + \
|
|
||||||
hex(int(line[16:19]))[2:]
|
|
||||||
icon_colors.append((background_color, foreground_color))
|
|
||||||
|
|
||||||
step = 24
|
|
||||||
|
|
||||||
width = 24 * 16
|
|
||||||
|
|
||||||
extracter = extract_icon.IconExtractor(icons_file_name)
|
extracter = extract_icon.IconExtractor(icons_file_name)
|
||||||
|
|
||||||
x = step / 2
|
|
||||||
y = step / 2
|
|
||||||
|
|
||||||
to_draw = []
|
to_draw = []
|
||||||
|
|
||||||
for element in scheme['tags']:
|
for element in scheme['tags']:
|
||||||
|
@ -72,44 +48,13 @@ for element in scheme['tags']:
|
||||||
if not (set([icon] + [icon2] + [icon3] + element['over_icon']) in to_draw):
|
if not (set([icon] + [icon2] + [icon3] + element['over_icon']) in to_draw):
|
||||||
to_draw.append(set([icon] + [icon2] + [icon3] + element['over_icon']))
|
to_draw.append(set([icon] + [icon2] + [icon3] + element['over_icon']))
|
||||||
|
|
||||||
number = 0
|
|
||||||
|
|
||||||
icons = []
|
|
||||||
|
|
||||||
for icons_to_draw in to_draw:
|
for icons_to_draw in to_draw:
|
||||||
drawed = False
|
drawed = False
|
||||||
icon_set = {'icons': []}
|
icon_set = {'icons': []}
|
||||||
for icon in icons_to_draw:
|
for icon in icons_to_draw:
|
||||||
path, xx, yy = extracter.get_path(icon)
|
path, xx, yy = extracter.get_path(icon)
|
||||||
if xx:
|
assert xx
|
||||||
icon_set['icons'].append({'path': path,
|
icon_set['icons'].append({'path': path,
|
||||||
'x': (- 8.0 - xx * 16),
|
'x': (- 8.0 - xx * 16),
|
||||||
'y': (- 8.0 - yy * 16)})
|
'y': (- 8.0 - yy * 16)})
|
||||||
drawed = True
|
drawed = True
|
||||||
else:
|
|
||||||
print('\033[31m' + icon + '\033[0m')
|
|
||||||
if drawed:
|
|
||||||
icons.append(icon_set)
|
|
||||||
number += 1
|
|
||||||
|
|
||||||
height = int(number / (width / step) + 1) * step
|
|
||||||
|
|
||||||
output_file = svg.SVG(open(icon_grid_file_name, 'w+'))
|
|
||||||
output_file.begin(width, height)
|
|
||||||
|
|
||||||
output_file.rect(0, 0, width, height, color='FFFFFF')
|
|
||||||
|
|
||||||
for icon in icons:
|
|
||||||
background_color, foreground_color = random.choice(icon_colors)
|
|
||||||
output_file.rect(x - 2 - 8, y - 2 - 8, 20, 20, color=background_color)
|
|
||||||
for i in icon['icons']:
|
|
||||||
draw_icon(i, x, y, foreground_color)
|
|
||||||
x += step
|
|
||||||
if x > width - 8:
|
|
||||||
x = step / 2
|
|
||||||
y += step
|
|
||||||
height += step
|
|
||||||
|
|
||||||
print(f"Icons: {number}.")
|
|
||||||
|
|
||||||
output_file.end()
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue