Skip to content

Commit

Permalink
Merge pull request #15 from cohstats/master
Browse files Browse the repository at this point in the history
Add streamer overlay functionality
  • Loading branch information
JohannesMerkt authored Mar 4, 2023
2 parents 5e4076e + 99aef64 commit 77ef866
Show file tree
Hide file tree
Showing 17 changed files with 596 additions and 119 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/png" href="/ms-icon-310x310.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Coh3 Stats Desktop App (Alpha)</title>
<title>Coh3 Stats Desktop App</title>
</head>
<body style="overscroll-behavior: none">
<div id="root"></div>
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "coh3-stats-desktop-app",
"private": true,
"version": "0.0.8",
"version": "0.0.9",
"type": "module",
"scripts": {
"dev": "vite",
Expand All @@ -14,6 +14,7 @@
"@emotion/react": "^11.10.6",
"@mantine/core": "^6.0.0",
"@mantine/hooks": "^6.0.0",
"@tabler/icons-react": "^2.7.0",
"@tauri-apps/api": "^1.2.0",
"axios": "^1.3.4",
"coh-stats-components": "github:cohstats/coh-stats-components#0.0.7",
Expand Down
Binary file added public/instructions/navigateToPath.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "coh3-stats-desktop-app"
version = "0.0.8"
version = "0.0.9"
description = "A Tauri App"
authors = ["you"]
license = ""
Expand Down
12 changes: 11 additions & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"package": {
"productName": "Coh3 Stats Desktop App",
"version": "0.0.8"
"version": "0.0.9"
},
"tauri": {
"allowlist": {
Expand All @@ -16,6 +16,16 @@
"all": true,
"request": true,
"scope": ["https://coh3-api.reliclink.com/*"]
},
"fs": {
"writeFile": true,
"scope": ["$APPDATA/*"]
},
"path": {
"all": false
},
"clipboard": {
"writeText": true
}
},
"bundle": {
Expand Down
8 changes: 6 additions & 2 deletions src/Game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { PlayerCard } from "./components/PlayerCard"

export const Game: React.FC = () => {
const gameData = useGameData()
console.log("gamedata", gameData)
return (
<>
{gameData.logFileFound ? (
Expand Down Expand Up @@ -53,7 +52,12 @@ export const Game: React.FC = () => {
)}
</>
) : (
<>Could not find Log File</>
<Group position="center" mt={50}>
<Title>
<Loader mr="md" />
Waiting for logfile
</Title>
</Group>
)}
</>
)
Expand Down
90 changes: 88 additions & 2 deletions src/Settings.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,98 @@
import { useGameData } from "./game-data-provider/GameDataProvider"
import { ColorSchemeToggle } from "coh-stats-components"
import { Box } from "@mantine/core"
import {
Box,
Group,
Stack,
Divider,
Input,
ActionIcon,
Text,
List,
Image,
} from "@mantine/core"
import { appDataDir } from "@tauri-apps/api/path"
import { writeText } from "@tauri-apps/api/clipboard"
import { useEffect, useState } from "react"
import { IconCopy } from "@tabler/icons-react"

export const Settings: React.FC = () => {
const [appDataPath, setAppDataPath] = useState<string>("")
useEffect(() => {
const getAppDataPath = async () => {
const path = await appDataDir()
setAppDataPath(path)
}
if (appDataPath === "") {
getAppDataPath()
}
}, [appDataPath])

return (
<>
<Box p="xl">
Color Theme: <ColorSchemeToggle />
<Stack>
<Group>
<div>Color Theme:</div>
<div>
<ColorSchemeToggle />
</div>
</Group>
<Divider />
<div>
<Text weight={700}>
OBS Streamer Overlay instructions:
</Text>
<List type="ordered">
<List.Item>
In OBS Sources section click on "Add Source" and
select Browser
</List.Item>
<List.Item>
In the Browser source settings tick "Local File"
</List.Item>
<List.Item>
<Text>Copy this path:</Text>{" "}
<Group>
<Input
value={appDataPath}
style={{ width: 300 }}
readOnly
/>
<ActionIcon
onClick={() => {
writeText(appDataPath)
}}
>
<IconCopy size="1.125rem" />
</ActionIcon>
</Group>
</List.Item>
<List.Item>
In the Local File section click on "Browse"
</List.Item>
<List.Item>
An explorer window opens. Paste the copied path
into the path field shown in the image below:
<Image
src={"/instructions/navigateToPath.png"}
height={100}
/>
</List.Item>
<List.Item>
Select the file "streamerOverlay.html" and click
on open
</List.Item>
<List.Item>
Set the Width to 1920 and the Height to 1080
</List.Item>
<List.Item>
Click ok. All Done! The overlay will display
player ranks only when loading or ingame!
</List.Item>
</List>
</div>
</Stack>
</Box>
</>
)
Expand Down
16 changes: 0 additions & 16 deletions src/game-data-provider/gameClosedObject

This file was deleted.

74 changes: 0 additions & 74 deletions src/game-data-provider/gameStateObject

This file was deleted.

41 changes: 24 additions & 17 deletions src/game-data-provider/useFullGameData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import {
FullGameData,
FullPlayerData,
GameState,
GameType,
RawGameData,
RawTeamData,
TeamSide,
} from "./GameData"
import { useRawGameData } from "./useRawGameData"
import { fetch } from "@tauri-apps/api/http"
Expand All @@ -18,6 +16,7 @@ import {
logFileRaceTypeToRaceType,
} from "coh3-data-types-library"
import { MantineColor } from "@mantine/core"
import { renderStreamerHTML } from "../streamer-overlay/renderStreamerOverlay"

const PLAYER_COLOR_OBJECT: { left: MantineColor[]; right: MantineColor[] } = {
left: ["blue", "blue", "blue", "blue"],
Expand All @@ -33,6 +32,7 @@ export const useFullGameData = () => {
reloadLogFile,
} = useRawGameData()
const lastGameUniqueKeyRef = useRef<string>("")
const lastGameStateRef = useRef<GameState>()
const [gameData, setGameData] = useState<FullGameData>()

const generateUniqueGameKey = useCallback((rawGameData: RawGameData) => {
Expand Down Expand Up @@ -106,11 +106,8 @@ export const useFullGameData = () => {
member.level
refinedPlayerData[refinedPlayerIndex].xp = member.xp
}
console.log(gameMode)
console.log(response.faction)
const leaderboardID =
leaderboardsIDAsObject[gameMode][response.faction]
console.log(leaderboardID)
const leaderboard = data.leaderboardStats.find(
(leaderboard) =>
leaderboard.leaderboard_id === leaderboardID
Expand Down Expand Up @@ -151,7 +148,7 @@ export const useFullGameData = () => {
refineSide(rawGameData.left, true),
refineSide(rawGameData.right, false),
])
setGameData({
const newGameData: FullGameData = {
uniqueID: generateUniqueGameKey(rawGameData),
state: rawGameData.game_state,
type: rawGameData.game_type,
Expand All @@ -167,21 +164,31 @@ export const useFullGameData = () => {
side: rawGameData.right.side,
players: rightRefined,
},
})
console.log("done")
}
renderStreamerHTML(newGameData)
setGameData(newGameData)
} catch (e: any) {
console.error(e)
}
}
if (
logFileFound &&
rawGameData &&
lastGameUniqueKeyRef.current !== generateUniqueGameKey(rawGameData)
) {
console.log("Refine log file data")
console.log(rawGameData)
refineLogFileData(rawGameData)
lastGameUniqueKeyRef.current = generateUniqueGameKey(rawGameData)
// when raw data from log file changes check if its a new game with the generated unique key and refine data external api data
if (logFileFound && rawGameData) {
if (
lastGameUniqueKeyRef.current !==
generateUniqueGameKey(rawGameData)
) {
refineLogFileData(rawGameData)
lastGameUniqueKeyRef.current =
generateUniqueGameKey(rawGameData)
} else if (lastGameStateRef.current !== rawGameData.game_state) {
if (gameData) {
lastGameStateRef.current = rawGameData.game_state
const newGameData = gameData
newGameData.state = rawGameData.game_state
renderStreamerHTML(newGameData)
setGameData(newGameData)
}
}
}
}, [logFilePath, rawGameData])

Expand Down
1 change: 0 additions & 1 deletion src/game-data-provider/useRawGameData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const useRawGameData = () => {
setRawGameData(data)
}
const interval = useInterval(() => {
console.log("Check log file")
if (logFilePath !== undefined) {
getLogFileData(logFilePath)
}
Expand Down
Loading

0 comments on commit 77ef866

Please sign in to comment.