Merge pull request #39 from Pandipipas/add-team-and-country-options-to-scoreboardpanel-plhajv

Refactor ScoreboardPanel custom player flow and add team/country overrides
This commit is contained in:
Pandipipas
2026-02-11 10:48:19 +01:00
committed by GitHub
@@ -70,33 +70,35 @@ const playerOptions = computed(() => {
return base.concat(options); return base.concat(options);
}); });
const leftPlayerOptions = computed(() => { const buildPlayerOptions = (
const options = filterOptions(playerOptions.value, leftFilter.value); filterValue: string,
if ( selectedPlayerId: string,
scoreboardStore.scoreboard.leftPlayerId !== CUSTOM_LEFT_PLAYER_ID customPlayerId: string,
|| !scoreboardStore.scoreboard.leftNameOverride.trim() customNameOverride: string,
) { ) => {
const options = filterOptions(playerOptions.value, filterValue);
if (selectedPlayerId !== customPlayerId || !customNameOverride.trim()) {
return options; return options;
} }
return [{ return [{
value: CUSTOM_LEFT_PLAYER_ID, value: customPlayerId,
label: scoreboardStore.scoreboard.leftNameOverride, label: customNameOverride,
}].concat(options); }].concat(options);
}); };
const rightPlayerOptions = computed(() => { const leftPlayerOptions = computed(() => buildPlayerOptions(
const options = filterOptions(playerOptions.value, rightFilter.value); leftFilter.value,
if ( scoreboardStore.scoreboard.leftPlayerId,
scoreboardStore.scoreboard.rightPlayerId !== CUSTOM_RIGHT_PLAYER_ID CUSTOM_LEFT_PLAYER_ID,
|| !scoreboardStore.scoreboard.rightNameOverride.trim() scoreboardStore.scoreboard.leftNameOverride,
) { ));
return options;
} const rightPlayerOptions = computed(() => buildPlayerOptions(
return [{ rightFilter.value,
value: CUSTOM_RIGHT_PLAYER_ID, scoreboardStore.scoreboard.rightPlayerId,
label: scoreboardStore.scoreboard.rightNameOverride, CUSTOM_RIGHT_PLAYER_ID,
}].concat(options); scoreboardStore.scoreboard.rightNameOverride,
}); ));
const leftSelectedPlayer = computed(() => playersStore.players[scoreboardStore.scoreboard.leftPlayerId]); const leftSelectedPlayer = computed(() => playersStore.players[scoreboardStore.scoreboard.leftPlayerId]);
const rightSelectedPlayer = computed(() => playersStore.players[scoreboardStore.scoreboard.rightPlayerId]); const rightSelectedPlayer = computed(() => playersStore.players[scoreboardStore.scoreboard.rightPlayerId]);
@@ -187,46 +189,70 @@ const startRightCustomPlayer = () => {
} }
}; };
const onLeftFilter = (val: string, update: (fn: () => void) => void) => { const filterPlayerInput = (
val: string,
update: (fn: () => void) => void,
filterValue: Ref<string>,
focused: Ref<boolean>,
inputValue: Ref<string>,
selectedPlayerId: string,
customPlayerId: string,
customNameOverride: string,
setCustomNameOverride: (value: string) => void,
startCustomPlayer: () => void,
) => {
update(() => { update(() => {
leftFilter.value = val; filterValue.value = val;
if (!leftFocused.value) { if (!focused.value) {
return; return;
} }
if (!val.trim() && scoreboardStore.scoreboard.leftPlayerId === CUSTOM_LEFT_PLAYER_ID) { if (!val.trim() && selectedPlayerId === customPlayerId) {
leftInput.value = scoreboardStore.scoreboard.leftNameOverride; inputValue.value = customNameOverride;
return; return;
} }
leftInput.value = val; inputValue.value = val;
scoreboardStore.scoreboard.leftNameOverride = val; setCustomNameOverride(val);
if (val.trim()) { if (val.trim()) {
startLeftCustomPlayer(); startCustomPlayer();
} }
}); });
}; };
const onLeftFilter = (val: string, update: (fn: () => void) => void) => {
filterPlayerInput(
val,
update,
leftFilter,
leftFocused,
leftInput,
scoreboardStore.scoreboard.leftPlayerId,
CUSTOM_LEFT_PLAYER_ID,
scoreboardStore.scoreboard.leftNameOverride,
(value) => {
scoreboardStore.scoreboard.leftNameOverride = value;
},
startLeftCustomPlayer,
);
};
const onRightFilter = (val: string, update: (fn: () => void) => void) => { const onRightFilter = (val: string, update: (fn: () => void) => void) => {
update(() => { filterPlayerInput(
rightFilter.value = val; val,
update,
if (!rightFocused.value) { rightFilter,
return; rightFocused,
} rightInput,
scoreboardStore.scoreboard.rightPlayerId,
if (!val.trim() && scoreboardStore.scoreboard.rightPlayerId === CUSTOM_RIGHT_PLAYER_ID) { CUSTOM_RIGHT_PLAYER_ID,
rightInput.value = scoreboardStore.scoreboard.rightNameOverride; scoreboardStore.scoreboard.rightNameOverride,
return; (value) => {
} scoreboardStore.scoreboard.rightNameOverride = value;
},
rightInput.value = val; startRightCustomPlayer,
scoreboardStore.scoreboard.rightNameOverride = val; );
if (val.trim()) {
startRightCustomPlayer();
}
});
}; };
const onLeftFocus = () => { const onLeftFocus = () => {