Skip to content

Commit

Permalink
Add macro preference option (#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
zelytra authored Apr 8, 2024
1 parent 26b49d0 commit 75bb71c
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 58 deletions.
3 changes: 3 additions & 0 deletions webapp/src/assets/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@
"lang": {
"label": "Langue"
},
"macro": {
"check": "Activer/Déseactiver la macro de session"
},
"name": {
"label": "Pseudonyme",
"placeholder": "Pseudonyme"
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/components/FleetMenuNavigator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ onMounted(() => {
isReady: false,
status: PlayerStates.CLOSED,
username: "",
device: PlayerDevice.MICROSOFT
device: PlayerDevice.MICROSOFT,
macroEnable:true
});
});
window.onbeforeunload = () => {
Expand Down
23 changes: 15 additions & 8 deletions webapp/src/components/fleet/Config.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
:label="t('config.device.label')"
v-model:data="deviceOptions"
/>
<div class="checkbox-wrapper">
<input type="checkbox" v-model="activeMacro"/>
<p @click="activeMacro = !activeMacro">{{ t("config.macro.check") }}</p>
</div>
</ParameterPart>
<ParameterPart :title="t('config.part.audio')">
<div class="input-section">
Expand All @@ -46,7 +50,7 @@
<p>{{ t("config.sound.test") }}</p>
</button>
</div>
<div class="dev-mode-wrapper">
<div class="checkbox-wrapper">
<input type="checkbox" v-model="activeSound"/>
<p @click="activeSound = !activeSound">{{ t("config.sound.check") }}</p>
</div>
Expand All @@ -60,7 +64,7 @@
:label="t('config.server.label')"
:lock="!devMode"
/>
<div class="dev-mode-wrapper">
<div class="checkbox-wrapper">
<input type="checkbox" v-model="devMode"/>
<p @click="devMode = !devMode">{{ t("config.devmode") }}</p>
</div>
Expand Down Expand Up @@ -135,6 +139,7 @@ const deviceOptions = ref<SingleSelectInterface>({data: []});
const devMode = ref<boolean>(false);
const volume = ref<number>(50);
const activeSound = ref<boolean>(true)
const activeMacro = ref<boolean>(true)
const hostName = ref<string>(UserStore.player.serverHostName!)
const username = ref<string>(UserStore.player.username);
Expand Down Expand Up @@ -200,13 +205,15 @@ function resetConfig() {
volume.value = UserStore.player.soundLevel;
activeSound.value = UserStore.player.soundEnable;
activeMacro.value = UserStore.player.macroEnable;
}
function onSave() {
UserStore.setLang(langOptions.value.selectedValue!.id);
UserStore.player.device = deviceOptions.value.selectedValue!.id as PlayerDevice;
UserStore.player.soundLevel = volume.value;
UserStore.player.soundEnable = activeSound.value;
UserStore.player.macroEnable = activeMacro.value;
if (username.value.length == 0 || username.value.length >= 16) {
alerts!.sendAlert({
content: t('alert.username.length.content'),
Expand All @@ -229,6 +236,7 @@ function isConfigDifferent(): boolean {
if (langOptions.value.selectedValue && UserStore.player.lang != langOptions.value.selectedValue!.id) return true;
if (volume.value != UserStore.player.soundLevel) return true;
if (activeSound.value != UserStore.player.soundEnable) return true;
if (activeMacro.value != UserStore.player.macroEnable) return true;
return deviceOptions.value.selectedValue != undefined && UserStore.player.device != deviceOptions.value.selectedValue!.id;
}
Expand Down Expand Up @@ -345,13 +353,12 @@ button {
cursor: pointer;
}
}
}
.dev-mode-wrapper {
display: flex;
align-items: center;
gap: 12px;
}
.checkbox-wrapper{
display: flex;
align-items: center;
gap: 12px;
}
input[type="checkbox"] {
Expand Down
4 changes: 3 additions & 1 deletion webapp/src/components/fleet/session/SessionCountdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ let updateTimer = setInterval(() => {
})
break
}
invoke('rise_anchor');
if (UserStore.player.macroEnable) {
invoke('rise_anchor');
}
break
}
case PlayerStates.CLOSED: {
Expand Down
15 changes: 10 additions & 5 deletions webapp/src/objects/fleet/FleetTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,44 @@ export function getStressTestFleet(): Fleet {
isMaster: true,
device: PlayerDevice.MICROSOFT,
soundEnable: true,
soundLevel: 1
soundLevel: 1,
macroEnable:true
}, {
username: "Player 2",
status: PlayerStates.IN_GAME,
isReady: false,
isMaster: true,
device: PlayerDevice.XBOX,
soundEnable: true,
soundLevel: 1
soundLevel: 1,
macroEnable:true
}, {
username: "Player 3",
status: PlayerStates.STARTED,
isReady: false,
isMaster: true,
device: PlayerDevice.PLAYSTATION,
soundEnable: true,
soundLevel: 1
soundLevel: 1,
macroEnable:true
}, {
username: "Player 4",
status: PlayerStates.STARTED,
isReady: false,
isMaster: true,
device: PlayerDevice.PLAYSTATION,
soundEnable: true,
soundLevel: 1
soundLevel: 1,
macroEnable:true
}, {
username: "Player 5",
status: PlayerStates.STARTED,
isReady: false,
isMaster: true,
device: PlayerDevice.PLAYSTATION,
soundEnable: true,
soundLevel: 1
soundLevel: 1,
macroEnable:true
}
]

Expand Down
9 changes: 5 additions & 4 deletions webapp/src/objects/fleet/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ export interface Player extends Preferences {
status: PlayerStates;
isReady: boolean;
isMaster: boolean;
device: PlayerDevice
device: PlayerDevice;
fleet?: Fleet;
sessionId?: string;
serverHostName?: string;
countDown?: SessionRunner;
server?: SotServer;
clientVersion?: string
clientVersion?: string;
}

export interface Preferences {
lang?: string;
soundEnable: boolean
soundLevel: number
soundEnable: boolean;
soundLevel: number;
macroEnable:boolean;
}
71 changes: 33 additions & 38 deletions webapp/src/objects/stores/UserStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,38 @@ import {Fleet} from "@/objects/fleet/Fleet.ts";
import {keycloakStore} from "@/objects/stores/LoginStates.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.lang = readedPlayer.lang;
this.player.serverHostName = readedPlayer.serverHostName;
this.player.device = readedPlayer.device;
this.player.soundLevel = readedPlayer.soundLevel;
this.player.soundEnable = readedPlayer.soundEnable;
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;

if (!this.player.lang) this.player.lang = browserLang;
if (!this.player.device) this.player.device = PlayerDevice.MICROSOFT;
if (!this.player.username) this.player.username = keycloakStore.user.username;
if (!this.player.soundEnable) this.player.soundEnable = true;
if (!this.player.soundLevel) this.player.soundLevel = 30;
if (!this.player.serverHostName) {
this.player.serverHostName = import.meta.env.VITE_SOCKET_HOST;
}
// Use object destructuring to apply saved settings, falling back to default values
this.player = {
...defaultPlayerValue,
...readedPlayer,
lang: readedPlayer.lang || browserLang,
device: readedPlayer.device || PlayerDevice.MICROSOFT,
username: readedPlayer.username || keycloakStore.user.username,
soundEnable: readedPlayer.soundEnable !== undefined ? readedPlayer.soundEnable : true,
macroEnable: readedPlayer.macroEnable !== undefined ? readedPlayer.macroEnable : true,
soundLevel: readedPlayer.soundLevel || 30,
serverHostName: readedPlayer.serverHostName || import.meta.env.VITE_SOCKET_HOST,
clientVersion: readedPlayer.clientVersion || import.meta.env.VITE_VERSION,
fleet: new Fleet()
};

if (!this.player.clientVersion) {
this.player.clientVersion = import.meta.env.VITE_VERSION;
}

//@ts-ignore I18N typescript implementation
i18n.global.locale.value = this.player.lang;
this.player.fleet = new Fleet();
},

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 as "fr") || "en";
},
});
//@ts-ignore I18N typescript implementation
i18n.global.locale.value = this.player.lang;
this.player.fleet = new Fleet();
},
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 as "fr") || "en";
},
})
;

0 comments on commit 75bb71c

Please sign in to comment.