remove unused fix

This commit is contained in:
2026-01-18 16:32:33 -05:00
parent cbfb3403b7
commit 044ef8b818
9 changed files with 21 additions and 61 deletions

View File

@@ -143,12 +143,11 @@ if(WIN32)
endif() endif()
endif() endif()
else() else()
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -pedantic)
if(CMAKE_BUILD_TYPE STREQUAL "Debug") if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_options(${PROJECT_NAME} PRIVATE -O0 -pg) target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wpedantic -O0 -pg)
else() else()
set(CMAKE_BUILD_TYPE "Release") set(CMAKE_BUILD_TYPE "Release")
target_compile_options(${PROJECT_NAME} PRIVATE -Os) target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wpedantic -O2)
endif() endif()
target_link_libraries(${PROJECT_NAME} PRIVATE m) target_link_libraries(${PROJECT_NAME} PRIVATE m)
endif() endif()

View File

@@ -37,11 +37,14 @@ namespace anm2ed::anm2
element = element->NextSiblingElement("Animation")) element = element->NextSiblingElement("Animation"))
{ {
auto index = start + count; auto index = start + count;
animations.items.insert(animations.items.begin() + start + count, Animation(element)); auto& animation = *animations.items.insert(animations.items.begin() + start + count, Animation(element));
for (auto& trigger : animation.triggers.frames)
if (!content.events.contains(trigger.eventID)) content.events[trigger.eventID];
indices.insert(index); indices.insert(index);
count++; count++;
} }
return true; return true;
} }
else if (errorString) else if (errorString)

View File

@@ -174,35 +174,20 @@ namespace anm2ed
{ {
hash_set(); hash_set();
auto layers_set = [&]() { layer.unused = anm2.layers_unused(); }; auto events_set = [&]() { event.labels_set(anm2.event_labels_get(), anm2.event_ids_get()); };
auto nulls_set = [&]() { null.unused = anm2.nulls_unused(); };
auto events_set = [&]()
{
event.unused = anm2.events_unused();
event.labels_set(anm2.event_labels_get(), anm2.event_ids_get());
};
auto animations_set = [&]() { animation.labels_set(anm2.animation_labels_get()); }; auto animations_set = [&]() { animation.labels_set(anm2.animation_labels_get()); };
auto spritesheets_set = [&]() auto spritesheets_set = [&]()
{ { spritesheet.labels_set(anm2.spritesheet_labels_get(), anm2.spritesheet_ids_get()); };
spritesheet.unused = anm2.spritesheets_unused();
spritesheet.labels_set(anm2.spritesheet_labels_get(), anm2.spritesheet_ids_get());
};
auto sounds_set = [&]() auto sounds_set = [&]() { sound.labels_set(anm2.sound_labels_get(), anm2.sound_ids_get()); };
{
sound.unused = anm2.sounds_unused();
sound.labels_set(anm2.sound_labels_get(), anm2.sound_ids_get());
};
switch (type) switch (type)
{ {
case LAYERS: case LAYERS:
layers_set();
break; break;
case NULLS: case NULLS:
nulls_set();
break; break;
case EVENTS: case EVENTS:
events_set(); events_set();
@@ -218,14 +203,10 @@ namespace anm2ed
sounds_set(); sounds_set();
break; break;
case ITEMS: case ITEMS:
layers_set();
nulls_set();
spritesheets_set(); spritesheets_set();
break; break;
case ANIMATIONS: case ANIMATIONS:
case ALL: case ALL:
layers_set();
nulls_set();
events_set(); events_set();
spritesheets_set(); spritesheets_set();
animations_set(); animations_set();

View File

@@ -17,7 +17,6 @@ namespace anm2ed::imgui
{ {
auto& document = *manager.get(); auto& document = *manager.get();
auto& anm2 = document.anm2; auto& anm2 = document.anm2;
auto& unused = document.event.unused;
auto& reference = document.event.reference; auto& reference = document.event.reference;
auto& selection = document.event.selection; auto& selection = document.event.selection;
@@ -45,6 +44,7 @@ namespace anm2ed::imgui
auto remove_unused = [&]() auto remove_unused = [&]()
{ {
auto unused = anm2.events_unused();
if (unused.empty()) return; if (unused.empty()) return;
auto behavior = [&]() auto behavior = [&]()
@@ -57,7 +57,6 @@ namespace anm2ed::imgui
anm2.content.events.erase(id); anm2.content.events.erase(id);
} }
unused.clear();
}; };
DOCUMENT_EDIT(document, localize.get(EDIT_REMOVE_UNUSED_EVENTS), Document::EVENTS, behavior()); DOCUMENT_EDIT(document, localize.get(EDIT_REMOVE_UNUSED_EVENTS), Document::EVENTS, behavior());
@@ -163,9 +162,7 @@ namespace anm2ed::imgui
selection.size() == 1)) selection.size() == 1))
rename(); rename();
if (ImGui::MenuItem(localize.get(SHORTCUT_STRING_ADD), settings.shortcutAdd.c_str())) add(); if (ImGui::MenuItem(localize.get(SHORTCUT_STRING_ADD), settings.shortcutAdd.c_str())) add();
if (ImGui::MenuItem(localize.get(BASIC_REMOVE_UNUSED), settings.shortcutRemove.c_str(), false, if (ImGui::MenuItem(localize.get(BASIC_REMOVE_UNUSED), settings.shortcutRemove.c_str())) remove_unused();
!unused.empty()))
remove_unused();
ImGui::Separator(); ImGui::Separator();
@@ -187,10 +184,8 @@ namespace anm2ed::imgui
set_item_tooltip_shortcut(localize.get(TOOLTIP_ADD_EVENT), settings.shortcutAdd); set_item_tooltip_shortcut(localize.get(TOOLTIP_ADD_EVENT), settings.shortcutAdd);
ImGui::SameLine(); ImGui::SameLine();
ImGui::BeginDisabled(unused.empty());
shortcut(manager.chords[SHORTCUT_REMOVE]); shortcut(manager.chords[SHORTCUT_REMOVE]);
if (ImGui::Button(localize.get(BASIC_REMOVE_UNUSED), widgetSize)) remove_unused(); if (ImGui::Button(localize.get(BASIC_REMOVE_UNUSED), widgetSize)) remove_unused();
ImGui::EndDisabled();
set_item_tooltip_shortcut(localize.get(TOOLTIP_REMOVE_UNUSED_EVENTS), settings.shortcutRemove); set_item_tooltip_shortcut(localize.get(TOOLTIP_REMOVE_UNUSED_EVENTS), settings.shortcutRemove);
} }
ImGui::End(); ImGui::End();

View File

@@ -18,7 +18,6 @@ namespace anm2ed::imgui
auto& document = *manager.get(); auto& document = *manager.get();
auto& anm2 = document.anm2; auto& anm2 = document.anm2;
auto& reference = document.layer.reference; auto& reference = document.layer.reference;
auto& unused = document.layer.unused;
auto& selection = document.layer.selection; auto& selection = document.layer.selection;
auto& propertiesPopup = manager.layerPropertiesPopup; auto& propertiesPopup = manager.layerPropertiesPopup;
@@ -26,12 +25,13 @@ namespace anm2ed::imgui
auto remove_unused = [&]() auto remove_unused = [&]()
{ {
auto unused = anm2.layers_unused();
if (unused.empty()) return; if (unused.empty()) return;
auto behavior = [&]() auto behavior = [&]()
{ {
for (auto& id : unused) for (auto& id : unused)
anm2.content.layers.erase(id); anm2.content.layers.erase(id);
unused.clear();
}; };
DOCUMENT_EDIT(document, localize.get(EDIT_REMOVE_UNUSED_LAYERS), Document::LAYERS, behavior()); DOCUMENT_EDIT(document, localize.get(EDIT_REMOVE_UNUSED_LAYERS), Document::LAYERS, behavior());
@@ -131,9 +131,7 @@ namespace anm2ed::imgui
if (ImGui::MenuItem(localize.get(BASIC_PROPERTIES), nullptr, false, selection.size() == 1)) if (ImGui::MenuItem(localize.get(BASIC_PROPERTIES), nullptr, false, selection.size() == 1))
properties(*selection.begin()); properties(*selection.begin());
if (ImGui::MenuItem(localize.get(BASIC_ADD), settings.shortcutAdd.c_str())) add(); if (ImGui::MenuItem(localize.get(BASIC_ADD), settings.shortcutAdd.c_str())) add();
if (ImGui::MenuItem(localize.get(BASIC_REMOVE_UNUSED), settings.shortcutRemove.c_str(), false, if (ImGui::MenuItem(localize.get(BASIC_REMOVE_UNUSED), settings.shortcutRemove.c_str())) remove_unused();
!unused.empty()))
remove_unused();
ImGui::Separator(); ImGui::Separator();
@@ -155,10 +153,8 @@ namespace anm2ed::imgui
set_item_tooltip_shortcut(localize.get(TOOLTIP_ADD_LAYER), settings.shortcutAdd); set_item_tooltip_shortcut(localize.get(TOOLTIP_ADD_LAYER), settings.shortcutAdd);
ImGui::SameLine(); ImGui::SameLine();
ImGui::BeginDisabled(unused.empty());
shortcut(manager.chords[SHORTCUT_REMOVE]); shortcut(manager.chords[SHORTCUT_REMOVE]);
if (ImGui::Button(localize.get(BASIC_REMOVE_UNUSED), widgetSize)) remove_unused(); if (ImGui::Button(localize.get(BASIC_REMOVE_UNUSED), widgetSize)) remove_unused();
ImGui::EndDisabled();
set_item_tooltip_shortcut(localize.get(TOOLTIP_REMOVE_UNUSED_LAYERS), settings.shortcutRemove); set_item_tooltip_shortcut(localize.get(TOOLTIP_REMOVE_UNUSED_LAYERS), settings.shortcutRemove);
} }
ImGui::End(); ImGui::End();

View File

@@ -18,7 +18,6 @@ namespace anm2ed::imgui
auto& document = *manager.get(); auto& document = *manager.get();
auto& anm2 = document.anm2; auto& anm2 = document.anm2;
auto& reference = document.null.reference; auto& reference = document.null.reference;
auto& unused = document.null.unused;
auto& selection = document.null.selection; auto& selection = document.null.selection;
auto& propertiesPopup = manager.nullPropertiesPopup; auto& propertiesPopup = manager.nullPropertiesPopup;
@@ -26,12 +25,12 @@ namespace anm2ed::imgui
auto remove_unused = [&]() auto remove_unused = [&]()
{ {
auto unused = anm2.nulls_unused();
if (unused.empty()) return; if (unused.empty()) return;
auto behavior = [&]() auto behavior = [&]()
{ {
for (auto& id : unused) for (auto& id : unused)
anm2.content.nulls.erase(id); anm2.content.nulls.erase(id);
unused.clear();
}; };
DOCUMENT_EDIT(document, localize.get(EDIT_REMOVE_UNUSED_NULLS), Document::NULLS, behavior()); DOCUMENT_EDIT(document, localize.get(EDIT_REMOVE_UNUSED_NULLS), Document::NULLS, behavior());
@@ -130,9 +129,7 @@ namespace anm2ed::imgui
if (ImGui::MenuItem(localize.get(BASIC_PROPERTIES), nullptr, false, selection.size() == 1)) if (ImGui::MenuItem(localize.get(BASIC_PROPERTIES), nullptr, false, selection.size() == 1))
properties(*selection.begin()); properties(*selection.begin());
if (ImGui::MenuItem(localize.get(BASIC_ADD), settings.shortcutAdd.c_str())) add(); if (ImGui::MenuItem(localize.get(BASIC_ADD), settings.shortcutAdd.c_str())) add();
if (ImGui::MenuItem(localize.get(BASIC_REMOVE_UNUSED), settings.shortcutRemove.c_str(), false, if (ImGui::MenuItem(localize.get(BASIC_REMOVE_UNUSED), settings.shortcutRemove.c_str())) remove_unused();
!unused.empty()))
remove_unused();
ImGui::Separator(); ImGui::Separator();
@@ -154,10 +151,8 @@ namespace anm2ed::imgui
set_item_tooltip_shortcut(localize.get(TOOLTIP_ADD_NULL), settings.shortcutAdd); set_item_tooltip_shortcut(localize.get(TOOLTIP_ADD_NULL), settings.shortcutAdd);
ImGui::SameLine(); ImGui::SameLine();
ImGui::BeginDisabled(unused.empty());
shortcut(manager.chords[SHORTCUT_REMOVE]); shortcut(manager.chords[SHORTCUT_REMOVE]);
if (ImGui::Button(localize.get(BASIC_REMOVE_UNUSED), widgetSize)) remove_unused(); if (ImGui::Button(localize.get(BASIC_REMOVE_UNUSED), widgetSize)) remove_unused();
ImGui::EndDisabled();
set_item_tooltip_shortcut(localize.get(TOOLTIP_REMOVE_UNUSED_NULLS), settings.shortcutRemove); set_item_tooltip_shortcut(localize.get(TOOLTIP_REMOVE_UNUSED_NULLS), settings.shortcutRemove);
} }
ImGui::End(); ImGui::End();

View File

@@ -19,7 +19,6 @@ namespace anm2ed::imgui
auto& document = *manager.get(); auto& document = *manager.get();
auto& anm2 = document.anm2; auto& anm2 = document.anm2;
auto& reference = document.sound.reference; auto& reference = document.sound.reference;
auto& unused = document.sound.unused;
auto& selection = document.sound.selection; auto& selection = document.sound.selection;
auto style = ImGui::GetStyle(); auto style = ImGui::GetStyle();
@@ -55,13 +54,13 @@ namespace anm2ed::imgui
auto remove_unused = [&]() auto remove_unused = [&]()
{ {
auto unused = anm2.sounds_unused();
if (unused.empty()) return; if (unused.empty()) return;
auto behavior = [&]() auto behavior = [&]()
{ {
for (auto& id : unused) for (auto& id : unused)
anm2.content.sounds.erase(id); anm2.content.sounds.erase(id);
unused.clear();
}; };
DOCUMENT_EDIT(document, localize.get(EDIT_REMOVE_UNUSED_SOUNDS), Document::SOUNDS, behavior()); DOCUMENT_EDIT(document, localize.get(EDIT_REMOVE_UNUSED_SOUNDS), Document::SOUNDS, behavior());
@@ -173,8 +172,7 @@ namespace anm2ed::imgui
open_directory(anm2.content.sounds[*selection.begin()]); open_directory(anm2.content.sounds[*selection.begin()]);
if (ImGui::MenuItem(localize.get(BASIC_ADD), settings.shortcutAdd.c_str())) add_open(); if (ImGui::MenuItem(localize.get(BASIC_ADD), settings.shortcutAdd.c_str())) add_open();
if (ImGui::MenuItem(localize.get(BASIC_REMOVE_UNUSED), settings.shortcutRemove.c_str(), false, !unused.empty())) if (ImGui::MenuItem(localize.get(BASIC_REMOVE_UNUSED), settings.shortcutRemove.c_str())) remove_unused();
remove_unused();
if (ImGui::MenuItem(localize.get(BASIC_RELOAD), nullptr, false, !selection.empty())) reload(); if (ImGui::MenuItem(localize.get(BASIC_RELOAD), nullptr, false, !selection.empty())) reload();
if (ImGui::MenuItem(localize.get(BASIC_REPLACE), nullptr, false, selection.size() == 1)) replace_open(); if (ImGui::MenuItem(localize.get(BASIC_REPLACE), nullptr, false, selection.size() == 1)) replace_open();
@@ -295,11 +293,9 @@ namespace anm2ed::imgui
ImGui::SameLine(); ImGui::SameLine();
ImGui::BeginDisabled(unused.empty());
imgui::shortcut(manager.chords[SHORTCUT_REMOVE]); imgui::shortcut(manager.chords[SHORTCUT_REMOVE]);
if (ImGui::Button(localize.get(BASIC_REMOVE_UNUSED), widgetSize)) remove_unused(); if (ImGui::Button(localize.get(BASIC_REMOVE_UNUSED), widgetSize)) remove_unused();
imgui::set_item_tooltip_shortcut(localize.get(TOOLTIP_REMOVE_UNUSED_SOUNDS), settings.shortcutRemove); imgui::set_item_tooltip_shortcut(localize.get(TOOLTIP_REMOVE_UNUSED_SOUNDS), settings.shortcutRemove);
ImGui::EndDisabled();
ImGui::SameLine(); ImGui::SameLine();

View File

@@ -24,7 +24,6 @@ namespace anm2ed::imgui
auto& document = *manager.get(); auto& document = *manager.get();
auto& anm2 = document.anm2; auto& anm2 = document.anm2;
auto& selection = document.spritesheet.selection; auto& selection = document.spritesheet.selection;
auto& unused = document.spritesheet.unused;
auto& reference = document.spritesheet.reference; auto& reference = document.spritesheet.reference;
auto style = ImGui::GetStyle(); auto style = ImGui::GetStyle();
@@ -40,6 +39,7 @@ namespace anm2ed::imgui
auto remove_unused = [&]() auto remove_unused = [&]()
{ {
auto unused = anm2.spritesheets_unused();
if (unused.empty()) return; if (unused.empty()) return;
auto behavior = [&]() auto behavior = [&]()
@@ -53,7 +53,6 @@ namespace anm2ed::imgui
std::make_format_args(id, pathString))); std::make_format_args(id, pathString)));
anm2.content.spritesheets.erase(id); anm2.content.spritesheets.erase(id);
} }
unused.clear();
}; };
DOCUMENT_EDIT(document, localize.get(EDIT_REMOVE_UNUSED_SPRITESHEETS), Document::ALL, behavior()); DOCUMENT_EDIT(document, localize.get(EDIT_REMOVE_UNUSED_SPRITESHEETS), Document::ALL, behavior());
@@ -189,8 +188,7 @@ namespace anm2ed::imgui
open_directory(anm2.content.spritesheets[*selection.begin()]); open_directory(anm2.content.spritesheets[*selection.begin()]);
if (ImGui::MenuItem(localize.get(BASIC_ADD), settings.shortcutAdd.c_str())) add_open(); if (ImGui::MenuItem(localize.get(BASIC_ADD), settings.shortcutAdd.c_str())) add_open();
if (ImGui::MenuItem(localize.get(BASIC_REMOVE_UNUSED), settings.shortcutRemove.c_str(), false, !unused.empty())) if (ImGui::MenuItem(localize.get(BASIC_REMOVE_UNUSED), settings.shortcutRemove.c_str())) remove_unused();
remove_unused();
if (ImGui::MenuItem(localize.get(BASIC_RELOAD), nullptr, false, !selection.empty())) reload(); if (ImGui::MenuItem(localize.get(BASIC_RELOAD), nullptr, false, !selection.empty())) reload();
if (ImGui::MenuItem(localize.get(BASIC_REPLACE), nullptr, false, selection.size() == 1)) replace_open(); if (ImGui::MenuItem(localize.get(BASIC_REPLACE), nullptr, false, selection.size() == 1)) replace_open();
@@ -366,11 +364,9 @@ namespace anm2ed::imgui
auto rowTwoWidgetSize = widget_size_with_row_get(2); auto rowTwoWidgetSize = widget_size_with_row_get(2);
ImGui::BeginDisabled(unused.empty());
shortcut(manager.chords[SHORTCUT_REMOVE]); shortcut(manager.chords[SHORTCUT_REMOVE]);
if (ImGui::Button(localize.get(BASIC_REMOVE_UNUSED), rowTwoWidgetSize)) remove_unused(); if (ImGui::Button(localize.get(BASIC_REMOVE_UNUSED), rowTwoWidgetSize)) remove_unused();
set_item_tooltip_shortcut(localize.get(TOOLTIP_REMOVE_UNUSED_SPRITESHEETS), settings.shortcutRemove); set_item_tooltip_shortcut(localize.get(TOOLTIP_REMOVE_UNUSED_SPRITESHEETS), settings.shortcutRemove);
ImGui::EndDisabled();
ImGui::SameLine(); ImGui::SameLine();

View File

@@ -9,7 +9,6 @@ namespace anm2ed
public: public:
int reference{-1}; int reference{-1};
int hovered{-1}; int hovered{-1};
std::set<int> unused{};
std::vector<std::string> labelsString{}; std::vector<std::string> labelsString{};
std::vector<const char*> labels{}; std::vector<const char*> labels{};
std::vector<int> ids{}; std::vector<int> ids{};