Delete characters with backspace
This commit is contained in:
parent
38ab48d6f8
commit
704ff9b3d1
3 changed files with 20 additions and 14 deletions
|
|
@ -43,6 +43,8 @@ class ChunkDiff():
|
||||||
self._chars[x+y*CHUNK_WIDTH] = character
|
self._chars[x+y*CHUNK_WIDTH] = character
|
||||||
|
|
||||||
def delete(self, x, y):
|
def delete(self, x, y):
|
||||||
|
pos = x + y*CHUNK_WIDTH
|
||||||
|
if pos in self._chars:
|
||||||
del self._chars[x+y*CHUNK_WIDTH]
|
del self._chars[x+y*CHUNK_WIDTH]
|
||||||
|
|
||||||
def apply(self, diff):
|
def apply(self, diff):
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,7 @@ class Client():
|
||||||
# edit world
|
# edit world
|
||||||
elif i in string.digits + string.ascii_letters + string.punctuation + " ":
|
elif i in string.digits + string.ascii_letters + string.punctuation + " ":
|
||||||
self.map_.write(i)
|
self.map_.write(i)
|
||||||
|
elif i == "\x7f": self.map_.delete()
|
||||||
|
|
||||||
else: sys.stdout.write(repr(i) + "\n")
|
else: sys.stdout.write(repr(i) + "\n")
|
||||||
|
|
||||||
|
|
|
||||||
29
maps.py
29
maps.py
|
|
@ -14,12 +14,12 @@ class Map():
|
||||||
def __init__(self, width, height, chunkpool, drawevent):
|
def __init__(self, width, height, chunkpool, drawevent):
|
||||||
self._lock = threading.RLock()
|
self._lock = threading.RLock()
|
||||||
|
|
||||||
self.worldx = 0
|
|
||||||
self.worldy = 0
|
|
||||||
self.cursorx = 0
|
|
||||||
self.cursory = 0
|
|
||||||
self.chunkpreload = 0
|
self.chunkpreload = 0
|
||||||
self.cursorpadding = 2
|
self.cursorpadding = 2
|
||||||
|
self.worldx = 0
|
||||||
|
self.worldy = 0
|
||||||
|
self.cursorx = self.cursorpadding
|
||||||
|
self.cursory = self.cursorpadding
|
||||||
|
|
||||||
self.chunkpool = chunkpool
|
self.chunkpool = chunkpool
|
||||||
self.drawevent = drawevent
|
self.drawevent = drawevent
|
||||||
|
|
@ -67,6 +67,12 @@ class Map():
|
||||||
s = "."*CHUNK_WIDTH
|
s = "."*CHUNK_WIDTH
|
||||||
self._pad.addstr(y+dy, x, s)
|
self._pad.addstr(y+dy, x, s)
|
||||||
|
|
||||||
|
def load_visible(self):
|
||||||
|
with self.chunkpool as pool:
|
||||||
|
pool.load_list(self.visible_chunk_coords())
|
||||||
|
|
||||||
|
self.drawevent.set()
|
||||||
|
|
||||||
def resize(self, width, height):
|
def resize(self, width, height):
|
||||||
self.width = width
|
self.width = width
|
||||||
self.height = height
|
self.height = height
|
||||||
|
|
@ -76,18 +82,15 @@ class Map():
|
||||||
(chunkx(width) + 2)*CHUNK_WIDTH + 1 # workaround for addwstr issue when drawing
|
(chunkx(width) + 2)*CHUNK_WIDTH + 1 # workaround for addwstr issue when drawing
|
||||||
)
|
)
|
||||||
|
|
||||||
with self.chunkpool as pool:
|
self.load_visible()
|
||||||
pool.load_list(self.visible_chunk_coords())
|
|
||||||
|
|
||||||
self.drawevent.set()
|
|
||||||
|
|
||||||
def visible_chunk_coords(self):
|
def visible_chunk_coords(self):
|
||||||
coords = []
|
coords = []
|
||||||
|
|
||||||
xstart = chunkx(self.worldx) - self.chunkpreload
|
xstart = chunkx(self.worldx) - self.chunkpreload
|
||||||
ystart = chunky(self.worldy) - self.chunkpreload
|
ystart = chunky(self.worldy) - self.chunkpreload
|
||||||
xend = xstart + chunkx(self.width) + 1 + 2*self.chunkpreload
|
xend = xstart + chunkx(self.width)+2 + 2*self.chunkpreload
|
||||||
yend = ystart + chunky(self.height) + 1 + 2*self.chunkpreload
|
yend = ystart + chunky(self.height)+2 + 2*self.chunkpreload
|
||||||
|
|
||||||
for x in range(xstart, xend):
|
for x in range(xstart, xend):
|
||||||
for y in range(ystart, yend):
|
for y in range(ystart, yend):
|
||||||
|
|
@ -109,7 +112,7 @@ class Map():
|
||||||
with self.chunkpool as pool:
|
with self.chunkpool as pool:
|
||||||
chunk = pool.get(Position(chunkx(self.cursorx-1), chunky(self.cursory)))
|
chunk = pool.get(Position(chunkx(self.cursorx-1), chunky(self.cursory)))
|
||||||
if chunk:
|
if chunk:
|
||||||
chunk.delete(inchunkx(self.cursorx-1), inchunky(self.cursory), char)
|
chunk.delete(inchunkx(self.cursorx-1), inchunky(self.cursory))
|
||||||
|
|
||||||
self.move_cursor(-1, 0)
|
self.move_cursor(-1, 0)
|
||||||
|
|
||||||
|
|
@ -133,7 +136,7 @@ class Map():
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
self.drawevent.set()
|
self.load_visible()
|
||||||
|
|
||||||
def scroll(self, dx, dy):
|
def scroll(self, dx, dy):
|
||||||
self.worldx += dx
|
self.worldx += dx
|
||||||
|
|
@ -161,7 +164,7 @@ class Map():
|
||||||
#)
|
#)
|
||||||
#)
|
#)
|
||||||
|
|
||||||
self.drawevent.set()
|
self.load_visible()
|
||||||
|
|
||||||
|
|
||||||
class ChunkMap():
|
class ChunkMap():
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue