#pragma once #include #include #include #include #include #include #include #include #include "asset_store.hpp" #include "edit/edit.hpp" #include "selection.hpp" #include "snapshots.hpp" #include "strings.hpp" #include #include "shader.hpp" namespace anm2ed { class Manager; struct Command; // Ids and labels for a combo box of content items. struct Choices { std::vector ids{}; std::vector labels{}; }; struct DocumentData { std::filesystem::path path{}; uint64_t tabId{}; Snapshots snapshots{}; resource::AssetStore assets{}; std::map textureDrafts{}; int changeAllFramePropertiesRegionId{-1}; int changeAllFramePropertiesShaderId{-1}; float previewZoom{200}; glm::vec2 previewPan{}; glm::vec2 editorPan{}; float editorZoom{200}; int overlayIndex{-1}; uint64_t overlayDocumentId{}; uint64_t hash{}; uint64_t saveHash{}; uint64_t autosaveHash{}; double lastAutosaveTime{}; bool isValid{true}; bool isOpen{true}; bool isForceDirty{false}; std::unordered_map spritesheetHashes{}; std::unordered_map spritesheetSaveHashes{}; std::unordered_map spritesheetAutosaveHashes{}; std::unordered_map texturePaths{}; std::unordered_map textureWriteTimes{}; std::unordered_map soundPaths{}; std::map shaderVertexPaths{}; std::map shaderFragmentPaths{}; std::map shaders{}; bool isAnimationPreviewSet{false}; bool isSpritesheetEditorSet{false}; }; class Document : public DocumentData { public: enum class FrameReferenceFallback { NONE, CURRENT, }; enum class EditTarget { NONE, FRAME, REGION, SPRITESHEET }; Snapshot& current = snapshots.current; #define X(type, name) type& name = current.name; SNAPSHOT_STEP_STATE_FIELDS #undef X std::string& message = current.message; EditTarget editTarget{EditTarget::NONE}; model::UidIndex index{}; Document(const std::filesystem::path&, bool = false, std::string* = nullptr); Document(const Document&) = delete; Document& operator=(const Document&) = delete; Document(Document&&) noexcept; Document& operator=(Document&&) noexcept; bool save(const std::filesystem::path& = {}, std::string* = nullptr, Options = {}); void assets_sync(); void texture_change(int); bool texture_reload(int); bool sound_reload(int); bool shader_reload(int, std::string* = nullptr); const resource::Image* texture_get(int) const; resource::Image* texture_edit(int); void texture_set(int, resource::Image); const resource::AudioData* sound_get(int) const; void sound_set(int, resource::AudioData); resource::Shader* shader_get(int); bool regions_trim(int, const std::set&); bool spritesheet_pack(int, int); bool spritesheets_merge(const std::set&, bool, bool, bool, Origin); void hash_set(); void clean(); void change(); void edit_begin(StringType); edit::Uids edit_run(StringType, const std::function&); // Snapshots for undo, runs the operation on the model, then commits; void operations select nothing. template edit::Uids edit_apply(StringType label, Operation&& operation) { return edit_run(label, [&](model::Model& model) -> edit::Uids { if constexpr (std::is_void_v>) { operation(model); return {}; } else return operation(model); }); } std::vector references_get(const edit::Uids&) const; bool is_dirty() const; bool is_autosave_dirty(); std::filesystem::path directory_get() const; std::filesystem::path filename_get() const; bool is_valid() const; void command_run(Manager&, Command&); void spritesheet_hash_update(int); void spritesheet_hash_set_saved(int); bool spritesheet_is_dirty(int); bool spritesheet_any_dirty(); void spritesheet_hashes_sync(); std::set spritesheets_changed_get(); void spritesheets_reload(const std::set&); std::filesystem::path spritesheet_autosave_path_get(const model::Spritesheet&); std::set spritesheets_autosave_dirty_get(); void spritesheets_autosave_restore(); void spritesheets_autosave_clear(); Reference reference_get() const; void reference_set(Reference); std::set selected_get(SelectionKind) const; void selected_set(SelectionKind, const std::set&); std::set selected_ids_get(SelectionKind) const; void selected_ids_set(SelectionKind, const std::set&); int focused_id_get(SelectionKind) const; void focused_id_set(SelectionKind, int); void selected_clear(SelectionKind); Choices choices_get(SelectionKind, int = -1) const; void frames_select(const edit::Uids&); void frame_select(Reference); void frame_toggle(Reference); bool frames_range_select(Reference, Reference, bool); void frame_focus_select(); void focus_clear(); void track_select(Reference); std::set animations_selected_get() const; void animations_selected_set(const std::set&); std::set item_frame_references_get(Reference) const; std::set selected_item_frame_references_get() const; std::set frame_references_get(FrameReferenceFallback = FrameReferenceFallback::CURRENT) const; void frame_references_set(std::set); void frame_references_clear(); std::vector layer_references_get(); void spritesheets_add(const std::vector&); void sounds_add(const std::vector&); bool autosave(std::string* = nullptr, Options = {}); std::filesystem::path autosave_path_get(); std::filesystem::path path_from_autosave_get(const std::filesystem::path&); void undo(); void redo(); bool is_able_to_undo(); bool is_able_to_redo(); }; }