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
1 change: 1 addition & 0 deletions .github/workflows/monkey-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ jobs:
- 'frontend/static/themes/**'
- 'frontend/static/webfonts/**'
- 'frontend/static/challenges/**'
- 'frontend/static/sounds/**'

- name: Set up Node.js
uses: actions/setup-node@v4
Expand Down
54 changes: 54 additions & 0 deletions frontend/scripts/check-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { z } from "zod";
import { ChallengeSchema, Challenge } from "@monkeytype/schemas/challenges";
import { LayoutObject, LayoutObjectSchema } from "@monkeytype/schemas/layouts";
import { QuoteDataSchema, QuoteData } from "@monkeytype/schemas/quotes";
import { clickSoundConfig } from "../src/ts/constants/sounds";

class Problems<K extends string, T extends string> {
private type: string;
Expand Down Expand Up @@ -421,6 +422,57 @@ async function validateThemes(): Promise<void> {
}
}

async function validateSounds(): Promise<void> {
const problems = new Problems<string, "_additional">("Sounds", {
_additional:
"Sound files present but missing in frontend/src/ts/constants/sounds",
});

const soundFiles = new Set(
fs
.readdirSync("./static/sound")
.filter((it) => it.startsWith("click"))
.flatMap((folder) =>
fs
.readdirSync(`./static/sound/${folder}`)
.map((it) => `${folder}/${it}`),
),
);

//missing sound files
Object.entries(clickSoundConfig).forEach(([key, value]) => {
value
.flatMap((it) =>
it.sounds.map((file) => file.substring("../sound/".length)),
)

.filter((it) => !soundFiles.has(it))
.forEach((file) =>
problems.add(
"click" + key,
`missing file frontend/static/sound/${file}`,
),
);
});

//additional files
const expectedSoundFiles = new Set(
Object.values(clickSoundConfig).flatMap((it) =>
it.flatMap((cfg) =>
cfg.sounds.map((file) => file.substring("../sound/".length)),
),
),
);
soundFiles
.values()
.filter((name) => !expectedSoundFiles.has(name))
.forEach((file) => problems.add("_additional", file));

console.log(problems.toString());

return;
}

type Validator = () => Promise<void>;

async function main(): Promise<void> {
Expand All @@ -436,11 +488,13 @@ async function main(): Promise<void> {
challenges: [validateChallenges],
fonts: [validateFonts],
themes: [validateThemes],
sounds: [validateSounds],
others: [
validateChallenges,
validateLayouts,
validateFonts,
validateThemes,
validateSounds,
],
};

Expand Down
91 changes: 91 additions & 0 deletions frontend/src/ts/constants/sounds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { PlaySoundOnClick } from "@monkeytype/schemas/configs";

export const soundsConfig: SoundConfigType = {
1: { numberOfSounds: 3 },
2: { numberOfSounds: 3 },
3: { numberOfSounds: 3 },
4: { numberOfSounds: 6, hasSecondVariant: true },
5: { numberOfSounds: 6, hasSecondVariant: true },
6: { numberOfSounds: 3, hasSecondVariant: true },
7: { numberOfSounds: 3, hasSecondVariant: true },
8: { oscillatorType: "sine" },
9: { oscillatorType: "sawtooth" },
10: { oscillatorType: "square" },
11: { oscillatorType: "triangle" },
12: { validNotes: ["C", "D", "E", "G", "A"] },
13: { validNotes: ["C", "D", "E", "Gb", "Ab", "Bb"] },
14: { numberOfSounds: 8 },
15: { numberOfSounds: 5 },
16: { numberOfSounds: 8 },
};

export type ClickSoundConfig = {
numberOfSounds: number;
hasSecondVariant?: true;
};

export type SupportedOscillatorTypes = Exclude<OscillatorType, "custom">;
export type OscillatorSoundConfig = {
oscillatorType: SupportedOscillatorTypes;
};

export type ScaleSoundConfig = {
validNotes: ValidNotes[];
};

export type SoundConfigType = Record<
Exclude<PlaySoundOnClick, "off">,
ClickSoundConfig | OscillatorSoundConfig | ScaleSoundConfig
>;

export type ValidNotes =
| "C"
| "Db"
| "D"
| "Eb"
| "E"
| "F"
| "Gb"
| "G"
| "Ab"
| "A"
| "Bb"
| "B";

type ClickSoundConfigType = Partial<
Record<
Exclude<PlaySoundOnClick, "off">,
{
sounds: string[];
counter: number;
}[]
>
>;

export const clickSoundConfig: ClickSoundConfigType =
extractClickSounds(soundsConfig);

function extractClickSounds(
shortConfig: SoundConfigType,
): ClickSoundConfigType {
return Object.fromEntries(
Object.entries(shortConfig)
.filter(([_, cfg]) => "numberOfSounds" in cfg)
.map(([key, cfg]) => {
const config = cfg as ClickSoundConfig;
const fullConfig = new Array(config.numberOfSounds)
.fill(0)
.map((_, index) => {
const sounds = config.hasSecondVariant
? [
`../sound/click${key}/click${key}_${index + 1}.wav`,
`../sound/click${key}/click${key}_${index + 1}_2.wav`,
]
: [`../sound/click${key}/click${key}_${index + 1}.wav`];

return { sounds, counter: 0 };
});
return [key, fullConfig];
}),
);
}
Loading
Loading