-
Notifications
You must be signed in to change notification settings - Fork 4
feat(playtest): consolidate preview and quality workbench #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
xyh202131
wants to merge
5
commits into
1024XEngineer:main
Choose a base branch
from
xyh202131:feat/playtest-preview-quality-engine
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b852b44
feat(playtest): add backend data adapters
xyh202131 a7c2aa0
feat(playtest): add preview and quality engine
xyh202131 8f9abeb
feat(playtest): integrate catalog and review workbench
xyh202131 e36d970
fix(playtest): honor API success and pagination
xyh202131 4c70f79
feat(playtest): consolidate playable assets in workbench
xyh202131 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // @vitest-environment jsdom | ||
| import { cleanup, render, screen } from '@testing-library/react' | ||
| import { afterEach, describe, expect, it } from 'vitest' | ||
|
|
||
| import { App } from './app' | ||
|
|
||
| afterEach(() => { | ||
| cleanup() | ||
| window.history.replaceState({}, '', '/') | ||
| }) | ||
|
|
||
| describe('App Playtest route', () => { | ||
| it('routes /playtest to the standalone Playtest catalog', () => { | ||
| window.history.replaceState({}, '', '/playtest') | ||
|
|
||
| render(<App />) | ||
|
|
||
| expect(screen.getByRole('heading', { name: 'Playtest' })).toBeTruthy() | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import { afterEach, describe, expect, it, vi } from 'vitest' | ||
|
|
||
| import { createCharacterApis } from './api' | ||
|
|
||
| afterEach(() => { | ||
| vi.unstubAllGlobals() | ||
| }) | ||
|
|
||
| describe('character API adapter', () => { | ||
| it('preserves an action loop flag when saving the complete character tree', async () => { | ||
| const backendCharacter = { | ||
| id: 25, | ||
| project_id: 3, | ||
| description: null, | ||
| reference_image_url: null, | ||
| status: 1, | ||
| character_data: { | ||
| version: 1, | ||
| outfits: [ | ||
| { | ||
| id: 'outfit-default', | ||
| name: 'Default', | ||
| description: null, | ||
| preview_url: null, | ||
| actions: [ | ||
| { | ||
| id: 'idle', | ||
| type: 'idle', | ||
| name: 'Idle', | ||
| loop: true, | ||
| fps: 8, | ||
| frame_count: 1, | ||
| frames: [ | ||
| { index: 0, image_url: '/idle-0.png', duration_ms: 125, root_motion: null }, | ||
| ], | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }, | ||
| } | ||
| const fetchMock = vi | ||
| .fn() | ||
| .mockResolvedValueOnce(jsonResponse(backendCharacter)) | ||
| .mockResolvedValueOnce(jsonResponse(backendCharacter)) | ||
| vi.stubGlobal('fetch', fetchMock) | ||
|
|
||
| const apis = createCharacterApis() | ||
| const character = await apis.get('25') | ||
| await apis.update(character) | ||
|
|
||
| expect(character.outfits[0]?.actions[0]?.loop).toBe(true) | ||
| const updateRequest = fetchMock.mock.calls[1]?.[1] as RequestInit | ||
| const updateBody = JSON.parse(String(updateRequest.body)) as { | ||
| character_data: { outfits: Array<{ actions: Array<{ loop: boolean }> }> } | ||
| } | ||
| expect(updateBody.character_data.outfits[0]?.actions[0]?.loop).toBe(true) | ||
| }) | ||
| }) | ||
|
|
||
| function jsonResponse(data: unknown) { | ||
| return new Response(JSON.stringify({ code: 200, message: 'success', data }), { | ||
| status: 200, | ||
| headers: { 'Content-Type': 'application/json' }, | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| import type { Action, ActionType, Character, CharacterApis, Frame, Outfit } from '.' | ||
|
|
||
| import { del, get, patch } from '@/shared/api' | ||
|
|
||
| /* ─── 后端 DTO ─── */ | ||
|
|
||
| interface BackendFrame { | ||
| index: number | ||
| image_url: string | ||
| duration_ms: number | null | ||
| root_motion?: { dx: number; dy: number } | null | ||
| } | ||
|
|
||
| interface BackendAction { | ||
| id: string | ||
| type: string | ||
| name: string | ||
| loop: boolean | ||
| fps: number | ||
| frame_count: number | ||
| frames: BackendFrame[] | ||
| } | ||
|
|
||
| interface BackendOutfit { | ||
| id: string | ||
| name: string | ||
| description: string | null | ||
| preview_url: string | null | ||
| actions: BackendAction[] | ||
| } | ||
|
|
||
| interface BackendCharacterData { | ||
| version: number | ||
| outfits: BackendOutfit[] | ||
| } | ||
|
|
||
| interface BackendCharacter { | ||
| id: number | ||
| project_id: number | ||
| description: string | null | ||
| reference_image_url: string | null | ||
| character_data: BackendCharacterData | ||
| status: number | ||
| } | ||
|
|
||
| /* ─── 映射 ─── */ | ||
|
|
||
| const ACTION_TYPE_SET = new Set<string>(['walk', 'idle', 'attack', 'jump', 'custom']) | ||
|
|
||
| function toActionType(raw: string): ActionType { | ||
| return ACTION_TYPE_SET.has(raw) ? (raw as ActionType) : 'custom' | ||
| } | ||
|
|
||
| function toFrame(raw: BackendFrame): Frame { | ||
| return { | ||
| imageUrl: raw.image_url, | ||
| durationMs: raw.duration_ms, | ||
| rootMotion: raw.root_motion ?? null, | ||
| } | ||
| } | ||
|
|
||
| function toAction(raw: BackendAction, outfitId: string): Action { | ||
| return { | ||
| id: raw.id, | ||
| outfitId, | ||
| name: raw.name, | ||
| loop: raw.loop, | ||
| kind: 'custom', // 后端不区分 preset/custom | ||
| type: toActionType(raw.type), | ||
| fps: raw.fps, | ||
| keyFrameIndex: null, // 后端不提供关键帧索引 | ||
| frames: raw.frames.sort((a, b) => a.index - b.index).map(toFrame), | ||
| } | ||
| } | ||
|
|
||
| function toOutfit(raw: BackendOutfit, characterId: string): Outfit { | ||
| return { | ||
| id: raw.id, | ||
| characterId, | ||
| name: raw.name, | ||
| candidateCharacterTemplates: [], // 后端 character_data 不含候选 | ||
| characterTemplateUrl: raw.preview_url, | ||
| baseFrames: [], | ||
| actions: raw.actions.map((a) => toAction(a, raw.id)), | ||
| } | ||
| } | ||
|
|
||
| function toCharacter(raw: BackendCharacter): Character { | ||
| const id = String(raw.id) | ||
| return { | ||
| id, | ||
| projectId: String(raw.project_id), | ||
| createdAt: '', // 后端列表不返回时间戳 | ||
| updatedAt: '', | ||
| outfits: (raw.character_data?.outfits ?? []).map((o) => toOutfit(o, id)), | ||
| } | ||
| } | ||
|
|
||
| /* ─── 适配器 ─── */ | ||
|
|
||
| export function createCharacterApis(): Pick< | ||
| CharacterApis, | ||
| 'get' | 'listByProject' | 'update' | 'remove' | ||
| > { | ||
| return { | ||
| async get(id: string): Promise<Character> { | ||
| const raw = await get<BackendCharacter>(`/characters/${id}`) | ||
| return toCharacter(raw) | ||
| }, | ||
|
|
||
| async listByProject(projectId: string): Promise<Character[]> { | ||
| // http-client 已解包 ApiEnvelope,data 字段就是角色数组本身 | ||
| const raw = await get<BackendCharacter[]>( | ||
| `/characters?project_id=${encodeURIComponent(projectId)}&page_size=100`, | ||
| ) | ||
| return raw.map(toCharacter) | ||
| }, | ||
|
|
||
| async update(character: Character): Promise<Character> { | ||
| const payload = { | ||
| project_id: Number(character.projectId), | ||
| character_data: { | ||
| version: 1, | ||
| outfits: character.outfits.map((outfit) => ({ | ||
| id: outfit.id, | ||
| name: outfit.name, | ||
| description: null, | ||
| preview_url: outfit.characterTemplateUrl, | ||
| actions: outfit.actions.map((action) => ({ | ||
| id: action.id, | ||
| type: action.type, | ||
| name: action.name, | ||
| loop: action.loop ?? false, | ||
| fps: action.fps, | ||
| frame_count: action.frames.length, | ||
| frames: action.frames.map((frame, index) => ({ | ||
| index, | ||
| image_url: frame.imageUrl, | ||
| duration_ms: frame.durationMs, | ||
| root_motion: frame.rootMotion, | ||
| })), | ||
| })), | ||
| })), | ||
| }, | ||
| } | ||
| const raw = await patch<BackendCharacter>(`/characters/${character.id}`, payload) | ||
| const saved = toCharacter(raw) | ||
| if (saved.projectId !== character.projectId) { | ||
| throw new Error('后端未保存新的项目归属') | ||
| } | ||
| return saved | ||
| }, | ||
|
|
||
| async remove(id: string): Promise<void> { | ||
| await del(`/characters/${id}`) | ||
| }, | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.