-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsprite_from_folder.py
53 lines (44 loc) · 1.46 KB
/
sprite_from_folder.py
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
import urllib.request, time, sprite_creator, io, os
SUFFIX = ''
SPRITE_NAME = 'SmiteRole'
IMAGE_DIR = 'Sprites/' + SPRITE_NAME + ' Images'
DATA_FILE_LOCATION = 'Sprites/' + SPRITE_NAME + 'Sprite' + SUFFIX + '.txt'
IMAGE_WIDTH = 25
IMAGE_HEIGHT = 25
IMAGE_GAP = 2
IMAGES_ACROSS = 4
SPRITE_FILE_NAME = 'Sprites/' + SPRITE_NAME + 'Sprite' + SUFFIX
sprite = sprite_creator.Sprite(IMAGE_WIDTH, IMAGE_HEIGHT, IMAGES_ACROSS, IMAGE_GAP, SPRITE_FILE_NAME)
sprite.create_new()
lines = [
"""return {{
settings = {{
align = 'middle',
autolinksuffix = '',
defaultlengthkey = 'link',
defaultlinkkey = 'link',
height = {},
lookup = 'SPRITENAMEnames',
name = 'SPRITENAME',
nourl = 'Yes',
sheetsize = {},
spacing = {},
stylesheet = true,
url = require( [[Module:Sprite]] ).getUrl( 'SPRITENAMESprite.png'),
width = {},
}},
sections = {{
{{ name = 'Uncategorized', id = 1 }},
}},
ids = {{""".format(str(IMAGE_HEIGHT), str(sprite.sheet_width), str(IMAGE_GAP), str(IMAGE_WIDTH)).replace('SPRITENAME', SPRITE_NAME)
]
for pos, fname in enumerate(os.listdir(IMAGE_DIR)):
name = fname.replace('.png','')
sprite.add_next_image_from_file(IMAGE_DIR + '/' + fname)
lines.append('\t\t["{}"] = {{ pos = {}, section = 1 }},'.format(name.replace('_', ' '), pos + 2))
lines.append('\t\t["{}"] = {{ pos = {}, section = 1 }},'.format('unknown', '1'))
lines.append(' },')
lines.append('}')
with open(DATA_FILE_LOCATION, 'w', encoding="utf-8") as f:
f.write('\n'.join(lines))
sprite.save()