-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
homescreen stats, deeeeeper integration
- Loading branch information
Showing
7 changed files
with
171 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React, { useState } from "react"; | ||
import { Dialog } from "./dialog"; | ||
import { CidLookup } from "./cidLookup"; | ||
|
||
type DetailedCidProps = { | ||
cid: string; | ||
}; | ||
|
||
export const DetailedCid: React.FC<DetailedCidProps> = ( | ||
props: DetailedCidProps | ||
) => { | ||
const [open, setOpen] = useState(false); | ||
|
||
return ( | ||
<> | ||
<div | ||
onClick={() => setOpen(true)} | ||
className="cursor-pointer inline text-blue-600" | ||
> | ||
{props.cid} | ||
</div> | ||
{open && ( | ||
<Dialog open={open} toggle={() => setOpen(false)}> | ||
<CidLookup initialCid={props.cid} /> | ||
</Dialog> | ||
)} | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React, { useState } from "react"; | ||
import { Dialog } from "./dialog"; | ||
import { IpLookup } from "./ipLookup"; | ||
|
||
type DetailedIpProps = { | ||
ip: string; | ||
}; | ||
|
||
export const DetailedIp: React.FC<DetailedIpProps> = ( | ||
props: DetailedIpProps | ||
) => { | ||
const [open, setOpen] = useState(false); | ||
|
||
return ( | ||
<> | ||
<div | ||
onClick={() => setOpen(true)} | ||
className="cursor-pointer inline text-blue-600" | ||
> | ||
{props.ip} | ||
</div> | ||
{open && ( | ||
<Dialog open={open} toggle={() => setOpen(false)}> | ||
<IpLookup initialIp={props.ip} /> | ||
</Dialog> | ||
)} | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import React, { PropsWithChildren, useEffect, useState } from "react"; | ||
|
||
type RoundData = { | ||
mode: string; | ||
vote: number; | ||
ai: boolean; | ||
host?: string; | ||
round_id: number; | ||
players: number; | ||
revision: string; | ||
admins: number; | ||
gamestate: number; | ||
map_name: string; | ||
security_level: string; | ||
round_duration: number; | ||
time_dilation_current: number; | ||
time_dilation_avg: number; | ||
time_dilation_avg_slow: number; | ||
time_dilation_avg_fast: number; | ||
mcpu: number; | ||
cpu: number; | ||
}; | ||
|
||
export const RoundData: React.FC = () => { | ||
const [roundData, setRoundData] = useState<RoundData | null>(null); | ||
|
||
useEffect(() => { | ||
if (!roundData) { | ||
fetch(`${import.meta.env.VITE_API_PATH}/Round`).then((value) => | ||
value.json().then((json) => setRoundData(json.data)) | ||
); | ||
} | ||
}); | ||
|
||
if (!roundData) { | ||
return <div>Loading...</div>; | ||
} | ||
|
||
const formatGameState = (gameState: number) => { | ||
switch (gameState) { | ||
case 0: | ||
return "Starting"; | ||
case 1: | ||
return "Lobby"; | ||
case 2: | ||
return "Setting Up"; | ||
case 3: | ||
return "Playing"; | ||
case 4: | ||
return "Finished"; | ||
} | ||
return "Unknown"; | ||
}; | ||
|
||
const formatDuration = (ms: number) => { | ||
if (ms < 0) ms = -ms; | ||
const time = { | ||
day: Math.floor(ms / 86400000), | ||
hour: Math.floor(ms / 3600000) % 24, | ||
minute: Math.floor(ms / 60000) % 60, | ||
second: Math.floor(ms / 1000) % 60, | ||
}; | ||
return Object.entries(time) | ||
.filter((val) => val[1] !== 0) | ||
.map(([key, val]) => `${val} ${key}${val !== 1 ? "s" : ""}`) | ||
.join(", "); | ||
}; | ||
|
||
return ( | ||
<div className="flex flex-col justify-center mt-20 gap-2"> | ||
<div className="flex flex-row justify-center gap-3"> | ||
<InfoBox label="Round ID">{roundData.round_id}</InfoBox> | ||
<InfoBox label="Players">{roundData.players}</InfoBox> | ||
<InfoBox label="Admins">{roundData.admins}</InfoBox> | ||
</div> | ||
<div className="flex flex-row gap-3"> | ||
<InfoBox label="Map Name">{roundData.map_name}</InfoBox> | ||
<InfoBox label="Game State"> | ||
{formatGameState(roundData.gamestate)} | ||
</InfoBox> | ||
</div> | ||
<div className="flex flex-row gap-3"> | ||
<InfoBox label="Duration"> | ||
{formatDuration(roundData.round_duration * 100)} | ||
</InfoBox> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
interface InfoBoxProps extends PropsWithChildren { | ||
label: string; | ||
} | ||
|
||
const InfoBox = (props: InfoBoxProps) => { | ||
return ( | ||
<div className="p-5 border-white border flex flex-col gap-2 grow"> | ||
<div className="text-3xl">{props.label}</div> | ||
{props.children} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters