2026-02-22 17:05:36 -05:00
|
|
|
import { handleListControlKey } from '../input/listController';
|
|
|
|
|
import { getEditSessionAction } from '../input/editSession';
|
|
|
|
|
import { formatSteppedNumber, snapNumberToStep } from '../input/numeric';
|
|
|
|
|
import { type WorldItem } from '../state/gameState';
|
|
|
|
|
|
2026-02-22 17:12:28 -05:00
|
|
|
/**
|
|
|
|
|
* Dependencies required to drive item property inspect/edit flows.
|
|
|
|
|
*/
|
2026-02-22 17:05:36 -05:00
|
|
|
type EditorDeps = {
|
|
|
|
|
state: {
|
|
|
|
|
mode: string;
|
|
|
|
|
selectedItemId: string | null;
|
|
|
|
|
editingPropertyKey: string | null;
|
|
|
|
|
itemPropertyOptionValues: string[];
|
|
|
|
|
itemPropertyOptionIndex: number;
|
|
|
|
|
itemPropertyKeys: string[];
|
|
|
|
|
itemPropertyIndex: number;
|
|
|
|
|
nicknameInput: string;
|
|
|
|
|
cursorPos: number;
|
|
|
|
|
items: Map<string, WorldItem>;
|
|
|
|
|
};
|
|
|
|
|
signalingSend: (message: unknown) => void;
|
|
|
|
|
getItemPropertyValue: (item: WorldItem, key: string) => string;
|
|
|
|
|
itemPropertyLabel: (key: string) => string;
|
|
|
|
|
isItemPropertyEditable: (item: WorldItem, key: string) => boolean;
|
|
|
|
|
getItemPropertyOptionValues: (key: string) => string[] | undefined;
|
|
|
|
|
openItemPropertyOptionSelect: (item: WorldItem, key: string) => void;
|
|
|
|
|
describeItemPropertyHelp: (item: WorldItem, key: string) => string;
|
2026-02-24 02:49:17 -05:00
|
|
|
getItemPropertyMetadata: (
|
|
|
|
|
itemType: WorldItem['type'],
|
|
|
|
|
key: string,
|
|
|
|
|
) => {
|
|
|
|
|
valueType?: string;
|
|
|
|
|
maxLength?: number;
|
|
|
|
|
range?: { min: number; max: number; step?: number };
|
|
|
|
|
} | undefined;
|
2026-02-22 17:05:36 -05:00
|
|
|
validateNumericItemPropertyInput: (
|
|
|
|
|
item: WorldItem,
|
|
|
|
|
key: string,
|
|
|
|
|
rawValue: string,
|
|
|
|
|
requireInteger: boolean,
|
|
|
|
|
) => { ok: true; value: number } | { ok: false; message: string };
|
|
|
|
|
applyTextInputEdit: (code: string, key: string, maxLength: number, ctrlKey?: boolean, allowReplaceOnNextType?: boolean) => void;
|
|
|
|
|
setReplaceTextOnNextType: (value: boolean) => void;
|
2026-02-22 20:50:04 -05:00
|
|
|
suppressItemPropertyEchoMs: (ms: number) => void;
|
2026-02-22 23:51:13 -05:00
|
|
|
onPreviewPropertyChange?: (item: WorldItem, key: string, value: unknown) => void;
|
2026-02-22 17:05:36 -05:00
|
|
|
updateStatus: (message: string) => void;
|
|
|
|
|
sfxUiBlip: () => void;
|
|
|
|
|
sfxUiCancel: () => void;
|
|
|
|
|
};
|
|
|
|
|
|
2026-02-22 17:12:28 -05:00
|
|
|
/**
|
|
|
|
|
* Creates item property mode handlers so main input dispatch can stay lean.
|
|
|
|
|
*/
|
2026-02-22 17:05:36 -05:00
|
|
|
export function createItemPropertyEditor(deps: EditorDeps): {
|
|
|
|
|
handleItemPropertiesModeInput: (code: string, key: string) => void;
|
|
|
|
|
handleItemPropertyEditModeInput: (code: string, key: string, ctrlKey: boolean) => void;
|
|
|
|
|
handleItemPropertyOptionSelectModeInput: (code: string, key: string) => void;
|
|
|
|
|
} {
|
|
|
|
|
function handleItemPropertiesModeInput(code: string, key: string): void {
|
|
|
|
|
const itemId = deps.state.selectedItemId;
|
|
|
|
|
if (!itemId) {
|
|
|
|
|
deps.state.mode = 'normal';
|
|
|
|
|
deps.state.editingPropertyKey = null;
|
|
|
|
|
deps.state.itemPropertyOptionValues = [];
|
|
|
|
|
deps.state.itemPropertyOptionIndex = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const item = deps.state.items.get(itemId);
|
|
|
|
|
if (!item) {
|
|
|
|
|
deps.state.mode = 'normal';
|
|
|
|
|
deps.state.editingPropertyKey = null;
|
|
|
|
|
deps.state.itemPropertyOptionValues = [];
|
|
|
|
|
deps.state.itemPropertyOptionIndex = 0;
|
|
|
|
|
deps.updateStatus('Item no longer exists.');
|
|
|
|
|
deps.sfxUiCancel();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const control = handleListControlKey(code, key, deps.state.itemPropertyKeys, deps.state.itemPropertyIndex, (propertyKey) => propertyKey);
|
|
|
|
|
if (control.type === 'move') {
|
|
|
|
|
deps.state.itemPropertyIndex = control.index;
|
|
|
|
|
const selectedKey = deps.state.itemPropertyKeys[deps.state.itemPropertyIndex];
|
|
|
|
|
const value = deps.getItemPropertyValue(item, selectedKey);
|
|
|
|
|
deps.updateStatus(`${deps.itemPropertyLabel(selectedKey)}: ${value}`);
|
|
|
|
|
deps.sfxUiBlip();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (code === 'Space') {
|
|
|
|
|
const selectedKey = deps.state.itemPropertyKeys[deps.state.itemPropertyIndex];
|
|
|
|
|
deps.updateStatus(deps.describeItemPropertyHelp(item, selectedKey));
|
|
|
|
|
deps.sfxUiBlip();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-02-22 20:47:06 -05:00
|
|
|
if (code === 'ArrowLeft' || code === 'ArrowRight') {
|
|
|
|
|
const selectedKey = deps.state.itemPropertyKeys[deps.state.itemPropertyIndex];
|
|
|
|
|
if (!deps.isItemPropertyEditable(item, selectedKey)) {
|
|
|
|
|
deps.updateStatus(`${deps.itemPropertyLabel(selectedKey)} is not editable.`);
|
|
|
|
|
deps.sfxUiCancel();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const options = deps.getItemPropertyOptionValues(selectedKey);
|
|
|
|
|
if (options && options.length > 0) {
|
|
|
|
|
const currentRaw = String(item.params[selectedKey] ?? '').trim().toLowerCase();
|
|
|
|
|
const currentIndex = Math.max(
|
|
|
|
|
0,
|
|
|
|
|
options.findIndex((option) => option.toLowerCase() === currentRaw),
|
|
|
|
|
);
|
|
|
|
|
const delta = code === 'ArrowRight' ? 1 : -1;
|
|
|
|
|
const nextIndex = (currentIndex + delta + options.length) % options.length;
|
|
|
|
|
const nextValue = options[nextIndex];
|
2026-02-22 20:50:04 -05:00
|
|
|
deps.suppressItemPropertyEchoMs(600);
|
2026-02-22 20:47:06 -05:00
|
|
|
deps.signalingSend({ type: 'item_update', itemId, params: { [selectedKey]: nextValue } });
|
2026-02-22 23:51:13 -05:00
|
|
|
deps.onPreviewPropertyChange?.(item, selectedKey, nextValue);
|
2026-02-22 20:47:06 -05:00
|
|
|
deps.updateStatus(nextValue);
|
|
|
|
|
deps.sfxUiBlip();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const metadata = deps.getItemPropertyMetadata(item.type, selectedKey);
|
|
|
|
|
if (metadata?.valueType === 'boolean') {
|
|
|
|
|
let current = item.params[selectedKey];
|
|
|
|
|
if (typeof current !== 'boolean') {
|
2026-02-24 02:49:17 -05:00
|
|
|
current = item.params[selectedKey] === true;
|
2026-02-22 20:47:06 -05:00
|
|
|
}
|
|
|
|
|
const nextValue = !current;
|
2026-02-22 20:50:04 -05:00
|
|
|
deps.suppressItemPropertyEchoMs(600);
|
2026-02-22 20:47:06 -05:00
|
|
|
deps.signalingSend({ type: 'item_update', itemId, params: { [selectedKey]: nextValue } });
|
2026-02-22 23:51:13 -05:00
|
|
|
deps.onPreviewPropertyChange?.(item, selectedKey, nextValue);
|
2026-02-22 20:47:06 -05:00
|
|
|
deps.updateStatus(nextValue ? 'on' : 'off');
|
|
|
|
|
deps.sfxUiBlip();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (metadata?.valueType === 'number') {
|
|
|
|
|
const range = metadata.range;
|
|
|
|
|
const step = range?.step && range.step > 0 ? range.step : 1;
|
|
|
|
|
const min = range?.min;
|
|
|
|
|
const max = range?.max;
|
|
|
|
|
const currentRaw = Number(item.params[selectedKey]);
|
|
|
|
|
const currentValue = Number.isFinite(currentRaw)
|
|
|
|
|
? currentRaw
|
|
|
|
|
: Number.isFinite(min)
|
|
|
|
|
? min
|
|
|
|
|
: 0;
|
|
|
|
|
const delta = code === 'ArrowRight' ? step : -step;
|
|
|
|
|
const anchor = Number.isFinite(min) ? min : 0;
|
|
|
|
|
const attempted = snapNumberToStep(currentValue + delta, step, anchor);
|
|
|
|
|
let nextValue = attempted;
|
|
|
|
|
if (Number.isFinite(min)) nextValue = Math.max(min, nextValue);
|
|
|
|
|
if (Number.isFinite(max)) nextValue = Math.min(max, nextValue);
|
2026-02-22 20:50:04 -05:00
|
|
|
deps.suppressItemPropertyEchoMs(600);
|
2026-02-22 20:47:06 -05:00
|
|
|
deps.signalingSend({ type: 'item_update', itemId, params: { [selectedKey]: nextValue } });
|
2026-02-22 23:51:13 -05:00
|
|
|
deps.onPreviewPropertyChange?.(item, selectedKey, nextValue);
|
2026-02-22 20:47:06 -05:00
|
|
|
deps.updateStatus(formatSteppedNumber(nextValue, step));
|
|
|
|
|
if (Math.abs(nextValue - currentValue) < 1e-9 || Math.abs(nextValue - attempted) > 1e-9) {
|
|
|
|
|
deps.sfxUiCancel();
|
|
|
|
|
} else {
|
|
|
|
|
deps.sfxUiBlip();
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
deps.sfxUiCancel();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-02-22 17:05:36 -05:00
|
|
|
if (control.type === 'select') {
|
|
|
|
|
const selectedKey = deps.state.itemPropertyKeys[deps.state.itemPropertyIndex];
|
|
|
|
|
if (!deps.isItemPropertyEditable(item, selectedKey)) {
|
|
|
|
|
deps.updateStatus(`${deps.itemPropertyLabel(selectedKey)} is not editable.`);
|
|
|
|
|
deps.sfxUiCancel();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-02-24 02:49:17 -05:00
|
|
|
const metadata = deps.getItemPropertyMetadata(item.type, selectedKey);
|
|
|
|
|
if (metadata?.valueType === 'boolean') {
|
|
|
|
|
const current = item.params[selectedKey];
|
|
|
|
|
const nextValue = typeof current === 'boolean' ? !current : deps.getItemPropertyValue(item, selectedKey).toLowerCase() !== 'on';
|
|
|
|
|
deps.signalingSend({ type: 'item_update', itemId, params: { [selectedKey]: nextValue } });
|
|
|
|
|
deps.onPreviewPropertyChange?.(item, selectedKey, nextValue);
|
|
|
|
|
deps.updateStatus(`${deps.itemPropertyLabel(selectedKey)}: ${nextValue ? 'on' : 'off'}`);
|
2026-02-22 17:05:36 -05:00
|
|
|
deps.sfxUiBlip();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (deps.getItemPropertyOptionValues(selectedKey)) {
|
|
|
|
|
deps.openItemPropertyOptionSelect(item, selectedKey);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
deps.state.mode = 'itemPropertyEdit';
|
|
|
|
|
deps.state.editingPropertyKey = selectedKey;
|
2026-02-24 02:49:17 -05:00
|
|
|
const selectedMetadata = deps.getItemPropertyMetadata(item.type, selectedKey);
|
2026-02-22 17:05:36 -05:00
|
|
|
deps.state.nicknameInput =
|
|
|
|
|
selectedKey === 'title'
|
|
|
|
|
? item.title
|
2026-02-24 02:49:17 -05:00
|
|
|
: selectedMetadata?.valueType === 'boolean'
|
|
|
|
|
? item.params[selectedKey] === true
|
|
|
|
|
? 'on'
|
|
|
|
|
: 'off'
|
2026-02-22 17:05:36 -05:00
|
|
|
: String(item.params[selectedKey] ?? '');
|
|
|
|
|
deps.state.cursorPos = deps.state.nicknameInput.length;
|
|
|
|
|
deps.setReplaceTextOnNextType(true);
|
|
|
|
|
deps.updateStatus(`Edit ${deps.itemPropertyLabel(selectedKey)}: ${deps.state.nicknameInput}`);
|
|
|
|
|
deps.sfxUiBlip();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (control.type === 'cancel') {
|
|
|
|
|
deps.state.mode = 'normal';
|
|
|
|
|
deps.state.selectedItemId = null;
|
|
|
|
|
deps.state.itemPropertyKeys = [];
|
|
|
|
|
deps.state.itemPropertyIndex = 0;
|
|
|
|
|
deps.state.editingPropertyKey = null;
|
|
|
|
|
deps.state.itemPropertyOptionValues = [];
|
|
|
|
|
deps.state.itemPropertyOptionIndex = 0;
|
|
|
|
|
deps.updateStatus('Closed item properties.');
|
|
|
|
|
deps.sfxUiCancel();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleItemPropertyEditModeInput(code: string, key: string, ctrlKey: boolean): void {
|
|
|
|
|
const itemId = deps.state.selectedItemId;
|
|
|
|
|
const propertyKey = deps.state.editingPropertyKey;
|
|
|
|
|
if (!itemId || !propertyKey) {
|
|
|
|
|
deps.state.mode = 'normal';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const item = deps.state.items.get(itemId);
|
|
|
|
|
if (!item) {
|
|
|
|
|
deps.state.mode = 'normal';
|
|
|
|
|
deps.state.editingPropertyKey = null;
|
|
|
|
|
deps.updateStatus('Item no longer exists.');
|
|
|
|
|
deps.sfxUiCancel();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-02-22 17:12:28 -05:00
|
|
|
if (code === 'ArrowUp' || code === 'ArrowDown' || code === 'PageUp' || code === 'PageDown') {
|
2026-02-22 17:05:36 -05:00
|
|
|
const metadata = deps.getItemPropertyMetadata(item.type, propertyKey);
|
|
|
|
|
if (metadata?.valueType === 'number') {
|
|
|
|
|
const range = metadata.range;
|
|
|
|
|
const step = range?.step && range.step > 0 ? range.step : 1;
|
|
|
|
|
const min = range?.min;
|
|
|
|
|
const max = range?.max;
|
|
|
|
|
const rawCurrent = Number(deps.state.nicknameInput.trim());
|
|
|
|
|
const paramCurrent = Number(item.params[propertyKey]);
|
|
|
|
|
const currentValue = Number.isFinite(rawCurrent)
|
|
|
|
|
? rawCurrent
|
|
|
|
|
: Number.isFinite(paramCurrent)
|
|
|
|
|
? paramCurrent
|
|
|
|
|
: Number.isFinite(min)
|
|
|
|
|
? min
|
|
|
|
|
: 0;
|
2026-02-22 17:12:28 -05:00
|
|
|
const multiplier = code === 'PageUp' || code === 'PageDown' ? 10 : 1;
|
|
|
|
|
const delta = (code === 'ArrowUp' || code === 'PageUp' ? step : -step) * multiplier;
|
2026-02-22 17:05:36 -05:00
|
|
|
const anchor = Number.isFinite(min) ? min : 0;
|
|
|
|
|
const attempted = snapNumberToStep(currentValue + delta, step, anchor);
|
|
|
|
|
let nextValue = attempted;
|
|
|
|
|
if (Number.isFinite(min)) nextValue = Math.max(min, nextValue);
|
|
|
|
|
if (Number.isFinite(max)) nextValue = Math.min(max, nextValue);
|
|
|
|
|
deps.state.nicknameInput = formatSteppedNumber(nextValue, step);
|
|
|
|
|
deps.state.cursorPos = deps.state.nicknameInput.length;
|
|
|
|
|
deps.setReplaceTextOnNextType(false);
|
2026-02-22 23:51:13 -05:00
|
|
|
deps.onPreviewPropertyChange?.(item, propertyKey, nextValue);
|
2026-02-22 17:05:36 -05:00
|
|
|
deps.updateStatus(deps.state.nicknameInput);
|
|
|
|
|
if (Math.abs(nextValue - currentValue) < 1e-9 || Math.abs(nextValue - attempted) > 1e-9) {
|
|
|
|
|
deps.sfxUiCancel();
|
|
|
|
|
} else {
|
|
|
|
|
deps.sfxUiBlip();
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const editAction = getEditSessionAction(code);
|
|
|
|
|
if (editAction === 'submit') {
|
|
|
|
|
const value = deps.state.nicknameInput.trim();
|
2026-02-24 02:49:17 -05:00
|
|
|
const metadata = deps.getItemPropertyMetadata(item.type, propertyKey);
|
|
|
|
|
const valueType = metadata?.valueType;
|
2026-02-22 17:05:36 -05:00
|
|
|
const sendItemParams = (params: Record<string, unknown>): void => {
|
|
|
|
|
deps.signalingSend({ type: 'item_update', itemId, params });
|
2026-02-22 23:51:13 -05:00
|
|
|
for (const [key, nextValue] of Object.entries(params)) {
|
|
|
|
|
deps.onPreviewPropertyChange?.(item, key, nextValue);
|
|
|
|
|
}
|
2026-02-22 17:05:36 -05:00
|
|
|
};
|
|
|
|
|
const parseToggleValue = (raw: string, field: string): { ok: true; value: boolean } | { ok: false } => {
|
|
|
|
|
const normalized = raw.toLowerCase();
|
|
|
|
|
if (!['on', 'off', 'true', 'false', '1', '0', 'yes', 'no'].includes(normalized)) {
|
|
|
|
|
deps.updateStatus(`${field} must be on or off.`);
|
|
|
|
|
deps.sfxUiCancel();
|
|
|
|
|
return { ok: false };
|
|
|
|
|
}
|
|
|
|
|
return { ok: true, value: ['on', 'true', '1', 'yes'].includes(normalized) };
|
|
|
|
|
};
|
2026-02-24 02:49:17 -05:00
|
|
|
const submitNumericParam = (targetKey: string): boolean => {
|
|
|
|
|
const parsed = deps.validateNumericItemPropertyInput(item, targetKey, value, false);
|
2026-02-22 17:05:36 -05:00
|
|
|
if (!parsed.ok) {
|
|
|
|
|
deps.updateStatus(parsed.message);
|
|
|
|
|
deps.sfxUiCancel();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2026-02-24 02:49:17 -05:00
|
|
|
sendItemParams({ [targetKey]: parsed.value });
|
2026-02-22 17:05:36 -05:00
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
if (propertyKey === 'title') {
|
|
|
|
|
if (!value) {
|
|
|
|
|
deps.updateStatus('Value is required.');
|
|
|
|
|
deps.sfxUiCancel();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
deps.signalingSend({ type: 'item_update', itemId, title: value });
|
2026-02-24 02:49:17 -05:00
|
|
|
} else if (valueType === 'boolean') {
|
2026-02-22 17:05:36 -05:00
|
|
|
const toggle = parseToggleValue(value, propertyKey);
|
|
|
|
|
if (!toggle.ok) return;
|
|
|
|
|
sendItemParams({ [propertyKey]: toggle.value });
|
2026-02-24 02:49:17 -05:00
|
|
|
} else if (valueType === 'number') {
|
|
|
|
|
if (!submitNumericParam(propertyKey)) return;
|
|
|
|
|
} else if (valueType === 'list') {
|
|
|
|
|
const options = deps.getItemPropertyOptionValues(propertyKey) ?? [];
|
|
|
|
|
if (options.length === 0) {
|
|
|
|
|
deps.updateStatus(`${deps.itemPropertyLabel(propertyKey)} has no options.`);
|
2026-02-22 17:05:36 -05:00
|
|
|
deps.sfxUiCancel();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-02-24 02:49:17 -05:00
|
|
|
const normalized = value.toLowerCase();
|
|
|
|
|
const matched = options.find((option) => option.toLowerCase() === normalized);
|
|
|
|
|
if (!matched) {
|
|
|
|
|
deps.updateStatus(`${deps.itemPropertyLabel(propertyKey)} must be one of: ${options.join(', ')}.`);
|
2026-02-22 17:05:36 -05:00
|
|
|
deps.sfxUiCancel();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-02-24 02:49:17 -05:00
|
|
|
sendItemParams({ [propertyKey]: matched });
|
|
|
|
|
} else {
|
|
|
|
|
if (metadata?.maxLength !== undefined && value.length > metadata.maxLength) {
|
|
|
|
|
deps.updateStatus(`${deps.itemPropertyLabel(propertyKey)} must be ${metadata.maxLength} characters or less.`);
|
2026-02-22 17:05:36 -05:00
|
|
|
deps.sfxUiCancel();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-02-24 02:49:17 -05:00
|
|
|
sendItemParams({ [propertyKey]: value });
|
2026-02-22 17:05:36 -05:00
|
|
|
}
|
|
|
|
|
deps.state.mode = 'itemProperties';
|
|
|
|
|
deps.state.editingPropertyKey = null;
|
|
|
|
|
deps.setReplaceTextOnNextType(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (editAction === 'cancel') {
|
|
|
|
|
deps.state.mode = 'itemProperties';
|
|
|
|
|
deps.state.editingPropertyKey = null;
|
|
|
|
|
deps.setReplaceTextOnNextType(false);
|
|
|
|
|
deps.updateStatus('Cancelled.');
|
|
|
|
|
deps.sfxUiCancel();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-02-24 02:49:17 -05:00
|
|
|
const maxLength = deps.getItemPropertyMetadata(item.type, propertyKey)?.maxLength ?? 500;
|
|
|
|
|
deps.applyTextInputEdit(code, key, maxLength, ctrlKey, true);
|
2026-02-22 17:05:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleItemPropertyOptionSelectModeInput(code: string, key: string): void {
|
|
|
|
|
const itemId = deps.state.selectedItemId;
|
|
|
|
|
const propertyKey = deps.state.editingPropertyKey;
|
|
|
|
|
if (!itemId || !propertyKey || deps.state.itemPropertyOptionValues.length === 0) {
|
|
|
|
|
deps.state.mode = 'itemProperties';
|
|
|
|
|
deps.state.editingPropertyKey = null;
|
|
|
|
|
deps.state.itemPropertyOptionValues = [];
|
|
|
|
|
deps.state.itemPropertyOptionIndex = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const control = handleListControlKey(
|
|
|
|
|
code,
|
|
|
|
|
key,
|
|
|
|
|
deps.state.itemPropertyOptionValues,
|
|
|
|
|
deps.state.itemPropertyOptionIndex,
|
|
|
|
|
(value) => value,
|
|
|
|
|
);
|
|
|
|
|
if (control.type === 'move') {
|
|
|
|
|
deps.state.itemPropertyOptionIndex = control.index;
|
|
|
|
|
deps.updateStatus(deps.state.itemPropertyOptionValues[deps.state.itemPropertyOptionIndex]);
|
|
|
|
|
deps.sfxUiBlip();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (control.type === 'select') {
|
|
|
|
|
const selectedValue = deps.state.itemPropertyOptionValues[deps.state.itemPropertyOptionIndex];
|
|
|
|
|
deps.signalingSend({ type: 'item_update', itemId, params: { [propertyKey]: selectedValue } });
|
2026-02-22 23:51:13 -05:00
|
|
|
const item = deps.state.items.get(itemId);
|
|
|
|
|
if (item) {
|
|
|
|
|
deps.onPreviewPropertyChange?.(item, propertyKey, selectedValue);
|
|
|
|
|
}
|
2026-02-22 17:05:36 -05:00
|
|
|
deps.state.mode = 'itemProperties';
|
|
|
|
|
deps.state.editingPropertyKey = null;
|
|
|
|
|
deps.state.itemPropertyOptionValues = [];
|
|
|
|
|
deps.state.itemPropertyOptionIndex = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (control.type === 'cancel') {
|
|
|
|
|
deps.state.mode = 'itemProperties';
|
|
|
|
|
deps.state.editingPropertyKey = null;
|
|
|
|
|
deps.state.itemPropertyOptionValues = [];
|
|
|
|
|
deps.state.itemPropertyOptionIndex = 0;
|
|
|
|
|
deps.updateStatus('Cancelled.');
|
|
|
|
|
deps.sfxUiCancel();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
handleItemPropertiesModeInput,
|
|
|
|
|
handleItemPropertyEditModeInput,
|
|
|
|
|
handleItemPropertyOptionSelectModeInput,
|
|
|
|
|
};
|
|
|
|
|
}
|