Isaac compatibility: Convert and Save bridges what the game can't show
The Isaac prompt offers Convert and Save, Ignore and Save, or Cancel; the
document remembers the choice (IsaacIgnored / "isaacIgnored", editor-only)
for saves that don't ask (the warning off, or `convert`). Converting:
- depth: a copy of the layer per depth ("body (depth +1)"), standing where
the editor draws it and showing only that depth's frames
- alpha offsets join the alpha tint (the same on opaque pixels)
- skew, blur and shaders: each layer frame using one is drawn alone at 1x
into <name>.baked.png beside the save (each image once), on a copy of its
layer ("body (baked)") right after it, one frame per step; a skewed root
or group root goes into its layers' images. `convert` makes a headless
OpenGL context for it; without one (or if the sheet can't be written)
these are dropped with a warning. Autosaves don't bake.
Tests check the bridged copy draws as the editor does, frame by frame.
Purge Default Color Values is gone: XML saves always leave out tints of 255
and color offsets of 0, in both copies.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
065dd522f3
commit
8ef089d306
36 files changed
+772
-220
No files matched your search
@@ -143,5 +143,6 @@ namespace anm2ed::edit
|
||||
const std::set<int>& = {});
|
||||
Uids content_remove(model::Model&, ElementType, const std::set<int>&, int, const model::LibraryGet&,
|
||||
const SpritesheetPathGet&);
|
||||
model::Model isaac_bridge(model::Model);
|
||||
bool file_merge(model::Model&, const std::filesystem::path&, const std::filesystem::path&, FileMergePreset);
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
#include "edit.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <format>
|
||||
#include <map>
|
||||
|
||||
#include "math.hpp"
|
||||
#include "model/frames.hpp"
|
||||
|
||||
using namespace anm2ed::model;
|
||||
using namespace anm2ed::util;
|
||||
|
||||
namespace anm2ed::edit
|
||||
{
|
||||
// An alpha offset joins the alpha tint: exact on opaque pixels, which the offset can only fade.
|
||||
void alpha_offsets_bridge(Model& model)
|
||||
{
|
||||
auto is_offset = [](const Frame& frame) { return math::float_to_uint8(frame.colorOffset.a) != 0; };
|
||||
for (int i = 0; i < model.animations_count_get(); ++i)
|
||||
{
|
||||
auto isUsed = false;
|
||||
animation_tracks_each(*model.animation_get(i),
|
||||
[&](const Track& track) { isUsed |= std::ranges::any_of(track.frames, is_offset); });
|
||||
if (!isUsed) continue;
|
||||
animation_tracks_each(*model.animation_edit(i),
|
||||
[&](Track& track)
|
||||
{
|
||||
if (track.type == ItemType::TRIGGER) return;
|
||||
for (auto& frame : track.frames)
|
||||
{
|
||||
frame.tint.a = std::clamp(frame.tint.a + frame.colorOffset.a, 0.0f, 1.0f);
|
||||
frame.colorOffset.a = 0.0f;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// A layer frame's depth becomes a copy of its layer, named for the depth, standing where the editor draws it (the
|
||||
// layer at the copy's place + depth, past the layer already there), and showing only the frames at that depth; the
|
||||
// layer itself shows the rest. Groups can't stand apart in the game, so their roots go into their tracks first.
|
||||
void depths_bridge(Model& model)
|
||||
{
|
||||
auto& content = model.content;
|
||||
std::map<std::pair<int, int>, int> copyIds{};
|
||||
auto copy_id_get = [&](int layerId, int depth)
|
||||
{
|
||||
auto [it, isNew] = copyIds.try_emplace({layerId, depth});
|
||||
if (!isNew) return it->second;
|
||||
auto layer = item_get(content.layers, layerId) ? *item_get(content.layers, layerId) : Layer{};
|
||||
layer.id = item_next_id_get(content.layers);
|
||||
layer.name = std::format("{} (depth {:+})", layer.name, depth);
|
||||
content.layers.push_back(layer);
|
||||
return it->second = layer.id;
|
||||
};
|
||||
auto is_depth = [](const Frame& frame) { return frame.depth != 0; };
|
||||
|
||||
for (int i = 0; i < model.animations_count_get(); ++i)
|
||||
{
|
||||
auto isUsed = false;
|
||||
tracks_each(model.animation_get(i)->layers,
|
||||
[&](const Track& track, auto*) { isUsed |= std::ranges::any_of(track.frames, is_depth); });
|
||||
if (!isUsed) continue;
|
||||
auto& animation = *model.animation_edit(i);
|
||||
|
||||
std::vector<Track> tracks{};
|
||||
for (auto& entry : animation.layers)
|
||||
if (auto track = std::get_if<Track>(&entry))
|
||||
tracks.push_back(std::move(*track));
|
||||
else
|
||||
{
|
||||
auto& group = std::get<TrackGroup>(entry);
|
||||
for (auto& groupTrack : group.tracks)
|
||||
{
|
||||
track_group_root_bake(groupTrack, group.root, animation.frameNum);
|
||||
groupTrack.isVisible = groupTrack.isVisible && group.isVisible;
|
||||
tracks.push_back(std::move(groupTrack));
|
||||
}
|
||||
}
|
||||
|
||||
// Each track's place in drawing order: (its position + depth, depth), kept in position order when equal.
|
||||
std::vector<std::pair<std::pair<int, int>, Track>> placed{};
|
||||
auto shown_set = [](Track& track, int depth)
|
||||
{
|
||||
for (auto& frame : track.frames)
|
||||
{
|
||||
frame.isVisible = frame.isVisible && frame.depth == depth;
|
||||
frame.depth = 0;
|
||||
}
|
||||
};
|
||||
for (int position = 0; position < (int)tracks.size(); ++position)
|
||||
{
|
||||
auto& track = tracks[position];
|
||||
std::set<int> depths{};
|
||||
for (const auto& frame : track.frames)
|
||||
if (frame.depth != 0) depths.insert(frame.depth);
|
||||
for (auto depth : depths)
|
||||
{
|
||||
auto copy = track;
|
||||
copy.id = copy_id_get(track.id, depth);
|
||||
shown_set(copy, depth);
|
||||
placed.push_back({{position + depth, depth}, std::move(copy)});
|
||||
}
|
||||
shown_set(track, 0);
|
||||
placed.push_back({{position, 0}, std::move(track)});
|
||||
}
|
||||
std::ranges::stable_sort(placed, {}, &std::pair<std::pair<int, int>, Track>::first);
|
||||
animation.layers.clear();
|
||||
for (auto& [order, track] : placed)
|
||||
animation.layers.emplace_back(std::move(track));
|
||||
}
|
||||
}
|
||||
|
||||
// The game's copy with what the game can't show worked around (Convert and Save).
|
||||
Model isaac_bridge(Model model)
|
||||
{
|
||||
alpha_offsets_bridge(model);
|
||||
depths_bridge(model);
|
||||
return model;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user