forked from Orpheon/Navmesh-Pathfinder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wallmask.py
65 lines (53 loc) · 2.21 KB
/
wallmask.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
from __future__ import division, print_function
import Image
class Wallmask(object):
def __init__(self):
self.load_wallmask("Maps/ctf_paramental.png")
self.name = "ctf_paramental"
def load_wallmask(self, name):
print("---LOADING WALLMASK---")
image = Image.open(name)
for key, value in image.text.items():
if key == "Gang Garrison 2 Level Data":
text = value
break
text = text[text.find("{WALKMASK}\n")+len("{WALKMASK}\n"):text.find("\n{END WALKMASK}")]
index = text.find("\n")
self.width = int(text[:index])
text = text[index+1:]
index = text.find("\n")
self.height = int(text[:index])
text = text[index+1:]
self.mask = [[False for j in range(self.height)] for i in range(self.width)]
self.uncompress_wallmask_data(text)
large_mask = [[False for j in range(len(self.mask[0])*6)] for i in range(len(self.mask)*6)]
for i in range(len(self.mask)*6):
for j in range(len(self.mask[0])*6 - 7):
large_mask[i][j] = self.mask[int(i/6)][int(j/6)]
self.mask = large_mask
self.width = len(self.mask)
self.height = len(self.mask[0])
def uncompress_wallmask_data(self, data):
bitmask = 0x1
index = len(data)-1
value = ord(data[index]) - 32
for i in range(len(data)*6 - self.width*self.height):
bitmask *= 2
for y in range(self.height-1, -1, -1):
for x in range(self.width-1, -1, -1):
if bitmask == 64:
index -= 1
bitmask = 0x1
value = ord(data[index]) - 32
if value & bitmask:
self.mask[x][y] = True
bitmask *= 2
def print_wallmask(self):
n_image = Image.new("L", (self.width, self.height))
for x in range(self.width):
for y in range(self.height):
if self.mask[x][y]:
n_image.putpixel((x, y), 0)
else:
n_image.putpixel((x, y), 255)
n_image.save("output.png")