Site/Game for Harvest Hackathon Haunted House.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

:recycle: Refractor out code to something a bit cleaner.

+170 -42
+3 -1
package.json
··· 33 33 "@sveltejs/adapter-vercel": "^3.0.3", 34 34 "@upstash/redis": "^1.24.1", 35 35 "@vercel/analytics": "^1.1.1", 36 + "dotenv": "^16.3.1", 36 37 "firebase": "^10.5.2", 37 38 "open-props": "^1.6.10", 38 39 "partysocket": "0.0.12", 39 - "svelte-preprocess": "^5.0.4" 40 + "svelte-preprocess": "^5.0.4", 41 + "ts-node": "^10.9.1" 40 42 } 41 43 }
+97 -13
pnpm-lock.yaml
··· 14 14 '@vercel/analytics': 15 15 specifier: ^1.1.1 16 16 version: 1.1.1 17 + dotenv: 18 + specifier: ^16.3.1 19 + version: 16.3.1 17 20 firebase: 18 21 specifier: ^10.5.2 19 22 version: 10.5.2 ··· 26 29 svelte-preprocess: 27 30 specifier: ^5.0.4 28 31 version: 5.0.4(postcss@8.4.31)(svelte@4.0.5)(typescript@5.0.2) 32 + ts-node: 33 + specifier: ^10.9.1 34 + version: 10.9.1(@types/node@20.8.9)(typescript@5.0.2) 29 35 30 36 devDependencies: 31 37 '@sveltejs/adapter-auto': ··· 48 54 version: 8.5.0(eslint@8.28.0) 49 55 eslint-plugin-svelte: 50 56 specifier: ^2.30.0 51 - version: 2.30.0(eslint@8.28.0)(svelte@4.0.5) 57 + version: 2.30.0(eslint@8.28.0)(svelte@4.0.5)(ts-node@10.9.1) 52 58 partykit: 53 59 specifier: 0.0.32 54 60 version: 0.0.32 ··· 72 78 version: 5.0.2 73 79 vite: 74 80 specifier: ^4.4.2 75 - version: 4.4.2 81 + version: 4.4.2(@types/node@20.8.9) 76 82 77 83 packages: 78 84 ··· 204 210 /@cloudflare/workers-types@4.20231016.0: 205 211 resolution: {integrity: sha512-eGB0cRVyoJpeyGJx2re5sbd9R316a61sY73xwnqm4cwGpb+OxCK2gc651RxGiN7H4w6LY1RpysUgeGLmj5B3+g==} 206 212 dev: true 213 + 214 + /@cspotcode/source-map-support@0.8.1: 215 + resolution: {integrity: sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==} 216 + engines: {node: '>=12'} 217 + dependencies: 218 + '@jridgewell/trace-mapping': 0.3.9 207 219 208 220 /@esbuild/android-arm64@0.18.20: 209 221 resolution: {integrity: sha512-Nz4rJcchGDtENV0eMKUNa6L12zz2zBDXuhj/Vjh18zGqB44Bi7MBMSXjgunJgjRhCmKOjnPuZp4Mb6OKqtMHLQ==} ··· 1129 1141 '@jridgewell/resolve-uri': 3.1.1 1130 1142 '@jridgewell/sourcemap-codec': 1.4.15 1131 1143 1144 + /@jridgewell/trace-mapping@0.3.9: 1145 + resolution: {integrity: sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==} 1146 + dependencies: 1147 + '@jridgewell/resolve-uri': 3.1.1 1148 + '@jridgewell/sourcemap-codec': 1.4.15 1149 + 1132 1150 /@mapbox/node-pre-gyp@1.0.11: 1133 1151 resolution: {integrity: sha512-Yhlar6v9WQgUp/He7BdgzOz8lqMQ8sU+jkCq7Wx8Myc5YFJLbEe7lgui/V7G1qB1DJykHSGwreceSaD60Y0PUQ==} 1134 1152 hasBin: true ··· 1266 1284 sirv: 2.0.3 1267 1285 svelte: 4.0.5 1268 1286 undici: 5.22.1 1269 - vite: 4.4.2 1287 + vite: 4.4.2(@types/node@20.8.9) 1270 1288 transitivePeerDependencies: 1271 1289 - supports-color 1272 1290 ··· 1281 1299 '@sveltejs/vite-plugin-svelte': 2.4.6(svelte@4.0.5)(vite@4.4.2) 1282 1300 debug: 4.3.4 1283 1301 svelte: 4.0.5 1284 - vite: 4.4.2 1302 + vite: 4.4.2(@types/node@20.8.9) 1285 1303 transitivePeerDependencies: 1286 1304 - supports-color 1287 1305 ··· 1299 1317 magic-string: 0.30.5 1300 1318 svelte: 4.0.5 1301 1319 svelte-hmr: 0.15.3(svelte@4.0.5) 1302 - vite: 4.4.2 1320 + vite: 4.4.2(@types/node@20.8.9) 1303 1321 vitefu: 0.2.5(vite@4.4.2) 1304 1322 transitivePeerDependencies: 1305 1323 - supports-color 1306 1324 1325 + /@tsconfig/node10@1.0.9: 1326 + resolution: {integrity: sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==} 1327 + 1328 + /@tsconfig/node12@1.0.11: 1329 + resolution: {integrity: sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==} 1330 + 1331 + /@tsconfig/node14@1.0.3: 1332 + resolution: {integrity: sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==} 1333 + 1334 + /@tsconfig/node16@1.0.4: 1335 + resolution: {integrity: sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==} 1336 + 1307 1337 /@types/cookie@0.5.3: 1308 1338 resolution: {integrity: sha512-SLg07AS9z1Ab2LU+QxzU8RCmzsja80ywjf/t5oqw+4NSH20gIGlhLOrBDm1L3PBWzPa4+wkgFQVZAjE6Ioj2ug==} 1309 1339 ··· 1318 1348 resolution: {integrity: sha512-UzykFsT3FhHb1h7yD4CA4YhBHq545JC0YnEz41xkipN88eKQtL6rSgocL5tbAP6Ola9Izm/Aw4Ora8He4x0BHg==} 1319 1349 dependencies: 1320 1350 undici-types: 5.26.5 1321 - dev: false 1322 1351 1323 1352 /@types/pug@2.0.8: 1324 1353 resolution: {integrity: sha512-QzhsZ1dMGyJbn/D9V80zp4GIA4J4rfAjCCxc3MP+new0E8dyVdSkR735Lx+n3LIaHNFcjHL5+TbziccuT+fdoQ==} ··· 1514 1543 /acorn-walk@8.3.0: 1515 1544 resolution: {integrity: sha512-FS7hV565M5l1R08MXqo8odwMTB02C2UqzB17RVgu9EyuYFBqJZ3/ZY97sQD5FewVu1UyDFc1yztUDrAwT0EypA==} 1516 1545 engines: {node: '>=0.4.0'} 1517 - dev: true 1518 1546 1519 1547 /acorn@8.11.2: 1520 1548 resolution: {integrity: sha512-nc0Axzp/0FILLEVsm4fNwLCwMttvhEI263QtVPQcbpfZZ3ts0hLsZGOpE6czNlid7CJ9MlyH8reXkpsf3YUY4w==} ··· 1572 1600 delegates: 1.0.0 1573 1601 readable-stream: 3.6.2 1574 1602 dev: false 1603 + 1604 + /arg@4.1.3: 1605 + resolution: {integrity: sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==} 1575 1606 1576 1607 /argparse@2.0.1: 1577 1608 resolution: {integrity: sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==} ··· 1735 1766 resolution: {integrity: sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==} 1736 1767 engines: {node: '>= 0.6'} 1737 1768 1769 + /create-require@1.1.1: 1770 + resolution: {integrity: sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==} 1771 + 1738 1772 /cross-spawn@7.0.3: 1739 1773 resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==} 1740 1774 engines: {node: '>= 8'} ··· 1798 1832 /devalue@4.3.2: 1799 1833 resolution: {integrity: sha512-KqFl6pOgOW+Y6wJgu80rHpo2/3H07vr8ntR9rkkFIRETewbf5GaYYcakYfiKz89K+sLsuPkQIZaXDMjUObZwWg==} 1800 1834 1835 + /diff@4.0.2: 1836 + resolution: {integrity: sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==} 1837 + engines: {node: '>=0.3.1'} 1838 + 1801 1839 /dir-glob@3.0.1: 1802 1840 resolution: {integrity: sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==} 1803 1841 engines: {node: '>=8'} ··· 1812 1850 esutils: 2.0.3 1813 1851 dev: true 1814 1852 1853 + /dotenv@16.3.1: 1854 + resolution: {integrity: sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==} 1855 + engines: {node: '>=12'} 1856 + dev: false 1857 + 1815 1858 /emoji-regex@8.0.0: 1816 1859 resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==} 1817 1860 dev: false ··· 1897 1940 eslint: 8.28.0 1898 1941 dev: true 1899 1942 1900 - /eslint-plugin-svelte@2.30.0(eslint@8.28.0)(svelte@4.0.5): 1943 + /eslint-plugin-svelte@2.30.0(eslint@8.28.0)(svelte@4.0.5)(ts-node@10.9.1): 1901 1944 resolution: {integrity: sha512-2/qj0BJsfM0U2j4EjGb7iC/0nbUvXx1Gn78CdtyuXpi/rSomLPCPwnsZsloXMzlt6Xwe8LBlpRvZObSKEHLP5A==} 1902 1945 engines: {node: ^14.17.0 || >=16.0.0} 1903 1946 peerDependencies: ··· 1914 1957 esutils: 2.0.3 1915 1958 known-css-properties: 0.27.0 1916 1959 postcss: 8.4.31 1917 - postcss-load-config: 3.1.4(postcss@8.4.31) 1960 + postcss-load-config: 3.1.4(postcss@8.4.31)(ts-node@10.9.1) 1918 1961 postcss-safe-parser: 6.0.0(postcss@8.4.31) 1919 1962 svelte: 4.0.5 1920 1963 svelte-eslint-parser: 0.30.0(svelte@4.0.5) ··· 2521 2564 semver: 6.3.1 2522 2565 dev: false 2523 2566 2567 + /make-error@1.3.6: 2568 + resolution: {integrity: sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==} 2569 + 2524 2570 /mdn-data@2.0.30: 2525 2571 resolution: {integrity: sha512-GaqWWShW4kv/G9IEucWScBx9G1/vsFZZJUO+tD26M8J8z3Kw5RDQjaoZe03YAClgeS/SWPOcb4nkFBTEi5DUEA==} 2526 2572 ··· 2829 2875 resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==} 2830 2876 engines: {node: '>=8.6'} 2831 2877 2832 - /postcss-load-config@3.1.4(postcss@8.4.31): 2878 + /postcss-load-config@3.1.4(postcss@8.4.31)(ts-node@10.9.1): 2833 2879 resolution: {integrity: sha512-6DiM4E7v4coTE4uzA8U//WhtPwyhiim3eyjEMFCnUpzbrkK9wJHgKDT2mR+HbtSrd/NubVaYTOpSpjUl8NQeRg==} 2834 2880 engines: {node: '>= 10'} 2835 2881 peerDependencies: ··· 2843 2889 dependencies: 2844 2890 lilconfig: 2.1.0 2845 2891 postcss: 8.4.31 2892 + ts-node: 10.9.1(@types/node@20.8.9)(typescript@5.0.2) 2846 2893 yaml: 1.10.2 2847 2894 dev: true 2848 2895 ··· 3344 3391 typescript: 5.0.2 3345 3392 dev: true 3346 3393 3394 + /ts-node@10.9.1(@types/node@20.8.9)(typescript@5.0.2): 3395 + resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==} 3396 + hasBin: true 3397 + peerDependencies: 3398 + '@swc/core': '>=1.2.50' 3399 + '@swc/wasm': '>=1.2.50' 3400 + '@types/node': '*' 3401 + typescript: '>=2.7' 3402 + peerDependenciesMeta: 3403 + '@swc/core': 3404 + optional: true 3405 + '@swc/wasm': 3406 + optional: true 3407 + dependencies: 3408 + '@cspotcode/source-map-support': 0.8.1 3409 + '@tsconfig/node10': 1.0.9 3410 + '@tsconfig/node12': 1.0.11 3411 + '@tsconfig/node14': 1.0.3 3412 + '@tsconfig/node16': 1.0.4 3413 + '@types/node': 20.8.9 3414 + acorn: 8.11.2 3415 + acorn-walk: 8.3.0 3416 + arg: 4.1.3 3417 + create-require: 1.1.1 3418 + diff: 4.0.2 3419 + make-error: 1.3.6 3420 + typescript: 5.0.2 3421 + v8-compile-cache-lib: 3.0.1 3422 + yn: 3.1.1 3423 + 3347 3424 /tslib@2.4.1: 3348 3425 resolution: {integrity: sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==} 3349 3426 ··· 3372 3449 3373 3450 /undici-types@5.26.5: 3374 3451 resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==} 3375 - dev: false 3376 3452 3377 3453 /undici@5.22.1: 3378 3454 resolution: {integrity: sha512-Ji2IJhFXZY0x/0tVBXeQwgPlLWw13GVzpsWPQ3rV50IFMMof2I55PZZxtm4P6iNq+L5znYN9nSTAq0ZyE6lSJw==} ··· 3390 3466 resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==} 3391 3467 dev: false 3392 3468 3393 - /vite@4.4.2: 3469 + /v8-compile-cache-lib@3.0.1: 3470 + resolution: {integrity: sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==} 3471 + 3472 + /vite@4.4.2(@types/node@20.8.9): 3394 3473 resolution: {integrity: sha512-zUcsJN+UvdSyHhYa277UHhiJ3iq4hUBwHavOpsNUGsTgjBeoBlK8eDt+iT09pBq0h9/knhG/SPrZiM7cGmg7NA==} 3395 3474 engines: {node: ^14.18.0 || >=16.0.0} 3396 3475 hasBin: true ··· 3418 3497 terser: 3419 3498 optional: true 3420 3499 dependencies: 3500 + '@types/node': 20.8.9 3421 3501 esbuild: 0.18.20 3422 3502 postcss: 8.4.31 3423 3503 rollup: 3.29.4 ··· 3432 3512 vite: 3433 3513 optional: true 3434 3514 dependencies: 3435 - vite: 4.4.2 3515 + vite: 4.4.2(@types/node@20.8.9) 3436 3516 3437 3517 /webidl-conversions@3.0.1: 3438 3518 resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==} ··· 3541 3621 y18n: 5.0.8 3542 3622 yargs-parser: 21.1.1 3543 3623 dev: false 3624 + 3625 + /yn@3.1.1: 3626 + resolution: {integrity: sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==} 3627 + engines: {node: '>=6'} 3544 3628 3545 3629 /yocto-queue@0.1.0: 3546 3630 resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==}
+15 -1
sample.env
··· 1 + # Private 2 + 1 3 UPSTASH_REDIS_REST_URL="FILL ME IN" 2 - UPSTASH_REDIS_REST_TOKEN="FILL ME IN" 4 + UPSTASH_REDIS_REST_TOKEN="FILL ME IN" 5 + 6 + # Firebase 7 + FIREBASE_DATABASE_URL="" 8 + FIREBASE_PEOJECT_ID="" 9 + FIREBASE_PRIVATE_KEY_ID="" 10 + FIREBASE_PRIVATE_KEY= "" 11 + FIREBASE_CLIENT_EMAIL="" 12 + FIREBASE_CLIENT_ID="" 13 + FIREBASE_CLIENT_CERT_URL="" 14 + 15 + 16 + # Public
+1 -1
src/hooks.server.ts
··· 1 1 import type { Handle } from '@sveltejs/kit'; 2 - import { COUNTRY_HEADER, CITY_HEADER } from '$lib/constants'; 2 + import { COUNTRY_HEADER, CITY_HEADER } from './lib/constants'; 3 3 import { dev } from '$app/environment'; 4 4 5 5 export const handle: Handle = async function ({ event, resolve }) {
+2 -2
src/routes/+page.server.ts
··· 1 - import { CITY_HEADER, COUNTRY_HEADER } from '$lib/constants'; 2 - import { get_visitors, add_visitor } from '$lib/data'; 1 + import { CITY_HEADER, COUNTRY_HEADER } from '../lib/constants'; 2 + import { get_visitors, add_visitor } from '../lib/data'; 3 3 import type { Actions, PageServerLoad } from './$types'; 4 4 5 5 export const load: PageServerLoad = async function ({ request }) {
+31
src/routes/game/+page.server.ts
··· 1 + import { 2 + FIREBASE_DATABASE_URL, 3 + FIREBASE_PROJECT_ID, 4 + FIREBASE_PRIVATE_KEY_ID, 5 + FIREBASE_CLIENT_ID, 6 + FIREBASE_CLIENT_CERT_URL, 7 + FIREBASE_PRIVATE_KEY, 8 + FIREBASE_CLIENT_EMAIL 9 + } from '$env/static/private'; 10 + 11 + import type { PageServerLoad } from '../$types'; 12 + 13 + export const load: PageServerLoad = async ({ params }) => { 14 + return { 15 + // See: https://firebase.google.com/docs/web/learn-more#config-object 16 + firebaseConfig: { 17 + databaseURL: FIREBASE_DATABASE_URL, 18 + type: 'service_account', 19 + project_id: FIREBASE_PROJECT_ID, 20 + private_key_id: FIREBASE_PRIVATE_KEY_ID, 21 + private_key: FIREBASE_PRIVATE_KEY.replace(/\\n/g, '\n'), 22 + client_email: FIREBASE_CLIENT_EMAIL, 23 + client_id: FIREBASE_CLIENT_ID, 24 + auth_uri: 'https://accounts.google.com/o/oauth2/auth', 25 + token_uri: 'https://oauth2.googleapis.com/token', 26 + auth_provider_x509_cert_url: 'https://www.googleapis.com/oauth2/v1/certs', 27 + client_x509_cert_url: FIREBASE_CLIENT_CERT_URL, 28 + universe_domain: 'googleapis.com' 29 + } 30 + }; 31 + };
+19 -23
src/routes/game/+page.svelte
··· 2 2 <script lang="ts"> 3 3 import { onMount } from 'svelte'; 4 4 import { initializeApp } from 'firebase/app'; 5 - 6 5 import { getDatabase, ref, update, get, onValue } from 'firebase/database'; 7 6 8 - // See: https://firebase.google.com/docs/web/learn-more#config-object 9 - const firebaseConfig = { 10 - databaseURL: process.env.FIREBASE_DATABASE_URL!, 11 - type: 'service_account', 12 - project_id: process.env.FIREBASE_PROJECT_ID!, 13 - private_key_id: process.env.FIREBASE_PRIVATE_KEY_ID!, 14 - private_key: process.env.FIREBASE_PRIVATE_KEY!.replace(/\\n/g, '\n'), 15 - client_email: process.env.FIREBASE_CLIENT_EMAIL!, 16 - client_id: process.env.FIREBASE_CLIENT_ID!, 17 - auth_uri: 'https://accounts.google.com/o/oauth2/auth', 18 - token_uri: 'https://oauth2.googleapis.com/token', 19 - auth_provider_x509_cert_url: 'https://www.googleapis.com/oauth2/v1/certs', 20 - client_x509_cert_url: process.env.FIREBASE_CLIENT_CERT_URL!, 21 - universe_domain: 'googleapis.com' 22 - }; 7 + import type { PageData } from './$types'; 8 + 9 + import { page } from '$app/stores'; 23 10 24 11 // Initialize Firebase 25 - const app = initializeApp(firebaseConfig); 26 - 12 + const app = initializeApp($page.data.firebaseConfig); 27 13 // Initialize Realtime Database and get a reference to the service 28 14 const db = getDatabase(app); 29 15 16 + // Set up important game variables. 30 17 let currentHand = ''; 31 18 let otherHand = ''; 32 - 33 19 let gameTimer = 0; 34 20 35 21 onMount(async () => { 22 + // Set the game state to the current state in the database. 36 23 let gameState = (await get(ref(db, '/'))).val(); 37 24 38 - console.log('lastactive', gameState.leftHand.sessionLastActive); 39 - console.log(new Date(Date.now() - 5000)); 25 + // Set the current hand to the one that was not last active, and the other hand to the one that was last active. 40 26 currentHand = 41 27 new Date(gameState.leftHand.sessionLastActive) > new Date(Date.now() - 5000) 42 28 ? 'rightHand' 43 29 : 'leftHand'; 44 30 otherHand = currentHand == 'leftHand' ? 'rightHand' : 'leftHand'; 45 31 32 + // Add event listeners to the current hand. 46 33 window.addEventListener('mousemove', (e) => { 34 + // Get the mouse position. 47 35 const x = e.clientX; 48 36 const y = e.clientY; 49 37 38 + // Update the database with the new mouse position. 50 39 update(ref(db, currentHand), { 51 40 x: x, 52 41 y: y 53 42 }); 54 43 }); 55 44 45 + // Move the current hand to the position in the database. 56 46 onValue(ref(db, currentHand), (snapshot) => { 57 47 const data = snapshot.val(); 58 48 ··· 62 52 hand!.style.top = data.y - 50 + 'px'; 63 53 }); 64 54 55 + // Move the other hand to the position in the database. 65 56 onValue(ref(db, otherHand), (snapshot) => { 66 57 const data = snapshot.val(); 67 58 ··· 71 62 hand!.style.top = data.y - 50 + 'px'; 72 63 }); 73 64 65 + // Update the current hand in the database with sessionLastActive every 500ms. 74 66 setInterval(() => { 75 67 update(ref(db, currentHand), { 76 68 sessionLastActive: new Date() 77 69 }); 78 70 }, 500); 79 71 72 + // Update the game timer in the database based on if the hands are touching (checks every 500ms). 80 73 setInterval(() => { 81 74 // check if hands are touching 82 75 let leftHand = document.getElementById('leftHand'); ··· 110 103 </script> 111 104 112 105 <div class="box"> 113 - <h1>Hello world</h1> 106 + <h1 class="title">Welcome to the Harvest Hackathon Game!</h1> 107 + <p> 108 + Link your hand with the hand of the other player, then dodge objects together for as long as 109 + possible! 110 + </p> 114 111 115 112 <p>Timer {gameTimer}</p> 116 113 </div> 117 - 118 114 <!-- LEFT --> 119 115 <div id="leftHand"> 120 116 <img src="/left_hand.png" alt="Logo" width="100" height="100" />
+2 -1
tsconfig.json
··· 8 8 "resolveJsonModule": true, 9 9 "skipLibCheck": true, 10 10 "sourceMap": true, 11 - "strict": true 11 + "strict": true, 12 + "noImplicitAny": false 12 13 } 13 14 // Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias 14 15 //