7, 'new' => true]): Game { $this->game->start(RevisitedScene::class, $params + ['help' => false]); $this->game->run(4); // the loading card, then the zone self::assertSame('play', $this->game->peek('mode')); return $this->game->peek('game'); } public function testWalkingForwardMovesRob(): void { $g = $this->begin(); $x = $g->x; $z = $g->z; $this->game->hold('up', 90); self::assertGreaterThan(3.0, hypot($g->x - $x, $g->z - $z)); $yaw = $g->yaw; $this->game->hold('right', 30); self::assertNotEqualsWithDelta($yaw, $g->yaw, 0.2); $this->game->shot('revisited-walk'); } public function testDraggingTheMouseOnTheViewLooksAroundWithoutLockingTheCursor(): void { $g = $this->begin(); $mouse = $this->game->engine->input->getMouse(); $yaw = $g->yaw; $pitch = $g->pitch; $mouse->move(160, 100); $mouse->down(1); $this->game->run(1); for ($i = 1; $i <= 10; $i++) { $mouse->move(160 + $i * 4, 100 - $i * 2); $this->game->run(1); } $mouse->up(1); $this->game->run(1); self::assertNotEqualsWithDelta($yaw, $g->yaw, 0.1, 'the drag turned the view'); self::assertGreaterThan($pitch, $g->pitch, 'dragging up looks up'); self::assertFalse($this->game->peek('captured'), 'the cursor is never locked'); $yaw = $g->yaw; $mouse->move(10, 10); $this->game->run(5); self::assertEqualsWithDelta($yaw, $g->yaw, 0.0001, 'moving without a button does not turn'); } public function testTheDashboardShowsTheVitalsTheSlotsAndTheObjective(): void { $this->begin(); $this->game->run(30); /** @var HudData $d */ $d = $this->game->peek('data'); self::assertNotSame('', $d->objective); self::assertStringContainsString('Chapitre 1', $d->quest); self::assertSame('ration', $d->slots[2]); self::assertNotEmpty($d->feed, 'the first lines of the story are in the log'); /** @var Canvas $c */ $c = $this->game->peek('canvas'); self::assertSame('slot:1', $c->hitAt(751, 670), 'the quick slots are drawn in the bar'); $this->game->shot('revisited-hud'); // a wound: the condition badge comes, the screen flashes $g = $this->game->peek('game'); $g->hitPlayer('rleg', 'bite', 0.6, 'Le rôdeur nocturne'); $this->game->run(30); $labels = array_column($this->game->peek('data')->conditions, 'label'); self::assertContains('Hémorragie', $labels); $this->game->shot('revisited-hud-wounded'); } public function testOpeningTheInventoryAndEatingTheRation(): void { $g = $this->begin(); $g->body = Body::fromArray(array_merge($g->body->toArray(), ['hunger' => 40.0])); $this->game->press('rv_inventory', 2); self::assertSame('screen', $this->game->peek('mode')); /** @var Screens $s */ $s = $this->game->peek('screens'); self::assertSame('inventory', $s->tab); $items = $this->game->peek('items', $s); $s->invSel = (int) array_search('ration', $items, true); $this->game->run(1); $this->game->shot('revisited-inventory'); $this->game->press('rv_act', 2); self::assertSame(0, $g->inv->count('ration')); self::assertGreaterThan(60.0, $g->body->vitals()['hunger']); $this->game->press('rv_close', 2); self::assertSame('play', $this->game->peek('mode')); } public function testCraftingAFireDrillFromTheScreen(): void { $g = $this->begin(); $g->inv->add('stick', 2); $g->inv->add('fiber', 1); $this->game->press('rv_craft', 2); /** @var Screens $s */ $s = $this->game->peek('screens'); self::assertSame('craft', $s->tab); foreach ($this->game->peek('recipes', $s) as $i => $r) { if ($r['id'] === 'fire_drill') { $s->craftSel = $i; } } $this->game->run(1); $this->game->shot('revisited-craft'); $this->game->press('rv_act', 2); self::assertTrue($g->inv->has('fire_drill')); self::assertFalse($g->inv->has('stick')); } public function testTreatingABleedingArmFromTheBodyScreen(): void { $g = $this->begin(); $g->body->wound('larm', 'cut', 0.5); $this->game->press('rv_body', 2); /** @var Screens $s */ $s = $this->game->peek('screens'); self::assertSame('body', $s->tab); self::assertSame('dressed', $s->bodyView, 'the body tab opens on the dressed view'); $this->game->press('rv_drop', 2); self::assertSame('medical', $s->bodyView, 'X switches to the medical view'); $s->part = 3; // larm (head torso rarm larm rleg lleg) $this->game->run(1); $this->game->shot('revisited-body'); $this->game->press('rv_act', 2); self::assertFalse($g->inv->has('bandage')); self::assertTrue($g->body->injuries()[0]['treated']); } public function testTheMapAndTheJournalOpen(): void { $this->begin(); $this->game->press('rv_map', 2); self::assertSame('map', $this->game->peek('screens')->tab); $this->game->shot('revisited-map'); $this->game->press('rv_next', 2); self::assertSame('journal', $this->game->peek('screens')->tab); $this->game->shot('revisited-journal'); } public function testTalkingWithTheElderOfTheHaldi(): void { $g = $this->begin(['seed' => 7, 'zone' => 'canyon']); $maeva = null; foreach ($g->npcs as $n) { if ($n->name === 'Maëva') { $maeva = $n; } } self::assertInstanceOf(Npc::class, $maeva); $this->face($g, $maeva, 1.5); $this->game->press('rv_act', 2); $d = $g->dialogue(); self::assertSame('Maëva', $d['npc'] ?? null); $this->game->shot('revisited-dialogue'); $k = 0; foreach ($d['choices'] as $i => $c) { if (str_contains($c, 'quitter cette lune')) { $k = $i + 1; } } self::assertGreaterThan(0, $k, 'the elder can be asked how to leave'); $this->game->press('rv_' . $k, 2); self::assertNotSame($d['text'], $g->dialogue()['text'] ?? ''); $this->game->press('rv_close', 2); self::assertNull($g->dialogue()); } public function testDyingShowsTheDeathScreen(): void { $g = $this->begin(); $g->body = Body::fromArray(array_merge($g->body->toArray(), ['health' => 0.2, 'thirst' => 0.0])); $this->game->run(240); self::assertSame('dead', $this->game->peek('mode')); self::assertNotNull($g->over()); $this->game->shot('revisited-death'); } public function testSavingThenContinuingRestoresThePosition(): void { $g = $this->begin(); $this->game->hold('up', 60); $this->game->press('pause', 2); self::assertSame('pause', $this->game->peek('mode')); $this->game->shot('revisited-pause'); $this->game->press('down', 1); $this->game->press('rv_act', 2); // Sauvegarder… self::assertSame('saves', $this->game->peek('mode')); $this->game->press('rv_act', 2); // Sauvegarder ici (a new slot) $this->game->press('rv_act', 2); // its name as proposed $x = $g->x; $z = $g->z; $h = $this->begin(['continue' => true]); self::assertNotSame($g, $h); self::assertEqualsWithDelta($x, $h->x, 0.01); self::assertEqualsWithDelta($z, $h->z, 0.01); } public function testTheTitleCardOffersANewGame(): void { $this->game->start(RevisitedScene::class, ['seed' => 7, 'help' => false]); $this->game->run(4); self::assertSame('title', $this->game->peek('mode')); $this->game->shot('revisited-title'); $this->game->press('rv_act', 4); self::assertSame('play', $this->game->peek('mode')); } public function testSpaceJumpsAndRobLandsAgain(): void { $g = $this->begin(); $y0 = $g->y; $this->game->press('rv_jump', 1); $this->game->run(8); self::assertGreaterThan($y0 + 0.3, $g->y, 'Rob is in the air'); self::assertTrue($g->airborne()); $this->game->run(60); self::assertTrue($g->onGround, 'he lands'); self::assertSame([], $g->body->injuries(), 'a jump on flat ground does not hurt'); } public function testTheBigHintFadesOnceTheActionIsLearned(): void { $this->begin(); /** @var \App\Revisited\Ui\Hints $h */ $h = $this->game->peek('hints'); self::assertGreaterThan(0.9, $h->update('fiber', 0.0) + 0.0 * $h->update('fiber', 0.1)); $h->done('fiber'); self::assertSame(0.0, $h->update('fiber', 0.1), 'learned: only the small marker'); self::assertSame(1.0, $h->update('talk', 0.1), 'talking is always explained'); $h->update(null, 0.1); $level = 1.0; foreach (range(1, 4) as $k) { $h->update('clay', 0.0); $level = $h->update('clay', 5.0); $h->update(null, 0.1); } self::assertSame(0.0, $level, 'shown a few seconds a few times, then discreet'); } public function testTheControlsPanelComesAtANewGameAndWithH(): void { $this->game->start(RevisitedScene::class, ['seed' => 7, 'new' => true]); $this->game->run(4); self::assertSame('controls', $this->game->peek('mode')); $this->game->shot('revisited-controls'); $this->game->press('rv_close', 2); self::assertSame('play', $this->game->peek('mode')); $this->game->press('rv_help', 2); self::assertSame('controls', $this->game->peek('mode')); $this->game->press('rv_help', 2); self::assertSame('play', $this->game->peek('mode')); } public function testTheScannerShowsTheLandAroundAndDrainsItsBattery(): void { $g = $this->begin(); self::assertTrue($g->inv->has('scanner'), 'the pod\'s scanner is in the bag'); $g->body->wound('lleg', 'cut', 0.5); $this->game->press('rv_scanner', 2); self::assertSame('scanner', $this->game->peek('screens')->tab); $bat = $g->scanBattery(); $this->game->run(60); $this->game->shot('revisited-scanner'); self::assertLessThan($bat, $g->scanBattery()); $echoes = \App\Revisited\Ui\ScannerView::echoes($g, null); self::assertNotEmpty(array_filter($echoes, static fn ($e) => $e[2] === 'loot'), 'the pod wreck is on the radar'); $advice = implode(' ', array_column(\App\Revisited\Ui\ScannerView::advice($g), 1)); self::assertStringContainsString('bandage', $advice); } public function testTheBodyTabShowsTheDressedFigureAndTakesClothesOff(): void { $g = $this->begin(); self::assertSame('flight_suit_torn', $g->inv->worn, 'Rob crashed in his flight suit'); self::assertSame('pilot_boots_worn', $g->inv->feet); self::assertLessThan(70.0, $g->inv->condition('flight_suit_torn')); $g->body->wound('larm', 'cut', 0.5); $g->body->wound('rleg', 'fracture', 0.7); $g->body->wound('head', 'bruise', 0.3); $this->game->press('rv_body', 2); $this->game->run(20); $this->game->shot('revisited-body-figure'); $warm = $g->inv->warmth(); /** @var Canvas $c */ $c = $this->game->peek('canvas'); $this->game->peek('ui')->click = true; $hit = $c->hitAt(350, 250); self::assertSame('cloth:worn', $hit); $s = $this->game->peek('screens'); $in = new \App\Revisited\Ui\UiInput(); $in->click = true; $in->hit = 'cloth:worn'; $s->update($in, $g, $this->game->peek('data'), 0.016); self::assertNull($g->inv->worn, 'the suit is off'); self::assertLessThan($warm, $g->inv->warmth()); $s->update($in, $g, $this->game->peek('data'), 0.016); self::assertSame('flight_suit_torn', $g->inv->worn, 'and on again'); // dressed for the plateau: a hat, gloves, fur leggings, a coat: each drawn with its own shape foreach (['hat_fur', 'mittens_fur', 'leggings_fur', 'coat_fur'] as $id) { $g->inv->add($id); $g->useItem($id); } $g->inv->cond['coat_fur'] = 30.0; $this->game->run(4); $this->game->shot('revisited-body-dressed-plateau'); self::assertSame('coat_fur', $g->inv->worn); self::assertSame('hat_fur', $g->inv->head); // the medical view: wounds, a bandage, a splint, cold hands $g->useItem('bandage', 'larm'); $g->inv->add('splint'); $g->useItem('splint', 'rleg'); $s->bodyView = 'medical'; $this->game->run(4); $this->game->shot('revisited-body-medical'); self::assertTrue($g->body->injuries()[0]['treated']); } public function testTheMapShowsOnlyWhatWasExplored(): void { $g = $this->begin(); self::assertTrue($g->isExplored($g->x, $g->z)); self::assertFalse($g->isExplored($g->x + 200, $g->z + 200)); $share = $g->exploredShare(); $this->game->hold('up', 240); self::assertGreaterThan($share, $g->exploredShare(), 'walking reveals the land'); $this->game->press('rv_map', 2); $this->game->run(2); $this->game->shot('revisited-map-fog'); $h = Game::fromArray(json_decode(json_encode($g->toArray()), true)); self::assertGreaterThanOrEqual($g->exploredShare(), $h->exploredShare(), 'the explored map is saved'); } public function testOnAPhoneADragOnTheViewLooksAround(): void { $g = $this->begin(['seed' => 7, 'new' => true, 'touch' => true, 'uiscale' => 0.54]); $this->game->run(20); $this->game->shot('revisited-phone'); $yaw = $g->yaw; $pitch = $g->pitch; $m = $this->game->peek('engine')->input->getMouse(); $m->move(200, 100); $m->down(1); $this->game->run(1); for ($k = 1; $k <= 10; $k++) { $m->move(200 - $k * 6, 100 + $k * 2); $this->game->run(1); } $m->up(1); $this->game->run(1); self::assertNotEqualsWithDelta($yaw, $g->yaw, 0.05); self::assertNotEqualsWithDelta($pitch, $g->pitch, 0.02); } public function testTheSleepScreenChoosesHowLongFadesToBlackAndWakesUp(): void { $g = $this->begin(['seed' => 7, 'new' => true, 'minutes' => 14 * 60]); $g->creatures = []; $g->fires[] = ['x' => $g->x + 1.0, 'z' => $g->z, 'minutes' => 900.0]; $this->game->press('rv_sleep', 2); self::assertSame('sleep', $this->game->peek('mode')); /** @var \App\Revisited\Ui\SleepView $v */ $v = $this->game->peek('sleepView'); self::assertSame('choose', $v->phase); self::assertSame('fire', $v->info['place']); self::assertSame('dawn', $v->modes[0], 'at night: until dawn first'); $this->game->shot('revisited-sleep-choose'); $this->game->press('rv_act', 2); self::assertSame('sleep', $v->phase); $this->game->run(70); $this->game->shot('revisited-sleep-dark'); self::assertGreaterThan(21 * 60 + 20, $g->minutes + 7 * 60, 'the clock runs fast'); $this->game->run(600); self::assertSame('woke', $v->phase, 'at dawn Rob wakes up'); self::assertGreaterThanOrEqual(6.4, $g->hour(), $v->summary); self::assertLessThan(7.5, $g->hour(), $v->summary); self::assertStringContainsString('Tu dors', $v->summary); $this->game->shot('revisited-sleep-woke'); $this->game->run(30); $this->game->press('rv_act', 2); self::assertSame('play', $this->game->peek('mode')); // R: a short rest $this->game->press('rv_rest', 2); self::assertSame('sleep', $this->game->peek('mode')); $this->game->run(200); self::assertSame('woke', $v->phase); self::assertStringContainsString('reposes', $v->summary); } public function testClickingAGaugeOpensItsActionsAndDrinkingFromItWorks(): void { $g = $this->begin(); $g->creatures = []; $g->body = Body::fromArray(array_merge($g->body->toArray(), ['thirst' => 30.0])); $g->inv->add('gourd_dirty'); $g->inv->add('gourd_boiled'); $this->game->run(2); /** @var Canvas $c */ $c = $this->game->peek('canvas'); self::assertSame('vital:thirst', $c->hitAt(26 + 4 * 80 + 20, 660), 'the Soif gauge is clickable'); $u = $this->game->peek('ui'); $mouse = $this->game->engine->input->getMouse(); $mouse->move((26 + 4 * 80 + 20) * 320 / Canvas::W, 660 * 240 / Canvas::H); $this->game->run(2); self::assertNotNull($this->game->peek('data')->tooltip, 'a tooltip explains it ' . json_encode([$u->mx, $u->my, $u->hover])); $mouse->down(1); $this->game->run(1); $mouse->up(1); $this->game->run(1); self::assertSame('vitals', $this->game->peek('mode')); /** @var \App\Revisited\Ui\VitalMenu $m */ $m = $this->game->peek('vitals'); self::assertStringContainsString('bouillie', $m->rows[0][0], 'the safest water first'); $this->game->shot('revisited-gauge-thirst'); $this->game->press('rv_act', 2); self::assertSame('play', $this->game->peek('mode')); self::assertFalse($g->inv->has('gourd_boiled')); self::assertGreaterThan(60.0, $g->body->vitals()['thirst']); // a bleeding wound: the health gauge offers the bandage first $g->body->wound('rarm', 'cut', 0.6); $this->game->run(30); $s = $this->game->peek('screens'); $m->open($g, 'health', 26, []); self::assertStringContainsString('Bander', $m->rows[0][0]); ($m->rows[0][1])(); self::assertTrue($g->body->injuries()[0]['treated']); // a condition badge has its menu too $g->body = Body::fromArray(array_merge($g->body->toArray(), ['temp' => 34.0])); $m->open($g, 'cond:hypothermia', 26, []); self::assertSame('Hypothermie', $m->title); self::assertNotEmpty($m->rows); } public function testThePodLogGoesIntoTheGpsFromTheJournalAndTheCompassPointsAtTheCaves(): void { $g = $this->begin(); $g->flags['q_pod_log'] = true; $g->inv->add('pod_log'); $this->game->press('rv_journal', 2); $this->game->run(2); /** @var Canvas $c */ $c = $this->game->peek('canvas'); $found = null; for ($y = 140; $y < 640 && $found === null; $y += 4) { if ($c->hitAt(520, $y) === 'gpslog:pod_log') { $found = $y; } } self::assertNotNull($found, 'the journal offers "Insérer dans le GPS"'); $s = $this->game->peek('screens'); $in = new \App\Revisited\Ui\UiInput(); $in->click = true; $in->hit = 'gpslog:pod_log'; $s->update($in, $g, $this->game->peek('data'), 0.016); self::assertSame('halde_base', $g->activeWaypoint); $this->game->shot('revisited-journal-gps'); $s->open('scanner'); $s->scanPage = 'gps'; $this->game->run(2); $this->game->shot('revisited-scanner-gps'); $this->game->press('rv_close', 2); $this->game->run(4); $this->game->shot('revisited-compass-gps'); $t = $g->waypointTarget(); self::assertNotNull($t); self::assertStringContainsString('grotte', $t[2], 'from the valley: through the cave'); } // ------------------------------------------------------------------------------------------ wave 2 (the escape) public function testPOpensThePauseMenuAndTheControlsSaySo(): void { $this->begin(); $this->game->press('pause', 2); self::assertSame('pause', $this->game->peek('mode')); $this->game->press('pause', 2); self::assertSame('play', $this->game->peek('mode')); $keys = array_column(\App\Revisited\Ui\Controls::KEYBOARD, 0); self::assertContains('P', $keys, 'the controls panel shows P for the pause'); } public function testTalkingToTheOuviChiefShowsTheToneOfEachAnswerAndDigitsChoose(): void { $g = $this->begin(['seed' => 7, 'zone' => 'jungle', 'talk' => 'aika']); $d = $g->dialogue(); self::assertSame('Aïka', $d['npc'] ?? null); self::assertContains('gift', $d['tones']); self::assertSame('réservé', $d['attitude']); $this->game->shot('revisited-talk-aika'); $text = $d['text']; $this->game->press('rv_1', 2); self::assertNotSame($text, $g->dialogue()['text'] ?? '', 'the first answer leads on'); $this->game->press('rv_close', 2); self::assertNull($g->dialogue()); } public function testBuyingFromTheOuviMerchantWithCredits(): void { $g = $this->begin(['seed' => 7, 'zone' => 'jungle', 'talk' => 'nadje']); $g->inv->add('credit', 50); $this->choose($g, 'Voir ta marchandise'); $this->choose($g, 'Poisson fumé'); self::assertTrue($g->inv->has('smoked_fish')); self::assertLessThan(50, $g->inv->count('credit')); $this->game->shot('revisited-shop'); } public function testOnAPhoneTheDialogueUsesBigTextAndRows(): void { $g = $this->begin(['seed' => 7, 'zone' => 'marsh', 'talk' => 'kessa', 'touch' => true, 'uiscale' => 0.45]); self::assertNotNull($g->dialogue()); $canvas = $this->game->peek('canvas'); self::assertGreaterThan(1.0, $canvas->boost, 'phones: bigger text'); self::assertGreaterThanOrEqual(13, $canvas->minPx); $this->game->shot('revisited-talk-phone'); } public function testCrossingTheJungleRiverOnARaft(): void { $g = $this->begin(['seed' => 7, 'zone' => 'jungle']); $g->creatures = []; $n = \App\Revisited\Land\ZoneFactory::noiseOf('jungle', 7); $v = 0.36; $rx = \App\Revisited\Land\ZoneFactory::riverX($v, $n) * 512; $half = \App\Revisited\Land\ZoneFactory::riverHalf($v, $n); $g->x = $rx - $half - 1.5; $g->z = $v * 512; $g->y = $g->zone->heightAt($g->x, $g->z); $g->yaw = 1.5708; $g->inv->setCapacity(60.0); $g->inv->add('log', 4); $g->inv->add('rope', 3); $g->inv->add('raft_pole'); $g->act('raft'); foreach ($g->zone->things as $t) { if ($t->kind === 'raft') { $g->x = $t->x - 1.5; $g->z = $t->z; } } $g->act('board'); self::assertNotNull($g->raft); $x0 = $g->x; $g->yaw = 1.5708; $this->game->hold('up', 240); self::assertGreaterThan($x0 + 4, $g->x, 'poled across'); $this->game->shot('revisited-raft'); } public function testLightningFlashesAndItsThunderComesLater(): void { $g = $this->begin(); $g->weather = ['kind' => 'storm', 'amount' => 1.0]; \App\Revisited\Land\Wildfire::strike($g, [$g->x + 343, $g->z]); $this->game->run(2); $queued = $this->game->peek('sounds'); self::assertNotEmpty(array_filter($queued, fn (array $s) => $s[0] === 'thunder'), 'the thunder waits for its second'); $this->game->run(70); self::assertSame([], array_values(array_filter($this->game->peek('sounds'), fn (array $s) => $s[0] === 'thunder')), 'and comes'); self::assertNotNull($g->lightning); } public function testLaunchingTheShuttleAtDawnShowsTheEnding(): void { $g = $this->begin(['seed' => 7, 'zone' => 'coast', 'at' => 'shuttle', 'dist' => 5]); foreach (\App\Revisited\Land\Escape::PARTS as $p) { $g->flags['fit_' . $p] = true; } $g->flags['fuel'] = 3; $g->flags['shuttle_repaired'] = true; $g->flags['jonas_free'] = true; $g->minutes = 22 * 60; // day 2, 05:00 (day 1 starts at 07:00) $g->weather = ['kind' => 'clear', 'amount' => 0.0]; $g->creatures = []; $labels = array_column($g->actions(), 'label'); self::assertContains('Décoller !', $labels); $g->act('launch'); $this->game->run(4); self::assertSame('won', $this->game->peek('mode')); $this->game->run(60 * 14); $this->game->shot('revisited-escape'); } public function testOnAPhoneTheScreensAreOneColumnListThenDetailWithBackAndDrag(): void { $g = $this->begin(['seed' => 7, 'new' => true, 'touch' => true]); /** @var Screens $s */ $s = $this->game->peek('screens'); self::assertTrue($s->touch); $d = $this->game->peek('data'); $s->open('inventory'); $tap = function (string $hit) use ($s, $g, $d): void { $in = new \App\Revisited\Ui\UiInput(); $in->click = true; $in->hit = $hit; $in->held = true; $in->my = 300; $s->update($in, $g, $d, 0.016); $up = new \App\Revisited\Ui\UiInput(); $up->my = 300; $s->update($up, $g, $d, 0.016); // the finger lifts: the tap acts }; $tap('pitem:ration'); self::assertSame('ration', $s->pDetail, 'a row opens its page'); $tap('puse'); self::assertFalse($g->inv->has('ration'), 'eaten from its page'); self::assertNull($s->pDetail, 'nothing left: back to the list'); $tap('pitem:bandage'); $tap('pback'); self::assertNull($s->pDetail); // a drag scrolls instead of tapping $s->open('craft'); $in = new \App\Revisited\Ui\UiInput(); $in->click = true; $in->hit = 'prec:0'; $in->held = true; $in->my = 500; $s->update($in, $g, $d, 0.016); $mv = new \App\Revisited\Ui\UiInput(); $mv->held = true; $mv->my = 300; $s->update($mv, $g, $d, 0.016); $s->update(new \App\Revisited\Ui\UiInput(), $g, $d, 0.016); self::assertNull($s->pDetail, 'a drag does not open the row'); $tap('prec:0'); self::assertSame('0', $s->pDetail); $this->game->press('rv_inventory', 1); self::assertSame('screen', $this->game->peek('mode')); foreach (['inventory', 'craft', 'body', 'scanner', 'map', 'journal'] as $tab) { $s->open($tab); $this->game->run(2); self::assertSame('screen', $this->game->peek('mode'), "$tab stays open"); } $this->game->shot('revisited-phone-journal'); } // ---- graphics quality: levels, Auto, software rendering -------------------------------------------------- /** @return string|null the first level change while $seconds of frames of $dt seconds go by */ private static function feed(AdaptiveQuality $a, float $dt, float $seconds): ?string { for ($t = 0.0; $t < $seconds; $t += $dt) { if (($new = $a->frame($dt)) !== null) { return $new; } } return null; } public function testAutoQualityStepsDownWhenFramesAreSlowAndBackUpWhenFast(): void { $a = new AdaptiveQuality('high', true); self::assertNull(self::feed($a, 1 / 60, 10.0), '60 i/s: high stays'); self::assertSame('medium', self::feed($a, 0.03, 10.0), '33 i/s for a few seconds: one level down'); self::assertEqualsWithDelta(33.3, $a->fps, 1.0); self::assertSame('low', self::feed($a, 0.03, 10.0)); self::assertSame('ultra', self::feed($a, 0.03, 10.0)); self::assertNull(self::feed($a, 0.03, 10.0), 'nothing below ultra'); self::assertFalse($a->hopeless, '33 i/s in ultra is playable'); $b = new AdaptiveQuality('medium', true); self::assertNull(self::feed($b, 1 / 70, 15.0), 'fast, but not for long enough yet'); self::assertSame('high', self::feed($b, 1 / 70, 15.0), '70 i/s for 20 s: one level up'); self::assertSame('medium', self::feed($b, 0.03, 10.0), 'too slow in high: back down'); self::assertNull(self::feed($b, 1 / 70, 60.0), 'never back up to a level that was too slow'); self::assertNull(self::feed($b, 0.9, 10.0), 'hitches (a hidden tab) are not frames'); self::assertSame('medium', $b->level); } public function testAForcedQualityLevelIsNeverChangedButStillMeasured(): void { $a = new AdaptiveQuality('high', false); self::assertNull(self::feed($a, 0.05, 30.0)); self::assertSame('high', $a->level); self::assertEqualsWithDelta(20.0, $a->fps, 0.5); $u = new AdaptiveQuality('ultra', true); self::feed($u, 0.08, 10.0); self::assertTrue($u->hopeless, '12 i/s even in ultra: the computer cannot keep up'); self::assertSame(1, Quality::supersample('high', 1440, 1080), 'a 1080p window: no supersampling (6 million pixels)'); self::assertSame(2, Quality::supersample('high', 960, 720)); self::assertSame(1, Quality::supersample('medium', 960, 720)); self::assertTrue(Quality::isSoftware('Google SwiftShader')); self::assertTrue(Quality::isSoftware('llvmpipe (LLVM 15.0.7, 256 bits)')); self::assertTrue(Quality::isSoftware('ANGLE (Google, Vulkan 1.3.0 (SwiftShader Device (Subzero)), SwiftShader driver)')); self::assertFalse(Quality::isSoftware('ANGLE (NVIDIA, NVIDIA GeForce RTX 3060 Direct3D11 vs_5_0 ps_5_0, D3D11)')); self::assertFalse(Quality::isSoftware('WebKit WebGL')); } public function testOnASlowComputerTheSceneLowersTheQualityAndSaysSo(): void { $this->game->engine->options->set('rv_quality', 'auto'); $this->begin(['seed' => 7, 'new' => true, 'quality' => 'auto', 'start' => 'high', 'adaptive' => true, 'frame_ms' => 30]); self::assertSame('high', $this->game->peek('quality')); $this->game->run(300); self::assertSame('medium', $this->game->peek('quality')); self::assertSame('play', $this->game->peek('mode')); self::assertStringContainsString('abaissée à Moyenne', $this->game->peek('toast')); self::assertStringContainsString('(33 i/s)', $this->game->peek('toast')); self::assertSame('medium', $this->game->engine->options->get('rv_quality_auto'), 'the next session starts there'); $this->game->shot('revisited-quality-toast'); } public function testASoftwareRendererShowsThePanelAndStartsInUltraLow(): void { $opts = $this->game->engine->options; $opts->set('rv_quality', 'auto'); $opts->set('rv_soft_dismissed', false); $this->begin(['seed' => 7, 'new' => true, 'gpu' => 'Google SwiftShader']); self::assertSame('ultra', $this->game->peek('quality')); self::assertTrue($this->game->peek('softPanel')); $this->game->shot('revisited-software'); $g = $this->game->peek('game'); $x = $g->x; $this->game->hold('up', 30); self::assertEqualsWithDelta($x, $g->x, 0.0001, 'the game waits behind the panel'); $this->game->press('confirm', 2); self::assertFalse($this->game->peek('softPanel')); self::assertTrue($opts->get('rv_soft_dismissed')); $this->begin(['seed' => 7, 'new' => true, 'gpu' => 'Google SwiftShader']); self::assertFalse($this->game->peek('softPanel'), 'dismissed once: never again'); $this->begin(['seed' => 7, 'new' => true, 'gpu' => 'ANGLE (NVIDIA GeForce RTX 3060)']); self::assertNotSame('ultra', $this->game->peek('quality')); } public function testTheQualityAndFpsOptionsAreSaved(): void { $opts = $this->game->engine->options; $opts->set('rv_quality', 'auto'); $opts->set('rv_fps', false); $this->begin(); self::assertSame('auto', $this->game->peek('qualityPref')); $this->game->press('pause', 2); $this->game->peek('menu')->sel = (int) array_search('Options', $this->rows(), true); $this->game->press('rv_act', 2); // Options self::assertSame('options', $this->game->peek('mode')); $this->game->press('rv_act', 2); // Qualité: Auto -> Très basse $this->game->run(4); self::assertSame('options', $this->game->peek('mode')); self::assertSame('ultra', $opts->get('rv_quality')); self::assertSame('ultra', $this->game->peek('quality')); self::assertFalse($this->game->peek('adaptive')->auto, 'a forced level: no adapting'); $this->game->press('down', 1); $this->game->press('rv_act', 2); // Afficher les images par seconde self::assertTrue($opts->get('rv_fps')); $this->begin(); self::assertSame('ultra', $this->game->peek('qualityPref')); self::assertSame('ultra', $this->game->peek('quality')); self::assertTrue($this->game->peek('showFps')); $this->game->run(30); $this->game->shot('revisited-ultra-fps'); $opts->set('rv_quality', 'auto'); $opts->set('rv_fps', false); } // ---- comfort: zoom, eye height, crouching ------------------------------------------------------------------ public function testTheWheelZoomsTheViewWithinItsLimitsAndIsSaved(): void { $opts = $this->game->engine->options; $opts->set('rv_fov', RevisitedScene::FOV_DEFAULT); $this->begin(); self::assertSame(80.0, $this->game->peek('fov'), 'a bit wider than before by default'); $mouse = $this->game->engine->input->getMouse(); $mouse->wheel(0, -2); // towards the player: wider $this->game->run(1); self::assertSame(88.0, $this->game->peek('fov')); for ($i = 0; $i < 20; $i++) { $mouse->wheel(0, -1); $this->game->run(1); } self::assertSame(RevisitedScene::FOV_MAX, $this->game->peek('fov')); for ($i = 0; $i < 30; $i++) { $mouse->wheel(0, 1); $this->game->run(1); } self::assertSame(RevisitedScene::FOV_MIN, $this->game->peek('fov')); self::assertSame(RevisitedScene::FOV_MIN, (float) $opts->get('rv_fov')); $this->begin(); self::assertSame(RevisitedScene::FOV_MIN, $this->game->peek('fov'), 'kept for the next game'); $opts->set('rv_fov', RevisitedScene::FOV_DEFAULT); } public function testCrouchingLowersTheEyeSmoothlyAndStandingRaisesIt(): void { $g = $this->begin(); self::assertEqualsWithDelta(Game::EYE, $this->game->peek('eyeH'), 0.001); $this->game->press('rv_crouch', 1); self::assertTrue($g->crouching); $heights = []; for ($i = 0; $i < 30; $i++) { $this->game->run(1); $heights[] = $this->game->peek('eyeH'); } self::assertGreaterThan(Game::CROUCH_EYE + 0.15, $heights[1], 'no snap: two frames later the eye is still high'); for ($i = 1; $i < 30; $i++) { self::assertLessThanOrEqual($heights[$i - 1] + 0.0001, $heights[$i], 'it only goes down (no bounce)'); } self::assertEqualsWithDelta(Game::CROUCH_EYE, $heights[29], 0.01, 'down in about a quarter of a second'); $this->game->press('rv_crouch', 1); $this->game->run(2); self::assertLessThan(Game::EYE - 0.15, $this->game->peek('eyeH'), 'standing up is eased too'); $this->game->run(30); self::assertEqualsWithDelta(Game::EYE, $this->game->peek('eyeH'), 0.01); } // ---- menus with the mouse, Quitter --------------------------------------------------------------------------- /** Where a region drawn last frame is, in the game's view coordinates (the mouse's): its centre. @return array{0: float, 1: float} */ private function spot(string $id): array { $canvas = $this->game->peek('canvas'); foreach ($this->game->peek('lastHits', $canvas) as [$x, $y, $w, $h, $hid]) { if ($hid === $id) { [, , $lw, $lh] = $this->game->engine->sdl->getRenderer()->letterbox(); $vw = $this->game->engine->config->width(); $vh = $this->game->engine->config->height(); return [($x + $w / 2) * $canvas->s * $vw / $lw, ($y + $h / 2) * $canvas->s * $vh / $lh]; } } self::fail("no region $id drawn"); } private function clickAt(string $id, bool $release = true): void { $mouse = $this->game->engine->input->getMouse(); $mouse->move(...$this->spot($id)); $this->game->run(1); $mouse->down(1); $this->game->run(1); if ($release) { $mouse->up(1); $this->game->run(1); } } /** @return list the labels of the menu shown */ private function rows(): array { return array_map(static fn (array $r): string => $r[0], $this->game->peek('menu')->rows); } public function testTheMenusFollowTheMouseAndAClickRunsExactlyTheRowClicked(): void { $opts = $this->game->engine->options; $opts->set('rv_quality', 'auto'); $this->game->start(RevisitedScene::class, ['seed' => 7, 'help' => false]); $this->game->run(4); self::assertSame('title', $this->game->peek('mode')); self::assertContains('Quitter le jeu', $this->rows(), 'the title card has a way out'); $menu = $this->game->peek('menu'); $options = array_search('Options', $this->rows(), true); $this->game->engine->input->getMouse()->move(...$this->spot('menu:' . $options)); $this->game->run(1); self::assertSame($options, $menu->sel, 'the row under the pointer lights up'); $this->game->press('up', 1); self::assertNotSame($options, $menu->sel, 'the keys move the selection away'); $this->clickAt('menu:' . $options); self::assertSame('options', $this->game->peek('mode'), 'the click runs the row clicked, not the one of the keys'); self::assertSame('auto', $this->game->peek('qualityPref'), 'and nothing of the menu opened under it'); $this->game->run(3); self::assertSame('auto', $this->game->peek('qualityPref')); $back = array_search('Retour', $this->rows(), true); $this->game->run(1); $this->clickAt('menu:' . $back); self::assertSame('title', $this->game->peek('mode'), 'Retour: back to the title card, once'); $this->game->run(3); self::assertSame('title', $this->game->peek('mode')); } public function testClickingResumeInThePauseMenuNeverTurnsTheView(): void { $g = $this->begin(); $mouse = $this->game->engine->input->getMouse(); $mouse->move(160, 120); $mouse->down(1); // a look drag on the view... $this->game->run(2); $mouse->up(1); $this->game->run(1); $this->game->press('pause', 2); self::assertSame('pause', $this->game->peek('mode')); $this->clickAt('menu:0', false); // Reprendre, the button kept down self::assertSame('play', $this->game->peek('mode')); $yaw = $g->yaw; $pitch = $g->pitch; for ($i = 1; $i <= 10; $i++) { $mouse->move(160 + $i * 5, 120 + $i * 3); $this->game->run(1); } $mouse->up(1); $this->game->run(1); self::assertEqualsWithDelta($yaw, $g->yaw, 0.0001, 'the click of the menu does not become a drag of the view'); self::assertEqualsWithDelta($pitch, $g->pitch, 0.0001); } public function testOnAPhoneSizedDashboardTheMenuRowsAreWhereTheyAreDrawn(): void { $this->begin(['seed' => 7, 'new' => true, 'uiscale' => 0.54]); $this->game->press('pause', 2); $this->game->run(1); $rows = $this->rows(); $controls = array_search('Commandes', $rows, true); $this->clickAt('menu:' . $controls); self::assertSame('controls', $this->game->peek('mode'), 'the row drawn smaller is the row clicked'); } public function testQuitLeavesTheGameFromTheTitleAndThePause(): void { $this->begin(); $this->game->press('pause', 2); $this->game->run(1); $rows = $this->rows(); self::assertContains('Quitter le jeu', $rows); $engine = $this->game->engine; $quits = 0; $count = function () use (&$quits): void { $quits++; }; $engine->on('quit', $count); $this->clickAt('menu:' . array_search('Quitter le jeu', $rows, true)); if ($this->game->peek('mode') === 'askleave') { // progress not saved in a slot: "Sauvegarder avant de quitter ?" → Non self::assertSame(0, $quits, 'not before the answer'); $this->clickAt('menu:' . array_search('Non, quitter sans sauvegarder', $this->rows(), true)); } self::assertTrue($this->game->peek('quitting')); self::assertSame(1, $quits, 'the engine quits once (desktop: the window closes; browser: the page takes over)'); self::assertTrue($this->game->engine->storage->exists(\App\Revisited\Ui\SaveStore::file(\App\Revisited\Ui\SaveStore::AUTO)), 'the autosave written before leaving'); // the test goes on with the next ones: the engine runs again \Closure::bind(function (): void { $this->running = true; }, $engine, $engine::class)(); $engine->removeListener('quit', $count); } private function choose(Game $g, string $part): void { $d = $g->dialogue(); self::assertNotNull($d); foreach ($d['choices'] as $i => $c) { if (str_contains($c, $part)) { $g->choose($i); return; } } self::fail("no choice '$part' in " . implode(' | ', $d['choices'])); } private function face(Game $g, Npc $t, float $dist): void { for ($k = 0; $k < 16; $k++) { $a = $k * M_PI / 8; $x = $t->x - sin($a) * $dist; $z = $t->z - cos($a) * $dist; if (!$g->zone->solidAt($x, $z) && $g->zone->waterDepth($x, $z) < 0.3) { $g->x = $x; $g->z = $z; $g->y = $g->zone->heightAt($x, $z); $g->yaw = $a; return; } } self::fail('no room around ' . $t->name); } }