Add alternating color mode (F3)
This commit is contained in:
parent
e3b599eee1
commit
8c5d5bc2cb
3 changed files with 36 additions and 17 deletions
11
chunks.py
11
chunks.py
|
|
@ -105,10 +105,13 @@ class Chunk():
|
||||||
def age(self, now=None):
|
def age(self, now=None):
|
||||||
return self.last_modified - (now or time.time())
|
return self.last_modified - (now or time.time())
|
||||||
|
|
||||||
def draw_to(self, x, y, window):
|
#def draw_to(self, x, y, window):
|
||||||
for line in self._content.combine(self._modifications).lines():
|
#for line in self._content.combine(self._modifications).lines():
|
||||||
window.addstr(y, x, line)
|
#window.addstr(y, x, line)
|
||||||
y += 1
|
#y += 1
|
||||||
|
|
||||||
|
def lines(self):
|
||||||
|
return self._content.combine(self._modifications).lines()
|
||||||
|
|
||||||
def modified(self):
|
def modified(self):
|
||||||
return not self._modifications.empty()
|
return not self._modifications.empty()
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,9 @@ class Client():
|
||||||
elif i == "KEY_F(2)":
|
elif i == "KEY_F(2)":
|
||||||
self.chunkmap_active = not self.chunkmap_active
|
self.chunkmap_active = not self.chunkmap_active
|
||||||
self.redraw()
|
self.redraw()
|
||||||
|
elif i == "KEY_F(3)":
|
||||||
|
self.map_.alternating_colors = not self.map_.alternating_colors
|
||||||
|
self.redraw()
|
||||||
elif i == "KEY_F(5)": self.map_.redraw()
|
elif i == "KEY_F(5)": self.map_.redraw()
|
||||||
# scrolling the map (10 vertical, 20 horizontal)
|
# scrolling the map (10 vertical, 20 horizontal)
|
||||||
elif i == "kUP5": self.map_.scroll(0, -10)
|
elif i == "kUP5": self.map_.scroll(0, -10)
|
||||||
|
|
|
||||||
39
maps.py
39
maps.py
|
|
@ -26,11 +26,14 @@ class Map():
|
||||||
self.chunkpool = chunkpool
|
self.chunkpool = chunkpool
|
||||||
self.client = client
|
self.client = client
|
||||||
|
|
||||||
|
self.alternating_colors = False
|
||||||
|
|
||||||
self._pad = curses.newpad(5, 5)
|
self._pad = curses.newpad(5, 5)
|
||||||
self.resize(width, height)
|
self.resize(width, height)
|
||||||
|
|
||||||
if curses.has_colors():
|
if curses.has_colors():
|
||||||
curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_WHITE) # chunk not loaded
|
curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_WHITE) # chunk not loaded
|
||||||
|
curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_BLUE) # alternate color for chunks
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
self._lock.acquire()
|
self._lock.acquire()
|
||||||
|
|
@ -48,9 +51,10 @@ class Map():
|
||||||
with self.chunkpool as pool:
|
with self.chunkpool as pool:
|
||||||
for x in range(chunkx(self.width) + 2): # +2, not +1, or there will be empty gaps
|
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
|
for y in range(chunky(self.height) + 2): # in the bottom and right borders
|
||||||
chunk = pool.get(Position(x+chunkx(self.worldx), y+chunky(self.worldy)))
|
pos = Position(x+chunkx(self.worldx), y+chunky(self.worldy))
|
||||||
|
chunk = pool.get(pos)
|
||||||
if chunk:
|
if chunk:
|
||||||
chunk.draw_to(x*CHUNK_WIDTH, y*CHUNK_HEIGHT, self._pad)
|
self.draw_chunk_to(x*CHUNK_WIDTH, y*CHUNK_HEIGHT, chunk, (pos.x+pos.y)%2)
|
||||||
else:
|
else:
|
||||||
self.draw_empty_to(x*CHUNK_WIDTH, y*CHUNK_HEIGHT)
|
self.draw_empty_to(x*CHUNK_WIDTH, y*CHUNK_HEIGHT)
|
||||||
|
|
||||||
|
|
@ -68,7 +72,6 @@ class Map():
|
||||||
|
|
||||||
def draw_empty_to(self, x, y):
|
def draw_empty_to(self, x, y):
|
||||||
if curses.has_colors():
|
if curses.has_colors():
|
||||||
curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_WHITE)
|
|
||||||
for dy in range(CHUNK_HEIGHT):
|
for dy in range(CHUNK_HEIGHT):
|
||||||
self._pad.addstr(y+dy, x, " "*CHUNK_WIDTH, curses.color_pair(1))
|
self._pad.addstr(y+dy, x, " "*CHUNK_WIDTH, curses.color_pair(1))
|
||||||
else:
|
else:
|
||||||
|
|
@ -76,6 +79,16 @@ class Map():
|
||||||
s = "."*CHUNK_WIDTH
|
s = "."*CHUNK_WIDTH
|
||||||
self._pad.addstr(y+dy, x, s)
|
self._pad.addstr(y+dy, x, s)
|
||||||
|
|
||||||
|
def draw_chunk_to(self, x, y, chunk, blue=False):
|
||||||
|
if self.alternating_colors and curses.has_colors() and blue:
|
||||||
|
for line in chunk.lines():
|
||||||
|
self._pad.addstr(y, x, line, curses.color_pair(2))
|
||||||
|
y += 1
|
||||||
|
else:
|
||||||
|
for line in chunk.lines():
|
||||||
|
self._pad.addstr(y, x, line)
|
||||||
|
y += 1
|
||||||
|
|
||||||
def _unload_condition(self, pos, chunk):
|
def _unload_condition(self, pos, chunk):
|
||||||
xstart = chunkx(self.worldx) - self.chunkunload
|
xstart = chunkx(self.worldx) - self.chunkunload
|
||||||
ystart = chunky(self.worldy) - self.chunkunload
|
ystart = chunky(self.worldy) - self.chunkunload
|
||||||
|
|
@ -204,11 +217,11 @@ class ChunkMap():
|
||||||
"""
|
"""
|
||||||
|
|
||||||
styles = {
|
styles = {
|
||||||
"empty": ChunkStyle("()", 2),
|
"empty": ChunkStyle("()", 3),
|
||||||
"normal": ChunkStyle("[]", 3),
|
"normal": ChunkStyle("[]", 4),
|
||||||
"unload": ChunkStyle("{}", 4),
|
"unload": ChunkStyle("{}", 5),
|
||||||
"visible": ChunkStyle("##", 5),
|
"visible": ChunkStyle("##", 6),
|
||||||
"modified": ChunkStyle("!!", 6),
|
"modified": ChunkStyle("!!", 7),
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, map_):
|
def __init__(self, map_):
|
||||||
|
|
@ -221,11 +234,11 @@ class ChunkMap():
|
||||||
self.win = curses.newwin(2, 2)
|
self.win = curses.newwin(2, 2)
|
||||||
|
|
||||||
if curses.has_colors():
|
if curses.has_colors():
|
||||||
curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_BLUE) # empty chunk
|
curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_BLUE) # empty chunk
|
||||||
curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE) # chunk
|
curses.init_pair(4, curses.COLOR_BLACK, curses.COLOR_WHITE) # chunk
|
||||||
curses.init_pair(4, curses.COLOR_BLACK, curses.COLOR_YELLOW) # chunk to be unloaded
|
curses.init_pair(5, curses.COLOR_BLACK, curses.COLOR_YELLOW) # chunk to be unloaded
|
||||||
curses.init_pair(5, curses.COLOR_BLACK, curses.COLOR_GREEN) # visible chunk
|
curses.init_pair(6, curses.COLOR_BLACK, curses.COLOR_GREEN) # visible chunk
|
||||||
curses.init_pair(6, curses.COLOR_BLACK, curses.COLOR_RED) # modified chunk
|
curses.init_pair(7, curses.COLOR_BLACK, curses.COLOR_RED) # modified chunk
|
||||||
|
|
||||||
def update_size(self, sizex, sizey):
|
def update_size(self, sizex, sizey):
|
||||||
winy, winx = self.win.getmaxyx()
|
winy, winx = self.win.getmaxyx()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue