diff --git a/components.d.ts b/components.d.ts index 51ceb3c..7e7b9f4 100644 --- a/components.d.ts +++ b/components.d.ts @@ -7,8 +7,12 @@ export {} declare module 'vue' { export interface GlobalComponents { + EditGoal: typeof import('./src/composables/EditGoal.vue')['default'] + EditGoalDialog: typeof import('./src/composables/EditGoalDialog.vue')['default'] EditorComponent: typeof import('./src/components/EditorComponent.vue')['default'] + GameList: typeof import('./src/composables/GameList.vue')['default'] GeneratorComponent: typeof import('./src/components/GeneratorComponent.vue')['default'] + GoalEditorDialog: typeof import('./src/components/GoalEditorDialog.vue')['default'] MarkdownRenderer: typeof import('./src/components/MarkdownRenderer.vue')['default'] NavbarComponent: typeof import('./src/components/NavbarComponent.vue')['default'] RouterLink: typeof import('vue-router')['RouterLink'] diff --git a/package.json b/package.json index 7d78688..a1ebed7 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ }, "dependencies": { "@quasar/extras": "^1.16.8", + "@sindresorhus/string-hash": "^2.0.0", "@types/markdown-it": "^13.0.6", "@vue/runtime-core": "^3.3.8", "class-transformer": "^0.5.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ed978e9..d89f3cf 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,9 @@ dependencies: '@quasar/extras': specifier: ^1.16.8 version: 1.16.8 + '@sindresorhus/string-hash': + specifier: ^2.0.0 + version: 2.0.0 '@types/markdown-it': specifier: ^13.0.6 version: 13.0.6 @@ -791,6 +794,18 @@ packages: resolution: {integrity: sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==} dev: true + /@sindresorhus/fnv1a@3.1.0: + resolution: {integrity: sha512-KV321z5m/0nuAg83W1dPLy85HpHDk7Sdi4fJbwvacWsEhAh+rZUW4ZfGcXmUIvjZg4ss2bcwNlRhJ7GBEUG08w==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + dev: false + + /@sindresorhus/string-hash@2.0.0: + resolution: {integrity: sha512-eNmMOd5DZkiu9LxIeHdh1XvDbcpFXV4HdBqg9hlg8YNKDvE6qmHiJ+Vy+rFrzXofRYmtheNv4A3ESad8unxwwA==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + dependencies: + '@sindresorhus/fnv1a': 3.1.0 + dev: false + /@stylistic/eslint-plugin-js@1.2.0: resolution: {integrity: sha512-1Zi/AlQzOzTlTegupd3vrUYHd02ilvk7x5O9ZRFjYGtUcwHVk+WTEKk/3Nmr8yuvzEiXqUNFJ8bv8b4rLYCPRQ==} dependencies: diff --git a/src/components/EditorComponent.vue b/src/components/EditorComponent.vue index 959e667..eeb14ed 100644 --- a/src/components/EditorComponent.vue +++ b/src/components/EditorComponent.vue @@ -205,4 +205,3 @@ watch(learn_more, newValue => { selected_game.value = undefined; }); -@/js/lib/LocalGames diff --git a/src/components/GoalEditorDialog.vue b/src/components/GoalEditorDialog.vue new file mode 100644 index 0000000..e69de29 diff --git a/src/composables/EditGoalDialog.vue b/src/composables/EditGoalDialog.vue new file mode 100644 index 0000000..82055e4 --- /dev/null +++ b/src/composables/EditGoalDialog.vue @@ -0,0 +1,134 @@ + + + + + diff --git a/src/composables/GameList.vue b/src/composables/GameList.vue new file mode 100644 index 0000000..2a5a944 --- /dev/null +++ b/src/composables/GameList.vue @@ -0,0 +1,308 @@ + + + + diff --git a/src/js/lib/BingoGame.ts b/src/js/lib/BingoGame.ts index 3a62f1d..33daf2a 100644 --- a/src/js/lib/BingoGame.ts +++ b/src/js/lib/BingoGame.ts @@ -3,12 +3,14 @@ import BingoCategory from '@/js/lib/BingoCategory.ts'; import BingoGoal from '@/js/lib/BingoGoal.ts'; import BingoGoalList from '@/js/lib/BingoGoalList.ts'; import SuccessResponse from '@/js/lib/SuccessResponse.ts'; -import Util from '@/js/lib/Util.ts'; +import { + stringCompare +} from '@/js/lib/Util.ts'; import { Transform, plainToInstance, type TransformFnParams, Exclude } from 'class-transformer'; -type BingoCategoryOrGoalList = BingoCategory | BingoGoalList; +export type BingoCategoryOrGoalList = BingoCategory | BingoGoalList; export default class BingoGame { id: string; @@ -86,7 +88,7 @@ export default class BingoGame { removeItemByName(name: string): SuccessResponse { const group = this.items.find( - g => Util.stringCompare(g.name, name) + g => stringCompare(g.name, name) ); if (!group) { return SuccessResponse.error('Category not found'); @@ -95,6 +97,26 @@ export default class BingoGame { return this.removeItem(group); } + getAllTags(): string[] { + const tags: string[] = []; + + this.items.map(group => { + const goal_lists = group instanceof BingoGoalList ? [ group ] : group.goal_lists; + + goal_lists.map(subgroup => { + subgroup.goals.map(goal => { + goal.tags.map(tag => { + if (!tags.includes(tag)) { + tags.push(tag); + } + }); + }); + }); + }); + + return tags; + } + getGoalsByTags(...tags: string[]): BingoGoal[] { const goals: BingoGoal[] = []; @@ -105,7 +127,7 @@ export default class BingoGame { subgroup.goals.map(goal => { if (goal.tags.some( tag => tags.some( - inputTag => Util.stringCompare(tag, inputTag) + inputTag => stringCompare(tag, inputTag) ) )) { goals.push(goal); diff --git a/src/js/lib/BingoGoal.ts b/src/js/lib/BingoGoal.ts index bced002..25a6ba1 100644 --- a/src/js/lib/BingoGoal.ts +++ b/src/js/lib/BingoGoal.ts @@ -1,6 +1,8 @@ import SuccessResponse from '@/js/lib/SuccessResponse.js'; -import Util from './Util'; +import { + stringCompare +} from '@/js/lib/Util.ts'; export default class BingoGoal { name: string; @@ -15,7 +17,7 @@ export default class BingoGoal { addTag(tag: string): SuccessResponse { if (this.tags.some( - existingTag => Util.stringCompare(existingTag, tag) + existingTag => stringCompare(existingTag, tag) )) { return SuccessResponse.error('Tag already exists'); } @@ -28,13 +30,13 @@ export default class BingoGoal { removeTag(tag: string): SuccessResponse { if (!this.tags.some( - existingTag => Util.stringCompare(existingTag, tag) + existingTag => stringCompare(existingTag, tag) )) { return SuccessResponse.error('Tag doesn\'t exist'); } else { this.tags = this.tags.filter( - existingTag => !Util.stringCompare(existingTag, tag) + existingTag => !stringCompare(existingTag, tag) ); return SuccessResponse.success(); diff --git a/src/js/lib/Util.ts b/src/js/lib/Util.ts index e3672f6..a68d549 100644 --- a/src/js/lib/Util.ts +++ b/src/js/lib/Util.ts @@ -1,7 +1,33 @@ -export default class Util { - static stringCompare(str1: string, str2: string): boolean { - return str1.localeCompare(str2, undefined, { - sensitivity: 'accent' - }) === 0; - } +const colors = [ + 'red', + 'pink', + 'purple', + 'deep-purple', + 'indigo', + 'blue', + 'light-blue', + 'cyan', + 'teal', + 'green', + 'light-green', + 'lime', + 'yellow', + 'amber', + 'orange', + 'deep-orange', + 'brown', + 'grey', + 'blue-grey' +]; + +import stringHash from '@sindresorhus/string-hash'; + +export function stringCompare(str1: string, str2: string): boolean { + return str1.localeCompare(str2, undefined, { + sensitivity: 'accent' + }) === 0; +} + +export function getColorForString(input: string): string { + return colors[stringHash(input) % colors.length]; } diff --git a/src/stores/local-games.ts b/src/stores/local-games.ts index 255fd2f..541ca83 100644 --- a/src/stores/local-games.ts +++ b/src/stores/local-games.ts @@ -42,9 +42,9 @@ export const useLocalGamesStore = defineStore('localGames', () => { // }); console.info('--- Finished fetching games!'); - console.info(''); - console.log(games.value); + + console.info(''); } async function saveGames() { diff --git a/src/views/EditorPage.vue b/src/views/EditorPage.vue index 6994cd2..b76ce6c 100644 --- a/src/views/EditorPage.vue +++ b/src/views/EditorPage.vue @@ -1,3 +1,35 @@ + + diff --git a/vite.config.ts b/vite.config.ts index 9a1028d..517849d 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -22,7 +22,11 @@ export default defineConfig({ plugins: [ VueRouter(), Components({ - dts: true + dts: true, + dirs: [ + 'src/components', + 'src/composables' + ] }), AutoImport({ include: [