-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbib-shelf-randomizer.py
executable file
·45 lines (40 loc) · 1.4 KB
/
bib-shelf-randomizer.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
#!/usr/bin/env python3
import sys
import json
import random
def main():
filename = sys.argv[1]
rnd_groups = [
[48,49,50,51,52,53,54],
[64,65,66,67,68,69,70],
[80,96,112,128,144,160,176],
[81,97,113,129,145,161,177],
[82,98,114,130,146,162,178],
[83,99,115,131,147,163,179]
]
# Read data
with open(filename) as json_file:
map = json.load(json_file)
# Get offset from tileset and add to rnd_group elements
for tileset in map['tilesets']:
if tileset['name'] == 'bib-structures':
for i in range(0, len(rnd_groups)):
for j in range(0, len(rnd_groups[i])):
rnd_groups[i][j] = rnd_groups[i][j] + tileset['firstgid']
# Find Floor layer
for layer in map['layers']:
if layer['name'] == 'Floor':
# Parse data
for n in range(0, len(layer['data'])):
for g in rnd_groups:
# If tile is rnd_group...
if layer['data'][n] in g:
# Replace with random selection
new_value = g[random.randrange(len(g))]
print('Replacing %d with %d' % ( layer['data'][n], new_value))
layer['data'][n] = new_value
# Write JSON
with open(filename, 'w') as outfile:
json.dump(map, outfile)
if __name__ == "__main__":
main()