From 9682bb85983520ee796ac76a326c3db24c1db2fc Mon Sep 17 00:00:00 2001 From: Ken Eucker Date: Wed, 10 Jan 2024 03:22:42 -0800 Subject: [PATCH] fix(library): resolves bugs when trying to set the target game in the store --- publish.config.ts | 3 +++ src/common/constants.ts | 2 +- src/index.ts | 9 ++++++++- src/store/index.ts | 21 +++++++++++++-------- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/publish.config.ts b/publish.config.ts index faf75ef5..4c9b11ad 100644 --- a/publish.config.ts +++ b/publish.config.ts @@ -23,6 +23,9 @@ export default defineConfig({ exports: 'named', globals: { vue: 'Vue', + pinia: 'pinia', + biketag: 'BikeTagClient', + 'vue-router': 'vueRouter', }, }, }, diff --git a/src/common/constants.ts b/src/common/constants.ts index 22290bcc..2a84f036 100644 --- a/src/common/constants.ts +++ b/src/common/constants.ts @@ -39,7 +39,7 @@ export const BikeTagEnv = { /* Bugs Configuration */ B_AKEY: process.env.B_AKEY ?? null, /* BikeTag Configuration */ - GAME_NAME: process.env.GAME_NAME ?? 'null', + GAME_NAME: process.env.GAME_NAME ?? null, GAME_SOURCE: process.env.GAME_SOURCE ?? null, HOST: process.env.HOST ?? BikeTagDefaults.host, HOST_KEY: process.env.HOST_KEY ?? BikeTagDefaults.hostKey, diff --git a/src/index.ts b/src/index.ts index 32fdefd7..77165105 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,6 +18,7 @@ import BikeTagButton from './components/BikeTagButton.vue' // import BikeTagGames from './components/BikeTagGames.vue' import BikeTagHeader from './components/BikeTagHeader.vue' // import BikeTagInput from './components/BikeTagInput.vue' +import { BikeTagCredentials } from 'biketag' import BikeTagLabel from './components/BikeTagLabel.vue' // import BikeTagLoader from './components/BikeTagLoader.vue' // import BikeTagMap from './components/BikeTagMap.vue' @@ -30,8 +31,13 @@ export interface BikeTagPlugin { useBikeTagStore: () => BikeTagStore } +export type createBikeTagOptions = Partial & { + includeComponents?: boolean + includeDirectives?: boolean +} + const createBikeTag = ( - options = { + options: createBikeTagOptions = { includeComponents: true, includeDirectives: true, }, @@ -44,6 +50,7 @@ const createBikeTag = ( .component('BikeTagBlurb', BikeTagBlurb) .component('BikeTagHeader', BikeTagHeader) .component('BikeTagButton', BikeTagButton) + .component('BikeTagLabel', BikeTagLabel) } if (options.includeDirectives) { app.directive('dynamic-font', dynamicFontDirective) diff --git a/src/store/index.ts b/src/store/index.ts index 94275533..84f7d1ae 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -64,7 +64,7 @@ export const useBikeTagStore = defineStore(BikeTagDefaults.store, { state: (): BikeTagStoreState => ({ dataLoaded: false, gameName, - gameNameProper: gameName[0].toUpperCase() + gameName.slice(1), + gameNameProper: gameName?.length ? gameName[0].toUpperCase() + gameName.slice(1) : '', game: {} as Game, allGames: [] as Game[], achievements: [] as Achievement[], @@ -160,18 +160,23 @@ export const useBikeTagStore = defineStore(BikeTagDefaults.store, { return this.SET_PROFILE(profile) }, - async setGame(gameName?: string) { - gameName = gameName || this.gameName - if (this.game.name !== gameName || this.game?.mainhash) { + async setGame(newGameName?: string) { + newGameName = newGameName ?? this.gameName + if (this.game?.name !== newGameName || !this.game?.mainhash) { this.dataLoaded = false - return client.game(gameName, biketagGameOpts as any).then(async (d) => { - if (d) { - const game = d as Game + return client.getGame({ game: newGameName }, biketagGameOpts as any).then(async (r) => { + if (r.success) { + const game = r.data as Game biketagClientOpts.imgur.hash = game.mainhash biketagClientOpts.imgur.queuehash = game.queuehash client.config(biketagClientOpts) return this.SET_GAME(game) + } else { + const cachedGame = this.allGames.find((g) => g.name === newGameName) + if (cachedGame) { + return this.SET_GAME(cachedGame) + } } return false }) @@ -883,7 +888,7 @@ export const useBikeTagStore = defineStore(BikeTagDefaults.store, { return `https://biketag.org/${BikeTagDefaults.jingle}` }, getGameTitle(state) { - return `${state.gameName.toUpperCase()}.BIKETAG` + return `${state.gameName?.toUpperCase()}.BIKETAG` }, getGameName(state) { return state.gameName