49 lines
2.5 KiB
Python
49 lines
2.5 KiB
Python
"""t72: rescue messages and keyboard escape in the pixel game."""
|
|
import pathlib
|
|
import sys
|
|
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1] / 'tools'))
|
|
from use_venv import ensure_playwright; ensure_playwright()
|
|
from browser import launch, consume_gpu_option
|
|
consume_gpu_option()
|
|
ROOT = pathlib.Path(__file__).resolve().parents[1]
|
|
with launch(viewport={'width': 1280, 'height': 760}) as (_, page, url):
|
|
errors = []
|
|
page.on('pageerror', lambda e: errors.append(str(e)))
|
|
page.goto(url)
|
|
page.evaluate("""() => {
|
|
const enter=enterGame;enterGame=()=>{enter();GAME.paused=true;};
|
|
SET.look='pixel';SET.workerCap=0;SET.cameraLead=false;SET.autosave=0;
|
|
startNewWorld(7,768,600);
|
|
}""")
|
|
page.wait_for_function('GAME.running', timeout=60000)
|
|
page.evaluate("""() => {
|
|
mat.fill(EMPTY);flags.fill(0);temp.fill(20);bgm.fill(0);fog.fill(255);
|
|
machines=[null];molds=[];ents=[];flyers=[];treeBases=[];saplings=[];
|
|
weather.next=1e15;weather.shower=null;surfY.fill(300);updateRoof();
|
|
botTrailCount=botTrailHead=0;botEscape=false;bot.vx=bot.vy=0;bot.y=200;
|
|
for(let x=200;x<=360;x+=4){bot.x=x;botStep(0,0,false);}
|
|
for(let y=140;y<280;y++)for(let x=240;x<450;x++)setCell(y*W+x,BASALT,20,F_NAT);
|
|
document.querySelectorAll('.card,.toast').forEach(e=>e.remove());
|
|
botStep(0,0,false);drainEvents();
|
|
SET.zoom=6;resizeRender();snapCamera();renderDirty.fill(1);GPU.world=null;SM.surf=-1;
|
|
}""")
|
|
assert page.evaluate('bot.x===232 && !botOverlapSolid(bot.x,bot.y)')
|
|
assert page.get_by_text('Dug out: back where you came from', exact=True).is_visible()
|
|
page.screenshot(path=str(ROOT / 'shots/t72-retrace.png'))
|
|
page.evaluate("""() => {
|
|
document.querySelectorAll('.toast').forEach(e=>e.remove());
|
|
botTrailCount=botTrailHead=0;bot.x=360;bot.y=200;bot.vx=bot.vy=0;
|
|
botStep(0,0,false);drainEvents();snapCamera();
|
|
}""")
|
|
assert page.get_by_text('Dug out: Fly through the rock to open space', exact=True).is_visible()
|
|
page.screenshot(path=str(ROOT / 'shots/t72-escape.png'))
|
|
page.keyboard.down('d')
|
|
page.evaluate('GAME.paused=false')
|
|
page.wait_for_function('bot.x>=450 && !botEscape', timeout=15000)
|
|
page.keyboard.up('d')
|
|
page.evaluate('GAME.paused=true')
|
|
assert page.evaluate('!botOverlapSolid(bot.x,bot.y)')
|
|
page.screenshot(path=str(ROOT / 'shots/t72-open.png'))
|
|
assert not errors, errors
|
|
print('PASS pixel retrace toast, fallback toast, real keyboard flight through basalt and exit; no page errors')
|