Skip to content

Commit

Permalink
kengi.console more flexibility, +bugfix iso viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
wkta committed May 23, 2022
1 parent fea2a92 commit b5903d7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
36 changes: 28 additions & 8 deletions src/katagames_engine/_sm_shelf/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def __init__(self, screen, rect, functions=None, key_calls=None, vari=None, synt
v is a regexp processor
k is a function in the form console_func(console, match) that calls console.output(...)
"""
self.message_of_the_day = ["-Niobe Polis CONSOLE ready-"]
self.message_of_the_day = ["no Motd"]

self.bg_color = '#06170e' # very dark green

Expand All @@ -99,7 +99,7 @@ def __init__(self, screen, rect, functions=None, key_calls=None, vari=None, synt

# --- c_out is the history of all text
# -- c_hist is the history of all commands
self.c_out = self.message_of_the_day
self.c_out = ['',]
self.c_in = ""
self.c_hist = [""]
self.c_hist_pos = 0
Expand All @@ -124,8 +124,7 @@ def __init__(self, screen, rect, functions=None, key_calls=None, vari=None, synt
self.max_lines = int((self.size[1] / self.font_height) - 1)
ftdim = self.font.size(omega_ascii_letters)
kappa = ftdim[0] / len(omega_ascii_letters)
print('kappa', kappa)
print('ratio', ftdim[0]/ftdim[1])

self.max_chars = int(((self.size[0]) / kappa) - 1)
self.txt_wrapper = textwrap.TextWrapper()
self.bg_layer = pygame.Surface(self.size)
Expand All @@ -150,6 +149,12 @@ def __init__(self, screen, rect, functions=None, key_calls=None, vari=None, synt
self.add_functions_calls({"help": self.help, "echo": self.output, "clear": self.clear})
self.add_functions_calls(functions)

self.cb_func = None

def set_motd(self, msg):
self.message_of_the_day = msg.splitlines()
self.c_out.extend(self.message_of_the_day)

def screen(self):
return self.parent_screen

Expand All @@ -175,15 +180,27 @@ def output(self, text):

def submit_input(self, text):
self.clear_input()
self.output(self.c_ps + text)
if self.cb_func:
self.output(text)
else:
self.output(self.c_ps + text)

self.c_scroll = 0
self.send_pyconsole(text)
if self.cb_func:
self.cb_func(text)
self.cb_func = None
else:
self.send_pyconsole(text)

def format_input_line(self):
text = self.c_in[:self.c_pos] + self.pos_sym_char + self.c_in[self.c_pos + 1:]
n_max = int(self.max_chars - len(self.c_ps))
vis_range = self.c_draw_pos, self.c_draw_pos + n_max
return self.c_ps + text[vis_range[0]:vis_range[1]]
if self.cb_func:
prefix = ''
else:
prefix = self.c_ps
return prefix + text[vis_range[0]:vis_range[1]]

def str_insert(self, text, strn):
string = text[:self.c_pos] + strn + text[self.c_pos:]
Expand Down Expand Up @@ -455,6 +472,9 @@ def help(self, *args):
self.output(out)
self.txt_wrapper.subsequent_indent = tmp_indent
else:
out = "Available commands: " + str(self.func_calls.keys()).strip("[]")
out = "Available commands are\n"
lc = list(self.func_calls.keys())
lc.sort()
out += '; '.join(lc)
self.output(out)
self.output(r'Type "help command-name" for more information on that command')
17 changes: 10 additions & 7 deletions src/katagames_engine/_sm_shelf/isometric/IsometricMapViewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def __init__(self, isometric_map, screen, postfx=None, cursor=None,
self.lastmousepos = None

self.visible_area = None
self.tfrskip = 2

# util for the drawing of tiles
self.line_cache = list()
Expand Down Expand Up @@ -274,13 +275,15 @@ def proc_event(self, ev, source=None):
# # }}

if ev.type == EngineEvTypes.PAINT:
if self.phase < 240: # dirty frameskip, its TEMPORARY
if self.visible_area is None:
self._init_visible_area_init(ev.screen)
# frameskip (temporary)
self.tfrskip = (self.tfrskip+1) % 3
if not self.tfrskip:
ev.screen.fill('black')
self._paint_all(ev.screen)
self._paint_all()

def _paint_all(self, rscreen):
if self.visible_area is None:
self._init_visible_area_init(rscreen)
def _paint_all(self):

self.camera_updated_this_frame = False
if self._focused_object and (self._focused_object_x0 != self._focused_object.x or
Expand Down Expand Up @@ -326,7 +329,7 @@ def _paint_all(self, rscreen):
my_tile = self.isometric_map.tilesets[tile_id]

sx, sy = self.screen_coords(x, y)
my_tile(rscreen, sx, sy + layer.offsety, gid & FLIPPED_HORIZONTALLY_FLAG,
my_tile(self.screen, sx, sy + layer.offsety, gid & FLIPPED_HORIZONTALLY_FLAG,
gid & FLIPPED_VERTICALLY_FLAG)

if self.cursor and self.cursor.layer_name == layer.name and x == self.cursor.x and y == self.cursor.y:
Expand All @@ -344,7 +347,7 @@ def _paint_all(self, rscreen):
layer.offsetx + self.isometric_map.objectgroups[layer].offsetx,
layer.offsety + self.isometric_map.objectgroups[layer].offsety
)
ob(rscreen, sx, sy, self.isometric_map)
ob(self.screen, sx, sy, self.isometric_map)

elif self.line_cache[current_line] is None and layer == self.isometric_map.layers[-1]:
painting_tiles = False
Expand Down

0 comments on commit b5903d7

Please sign in to comment.