Skip to content

Commit

Permalink
Use full names of variants in lists where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
Perlkonig committed Sep 22, 2024
1 parent 2cff62a commit 44a98ed
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 12 deletions.
18 changes: 14 additions & 4 deletions src/components/ListGames.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState, useEffect, useMemo } from "react";
import { Link, useParams } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { gameinfo } from "@abstractplay/gameslib";
import { gameinfo, GameFactory } from "@abstractplay/gameslib";
import { API_ENDPOINT_OPEN } from "../config";
import {
getCoreRowModel,
Expand Down Expand Up @@ -58,6 +58,16 @@ function ListGames({ fixedState }) {
}, [gameState, metaGame, fixedState]);

const metaGameName = gameinfo.get(metaGame).name;
const variantMap = useMemo(() => {
const info = gameinfo.get(metaGame);
let gameEngine;
if (info.playercounts.length > 1) {
gameEngine = GameFactory(info.uid, 2);
} else {
gameEngine = GameFactory(info.uid);
}
return new Map(gameEngine.allvariants().map(rec => [rec.uid, rec.name]));
}, [metaGame]);

const data = useMemo(
() =>
Expand All @@ -79,11 +89,11 @@ function ListGames({ fixedState }) {
? rec.winner.map((w) => rec.players[w - 1].name)
: null,
variants:
"variants" in rec && rec.variants !== null ? rec.variants : null,
"variants" in rec && rec.variants !== null ? rec.variants.map(id => variantMap.has(id) ? variantMap.get(id) : id) : null,
cbit: fixedState === "completed" || gameState === "completed" ? 1 : 0,
};
}),
[games, gameState, fixedState]
[games, gameState, fixedState, variantMap]
);

const columnHelper = createColumnHelper();
Expand Down Expand Up @@ -129,7 +139,7 @@ function ListGames({ fixedState }) {
columnHelper.accessor("variants", {
header: "Variants",
cell: (props) =>
props.getValue() === null ? "" : props.getValue().join(", "),
props.getValue() === null ? "" : props.getValue().join("; "),
}),
columnHelper.display({
id: "actions",
Expand Down
15 changes: 13 additions & 2 deletions src/components/Me/ChallengeResponseModal.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useContext, useState } from "react";
import { useTranslation } from "react-i18next";
import { gameinfo } from "@abstractplay/gameslib";
import { gameinfo, GameFactory } from "@abstractplay/gameslib";
import { MeContext } from "../../pages/Skeleton";
import Modal from "../Modal";

Expand Down Expand Up @@ -49,7 +49,18 @@ function ChallengeResponseModal(props) {
var desc = "";
const numVariants =
challenge.variants === undefined ? 0 : challenge.variants.length;
const variants = numVariants > 0 ? challenge.variants.join(", ") : null;
let variantMap = new Map();
if (numVariants > 0) {
const info = gameinfo.get(challenge.metaGame);
let gameEngine;
if (info.playercounts.length > 1) {
gameEngine = GameFactory(info.uid, 2);
} else {
gameEngine = GameFactory(info.uid);
}
variantMap = new Map(gameEngine.allvariants().map(rec => [rec.uid, rec.name]));
}
const variants = numVariants > 0 ? challenge.variants.map(id => variantMap.has(id) ? variantMap.get(id) : id).join("; ") : null;
desc =
t("ChallengeResponseDesc", {
opp: challenge.challenger.name,
Expand Down
15 changes: 13 additions & 2 deletions src/components/Me/ChallengeViewModal.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from "react";
import { useTranslation } from "react-i18next";
import { gameinfo } from "@abstractplay/gameslib";
import { gameinfo, GameFactory } from "@abstractplay/gameslib";
import Modal from "../Modal";

function ChallengeViewModal(props) {
Expand All @@ -22,7 +22,18 @@ function ChallengeViewModal(props) {
const game = gameinfo.get(challenge.metaGame);
const numVariants =
challenge.variants === undefined ? 0 : challenge.variants.length;
const variants = numVariants > 0 ? challenge.variants.join(", ") : null;
let variantMap = new Map();
if (numVariants > 0) {
const info = gameinfo.get(challenge.metaGame);
let gameEngine;
if (info.playercounts.length > 1) {
gameEngine = GameFactory(info.uid, 2);
} else {
gameEngine = GameFactory(info.uid);
}
variantMap = new Map(gameEngine.allvariants().map(rec => [rec.uid, rec.name]));
}
const variants = numVariants > 0 ? challenge.variants.map(id => variantMap.has(id) ? variantMap.get(id) : id).join("; ") : null;
var challengeDesc = "";
var players = "";
const otherplayers = challenge.players
Expand Down
18 changes: 14 additions & 4 deletions src/components/StandingChallenges.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState, useEffect, useContext, useMemo } from "react";
import { useTranslation } from "react-i18next";
import { useParams, Link } from "react-router-dom";
import { gameinfo } from "@abstractplay/gameslib";
import { gameinfo, GameFactory } from "@abstractplay/gameslib";
import { API_ENDPOINT_OPEN, API_ENDPOINT_AUTH } from "../config";
import {
getCoreRowModel,
Expand Down Expand Up @@ -262,6 +262,16 @@ function StandingChallenges(props) {
const metaGameName = gameinfo.get(metaGame).name;
console.log(metaGame);
const showRespond = loggedin && challenges;
const variantMap = useMemo(() => {
const info = gameinfo.get(metaGame);
let gameEngine;
if (info.playercounts.length > 1) {
gameEngine = GameFactory(info.uid, 2);
} else {
gameEngine = GameFactory(info.uid);
}
return new Map(gameEngine.allvariants().map(rec => [rec.uid, rec.name]));
}, [metaGame]);

const data = useMemo(
() =>
Expand All @@ -287,11 +297,11 @@ function StandingChallenges(props) {
players: rec.players.filter((p) => p.id !== rec.challenger?.id),
rated: rec.rated,
seating: rec.seating,
variants: rec.variants,
variants: rec.variants.map(id => variantMap.has(id) ? variantMap.get(id) : id),
comment: rec.comment,
};
}),
[challenges, allUsers]
[challenges, allUsers, variantMap]
);

const columnHelper = createColumnHelper();
Expand Down Expand Up @@ -338,7 +348,7 @@ function StandingChallenges(props) {
}),
columnHelper.accessor("variants", {
header: "Variants",
cell: (props) => props.getValue().join(", "),
cell: (props) => props.getValue().join("; "),
}),
columnHelper.accessor("comment", {
header: "Notes",
Expand Down

0 comments on commit 44a98ed

Please sign in to comment.