Refactor type handling in scripts and add player start look/target button controls

This commit is contained in:
2026-04-27 16:03:41 +02:00
parent 9d435f52ab
commit 8496d99aec
2 changed files with 28 additions and 21 deletions

View File

@@ -324,14 +324,6 @@ function getTypeKey(type: ts.Type): string {
);
}
function getTypeLabel(type: ts.Type): string {
try {
return checker.typeToString(type);
} catch {
return getTypeKey(type);
}
}
function isCallableType(type: ts.Type): boolean {
const normalizedType = withoutNullish(type);
return normalizedType.getCallSignatures().length > 0;
@@ -389,10 +381,11 @@ function literalLabel(type: ts.Type): string | null {
return String(type.value);
}
const typeText = checker.typeToString(type);
const intrinsicName = (type as ts.Type & { intrinsicName?: string })
.intrinsicName;
if (typeText === "true" || typeText === "false") {
return typeText;
if (intrinsicName === "true" || intrinsicName === "false") {
return intrinsicName;
}
return null;
@@ -610,7 +603,9 @@ function collectUnionFields(
const typeLabels = objectTypes.map((objectType) => {
const propertyType = getPropertyType(objectType, name);
return propertyType === null ? "" : getTypeLabel(propertyType);
return propertyType === null
? ""
: getTypeKey(withoutNullish(propertyType));
});
return new Set(typeLabels).size === 1;
@@ -635,7 +630,7 @@ function collectUnionFields(
? ""
: literalUnionLabels(discriminatorType)[0] ?? "";
const groupKey =
discriminator === null ? getTypeLabel(objectType) : discriminatorValue;
discriminator === null ? getTypeKey(objectType) : discriminatorValue;
groupedTypes.set(groupKey, [...(groupedTypes.get(groupKey) ?? []), objectType]);
}

View File

@@ -8887,10 +8887,12 @@ export function App({ store, initialStatusMessage }: AppProps) {
const applyPlayerStartChange = (
overrides: {
allowLookInputTargetSwitch?: boolean;
colliderMode?: PlayerStartColliderMode;
movementTemplate?: PlayerStartMovementTemplate;
navigationMode?: PlayerStartNavigationMode;
inputBindings?: PlayerStartInputBindings;
targetButtonCyclesActiveTarget?: boolean;
} = {}
) => {
if (selectedPlayerStart === null) {
@@ -8920,6 +8922,12 @@ export function App({ store, initialStatusMessage }: AppProps) {
playerStartInteractionAngleDraft,
"Player Start interaction angle"
);
const allowLookInputTargetSwitch =
overrides.allowLookInputTargetSwitch ??
playerStartAllowLookInputTargetSwitchDraft;
const targetButtonCyclesActiveTarget =
overrides.targetButtonCyclesActiveTarget ??
playerStartTargetButtonCyclesActiveTargetDraft;
const nextEntity = createPlayerStartEntity({
id: selectedPlayerStart.id,
name: selectedPlayerStart.name,
@@ -8928,10 +8936,8 @@ export function App({ store, initialStatusMessage }: AppProps) {
navigationMode,
interactionReachMeters,
interactionAngleDegrees,
allowLookInputTargetSwitch:
playerStartAllowLookInputTargetSwitchDraft,
targetButtonCyclesActiveTarget:
playerStartTargetButtonCyclesActiveTargetDraft,
allowLookInputTargetSwitch,
targetButtonCyclesActiveTarget,
movementTemplate,
inputBindings,
collider: {
@@ -20782,11 +20788,14 @@ export function App({ store, initialStatusMessage }: AppProps) {
playerStartAllowLookInputTargetSwitchDraft
}
onChange={(event) => {
const nextValue = event.currentTarget.checked;
setPlayerStartAllowLookInputTargetSwitchDraft(
event.currentTarget.checked
nextValue
);
scheduleDraftCommit(() =>
applyPlayerStartChange()
applyPlayerStartChange({
allowLookInputTargetSwitch: nextValue
})
);
}}
/>
@@ -20802,11 +20811,14 @@ export function App({ store, initialStatusMessage }: AppProps) {
playerStartTargetButtonCyclesActiveTargetDraft
}
onChange={(event) => {
const nextValue = event.currentTarget.checked;
setPlayerStartTargetButtonCyclesActiveTargetDraft(
event.currentTarget.checked
nextValue
);
scheduleDraftCommit(() =>
applyPlayerStartChange()
applyPlayerStartChange({
targetButtonCyclesActiveTarget: nextValue
})
);
}}
/>