| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- """Temporary-map gesture regression checks."""
- import json
- import tempfile
- from pathlib import Path
- from verify_recovery import editor, pygame
- from game.frame import obstacle
- from game.frame.frame import Frame
- from game.frame.obstacle_instance import ObstacleInstance
- with tempfile.TemporaryDirectory() as tmp:
- target = Path(tmp) / 'map.json'
- target.write_text(json.dumps(dict(basic=dict(name='test', width=40, height=40,
- scroll=[0, 0], begin=[0, 0], finish=[39, 39]), floor=[], obstacle=[], districts=[])))
- editor.MAP_JSON_FILE_NAME = str(target)
- editor.MapBuilder.update = lambda self: None
- app = editor.MapBuilder()
- import time
- from asset_library import scan, decode
- lib = app.library
- def wait_until(predicate):
- deadline = time.monotonic()+30
- while not predicate():
- lib.update()
- if time.monotonic() > deadline:
- raise AssertionError('background load timeout')
- time.sleep(0.005)
- try:
- lib.toggle()
- lib.choose_library('common')
- lib.choose_library('crimson_manor')
- wait_until(lambda: lib.scan_job is None and not lib.pending and not lib.jobs and bool(lib.entries))
- assert all(e['type'] == 'crimson_manor' for e in lib.entries)
- assert any(e['elem_type'] == 'floor' for e in lib.entries)
- assert any(e['elem_type'] == 'obstacle' for e in lib.entries)
- assert all(e['thumbnail'].get_size() == (112, 88) for e in lib.entries)
- for kind in ('floor', 'obstacle'):
- entry = next(e for e in lib.entries if e['elem_type'] == kind)
- lib.selected_job = lib.pool.submit(decode, lib.root, entry, True)
- wait_until(lambda: lib.selected_job is None)
- assert app.current_elem['name'] == entry['name'] and len(app.selection.group) == 1
- app.menu.block_pointer = False
- pos = (editor.MAP_AT[0]+405, editor.MAP_AT[1]+405)
- assert app.placement.handle_event(pygame.event.Event(pygame.MOUSEBUTTONDOWN, button=1, pos=pos))
- app.placement.handle_event(pygame.event.Event(pygame.MOUSEBUTTONUP, button=1, pos=pos))
- assert (10, 10) in app.map_obstacles_dict
- app.menu.undo()
- assert (10, 10) not in app.map_obstacles_dict
- lib.draw()
- app.menu.draw()
- app.settings.draw_speaker()
- lib.draw_button()
- pygame.image.save(app.screen, 'recovered_map_editor/library_preview.png')
- lib.dropdown = True
- lib.scroll(10000)
- lib.draw()
- lib.choose_library('missing_test_directory')
- wait_until(lambda: lib.scan_job is None)
- assert not lib.entries
- print('PASS: concurrent loading, stale job isolation, thumbnails, floor/obstacle selection and placement, undo, dropdown scrolling, invalid directory')
- finally:
- lib.close()
- pygame.quit()
|