Skip to content

Commit

Permalink
add start set and dq functionality #8
Browse files Browse the repository at this point in the history
also adjust replay list width (reduce left/right pad)
  • Loading branch information
jmlee337 committed Mar 1, 2024
1 parent a6f353b commit 7a8aaeb
Show file tree
Hide file tree
Showing 11 changed files with 217 additions and 60 deletions.
3 changes: 2 additions & 1 deletion src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ export type StartggGame = {
};

export type StartggSet = {
gameData: StartggGame[];
setId: number;
winnerId: number;
isDQ: boolean;
gameData: StartggGame[];
};

export enum Output {
Expand Down
13 changes: 13 additions & 0 deletions src/main/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
getPhase,
getPhaseGroup,
getTournament,
startSet,
reportSet,
updateSet,
} from './startgg';
Expand Down Expand Up @@ -112,6 +113,18 @@ export default function setupIPCs(mainWindow: BrowserWindow): void {
},
);

ipcMain.removeHandler('startSet');
ipcMain.handle(
'startSet',
async (event: IpcMainInvokeEvent, setId: number) => {
if (!sggApiKey) {
throw new Error('Please set start.gg API key');
}

return startSet(sggApiKey, setId);
},
);

ipcMain.removeHandler('reportSet');
ipcMain.handle(
'reportSet',
Expand Down
2 changes: 1 addition & 1 deletion src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const createWindow = async () => {
};

mainWindow = new BrowserWindow({
minWidth: 933,
minWidth: 901,
minHeight: 668,
show: false,
width: 1024,
Expand Down
1 change: 1 addition & 0 deletions src/main/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const electronHandler = {
ipcRenderer.invoke('getPhase', id),
getPhaseGroup: (id: number): Promise<Sets> =>
ipcRenderer.invoke('getPhaseGroup', id),
startSet: (id: number): Promise<void> => ipcRenderer.invoke('startSet', id),
reportSet: (set: StartggSet): Promise<void> =>
ipcRenderer.invoke('reportSet', set),
updateSet: (set: StartggSet): Promise<void> =>
Expand Down
21 changes: 15 additions & 6 deletions src/main/startgg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,26 +181,35 @@ export async function getPhaseGroup(key: string, id: number): Promise<Sets> {
};
}

const REPORT_BRACKET_SET_MUTATION = `
mutation ReportBracketSet($setId: ID!, $gameData: [BracketSetGameDataInput], $winnerId: ID) {
reportBracketSet(setId: $setId, gameData: $gameData, winnerId: $winnerId) {
const MARK_SET_IN_PROGRESS_MUTATION = `
mutation MarkSetInProgress($setId: ID!) {
markSetInProgress(setId: $setId) {
id
}
}
`;
export async function startSet(key: string, setId: number) {
await fetchGql(key, MARK_SET_IN_PROGRESS_MUTATION, { setId });
}

const REPORT_BRACKET_SET_MUTATION = `
mutation ReportBracketSet($setId: ID!, $winnerId: ID, $isDQ: Boolean, $gameData: [BracketSetGameDataInput]) {
reportBracketSet(setId: $setId, isDQ: $isDQ, winnerId: $winnerId, gameData: $gameData) {
id
}
}
`;
export async function reportSet(key: string, set: StartggSet) {
await fetchGql(key, REPORT_BRACKET_SET_MUTATION, set);
}

const UPDATE_BRACKET_SET_MUTATION = `
mutation UpdateBracketSet($setId: ID!, $gameData: [BracketSetGameDataInput], $winnerId: ID) {
updateBracketSet(setId: $setId, gameData: $gameData, winnerId: $winnerId) {
mutation UpdateBracketSet($setId: ID!, $winnerId: ID, $isDQ: Boolean, $gameData: [BracketSetGameDataInput]) {
updateBracketSet(setId: $setId, isDQ: $isDQ, winnerId: $winnerId, gameData: $gameData) {
id
}
}
`;

export async function updateSet(key: string, set: StartggSet) {
await fetchGql(key, UPDATE_BRACKET_SET_MUTATION, set);
}
118 changes: 101 additions & 17 deletions src/renderer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ import {
Typography,
} from '@mui/material';
import {
Backup,
DeleteForever,
DeleteForeverOutlined,
Edit,
FolderOpen,
HourglassTop,
Refresh,
} from '@mui/icons-material';
import styled from '@emotion/styled';
Expand Down Expand Up @@ -113,6 +115,10 @@ function Hello() {
{ displayName: '', entrantId: 0 },
]);
};
const [dq, setDq] = useState({ displayName: '', entrantId: 0 });
const resetDq = () => {
setDq({ displayName: '', entrantId: 0 });
};

// Replay list
const [allReplaysSelected, setAllReplaysSelected] = useState(true);
Expand Down Expand Up @@ -214,6 +220,7 @@ function Hello() {
setBatchActives(newBatchActives);
setOverrides(newOverrides);
setReplays(newReplays);
resetDq();
};
useEffect(() => {
window.electron.onUsb(refreshReplays);
Expand Down Expand Up @@ -310,6 +317,7 @@ function Hello() {
});
});
setOverrides(newOverrides);
resetDq();
resetSelectedChipData();
};
const batchChip = (index: number) => (
Expand Down Expand Up @@ -475,6 +483,28 @@ function Hello() {
setSelectedSetChain({ eventId, phaseId, phaseGroupId });
setSelectedSet(set);
};

const startSet = async (setId: number) => {
try {
await window.electron.startSet(setId);
await new Promise((resolve) => {
// it seems that start.gg needs a moment to settle
// before the set will be reflected as completed.
setTimeout(resolve, 1000);
});
await getPhaseGroup(
selectedSetChain.phaseGroupId,
selectedSetChain.phaseId,
selectedSetChain.eventId,
);
const updatedSelectedSet = { ...selectedSet };
updatedSelectedSet.state = 2;
setSelectedSet(updatedSelectedSet);
} catch (e: any) {
showErrorDialog(e.toString());
}
};

const reportSet = async (set: StartggSet, update: boolean) => {
try {
if (update) {
Expand Down Expand Up @@ -520,7 +550,7 @@ function Hello() {
<AppBar position="fixed" style={{ backgroundColor: 'white' }}>
<Toolbar disableGutters variant="dense">
<AppBarSection flexGrow={1} minWidth={600}>
<Stack alignItems="center" direction="row" paddingLeft="16px">
<Stack alignItems="center" direction="row">
<Tooltip
arrow
title={
Expand Down Expand Up @@ -698,7 +728,7 @@ function Hello() {
boxSizing="border-box"
flexGrow={1}
minWidth="600px"
padding="20px 16px 0 58px"
padding="20px 0 0 42px"
>
<Stack direction="row">
{batchChip(0)}
Expand Down Expand Up @@ -736,13 +766,25 @@ function Hello() {
<Stack>
{!!selectedSet.id && (
<>
<Typography
lineHeight="20px"
textAlign="center"
variant="caption"
<Stack
alignItems="center"
justifyContent="center"
direction="row"
>
{selectedSet.fullRoundText} ({selectedSet.id})
</Typography>
<Typography lineHeight="20px" variant="caption">
{selectedSet.fullRoundText} ({selectedSet.id})
</Typography>
{selectedSet.state === 2 && (
<Tooltip placement="top" title="Started">
<HourglassTop fontSize="inherit" />
</Tooltip>
)}
{selectedSet.state === 3 && (
<Tooltip placement="top" title="Finished">
<Backup fontSize="inherit" />
</Tooltip>
)}
</Stack>
<Tooltip arrow title="Drag or select players!">
<Stack direction="row" gap="8px">
<Stack gap="8px" width="50%">
Expand Down Expand Up @@ -795,21 +837,57 @@ function Hello() {
)}
</Stack>
<Stack direction="row" paddingTop="8px" spacing="8px">
<Stack direction="row" justifyContent="center" width="50%">
<Stack direction="row" width="50%">
<DroppableChip
active
label={dq.displayName || 'DQ'}
outlined
selectedChipData={selectedChipData}
style={{ width: '100%' }}
onClickOrDrop={(displayName: string, entrantId: number) => {
const newOverrides = [
{ displayName: '', entrantId: 0 },
{ displayName: '', entrantId: 0 },
{ displayName: '', entrantId: 0 },
{ displayName: '', entrantId: 0 },
];
selectedReplays.forEach((replay) => {
replay.selected = false;
replay.players.forEach((player, i) => {
player.playerOverrides = { ...newOverrides[i] };
});
});
const newReplays = Array.from(replays);
setOverrides(newOverrides);
setReplays(newReplays);
setDq({ displayName, entrantId });
resetSelectedChipData();
}}
/>
</Stack>
<Stack
direction="row"
justifyContent="flex-end"
flexGrow={1}
spacing="8px"
>
<Tooltip title="Start Match">
<IconButton
color="primary"
disabled={!(selectedSet.id && selectedSet.state < 2)}
size="small"
onClick={() => startSet(selectedSet.id)}
>
<HourglassTop />
</IconButton>
</Tooltip>
<SetControls
reportSet={reportSet}
dqId={dq.entrantId}
selectedReplays={selectedReplays}
set={selectedSet}
/>
</Stack>
<Stack direction="row" justifyContent="center" width="50%">
<Settings
appVersion={appVersion}
gotStartggApiKey={gotStartggApiKey}
startggApiKey={startggApiKey}
setStartggApiKey={setStartggApiKey}
/>
</Stack>
</Stack>
</Stack>
</BottomColumns>
Expand All @@ -827,6 +905,12 @@ function Hello() {
}}
open={errorDialogOpen}
/>
<Settings
appVersion={appVersion}
gotStartggApiKey={gotStartggApiKey}
startggApiKey={startggApiKey}
setStartggApiKey={setStartggApiKey}
/>
</>
);
}
Expand Down
1 change: 1 addition & 0 deletions src/renderer/ReplayList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ const ReplayListItem = memo(function ReplayListItem({

return (
<ListItemButton
disableGutters
style={replay.isValid ? {} : { opacity: '50%' }}
selected={replay.selected}
onClick={onClickCallback}
Expand Down
Loading

0 comments on commit 7a8aaeb

Please sign in to comment.