Skip to content
Merged

4.6.6 #662

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webgal-terre",
"version": "4.6.5",
"version": "4.6.6",
"private": true,
"scripts": {
"dev": "concurrently -n terre,origine,dev-server -c cyan,green,magenta \"yarn dev:terre\" \"yarn dev:origine\" \"yarn dev:start-dev-server\"",
Expand Down
30 changes: 30 additions & 0 deletions packages/editor-preview-protocol/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,21 @@ export interface SetEffectPayload {
phase?: SetEffectPhase;
}

/**
* 把动画在 time 时刻的状态写入目标,仅用于预览,不写入舞台状态。
* animation 为动画 JSON(v1 关键帧数组或 v2 对象)
*/
export interface SeekAnimationPayload {
target: string;
animation: JsonValue;
time: number;
/**
* 动画开始前目标的状态,与默认变换合并后作为当前基准状态。
* 缺省时取带 transformBaselineRevision 的 sync-scene 记录的目标语句执行前的变换,再缺省时取演算状态中的变换
*/
baseTransform?: Transform;
}

export interface SetFontOptimizationPayload {
enabled: boolean;
}
Expand Down Expand Up @@ -193,6 +208,7 @@ export const PREVIEW_COMMAND_PAYLOADS = definePayloadMap({
'preview.command.set-component-visibility': payload<SetComponentVisibilityPayload>(),
'preview.command.set-font-optimization': payload<SetFontOptimizationPayload>(),
'preview.command.set-text-read-mode': payload<SetTextReadModePayload>(),
'preview.command.seek-animation': payload<SeekAnimationPayload>(),
});

export type PreviewCommandPayloadByType = typeof PREVIEW_COMMAND_PAYLOADS;
Expand Down Expand Up @@ -258,6 +274,16 @@ export interface RegisterPreviewRequestPayload {
embeddedLaunchId?: string;
}

/**
* 独占预览:embeddedLaunchId 带有此前缀的嵌入式预览只听从指定了它的命令(见 RequestEnvelope.embeddedLaunchId),
* 不接收广播,它发出的事件转发给编辑器时会带上 embeddedLaunchId。用于动画编辑器等自带预览窗口的场合
*/
export const DEDICATED_PREVIEW_LAUNCH_ID_PREFIX = 'dedicated:';

export function isDedicatedPreviewLaunchId(embeddedLaunchId: string | undefined): boolean {
return embeddedLaunchId?.startsWith(DEDICATED_PREVIEW_LAUNCH_ID_PREFIX) ?? false;
}

export const SESSION_REQUEST_PAYLOADS = definePayloadMap({
[SESSION_REGISTER_PREVIEW_TYPE]: payload<RegisterPreviewRequestPayload>(),
});
Expand Down Expand Up @@ -325,13 +351,17 @@ export interface EventEnvelope<TPayload = unknown, TType extends string = string
kind: 'event';
type: TType;
payload: TPayload;
/** 事件来自哪个独占预览;来自普通预览时缺省 */
embeddedLaunchId?: string;
}

export interface RequestEnvelope<TPayload = unknown, TType extends string = string> {
kind: 'request';
type: TType;
requestId: string;
payload: TPayload;
/** 只发给这个独占预览;缺省时广播给普通预览 */
embeddedLaunchId?: string;
}

export interface ResponseEnvelope<TPayload = unknown, TType extends string = string> {
Expand Down
3 changes: 2 additions & 1 deletion packages/origine2/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "webgal-origine-2",
"private": true,
"version": "4.6.5",
"version": "4.6.6",
"license": "MPL-2.0",
"scripts": {
"sync:editor-preview-protocol": "yarn workspace @webgal/editor-preview-protocol build",
Expand Down Expand Up @@ -54,6 +54,7 @@
"monaco-textmate": "^3.0.1",
"natural-compare-lite": "^1.4.0",
"onigasm": "^2.2.5",
"popmotion": "^11.0.5",
"primereact": "^9.5.0",
"react": "^18.0.0",
"react-dom": "^18.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/origine2/src/components/Assets/Assets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export interface IFile {
lastModified?: number;
}

interface IAssetsReadResponse {
export interface IAssetsReadResponse {
dirInfo?: IFile[];
}

Expand Down
38 changes: 38 additions & 0 deletions packages/origine2/src/hooks/useHiddenAnimationFiles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { useMemo } from 'react';
import useSWR from 'swr';
import axios from 'axios';
import { api } from '@/api';
import useEditorStore from '@/store/useEditorStore';
import type { IAssetsReadResponse } from '@/components/Assets/Assets';

/**
* 选择动画时需要隐藏的文件(相对于 animation 目录):动画表,以及 v1 动画。
*
* v1 动画(顶层为关键帧数组)只为兼容旧脚本保留,不再推荐使用:资源管理器中照常显示,
* 但在明确选择动画的地方隐藏。只检查 animation 目录的第一层
*/
export function useHiddenAnimationFiles(): string[] {
const gameDir = useEditorStore.use.subPage();
const { data: v1Animations } = useSWR(`v1-animation-files-${gameDir}`, () => fetchV1AnimationFiles(gameDir));
return useMemo(() => ['animationTable.json', ...(v1Animations ?? [])], [v1Animations]);
}

async function fetchV1AnimationFiles(gameDir: string): Promise<string[]> {
const animationDir = `games/${gameDir}/game/animation`;
const res = await api.assetsControllerReadAssets(animationDir);
const { dirInfo = [] } = res.data as unknown as IAssetsReadResponse;
const animationFiles = dirInfo.filter(
(file) => !file.isDir && file.name.toLowerCase().endsWith('.json') && file.name !== 'animationTable.json',
);
const isV1List = await Promise.all(animationFiles.map((file) => isV1Animation(`/${animationDir}/${file.name}`)));
return animationFiles.filter((_, index) => isV1List[index]).map((file) => file.name);
}

async function isV1Animation(url: string): Promise<boolean> {
try {
const res = await axios.get(url);
return Array.isArray(res.data);
} catch {
return false;
}
}
Loading
Loading