Skip to content

Commit

Permalink
Merge pull request #232 from moonstream-to/desktop-playing
Browse files Browse the repository at this point in the history
Desktop playing
  • Loading branch information
Anton-Mushnin authored Apr 3, 2024
2 parents 3d20118 + 958b082 commit 7f61009
Show file tree
Hide file tree
Showing 23 changed files with 798 additions and 43 deletions.
1 change: 1 addition & 0 deletions web/src/components/atbat/AtBatFooter.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
border-top: 1px solid #262019;
background: #FCECD9;
z-index: 2;
margin-top: 15px;
}

.vs {
Expand Down
18 changes: 16 additions & 2 deletions web/src/components/atbat/AtBatView.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,19 @@

.playerView {
display: flex;
margin-bottom: -15px;
}
flex-grow: 2;
align-items: flex-end;
}

@media (min-width: 1024px) {
.playerView {
padding-right: 15px;
padding-left: 15px;
flex-grow: 0;
position: relative;
min-height: 643px;
}
.container {
justify-content: center;
}
}
31 changes: 24 additions & 7 deletions web/src/components/atbat/AtBatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import { AtBatStatus, OwnedToken, Token } from "../../types";
import BatterViewMobile from "../playing/BatterViewMobile";
import { getContracts } from "../../utils/getWeb3Contracts";
import { FULLCOUNT_ASSETS_PATH } from "../../constants";
import { Image } from "@chakra-ui/react";
import { Image, useMediaQuery } from "@chakra-ui/react";
import Outcome2, { sessionOutcomeType } from "./Outcome2";
import ExitIcon from "../icons/ExitIcon";
import TokenCard from "./TokenCard";
import ScoreForDesktop from "./ScoreForDesktop";

const outcomes = [
"In Progress",
Expand Down Expand Up @@ -58,6 +60,7 @@ const AtBatView: React.FC = () => {
const [showPitchOutcome, setShowPitchOutcome] = useState(false);
const [currentSessionId, setCurrentSessionId] = useState(0);
const [currentSessionIdx, setCurrentSessionIdx] = useState(0);
const [isBigView] = useMediaQuery("(min-width: 1024px)");

useEffect(() => {
window.scrollTo(0, 0);
Expand Down Expand Up @@ -159,12 +162,21 @@ const AtBatView: React.FC = () => {
</div>
)}

{atBatState.data && (
{atBatState.data && !isBigView && (
<Score
atBat={atBatState.data.atBat}
pitch={atBatState.data.atBat.pitches[currentSessionIdx]}
/>
)}
{atBatState.data &&
isBigView &&
atBatState.data?.atBat.outcome === 0 &&
!showPitchOutcome && (
<ScoreForDesktop
atBat={atBatState.data.atBat}
pitch={atBatState.data.atBat.pitches[currentSessionIdx]}
/>
)}
{atBatState.data && atBatState.data.atBat.outcome !== 0 && selectedToken && (
<div
className={
Expand Down Expand Up @@ -223,10 +235,10 @@ const AtBatView: React.FC = () => {
!showPitchOutcome &&
atBatState.data.atBat.pitches[atBatState.data.atBat.numberOfSessions - 1].progress !== 2 &&
atBatState.data.atBat.pitches[currentSessionIdx].progress !== 6 && (
<div
id={"player_container"}
style={{ display: "flex", flexGrow: "2", alignItems: "flex-end" }}
>
<div className={styles.playerView}>
{isBigView && atBatState.data?.atBat.pitcher && (
<TokenCard token={atBatState.data?.atBat.pitcher} isPitcher={true} />
)}
{selectedToken &&
isSameToken(selectedToken, atBatState.data?.atBat.pitcher) &&
atBatState.data && (
Expand All @@ -243,6 +255,9 @@ const AtBatView: React.FC = () => {
token={selectedToken as OwnedToken} //TODO something. selectedToken can be Token (when view), but for actions OwnedToken needed
/>
)}
{isBigView && atBatState.data?.atBat.batter && (
<TokenCard token={atBatState.data?.atBat.batter} isPitcher={false} />
)}
</div>
)}
{atBatState.data?.atBat && showPitchOutcome && atBatState.data.atBat.pitches.length > 0 && (
Expand All @@ -259,7 +274,9 @@ const AtBatView: React.FC = () => {
)}
</>
)}
{atBatState.data && !showPitchOutcome && <AtBatFooter atBat={atBatState.data.atBat} />}
{atBatState.data && !showPitchOutcome && !isBigView && (
<AtBatFooter atBat={atBatState.data.atBat} />
)}
</div>
);
};
Expand Down
8 changes: 8 additions & 0 deletions web/src/components/atbat/PitchHistory.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,11 @@
.negativeOutcome {
color: #CD7676;
}

@media (min-width: 1024px) {
.container {
left: calc(100% + 10px);
top: 0;

}
}
50 changes: 50 additions & 0 deletions web/src/components/atbat/ScoreForDesktop.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
.container {
display: flex;
flex-direction: column;
gap: 22px;
justify-content: center;
z-index: 5;
flex-grow: 0;
align-self: stretch;
width: fit-content;
place-self: center;
position: absolute;
top: 20px;
}

.pitches {
display: flex;
padding: 5px 10px;
align-items: center;
gap: 5px;
align-self: center;
cursor: pointer;
}

.pitchNumber {
color: #FFF;
text-align: center;
-webkit-text-stroke-width: thin;
-webkit-text-stroke-color: #262019;
font-family: Bangers, cursive;
font-size: 32px;
font-style: normal;
font-weight: 400;
line-height: 100%; /* 32px */
letter-spacing: 1.6px;
}

.content {
display: flex;
justify-content: center;
border: 1px solid #262019;
}

.score {
display: flex;
padding: 10px 15px;
justify-content: center;
align-items: center;
gap: 15px;
background: #328449;
}
37 changes: 37 additions & 0 deletions web/src/components/atbat/ScoreForDesktop.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import styles from "./ScoreForDesktop.module.css";
import { AtBatStatus, SessionStatus } from "../../types";
import { useGameContext } from "../../contexts/GameContext";
import Timer from "./Timer";
import { useState } from "react";
import PitchHistory from "./PitchHistory";
import ChevronUpLarge from "../icons/ChevronUpLarge";
import ChevronDownLarge from "../icons/ChevronDownLarge";
import DotsCounterLarge from "../sessions/DotsCounterLarge";

const ScoreForDesktop = ({ atBat, pitch }: { atBat: AtBatStatus; pitch: SessionStatus }) => {
const { secondsPerPhase } = useGameContext();
const [isHistoryOpen, setIsHistoryOpen] = useState(false);

return (
<div className={styles.container}>
{isHistoryOpen && <PitchHistory atBat={atBat} />}
<div className={styles.pitches} onClick={() => setIsHistoryOpen(!isHistoryOpen)}>
<div className={styles.pitchNumber}>{`Pitch ${atBat.numberOfSessions}`}</div>
{isHistoryOpen ? <ChevronUpLarge /> : <ChevronDownLarge />}
</div>
<div className={styles.content}>
<div className={styles.score}>
<DotsCounterLarge label={"Ball"} count={atBat.balls} capacity={4} />
<DotsCounterLarge label={"Strike"} count={atBat.strikes} capacity={3} />
</div>
<Timer
start={pitch.phaseStartTimestamp ?? "0"}
delay={secondsPerPhase ?? 120}
isActive={pitch.progress === 3 || pitch.progress === 4}
/>
</div>
</div>
);
};

export default ScoreForDesktop;
6 changes: 6 additions & 0 deletions web/src/components/atbat/Timer.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@
font-style: normal;
font-weight: 400;
line-height: normal;
}

@media (min-width: 1024px) {
.container {
font-size: 26px;
}
}
62 changes: 62 additions & 0 deletions web/src/components/atbat/TokenCard.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
.pitcherContainer, .batterContainer {
display: flex;
padding: 14px;
flex-direction: column;
align-items: stretch;
gap: 10px;
border: 1px solid #262019;
background: #EBE4DC;
min-height: 643px;
z-index: 2;
position: absolute;
max-width: 290px;
left: calc((100vw - 66vh) / 4);
transform: translateX(-35%);

}

.batterContainer {
left: calc(100vw - (100vw - 66vh) / 4);
transform: translateX(-65%);
}

.image {
width: 260px;
min-width: 260px;

height: 260px;
border: 1px solid #262019;
background-color: white;
}

.tokenInfo {
display: flex;
align-items: center;
justify-content: center;
gap: 10px;
}

.tokenName {
color: #262019;
font-family: Bangers, cursive;
font-size: 24px;
font-style: normal;
font-weight: 400;
line-height: 120%; /* 28.8px */
}

.tokenId {
color: #8EAB8F;
font-family: Bangers, cursive;
font-size: 14px;
font-style: normal;
font-weight: 400;
line-height: 100%; /* 14px */
}

.detailedStat {
display: flex;
align-items: flex-start;
gap: 10px;
align-self: stretch;
}
Loading

0 comments on commit 7f61009

Please sign in to comment.