Files
anm2ed/src/document.hpp
T
shweetandClaude Opus 5.5 4c569cb1e5 Stage 10a: delete dead code, merge tiny files, unify duplicated concepts
- Dead code: util/map, util/unordered_map, unused vector/math/string/input
  helpers, Document getters, special-interpolation bake leftovers,
  triggers_sort, SnapshotStack::max_size_get, AudioStream capture API.
- Merges: util/xml, util/string, resource/strings.cpp inlined; constants
  into input.hpp; tooltip into layout; Recorder into render; onionskin,
  tools, welcome and frame properties are panel functions; timeline
  popups.cpp folded into timeline.cpp.
- util/origin.hpp replaced by model Origin (the merge setting stays a
  combo index, so saved preferences keep their meaning).
- Item type names/icons/colors moved from model/common.hpp to the
  timeline header; the model no longer includes icon/strings headers.

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

187 lines
6.0 KiB
C++

#pragma once
#include <cstdint>
#include <filesystem>
#include <functional>
#include <map>
#include <set>
#include <type_traits>
#include <unordered_map>
#include <vector>
#include "asset_store.hpp"
#include "edit/edit.hpp"
#include "selection.hpp"
#include "snapshots.hpp"
#include "strings.hpp"
#include <glm/glm.hpp>
#include "shader.hpp"
#include "types.hpp"
namespace anm2ed
{
class Manager;
struct Command;
// Ids and labels for a combo box of content items.
struct Choices
{
std::vector<int> ids{};
std::vector<std::string> labels{};
};
struct DocumentData
{
std::filesystem::path path{};
uint64_t tabId{};
Snapshots snapshots{};
resource::AssetStore assets{};
std::map<int, resource::Image> 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<int, uint64_t> spritesheetHashes{};
std::unordered_map<int, uint64_t> spritesheetSaveHashes{};
std::unordered_map<int, std::filesystem::path> texturePaths{};
std::unordered_map<int, std::filesystem::path> soundPaths{};
std::map<int, std::filesystem::path> shaderVertexPaths{};
std::map<int, std::filesystem::path> shaderFragmentPaths{};
std::map<int, resource::Shader> 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<int>&);
bool spritesheet_pack(int, int);
bool spritesheets_merge(const std::set<int>&, bool, bool, bool, Origin);
void hash_set();
void clean();
void change();
void edit_begin(StringType);
edit::Uids edit_run(StringType, const std::function<edit::Uids(model::Model&)>&);
// Snapshots for undo, runs the operation on the model, then commits; void operations select nothing.
template <class Operation> edit::Uids edit_apply(StringType label, Operation&& operation)
{
return edit_run(label,
[&](model::Model& model) -> edit::Uids
{
if constexpr (std::is_void_v<std::invoke_result_t<Operation&, model::Model&>>)
{
operation(model);
return {};
}
else
return operation(model);
});
}
std::vector<Reference> references_get(const edit::Uids&) const;
bool is_dirty() const;
bool is_autosave_dirty() const;
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();
Reference reference_get() const;
void reference_set(Reference);
std::set<Reference> selected_get(SelectionKind) const;
void selected_set(SelectionKind, const std::set<Reference>&);
std::set<int> selected_ids_get(SelectionKind) const;
void selected_ids_set(SelectionKind, const std::set<int>&);
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<int> animations_selected_get() const;
void animations_selected_set(const std::set<int>&);
std::set<Reference> item_frame_references_get(Reference) const;
std::set<Reference> selected_item_frame_references_get() const;
std::set<Reference> frame_references_get(FrameReferenceFallback = FrameReferenceFallback::CURRENT) const;
void frame_references_set(std::set<Reference>);
void frame_references_clear();
std::vector<Reference> layer_references_get();
void spritesheets_add(const std::vector<std::filesystem::path>&);
void sounds_add(const std::vector<std::filesystem::path>&);
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();
};
}