Skip to content
Open
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
2 changes: 1 addition & 1 deletion next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ const nextConfig: NextConfig = {
devIndicators: false,
};

export default nextConfig;
export default nextConfig;
26 changes: 0 additions & 26 deletions package-lock.json

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

32 changes: 28 additions & 4 deletions src/app/api/overlay-state/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { readFileSync, statSync } from 'fs';
import path from 'path';
import { OverlayState } from '../../lib/overlayState';

// Fuel count files inside the game file folder.
// Change these if your sim writes fuel counts under different names.
const FUEL_FILE_RED = 'Fuel_R.txt';
const FUEL_FILE_BLUE = 'Fuel_B.txt';

// File cache to avoid unnecessary reads
interface FileCacheEntry {
content: string | { red: { username: string; score: number }[], blue: { username: string; score: number }[] };
Expand Down Expand Up @@ -32,6 +37,11 @@ let overlayState: OverlayState = {
redSeriesScore: 0,
blueSeriesScore: 0,
allianceBranding: false,
// Fuel RP
fuelRPEnabled: true,
fuelRPThresholds: [100],
redFuel: 0,
blueFuel: 0,
// Tournament mode
tournamentModeEnabled: false,
tournamentPath: '',
Expand All @@ -45,6 +55,8 @@ let overlayState: OverlayState = {
field2GameState: '',
field2RedScore: 0,
field2BlueScore: 0,
field2RedFuel: 0,
field2BlueFuel: 0,
field2RedOPR: [],
field2BlueOPR: [],
field2SeriesEnabled: false,
Expand Down Expand Up @@ -222,12 +234,14 @@ export async function GET() {
const basePath = overlayState.gameFileLocation;

// Read all files in parallel for maximum speed
const [newRedScore, newBlueScore, newMatchTime, newOPR, newGameState] = await Promise.all([
const [newRedScore, newBlueScore, newMatchTime, newOPR, newGameState, newRedFuel, newBlueFuel] = await Promise.all([
Promise.resolve(readScore(path.join(basePath, 'Score_R.txt'))),
Promise.resolve(readScore(path.join(basePath, 'Score_B.txt'))),
Promise.resolve(readTimer(path.join(basePath, 'Timer.txt'))),
Promise.resolve(readOPR(path.join(basePath, 'OPR.txt'))),
Promise.resolve(readTimer(path.join(basePath, 'GameState.txt')))
Promise.resolve(readTimer(path.join(basePath, 'GameState.txt'))),
Promise.resolve(readScore(path.join(basePath, FUEL_FILE_RED))),
Promise.resolve(readScore(path.join(basePath, FUEL_FILE_BLUE)))
]);

// Check if values actually changed using efficient comparison
Expand All @@ -236,6 +250,8 @@ export async function GET() {
overlayState.blueScore !== newBlueScore ||
overlayState.matchTime !== newMatchTime ||
overlayState.gameState !== newGameState ||
overlayState.redFuel !== newRedFuel ||
overlayState.blueFuel !== newBlueFuel ||
!oprArraysEqual(overlayState.redOPR || [], newOPR.red) ||
!oprArraysEqual(overlayState.blueOPR || [], newOPR.blue)
) {
Expand All @@ -246,6 +262,8 @@ export async function GET() {
blueScore: newBlueScore,
matchTime: newMatchTime,
gameState: newGameState,
redFuel: newRedFuel,
blueFuel: newBlueFuel,
redOPR: newOPR.red,
blueOPR: newOPR.blue,
};
Expand All @@ -261,12 +279,14 @@ export async function GET() {
const basePath = overlayState.field2GameFileLocation;

// Read all files in parallel for maximum speed
const [newRedScore, newBlueScore, newMatchTime, newOPR, newGameState] = await Promise.all([
const [newRedScore, newBlueScore, newMatchTime, newOPR, newGameState, newRedFuel, newBlueFuel] = await Promise.all([
Promise.resolve(readScore(path.join(basePath, 'Score_R.txt'))),
Promise.resolve(readScore(path.join(basePath, 'Score_B.txt'))),
Promise.resolve(readTimer(path.join(basePath, 'Timer.txt'))),
Promise.resolve(readOPR(path.join(basePath, 'OPR.txt'))),
Promise.resolve(readTimer(path.join(basePath, 'GameState.txt')))
Promise.resolve(readTimer(path.join(basePath, 'GameState.txt'))),
Promise.resolve(readScore(path.join(basePath, FUEL_FILE_RED))),
Promise.resolve(readScore(path.join(basePath, FUEL_FILE_BLUE)))
]);

// Check if values actually changed using efficient comparison
Expand All @@ -275,6 +295,8 @@ export async function GET() {
overlayState.field2BlueScore !== newBlueScore ||
overlayState.field2MatchTime !== newMatchTime ||
overlayState.field2GameState !== newGameState ||
overlayState.field2RedFuel !== newRedFuel ||
overlayState.field2BlueFuel !== newBlueFuel ||
!oprArraysEqual(overlayState.field2RedOPR || [], newOPR.red) ||
!oprArraysEqual(overlayState.field2BlueOPR || [], newOPR.blue)
) {
Expand All @@ -285,6 +307,8 @@ export async function GET() {
field2BlueScore: newBlueScore,
field2MatchTime: newMatchTime,
field2GameState: newGameState,
field2RedFuel: newRedFuel,
field2BlueFuel: newBlueFuel,
field2RedOPR: newOPR.red,
field2BlueOPR: newOPR.blue,
};
Expand Down
1 change: 1 addition & 0 deletions src/app/lib/gameConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const GAME_MODE: string = 'REBUILT';
16 changes: 16 additions & 0 deletions src/app/lib/overlayState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export interface OverlayState {
blueSecondaryColor?: string;
allianceBranding: boolean;
flippedTeams?: boolean;
// Fuel RP
fuelRPEnabled?: boolean;
fuelRPThresholds?: number[]; // Fuel counts that earn an RP, e.g. [100] or [100, 360]
redFuel?: number;
blueFuel?: number;
// Tournament mode
tournamentModeEnabled?: boolean;
tournamentPath?: string;
Expand All @@ -39,6 +44,8 @@ export interface OverlayState {
field2GameState?: string; // Track Field 2 game state
field2RedScore?: number;
field2BlueScore?: number;
field2RedFuel?: number;
field2BlueFuel?: number;
field2RedOPR?: { username: string; score: number }[];
field2BlueOPR?: { username: string; score: number }[];
field2SeriesEnabled?: boolean;
Expand All @@ -55,6 +62,7 @@ export interface OverlayState {
field2BlueSecondaryColor?: string;
field2AllianceBranding?: boolean;
field2FlippedTeams?: boolean;
differentialData?: { redScore: number; blueScore: number; differential: number; gameTime: string; timestamp: number }[];
}

const defaultState: OverlayState = {
Expand All @@ -76,6 +84,11 @@ const defaultState: OverlayState = {
blueSeriesScore: 0,
allianceBranding: false,
flippedTeams: false,
// Fuel RP defaults
fuelRPEnabled: true,
fuelRPThresholds: [100],
redFuel: 0,
blueFuel: 0,
// Tournament mode defaults
tournamentModeEnabled: false,
tournamentPath: '',
Expand All @@ -88,6 +101,8 @@ const defaultState: OverlayState = {
field2GameFileLocation: '',
field2RedScore: 0,
field2BlueScore: 0,
field2RedFuel: 0,
field2BlueFuel: 0,
field2RedOPR: [{ username: '', score: 0 }, { username: '', score: 0 }, { username: '', score: 0 }],
field2BlueOPR: [{ username: '', score: 0 }, { username: '', score: 0 }, { username: '', score: 0 }],
field2SeriesEnabled: false,
Expand All @@ -98,6 +113,7 @@ const defaultState: OverlayState = {
field2BlueSeriesScore: 0,
field2AllianceBranding: false,
field2FlippedTeams: false,
differentialData: [],
};

export const getOverlayState = async (): Promise<OverlayState> => {
Expand Down
Loading