Skip to content

Commit

Permalink
refactor: rename warnInconsistentState()
Browse files Browse the repository at this point in the history
  • Loading branch information
manuartero committed Jan 9, 2023
1 parent 506d8f9 commit 8b9988d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
14 changes: 7 additions & 7 deletions src/components/board/board-controller.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useGameContext } from "contexts";
import { useState } from "react";
import { logInconsistentState } from "utils/console";
import { warnInconsistentState } from "utils/console";
import Board from "./board";
import BuildDialog from "./build-dialog";
import { inferVisualBoardFromGameContext } from "./infer-visual-board";
Expand All @@ -27,7 +27,7 @@ function BoardController(): JSX.Element {
const settleOnTile = (tile: TileID) => {
const piece = board[tile].piece;
if (!piece) {
return logInconsistentState(
return warnInconsistentState(
`trying to settle on ${tile} but no soldier found`,
{ tile: board[tile] }
);
Expand All @@ -46,7 +46,7 @@ function BoardController(): JSX.Element {
const upgradeBuildingOnTile = (tile: TileID) => {
const building = board[tile].building;
if (!building) {
return logInconsistentState(
return warnInconsistentState(
`trying to upgrade building on ${tile} but no building found`,
{ tile: board[tile] }
);
Expand All @@ -66,7 +66,7 @@ function BoardController(): JSX.Element {
const buildWallsOnTile = (tile: TileID) => {
const building = board[tile].building;
if (!building) {
return logInconsistentState(
return warnInconsistentState(
`trying to build walls on ${tile} but no building found`,
{ tile: board[tile] }
);
Expand Down Expand Up @@ -103,13 +103,13 @@ function BoardController(): JSX.Element {
const recruitOnTile = (tile: TileID) => {
const building = board[tile].building;
if (!building) {
return logInconsistentState(
return warnInconsistentState(
`trying to recruit on ${tile} but no building found`,
{ tile: board[tile] }
);
}
if (board[tile].piece) {
return logInconsistentState(
return warnInconsistentState(
`trying to recruit on ${tile} but piece already found`,
{ tile: board[tile] }
);
Expand Down Expand Up @@ -141,7 +141,7 @@ function BoardController(): JSX.Element {

const resolveActionOnTile = (tile: TileID) => {
if (gameContext.activeCard?.cardType !== "actionCard") {
return logInconsistentState(
return warnInconsistentState(
`trying to resolve an action on ${tile} while no action card`,
{ tile: board[tile] }
);
Expand Down
6 changes: 3 additions & 3 deletions src/components/player-hand/player-hand-controller.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useGameContext } from "contexts";
import { useEffect, useState } from "react";
import { logInconsistentState } from "utils/console";
import { warnInconsistentState } from "utils/console";
import { inferPlayerHandsFromGameContext } from "./infer-player-hands";
import PlayerHand from "./player-hand";

Expand Down Expand Up @@ -31,13 +31,13 @@ function PlayerHandController(): JSX.Element {

const handlePlayerCardClick = (cardId: string) => {
if (!gameContext.activePlayer) {
return logInconsistentState(
return warnInconsistentState(
`trying to handle click on ${cardId} while no activePlayer`
);
}
const playerCard = activePlayerHand.find((e) => e.card.cardId === cardId);
if (!playerCard) {
return logInconsistentState(
return warnInconsistentState(
`trying to handle click on ${cardId}, can't find this card on player's hand`,
{ activePlayerHand }
);
Expand Down
4 changes: 2 additions & 2 deletions src/contexts/game-context/use-players.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState } from "react";
import { logInconsistentState } from "utils/console";
import { warnInconsistentState } from "utils/console";

const initialPlayerStatus: PlayerStatus[] = [
{ player: "player", points: 0, greatestEmpirePoint: false },
Expand All @@ -20,7 +20,7 @@ function usePlayers() {
console.info(`GameContext.firstPlayer({ player: ${player} })`);
const newFirstPlayer = players.find((p) => p.player === player);
if (!newFirstPlayer) {
return logInconsistentState(`trying to set first player to ${player}`);
return warnInconsistentState(`trying to set first player to ${player}`);
}
setPlayers([newFirstPlayer, ...players.filter((p) => p.player !== player)]);
};
Expand Down
4 changes: 2 additions & 2 deletions src/game-logic/available-tiles.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { tilesInRange } from "game-logic/tiles-in-range";
import { logInconsistentState } from "utils/console";
import { warnInconsistentState } from "utils/console";
import { pieces } from "./pieces";

type _FilterPredicate = (_: [string, Tile]) => boolean;
Expand Down Expand Up @@ -64,7 +64,7 @@ type _TileInBoard = { tileId: TileID; board: Board };
export function getInRangeMovements({ tileId, board }: _TileInBoard): TileID[] {
const piece = board[tileId].piece;
if (!piece) {
logInconsistentState(
warnInconsistentState(
`getting range movement for piece at ${tileId}, but no piece found`,
{ tile: board[tileId] }
);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export function logRender(componentName: string) {

const WARN_TAG_STYLE = "color: red; font: bold; padding: 4px";

export function logInconsistentState(...args: unknown[]) {
export function warnInconsistentState(...args: unknown[]) {
console.warn(`%cInconsistent State%c: `, WARN_TAG_STYLE, ...args);
}

0 comments on commit 8b9988d

Please sign in to comment.