def check_col(rootdim, colpos, colcon, expcon, expdim): root = dummy_root(rootdim) col = root.panel('pan1', Orient.VERT, colpos, colcon) root.do_layout() ccon = col.con assert ccon == expcon cdim = col.dim assert cdim == expdim
def assert_game(model, keys, paint=False): root_layout = dummy_root(dim=Dim(110, 14), logger=Logger('dbg.py')) control = PrpgControl(root_layout, model) def get_key(): if paint: control.root_layout.window.paint() ret = keys.pop(0) return ret main(root_layout, model, get_key=get_key)
def check_flow_layout(orient, dim, pos, con, children_con, exp_pdim, exp_cdims): root = dummy_root(dim) # root.log(f'check_flow_layout({orient} dim:[{dim}] pos:[{pos}] con:[{con}] child_con:{children_con})') panel = root.panel('root-pan', orient, pos, con) for cc in children_con: panel.window(None, cc) for c in panel.children: c.initwin(TextWindow, model=TextModel(['hi'])) root.do_layout() # root.window.paint() pdim = panel.dim assert pdim == exp_pdim dims = list(c.dim for c in panel.children) assert dims == exp_cdims
def test_text_win(): root = dummy_root(Dim(30,10)) pan = root.panel('pan1', Orient.VERT, None, None) pan.window('win1', Con(6,4,10,8)).initwin(TextWindow, model=TextModel('foo')) textwin = pan.window('win2', Con(8,4,11,9)) textwin.initwin(TextWindow, model=TextModel('test-model')) root.do_layout() call_info = [] textwin.window.model.subscribe(lambda model, msg, **params: call_info.append((model.model_name, msg, params['new']))) textwin.window.model.print('hi there', 'you') assert call_info == [('test-model', 'update', ['hi there you'])] assert textwin.window.model.text == ['hi there you'] root.window.paint() textwin.window.model.print('hi 1234567890') textwin.window.model.print('hi 1234567890') textwin.window.model.print('hi 1234567890') textwin.window.model.print('hi 1234567890') textwin.window.model.print('hi 1234567890') textwin.window.model.print('hi 1234567890') root.window.paint()
def test_paint(): printe('') root = dummy_root(Dim(100,15)) hpan = root.panel('root-panel', Orient.HORI, None, None) w1 = hpan.window('w1', Con(10,4,20,5)) w2 = hpan.window('w2', Con(5,3,10,8)) w1.initwin(TextWindow, model=TextModel('model 1', 'window 1')) w2.initwin(TextWindow, model=TextModel('model 2', 'window 2')) root.do_layout() # root.window.paint() assert root.info.comp_by_name['w1'].name == 'w1' assert root.info.comp_by_name['w2'].name == 'w2' assert root.info.comp_by_name['root'].name == 'root' assert hpan.con == Con(15,4,30,8) root.clear_layout() assert hpan.con is None root.do_layout() assert hpan.con == Con(15,4,30,8)
def test_draw_target(): data = ( (0, -4), (1, -4), (2, -4), (3, -4), (4, -4), (4, -3), (4, -2), (4, -1), (4, 0), (4, 1), (4, 2), (4, 3), (4, 4), (3, 4), (2, 4), (1, 4), (0, 4), (-1, 4), (-2, 4), (-3, 4), (-4, 4), (-4, 3), (-4, 2), (-4, 1), (-4, 0), (-4, -1), (-4, -2), (-4, -3), (-4, -4), (-3, -4), (-2, -4), (-1, -4), (0, -4), ) random.seed = 1 game = dungeons.create_game({ 'walls': [ '%%%%%%%%%', '%.......%', '%.......%', '%.......%', '%.......%', '%.......%', '%.......%', '%.......%', '%%%%%%%%%', ], 'peeps': [ create_peep('human', name='Super Dad', pos=(4, 4)), ] }) root_layout = dummy_root(dim=Dim(11, 11), logger=Logger('dbg.py')) control = PrpgControl(root_layout, game) for comp in root_layout.info.comp_by_name.values(): if not comp.children and comp.name != 'maze': comp.con = Con(0, 0, 1, 1) root_layout.do_layout() player = game.maze_model.peeps[0] for target in data: tp = (player.pos[0] + target[0], player.pos[1] + target[1]) game.maze_model.target_path = tuple(line_points(player.pos, tp)) control.root_layout.window.paint()
from lib.logger import Logger from lib.prpg_main import main from lib.startup import dummy_root import lib.dungeons as dungeons root_layout = dummy_root(logger=Logger('dbg.py')) game = dungeons.create_game('level_2') main(root_layout, game)