Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(frontend/battle): add status text to game over card and loss-only grayed out background #600

Merged
merged 2 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
position: relative;
width: 100%;
height: 100%;
backdrop-filter: grayscale(100%);

&.grayedOut {
backdrop-filter: grayscale(100%);
}
}

.card {
Expand Down Expand Up @@ -39,16 +42,3 @@
height: 32px;
width: 32px;
}

.result {
position: absolute;
top: 486px;
text-transform: uppercase;
text-align: center;
width: 100%;
font-size: 56px;
line-height: 67px;
font-weight: 700;
color: #ffffff;
-webkit-text-stroke: 2px #000000;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ type GameOverCardProps = {
className?: string;
};

const STATUS = {
WIN: 'win',
LOSS: 'loss',
DRAW: 'draw',
} as const;

const STATUS_TEXT = {
[STATUS.WIN]: 'You won',
[STATUS.LOSS]: 'You lost',
[STATUS.DRAW]: "It's a draw",
} as const;

const GameOverCard = ({
bid,
className,
Expand All @@ -40,16 +52,18 @@ const GameOverCard = ({

const isTournamentDraw = isTournamentOver && state.gameIsOver.winners[1];

const getMyResultStatus = () => {
if (!account) return null;
const getStatus = () => {
if (!account) return;

if (isCurrentDraw || (isTournamentDraw && state.gameIsOver.winners.includes(account.decodedAddress)))
return 'It’s a draw';
if (!isAlive && (!isShowOtherBattle || isTournamentOver)) return 'You lose';
if (isTournamentOver && state.gameIsOver.winners[0] === account.decodedAddress) return 'You win';
return null;
return STATUS.DRAW;

if (!isAlive && (!isShowOtherBattle || isTournamentOver)) return STATUS.LOSS;

if (isTournamentOver && state.gameIsOver.winners[0] === account.decodedAddress) return STATUS.WIN;
};

const myResultStatus = getMyResultStatus();
const status = getStatus();

const getDesctiptionText = () => {
if (!isTournamentOver) {
Expand All @@ -72,10 +86,10 @@ const GameOverCard = ({
};

return (
myResultStatus && (
<div className={clsx(styles.backdrop, className)}>
status && (
<div className={clsx(styles.backdrop, status === STATUS.LOSS && styles.grayedOut, className)}>
{!isCurrentDraw && (
<Card title="Game over" description={getDesctiptionText()} className={styles.card} size="md">
<Card title={STATUS_TEXT[status]} description={getDesctiptionText()} className={styles.card} size="md">
{isTournamentOver && (
<div className={styles.prize}>
<Text size="sm">Winner prize:</Text>
Expand All @@ -87,8 +101,6 @@ const GameOverCard = ({
)}
</Card>
)}

<p className={styles.result}>{myResultStatus}</p>
</div>
)
);
Expand Down
10 changes: 3 additions & 7 deletions frontend/apps/web3-warriors-battle/src/features/game/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { decodeAddress } from '@gear-js/api';
import React from 'react';
import { lazy } from 'react';

import { CharacterView } from './components/character/character';
import { assetsCount, back_colors, body_colors } from './consts';
Expand All @@ -8,11 +8,7 @@ import { AssetType } from './types';
export const getLazySvg = (assetType: AssetType, index: number) => {
const assetNumber = index > 0 ? (index % assetsCount[assetType]) + 1 : 1;

return React.lazy(() =>
import(`./assets/images/character/${assetType}-${assetNumber}.svg`).then((module) => ({
default: module.ReactComponent,
})),
);
return lazy(() => import(`./assets/images/character/${assetType}-${assetNumber}.svg?react`));
};

export const getRandomNumber = (maxNumber: number) => Math.floor(Math.random() * maxNumber);
Expand All @@ -30,7 +26,7 @@ export const getSafeDecodedAddress = (address?: string) => {
if (address) {
try {
return decodeAddress(address.trim());
} catch (error) {
} catch (_error) {
// empty
}
}
Expand Down