Files
anm2ed/src/snapshots.hpp
T
shweetandClaude Opus 5.5 3f31cedeed Slim Document: move data-model code out, unify edit plumbing
- Region generate/scan move to anm2/regions.cpp; both generators number from 1
- file_merge moves to anm2/merge.cpp and is table-driven
- MaxRects packer moves to util/pack
- Uniform config apply/trim/save move to resource/shader
- Snapshots push from their owned state; Document snapshot wrappers removed
- DocumentData base replaces the hand-written move constructor
- toast_log replaces 55 duplicated toast + English log pairs
- Apply repo .clang-format to touched files

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 13:08:00 -04:00

154 lines
4.8 KiB
C++

#pragma once
#include <deque>
#include <map>
#include <optional>
#include <set>
#include <vector>
#include "anm2/anm2.hpp"
#include "audio.hpp"
#include "playback.hpp"
#include "storage.hpp"
#include "texture.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 animation{};
Storage event{};
Storage frames{};
Storage items{};
Storage layer{};
Storage merge{};
Storage null{};
Storage region{};
Storage shader{};
Storage sound{};
Storage spritesheet{};
std::map<int, resource::Texture> textures{};
std::map<int, resource::Audio> sounds{};
Anm2 anm2{};
Reference reference{};
std::set<Reference> groupReferences{};
float frameTime{};
std::string message = snapshots::ACTION;
};
using SnapshotTextureMap = std::map<int, resource::Texture>;
using SnapshotSoundMap = std::map<int, resource::Audio>;
#define SNAPSHOT_STEP_STATE_FIELDS \
X(Playback, playback) \
X(Storage, animation) \
X(Storage, event) \
X(Storage, frames) \
X(Storage, items) \
X(Storage, layer) \
X(Storage, merge) \
X(Storage, null) \
X(Storage, region) \
X(Storage, shader) \
X(Storage, sound) \
X(Storage, spritesheet) \
X(Reference, reference) \
X(std::set<Reference>, groupReferences) \
X(float, frameTime)
#define SNAPSHOT_STEP_RESOURCE_FIELDS \
X(SnapshotTextureMap, textures) \
X(SnapshotSoundMap, sounds)
struct SnapshotStep
{
std::string message = snapshots::ACTION;
SnapshotAnm2Step anm2{};
#define X(type, name) std::optional<SnapshotStepValue<type>> name{};
SNAPSHOT_STEP_STATE_FIELDS
SNAPSHOT_STEP_RESOURCE_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{};
void anm2_push(const std::string&);
void tracks_push(const std::string&, const std::set<Reference>&);
void frames_push(const std::string&, const std::set<Reference>&);
void regions_push(const std::string&, int, const std::set<int>&);
void textures_push(const std::string&);
void anm2_textures_push(const std::string&);
void step_push(const std::string&, SnapshotStep);
void commit();
bool undo();
bool redo();
void reset();
void apply_limit();
};
}