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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
16 changes: 13 additions & 3 deletions frontend/src/ts/test/funbox/funbox-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ const list: FunboxMetadata[] = [
{
name: "nausea",
info: "I think I'm gonna be sick.",
properties: ["movesText", "rotatesText"],
hasCSS: true,
},
{
name: "round_round_baby",
info: "...right round, like a record baby. Right, round round round.",
properties: ["movesText", "changesTextOrientation"],
hasCSS: true,
},
{
Expand All @@ -23,11 +25,13 @@ const list: FunboxMetadata[] = [
{
name: "mirror",
info: "Everything is mirrored!",
properties: ["mirror"],
hasCSS: true,
},
{
name: "upside_down",
info: "Everything is upside down!",
properties: ["changesTextOrientation", "conflictsWithMirror"],
hasCSS: true,
},
{
Expand All @@ -42,7 +46,12 @@ const list: FunboxMetadata[] = [
{
name: "choo_choo",
info: "All the letters are spinning!",
properties: ["noLigatures", "conflictsWithSymmetricChars"],
properties: [
"noLigatures",
"conflictsWithSymmetricChars",
"rotatesText",
"movesCharacters",
],
hasCSS: true,
},
{
Expand Down Expand Up @@ -79,12 +88,13 @@ const list: FunboxMetadata[] = [
{
name: "earthquake",
info: "Everybody get down! The words are shaking!",
properties: ["noLigatures"],
properties: ["noLigatures", "movesCharacters"],
hasCSS: true,
},
{
name: "space_balls",
info: "In a galaxy far far away.",
properties: ["changesBackground"],
hasCSS: true,
},
{
Expand Down Expand Up @@ -259,7 +269,7 @@ const list: FunboxMetadata[] = [
{
name: "crt",
info: "Go back to the 1980s",
properties: ["noLigatures"],
properties: ["noLigatures", "changesBackground"],
},
{
name: "backwards",
Expand Down
35 changes: 32 additions & 3 deletions frontend/src/ts/test/funbox/funbox-validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,6 @@ export function areFunboxesCompatible(
(f.properties?.find((fp) => fp.startsWith("toPush:")) ?? "") ||
f.functions?.pullSection
).length <= 1;
const oneApplyCSSMax =
funboxesToCheck.filter((f) => f.hasCSS == true).length <= 1;
const onePunctuateWordMax =
funboxesToCheck.filter((f) => f.functions?.punctuateWord).length <= 1;
const oneCharCheckerMax =
Expand All @@ -300,6 +298,32 @@ export function areFunboxesCompatible(
funboxesToCheck.filter((f) =>
f.properties?.find((fp) => fp === "changesCapitalisation")
).length <= 1;
const oneMovesText =
funboxesToCheck.filter((f) =>
f.properties?.find((fp) => fp === "movesText")
).length <= 1;
const oneMovesCharacters =
funboxesToCheck.filter((f) =>
f.properties?.find((fp) => fp === "movesCharacters")
).length <= 1;
const oneRotatesText =
funboxesToCheck.filter((f) =>
f.properties?.find((fp) => fp === "rotatesText")
).length <= 1;
const oneChangesTextOrientation =
funboxesToCheck.filter((f) =>
f.properties?.find((fp) => fp === "changesTextOrientation")
).length <= 1;
const oneChangesBackground =
funboxesToCheck.filter((f) =>
f.properties?.find((fp) => fp === "changesBackground")
).length <= 1;
const noConflictsWithMirror =
funboxesToCheck.filter((f) =>
f.properties?.find((fp) => fp === "conflictsWithMirror")
).length === 0 ||
funboxesToCheck.filter((f) => f.properties?.find((fp) => fp === "mirror"))
.length === 0;
const allowedConfig = {} as FunboxForcedConfig;
let noConfigConflicts = true;
for (const f of funboxesToCheck) {
Expand Down Expand Up @@ -335,11 +359,16 @@ export function areFunboxesCompatible(
oneCanSpeakMax &&
hasLanguageToSpeakAndNoUnspeakable &&
oneToPushOrPullSectionMax &&
oneApplyCSSMax &&
onePunctuateWordMax &&
oneCharCheckerMax &&
oneCharReplacerMax &&
oneChangesCapitalisationMax &&
oneMovesText &&
oneMovesCharacters &&
oneRotatesText &&
oneChangesTextOrientation &&
oneChangesBackground &&
noConflictsWithMirror &&
noConfigConflicts
);
}
28 changes: 10 additions & 18 deletions frontend/src/ts/test/funbox/funbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,6 @@ export async function clear(): Promise<boolean> {
?.join(" ") ?? ""
);

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

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

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

$(".funBoxTheme").map((_index, domElement) => domElement.remove());
//currently we only support one active funbox with hasCSS
const activeFunboxWithTheme = FunboxList.get(Config.funbox).find(
(it) => it.hasCSS == true
);

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

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

if (activeTheme != currentTheme) {
$theme.attr("href", activeTheme);
}
FunboxList.get(Config.funbox).forEach((funbox) => {
if (funbox.hasCSS) {
const css = document.createElement("link");
css.classList.add("funBoxTheme");
css.rel = "stylesheet";
css.href = "funbox/" + funbox.name + ".css";
document.head.appendChild(css);
}
});

return true;
}
9 changes: 8 additions & 1 deletion frontend/src/ts/utils/json-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,14 @@ type FunboxProperty =
| `toPush:${number}`
| "noInfiniteDuration"
| "changesWordsFrequency"
| `wordOrder:${FunboxWordOrder}`;
| `wordOrder:${FunboxWordOrder}`
| "movesText"
| "movesCharacters"
| "rotatesText"
| "changesTextOrientation"
| "mirror"
| "conflictsWithMirror"
| "changesBackground";

export type FunboxForcedConfig = Record<string, ConfigValue[]>;

Expand Down
Loading