#pragma once #include #include #include #include #include #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 struct SnapshotStepValue { T undo{}; T redo{}; }; struct SnapshotElementStep { std::vector path{}; Element undo{}; Element redo{}; }; struct SnapshotAnm2Step { std::optional> isValid{}; std::vector 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 textures{}; std::map sounds{}; Anm2 anm2{}; Reference reference{}; std::set groupReferences{}; float frameTime{}; std::string message = snapshots::ACTION; }; using SnapshotTextureMap = std::map; using SnapshotSoundMap = std::map; #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, 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> 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 pop(); void clear(); void trim_to_limit(); static void max_size_set(int); static int max_size_get(); private: static int maxSize; std::deque stack; }; class Snapshots { public: SnapshotStack undoStack{}; SnapshotStack redoStack{}; Snapshot current{}; std::optional pendingStep{}; void anm2_push(const std::string&); void tracks_push(const std::string&, const std::set&); void frames_push(const std::string&, const std::set&); void regions_push(const std::string&, int, const std::set&); 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(); }; }