Need to save anm2 first before doing anything, should eliminate a few problems

This commit is contained in:
2025-08-28 10:27:47 -04:00
parent de034b9b29
commit 8f3c666922
4 changed files with 24 additions and 18 deletions

View File

@@ -123,6 +123,8 @@ bool anm2_serialize(Anm2* self, const std::string& path)
// Animations
animationsElement = document.NewElement(ANM2_ELEMENT_STRINGS[ANM2_ELEMENT_ANIMATIONS]);
if (self->defaultAnimationID != ID_NONE)
animationsElement->SetAttribute(ANM2_ATTRIBUTE_STRINGS[ANM2_ATTRIBUTE_DEFAULT_ANIMATION], self->animations[self->defaultAnimationID].name.c_str()); // DefaultAnimation
for (auto& [id, animation] : self->animations)

View File

@@ -211,7 +211,7 @@ struct Anm2
std::map<s32, Anm2Event> events;
std::map<s32, Anm2Animation> animations;
std::map<s32, s32> layerMap; // index, id
s32 defaultAnimationID{};
s32 defaultAnimationID = ID_NONE;
s32 fps = ANM2_FPS_DEFAULT;
s32 version{};
};

View File

@@ -35,15 +35,16 @@ static void _imgui_anm2_open(Imgui* self, const std::string& path)
static void _imgui_spritesheet_add(Imgui* self, const std::string& path)
{
std::filesystem::path workingPath = std::filesystem::current_path();
std::string spritesheetPath = path;
if (!self->anm2->path.empty())
if (self->anm2->path.empty())
{
std::string anm2WorkingPath = working_directory_from_file_set(self->anm2->path);
spritesheetPath = std::filesystem::relative(path, anm2WorkingPath).string();
imgui_log_push(self, IMGUI_LOG_NO_ANM2_PATH);
return;
}
std::filesystem::path workingPath = std::filesystem::current_path();
std::string spritesheetPath = path;
std::string anm2WorkingPath = working_directory_from_file_set(self->anm2->path);
spritesheetPath = std::filesystem::relative(path, anm2WorkingPath).string();
s32 id = map_next_id_get(self->anm2->spritesheets);
self->anm2->spritesheets[id] = Anm2Spritesheet{};
self->anm2->spritesheets[id].path = spritesheetPath;
@@ -209,7 +210,8 @@ static void _imgui_item_post(const ImguiItem& self, Imgui* imgui, ImguiItemType
if (self.is_undoable())
imgui_snapshot(imgui, self.snapshotAction);
if (self.function) self.function(imgui);
if (self.function)
self.function(imgui);
if (self.is_popup())
{
@@ -1754,12 +1756,12 @@ static void _imgui_animations(Imgui* self)
_imgui_begin_child(IMGUI_FOOTER_CHILD, self);
if (_imgui_button(IMGUI_ANIMATION_ADD, self))
if (_imgui_button(IMGUI_ANIMATION_ADD.copy({self->anm2->path.empty()}), self))
{
s32 id = anm2_animation_add(self->anm2);
self->reference->animationID = id;
if (self->anm2->animations.size() == 0)
if (self->anm2->animations.size() == 1)
self->anm2->defaultAnimationID = id;
}
@@ -1924,7 +1926,7 @@ static void _imgui_events(Imgui* self)
_imgui_begin_child(IMGUI_FOOTER_CHILD, self);
if (_imgui_button(IMGUI_EVENTS_ADD, self))
if (_imgui_button(IMGUI_EVENTS_ADD.copy({self->anm2->path.empty()}), self))
{
s32 id = map_next_id_get(self->anm2->events);
self->anm2->events[id] = Anm2Event{};
@@ -2027,7 +2029,7 @@ static void _imgui_spritesheets(Imgui* self)
_imgui_begin_child(IMGUI_SPRITESHEETS_FOOTER_CHILD, self);
if (_imgui_button(IMGUI_SPRITESHEET_ADD, self))
if (_imgui_button(IMGUI_SPRITESHEET_ADD.copy({self->anm2->path.empty()}), self))
dialog_spritesheet_add(self->dialog);
if (self->dialog->isSelected && self->dialog->type == DIALOG_SPRITESHEET_ADD)
@@ -2227,8 +2229,8 @@ static void _imgui_animation_preview(Imgui* self)
const bool isUp = ImGui::IsKeyPressed(IMGUI_INPUT_UP);
const bool isDown = ImGui::IsKeyPressed(IMGUI_INPUT_DOWN);
const bool isMod = ImGui::IsKeyDown(IMGUI_INPUT_SHIFT);
const bool isZoomIn = ImGui::IsKeyDown(IMGUI_INPUT_ZOOM_IN);
const bool isZoomOut = ImGui::IsKeyDown(IMGUI_INPUT_ZOOM_OUT);
const bool isZoomIn = ImGui::IsKeyPressed(IMGUI_INPUT_ZOOM_IN);
const bool isZoomOut = ImGui::IsKeyPressed(IMGUI_INPUT_ZOOM_OUT);
const bool isMouseClick = ImGui::IsMouseClicked(ImGuiMouseButton_Left);
const bool isMouseDown = ImGui::IsMouseDown(ImGuiMouseButton_Left);
const bool isMouseMiddleDown = ImGui::IsMouseDown(ImGuiMouseButton_Middle);
@@ -2357,8 +2359,8 @@ static void _imgui_spritesheet_editor(Imgui* self)
const bool isMouseClick = ImGui::IsMouseClicked(ImGuiMouseButton_Left);
const bool isMouseDown = ImGui::IsMouseDown(ImGuiMouseButton_Left);
const bool isMouseMiddleDown = ImGui::IsMouseDown(ImGuiMouseButton_Middle);
const bool isZoomIn = ImGui::IsKeyDown(IMGUI_INPUT_ZOOM_IN);
const bool isZoomOut = ImGui::IsKeyDown(IMGUI_INPUT_ZOOM_OUT);
const bool isZoomIn = ImGui::IsKeyPressed(IMGUI_INPUT_ZOOM_IN);
const bool isZoomOut = ImGui::IsKeyPressed(IMGUI_INPUT_ZOOM_OUT);
const bool isMod = ImGui::IsKeyDown(IMGUI_INPUT_SHIFT);
const f32 mouseWheel = ImGui::GetIO().MouseWheel;
const ImVec2 mouseDelta = ImGui::GetIO().MouseDelta;

View File

@@ -75,6 +75,7 @@
#define IMGUI_POPUP_FLAGS ImGuiWindowFlags_NoMove
#define IMGUI_POPUP_MODAL_FLAGS ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize
#define IMGUI_LOG_NO_ANM2_PATH "Please save the .anm2 to a path first!"
#define IMGUI_LOG_FILE_OPEN_FORMAT "Opened anm2: {}"
#define IMGUI_LOG_FILE_SAVE_FORMAT "Saved anm2 to: {}"
#define IMGUI_LOG_SPRITESHEET_RELOAD "Reloaded selected spritesheets"
@@ -274,6 +275,7 @@ static inline void imgui_explore(Imgui* self)
static inline void imgui_snapshot(Imgui* self, const std::string& action = SNAPSHOT_ACTION)
{
self->snapshots->action = action;
Snapshot snapshot = snapshot_get(self->snapshots);
snapshots_undo_push(self->snapshots, &snapshot);
}