Skip to content

Commit

Permalink
Add support for expansion to multiple game types
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasBottone committed Jun 9, 2024
1 parent 021b919 commit 99843f1
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 23 deletions.
24 changes: 3 additions & 21 deletions src/lib/field.ts → src/lib/field/chargedUp.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import fs from "fs/promises";
import fsSync from "fs";
import type { GoogleSpreadsheetRow } from "google-spreadsheet";
import type { Match } from "./match";
import type { Match } from "../match/chargedUp";

export const SUSTAINABILITY_BONUS_RP = 9;
export const ACTIVATION_BONUS_RP = 32;

export const PLAYOFF_MATCHES_BEFORE_FINALS = 13;
const SUSTAINABILITY_BONUS_RP = 9;
const ACTIVATION_BONUS_RP = 32;

export async function getMatchData(
scheduledMatch: GoogleSpreadsheetRow,
Expand Down Expand Up @@ -173,19 +171,3 @@ export async function getMatchData(

return match;
}

export async function setMatchNumber(matchType: string, matchNumber: number) {
const type =
matchType === "Qual"
? "Quals"
: matchNumber > PLAYOFF_MATCHES_BEFORE_FINALS
? "Finals"
: "Playoff";

fsSync.existsSync("TourneyData/") || (await fs.mkdir("TourneyData/"));
await fs.writeFile("TourneyData/MatchNumber.txt", `${type} ${matchNumber}`);
await fs.writeFile(
"TourneyData/PrevMatchNumber.txt",
`${type} ${matchNumber - 1}`
);
}
33 changes: 33 additions & 0 deletions src/lib/field/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import fs from "fs/promises";
import fsSync from "fs";

import { getMatchData as chargedUpGetMatchData } from "./chargedUp";

export const PLAYOFF_MATCHES_BEFORE_FINALS = 13;

export async function setMatchNumber(matchType: string, matchNumber: number) {
const type =
matchType === "Qual"
? "Quals"
: matchNumber > PLAYOFF_MATCHES_BEFORE_FINALS
? "Finals"
: "Playoff";

fsSync.existsSync("TourneyData/") || (await fs.mkdir("TourneyData/"));
await fs.writeFile("TourneyData/MatchNumber.txt", `${type} ${matchNumber}`);
await fs.writeFile(
"TourneyData/PrevMatchNumber.txt",
`${type} ${matchNumber - 1}`
);
}

let gameGetMatchData;

switch (process.env.GAME_NAME) {
case "CHARGED UP":
default:
gameGetMatchData = chargedUpGetMatchData;
break;
}

export const getMatchData = gameGetMatchData;
File renamed without changes.
24 changes: 24 additions & 0 deletions src/lib/match/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {
type Match as chargedUpMatch,
headerValues as chargedUpHeaderValues,
matchToArray as chargedUpMatchToArray,
saveMatchToRow as chargedUpSaveMatchToRow,
} from "./chargedUp";

let gameHeaderValues;
let gameMatchToArray;
let gameSaveMatchToRow;

switch (process.env.GAME_NAME) {
case "CHARGED UP":
default:
gameHeaderValues = chargedUpHeaderValues;
gameMatchToArray = chargedUpMatchToArray;
gameSaveMatchToRow = chargedUpSaveMatchToRow;
break;
}

export type Match = chargedUpMatch; // | otherMatch;
export const headerValues = gameHeaderValues;
export const matchToArray = gameMatchToArray;
export const saveMatchToRow = gameSaveMatchToRow;
4 changes: 2 additions & 2 deletions src/lib/resultEmbed.ts → src/lib/resultEmbed/chargedUp.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EmbedBuilder, type Guild } from "discord.js";
import type { Match } from "./match";
import { PLAYOFF_MATCHES_BEFORE_FINALS } from "./field";
import type { Match } from "../match";
import { PLAYOFF_MATCHES_BEFORE_FINALS } from "../field";

const codeBlock = (str: string) => `\`\`\`\n${str}\n\`\`\``;

Expand Down
18 changes: 18 additions & 0 deletions src/lib/resultEmbed/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {
sendQualMatchEmbed as chargedUpSendQualMatchEmbed,
sendPlayoffMatchEmbed as chargedUpSendPlayoffMatchEmbed,
} from "./chargedUp";

let gameSendQualMatchEmbed;
let gameSendPlayoffMatchEmbed;

switch (process.env.GAME_NAME) {
case "CHARGED UP":
default:
gameSendQualMatchEmbed = chargedUpSendQualMatchEmbed;
gameSendPlayoffMatchEmbed = chargedUpSendPlayoffMatchEmbed;
break;
}

export const sendQualMatchEmbed = gameSendQualMatchEmbed;
export const sendPlayoffMatchEmbed = gameSendPlayoffMatchEmbed;

0 comments on commit 99843f1

Please sign in to comment.