merge: 최신 main을 내 정보 진입 개선에 통합
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import type { CommandMapData, CommandOption } from './types';
|
||||
|
||||
export const commandCityOptions = (
|
||||
commandKey: string,
|
||||
options: readonly CommandOption[],
|
||||
mapData?: CommandMapData | null
|
||||
): CommandOption[] => {
|
||||
if (commandKey !== 'che_발령' || typeof mapData?.myNation !== 'number') return [...options];
|
||||
|
||||
const nationByCityId = new Map(mapData.cityList.map(([cityId, , , nationId]) => [cityId, nationId]));
|
||||
return options
|
||||
.map((option, index) => ({ option, index }))
|
||||
.sort((left, right) => {
|
||||
const leftOwned =
|
||||
typeof left.option.value === 'number' && nationByCityId.get(left.option.value) === mapData.myNation;
|
||||
const rightOwned =
|
||||
typeof right.option.value === 'number' && nationByCityId.get(right.option.value) === mapData.myNation;
|
||||
return Number(rightOwned) - Number(leftOwned) || left.index - right.index;
|
||||
})
|
||||
.map(({ option }) => option);
|
||||
};
|
||||
@@ -2,6 +2,7 @@
|
||||
import { computed, reactive, watch, type CSSProperties } from 'vue';
|
||||
import MapViewer from './MapViewer.vue';
|
||||
import { commandArgumentPresentation } from '../command/commandArgumentPresentation';
|
||||
import { commandCityOptions } from '../command/commandArgumentOptions';
|
||||
import {
|
||||
commandArgumentFieldContract,
|
||||
shouldPreserveCommandArgumentValue,
|
||||
@@ -64,6 +65,9 @@ const optionsFor = (field: CommandInputField): CommandOption[] => {
|
||||
if (field.optionSource === 'nations') {
|
||||
return props.options.nationTargets?.[props.commandKey] ?? props.options.nations;
|
||||
}
|
||||
if (field.optionSource === 'cities') {
|
||||
return commandCityOptions(props.commandKey, props.options.cities, props.mapData);
|
||||
}
|
||||
if (field.optionSource === 'items') {
|
||||
return props.options.items[String(values.itemType ?? '')] ?? [];
|
||||
}
|
||||
@@ -104,12 +108,7 @@ const synchronizeValues = () => {
|
||||
for (const field of props.fields) {
|
||||
const preserve =
|
||||
!commandChanged &&
|
||||
shouldPreserveCommandArgumentValue(
|
||||
field,
|
||||
previousFieldContracts.get(field.key),
|
||||
values,
|
||||
optionsFor(field)
|
||||
);
|
||||
shouldPreserveCommandArgumentValue(field, previousFieldContracts.get(field.key), values, optionsFor(field));
|
||||
if (!preserve) values[field.key] = defaultValue(field);
|
||||
}
|
||||
const itemCodeField = props.fields.find((field) => field.key === 'itemCode');
|
||||
|
||||
Reference in New Issue
Block a user