Drop dead model code, and let edits that select nothing return nothing
Model::uid_get, the UidIndex element types, Playback's accumulator, ID_NONE and track_frames_count_get were unused. Fourteen edit functions only ever returned an empty selection, so they return void.
This commit is contained in:
1 parent
c44c7fe8df
commit
544ab3cac9
16 files changed
+79
-117
No files matched your search
@@ -114,11 +114,10 @@ Uids animation_add(Model& model, int index, int groupId, int templateIndex, cons
|
||||
return {uid};
|
||||
}
|
||||
|
||||
Uids animations_remove(Model& model, const std::set<int>& indices, const std::set<int>& groupIds)
|
||||
void animations_remove(Model& model, const std::set<int>& indices, const std::set<int>& groupIds)
|
||||
{
|
||||
animations_take(model, indices, {});
|
||||
animation_groups_remove(model, groupIds);
|
||||
return {};
|
||||
}
|
||||
|
||||
// Moves animations and whole groups beside a target animation or group. Animations dropped on their own join the
|
||||
@@ -176,17 +175,16 @@ Uids animations_move(Model& model, const std::set<int>& indices, const std::set<
|
||||
}
|
||||
|
||||
// Gathers animations into a new group placed where the first of them was.
|
||||
Uids animations_group(Model& model, const std::set<int>& indices, const std::string& name)
|
||||
void animations_group(Model& model, const std::set<int>& indices, const std::string& name)
|
||||
{
|
||||
auto first = indices.empty() ? nullptr : model.animation_get(*indices.begin());
|
||||
if (!first)
|
||||
return {};
|
||||
return;
|
||||
auto& entries = model.animations.entries;
|
||||
auto entry = animation_place_get(model, first->uid).entry;
|
||||
AnimationGroup group = {
|
||||
.id = group_next_id(entries), .name = name, .items = animations_take(model, indices, {}).items};
|
||||
entries.insert(entries.begin() + std::clamp(entry, 0, (int)entries.size()), std::move(group));
|
||||
return {};
|
||||
}
|
||||
|
||||
// Pastes clipboard animations (and groups, which get new ids) before the animation at `start`. Lone animations join
|
||||
|
||||
+6
-11
@@ -39,7 +39,7 @@ template <class Callback> static void layer_frames_each(Model& model, int animat
|
||||
}
|
||||
|
||||
// Makes a region for each distinct crop/size/pivot among the frames (and points frames at them when mapping is SET).
|
||||
Uids regions_generate(Model& model, const std::set<int>& animationIndices, const std::set<Reference>& frames,
|
||||
void regions_generate(Model& model, const std::set<int>& animationIndices, const std::set<Reference>& frames,
|
||||
const std::string& format, RegionFrameMapping mapping)
|
||||
{
|
||||
std::unordered_map<int, int> regionNumbers;
|
||||
@@ -66,11 +66,10 @@ Uids regions_generate(Model& model, const std::set<int>& animationIndices, const
|
||||
if (spritesheet && source && source->regionId == -1)
|
||||
frame_apply(*model.frame_edit(reference), spritesheet->id);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
// Points frames without a region at a region of their spritesheet with the same crop/size/pivot.
|
||||
Uids regions_scan(Model& model)
|
||||
void regions_scan(Model& model)
|
||||
{
|
||||
for (int i = 0; i < model.animations_count_get(); ++i)
|
||||
layer_frames_each(model, i, [&](Frame& frame, int spritesheetId) {
|
||||
@@ -79,17 +78,15 @@ Uids regions_scan(Model& model)
|
||||
if (auto match = region_matched_get(item_get(model.content.spritesheets, spritesheetId)->regions, frame))
|
||||
frame.regionId = match->id;
|
||||
});
|
||||
return {};
|
||||
}
|
||||
|
||||
// Copies each layer frame's region crop/size/pivot onto it. Frames pointing at a missing region lose it.
|
||||
Uids region_frames_sync(Model& model)
|
||||
void region_frames_sync(Model& model)
|
||||
{
|
||||
for (int i = 0; i < model.animations_count_get(); ++i)
|
||||
layer_frames_each(model, i, [&](Frame& frame, int spritesheetId) {
|
||||
frame_region_apply(frame, item_get(model.content.spritesheets, spritesheetId)->regions);
|
||||
});
|
||||
return {};
|
||||
}
|
||||
|
||||
// Clears frame references to the spritesheet's unused regions, then removes them.
|
||||
@@ -97,7 +94,7 @@ Uids region_frames_sync(Model& model)
|
||||
// in every animation, an event or sound from its triggers (dropping those left with neither), a shader from its
|
||||
// frames (which go back to the default), a region from its frames (which keep its crop, size and pivot), a
|
||||
// spritesheet's plain layers, and a library's layers, flattened into plain ones.
|
||||
Uids content_remove(Model& model, ElementType type, const std::set<int>& ids, int spritesheetId,
|
||||
void content_remove(Model& model, ElementType type, const std::set<int>& ids, int spritesheetId,
|
||||
const LibraryGet& library_get, const SpritesheetPathGet& path_get)
|
||||
{
|
||||
auto& content = model.content;
|
||||
@@ -186,21 +183,19 @@ Uids content_remove(Model& model, ElementType type, const std::set<int>& ids, in
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
// Pastes regions into a spritesheet at a position. They get fresh ids after the existing ones.
|
||||
Uids regions_paste(Model& model, int spritesheetId, const std::string& text, int insertIndex, std::string* errorString)
|
||||
void regions_paste(Model& model, int spritesheetId, const std::string& text, int insertIndex, std::string* errorString)
|
||||
{
|
||||
auto spritesheet = item_get(model.content.spritesheets, spritesheetId);
|
||||
if (!spritesheet)
|
||||
return {};
|
||||
return;
|
||||
auto regions = items_from_string<Region>(text, errorString);
|
||||
for (auto& region : regions)
|
||||
region.id = item_next_id_get(spritesheet->regions) + (int)(®ion - regions.data());
|
||||
insertIndex = std::clamp(insertIndex, 0, (int)spritesheet->regions.size());
|
||||
spritesheet->regions.insert(spritesheet->regions.begin() + insertIndex, regions.begin(), regions.end());
|
||||
return {};
|
||||
}
|
||||
|
||||
// Appends grid frames to each layer track (optionally making a region per frame) and fits the animation length.
|
||||
|
||||
+14
-14
@@ -94,39 +94,39 @@ Uids frames_property_set(Model&, const std::set<Reference>&, FrameProperty, cons
|
||||
std::map<Reference, std::set<int>> frames_by_track_get(const std::set<Reference>&);
|
||||
|
||||
Uids frame_insert(Model&, Reference, int);
|
||||
Uids frames_delete(Model&, const std::set<Reference>&);
|
||||
void frames_delete(Model&, const std::set<Reference>&);
|
||||
Uids frames_duplicate(Model&, const std::set<Reference>&, Reference);
|
||||
Uids frames_reverse(Model&, const std::set<Reference>&);
|
||||
void frames_reverse(Model&, const std::set<Reference>&);
|
||||
Uids frames_bake(Model&, const std::set<Reference>&, int, bool, bool);
|
||||
Uids frame_split(Model&, Reference, int);
|
||||
Uids frames_split(Model&, const std::set<Reference>&, int);
|
||||
Uids frames_move(Model&, const std::set<Reference>&, Reference, int);
|
||||
Uids frame_durations_set(Model&, const std::map<Reference, int>&);
|
||||
Uids trigger_at_frame_set(Model&, Reference, int);
|
||||
void frame_durations_set(Model&, const std::map<Reference, int>&);
|
||||
void trigger_at_frame_set(Model&, Reference, int);
|
||||
Uids frames_paste(Model&, Reference, const std::set<Reference>&, const std::string&, int, std::string*);
|
||||
Uids root_bake_into(Model&, const std::set<Reference>&, const std::set<Reference>&, RootBakeOptions);
|
||||
|
||||
Uids items_remove(Model&, int, const std::map<int, std::set<int>>&, const std::map<int, std::set<int>>&);
|
||||
void items_remove(Model&, int, const std::map<int, std::set<int>>&, const std::map<int, std::set<int>>&);
|
||||
Uids items_group(Model&, int, int, const std::set<int>&, const std::string&);
|
||||
Uids items_move(Model&, int, int, const std::set<int>&, const std::set<int>&, RowTarget, bool, bool);
|
||||
Uids animation_length_fit(Model&, int);
|
||||
void items_move(Model&, int, int, const std::set<int>&, const std::set<int>&, RowTarget, bool, bool);
|
||||
void animation_length_fit(Model&, int);
|
||||
int item_add(Model&, ItemType, int, int, Layer, Null, int, Destination);
|
||||
|
||||
std::set<int> animation_group_ids_get(const Model&);
|
||||
std::set<int> animation_group_indices_get(const Model&, int);
|
||||
void animation_groups_remove(Model&, const std::set<int>&);
|
||||
Uids animation_add(Model&, int, int, int, const std::string&);
|
||||
Uids animations_remove(Model&, const std::set<int>&, const std::set<int>&);
|
||||
void animations_remove(Model&, const std::set<int>&, const std::set<int>&);
|
||||
Uids animations_move(Model&, const std::set<int>&, const std::set<int>&, AnimationTarget);
|
||||
Uids animations_group(Model&, const std::set<int>&, const std::string&);
|
||||
void animations_group(Model&, const std::set<int>&, const std::string&);
|
||||
Uids animations_paste(Model&, const std::string&, int, int, std::set<int>&, std::string*);
|
||||
Uids animations_merge(Model&, int, std::set<int>, Merge, bool, const std::set<int>&);
|
||||
|
||||
std::string region_name_get(const std::string&, int);
|
||||
Uids regions_generate(Model&, const std::set<int>&, const std::set<Reference>&, const std::string&, RegionFrameMapping);
|
||||
Uids regions_scan(Model&);
|
||||
Uids region_frames_sync(Model&);
|
||||
Uids regions_paste(Model&, int, const std::string&, int, std::string*);
|
||||
void regions_generate(Model&, const std::set<int>&, const std::set<Reference>&, const std::string&, RegionFrameMapping);
|
||||
void regions_scan(Model&);
|
||||
void region_frames_sync(Model&);
|
||||
void regions_paste(Model&, int, const std::string&, int, std::string*);
|
||||
Uids animation_grid_generate(Model&, const std::vector<Reference>&, const GridOptions&);
|
||||
Uids frames_change_apply(Model&, const ChangeTargets&, FrameChange, ChangeType);
|
||||
bool regions_trim(Model&, int, const std::set<int>&, const Image&);
|
||||
@@ -136,6 +136,6 @@ std::optional<Image> spritesheets_merge(Model&, const std::set<int>&, const Imag
|
||||
// Where a spritesheet path of a document (this one, or a library) points, from this document.
|
||||
using SpritesheetPathGet = std::function<std::filesystem::path(const Model&, const std::filesystem::path&)>;
|
||||
Model animation_layers_flatten(Model, const LibraryGet&, const SpritesheetPathGet&, const std::set<int>& = {});
|
||||
Uids content_remove(Model&, ElementType, const std::set<int>&, int, const LibraryGet&, const SpritesheetPathGet&);
|
||||
void content_remove(Model&, ElementType, const std::set<int>&, int, const LibraryGet&, const SpritesheetPathGet&);
|
||||
Model isaac_bridge(Model);
|
||||
bool file_merge(Model&, const std::filesystem::path&, const std::filesystem::path&, FileMergePreset);
|
||||
+5
-9
@@ -53,14 +53,13 @@ Uids frame_insert(Model& model, Reference reference, int time)
|
||||
return {frame.uid};
|
||||
}
|
||||
|
||||
Uids frames_delete(Model& model, const std::set<Reference>& frames)
|
||||
void frames_delete(Model& model, const std::set<Reference>& frames)
|
||||
{
|
||||
for (auto& [trackReference, indices] : frames_by_track_get(frames))
|
||||
if (auto track = model.track_edit(trackReference))
|
||||
for (auto it = indices.rbegin(); it != indices.rend(); ++it)
|
||||
if (*it >= 0 && *it < (int)track->frames.size())
|
||||
track->frames.erase(track->frames.begin() + *it);
|
||||
return {};
|
||||
}
|
||||
|
||||
Uids frames_duplicate(Model& model, const std::set<Reference>& frames, Reference focus)
|
||||
@@ -100,7 +99,7 @@ Uids frames_duplicate(Model& model, const std::set<Reference>& frames, Reference
|
||||
}
|
||||
|
||||
// Reverses the selected frames of each track as one block placed where the first of them was.
|
||||
Uids frames_reverse(Model& model, const std::set<Reference>& frames)
|
||||
void frames_reverse(Model& model, const std::set<Reference>& frames)
|
||||
{
|
||||
for (auto& [trackReference, indices] : frames_by_track_get(frames))
|
||||
{
|
||||
@@ -118,7 +117,6 @@ Uids frames_reverse(Model& model, const std::set<Reference>& frames)
|
||||
auto index = std::min(*indices.begin(), (int)track->frames.size());
|
||||
track->frames.insert(track->frames.begin() + index, reversed.begin(), reversed.end());
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
Uids frames_bake(Model& model, const std::set<Reference>& frames, int interval, bool isRoundScale, bool isRoundRotation)
|
||||
@@ -319,25 +317,23 @@ Uids frames_property_set(Model& model, const std::set<Reference>& references, Fr
|
||||
return uids;
|
||||
}
|
||||
|
||||
Uids frame_durations_set(Model& model, const std::map<Reference, int>& durations)
|
||||
void frame_durations_set(Model& model, const std::map<Reference, int>& durations)
|
||||
{
|
||||
for (auto [reference, duration] : durations)
|
||||
if (auto frame = model.frame_edit(reference))
|
||||
frame->duration = std::clamp(duration, FRAME_DURATION_MIN, FRAME_DURATION_MAX);
|
||||
return {};
|
||||
}
|
||||
|
||||
// Places a trigger at a frame, stepping it back past any other trigger already there.
|
||||
Uids trigger_at_frame_set(Model& model, Reference reference, int atFrame)
|
||||
void trigger_at_frame_set(Model& model, Reference reference, int atFrame)
|
||||
{
|
||||
auto trigger = model.frame_edit(reference);
|
||||
if (!trigger)
|
||||
return {};
|
||||
return;
|
||||
trigger->atFrame = atFrame;
|
||||
for (auto& other : model.track_get(reference)->frames)
|
||||
if (&other != trigger && other.atFrame == trigger->atFrame)
|
||||
trigger->atFrame--;
|
||||
return {};
|
||||
}
|
||||
|
||||
// Pastes clipboard frames after the track's selected frames (or its current frame). Triggers go at `time`, stepping
|
||||
|
||||
+6
-9
@@ -8,7 +8,7 @@ static std::vector<TrackEntry>* track_entries_edit(Model& model, int animationIn
|
||||
return animation ? &animation_entries_get(*animation, type) : nullptr;
|
||||
}
|
||||
|
||||
Uids items_remove(Model& model, int animationIndex, const std::map<int, std::set<int>>& ids,
|
||||
void items_remove(Model& model, int animationIndex, const std::map<int, std::set<int>>& ids,
|
||||
const std::map<int, std::set<int>>& groupIds)
|
||||
{
|
||||
for (auto type : {LAYER, NULL_})
|
||||
@@ -18,7 +18,6 @@ Uids items_remove(Model& model, int animationIndex, const std::map<int, std::set
|
||||
auto typeGroupIds = groupIds.contains(type) ? groupIds.at(type) : std::set<int>{};
|
||||
entries_take(*entries, [&](Track& track) { return typeIds.contains(track.id); }, typeGroupIds);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
// Wraps ungrouped tracks in a new group placed where the first of them was.
|
||||
@@ -36,17 +35,17 @@ Uids items_group(Model& model, int animationIndex, int type, const std::set<int>
|
||||
|
||||
// Moves tracks and whole groups next to (or into) a target row. Layers are listed bottom-up, so for them "after" on
|
||||
// screen is "before" in the file.
|
||||
Uids items_move(Model& model, int animationIndex, int type, const std::set<int>& ids, const std::set<int>& groupIds,
|
||||
void items_move(Model& model, int animationIndex, int type, const std::set<int>& ids, const std::set<int>& groupIds,
|
||||
RowTarget target, bool isDropAfter, bool isDropIntoGroup)
|
||||
{
|
||||
if ((target.groupId != -1 && groupIds.contains(target.groupId)) || (target.isGroup && groupIds.contains(target.id)))
|
||||
return {};
|
||||
return;
|
||||
auto entries = track_entries_edit(model, animationIndex, type);
|
||||
if (!entries)
|
||||
return {};
|
||||
return;
|
||||
auto taken = entries_take(*entries, [&](Track& track) { return ids.contains(track.id); }, groupIds);
|
||||
if (taken.items.empty() && taken.groups.empty())
|
||||
return {};
|
||||
return;
|
||||
|
||||
// Where top-level items go: beside the target row, or beside the group that holds it.
|
||||
auto isAfter = type == LAYER ? !isDropAfter : isDropAfter;
|
||||
@@ -80,14 +79,12 @@ Uids items_move(Model& model, int animationIndex, int type, const std::set<int>&
|
||||
taken.items.clear();
|
||||
}
|
||||
entries_insert(*entries, topIndex, std::move(taken));
|
||||
return {};
|
||||
}
|
||||
|
||||
Uids animation_length_fit(Model& model, int animationIndex)
|
||||
void animation_length_fit(Model& model, int animationIndex)
|
||||
{
|
||||
if (auto animation = model.animation_edit(animationIndex))
|
||||
animation->frameNum = animation_length_get(*animation);
|
||||
return {};
|
||||
}
|
||||
|
||||
// Adds a layer or null (or updates the one with the item's id) and gives it a track in one or every animation.
|
||||
|
||||
Reference in new issue
Block a user