Files
feuerwerk/src/core/properties/assetRef.ts
T
adminandClaude Opus 5.5 23cb34f781 Keep a recorded take inside its song (#355)
A take used to land in the Assets panel as "Song – Take N", next to
every other sound of the project. Now a song can keep a sound, a
pattern or a sound FX to itself: an ordinary asset whose new field
`owner` names the song. Everything that finds an asset by its id
finds it, so playing, the tabs and the game need no change. Only
the places that list assets leave it out.

- `core/music/embedded.ts` holds the rules: which types can be
  embedded, `listedAssets`, the title "Song › Take 1", and the
  rows an embedded sound hides (Loop, Bus).
- One user per embedded asset. `SetSongCommand` settles the song
  after every edit: a place naming an asset an earlier place
  claimed, or one of another song, gets a copy, and what nothing
  names any more goes in the same undo step. The outcome is worked
  out once, so a redo brings back the same copies.
- A split, Ctrl+D and a paste get that for free. The clipboard
  keeps the embedded assets of the copied items, so a paste after a
  delete brings the take back.
- Deleting a song deletes what it keeps. Duplicating it copies
  that and points the copy at the copies. A duplicate of an
  embedded asset is a project asset.
- The item menu has Open, Make project asset and Embed a copy.
- An embedded item carries a bullet in front of its name. The
  first pick was a diamond, which the gate's font test refused:
  the UI font has no glyph for it.
- A take is "Take 1", 2, … numbered per song. With the song gone
  while it uploads, it becomes a project sound under a free name.
- Left out of: the Assets panel, every asset picker, the sound FX
  menu of a track, the test sound of the Sound FX tab and the
  naming of new assets. Delete on an embedded asset only says
  where it lives. A ping lights up its song.
- Loading drops an `owner` whose song is gone, the asset stays as
  a project asset. No migration: older projects have no owner.

Tests:
- Unit embedded (new): 13 green, 6 counter-checks each red
- Unit take, song, song-edit, asset-fx, asset-ref, serialize and
  neighbours: 116 green
- e2e 65 (melektaus-atx): ALL PASSED, 47 checks (1 new)
- Counter-check e2e 65 (asset panel unfiltered): exactly that
  check red
- Gate (melektaus-atx): CHECK EXIT 0, 269 files, 4167 tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 10:36:25 +02:00

37 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { Asset } from '../model/Asset';
import { type AssetType, isPlaceableType } from '../model/AssetTypes';
import { findAsset, type Project } from '../model/Project';
import { listedAssets } from '../music/embedded';
import { NO_FX } from './assetFx';
import { MASTER_BUS } from './buses';
export const NO_ASSET_LABEL = 'None';
export const MASTER_LABEL = 'Master';
/**
* The asset's name, "None" for the empty id, `<id>?` when it no longer resolves – a dangling
* reference shows its id rather than passing for an empty field.
*/
export function assetRefLabel(project: Project | null, id: string): string {
if (id === '' || id === NO_FX) return NO_ASSET_LABEL;
if (id === MASTER_BUS) return MASTER_LABEL;
return (project ? findAsset(project, id) : undefined)?.name ?? `${id}?`;
}
/**
* The assets an `asset` property offers, in menu order; without `assetTypes` every placeable one.
* Sorted by name so the order does not depend on creation time. What a song keeps to itself (#355)
* is offered nowhere.
*/
export function assetRefChoices(project: Project, assetTypes?: readonly AssetType[]): Asset[] {
const allowed = (asset: Asset): boolean =>
assetTypes ? assetTypes.includes(asset.type) : isPlaceableType(asset.type);
return listedAssets(project)
.filter(allowed)
.sort((a, b) => a.name.localeCompare(b.name) || a.type.localeCompare(b.type));
}
export function assetChoiceLabel(asset: Asset): string {
return `${asset.name} (${asset.type})`;
}