Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impr: allow multiple funboxes with css (@notTamion) #6017

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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: 0 additions & 1 deletion frontend/src/email-handler.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<!-- <link rel="stylesheet" href="css/fa.css" /> -->
<link rel="stylesheet" href="css/balloon.min.css" />
<link rel="stylesheet" href="themes/serika_dark.css" id="currentTheme" />
<link rel="stylesheet" href="" id="funBoxTheme" />
<link id="favicon" rel="shortcut icon" href="images/fav.png" />
<link rel="shortcut icon" href="images/fav.png" />
<link
Expand Down
1 change: 0 additions & 1 deletion frontend/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
defer
></script>
<link rel="stylesheet" href="/themes/serika_dark.css" id="currentTheme" />
<link rel="stylesheet" href="" id="funBoxTheme" />
<link rel="stylesheet" href="" id="globalFunBoxTheme" type="text/css" />
<script type="module" src="ts/index.ts"></script>
</body>
Expand Down
1 change: 0 additions & 1 deletion frontend/src/privacy-policy.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<!-- <link rel="stylesheet" href="css/fa.css" /> -->
<link rel="stylesheet" href="css/balloon.min.css" />
<link rel="stylesheet" href="themes/serika_dark.css" id="currentTheme" />
<link rel="stylesheet" href="" id="funBoxTheme" />
<link id="favicon" rel="shortcut icon" href="images/fav.png" />
<link rel="shortcut icon" href="images/fav.png" />
<link rel="stylesheet" href="styles/index.scss" />
Expand Down
1 change: 0 additions & 1 deletion frontend/src/security-policy.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<!-- <link rel="stylesheet" href="css/fa.css" /> -->
<link rel="stylesheet" href="css/balloon.min.css" />
<link rel="stylesheet" href="themes/serika_dark.css" id="currentTheme" />
<link rel="stylesheet" href="" id="funBoxTheme" />
<link id="favicon" rel="shortcut icon" href="images/fav.png" />
<link rel="shortcut icon" href="images/fav.png" />
<link rel="stylesheet" href="styles/index.scss" />
Expand Down
1 change: 0 additions & 1 deletion frontend/src/terms-of-service.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<!-- <link rel="stylesheet" href="css/fa.css" /> -->
<link rel="stylesheet" href="css/balloon.min.css" />
<link rel="stylesheet" href="themes/serika_dark.css" id="currentTheme" />
<link rel="stylesheet" href="" id="funBoxTheme" />
<link id="favicon" rel="shortcut icon" href="images/fav.png" />
<link rel="shortcut icon" href="images/fav.png" />
<link rel="stylesheet" href="styles/index.scss" />
Expand Down
29 changes: 10 additions & 19 deletions frontend/src/ts/test/funbox/funbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ export async function clear(): Promise<boolean> {
?.join(" ") ?? ""
);

$("#funBoxTheme").removeAttr("href");

$("#wordsWrapper").removeClass("hidden");
MemoryTimer.reset();
ManualRestart.set();
Expand Down Expand Up @@ -226,23 +224,16 @@ async function setFunboxBodyClasses(): Promise<boolean> {
}

async function applyFunboxCSS(): Promise<boolean> {
const $theme = $("#funBoxTheme");

//currently we only support one active funbox with hasCSS
const activeFunboxWithTheme = getActiveFunboxes().find((fb) =>
fb?.properties?.includes("hasCssFile")
);

const activeTheme =
activeFunboxWithTheme != null
? "funbox/" + activeFunboxWithTheme.name + ".css"
: "";

const currentTheme = ($theme.attr("href") ?? "") || null;

if (activeTheme != currentTheme) {
$theme.attr("href", activeTheme);
}
$(".funBoxTheme").map((_index, domElement) => domElement.remove());
getActiveFunboxes().forEach((funbox) => {
if (funbox.properties?.includes("hasCssFile")) {
const css = document.createElement("link");
css.classList.add("funBoxTheme");
css.rel = "stylesheet";
css.href = "funbox/" + funbox.name + ".css";
document.head.appendChild(css);
}
});

return true;
}
6 changes: 3 additions & 3 deletions frontend/static/funbox/choo_choo.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@keyframes woah {
@keyframes choochoo {
0% {
transform: rotateZ(0deg);
}
Expand All @@ -13,6 +13,6 @@
}

#words {
--correct-letter-animation: woah 2s infinite linear;
--untyped-letter-animation: woah 2s infinite linear;
--correct-letter-animation: choochoo 2s infinite linear;
--untyped-letter-animation: choochoo 2s infinite linear;
}
4 changes: 2 additions & 2 deletions frontend/static/funbox/nausea.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@keyframes woah {
@keyframes nausea {
0% {
transform: rotateY(-15deg) skewY(10deg) rotateX(-15deg) scaleX(1.2)
scaleY(0.9);
Expand All @@ -25,7 +25,7 @@
}

#typingTest {
animation: woah 7s infinite cubic-bezier(0.5, 0, 0.5, 1);
animation: nausea 7s infinite cubic-bezier(0.5, 0, 0.5, 1);
}

header {
Expand Down
8 changes: 8 additions & 0 deletions packages/funbox/src/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,23 @@ const list: Record<FunboxName, FunboxMetadata> = {
properties: ["hasCssFile"],
canGetPb: true,
difficultyLevel: 3,
cssModification: ["main"],
},
upside_down: {
name: "upside_down",
description: "Everything is upside down!",
properties: ["hasCssFile"],
canGetPb: true,
difficultyLevel: 3,
cssModification: ["main"],
},
nausea: {
name: "nausea",
description: "I think I'm gonna be sick.",
canGetPb: true,
difficultyLevel: 2,
properties: ["hasCssFile"],
cssModification: ["typingTest"],
},
round_round_baby: {
name: "round_round_baby",
Expand All @@ -46,6 +49,7 @@ const list: Record<FunboxName, FunboxMetadata> = {
canGetPb: true,
difficultyLevel: 3,
properties: ["hasCssFile"],
cssModification: ["typingTest"],
},
simon_says: {
name: "simon_says",
Expand All @@ -69,6 +73,7 @@ const list: Record<FunboxName, FunboxMetadata> = {
frontendFunctions: ["applyConfig", "rememberSettings", "toggleScript"],
name: "tts",
description: "Listen closely.",
cssModification: ["words"],
},
choo_choo: {
canGetPb: true,
Expand Down Expand Up @@ -140,13 +145,15 @@ const list: Record<FunboxName, FunboxMetadata> = {
difficultyLevel: 1,
properties: ["hasCssFile", "noLigatures"],
name: "earthquake",
cssModification: ["words"],
},
space_balls: {
description: "In a galaxy far far away.",
canGetPb: true,
difficultyLevel: 0,
properties: ["hasCssFile"],
name: "space_balls",
cssModification: ["body"],
},
gibberish: {
description: "Anvbuefl dizzs eoos alsb?",
Expand Down Expand Up @@ -376,6 +383,7 @@ const list: Record<FunboxName, FunboxMetadata> = {
properties: ["hasCssFile", "noLigatures"],
frontendFunctions: ["applyGlobalCSS", "clearGlobal"],
name: "crt",
cssModification: ["body"],
},
backwards: {
description: "...sdrawkcab epyt ot yrt woN",
Expand Down
3 changes: 3 additions & 0 deletions packages/funbox/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export type FunboxProperty =
| `toPush:${number}`
| "wordOrder:reverse";

type FunboxCSSModifications = "typingTest" | "words" | "body" | "main";

export type FunboxMetadata = {
name: FunboxName;
alias?: string;
Expand All @@ -71,4 +73,5 @@ export type FunboxMetadata = {
frontendFunctions?: string[];
difficultyLevel: number;
canGetPb: boolean;
cssModification?: FunboxCSSModifications[];
};
25 changes: 20 additions & 5 deletions packages/funbox/src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ export function checkCompatibility(
(f.properties?.find((fp) => fp.startsWith("toPush:")) ?? "") ||
f.frontendFunctions?.includes("pullSection")
).length <= 1;
const oneCssFileMax =
funboxesToCheck.filter((f) =>
f.properties?.find((fp) => fp === "hasCssFile")
).length <= 1;
const onePunctuateWordMax =
funboxesToCheck.filter((f) =>
f.frontendFunctions?.includes("punctuateWord")
Expand All @@ -106,6 +102,22 @@ export function checkCompatibility(
funboxesToCheck.filter((f) =>
f.properties?.find((fp) => fp === "changesCapitalisation")
).length <= 1;
const oneChangesTypingTestCSS =
funboxesToCheck.filter((f) =>
f.cssModification?.find((fc) => fc === "typingTest")
).length <= 1;
const oneChangesWordsCSS =
funboxesToCheck.filter((f) =>
f.cssModification?.find((fc) => fc === "words")
).length <= 1;
const oneChangesBodyCSS =
funboxesToCheck.filter((f) =>
f.cssModification?.find((fc) => fc === "body")
).length <= 1;
const oneChangesMainCSS =
funboxesToCheck.filter((f) =>
f.cssModification?.find((fc) => fc === "main")
).length <= 1;
const allowedConfig = {} as FunboxForcedConfig;
let noConfigConflicts = true;
for (const f of funboxesToCheck) {
Expand Down Expand Up @@ -143,11 +155,14 @@ export function checkCompatibility(
oneCanSpeakMax &&
hasLanguageToSpeakAndNoUnspeakable &&
oneToPushOrPullSectionMax &&
oneCssFileMax &&
onePunctuateWordMax &&
oneCharCheckerMax &&
oneCharReplacerMax &&
oneChangesCapitalisationMax &&
oneChangesTypingTestCSS &&
oneChangesWordsCSS &&
oneChangesBodyCSS &&
oneChangesMainCSS &&
noConfigConflicts &&
oneWordOrderMax
);
Expand Down
Loading