- 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>
137 lines
3.8 KiB
C++
137 lines
3.8 KiB
C++
#pragma once
|
|
|
|
#include <deque>
|
|
#include <map>
|
|
#include <optional>
|
|
#include <set>
|
|
#include <vector>
|
|
|
|
#include "anm2/anm2.hpp"
|
|
#include "playback.hpp"
|
|
#include "selection.hpp"
|
|
#include "storage.hpp"
|
|
|
|
namespace anm2ed::snapshots
|
|
{
|
|
constexpr auto ACTION = "Action";
|
|
constexpr auto MAX = 20;
|
|
};
|
|
|
|
namespace anm2ed
|
|
{
|
|
enum class SnapshotStepDirection
|
|
{
|
|
UNDO,
|
|
REDO
|
|
};
|
|
|
|
template <typename T> struct SnapshotStepValue
|
|
{
|
|
T undo{};
|
|
T redo{};
|
|
};
|
|
|
|
struct SnapshotElementStep
|
|
{
|
|
std::vector<int> path{};
|
|
Element undo{};
|
|
Element redo{};
|
|
};
|
|
|
|
struct SnapshotAnm2Step
|
|
{
|
|
std::optional<SnapshotStepValue<bool>> isValid{};
|
|
std::vector<SnapshotElementStep> elements{};
|
|
|
|
bool is_empty() const;
|
|
void apply(Anm2&, SnapshotStepDirection) const;
|
|
};
|
|
|
|
class Snapshot
|
|
{
|
|
public:
|
|
Playback playback{};
|
|
Storage event{};
|
|
Storage layer{};
|
|
Storage merge{};
|
|
Storage null{};
|
|
Storage region{};
|
|
Storage shader{};
|
|
Storage sound{};
|
|
Storage spritesheet{};
|
|
std::map<int, std::uint64_t> textures{};
|
|
std::map<int, std::uint64_t> sounds{};
|
|
Anm2 anm2{};
|
|
Selection selection{};
|
|
float frameTime{};
|
|
std::string message = snapshots::ACTION;
|
|
};
|
|
|
|
using AssetKeys = std::map<int, std::uint64_t>;
|
|
|
|
#define SNAPSHOT_STEP_STATE_FIELDS \
|
|
X(Playback, playback) \
|
|
X(Storage, event) \
|
|
X(Storage, layer) \
|
|
X(Storage, merge) \
|
|
X(Storage, null) \
|
|
X(Storage, region) \
|
|
X(Storage, shader) \
|
|
X(Storage, sound) \
|
|
X(Storage, spritesheet) \
|
|
X(Selection, selection) \
|
|
X(float, frameTime) \
|
|
X(AssetKeys, textures) \
|
|
X(AssetKeys, sounds)
|
|
|
|
struct SnapshotStep
|
|
{
|
|
std::string message = snapshots::ACTION;
|
|
SnapshotAnm2Step anm2{};
|
|
|
|
#define X(type, name) std::optional<SnapshotStepValue<type>> name{};
|
|
SNAPSHOT_STEP_STATE_FIELDS
|
|
#undef X
|
|
|
|
bool is_empty() const;
|
|
void apply(Snapshot&, SnapshotStepDirection) const;
|
|
};
|
|
|
|
class SnapshotStack
|
|
{
|
|
public:
|
|
SnapshotStack() = default;
|
|
|
|
bool is_empty();
|
|
void push(SnapshotStep);
|
|
std::optional<SnapshotStep> pop();
|
|
void clear();
|
|
void trim_to_limit();
|
|
|
|
static void max_size_set(int);
|
|
static int max_size_get();
|
|
|
|
private:
|
|
static int maxSize;
|
|
std::deque<SnapshotStep> stack;
|
|
};
|
|
|
|
class Snapshots
|
|
{
|
|
public:
|
|
SnapshotStack undoStack{};
|
|
SnapshotStack redoStack{};
|
|
Snapshot current{};
|
|
std::optional<SnapshotStep> pendingStep{};
|
|
std::optional<Reference> pendingFocus{};
|
|
|
|
void push(const std::string&);
|
|
void step_push(const std::string&, SnapshotStep);
|
|
void commit();
|
|
bool undo();
|
|
bool redo();
|
|
void reset();
|
|
void apply_limit();
|
|
};
|
|
}
|