From f1e00f6cdb92375d7ce3cde1c7ab44ebdb2d6513 Mon Sep 17 00:00:00 2001 From: Alexandru Chirila <1538458+alexkiro@users.noreply.github.com> Date: Wed, 13 Mar 2024 22:28:26 +0200 Subject: [PATCH] Move things around in the UI and add animations --- .eslintrc.cjs | 4 +- src/App.vue | 16 ++- src/assets/main.css | 75 +++++----- src/components/FoundWordList.vue | 67 +++++++++ src/components/GamePlay.vue | 232 +++++++++++++++++-------------- src/lib/animations.ts | 62 +++++++++ tsconfig.app.json | 2 +- tsconfig.node.json | 3 +- 8 files changed, 306 insertions(+), 155 deletions(-) create mode 100644 src/components/FoundWordList.vue create mode 100644 src/lib/animations.ts diff --git a/.eslintrc.cjs b/.eslintrc.cjs index be4f9b0..6d16344 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -31,6 +31,8 @@ module.exports = { "func-style": "off", // Exclude some commonly used iterators "id-length": ["error", { exceptions: ["i", "j", "k"] }], + // Disable max-params + "max-params": "off", // Disable max-statements "max-statements": "off", // Enforce separate lines for multiline comments @@ -39,9 +41,9 @@ module.exports = { "no-continue": "off", // Allow magic numbers "no-magic-numbers": "off", + // Disable no-shadow because of upstream bug // Allow negated conditions "no-negated-condition": "off", - // Disable no-shadow because of upstream bug // https://github.com/typescript-eslint/tslint-to-eslint-config/issues/856 "no-shadow": "off", // Force separate var declaration diff --git a/src/App.vue b/src/App.vue index 10b4569..eb9c73c 100644 --- a/src/App.vue +++ b/src/App.vue @@ -10,15 +10,15 @@ const enum GameModes { // multiPlayer, } -const selectedGameMode: Ref = ref(GameModes.singlePlayer); +const selectedGameMode: Ref = ref(GameModes.notSet); diff --git a/src/assets/main.css b/src/assets/main.css index ad268be..c9b12f8 100644 --- a/src/assets/main.css +++ b/src/assets/main.css @@ -25,14 +25,6 @@ --btn-primary-bg: var(--peach); } -html { - box-sizing: border-box; - color: var(--font-color); - font-family: "Reem Kufi", sans-serif; - letter-spacing: 0.1em; - word-spacing: 0.5em; -} - *, *::before, *::after { @@ -43,50 +35,47 @@ a { text-decoration: none; } -#app { - background-color: var(--background-color); - /*noinspection CssOverwrittenProperties*/ - min-height: 100vh; - /*noinspection CssOverwrittenProperties*/ - min-height: 100dvh; - - display: flex; - flex-direction: column; - align-items: center; - justify-items: center; -} - -header { - font-size: 2.5rem; +button { + cursor: pointer; text-transform: uppercase; font-weight: bold; - text-align: center; - padding: 2rem; + line-height: 1; } -main { - max-width: 768px; - padding: 1rem; - flex: 1; - - display: flex; - flex-direction: column; - align-items: center; - justify-items: center; +html { + box-sizing: border-box; + color: var(--font-color); + font-family: "Reem Kufi", sans-serif; + letter-spacing: 0.1em; + word-spacing: 0.5em; } -.btn { - display: flex; +body { + background-color: var(--background-color); +} - color: var(--btn-primary-fg); - background-color: var(--btn-primary-bg); +.brutal-border { border: 4px solid var(--border-color); border-radius: 8px; - padding: 1rem 2.5rem; - box-shadow: 2px 4px #000; +} - text-transform: uppercase; - font-weight: bold; - font-size: 1.5rem; +.bg-white { + background-color: white; +} + +.bg-peach { + background-color: var(--dark-peach); +} + +.bg-dark-peach { + background-color: var(--peach); +} + +.bg-ocean { + background-color: var(--dark-ocean); +} + +.bg-dark-ocean { + background-color: var(--ocean); } diff --git a/src/components/FoundWordList.vue b/src/components/FoundWordList.vue new file mode 100644 index 0000000..7f067ff --- /dev/null +++ b/src/components/FoundWordList.vue @@ -0,0 +1,67 @@ + + + + + diff --git a/src/components/GamePlay.vue b/src/components/GamePlay.vue index f316892..e408fb7 100644 --- a/src/components/GamePlay.vue +++ b/src/components/GamePlay.vue @@ -1,8 +1,45 @@ + + - - diff --git a/src/lib/animations.ts b/src/lib/animations.ts new file mode 100644 index 0000000..24d920a --- /dev/null +++ b/src/lib/animations.ts @@ -0,0 +1,62 @@ +function animate(thing: Element | null | string, colorName: string, keyframes: any[], animationOptions: any) { + let el = null; + if (typeof thing === "string") { + el = document.querySelector(thing); + } else { + el = thing as Element; + } + + if (!el) return; + const color = `var(--${colorName})`; + const borderColor = color; + + el.scrollIntoView({ behavior: "smooth", block: "center" }); + el.animate( + keyframes.map((keyframe) => { + return { + borderColor, + color, + ...keyframe, + }; + }), + animationOptions, + ); +} + +export function animateShake(thing: Element | string, colorName: string, options?: any) { + animate( + thing, + colorName, + [ + { offset: 0, transform: "translate(0px)" }, + { offset: 0.25, transform: "translate(5px)" }, + { offset: 0.5, transform: "translate(-5px)" }, + { offset: 0.75, transform: "translate(5px)" }, + { offset: 1, transform: "translate(0px)" }, + ], + { + duration: 150, + iterations: 2, + ...options, + }, + ); +} + +export function animateWiggle(thing: Element | string, colorName: string, options?: any) { + animate( + thing, + colorName, + [ + { offset: 0, transform: "rotate(0deg)" }, + { offset: 0.25, transform: "rotate(5deg) scale(1.1)" }, + { offset: 0.5, transform: "rotate(0deg) scale(1.1)" }, + { offset: 0.75, transform: "rotate(-5deg) scale(1.1)" }, + { offset: 1, transform: "rotate(0deg)" }, + ], + { + duration: 250, + iterations: 2, + ...options, + }, + ); +} diff --git a/tsconfig.app.json b/tsconfig.app.json index cf5e662..85ee9e2 100644 --- a/tsconfig.app.json +++ b/tsconfig.app.json @@ -1,6 +1,6 @@ { "extends": "@vue/tsconfig/tsconfig.dom.json", - "include": ["env.d.ts", "src/**/*", "src/**/*.vue"], + "include": ["env.d.ts", "src/**/*", "src/**/*.vue", "src/lib/*"], "exclude": ["src/**/__tests__/*", "src/scripts"], "compilerOptions": { "composite": true, diff --git a/tsconfig.node.json b/tsconfig.node.json index 1e7a561..0842716 100644 --- a/tsconfig.node.json +++ b/tsconfig.node.json @@ -6,8 +6,7 @@ "cypress.config.*", "nightwatch.conf.*", "playwright.config.*", - "src/scripts/**/*", - "src/lib/**/*" + "src/scripts/**/*" ], "compilerOptions": { "composite": true,