-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
79 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,35 @@ | ||
import {reactive} from "vue"; | ||
import LocalStore, {LocalKey} from "@/objects/stores/LocalStore.ts"; | ||
import {i18n} from "@/main.ts"; | ||
import type {Player} from "@/objects/Fleet.ts"; | ||
|
||
import { reactive } from "vue"; | ||
import LocalStore, { LocalKey } from "@/objects/stores/LocalStore.ts"; | ||
import { i18n } from "@/main.ts"; | ||
import type { Player } from "@/objects/Fleet.ts"; | ||
|
||
export const UserStore = reactive({ | ||
player: {} as Player, | ||
init(defaultPlayerValue: Player) { | ||
const userStoreKey = LocalStore(LocalKey.USER_STORE, {}); | ||
const browserLang = navigator.language.substring(0, 2); | ||
const readedPlayer = userStoreKey.value as Player; | ||
this.player = defaultPlayerValue; | ||
this.player.username = readedPlayer.username; | ||
this.player.lang = readedPlayer.lang; | ||
this.player.serverHostName = readedPlayer.serverHostName; | ||
player: {} as Player, | ||
init(defaultPlayerValue: Player) { | ||
const userStoreKey = LocalStore(LocalKey.USER_STORE, {}); | ||
const browserLang = navigator.language.substring(0, 2); | ||
const readedPlayer = userStoreKey.value as Player; | ||
this.player = defaultPlayerValue; | ||
this.player.username = readedPlayer.username; | ||
this.player.lang = readedPlayer.lang; | ||
this.player.serverHostName = readedPlayer.serverHostName; | ||
|
||
if (!this.player.lang) this.player.lang = browserLang; | ||
if (!this.player.username) this.player.username = ""; | ||
if (!this.player.serverHostName) this.player.serverHostName = import.meta.env.VITE_SOCKET_HOST; | ||
if (!this.player.lang) this.player.lang = browserLang; | ||
if (!this.player.username) this.player.username = ""; | ||
if (!this.player.serverHostName) | ||
this.player.serverHostName = import.meta.env.VITE_SOCKET_HOST; | ||
|
||
//@ts-ignore I18N typescript implementation | ||
i18n.global.locale.value = this.player.lang; | ||
}, | ||
//@ts-ignore I18N typescript implementation | ||
i18n.global.locale.value = this.player.lang; | ||
}, | ||
|
||
setUser(user: Player) { | ||
this.player = user; | ||
}, | ||
setUser(user: Player) { | ||
this.player = user; | ||
}, | ||
|
||
setLang(lang: string) { | ||
//@ts-ignore I18N typescript implementation | ||
this.player.lang = lang; | ||
i18n.global.locale.value = this.player.lang; | ||
} | ||
setLang(lang: string) { | ||
//@ts-ignore I18N typescript implementation | ||
this.player.lang = lang; | ||
i18n.global.locale.value = (this.player.lang as "fr") || "en"; | ||
}, | ||
}); |