-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsizetools.py
296 lines (269 loc) · 6.87 KB
/
sizetools.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
import sys, inspect
CELL_W = 64
CELL_H = 64
MAP_POS_X1 = 0
MAP_POS_Y1 = 0
DEFAULT_MAP_SIZE = (13, 13)
MAP_SIZE = None
MAP_SIZE_X = None
MAP_SIZE_Y = None
PLAY_SIZE_X = None
PLAY_SIZE_Y = None
MAP_W = None
MAP_H = None
WIDTH = None
HEIGHT = None
POS_CENTER_X = None
POS_CENTER_Y = None
POS_STATUS_Y = None
PLAY_X1 = None
PLAY_X2 = None
PLAY_Y1 = None
PLAY_Y2 = None
PLAY_X_RANGE = None
PLAY_Y_RANGE = None
MAP_X_RANGE = None
MAP_Y_RANGE = None
PLAY_4_SIZE_X = None
PLAY_4_SIZE_Y = None
ROOM_4_SIZE_X = None
ROOM_4_SIZE_Y = None
ROOM_4_X1 = None
ROOM_4_X2 = None
ROOM_4_Y1 = None
ROOM_4_Y2 = None
ROOM_4_X_RANGE = None
ROOM_4_Y_RANGE = None
ROOM_4_BORDERS_X = None
ROOM_4_BORDERS_Y = None
PLAY_9_SIZE_X = None
PLAY_9_SIZE_Y = None
ROOM_9_SIZE_X = None
ROOM_9_SIZE_Y = None
ROOM_9_X1 = None
ROOM_9_X2 = None
ROOM_9_Y1 = None
ROOM_9_Y2 = None
ROOM_9_X_RANGE = None
ROOM_9_Y_RANGE = None
ROOM_9_BORDERS_X = None
ROOM_9_BORDERS_Y = None
def set_map_size(size, has_border=True):
global MAP_SIZE
global MAP_SIZE_X
global MAP_SIZE_Y
global PLAY_SIZE_X
global PLAY_SIZE_Y
global MAP_W
global MAP_H
global WIDTH
global HEIGHT
global POS_CENTER_X
global POS_CENTER_Y
global POS_STATUS_Y
global PLAY_X1
global PLAY_X2
global PLAY_Y1
global PLAY_Y2
global PLAY_X_RANGE
global PLAY_Y_RANGE
global MAP_X_RANGE
global MAP_Y_RANGE
global PLAY_4_SIZE_X
global PLAY_4_SIZE_Y
global ROOM_4_SIZE_X
global ROOM_4_SIZE_Y
global ROOM_4_X1
global ROOM_4_X2
global ROOM_4_Y1
global ROOM_4_Y2
global ROOM_4_X_RANGE
global ROOM_4_Y_RANGE
global ROOM_4_BORDERS_X
global ROOM_4_BORDERS_Y
global PLAY_9_SIZE_X
global PLAY_9_SIZE_Y
global ROOM_9_SIZE_X
global ROOM_9_SIZE_Y
global ROOM_9_X1
global ROOM_9_X2
global ROOM_9_Y1
global ROOM_9_Y2
global ROOM_9_X_RANGE
global ROOM_9_Y_RANGE
global ROOM_9_BORDERS_X
global ROOM_9_BORDERS_Y
border_width = 1 if has_border else 0
if size == MAP_SIZE and PLAY_X1 == border_width:
return
MAP_SIZE = size
MAP_SIZE_X = size[0]
MAP_SIZE_Y = size[1]
PLAY_SIZE_X = MAP_SIZE_X - 2 * border_width
PLAY_SIZE_Y = MAP_SIZE_Y - 2 * border_width
MAP_W = CELL_W * MAP_SIZE_X
MAP_H = CELL_H * MAP_SIZE_Y
WIDTH = CELL_W * MAP_SIZE_X
HEIGHT = CELL_H * (MAP_SIZE_Y + 1)
POS_CENTER_X = MAP_W / 2
POS_CENTER_Y = MAP_H / 2
POS_STATUS_Y = HEIGHT - CELL_H / 2
PLAY_X1 = border_width
PLAY_X2 = PLAY_X1 + PLAY_SIZE_X - 1
PLAY_Y1 = border_width
PLAY_Y2 = PLAY_Y1 + PLAY_SIZE_Y - 1
PLAY_X_RANGE = range(PLAY_X1, PLAY_X2 + 1)
PLAY_Y_RANGE = range(PLAY_Y1, PLAY_Y2 + 1)
MAP_X_RANGE = range(0, MAP_SIZE_X)
MAP_Y_RANGE = range(0, MAP_SIZE_Y)
PLAY_4_SIZE_X = PLAY_SIZE_X - 1
PLAY_4_SIZE_Y = PLAY_SIZE_Y - 1
ROOM_4_SIZE_X = [
PLAY_4_SIZE_X // 2,
PLAY_4_SIZE_X - PLAY_4_SIZE_X // 2,
PLAY_4_SIZE_X // 2,
PLAY_4_SIZE_X - PLAY_4_SIZE_X // 2,
]
ROOM_4_SIZE_Y = [
PLAY_4_SIZE_Y // 2,
PLAY_4_SIZE_Y // 2,
PLAY_4_SIZE_Y - PLAY_4_SIZE_Y // 2,
PLAY_4_SIZE_Y - PLAY_4_SIZE_Y // 2,
]
ROOM_4_X1 = [
PLAY_X1,
PLAY_X1 + ROOM_4_SIZE_X[0] + 1,
PLAY_X1,
PLAY_X1 + ROOM_4_SIZE_X[0] + 1,
]
ROOM_4_X2 = [
PLAY_X1 + ROOM_4_SIZE_X[0] - 1,
PLAY_X2,
PLAY_X1 + ROOM_4_SIZE_X[0] - 1,
PLAY_X2,
]
ROOM_4_Y1 = [
PLAY_Y1,
PLAY_Y1,
PLAY_Y1 + ROOM_4_SIZE_Y[0] + 1,
PLAY_Y1 + ROOM_4_SIZE_Y[0] + 1,
]
ROOM_4_Y2 = [
PLAY_Y1 + ROOM_4_SIZE_Y[0] - 1,
PLAY_Y1 + ROOM_4_SIZE_Y[0] - 1,
PLAY_Y2,
PLAY_Y2,
]
ROOM_4_X_RANGE = [
range(ROOM_4_X1[0], ROOM_4_X2[0] + 1),
range(ROOM_4_X1[1], ROOM_4_X2[1] + 1),
range(ROOM_4_X1[2], ROOM_4_X2[2] + 1),
range(ROOM_4_X1[3], ROOM_4_X2[3] + 1),
]
ROOM_4_Y_RANGE = [
range(ROOM_4_Y1[0], ROOM_4_Y2[0] + 1),
range(ROOM_4_Y1[1], ROOM_4_Y2[1] + 1),
range(ROOM_4_Y1[2], ROOM_4_Y2[2] + 1),
range(ROOM_4_Y1[3], ROOM_4_Y2[3] + 1),
]
ROOM_4_BORDERS_X = [ROOM_4_X2[0] + 1]
ROOM_4_BORDERS_Y = [ROOM_4_Y2[0] + 1]
PLAY_9_SIZE_X = PLAY_SIZE_X - 2
PLAY_9_SIZE_Y = PLAY_SIZE_Y - 2
ROOM_9_SIZE_X = [
(PLAY_9_SIZE_X + 1) // 3,
PLAY_9_SIZE_X - (PLAY_9_SIZE_X + 1) // 3 * 2,
(PLAY_9_SIZE_X + 1) // 3,
(PLAY_9_SIZE_X + 1) // 3,
PLAY_9_SIZE_X - (PLAY_9_SIZE_X + 1) // 3 * 2,
(PLAY_9_SIZE_X + 1) // 3,
(PLAY_9_SIZE_X + 1) // 3,
PLAY_9_SIZE_X - (PLAY_9_SIZE_X + 1) // 3 * 2,
(PLAY_9_SIZE_X + 1) // 3,
]
ROOM_9_SIZE_Y = [
(PLAY_9_SIZE_Y + 1) // 3,
(PLAY_9_SIZE_Y + 1) // 3,
(PLAY_9_SIZE_Y + 1) // 3,
PLAY_9_SIZE_Y - (PLAY_9_SIZE_Y + 1) // 3 * 2,
PLAY_9_SIZE_Y - (PLAY_9_SIZE_Y + 1) // 3 * 2,
PLAY_9_SIZE_Y - (PLAY_9_SIZE_Y + 1) // 3 * 2,
(PLAY_9_SIZE_Y + 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[3] + ROOM_9_SIZE_Y[3] - 1,
ROOM_9_Y1[3] + ROOM_9_SIZE_Y[3] - 1,
ROOM_9_Y1[3] + ROOM_9_SIZE_Y[3] - 1,
PLAY_Y2,
PLAY_Y2,
PLAY_Y2,
]
ROOM_9_X_RANGE = [
range(ROOM_9_X1[0], ROOM_9_X2[0] + 1),
range(ROOM_9_X1[1], ROOM_9_X2[1] + 1),
range(ROOM_9_X1[2], ROOM_9_X2[2] + 1),
range(ROOM_9_X1[3], ROOM_9_X2[3] + 1),
range(ROOM_9_X1[4], ROOM_9_X2[4] + 1),
range(ROOM_9_X1[5], ROOM_9_X2[5] + 1),
range(ROOM_9_X1[6], ROOM_9_X2[6] + 1),
range(ROOM_9_X1[7], ROOM_9_X2[7] + 1),
range(ROOM_9_X1[8], ROOM_9_X2[8] + 1),
]
ROOM_9_Y_RANGE = [
range(ROOM_9_Y1[0], ROOM_9_Y2[0] + 1),
range(ROOM_9_Y1[1], ROOM_9_Y2[1] + 1),
range(ROOM_9_Y1[2], ROOM_9_Y2[2] + 1),
range(ROOM_9_Y1[3], ROOM_9_Y2[3] + 1),
range(ROOM_9_Y1[4], ROOM_9_Y2[4] + 1),
range(ROOM_9_Y1[5], ROOM_9_Y2[5] + 1),
range(ROOM_9_Y1[6], ROOM_9_Y2[6] + 1),
range(ROOM_9_Y1[7], ROOM_9_Y2[7] + 1),
range(ROOM_9_Y1[8], ROOM_9_Y2[8] + 1),
]
ROOM_9_BORDERS_X = [ROOM_9_X2[0] + 1, ROOM_9_X2[1] + 1]
ROOM_9_BORDERS_Y = [ROOM_9_Y2[0] + 1, ROOM_9_Y2[3] + 1]
def import_size_constants(dest_module=None):
if hasattr(dest_module, "__module__"):
dest_module = sys.modules[dest_module.__module__]
dest_globals = inspect.stack()[1][0].f_globals if dest_module is None else vars(dest_module)
for name in dir(sys.modules[__name__]):
if name.isupper():
dest_globals[name] = globals()[name]