Skip to content

Commit 268cd2e

Browse files
committed
feat(funbox): add tunnel vision effect (@d1rshan)
1 parent a8875f8 commit 268cd2e

6 files changed

Lines changed: 91 additions & 0 deletions

File tree

frontend/__tests__/test/funbox/funbox-validation.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ describe("funbox-validation", () => {
2424
"nospace", //nospace
2525
"plus_one", //toPush:
2626
"read_ahead_easy", //changesWordVisibility
27+
"tunnel_vision", //changesWordVisibility
2728
"tts", //speaks
2829
"layout_mirror", //changesLayout
2930
"zipf", //changesWordsFrequency

frontend/src/ts/test/funbox/funbox-functions.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ export class PolyglotWordset extends Wordset {
166166
}
167167
}
168168

169+
let tunnelVisionAnimationFrame: number | null = null;
170+
169171
const list: Partial<Record<FunboxName, FunboxFunctions>> = {
170172
"58008": {
171173
getWord(): string {
@@ -679,6 +681,49 @@ const list: Partial<Record<FunboxName, FunboxFunctions>> = {
679681
return word.toUpperCase();
680682
},
681683
},
684+
tunnel_vision: {
685+
applyGlobalCSS(): void {
686+
const words = qs("#words");
687+
if (!words) return;
688+
689+
const updateCaretPos = (): void => {
690+
const caretElem = qs("#caret");
691+
if (caretElem !== null) {
692+
const caretStyle = caretElem.getStyle();
693+
const left = caretStyle.left || "0px";
694+
const top = caretStyle.top || "0px";
695+
const marginLeft = caretStyle.marginLeft || "0px";
696+
const marginTop = caretStyle.marginTop || "0px";
697+
698+
words.native.style.setProperty(
699+
"--caret-left",
700+
`calc(${left} + ${marginLeft})`,
701+
);
702+
words.native.style.setProperty(
703+
"--caret-top",
704+
`calc(${top} + ${marginTop})`,
705+
);
706+
}
707+
tunnelVisionAnimationFrame = requestAnimationFrame(updateCaretPos);
708+
};
709+
710+
if (tunnelVisionAnimationFrame !== null) {
711+
cancelAnimationFrame(tunnelVisionAnimationFrame);
712+
}
713+
updateCaretPos();
714+
},
715+
clearGlobal(): void {
716+
if (tunnelVisionAnimationFrame !== null) {
717+
cancelAnimationFrame(tunnelVisionAnimationFrame);
718+
tunnelVisionAnimationFrame = null;
719+
}
720+
const words = qs("#words");
721+
if (words) {
722+
words.native.style.removeProperty("--caret-left");
723+
words.native.style.removeProperty("--caret-top");
724+
}
725+
},
726+
},
682727
polyglot: {
683728
async withWords(_words) {
684729
const promises = Config.customPolyglot.map(async (language) =>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#words {
2+
mask-image: radial-gradient(
3+
circle 150px at var(--caret-left) var(--caret-top),
4+
black 0%,
5+
black 50%,
6+
transparent 100%
7+
);
8+
-webkit-mask-image: radial-gradient(
9+
circle 150px at var(--caret-left) var(--caret-top),
10+
black 0%,
11+
black 50%,
12+
transparent 100%
13+
);
14+
mask-repeat: no-repeat;
15+
-webkit-mask-repeat: no-repeat;
16+
}

packages/funbox/__test__/validation.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,26 @@ describe("validation", () => {
115115
true,
116116
);
117117
});
118+
119+
it("should reject multiple word visibility funboxes", () => {
120+
//GIVEN
121+
getFunboxMock.mockReturnValueOnce([
122+
{
123+
name: "plus_one",
124+
properties: ["changesWordsVisibility"],
125+
} as FunboxMetadata,
126+
{
127+
name: "tunnel_vision",
128+
properties: ["changesWordsVisibility"],
129+
} as FunboxMetadata,
130+
]);
131+
132+
//WHEN / THEN
133+
expect(Validation.checkCompatibility(["plus_one", "tunnel_vision"])).toBe(
134+
false,
135+
);
136+
});
137+
118138
describe("should validate two funboxes modifying the wordset", () => {
119139
const testCases = [
120140
{

packages/funbox/src/list.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,14 @@ const list: Record<FunboxName, FunboxMetadata> = {
481481
difficultyLevel: 0,
482482
name: "no_quit",
483483
},
484+
tunnel_vision: {
485+
name: "tunnel_vision",
486+
description: "Only the area around the caret is visible.",
487+
canGetPb: true,
488+
difficultyLevel: 2,
489+
properties: ["hasCssFile", "changesWordsVisibility"],
490+
frontendFunctions: ["applyGlobalCSS", "clearGlobal"],
491+
},
484492
};
485493

486494
export function getObject(): Record<FunboxName, FunboxMetadata> {

packages/schemas/src/configs.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ export const FunboxNameSchema = z.enum([
321321
"asl",
322322
"rot13",
323323
"no_quit",
324+
"tunnel_vision",
324325
]);
325326
export type FunboxName = z.infer<typeof FunboxNameSchema>;
326327

0 commit comments

Comments
 (0)