Add ability to write on map
Todo: - make ChunkDiffs contain deletions - inserting a " " counts as deletion on chunk level - allow for more unicode characters! ^^ (only harmless ones though - no newline or control characters etc.)
This commit is contained in:
parent
7b5458e1d5
commit
38ab48d6f8
3 changed files with 107 additions and 10 deletions
16
maps.py
16
maps.py
|
|
@ -43,7 +43,7 @@ class Map():
|
|||
with self.chunkpool as pool:
|
||||
for x in range(chunkx(self.width) + 2): # +2, not +1, or there will be empty gaps
|
||||
for y in range(chunky(self.height) + 2): # in the bottom and right borders
|
||||
chunk = pool.get(x+chunkx(self.worldx), y+chunky(self.worldy))
|
||||
chunk = pool.get(Position(x+chunkx(self.worldx), y+chunky(self.worldy)))
|
||||
if chunk:
|
||||
chunk.draw_to(x*CHUNK_WIDTH, y*CHUNK_HEIGHT, self._pad)
|
||||
else:
|
||||
|
|
@ -97,14 +97,22 @@ class Map():
|
|||
|
||||
def write(self, char):
|
||||
with self.chunkpool as pool:
|
||||
chunk = pool.get(chunkx(self.cursorx), chunky(self.cursory))
|
||||
chunk = pool.get(Position(chunkx(self.cursorx), chunky(self.cursory)))
|
||||
if not chunk:
|
||||
chunk = pool.create(chunkx(self.cursorx), chunky(self.cursory))
|
||||
chunk = pool.create(Position(chunkx(self.cursorx), chunky(self.cursory)))
|
||||
|
||||
chunk.setch(inchunkx(self.cursorx), inchunky(self.cursory), char)
|
||||
chunk.set(inchunkx(self.cursorx), inchunky(self.cursory), char)
|
||||
|
||||
self.move_cursor(1, 0)
|
||||
|
||||
def delete(self):
|
||||
with self.chunkpool as pool:
|
||||
chunk = pool.get(Position(chunkx(self.cursorx-1), chunky(self.cursory)))
|
||||
if chunk:
|
||||
chunk.delete(inchunkx(self.cursorx-1), inchunky(self.cursory), char)
|
||||
|
||||
self.move_cursor(-1, 0)
|
||||
|
||||
def move_cursor(self, dx, dy):
|
||||
self.cursorx += dx
|
||||
self.cursory += dy
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue