-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbfill
executable file
·68 lines (49 loc) · 1.89 KB
/
dbfill
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/python
from os import getcwd, listdir, mkdir
from os.path import isfile, join, splitext, exists
from shutil import copyfile, rmtree
WORKING_DIR = getcwd()
CONCRETE_DIR = join(WORKING_DIR, 'concrete')
ABSTRACT_DIR = join(WORKING_DIR, 'abstract')
DRAWABLE_DIR = join(WORKING_DIR, 'drawable')
if exists(DRAWABLE_DIR): rmtree(DRAWABLE_DIR)
mkdir(DRAWABLE_DIR)
JTRUE = 'true'
JFALSE = 'false'
JDBFILL = ''
LINE_FMT = 'tiles.add(new Tile("{}", TileColor.{}, {}, TileShape.{}, TileType.{}));\n'
concrete = [f for f in listdir(CONCRETE_DIR) if isfile(join(CONCRETE_DIR, f))]
abstract = [f for f in listdir(ABSTRACT_DIR) if isfile(join(ABSTRACT_DIR, f))]
colors = set()
shapes = set()
for c in concrete:
# remove extension
tokens = splitext(c)[0].split('_')
img_name = tokens[0].lower()
img_color = tokens[1].upper()
img_directable = JTRUE if tokens[2] == 'y' else JFALSE
img_shape = tokens[3].upper()
img_type = tokens[4].upper()
colors.add(img_color)
shapes.add(img_shape)
# check if the file already exists in drawable dir
if isfile(join(DRAWABLE_DIR, img_name + '.png')):
img_name += '_' + img_color.lower()
JDBFILL += LINE_FMT.format(img_name, img_color, img_directable, img_shape, img_type)
copyfile(join(CONCRETE_DIR, c), join(DRAWABLE_DIR, img_name + '.png'))
JDBFILL += '\n'
# avoid to use NONE, WHITE and BLACK for abstract shapes
colors.remove('NONE')
colors.remove('BLACK')
colors.remove('WHITE')
for a in abstract:
# remove extension
tokens = splitext(a)[0].split('_')
img_name = tokens[0].lower()
img_directable = JTRUE if tokens[2] == 'y' else JFALSE
img_shape = tokens[3].upper()
img_type = tokens[4].upper()
for color in colors:
JDBFILL += LINE_FMT.format(img_name, color, img_directable, img_shape, img_type)
copyfile(join(ABSTRACT_DIR, a), join(DRAWABLE_DIR, img_name + '.png'))
print JDBFILL