Refactor sequence steps to distinguish held and impulse types
This commit is contained in:
@@ -8,52 +8,70 @@ import {
|
|||||||
} from "../interactions/interaction-links";
|
} from "../interactions/interaction-links";
|
||||||
import type { ProjectScheduleRoutine } from "../scheduler/project-scheduler";
|
import type { ProjectScheduleRoutine } from "../scheduler/project-scheduler";
|
||||||
|
|
||||||
export interface ControlSequenceStep {
|
export interface HeldControlSequenceStep {
|
||||||
|
stepClass: "held";
|
||||||
|
type: "controlEffect";
|
||||||
|
effect: ControlEffect;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ImpulseControlSequenceStep {
|
||||||
|
stepClass: "impulse";
|
||||||
type: "controlEffect";
|
type: "controlEffect";
|
||||||
effect: ControlEffect;
|
effect: ControlEffect;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface StartDialogueSequenceStep {
|
export interface StartDialogueSequenceStep {
|
||||||
|
stepClass: "impulse";
|
||||||
type: "startDialogue";
|
type: "startDialogue";
|
||||||
dialogueId: string;
|
dialogueId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TeleportPlayerSequenceStep {
|
export interface TeleportPlayerSequenceStep {
|
||||||
|
stepClass: "impulse";
|
||||||
type: "teleportPlayer";
|
type: "teleportPlayer";
|
||||||
targetEntityId: string;
|
targetEntityId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ToggleVisibilitySequenceStep {
|
export interface ToggleVisibilitySequenceStep {
|
||||||
|
stepClass: "impulse";
|
||||||
type: "toggleVisibility";
|
type: "toggleVisibility";
|
||||||
targetBrushId: string;
|
targetBrushId: string;
|
||||||
visible?: boolean;
|
visible?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SequenceStep =
|
export type HeldSequenceStep = HeldControlSequenceStep;
|
||||||
| ControlSequenceStep
|
|
||||||
|
export type ImpulseSequenceStep =
|
||||||
|
| ImpulseControlSequenceStep
|
||||||
| StartDialogueSequenceStep
|
| StartDialogueSequenceStep
|
||||||
| TeleportPlayerSequenceStep
|
| TeleportPlayerSequenceStep
|
||||||
| ToggleVisibilitySequenceStep;
|
| ToggleVisibilitySequenceStep;
|
||||||
|
|
||||||
|
export type SequenceStep = HeldSequenceStep | ImpulseSequenceStep;
|
||||||
|
|
||||||
export function cloneSequenceStep(step: SequenceStep): SequenceStep {
|
export function cloneSequenceStep(step: SequenceStep): SequenceStep {
|
||||||
switch (step.type) {
|
switch (step.type) {
|
||||||
case "controlEffect":
|
case "controlEffect":
|
||||||
return {
|
return {
|
||||||
|
stepClass: step.stepClass,
|
||||||
type: "controlEffect",
|
type: "controlEffect",
|
||||||
effect: cloneControlEffect(step.effect)
|
effect: cloneControlEffect(step.effect)
|
||||||
};
|
};
|
||||||
case "startDialogue":
|
case "startDialogue":
|
||||||
return {
|
return {
|
||||||
|
stepClass: "impulse",
|
||||||
type: "startDialogue",
|
type: "startDialogue",
|
||||||
dialogueId: step.dialogueId
|
dialogueId: step.dialogueId
|
||||||
};
|
};
|
||||||
case "teleportPlayer":
|
case "teleportPlayer":
|
||||||
return {
|
return {
|
||||||
|
stepClass: "impulse",
|
||||||
type: "teleportPlayer",
|
type: "teleportPlayer",
|
||||||
targetEntityId: step.targetEntityId
|
targetEntityId: step.targetEntityId
|
||||||
};
|
};
|
||||||
case "toggleVisibility":
|
case "toggleVisibility":
|
||||||
return {
|
return {
|
||||||
|
stepClass: "impulse",
|
||||||
type: "toggleVisibility",
|
type: "toggleVisibility",
|
||||||
targetBrushId: step.targetBrushId,
|
targetBrushId: step.targetBrushId,
|
||||||
visible: step.visible
|
visible: step.visible
|
||||||
@@ -65,14 +83,15 @@ export function cloneSequenceSteps(steps: SequenceStep[]): SequenceStep[] {
|
|||||||
return steps.map(cloneSequenceStep);
|
return steps.map(cloneSequenceStep);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getInteractionLinkSequenceSteps(
|
export function getInteractionLinkImpulseSteps(
|
||||||
link: InteractionLink
|
link: InteractionLink
|
||||||
): SequenceStep[] {
|
): ImpulseSequenceStep[] {
|
||||||
const controlEffect = getInteractionActionControlEffect(link.action);
|
const controlEffect = getInteractionActionControlEffect(link.action);
|
||||||
|
|
||||||
if (controlEffect !== null) {
|
if (controlEffect !== null) {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
stepClass: "impulse",
|
||||||
type: "controlEffect",
|
type: "controlEffect",
|
||||||
effect: controlEffect
|
effect: controlEffect
|
||||||
}
|
}
|
||||||
@@ -83,6 +102,7 @@ export function getInteractionLinkSequenceSteps(
|
|||||||
case "teleportPlayer":
|
case "teleportPlayer":
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
stepClass: "impulse",
|
||||||
type: "teleportPlayer",
|
type: "teleportPlayer",
|
||||||
targetEntityId: link.action.targetEntityId
|
targetEntityId: link.action.targetEntityId
|
||||||
}
|
}
|
||||||
@@ -90,6 +110,7 @@ export function getInteractionLinkSequenceSteps(
|
|||||||
case "toggleVisibility":
|
case "toggleVisibility":
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
stepClass: "impulse",
|
||||||
type: "toggleVisibility",
|
type: "toggleVisibility",
|
||||||
targetBrushId: link.action.targetBrushId,
|
targetBrushId: link.action.targetBrushId,
|
||||||
visible: link.action.visible
|
visible: link.action.visible
|
||||||
@@ -98,6 +119,7 @@ export function getInteractionLinkSequenceSteps(
|
|||||||
case "startDialogue":
|
case "startDialogue":
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
stepClass: "impulse",
|
||||||
type: "startDialogue",
|
type: "startDialogue",
|
||||||
dialogueId: link.action.dialogueId
|
dialogueId: link.action.dialogueId
|
||||||
}
|
}
|
||||||
@@ -113,11 +135,46 @@ export function getInteractionLinkSequenceSteps(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getProjectScheduleRoutineSequenceSteps(
|
export function getInteractionLinkSequenceSteps(
|
||||||
routine: ProjectScheduleRoutine
|
link: InteractionLink
|
||||||
): SequenceStep[] {
|
): SequenceStep[] {
|
||||||
|
return getInteractionLinkImpulseSteps(link);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getProjectScheduleRoutineHeldSteps(
|
||||||
|
routine: ProjectScheduleRoutine
|
||||||
|
): HeldSequenceStep[] {
|
||||||
return routine.effects.map((effect) => ({
|
return routine.effects.map((effect) => ({
|
||||||
|
stepClass: "held" as const,
|
||||||
type: "controlEffect" as const,
|
type: "controlEffect" as const,
|
||||||
effect: cloneControlEffect(effect)
|
effect: cloneControlEffect(effect)
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getProjectScheduleRoutineSequenceSteps(
|
||||||
|
routine: ProjectScheduleRoutine
|
||||||
|
): SequenceStep[] {
|
||||||
|
return getProjectScheduleRoutineHeldSteps(routine);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getHeldSequenceControlEffects(
|
||||||
|
steps: readonly HeldSequenceStep[]
|
||||||
|
): ControlEffect[] {
|
||||||
|
return steps
|
||||||
|
.filter((step): step is HeldControlSequenceStep => step.type === "controlEffect")
|
||||||
|
.map((step) => cloneControlEffect(step.effect));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function findHeldSequenceControlEffect<
|
||||||
|
TType extends ControlEffect["type"]
|
||||||
|
>(
|
||||||
|
steps: readonly HeldSequenceStep[],
|
||||||
|
type: TType
|
||||||
|
): Extract<ControlEffect, { type: TType }> | null {
|
||||||
|
return (
|
||||||
|
getHeldSequenceControlEffects(steps).find(
|
||||||
|
(effect): effect is Extract<ControlEffect, { type: TType }> =>
|
||||||
|
effect.type === type
|
||||||
|
) ?? null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user