-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContainers.py
214 lines (164 loc) · 5.13 KB
/
Containers.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
from typing import Union
import GameIDs
class Array:
def __init__(self):
self.size = 0
self.data = []
def add(self, other):
self.data.append(other)
self.size += 1
def __eq__(self, other):
return self.data == other.data
class Chunk:
def __init__(self):
self.id = None
self.data = {}
self.depth = 0
def __getitem__(self, key):
return self.data[key]
def __setitem__(self, key, value):
self.data[key] = value
def __eq__(self, other):
return self.data == other.data and self.id == other.id
def keys(self):
return self.data.keys()
def __repr__(self):
seen = set()
def dd(depth: int) -> str:
s = ""
for i in range(depth):
if i & 1:
s += " "
else:
s += "| "
return s
def rprint(cont: Union[Node, Chunk], depth: int, name: str = None) -> str:
s = ""
if isinstance(cont, Chunk):
s += dd(depth) + f"{cont.id}: \n"
for v in cont.data.keys():
s += rprint(cont.data[v], depth + 1, name=v)
elif isinstance(cont, Node):
s += dd(depth) + f"{cont.id} : {name}"
if cont not in seen:
seen.add(cont)
s += "\n"
for c in cont.chunk_list:
s += rprint(c, depth + 1)
else:
s += "(already printed)\n"
s += dd(depth) + "\n"
else:
s += dd(depth) + f"{name} : {cont} \n"
return s
return rprint(self, 0)
def __sub__(self, other):
c = Chunk()
c.id = self.id if (self.id == other.id) else (self.id, other.id)
for el in self.data:
if el not in other.data or self.data[el] != other.data[el]:
c.data[el] = self.data[el]
return c
class List:
def __init__(self):
self.size = 0
self.data = []
def add(self, other):
self.data.append(other)
self.size += 1
def __eq__(self, other):
return self.data == other.data
def __iter__(self):
for v in self.data:
yield v
class Vector3:
def __init__(self, x=0, y=0, z=0):
self.x = x
self.y = y
self.z = z
def __getitem__(self, key):
if key == 0:
return self.x
elif key == 1:
return self.y
elif key == 2:
return self.z
return None
def __eq__(self, other):
return self.x == other.x and self.y == other.y and self.z == other.z
def __repr__(self):
return f'({self.x}, {self.y}, {self.z})'
class Vector2:
def __init__(self, x, y):
self.x = x
self.y = y
def __repr__(self):
return f'({self.x}, {self.y})'
def __getitem__(self, key):
if key == 0:
return self.x
elif key == 1:
return self.y
return None
def __eq__(self, other):
return self.x == other.x and self.y == other.y
class File:
def __init__(self):
self.version = -1
self.checksum = -1
self.path = ''
self.locator_url = ''
def __repr__(self):
return f"{self.path} {self.locator_url}"
class Color:
def __init__(self):
self.r = 0
self.g = 0
self.b = 0
def __repr__(self):
return f"Color ({self.r}, {self.g}, {self.b})"
class Node:
def __init__(self):
self.id = None
self.chunk_list = []
self.depth = 0
# TODO: This was implemented to use noderef, not super happy with it
def __eq__(self, other):
return self is other
def __hash__(self):
return id(self)
def __repr__(self):
seen = set()
def dd(depth: int) -> str:
s = ""
for i in range(depth):
if i & 1:
s += " "
else:
s += "| "
return s
def rprint(cont: Union[Node, Chunk], depth: int, name: str = None) -> str:
s = ""
if isinstance(cont, Chunk):
s += dd(depth) + f"{cont.id}: \n"
for v in cont.data.keys():
s += rprint(cont.data[v], depth + 1, name=v)
elif isinstance(cont, Node):
s += dd(depth) + "\n" + dd(depth) + f"{cont.id} : {name}"
if cont not in seen:
seen.add(cont)
s += "\n"
for c in cont.chunk_list:
s += rprint(c, depth + 1)
else:
s += "(already printed)\n"
else:
s += dd(depth) + f"{name} : {cont} \n"
return s
return rprint(self, 0)
def __sub__(self, other):
n = Node()
n.id = self.id if (self.id == other.id) else (self.id, other.id)
for i in range(len(self.chunk_list)):
n.chunk_list.append(self.chunk_list[i] - other.chunk_list[i])
return n