-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevel.py
39 lines (32 loc) · 1.04 KB
/
level.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
import ctypes
import itertools
from legacy_level import *
class Level(object):
PATH_TEMPLATE="levels/%02d"
legacyLevel=None
def __init__(self,levelNumber):
self._loadFromPath(self.PATH_TEMPLATE%levelNumber)
self.levelNumber=levelNumber
def _loadFromPath(self,path):
with open(path,'rb') as f:
baseData=f.read()
buffer=ctypes.c_buffer(baseData)
self.legacyLevel=LEGACY_LEVEL.from_address(ctypes.addressof(buffer))
self.legacyLevel._origRaw=baseData
self.legacyLevel._curRaw=buffer
def __getstate__(self):
delta={}
index=0
for old,new in zip(self.legacyLevel._origRaw,self.legacyLevel._curRaw):
if new!=old:
delta[index]=new
index+=1
return (self.levelNumber,delta)
def __setstate__(self, xxx_todo_changeme):
(levelNumber,delta) = xxx_todo_changeme
self._loadFromPath(self.PATH_TEMPLATE%levelNumber)
for index,val in delta.items():
self.legacyLevel._curRaw[index]=val
self.levelNumber=levelNumber
def __getattr__(self,name):
return getattr(self.legacyLevel,name)