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>
This commit is contained in:
1 parent
a9f48bc3a0
commit
3f31cedeed
32 files changed
+3405
-4428
No files matched your search
@@ -1,12 +1,12 @@
|
||||
#include "generate_animation_from_grid.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <format>
|
||||
#include "math.hpp"
|
||||
#include "types.hpp"
|
||||
#include "util/imgui/draw.hpp"
|
||||
#include "util/imgui/input.hpp"
|
||||
#include "util/imgui/layout.hpp"
|
||||
#include <algorithm>
|
||||
#include <format>
|
||||
|
||||
using namespace anm2ed::types;
|
||||
using namespace anm2ed::util;
|
||||
@@ -102,10 +102,10 @@ namespace anm2ed::imgui::wizard
|
||||
{
|
||||
auto uvMin = frame.crop / textureSize;
|
||||
auto uvMax = (frame.crop + frame.size) / textureSize;
|
||||
mat4 transform = transform_get(zoom) *
|
||||
math::quad_model_get(frame.size, frame.position, frame.pivot,
|
||||
math::percent_to_unit(frame.scale), frame.rotation,
|
||||
math::percent_to_unit(frame.shear));
|
||||
mat4 transform =
|
||||
transform_get(zoom) * math::quad_model_get(frame.size, frame.position, frame.pivot,
|
||||
math::percent_to_unit(frame.scale), frame.rotation,
|
||||
math::percent_to_unit(frame.shear));
|
||||
auto vertices = math::uv_vertices_get(uvMin, uvMax);
|
||||
|
||||
texture_render(shaderTexture, sourceTexture->id, transform, frame.tint, frame.colorOffset, vertices.data());
|
||||
@@ -144,64 +144,60 @@ namespace anm2ed::imgui::wizard
|
||||
auto queuedIsMakeRegions = isMakeRegions;
|
||||
auto queuedRegionNameFormat = regionNameFormat;
|
||||
|
||||
manager.command_push({manager.selected,
|
||||
[=](Manager&, Document& document)
|
||||
{
|
||||
auto region_name_get = [](const std::string& format, int frameNumber)
|
||||
{
|
||||
try
|
||||
{
|
||||
return std::vformat(format, std::make_format_args(frameNumber));
|
||||
}
|
||||
catch (const std::format_error&)
|
||||
{
|
||||
return format;
|
||||
}
|
||||
};
|
||||
manager.command_push(
|
||||
{manager.selected, [=](Manager&, Document& document)
|
||||
{
|
||||
auto region_name_get = [](const std::string& format, int frameNumber)
|
||||
{
|
||||
try
|
||||
{
|
||||
return std::vformat(format, std::make_format_args(frameNumber));
|
||||
}
|
||||
catch (const std::format_error&)
|
||||
{
|
||||
return format;
|
||||
}
|
||||
};
|
||||
|
||||
bool isChanged{};
|
||||
bool isRegionsChanged{};
|
||||
for (auto queuedReference : queuedLayerReferences)
|
||||
{
|
||||
auto item = document.anm2.element_get(queuedReference);
|
||||
auto animation =
|
||||
document.anm2.element_get(ElementType::ANIMATION, queuedReference.animationIndex);
|
||||
auto layer = document.anm2.element_get(ElementType::LAYER_ELEMENT,
|
||||
queuedReference.itemID);
|
||||
auto spritesheet = layer ? document.anm2.element_get(ElementType::SPRITESHEET,
|
||||
layer->spritesheetId)
|
||||
: nullptr;
|
||||
if (!item || !animation) continue;
|
||||
bool isChanged{};
|
||||
bool isRegionsChanged{};
|
||||
for (auto queuedReference : queuedLayerReferences)
|
||||
{
|
||||
auto item = document.anm2.element_get(queuedReference);
|
||||
auto animation = document.anm2.element_get(ElementType::ANIMATION, queuedReference.animationIndex);
|
||||
auto layer = document.anm2.element_get(ElementType::LAYER_ELEMENT, queuedReference.itemID);
|
||||
auto spritesheet =
|
||||
layer ? document.anm2.element_get(ElementType::SPRITESHEET, layer->spritesheetId) : nullptr;
|
||||
if (!item || !animation) continue;
|
||||
|
||||
if (!isChanged)
|
||||
{
|
||||
document.anm2_snapshot(localize.get(EDIT_GENERATE_ANIMATION_FROM_GRID));
|
||||
isChanged = true;
|
||||
}
|
||||
auto frameIndexStart = (int)item->children.size();
|
||||
frames_generate_from_grid(*item, queuedStartPosition, queuedSize, queuedPivot,
|
||||
queuedColumns, queuedCount, queuedDelay);
|
||||
if (queuedIsMakeRegions && spritesheet)
|
||||
for (int frameIndex = frameIndexStart; frameIndex < (int)item->children.size();
|
||||
++frameIndex)
|
||||
{
|
||||
auto& frame = item->children[frameIndex];
|
||||
if (frame.type != ElementType::FRAME) continue;
|
||||
if (!isChanged)
|
||||
{
|
||||
document.snapshots.anm2_push(localize.get(EDIT_GENERATE_ANIMATION_FROM_GRID));
|
||||
isChanged = true;
|
||||
}
|
||||
auto frameIndexStart = (int)item->children.size();
|
||||
frames_generate_from_grid(*item, queuedStartPosition, queuedSize, queuedPivot, queuedColumns,
|
||||
queuedCount, queuedDelay);
|
||||
if (queuedIsMakeRegions && spritesheet)
|
||||
for (int frameIndex = frameIndexStart; frameIndex < (int)item->children.size(); ++frameIndex)
|
||||
{
|
||||
auto& frame = item->children[frameIndex];
|
||||
if (frame.type != ElementType::FRAME) continue;
|
||||
|
||||
auto region = element_make(ElementType::REGION);
|
||||
region.id = element_child_next_id_get(*spritesheet, ElementType::REGION);
|
||||
region.name = region_name_get(queuedRegionNameFormat, frameIndex - frameIndexStart);
|
||||
region.crop = frame.crop;
|
||||
region.size = frame.size;
|
||||
region.pivot = frame.pivot;
|
||||
frame.regionId = region.id;
|
||||
spritesheet->children.push_back(region);
|
||||
isRegionsChanged = true;
|
||||
}
|
||||
animation->frameNum = animation_length_get(*animation);
|
||||
}
|
||||
if (isChanged) document.anm2_change(isRegionsChanged ? Document::ALL : Document::FRAMES);
|
||||
}});
|
||||
auto region = element_make(ElementType::REGION);
|
||||
region.id = element_child_next_id_get(*spritesheet, ElementType::REGION);
|
||||
region.name = region_name_get(queuedRegionNameFormat, frameIndex - frameIndexStart);
|
||||
region.crop = frame.crop;
|
||||
region.size = frame.size;
|
||||
region.pivot = frame.pivot;
|
||||
frame.regionId = region.id;
|
||||
spritesheet->children.push_back(region);
|
||||
isRegionsChanged = true;
|
||||
}
|
||||
animation->frameNum = animation_length_get(*animation);
|
||||
}
|
||||
if (isChanged) document.change(isRegionsChanged ? Document::ALL : Document::FRAMES);
|
||||
}});
|
||||
isEnd = true;
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
|
||||
Reference in new issue
Block a user