mirror of
https://github.com/Pandipipas/scoreko-dev.git
synced 2026-06-06 03:32:06 +00:00
Set default characters by game when none are selected (#104)
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, ref, watch, watchEffect, type Ref } from 'vue';
|
import { computed, ref, watch, watchEffect, type Ref } from 'vue';
|
||||||
import { countryOptions, getCountryLabel } from '../../../shared/countries';
|
import { countryOptions, getCountryLabel } from '../../../shared/countries';
|
||||||
import { getCharactersByGame } from '../../../shared/fighting-characters';
|
import { getCharactersByGame, getDefaultCharactersByGame } from '../../../shared/fighting-characters';
|
||||||
import type { Schemas } from '../../../types';
|
import type { Schemas } from '../../../types';
|
||||||
import { usePlayersStore } from '../stores/players';
|
import { usePlayersStore } from '../stores/players';
|
||||||
import { useScoreboardStore } from '../stores/scoreboard';
|
import { useScoreboardStore } from '../stores/scoreboard';
|
||||||
@@ -659,8 +659,24 @@ watch(
|
|||||||
const allowed = new Set(options.map((option) => option.value));
|
const allowed = new Set(options.map((option) => option.value));
|
||||||
const savedCharacters = newGame ? charactersByGame.value[newGame] : undefined;
|
const savedCharacters = newGame ? charactersByGame.value[newGame] : undefined;
|
||||||
|
|
||||||
const nextLeftCharacter = savedCharacters?.leftCharacter ?? '';
|
let nextLeftCharacter = savedCharacters?.leftCharacter ?? '';
|
||||||
const nextRightCharacter = savedCharacters?.rightCharacter ?? '';
|
let nextRightCharacter = savedCharacters?.rightCharacter ?? '';
|
||||||
|
|
||||||
|
if (!allowed.has(nextLeftCharacter)) {
|
||||||
|
nextLeftCharacter = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!allowed.has(nextRightCharacter)) {
|
||||||
|
nextRightCharacter = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!nextLeftCharacter && !nextRightCharacter) {
|
||||||
|
const defaults = getDefaultCharactersByGame(newGame);
|
||||||
|
if (defaults) {
|
||||||
|
nextLeftCharacter = allowed.has(defaults.leftCharacter) ? defaults.leftCharacter : '';
|
||||||
|
nextRightCharacter = allowed.has(defaults.rightCharacter) ? defaults.rightCharacter : '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (allowed.has(nextLeftCharacter)) {
|
if (allowed.has(nextLeftCharacter)) {
|
||||||
scoreboardStore.scoreboard.leftCharacter = nextLeftCharacter;
|
scoreboardStore.scoreboard.leftCharacter = nextLeftCharacter;
|
||||||
|
|||||||
@@ -14,6 +14,17 @@ const characterNamesByGame: Record<string, string[]> = {
|
|||||||
'TEKKEN 8': ['Alisa', 'Anna', 'Armor King', 'Asuka', 'Azucena', 'Bob', 'Bryan', 'Claudio', 'Clive', 'Devil Jin', 'Dragunov', 'Eddy', 'Fahkumram', 'Feng', 'Heihachi', 'Hwoarang', 'Jack-8', 'Jin', 'Jun', 'Kazuya', 'King', 'Kuma', 'Kunimitsu', 'Lars', 'Law', 'Lee', 'Leo', 'Leroy', 'Lidia', 'Lili', 'Miary Zo', 'Nina', 'Panda', 'Paul', 'Raven', 'Reina', 'Roger Jr', 'Shaheen', 'Steve', 'Victor', 'Xiaoyu', 'Yoshimitsu', 'Zafina'],
|
'TEKKEN 8': ['Alisa', 'Anna', 'Armor King', 'Asuka', 'Azucena', 'Bob', 'Bryan', 'Claudio', 'Clive', 'Devil Jin', 'Dragunov', 'Eddy', 'Fahkumram', 'Feng', 'Heihachi', 'Hwoarang', 'Jack-8', 'Jin', 'Jun', 'Kazuya', 'King', 'Kuma', 'Kunimitsu', 'Lars', 'Law', 'Lee', 'Leo', 'Leroy', 'Lidia', 'Lili', 'Miary Zo', 'Nina', 'Panda', 'Paul', 'Raven', 'Reina', 'Roger Jr', 'Shaheen', 'Steve', 'Victor', 'Xiaoyu', 'Yoshimitsu', 'Zafina'],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const defaultCharacterPairByGame: Record<string, { leftCharacter: string; rightCharacter: string }> = {
|
||||||
|
'Street Fighter 6': {
|
||||||
|
leftCharacter: 'ryu',
|
||||||
|
rightCharacter: 'chun-li',
|
||||||
|
},
|
||||||
|
'TEKKEN 8': {
|
||||||
|
leftCharacter: 'jin',
|
||||||
|
rightCharacter: 'kazuya',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
const paletteByGame: Record<string, GamePalette> = {
|
const paletteByGame: Record<string, GamePalette> = {
|
||||||
'Street Fighter 6': ['#f97316', '#b91c1c'],
|
'Street Fighter 6': ['#f97316', '#b91c1c'],
|
||||||
'TEKKEN 8': ['#2563eb', '#111827'],
|
'TEKKEN 8': ['#2563eb', '#111827'],
|
||||||
@@ -102,3 +113,5 @@ export const fightingCharactersByGame: Record<string, FightingCharacterOption[]>
|
|||||||
);
|
);
|
||||||
|
|
||||||
export const getCharactersByGame = (game: string) => fightingCharactersByGame[game] ?? [];
|
export const getCharactersByGame = (game: string) => fightingCharactersByGame[game] ?? [];
|
||||||
|
|
||||||
|
export const getDefaultCharactersByGame = (game: string) => defaultCharacterPairByGame[game];
|
||||||
|
|||||||
Reference in New Issue
Block a user