|
1 | | -import { Scene } from '/src/engine/scene/index.js'; import { drawFrame, drawPanel } from '/src/engine/debug/index.js'; import { Theme, ThemeTokens } from '/src/engine/theme/index.js'; import { TexturePreprocessPipeline } from '/tools/shared/pipeline/index.js'; import { drawSpriteProjectFrame, loadSpriteProjectPreset } from '/samples/shared/spritePresetRuntime.js'; |
| 1 | +import { Scene } from "/src/engine/scene/index.js"; |
| 2 | +import { drawFrame, drawPanel } from "/src/engine/debug/index.js"; |
| 3 | +import { Theme, ThemeTokens } from "/src/engine/theme/index.js"; |
| 4 | +import { TexturePreprocessPipeline } from "/tools/shared/pipeline/index.js"; |
| 5 | +import { drawSpriteProjectFrame, loadSpriteProjectPreset } from "/samples/shared/spritePresetRuntime.js"; |
| 6 | + |
2 | 7 | const theme = new Theme(ThemeTokens); |
3 | | -const SPRITE_PRESET_PATH = '/samples/phase-14/1414/sample-1414-sprite-editor.json'; |
| 8 | +const SPRITE_PRESET_PATH = "/samples/phase-14/1414/sample-1414-sprite-editor.json"; |
| 9 | + |
4 | 10 | export default class TextureSpritePreprocessPipelineScene extends Scene { |
5 | | - constructor() { super(); this.pipeline = new TexturePreprocessPipeline(); this.texture = null; this.status = 'Preprocess a texture record.'; this.spriteProject = null; this.spriteStatus = 'loading'; this.spriteError = ''; void this.loadSpriteProject(); } |
6 | | - async loadSpriteProject() { try { this.spriteProject = await loadSpriteProjectPreset(SPRITE_PRESET_PATH); this.spriteStatus = 'loaded'; this.spriteError = ''; } catch (error) { this.spriteProject = null; this.spriteStatus = 'fallback'; this.spriteError = error instanceof Error ? error.message : 'unknown preset error'; } } |
7 | | - run() { this.texture = this.pipeline.run({ width: 64, height: 32 }); this.status = 'Texture preprocessing complete.'; } |
| 11 | + constructor() { |
| 12 | + super(); |
| 13 | + this.pipeline = new TexturePreprocessPipeline(); |
| 14 | + this.texture = null; |
| 15 | + this.status = "Preprocess a texture record."; |
| 16 | + this.spriteProject = null; |
| 17 | + this.spriteStatus = "loading"; |
| 18 | + this.spriteError = ""; |
| 19 | + void this.loadSpriteProject(); |
| 20 | + } |
| 21 | + |
| 22 | + async loadSpriteProject() { |
| 23 | + try { |
| 24 | + this.spriteProject = await loadSpriteProjectPreset(SPRITE_PRESET_PATH); |
| 25 | + this.spriteStatus = "loaded"; |
| 26 | + this.spriteError = ""; |
| 27 | + } catch (error) { |
| 28 | + this.spriteProject = null; |
| 29 | + this.spriteStatus = "fallback"; |
| 30 | + this.spriteError = error instanceof Error ? error.message : "unknown preset error"; |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + run() { |
| 35 | + this.texture = this.pipeline.run({ width: 64, height: 32 }); |
| 36 | + this.status = "Texture preprocessing complete."; |
| 37 | + } |
| 38 | + |
8 | 39 | render(renderer) { |
9 | | - const presetStatus = this.spriteStatus === 'loaded' |
10 | | - ? 'Sprite preset loaded from sample-1414-sprite-editor.json' |
11 | | - : this.spriteStatus === 'loading' |
12 | | - ? 'Loading shared sprite preset...' |
13 | | - : `Sprite preset unavailable (${this.spriteError || 'using pipeline-only view'})`; |
14 | | - drawFrame(renderer, theme, ['Engine Sample 1414', 'Texture preprocessing normalizes visual content in one centralized step.', 'This sample and Sprite Editor load the same sample-1414-sprite-editor.json source.', this.status, presetStatus]); |
15 | | - drawPanel(renderer, 120, 220, 540, 220, 'Texture Output', [`Width: ${this.texture?.width ?? 0}`, `Height: ${this.texture?.height ?? 0}`, `Padded: ${this.texture?.padded ?? false}`, `Atlas Ready: ${this.texture?.atlasReady ?? false}`, `Preset Frames: ${this.spriteProject?.frames?.length ?? 0}`]); |
16 | | - if (this.spriteProject) { |
17 | | - drawSpriteProjectFrame(renderer, this.spriteProject, 0, { x: 690, y: 260, pixelSize: 4 }); |
18 | | - drawPanel(renderer, 660, 220, 240, 220, 'Sprite Preset Preview', ['Frame source: sample-1414-sprite-editor.json', `Size: ${this.spriteProject.width}x${this.spriteProject.height}`, 'Edit in Sprite Editor, then relaunch sample.']); |
| 40 | + const presetStatus = this.spriteStatus === "loaded" |
| 41 | + ? "Sprite preset loaded from sample-1414-sprite-editor.json" |
| 42 | + : this.spriteStatus === "loading" |
| 43 | + ? "Loading shared sprite preset..." |
| 44 | + : `Sprite preset unavailable (${this.spriteError || "using pipeline-only view"})`; |
| 45 | + |
| 46 | + drawFrame(renderer, theme, [ |
| 47 | + "Engine Sample 1414", |
| 48 | + "Texture preprocessing normalizes visual content in one centralized step.", |
| 49 | + "This sample and Sprite Editor load the same sample-1414-sprite-editor.json source.", |
| 50 | + this.status, |
| 51 | + presetStatus |
| 52 | + ]); |
| 53 | + |
| 54 | + drawPanel(renderer, 120, 220, 540, 220, "Texture Output", [ |
| 55 | + `Width: ${this.texture?.width ?? 0}`, |
| 56 | + `Height: ${this.texture?.height ?? 0}`, |
| 57 | + `Padded: ${this.texture?.padded ?? false}`, |
| 58 | + `Atlas Ready: ${this.texture?.atlasReady ?? false}`, |
| 59 | + `Preset Frames: ${this.spriteProject?.frames?.length ?? 0}` |
| 60 | + ]); |
| 61 | + |
| 62 | + if (!this.spriteProject) { |
| 63 | + return; |
19 | 64 | } |
| 65 | + |
| 66 | + const previewPanel = { x: 660, y: 220, width: 240, height: 220 }; |
| 67 | + drawPanel(renderer, previewPanel.x, previewPanel.y, previewPanel.width, previewPanel.height, "Sprite Preset Preview", [ |
| 68 | + "Frame source: sample-1414-sprite-editor.json", |
| 69 | + `Size: ${this.spriteProject.width}x${this.spriteProject.height}`, |
| 70 | + "Edit in Sprite Editor, then relaunch sample." |
| 71 | + ]); |
| 72 | + |
| 73 | + drawSpriteProjectFrame(renderer, this.spriteProject, 0, { |
| 74 | + x: previewPanel.x + 16, |
| 75 | + y: previewPanel.y + 98, |
| 76 | + pixelSize: 4 |
| 77 | + }); |
20 | 78 | } |
21 | 79 | } |
0 commit comments