This repository has been archived by the owner on Jun 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlevelCodeConverter.py
75 lines (59 loc) · 1.92 KB
/
levelCodeConverter.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import numpy as np
from loadCode import loadFromInput
from encoder import encode_number
from compressV3 import compressV3
main = True
def convertV1toV3(V1):
global main
if __name__ != "__main__": main = False
if main:
V1 = loadFromInput(V1)
V1[3] = V1[3].split(",")
for i in range(len(V1[3])):
V1[3][i] = V1[3][i].split(".")
V1[4] = V1[4].split(",")
for i in range(len(V1[4])):
V1[4][i] = V1[4][i].split(".")
grid_array = np.array([72] * (int(V1[1]) * int(V1[2])), dtype=int)
grid_string = ""
try:
if len(V1[3][0][0]) != 0 :
for i in V1[3]:
grid_array[int(i[0]) + int(i[1]) * int(V1[1])] += 1
except IndexError:
print(colored("Somehow, some placeable background is outside your grid", "red"))
try:
if len(V1[4][0][0]) != 0 :
for i in V1[4]:
grid_array[int(i[2]) + int(i[3]) * int(V1[1])] += 2 * int(i[0]) + 18 * int(i[1]) - 72
except IndexError:
print(colored("Somehow, a block is outside your grid", "red"))
for i in grid_array:
grid_string += encode_number(i)
V3 = []
V3.append("V3")
V3.append(encode_number(int(V1[1])))
V3.append(encode_number(int(V1[2])))
if main:
V3.append(compressV3(grid_string, int(V1[1]), int(V1[2])))
else:
V3.append(grid_string)
V3.append(V1[5])
V3.append(V1[6])
if main:
return ";".join(V3) + ";"
else:
return V3
if __name__ == '__main__':
try:
from termcolor import colored
import colorama
colorama.init()
except ModuleNotFoundError:
def colored(text, _): return text
print(colored("Paste level code here: ", "green"), end="")
convert = convertV1toV3(input())
print()
print(colored("Your level code is converted:", "blue"))
print("\t" + convert)
print()