Images are uploaded to a content-addressed blob endpoint and stored as data/textures/<sha256>.<ext>; the project only keeps the file name. The sprite points at a texture asset through an ordinary property of the new kind `asset`, so instance overrides, "Apply to container", "Reset to asset", undo and `Set property` work without any extra code. The new kind also replaces the ad-hoc asset picker the graph nodes faked as an enum. Import goes through + -> Texture, drag & drop onto the canvas or Ctrl+V. Images wider than 2048px are downscaled client-side and re-encoded to WebP if needed, because nginx caps uploads at 1MB; an image that already fits is uploaded byte for byte so pixel art is never resampled. The sprite colour default changes from red to white, since colour tints the texture multiplicatively and a tint of white shows an image as it is. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
43 lines
2.0 KiB
TypeScript
43 lines
2.0 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
||
import { CreateTextureCommand } from '../../src/core/commands/assetCommands';
|
||
import { CommandError } from '../../src/core/commands/Command';
|
||
import { isTextureAsset } from '../../src/core/model/Asset';
|
||
import { findAsset } from '../../src/core/model/Project';
|
||
import { makeProject } from '../helpers';
|
||
|
||
const FILE = `${'b'.repeat(64)}.webp`;
|
||
|
||
describe('CreateTextureCommand', () => {
|
||
it('adds a texture asset carrying the uploaded image, and removes it again', () => {
|
||
const { project, stack } = makeProject();
|
||
const command = new CreateTextureCommand('Hero', { file: FILE, width: 64, height: 32 });
|
||
stack.execute(command);
|
||
|
||
const asset = findAsset(project, command.asset.id);
|
||
expect(asset && isTextureAsset(asset)).toBe(true);
|
||
expect(asset).toMatchObject({ type: 'texture', name: 'Hero', file: FILE, width: 64, height: 32 });
|
||
// The schema default comes along, so the new texture is a complete asset – nothing to fill in later.
|
||
expect(asset?.props).toEqual({ filter: 'linear' });
|
||
|
||
stack.undo();
|
||
expect(project.assets).toHaveLength(0);
|
||
stack.redo();
|
||
expect(findAsset(project, command.asset.id)?.name).toBe('Hero');
|
||
});
|
||
|
||
it('rejects a file name the server cannot have produced – in execute, not in the constructor', () => {
|
||
const { project, stack } = makeProject();
|
||
const command = new CreateTextureCommand('Hero', { file: '../secrets.png', width: 1, height: 1 });
|
||
expect(() => stack.execute(command)).toThrow(CommandError);
|
||
expect(project.assets).toHaveLength(0);
|
||
});
|
||
|
||
it('keeps two assets for the same file apart', () => {
|
||
const { project, stack } = makeProject();
|
||
stack.execute(new CreateTextureCommand('Hero', { file: FILE, width: 8, height: 8 }));
|
||
stack.execute(new CreateTextureCommand('Hero copy', { file: FILE, width: 8, height: 8 }));
|
||
expect(project.assets.map((a) => a.id)).toHaveLength(2);
|
||
expect(new Set(project.assets.map((a) => a.id)).size).toBe(2);
|
||
});
|
||
});
|