Remove namespaces, and make file-local helpers static
Names that only a namespace told apart get prefixes: TOOL_PAN, FONT_BOLD, ICON_FOLDER, COLOR_WHITE, path_to_utf8 and so on. The OpenGL shader class is ShaderProgram, and its uniform ShaderUniform, beside the document's Shader and Uniform. Free functions a member of the same name would hide are called through :: for now. Two unused shader window helpers are gone.
This commit is contained in:
1 parent
7fb2c607c2
commit
666f65bf3a
174 files changed
+2396
-3154
No files matched your search
+117
-120
@@ -4,29 +4,26 @@
|
||||
#include "playback.h"
|
||||
#include "pack.h"
|
||||
|
||||
using namespace anm2ed;
|
||||
using namespace anm2ed::test;
|
||||
static Model fixture_load(const char* name) { return model_load(file_load(CORPUS_DIR / name)); }
|
||||
|
||||
model::Model fixture_load(const char* name) { return model_load(file_load(CORPUS_DIR / name)); }
|
||||
|
||||
void operation_check(const char* name, const model::Model& model)
|
||||
static void operation_check(const char* name, const Model& model)
|
||||
{
|
||||
golden_check(GOLDEN_DIR / std::format("operation.{}.xml", name),
|
||||
model::model_serialize(model, SERIALIZE_ANM2ED_DEFAULT));
|
||||
model_serialize(model, SERIALIZE_ANM2ED_DEFAULT));
|
||||
}
|
||||
|
||||
model::Track& layer_track_get(model::Model& model, int animationIndex, int layerId)
|
||||
static Track& layer_track_get(Model& model, int animationIndex, int layerId)
|
||||
{
|
||||
auto track = model.track_edit({animationIndex, LAYER, layerId});
|
||||
REQUIRE(track);
|
||||
return *track;
|
||||
}
|
||||
|
||||
int groups_named_count(const model::Animation& animation, std::string_view name)
|
||||
static int groups_named_count(const Animation& animation, std::string_view name)
|
||||
{
|
||||
int count{};
|
||||
for (const auto* entries : {&animation.layers, &animation.nulls})
|
||||
model::groups_each(*entries, [&](const model::TrackGroup& group) { count += group.name == name; });
|
||||
groups_each(*entries, [&](const TrackGroup& group) { count += group.name == name; });
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -36,7 +33,7 @@ TEST_CASE("animations_merge keeps one group per name")
|
||||
{
|
||||
INFO("merge: ", std::string(name));
|
||||
auto model = fixture_load("03a_groups_nested.anm2");
|
||||
edit::animations_merge(model, 0, {0, 1}, type, false, {});
|
||||
animations_merge(model, 0, {0, 1}, type, false, {});
|
||||
CHECK(groups_named_count(*model.animation_get(0), "Main") == 1);
|
||||
}
|
||||
}
|
||||
@@ -50,7 +47,7 @@ TEST_CASE("file_merge presets")
|
||||
for (auto [name, preset] : PRESETS_FILE_MERGE)
|
||||
{
|
||||
auto model = fixture_load("02_items.anm2");
|
||||
CHECK(edit::file_merge(model, CORPUS_DIR / "05_regions.anm2", CORPUS_DIR, preset));
|
||||
CHECK(file_merge(model, CORPUS_DIR / "05_regions.anm2", CORPUS_DIR, preset));
|
||||
operation_check(name, model);
|
||||
}
|
||||
}
|
||||
@@ -58,23 +55,23 @@ TEST_CASE("file_merge presets")
|
||||
TEST_CASE("item_add")
|
||||
{
|
||||
auto model = fixture_load("02_items.anm2");
|
||||
CHECK(edit::item_add(model, ItemType::LAYER, 0, -1, {.name = "added", .spritesheetId = 1}, {}, 1,
|
||||
types::destination::ALL) == 2);
|
||||
CHECK(edit::item_add(model, ItemType::NULL_, 1, -1, {}, {.name = "thisOnly"}, -1, types::destination::THIS) == 2);
|
||||
CHECK(item_add(model, ItemType::LAYER, 0, -1, {.name = "added", .spritesheetId = 1}, {}, 1,
|
||||
DESTINATION_ALL) == 2);
|
||||
CHECK(item_add(model, ItemType::NULL_, 1, -1, {}, {.name = "thisOnly"}, -1, DESTINATION_THIS) == 2);
|
||||
operation_check("item_add", model);
|
||||
}
|
||||
|
||||
TEST_CASE("regions_generate and regions_scan")
|
||||
{
|
||||
auto model = fixture_load("02_items.anm2");
|
||||
edit::regions_generate(model, {0}, {}, "Region {}", RegionFrameMapping::SET);
|
||||
regions_generate(model, {0}, {}, "Region {}", RegionFrameMapping::SET);
|
||||
auto generated = model;
|
||||
edit::regions_generate(model, {0}, {}, "Region {}", RegionFrameMapping::SET);
|
||||
CHECK(model::is_model_equal(model, generated));
|
||||
regions_generate(model, {0}, {}, "Region {}", RegionFrameMapping::SET);
|
||||
CHECK(is_model_equal(model, generated));
|
||||
operation_check("regions_generate", model);
|
||||
|
||||
auto scanned = fixture_load("05_regions.anm2");
|
||||
edit::regions_scan(scanned);
|
||||
regions_scan(scanned);
|
||||
operation_check("regions_scan", scanned);
|
||||
}
|
||||
|
||||
@@ -92,7 +89,7 @@ TEST_CASE("frames_change")
|
||||
change.duration = 3;
|
||||
change.interpolation = Interpolation::EASE_IN;
|
||||
change.isFlipX = true;
|
||||
model::frames_change(layer_track_get(model, 0, 0), change, ItemType::LAYER, type, {0, 1});
|
||||
frames_change(layer_track_get(model, 0, 0), change, ItemType::LAYER, type, {0, 1});
|
||||
operation_check(std::format("frames_change_{}", name).c_str(), model);
|
||||
}
|
||||
}
|
||||
@@ -100,17 +97,17 @@ TEST_CASE("frames_change")
|
||||
TEST_CASE("frame_bake and frame_mix")
|
||||
{
|
||||
auto model = fixture_load("07_special_interpolation.anm2");
|
||||
model::frame_bake(layer_track_get(model, 0, 0), 0, 2, true, false);
|
||||
model::frame_bake(layer_track_get(model, 0, 0), 3, 1, false, true);
|
||||
frame_bake(layer_track_get(model, 0, 0), 0, 2, true, false);
|
||||
frame_bake(layer_track_get(model, 0, 0), 3, 1, false, true);
|
||||
operation_check("frame_bake", model);
|
||||
|
||||
model::Frame from{};
|
||||
model::Frame to{};
|
||||
Frame from{};
|
||||
Frame to{};
|
||||
to.position = {10.0f, -20.0f};
|
||||
to.skew = {30.0f, 0.0f};
|
||||
to.rotation = 90.0f;
|
||||
to.tint = {0.0f, 1.0f, 1.0f, 0.5f};
|
||||
model::frame_mix(from, to, 0.5f);
|
||||
frame_mix(from, to, 0.5f);
|
||||
CHECK(from.position == glm::vec2(5.0f, -10.0f));
|
||||
CHECK(from.skew == glm::vec2(15.0f, 0.0f));
|
||||
CHECK(from.rotation == doctest::Approx(45.0f));
|
||||
@@ -122,7 +119,7 @@ TEST_CASE("rects_pack fits every rect without overlap")
|
||||
std::vector<glm::ivec2> sizes{{16, 16}, {32, 8}, {8, 32}, {5, 7}, {64, 1}, {1, 1}};
|
||||
glm::ivec2 size{};
|
||||
std::vector<glm::ivec2> positions{};
|
||||
REQUIRE(util::pack::rects_pack(sizes, size, positions));
|
||||
REQUIRE(rects_pack(sizes, size, positions));
|
||||
REQUIRE(positions.size() == sizes.size());
|
||||
for (std::size_t i = 0; i < sizes.size(); ++i)
|
||||
{
|
||||
@@ -144,90 +141,90 @@ TEST_CASE("edit layer operations")
|
||||
{
|
||||
const char* name;
|
||||
const char* fixture;
|
||||
std::function<edit::Uids(model::Model&)> operation;
|
||||
std::function<Uids(Model&)> operation;
|
||||
std::size_t uidCount;
|
||||
};
|
||||
|
||||
const Reference head{0, LAYER, 0};
|
||||
const Case CASES[] = {
|
||||
{"frame_insert", "02_items.anm2",
|
||||
[&](model::Model& anm2) { return edit::frame_insert(anm2, {0, LAYER, 0, 0}, 0); }, 1},
|
||||
[&](Model& anm2) { return frame_insert(anm2, {0, LAYER, 0, 0}, 0); }, 1},
|
||||
{"trigger_insert", "02_items.anm2",
|
||||
[&](model::Model& anm2) { return edit::frame_insert(anm2, {0, TRIGGER, -1, 0}, 2); }, 1},
|
||||
[&](Model& anm2) { return frame_insert(anm2, {0, TRIGGER, -1, 0}, 2); }, 1},
|
||||
{"frames_delete", "02_items.anm2",
|
||||
[&](model::Model& anm2) { return edit::frames_delete(anm2, {{0, LAYER, 0, 0}, {0, ROOT, -1, 1}}); }, 0},
|
||||
{"frames_duplicate", "02_items.anm2", [&](model::Model& anm2)
|
||||
{ return edit::frames_duplicate(anm2, {{0, LAYER, 0, 0}, {0, LAYER, 0, 1}}, {0, LAYER, 0, 1}); }, 2},
|
||||
[&](Model& anm2) { return frames_delete(anm2, {{0, LAYER, 0, 0}, {0, ROOT, -1, 1}}); }, 0},
|
||||
{"frames_duplicate", "02_items.anm2", [&](Model& anm2)
|
||||
{ return frames_duplicate(anm2, {{0, LAYER, 0, 0}, {0, LAYER, 0, 1}}, {0, LAYER, 0, 1}); }, 2},
|
||||
{"frames_reverse", "07_special_interpolation.anm2",
|
||||
[&](model::Model& anm2) { return edit::frames_reverse(anm2, {{0, LAYER, 0, 0}, {0, LAYER, 0, 2}}); }, 0},
|
||||
{"frames_bake", "07_special_interpolation.anm2", [&](model::Model& anm2)
|
||||
{ return edit::frames_bake(anm2, {{0, LAYER, 0, 0}, {0, LAYER, 0, 1}}, 2, true, false); }, 5},
|
||||
{"frame_split", "02_items.anm2", [&](model::Model& anm2) { return edit::frame_split(anm2, {0, LAYER, 1, 0}, 2); },
|
||||
[&](Model& anm2) { return frames_reverse(anm2, {{0, LAYER, 0, 0}, {0, LAYER, 0, 2}}); }, 0},
|
||||
{"frames_bake", "07_special_interpolation.anm2", [&](Model& anm2)
|
||||
{ return frames_bake(anm2, {{0, LAYER, 0, 0}, {0, LAYER, 0, 1}}, 2, true, false); }, 5},
|
||||
{"frame_split", "02_items.anm2", [&](Model& anm2) { return frame_split(anm2, {0, LAYER, 1, 0}, 2); },
|
||||
1},
|
||||
{"frames_move", "02_items.anm2",
|
||||
[&](model::Model& anm2) { return edit::frames_move(anm2, {{0, LAYER, 0, 0}, {0, LAYER, 1, 0}}, head, 2); }, 2},
|
||||
[&](Model& anm2) { return frames_move(anm2, {{0, LAYER, 0, 0}, {0, LAYER, 1, 0}}, head, 2); }, 2},
|
||||
{"frames_paste", "02_items.anm2",
|
||||
[&](model::Model& anm2)
|
||||
[&](Model& anm2)
|
||||
{
|
||||
auto frame = anm2.frame_get(Reference{0, LAYER, 1, 0});
|
||||
auto text = model::frame_to_string(*frame, ItemType::LAYER) + model::frame_to_string(*frame, ItemType::LAYER);
|
||||
return edit::frames_paste(anm2, {0, LAYER, 0, 0}, {}, text, 0, nullptr);
|
||||
auto text = frame_to_string(*frame, ItemType::LAYER) + frame_to_string(*frame, ItemType::LAYER);
|
||||
return frames_paste(anm2, {0, LAYER, 0, 0}, {}, text, 0, nullptr);
|
||||
},
|
||||
2},
|
||||
{"root_bake_into", "04_group_root_transform.anm2",
|
||||
[&](model::Model& anm2)
|
||||
[&](Model& anm2)
|
||||
{
|
||||
return edit::root_bake_into(anm2, {{0, ROOT, -1, 0}}, {{0, LAYER, 2}},
|
||||
return root_bake_into(anm2, {{0, ROOT, -1, 0}}, {{0, LAYER, 2}},
|
||||
{.isRoundScale = true, .isMatchRootInterpolation = true});
|
||||
},
|
||||
1},
|
||||
{"items_group", "03b_groups_legacy_flat.anm2",
|
||||
[&](model::Model& anm2) { return edit::items_group(anm2, 0, LAYER, {2}, "New"); }, 1},
|
||||
{"items_move", "03b_groups_legacy_flat.anm2", [&](model::Model& anm2)
|
||||
{ return edit::items_move(anm2, 0, LAYER, {2}, {}, {true, LAYER, 0, -1}, false, true); }, 0},
|
||||
[&](Model& anm2) { return items_group(anm2, 0, LAYER, {2}, "New"); }, 1},
|
||||
{"items_move", "03b_groups_legacy_flat.anm2", [&](Model& anm2)
|
||||
{ return items_move(anm2, 0, LAYER, {2}, {}, {true, LAYER, 0, -1}, false, true); }, 0},
|
||||
{"items_remove", "03b_groups_legacy_flat.anm2",
|
||||
[&](model::Model& anm2) { return edit::items_remove(anm2, 0, {{LAYER, {2}}}, {{NULL_, {3}}}); }, 0},
|
||||
[&](Model& anm2) { return items_remove(anm2, 0, {{LAYER, {2}}}, {{NULL_, {3}}}); }, 0},
|
||||
{"animation_add", "03a_groups_nested.anm2",
|
||||
[&](model::Model& anm2) { return edit::animation_add(anm2, 1, 0, 0, "Added"); }, 1},
|
||||
[&](Model& anm2) { return animation_add(anm2, 1, 0, 0, "Added"); }, 1},
|
||||
{"animations_remove", "03a_groups_nested.anm2",
|
||||
[&](model::Model& anm2) { return edit::animations_remove(anm2, {1}, {0}); }, 0},
|
||||
{"animations_move", "02_items.anm2", [&](model::Model& anm2)
|
||||
{ return edit::animations_move(anm2, {0}, {}, {.animationIndex = 1, .isAfter = true}); }, 1},
|
||||
[&](Model& anm2) { return animations_remove(anm2, {1}, {0}); }, 0},
|
||||
{"animations_move", "02_items.anm2", [&](Model& anm2)
|
||||
{ return animations_move(anm2, {0}, {}, {.animationIndex = 1, .isAfter = true}); }, 1},
|
||||
{"animations_group", "02_items.anm2",
|
||||
[&](model::Model& anm2) { return edit::animations_group(anm2, {0, 1}, "Group"); }, 0},
|
||||
[&](Model& anm2) { return animations_group(anm2, {0, 1}, "Group"); }, 0},
|
||||
{"animations_paste", "02_items.anm2",
|
||||
[&](model::Model& anm2)
|
||||
[&](Model& anm2)
|
||||
{
|
||||
std::set<int> groupIds{};
|
||||
auto text = model::animation_to_string(*anm2.animation_get(1));
|
||||
return edit::animations_paste(anm2, text, 0, -1, groupIds, nullptr);
|
||||
auto text = animation_to_string(*anm2.animation_get(1));
|
||||
return animations_paste(anm2, text, 0, -1, groupIds, nullptr);
|
||||
},
|
||||
1},
|
||||
{"regions_paste", "05_regions.anm2",
|
||||
[&](model::Model& anm2)
|
||||
[&](Model& anm2)
|
||||
{
|
||||
auto region = model::item_get(model::item_get(anm2.content.spritesheets, 0)->regions, 1);
|
||||
return edit::regions_paste(anm2, 0, model::item_to_string(*region), 1, nullptr);
|
||||
auto region = item_get(item_get(anm2.content.spritesheets, 0)->regions, 1);
|
||||
return regions_paste(anm2, 0, item_to_string(*region), 1, nullptr);
|
||||
},
|
||||
0},
|
||||
{"animation_grid_generate", "05_regions.anm2",
|
||||
[&](model::Model& anm2)
|
||||
[&](Model& anm2)
|
||||
{
|
||||
return edit::animation_grid_generate(anm2, {{0, LAYER, 0}},
|
||||
return animation_grid_generate(anm2, {{0, LAYER, 0}},
|
||||
{{0, 0}, {8, 8}, {4, 4}, 2, 3, 2, true, "Grid {}"});
|
||||
},
|
||||
3},
|
||||
{"frames_change_apply", "02_items.anm2",
|
||||
[&](model::Model& anm2)
|
||||
[&](Model& anm2)
|
||||
{
|
||||
FrameChange change{.positionX = 3.0f, .rotation = 10.0f};
|
||||
return edit::frames_change_apply(
|
||||
return frames_change_apply(
|
||||
anm2, {.references = {{0, LAYER, 0, 1}, {0, NULL_, 0}}, .animations = {1}, .isRoot = true}, change,
|
||||
ChangeType::ADD);
|
||||
},
|
||||
0},
|
||||
{"animations_merge", "03a_groups_nested.anm2",
|
||||
[&](model::Model& anm2) { return edit::animations_merge(anm2, 0, {1}, types::merge::APPEND, true, {0}); }, 1},
|
||||
[&](Model& anm2) { return animations_merge(anm2, 0, {1}, MERGE_APPEND, true, {0}); }, 1},
|
||||
};
|
||||
|
||||
for (const auto& entry : CASES)
|
||||
@@ -237,7 +234,7 @@ TEST_CASE("edit layer operations")
|
||||
auto uids = entry.operation(anm2);
|
||||
CHECK(uids.size() == entry.uidCount);
|
||||
anm2.uids_repair();
|
||||
model::UidIndex index(anm2);
|
||||
UidIndex index(anm2);
|
||||
for (auto uid : uids)
|
||||
CHECK(index.reference_get(uid));
|
||||
operation_check(entry.name, anm2);
|
||||
@@ -248,11 +245,11 @@ TEST_CASE("spritesheet pixel edits")
|
||||
{
|
||||
auto image_make = [](glm::ivec2 size, std::vector<glm::ivec2> opaque = {})
|
||||
{
|
||||
std::vector<uint8_t> pixels((std::size_t)size.x * size.y * resource::image::CHANNELS, 0);
|
||||
std::vector<uint8_t> pixels((std::size_t)size.x * size.y * IMAGE_CHANNELS, 0);
|
||||
for (auto point : opaque)
|
||||
std::fill_n(pixels.begin() + ((std::size_t)point.y * size.x + point.x) * resource::image::CHANNELS,
|
||||
resource::image::CHANNELS, 255);
|
||||
return resource::Image(pixels.data(), size);
|
||||
std::fill_n(pixels.begin() + ((std::size_t)point.y * size.x + point.x) * IMAGE_CHANNELS,
|
||||
IMAGE_CHANNELS, 255);
|
||||
return Image(pixels.data(), size);
|
||||
};
|
||||
auto sheet = image_make({64, 64}, {{4, 6}});
|
||||
auto other = image_make({16, 16});
|
||||
@@ -260,8 +257,8 @@ TEST_CASE("spritesheet pixel edits")
|
||||
SUBCASE("regions_trim shrinks to content and keeps the custom pivot in place")
|
||||
{
|
||||
auto model = fixture_load("05_regions.anm2");
|
||||
CHECK(edit::regions_trim(model, 0, {0, 1}, sheet));
|
||||
auto region = model::item_get(model.content.spritesheets[0].regions, 0);
|
||||
CHECK(regions_trim(model, 0, {0, 1}, sheet));
|
||||
auto region = item_get(model.content.spritesheets[0].regions, 0);
|
||||
CHECK(region->crop == glm::vec2(4, 6));
|
||||
CHECK(region->size == glm::vec2(1, 1));
|
||||
CHECK(region->pivot == glm::vec2(-1, -1));
|
||||
@@ -270,7 +267,7 @@ TEST_CASE("spritesheet pixel edits")
|
||||
SUBCASE("spritesheet_pack returns an image holding every region")
|
||||
{
|
||||
auto model = fixture_load("05_regions.anm2");
|
||||
auto packed = edit::spritesheet_pack(model, 0, sheet, 1);
|
||||
auto packed = spritesheet_pack(model, 0, sheet, 1);
|
||||
REQUIRE(packed);
|
||||
CHECK(packed->is_valid());
|
||||
for (auto& region : model.content.spritesheets[0].regions)
|
||||
@@ -281,11 +278,11 @@ TEST_CASE("spritesheet pixel edits")
|
||||
{
|
||||
auto model = fixture_load("05_regions.anm2");
|
||||
auto image_get = [&](int id) { return id == 0 ? &sheet : &other; };
|
||||
auto merged = edit::spritesheets_merge(model, {0, 1}, image_get, true, true, false, Origin::TOP_LEFT);
|
||||
auto merged = spritesheets_merge(model, {0, 1}, image_get, true, true, false, Origin::TOP_LEFT);
|
||||
REQUIRE(merged);
|
||||
CHECK(merged->size == glm::ivec2(80, 64));
|
||||
CHECK(model.content.spritesheets.size() == 1);
|
||||
CHECK(model::item_get(model.content.layers, 1)->spritesheetId == 0);
|
||||
CHECK(item_get(model.content.layers, 1)->spritesheetId == 0);
|
||||
operation_check("spritesheets_merge", model);
|
||||
}
|
||||
}
|
||||
@@ -298,9 +295,9 @@ TEST_CASE("markers stay in the editor's copy and bound playback")
|
||||
animation->frameNum = 10;
|
||||
animation->startMarker = 2;
|
||||
animation->endMarker = 5;
|
||||
CHECK(model::animation_play_range_get(*animation) == glm::ivec2(2, 6));
|
||||
CHECK(animation_play_range_get(*animation) == glm::ivec2(2, 6));
|
||||
|
||||
auto text = model::model_to_string(model);
|
||||
auto text = model_to_string(model);
|
||||
CHECK(game_document_get(text).find("Marker") == std::string::npos);
|
||||
auto reloaded = model_load(text);
|
||||
CHECK(reloaded.animation_get(0)->startMarker == 2);
|
||||
@@ -316,36 +313,36 @@ TEST_CASE("markers stay in the editor's copy and bound playback")
|
||||
|
||||
TEST_CASE("isaac_issues_get counts what the game's copy changes")
|
||||
{
|
||||
CHECK(model::isaac_issues_get(fixture_load("01_minimal.anm2")) == model::IsaacIssues{});
|
||||
CHECK(model::isaac_issues_get(fixture_load("07_special_interpolation.anm2")).easedFrames == 5);
|
||||
CHECK(model::isaac_issues_get(fixture_load("04_group_root_transform.anm2")).groupTransforms > 0);
|
||||
auto shaders = model::isaac_issues_get(fixture_load("06_shaders.anm2"));
|
||||
CHECK(isaac_issues_get(fixture_load("01_minimal.anm2")) == IsaacIssues{});
|
||||
CHECK(isaac_issues_get(fixture_load("07_special_interpolation.anm2")).easedFrames == 5);
|
||||
CHECK(isaac_issues_get(fixture_load("04_group_root_transform.anm2")).groupTransforms > 0);
|
||||
auto shaders = isaac_issues_get(fixture_load("06_shaders.anm2"));
|
||||
CHECK(shaders.shaderFrames > 0);
|
||||
CHECK(shaders.skewFrames > 0);
|
||||
CHECK(model::isaac_issues_get(fixture_load("02_items.anm2")).triggerSounds > 0);
|
||||
CHECK(isaac_issues_get(fixture_load("02_items.anm2")).triggerSounds > 0);
|
||||
}
|
||||
|
||||
TEST_CASE("frames_property_set copies one property to the frames that have it")
|
||||
{
|
||||
auto model = fixture_load("02_items.anm2");
|
||||
model::Frame source{.crop = {7, 8}, .position = {3, 4}};
|
||||
Frame source{.crop = {7, 8}, .position = {3, 4}};
|
||||
Reference layer{0, LAYER, 0, 0};
|
||||
Reference null{0, NULL_, 0, 0};
|
||||
REQUIRE(model.frame_get(layer));
|
||||
REQUIRE(model.frame_get(null));
|
||||
auto nullCrop = model.frame_get(null)->crop;
|
||||
|
||||
edit::frames_property_set(model, {layer, null}, edit::FrameProperty::POSITION, source);
|
||||
frames_property_set(model, {layer, null}, FrameProperty::POSITION, source);
|
||||
CHECK(model.frame_get(layer)->position == glm::vec2(3, 4));
|
||||
CHECK(model.frame_get(null)->position == glm::vec2(3, 4));
|
||||
|
||||
edit::frames_property_set(model, {layer, null}, edit::FrameProperty::CROP, source);
|
||||
frames_property_set(model, {layer, null}, FrameProperty::CROP, source);
|
||||
CHECK(model.frame_get(layer)->crop == glm::vec2(7, 8));
|
||||
CHECK(model.frame_get(null)->crop == nullCrop);
|
||||
|
||||
CHECK_FALSE(edit::is_frame_property_valid(edit::FrameProperty::EVENT, ItemType::LAYER));
|
||||
CHECK(edit::is_frame_property_valid(edit::FrameProperty::SOUNDS, ItemType::TRIGGER));
|
||||
CHECK_FALSE(edit::is_frame_property_valid(edit::FrameProperty::POSITION, ItemType::TRIGGER));
|
||||
CHECK_FALSE(is_frame_property_valid(FrameProperty::EVENT, ItemType::LAYER));
|
||||
CHECK(is_frame_property_valid(FrameProperty::SOUNDS, ItemType::TRIGGER));
|
||||
CHECK_FALSE(is_frame_property_valid(FrameProperty::POSITION, ItemType::TRIGGER));
|
||||
}
|
||||
|
||||
TEST_CASE("frames_split splits every selected frame that spans the time")
|
||||
@@ -360,7 +357,7 @@ TEST_CASE("frames_split splits every selected frame that spans the time")
|
||||
REQUIRE(layerTrack->frames[0].duration > 1);
|
||||
REQUIRE(nullTrack->frames[0].duration > 1);
|
||||
|
||||
auto uids = edit::frames_split(model, {{0, LAYER, 0, 0}, {0, NULL_, 0, 0}}, 0);
|
||||
auto uids = frames_split(model, {{0, LAYER, 0, 0}, {0, NULL_, 0, 0}}, 0);
|
||||
CHECK(uids.size() == 2);
|
||||
CHECK(model.track_get({0, LAYER, 0})->frames.size() == layerCount + 1);
|
||||
CHECK(model.track_get({0, NULL_, 0})->frames.size() == nullCount + 1);
|
||||
@@ -372,8 +369,8 @@ TEST_CASE("change all frame properties changes layer depth only")
|
||||
auto model = fixture_load("02_items.anm2");
|
||||
Reference layer{0, LAYER, 0, 0};
|
||||
Reference null{0, NULL_, 0, 0};
|
||||
edit::frames_change_apply(model, {.references = {layer, null}}, {.depth = 2}, ChangeType::ADD);
|
||||
edit::frames_change_apply(model, {.references = {layer, null}}, {.depth = 1}, ChangeType::SUBTRACT);
|
||||
frames_change_apply(model, {.references = {layer, null}}, {.depth = 2}, ChangeType::ADD);
|
||||
frames_change_apply(model, {.references = {layer, null}}, {.depth = 1}, ChangeType::SUBTRACT);
|
||||
CHECK(model.frame_get(layer)->depth == 1);
|
||||
CHECK(model.frame_get(null)->depth == 0);
|
||||
}
|
||||
@@ -384,7 +381,7 @@ TEST_CASE("change all frame properties blurs layers and changes only animation l
|
||||
Reference animationLayer{0, LAYER, 1, 0};
|
||||
Reference spritesheetLayer{1, LAYER, 2, 0};
|
||||
REQUIRE(model.frame_get(spritesheetLayer));
|
||||
edit::frames_change_apply(model, {.references = {animationLayer, spritesheetLayer}},
|
||||
frames_change_apply(model, {.references = {animationLayer, spritesheetLayer}},
|
||||
{.blur = 8.0f, .childAnimation = "Spin", .childMode = ChildMode::ONCE, .childStart = 3},
|
||||
ChangeType::ADJUST);
|
||||
auto child = *model.frame_get(animationLayer);
|
||||
@@ -398,7 +395,7 @@ TEST_CASE("change all frame properties blurs layers and changes only animation l
|
||||
CHECK(sprite.childMode == ChildMode::LOOP);
|
||||
CHECK(sprite.childStart == 0);
|
||||
|
||||
edit::frames_change_apply(model, {.references = {animationLayer}}, {.blur = 1000.0f}, ChangeType::ADD);
|
||||
frames_change_apply(model, {.references = {animationLayer}}, {.blur = 1000.0f}, ChangeType::ADD);
|
||||
CHECK(model.frame_get(animationLayer)->blur == FRAME_BLUR_MAX);
|
||||
}
|
||||
|
||||
@@ -410,26 +407,26 @@ TEST_CASE("animations_merge moves triggers past the animation placed before them
|
||||
auto first = *model.animation_get(0);
|
||||
first.frameNum = 10;
|
||||
auto second = first;
|
||||
second.uid = util::uid_next();
|
||||
second.triggers.frames = {model::Frame{.atFrame = 5}};
|
||||
model.animations.entries = {std::make_shared<const model::Animation>(first),
|
||||
std::make_shared<const model::Animation>(second)};
|
||||
second.uid = uid_next();
|
||||
second.triggers.frames = {Frame{.atFrame = 5}};
|
||||
model.animations.entries = {std::make_shared<const Animation>(first),
|
||||
std::make_shared<const Animation>(second)};
|
||||
return model;
|
||||
};
|
||||
|
||||
auto appended = model_make();
|
||||
edit::animations_merge(appended, 0, {0, 1}, types::merge::APPEND, false, {});
|
||||
animations_merge(appended, 0, {0, 1}, MERGE_APPEND, false, {});
|
||||
CHECK(appended.animation_get(0)->triggers.frames.at(0).atFrame == 15);
|
||||
|
||||
auto prepended = model_make();
|
||||
edit::animations_merge(prepended, 1, {0, 1}, types::merge::PREPEND, false, {});
|
||||
animations_merge(prepended, 1, {0, 1}, MERGE_PREPEND, false, {});
|
||||
CHECK(prepended.animation_get(1)->triggers.frames.at(0).atFrame == 15);
|
||||
}
|
||||
|
||||
TEST_CASE("skew reads from the old Shear attributes too")
|
||||
{
|
||||
auto frames =
|
||||
model::frames_from_string(R"(<Frame ShearX="5" ShearY="6"/><Frame SkewX="7" ShearX="9"/>)", ItemType::NULL_);
|
||||
frames_from_string(R"(<Frame ShearX="5" ShearY="6"/><Frame SkewX="7" ShearX="9"/>)", ItemType::NULL_);
|
||||
REQUIRE(frames.size() == 2);
|
||||
CHECK(frames[0].skew == glm::vec2(5, 6));
|
||||
CHECK(frames[1].skew.x == 7);
|
||||
@@ -440,38 +437,38 @@ TEST_CASE("a trigger fires several events; the game's copy keeps the first")
|
||||
{
|
||||
auto model = fixture_load("02_items.anm2");
|
||||
model.frame_edit({0, TRIGGER, -1, 0})->eventIds = {1, 0};
|
||||
auto text = model::model_to_string(model);
|
||||
auto text = model_to_string(model);
|
||||
CHECK(model_load(text).frame_get({0, TRIGGER, -1, 0})->eventIds == std::vector{1, 0});
|
||||
CHECK(model_load(game_document_get(text)).frame_get({0, TRIGGER, -1, 0})->eventIds == std::vector{1});
|
||||
CHECK(model::isaac_issues_get(model).extraEvents == 1);
|
||||
CHECK(isaac_issues_get(model).extraEvents == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("SVG spritesheets pack and merge into SVGs")
|
||||
{
|
||||
auto model = model_load(file_load(TEST_DIR / "render" / "vector.anm2"));
|
||||
resource::Image vector(TEST_DIR / "render" / "vector.svg");
|
||||
Image vector(TEST_DIR / "render" / "vector.svg");
|
||||
auto& regions = model.content.spritesheets.front().regions;
|
||||
regions.push_back({.id = 0, .name = "circle", .crop = {0, 0}, .size = {16, 16}});
|
||||
regions.push_back({.id = 1, .name = "square", .crop = {16, 0}, .size = {16, 16}});
|
||||
|
||||
// Packing keeps the drawing: each region shows the same pixels where it now sits.
|
||||
auto packed = edit::spritesheet_pack(model, 0, vector, 1);
|
||||
auto packed = spritesheet_pack(model, 0, vector, 1);
|
||||
REQUIRE(packed);
|
||||
CHECK(packed->is_vector());
|
||||
for (auto [id, original] : {std::pair{0, glm::vec2(8, 8)}, std::pair{1, glm::vec2(24, 8)}})
|
||||
{
|
||||
auto region = model::item_get(model.content.spritesheets.front().regions, id);
|
||||
auto region = item_get(model.content.spritesheets.front().regions, id);
|
||||
CHECK(packed->pixel_read(region->crop + glm::vec2(8, 8)) == vector.pixel_read(original));
|
||||
}
|
||||
|
||||
// A PNG sheet merged after an SVG one: the result is an SVG holding the PNG; a PNG first takes the .svg name.
|
||||
const std::vector<uint8_t> pixels(4 * 4 * resource::image::CHANNELS, 255);
|
||||
resource::Image raster(pixels.data(), {4, 4});
|
||||
const std::vector<uint8_t> pixels(4 * 4 * IMAGE_CHANNELS, 255);
|
||||
Image raster(pixels.data(), {4, 4});
|
||||
model.content.spritesheets.push_back({.id = 1, .path = "white.png"});
|
||||
auto images = std::map<int, const resource::Image*>{{0, &vector}, {1, &raster}};
|
||||
auto images = std::map<int, const Image*>{{0, &vector}, {1, &raster}};
|
||||
auto image_get = [&](int id) { return images.at(id); };
|
||||
auto mixed = model;
|
||||
auto merged = edit::spritesheets_merge(mixed, {0, 1}, image_get, true, false, false, Origin::TOP_LEFT);
|
||||
auto merged = spritesheets_merge(mixed, {0, 1}, image_get, true, false, false, Origin::TOP_LEFT);
|
||||
REQUIRE(merged);
|
||||
CHECK(merged->is_vector());
|
||||
CHECK(merged->size == glm::ivec2(36, 16));
|
||||
@@ -480,21 +477,21 @@ TEST_CASE("SVG spritesheets pack and merge into SVGs")
|
||||
|
||||
std::swap(model.content.spritesheets.front().id, model.content.spritesheets.back().id);
|
||||
images = {{1, &vector}, {0, &raster}};
|
||||
REQUIRE(edit::spritesheets_merge(model, {0, 1}, image_get, true, false, false, Origin::TOP_LEFT));
|
||||
CHECK(model::item_get(model.content.spritesheets, 0)->path == "white.svg");
|
||||
REQUIRE(spritesheets_merge(model, {0, 1}, image_get, true, false, false, Origin::TOP_LEFT));
|
||||
CHECK(item_get(model.content.spritesheets, 0)->path == "white.svg");
|
||||
}
|
||||
|
||||
TEST_CASE("content_remove takes what refers to an item with it")
|
||||
{
|
||||
auto path_keep = [](const model::Model&, const std::filesystem::path& path) { return path; };
|
||||
auto remove = [&](model::Model& model, ElementType type, std::set<int> ids, int spritesheetId = -1,
|
||||
const model::LibraryGet& library_get = {})
|
||||
{ edit::content_remove(model, type, ids, spritesheetId, library_get, path_keep); };
|
||||
auto tracks_count = [](const model::Model& model, int layerId)
|
||||
auto path_keep = [](const Model&, const std::filesystem::path& path) { return path; };
|
||||
auto remove = [&](Model& model, ElementType type, std::set<int> ids, int spritesheetId = -1,
|
||||
const LibraryGet& library_get = {})
|
||||
{ content_remove(model, type, ids, spritesheetId, library_get, path_keep); };
|
||||
auto tracks_count = [](const Model& model, int layerId)
|
||||
{
|
||||
int count{};
|
||||
for (auto [index, animation] : model.animations_get())
|
||||
model::tracks_each(animation->layers, [&](const model::Track& track, auto*) { count += track.id == layerId; });
|
||||
tracks_each(animation->layers, [&](const Track& track, auto*) { count += track.id == layerId; });
|
||||
return count;
|
||||
};
|
||||
|
||||
@@ -503,7 +500,7 @@ TEST_CASE("content_remove takes what refers to an item with it")
|
||||
auto model = fixture_load("02_items.anm2");
|
||||
CHECK(model.uses_count(ElementType::LAYER_ELEMENT, {0}) == tracks_count(model, 0));
|
||||
remove(model, ElementType::LAYER_ELEMENT, {0});
|
||||
CHECK_FALSE(model::item_get(model.content.layers, 0));
|
||||
CHECK_FALSE(item_get(model.content.layers, 0));
|
||||
CHECK(tracks_count(model, 0) == 0);
|
||||
CHECK(tracks_count(model, 1) > 0);
|
||||
|
||||
@@ -546,7 +543,7 @@ TEST_CASE("content_remove takes what refers to an item with it")
|
||||
CHECK(after.crop == before.crop);
|
||||
CHECK(after.size == before.size);
|
||||
CHECK(after.pivot == before.pivot);
|
||||
CHECK_FALSE(model::item_get(regions.content.spritesheets.front().regions, 0));
|
||||
CHECK_FALSE(item_get(regions.content.spritesheets.front().regions, 0));
|
||||
}
|
||||
|
||||
SUBCASE("a library's layers, flattened")
|
||||
@@ -555,13 +552,13 @@ TEST_CASE("content_remove takes what refers to an item with it")
|
||||
auto spin = model_load(file_load(TEST_DIR / "render" / "spin.anm2"));
|
||||
CHECK(model.uses_count(ElementType::LIBRARY, {0}) == 1);
|
||||
remove(model, ElementType::LIBRARY, {0}, -1,
|
||||
[&](const model::Model&, int id) { return id == 0 ? &spin : nullptr; });
|
||||
[&](const Model&, int id) { return id == 0 ? &spin : nullptr; });
|
||||
CHECK(model.content.libraries.empty());
|
||||
CHECK_FALSE(model::item_get(model.content.layers, 0));
|
||||
CHECK_FALSE(item_get(model.content.layers, 0));
|
||||
CHECK(
|
||||
std::ranges::any_of(model.content.layers, [](const model::Layer& layer) { return layer.name == "spin/red"; }));
|
||||
std::ranges::any_of(model.content.layers, [](const Layer& layer) { return layer.name == "spin/red"; }));
|
||||
// Layers playing this file's animations stay as they are.
|
||||
CHECK(model::item_get(model.content.layers, 1)->is_animation());
|
||||
CHECK(model::item_get(model.content.layers, 3)->is_animation());
|
||||
CHECK(item_get(model.content.layers, 1)->is_animation());
|
||||
CHECK(item_get(model.content.layers, 3)->is_animation());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user