Skip to content

Commit

Permalink
➡️ Move portray to interface
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdodo committed Nov 30, 2024
1 parent 93c1f01 commit 27ba2c5
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 40 deletions.
16 changes: 10 additions & 6 deletions core/api/reroll.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import { test, expect } from "vitest";
import { withTwoPlayerGameStarted } from "../fixtures/with-two-player-game-started";
import { asPlayerReroll } from "../automations/as-player-reroll";
import { getDisplay } from "../utils/get-display";
import { getGame } from "../utils/get-game";
import { getGameShop } from "../utils/get-game-shop";

test("Reroll should swap the shop items with random hero from pool", async () => {
const testContext = await withTwoPlayerGameStarted();
const display = await getDisplay(testContext);
const game = await getGame(testContext);
const publicKey = testContext.frontContexts[0].publicKey || "Error";
const shop = getGameShop(game, publicKey);
const playsig = testContext.frontContexts[0].playsig || "Error";
const pool = await testContext.backContext.dataMapper.readPool(playsig);
await asPlayerReroll(testContext);
const displayAfter = await getDisplay(testContext);
const gameAfter = await getGame(testContext);
const shopAfter = getGameShop(gameAfter, publicKey);
const poolAfter = await testContext.backContext.dataMapper.readPool(playsig);
expect(displayAfter.shop).not.toEqual(display.shop);
expect(shopAfter).not.toEqual(shop);
expect(poolAfter?.heroes).not.toEqual(pool?.heroes);
expect(pool?.heroes).toBeTruthy();
const merged = [...displayAfter.shop, ...(poolAfter?.heroes || [])].sort();
const mergedAfter = [...display.shop, ...(pool?.heroes || [])].sort();
const merged = [...shopAfter, ...(poolAfter?.heroes || [])].sort();
const mergedAfter = [...shop, ...(pool?.heroes || [])].sort();
expect(merged).toEqual(mergedAfter);
});
25 changes: 0 additions & 25 deletions core/utils/get-display.ts

This file was deleted.

13 changes: 13 additions & 0 deletions core/utils/get-game-shop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { Game } from "../types/game";
import type { Appellation } from "../types/appellation";
import type { PublicKey } from "../types/public-key";

export function getGameShop(game: Game, publicKey: PublicKey): Appellation[] {
const shop = game.playerShops[publicKey];

if (!shop) {
throw new Error("Shop not found !");
}

return shop;
}
16 changes: 8 additions & 8 deletions core/utils/portray.ts → interface/utils/portray.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { Display } from "../types/display";
import type { Game } from "../types/game";
import type { Display } from "core/types/display";
import type { Game } from "core/types/game";
import type { Observable, OperatorFunction } from "rxjs";
import { map, combineLatestWith, startWith } from "rxjs/operators";
import { Animation } from "../types/animation";
import { Animation } from "core/types/animation";
import { interval } from "rxjs";
import { getLevelUpCost } from "./get-level-up-cost";
import { observePortrayedConfrontation } from "./observe-portrayed-confrontation";
import type { PublicKey } from "../types/public-key";
import type { Piece } from "../types/piece";
import { portrayBench } from "./portray-bench";
import { getLevelUpCost } from "core/utils/get-level-up-cost";
import { observePortrayedConfrontation } from "core/utils/observe-portrayed-confrontation";
import type { PublicKey } from "core/types/public-key";
import type { Piece } from "core/types/piece";
import { portrayBench } from "core/utils/portray-bench";

export function portray(publicKey: PublicKey): OperatorFunction<Game, Display> {
return (source: Observable<Game>) =>
Expand Down
2 changes: 1 addition & 1 deletion offline/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { startServer } from "core/utils/start-server";
import type { FrontContext } from "core/types/front-context";
import { initiateGame } from "core/api/initiate-game";
import { observeGame } from "core/api/observe-game";
import { portray } from "core/utils/portray";
import { portray } from "interface/utils/portray";
import { cast } from "core/utils/cast";
import { observeInteractions } from "interface/utils/observe-interactions";
import { firstValueFrom, of, map } from "rxjs";
Expand Down

0 comments on commit 27ba2c5

Please sign in to comment.