26 lines
1.7 KiB
TypeScript
26 lines
1.7 KiB
TypeScript
import type { WebEngineEditCommand } from "./web-engine";
|
|
|
|
type IOCommand<T extends WebEngineEditCommand["type"]> = Extract<WebEngineEditCommand, { type: T }>;
|
|
|
|
/** Typed constructors for media import and persistence-facing edit commands. */
|
|
export const ioMediaCommands = Object.freeze({
|
|
importImage(name: string, mimeType: IOCommand<"importImage">["mimeType"], width: number, height: number, base64: string): IOCommand<"importImage"> {
|
|
return { type: "importImage", name, mimeType, width, height, base64 };
|
|
},
|
|
setMaterialImageNode(materialId: string, imageId: string, usage: IOCommand<"setMaterialImageNode">["usage"], uvMap?: string): IOCommand<"setMaterialImageNode"> {
|
|
return { type: "setMaterialImageNode", materialId, imageId, usage, ...(uvMap ? { uvMap } : {}) };
|
|
},
|
|
setSoundProperties(dataId: string, properties: IOCommand<"setSoundProperties">["properties"]): IOCommand<"setSoundProperties"> {
|
|
return { type: "setSoundProperties", dataId, properties: { ...properties } };
|
|
},
|
|
setSpeakerProperties(dataId: string, properties: IOCommand<"setSpeakerProperties">["properties"]): IOCommand<"setSpeakerProperties"> {
|
|
return { type: "setSpeakerProperties", dataId, properties: { ...properties } };
|
|
},
|
|
setParticleSettings(dataId: string, properties: IOCommand<"setParticleSettings">["properties"]): IOCommand<"setParticleSettings"> {
|
|
return { type: "setParticleSettings", dataId, properties: { ...properties } };
|
|
},
|
|
setTextureProperties(dataId: string, properties: IOCommand<"setTextureProperties">["properties"]): IOCommand<"setTextureProperties"> {
|
|
return { type: "setTextureProperties", dataId, properties: { ...properties } };
|
|
},
|
|
} satisfies Record<string, (...args: never[]) => WebEngineEditCommand>);
|