Skip to content

Commit

Permalink
Merge pull request #236 from KenEucker/develop
Browse files Browse the repository at this point in the history
fix(library): resolves bugs when trying to set the target game in the store
  • Loading branch information
KenEucker authored Jan 10, 2024
2 parents e1ca8d8 + 9682bb8 commit 3c1ed19
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
3 changes: 3 additions & 0 deletions publish.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export default defineConfig({
exports: 'named',
globals: {
vue: 'Vue',
pinia: 'pinia',
biketag: 'BikeTagClient',
'vue-router': 'vueRouter',
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 8 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -30,8 +31,13 @@ export interface BikeTagPlugin {
useBikeTagStore: () => BikeTagStore
}

export type createBikeTagOptions = Partial<BikeTagCredentials> & {
includeComponents?: boolean
includeDirectives?: boolean
}

const createBikeTag = (
options = {
options: createBikeTagOptions = {
includeComponents: true,
includeDirectives: true,
},
Expand All @@ -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)
Expand Down
21 changes: 13 additions & 8 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[],
Expand Down Expand Up @@ -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
})
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3c1ed19

Please sign in to comment.