|
|
@ -29,28 +29,49 @@ def read_mapfile(fn):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MapFile:
|
|
|
|
class MapFile:
|
|
|
|
def __init__(self, filename):
|
|
|
|
def __init__(self, filename, start=None, end=None):
|
|
|
|
self.mapfilename = filename
|
|
|
|
self.mapfilename = filename
|
|
|
|
|
|
|
|
self.start = start
|
|
|
|
|
|
|
|
self.end = end
|
|
|
|
|
|
|
|
|
|
|
|
def load(self):
|
|
|
|
def load(self):
|
|
|
|
self.status, self.blocks, self.comments = read_mapfile(self.mapfilename)
|
|
|
|
self.status, self.blocks, self.comments = read_mapfile(self.mapfilename)
|
|
|
|
|
|
|
|
if self.start is not None or self.end is not None:
|
|
|
|
|
|
|
|
self.filter_data()
|
|
|
|
self.size = max(map(lambda blk: blk[0]+blk[1], self.blocks))
|
|
|
|
self.size = max(map(lambda blk: blk[0]+blk[1], self.blocks))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def filter_data(self):
|
|
|
|
|
|
|
|
assert self.start is not None and self.end is not None
|
|
|
|
|
|
|
|
self.blocks = self.filter_blocks(self.blocks, self.start, self.end)
|
|
|
|
|
|
|
|
self.blocks = self.trim_blocks(self.blocks, self.start, self.end)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Move blocks:
|
|
|
|
|
|
|
|
self.status = tuple([self.status[0] - self.start, *self.status[1:]])
|
|
|
|
|
|
|
|
nblocks = []
|
|
|
|
|
|
|
|
for blk in self.blocks:
|
|
|
|
|
|
|
|
nblk = tuple([blk[0] - self.start, *blk[1:]])
|
|
|
|
|
|
|
|
nblocks.append(nblk)
|
|
|
|
|
|
|
|
self.blocks = nblocks
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_state(self, pos):
|
|
|
|
def get_state(self, pos):
|
|
|
|
# TODO: this is lame
|
|
|
|
# TODO: this is lame
|
|
|
|
for blk in self.blocks:
|
|
|
|
for blk in self.blocks:
|
|
|
|
if pos >= blk[0] and pos < blk[0] + blk[1]:
|
|
|
|
if pos >= blk[0] and pos < blk[0] + blk[1]:
|
|
|
|
return blk[2]
|
|
|
|
return blk[2]
|
|
|
|
|
|
|
|
|
|
|
|
def get_hist(self, start, end):
|
|
|
|
@staticmethod
|
|
|
|
|
|
|
|
def filter_blocks(blocks, start, end):
|
|
|
|
relevant_blocks = []
|
|
|
|
relevant_blocks = []
|
|
|
|
for blk in self.blocks:
|
|
|
|
for blk in blocks:
|
|
|
|
if start < blk[0] + blk[1] and end >= blk[0]:
|
|
|
|
if start < blk[0] + blk[1] and end >= blk[0]:
|
|
|
|
relevant_blocks.append(blk)
|
|
|
|
relevant_blocks.append(blk)
|
|
|
|
|
|
|
|
return relevant_blocks
|
|
|
|
|
|
|
|
|
|
|
|
# Trimming:
|
|
|
|
@staticmethod
|
|
|
|
|
|
|
|
def trim_blocks(blocks, start, end):
|
|
|
|
trmblks = []
|
|
|
|
trmblks = []
|
|
|
|
for blk in relevant_blocks:
|
|
|
|
for blk in blocks:
|
|
|
|
bg, lt, symb = blk
|
|
|
|
bg, lt, symb = blk
|
|
|
|
if bg < start:
|
|
|
|
if bg < start:
|
|
|
|
lt -= start - bg
|
|
|
|
lt -= start - bg
|
|
|
@ -58,6 +79,12 @@ class MapFile:
|
|
|
|
if bg + lt > end:
|
|
|
|
if bg + lt > end:
|
|
|
|
lt -= bg+lt - end
|
|
|
|
lt -= bg+lt - end
|
|
|
|
trmblks.append((bg, lt, symb))
|
|
|
|
trmblks.append((bg, lt, symb))
|
|
|
|
|
|
|
|
return trmblks
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_hist(self, start, end):
|
|
|
|
|
|
|
|
relevant_blocks = self.filter_blocks(self.blocks, start, end)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
trmblks = self.trim_blocks(relevant_blocks, start, end)
|
|
|
|
|
|
|
|
|
|
|
|
# Grouping by symbols:
|
|
|
|
# Grouping by symbols:
|
|
|
|
grp = {}
|
|
|
|
grp = {}
|
|
|
|