Stage 5: content-hash AssetStore; undo records asset keys, not pixels

- resource::AssetStore (core) keeps immutable images and sounds keyed by content
  hash for the life of the document; nothing is purged until it closes.
- Undo state holds spritesheet/sound id -> asset key maps (always tracked), so
  every edit can undo texture changes; the textures-only snapshot flag
  (edit_begin(label, true) / push(message, isTextures)) and the pixel/audio
  equality helpers are gone.
- Document::texture_get/sound_get read through the store; texture_set/sound_set
  add assets; texture_edit gives the pencil a private draft that becomes a new
  asset on the next change().
- Spritesheet dirty state compares path + asset key instead of hashing pixels.
- Preview audio reads sounds through the store.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-10-03 15:53:34 -04:00
1 parent 65a3546c3b
commit 9f43a210c5
13 files changed
+195 -130

No files matched your search

+19
View File
@@ -1,5 +1,6 @@
#include "common.hpp"
#include "asset_store.hpp"
#include "audio_data.hpp"
#include "image.hpp"
@@ -39,3 +40,21 @@ TEST_CASE("AudioData holds file bytes")
CHECK(audio.uid != 0);
CHECK_FALSE(AudioData(std::filesystem::path("missing.wav")).is_valid());
}
TEST_CASE("AssetStore keys assets by content")
{
AssetStore store{};
const std::vector<uint8_t> pixels{1, 2, 3, 4};
auto key = store.image_add(Image(pixels.data(), {1, 1}));
CHECK(key != 0);
CHECK(store.image_add(Image(pixels.data(), {1, 1})) == key);
CHECK(store.image_add(Image(pixels.data(), {1, 1}, true)) != key);
REQUIRE(store.image_get(key));
CHECK(store.image_get(key)->pixels == pixels);
CHECK_FALSE(store.image_get(key + 1));
const unsigned char bytes[] = {'O', 'g', 'g', 'S'};
auto audioKey = store.audio_add(AudioData(bytes, sizeof(bytes)));
CHECK(store.audio_add(AudioData(bytes, sizeof(bytes))) == audioKey);
CHECK(store.audio_get(audioKey)->bytes.size() == sizeof(bytes));
}