Child triggers fire; Auto Resource Reload; animation layer labels

Playback, renders and the preview's event label include the triggers of
child animations (from this file or a library) as each child reaches them;
libraries' sounds load with them, and a frame can mix several sounds. The
reload setting is now Auto Resource Reload and covers libraries too.
Animation layers are labeled by their animation (not a spritesheet) in the
timeline and Item Properties as well as the Layers window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-10-08 18:06:47 -04:00
1 parent 280adaa189
commit 76c2186c81
16 files changed
+191 -87

No files matched your search

+38
View File
@@ -16,6 +16,7 @@
#include "file.hpp"
#include "log.hpp"
#include "manager.hpp"
#include "math.hpp"
#include "model/frames.hpp"
#include "model/xml.hpp"
#include "pack.hpp"
@@ -54,6 +55,8 @@ namespace anm2ed::document
util::WorkingDirectory workingDirectory(path.parent_path());
for (const auto& spritesheet : library.model.content.spritesheets)
library.images.emplace(spritesheet.id, resource::Image(path::case_insensitive_find(spritesheet.path)));
for (const auto& sound : library.model.content.sounds)
library.sounds.emplace(sound.id, resource::AudioData(path::case_insensitive_find(sound.path)));
}
uint64_t document_tab_id_next()
@@ -509,6 +512,41 @@ namespace anm2ed
return key == sounds.end() ? nullptr : assets.audio_get(key->second);
}
// Every sound that may be playing: this document's and its libraries'.
std::vector<const resource::AudioData*> Document::sounds_get() const
{
std::vector<const resource::AudioData*> result{};
for (const auto& [id, key] : sounds)
if (auto sound = sound_get(id)) result.push_back(sound);
for (const auto& [path, library] : libraries)
for (const auto& [id, sound] : library.sounds)
result.push_back(&sound);
return result;
}
// The sounds triggers play on an animation's frame, its children's included: one of each trigger's sounds, at random
// (or picked by `index` for repeatable renders).
std::vector<const resource::AudioData*> Document::trigger_sounds_get(const model::Animation& animation, int time,
int index) const
{
std::vector<const resource::AudioData*> result{};
for (const auto& [source, trigger] : model::animation_triggers_get(model, animation, time, library_resolver_get()))
{
if (trigger.soundIds.empty()) continue;
auto count = trigger.soundIds.size();
auto soundIndex = std::min(
index >= 0 ? (std::size_t)index % count : (std::size_t)math::random_in_range(0.0f, (float)count), count - 1);
auto soundId = trigger.soundIds[soundIndex];
const resource::AudioData* sound{};
if (source == &model) sound = sound_get(soundId);
for (const auto& [path, library] : libraries)
if (&library.model == source)
if (auto found = library.sounds.find(soundId); found != library.sounds.end()) sound = &found->second;
if (sound) result.push_back(sound);
}
return result;
}
void Document::sound_set(int id, resource::AudioData data) { sounds[id] = assets.audio_add(std::move(data)); }
resource::Shader* Document::shader_get(int shaderId)
+4 -1
View File
@@ -32,11 +32,12 @@ namespace anm2ed
std::vector<std::string> labels{};
};
// A linked .anm2, loaded read-only: its document and its spritesheets' images.
// A linked .anm2, loaded read-only: its document, its spritesheets' images and its sounds.
struct LibraryData
{
model::Model model{};
std::map<int, resource::Image> images{};
std::map<int, resource::AudioData> sounds{};
std::filesystem::file_time_type writeTime{};
};
@@ -123,6 +124,8 @@ namespace anm2ed
resource::Image* texture_edit(int);
void texture_set(int, resource::Image);
const resource::AudioData* sound_get(int) const;
std::vector<const resource::AudioData*> sounds_get() const;
std::vector<const resource::AudioData*> trigger_sounds_get(const model::Animation&, int, int = -1) const;
void sound_set(int, resource::AudioData);
resource::Shader* shader_get(int);
std::filesystem::path library_path_get(int) const;
+2 -2
View File
@@ -9,14 +9,14 @@ namespace anm2ed::imgui
if (auto document = manager.get(); document)
if (settings.windowIsAnimationPreview) animationPreview.tick(manager, settings, deltaSeconds);
// Files changed on disk are picked up every few seconds: libraries always, spritesheets when set to.
// Spritesheets and libraries changed on disk are picked up every few seconds.
if (!settings.fileIsAutoReloadResources) return;
reloadTime += deltaSeconds;
if (reloadTime < AUTO_RELOAD_INTERVAL) return;
reloadTime = 0.0f;
for (auto& document : manager.documents)
{
document.libraries_reload();
if (!settings.fileIsAutoReloadSpritesheets) continue;
if (auto ids = document.spritesheets_changed_get(); !ids.empty()) document.spritesheets_reload(ids);
}
}
+1 -3
View File
@@ -140,9 +140,7 @@ namespace anm2ed::imgui::popup
{
if (auto layer = model::item_get(model.content.layers, id))
{
auto label = std::vformat(localize.get(FORMAT_LAYER),
std::make_format_args(id, layer->name, layer->spritesheetId));
if (ImGui::Selectable(label.c_str(), isSelected))
if (ImGui::Selectable(layer_label_get(*layer).c_str(), isSelected))
{
edit.id = id;
}
+18 -36
View File
@@ -123,24 +123,6 @@ namespace anm2ed::imgui
return rect;
}
int trigger_sound_id_get(Document& document, const model::Animation* animation, float time,
int deterministicIndex = -1)
{
if (!animation || !animation->triggers.isVisible) return -1;
auto trigger = model::frame_generate(animation->triggers, time);
if (!trigger.isVisible || trigger.soundIds.empty()) return -1;
size_t soundIndex{};
if (trigger.soundIds.size() > 1)
soundIndex = deterministicIndex >= 0 ? (size_t)deterministicIndex % trigger.soundIds.size()
: (size_t)math::random_in_range(0.0f, (float)trigger.soundIds.size());
soundIndex = std::min(soundIndex, trigger.soundIds.size() - 1);
auto soundID = trigger.soundIds[soundIndex];
return document.sound_get(soundID) ? soundID : -1;
}
void AnimationPreview::tick(Manager& manager, Settings& settings, float deltaSeconds)
{
auto& document = *manager.get();
@@ -150,8 +132,8 @@ namespace anm2ed::imgui
auto stop_all_sounds = [&]()
{
for (auto& [id, _] : document.sounds)
if (auto sound = document.sound_get(id)) audio::stop(*sound, mixer);
for (auto sound : document.sounds_get())
audio::stop(*sound, mixer);
};
if (manager.isRecording)
@@ -190,9 +172,9 @@ namespace anm2ed::imgui
for (int step = 0; soundFrame != frame && step < range.y - range.x; ++step)
{
soundFrame = soundFrame + 1 >= range.y || soundFrame + 1 < range.x ? range.x : soundFrame + 1;
if (manager.isRecording || document.sounds.empty() || !isSound) continue;
if (auto soundID = trigger_sound_id_get(document, animation, (float)soundFrame); soundID != -1)
if (auto sound = document.sound_get(soundID)) audio::play(*sound, false, mixer);
if (manager.isRecording || !isSound) continue;
for (auto sound : document.trigger_sounds_get(*animation, soundFrame))
audio::play(*sound, false, mixer);
}
frameTime = playback.time;
@@ -806,10 +788,10 @@ namespace anm2ed::imgui
if (isRecordingFrame)
{
auto soundId = settings.timelineIsSound && animation && recorder.is_sound_frame()
? trigger_sound_id_get(document, animation, frameTime, recorder.index)
: -1;
if (!recorder.frame_capture(pixels_get(), size, soundId))
auto sounds = settings.timelineIsSound && animation && recorder.is_sound_frame()
? document.trigger_sounds_get(*animation, (int)frameTime, recorder.index)
: std::vector<const resource::AudioData*>{};
if (!recorder.frame_capture(pixels_get(), size, sounds))
{
toast_log(Level::ERROR, TOAST_EXPORT_RENDERED_ANIMATION_FAILED, path::to_utf8(recorder.options.path));
recorder.cancel();
@@ -826,10 +808,15 @@ namespace anm2ed::imgui
}
image_premultiplied_draw(texture, to_imvec2(size));
if (animation && animation->triggers.isVisible && !isOnlyShowLayers && !manager.isRecording)
{
if (auto trigger = model::frame_generate(animation->triggers, frameTime);
trigger.isVisible && !trigger.eventIds.empty())
// The events triggers (the animation's and its children's) fire on this frame.
std::string names{};
if (animation && !isOnlyShowLayers && !manager.isRecording)
for (const auto& [source, trigger] :
model::animation_triggers_get(model, *animation, (int)frameTime, document.library_resolver_get()))
for (auto eventId : trigger.eventIds)
if (auto event = model::item_get(source->content.events, eventId))
names += (names.empty() ? "" : ", ") + event->name;
if (!names.empty())
{
auto clipMin = ImGui::GetItemRectMin();
auto clipMax = ImGui::GetItemRectMax();
@@ -839,16 +826,11 @@ namespace anm2ed::imgui
drawList->PushClipRect(clipMin, clipMax);
ImGui::PushFont(resources.fonts[font::BOLD].get(), font::SIZE_LARGE);
auto triggerTextColor = isLightTheme ? TRIGGER_TEXT_COLOR_LIGHT : TRIGGER_TEXT_COLOR_DARK;
std::string names{};
for (auto eventId : trigger.eventIds)
if (auto event = model::item_get(model.content.events, eventId))
names += (names.empty() ? "" : ", ") + event->name;
drawList->AddText(textPos, ImGui::GetColorU32(triggerTextColor), names.c_str());
ImGui::PopFont();
drawList->PopClipRect();
}
}
}
if (tool == tool::PAN)
view_context_menu_draw("##Animation Preview Context Menu", manager, settings, document, zoom, pan, center_view,
+10 -10
View File
@@ -23,6 +23,15 @@ namespace anm2ed::imgui
ImGui::TextUnformatted(std::vformat(localize.get(FORMAT_ID), std::make_format_args(id)).c_str());
}
// "#id name", then what the layer shows: its spritesheet or its animation.
std::string layer_label_get(const model::Layer& layer)
{
if (layer.is_animation())
return std::vformat(localize.get(FORMAT_LAYER_ANIMATION),
std::make_format_args(layer.id, layer.name, layer.animation));
return std::vformat(localize.get(FORMAT_LAYER), std::make_format_args(layer.id, layer.name, layer.spritesheetId));
}
model::Layer item_edit_layer_get(const Manager::ItemEdit& edit)
{
return {.name = edit.name,
@@ -159,16 +168,7 @@ namespace anm2ed::imgui
TOOLTIP_ADD_LAYER, TOOLTIP_REMOVE_UNUSED_LAYERS, EDIT_REMOVE_UNUSED_LAYERS,
EDIT_PASTE_LAYERS, TOAST_DESERIALIZE_LAYERS_FAILED, layers_get);
ListRows rows{
.label_get =
[&](int id)
{
auto layer = model::item_get(layers, id);
if (layer->is_animation())
return std::vformat(localize.get(FORMAT_LAYER_ANIMATION),
std::make_format_args(layer->id, layer->name, layer->animation));
return std::vformat(localize.get(FORMAT_LAYER),
std::make_format_args(layer->id, layer->name, layer->spritesheetId));
},
.label_get = [&](int id) { return layer_label_get(*model::item_get(layers, id)); },
.tooltip_draw =
[&](int id)
{
+1
View File
@@ -149,6 +149,7 @@ namespace anm2ed::imgui
void nulls_update(Panel&);
void events_update(Panel&);
void sounds_update(Panel&);
std::string layer_label_get(const model::Layer&);
model::Layer item_edit_layer_get(const Manager::ItemEdit&);
model::Null item_edit_null_get(const Manager::ItemEdit&);
void layer_source_draw(Document&, Manager::ItemEdit&);
+1 -1
View File
@@ -203,7 +203,7 @@ namespace anm2ed::imgui
{
auto layer = model::item_get(model.content.layers, id);
if (!layer) return localize.get(TYPE_STRINGS[type]);
return std::vformat(localize.get(FORMAT_LAYER), std::make_format_args(id, layer->name, layer->spritesheetId));
return layer_label_get(*layer);
}
if (type == NULL_)
{
+4 -4
View File
@@ -69,10 +69,10 @@ namespace anm2ed::imgui::wizard
ImGui::Checkbox(localize.get(BASIC_ENABLED), &temporary.fileIsAutosave);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_AUTOSAVE_ENABLED));
ImGui::SeparatorText(localize.get(LABEL_AUTO_SPRITESHEET_RELOAD));
ImGui::PushID(LABEL_AUTO_SPRITESHEET_RELOAD);
ImGui::Checkbox(localize.get(BASIC_ENABLED), &temporary.fileIsAutoReloadSpritesheets);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_AUTO_SPRITESHEET_RELOAD));
ImGui::SeparatorText(localize.get(LABEL_AUTO_RESOURCE_RELOAD));
ImGui::PushID(LABEL_AUTO_RESOURCE_RELOAD);
ImGui::Checkbox(localize.get(BASIC_ENABLED), &temporary.fileIsAutoReloadResources);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_AUTO_RESOURCE_RELOAD));
ImGui::PopID();
ImGui::SeparatorText(localize.get(LABEL_SNAPSHOTS));
+57 -9
View File
@@ -85,6 +85,61 @@ namespace anm2ed::model
return 0.0f;
}
// The child animation an animation layer's frame plays: its own, or the layer's, from this file or a library.
std::pair<const Model*, const Animation*> child_get(const Model& model, const Layer& layer, const Frame& frame,
const LibraryGet& library_get)
{
auto childModel = layer.libraryId == -1 ? &model : library_get ? library_get(model, layer.libraryId) : nullptr;
auto childAnimation =
childModel
? childModel->animation_named_get(frame.childAnimation.empty() ? layer.animation : frame.childAnimation)
: nullptr;
if (childAnimation && childAnimation->frameNum < FRAME_NUM_MIN) childAnimation = nullptr;
return {childModel, childAnimation};
}
void animation_triggers_add(std::vector<TriggerFire>& fires, const Model& model, const Animation& animation, int time,
const LibraryGet& library_get, std::vector<const Animation*>& playing)
{
if (animation.triggers.isVisible)
if (auto trigger = frame_generate(animation.triggers, (float)time); trigger.isVisible)
fires.push_back({&model, std::move(trigger)});
// A child fires the trigger of each frame it reaches: when its frame (or animation) changes from the parent's last.
tracks_each(
animation.layers,
[&](const Track& track, const TrackGroup* group)
{
auto layer = item_get(model.content.layers, track.id);
if (!layer || !layer->is_animation() || !track.isVisible || (group && !group->isVisible)) return;
auto frame = frame_generate(track, (float)time);
auto [childModel, childAnimation] = child_get(model, *layer, frame, library_get);
if (!frame.isVisible || !childAnimation || std::ranges::contains(playing, childAnimation)) return;
auto childTime = (int)child_time_get(track, (float)time, childAnimation->frameNum, layer->id);
if (time > 0)
{
auto previous = frame_generate(track, (float)(time - 1));
auto previousTime = (int)child_time_get(track, (float)(time - 1), childAnimation->frameNum, layer->id);
if (previous.isVisible && child_get(model, *layer, previous, library_get).second == childAnimation &&
previousTime == childTime)
return;
}
playing.push_back(childAnimation);
animation_triggers_add(fires, *childModel, *childAnimation, childTime, library_get, playing);
playing.pop_back();
});
}
// The triggers that fire on an animation's frame: its own, and those its animation layers' children reach then.
std::vector<TriggerFire> animation_triggers_get(const Model& model, const Animation& animation, int time,
const LibraryGet& library_get)
{
std::vector<TriggerFire> fires{};
std::vector<const Animation*> playing{&animation};
animation_triggers_add(fires, model, animation, time, library_get, playing);
return fires;
}
// `playing` holds the animations being drawn into one another, so an animation never draws itself.
std::vector<Draw> animation_draws_get(const Model& model, const Animation& animation, const DrawOptions& options,
std::vector<const Animation*>& playing)
@@ -106,15 +161,8 @@ namespace anm2ed::model
auto child_draws_add =
[&](const Track& track, const Layer& layer, int sample, float time, const Frame& frame, const glm::mat4& parent)
{
auto childModel = layer.libraryId == -1 ? &model
: options.library_get ? options.library_get(model, layer.libraryId)
: nullptr;
auto childAnimation =
childModel
? childModel->animation_named_get(frame.childAnimation.empty() ? layer.animation : frame.childAnimation)
: nullptr;
if (!childAnimation || childAnimation->frameNum < FRAME_NUM_MIN || std::ranges::contains(playing, childAnimation))
return;
auto [childModel, childAnimation] = child_get(model, layer, frame, options.library_get);
if (!childAnimation || std::ranges::contains(playing, childAnimation)) return;
playing.push_back(childAnimation);
auto transform = parent * math::quad_model_get(glm::vec2(1.0f), frame.position, frame.pivot,
math::percent_to_unit(frame.scale), frame.rotation,
+8
View File
@@ -52,7 +52,15 @@ namespace anm2ed::model
int spritesheetId{-1};
};
// A trigger that fires, from the animation played or a child animation (whose ids belong to `source`).
struct TriggerFire
{
const Model* source{};
Frame trigger{};
};
glm::mat4 draw_quad_model_get(const Draw&);
float draw_scale_get(const Draw&);
std::vector<Draw> animation_draws_get(const Model&, const Animation&, const DrawOptions&);
std::vector<TriggerFire> animation_triggers_get(const Model&, const Animation&, int, const LibraryGet& = {});
}
+16 -15
View File
@@ -243,16 +243,16 @@ namespace anm2ed::render
void sounds_detach(const Document& document, MIX_Mixer* mixer)
{
for (auto& [id, _] : document.sounds)
if (auto sound = document.sound_get(id)) audio::track_detach(*sound, mixer);
for (auto sound : document.sounds_get())
audio::track_detach(*sound, mixer);
}
// Mixes each frame's trigger sound into one stream at the render frame rate.
bool audio_stream_generate(AudioStream& audioStream, const Document& document, const std::vector<int>& soundIds,
int fps)
// Mixes each frame's trigger sounds into one stream at the render frame rate.
bool audio_stream_generate(AudioStream& audioStream, const Document& document,
const std::vector<std::vector<const resource::AudioData*>>& frameSounds, int fps)
{
audioStream.stream.clear();
if (soundIds.empty() || fps <= 0) return true;
if (frameSounds.empty() || fps <= 0) return true;
SDL_AudioSpec mixSpec = audioStream.spec;
mixSpec.format = SDL_AUDIO_F32;
@@ -264,9 +264,10 @@ namespace anm2ed::render
auto accumulator = 0.0;
std::vector<float> buffer{};
auto isGenerated = true;
for (auto soundId : soundIds)
for (const auto& sounds : frameSounds)
{
if (auto sound = document.sound_get(soundId)) audio::play(*sound, false, mixer);
for (auto sound : sounds)
audio::play(*sound, false, mixer);
accumulator += framesPerStep;
auto sampleFrames = std::max((int)std::floor(accumulator), 1);
accumulator -= (double)sampleFrames;
@@ -341,7 +342,7 @@ namespace anm2ed::render
index = 0;
count = frame_count_get(options.start, options.end, options.animationFps, options.fps);
frames.clear();
soundIds.clear();
sounds.clear();
soundTime = -1;
directory = frames_directory_create(options);
return !directory.empty();
@@ -354,10 +355,11 @@ namespace anm2ed::render
// A trigger sound is taken once per animation frame, however many render frames it spans.
bool Recorder::is_sound_frame() const { return (int)std::floor(time_get()) != soundTime; }
bool Recorder::frame_capture(std::vector<uint8_t> pixels, glm::ivec2 size, int soundId)
bool Recorder::frame_capture(std::vector<uint8_t> pixels, glm::ivec2 size,
std::vector<const resource::AudioData*> frameSounds)
{
soundTime = (int)std::floor(time_get());
soundIds.push_back(soundId);
sounds.push_back(std::move(frameSounds));
if (options.isIsolated || options.isBounded) pixels_unpremultiply(pixels);
auto framePath = directory / frame_filename_get(options.format, index, options.type);
if (!Image::write_pixels_png(framePath, size, pixels.data())) return false;
@@ -396,8 +398,7 @@ namespace anm2ed::render
else
{
audioStream.stream.clear();
if (options.isSound && options.type != GIF &&
!audio_stream_generate(audioStream, document, soundIds, options.fps))
if (options.isSound && options.type != GIF && !audio_stream_generate(audioStream, document, sounds, options.fps))
{
toasts.push(localize.get(TOAST_EXPORT_RENDERED_ANIMATION_FAILED));
logger.error("Failed to generate deterministic render audio stream; exporting without audio.");
@@ -417,7 +418,7 @@ namespace anm2ed::render
if (options.type != PNGS && !directory.empty()) std::filesystem::remove_all(directory, ec);
directory.clear();
frames.clear();
soundIds.clear();
sounds.clear();
index = count = 0;
}
@@ -433,7 +434,7 @@ namespace anm2ed::render
{
auto pixels = animation_frame_render(canvas, shader, document, animation, recorder.time_get(), bounds, scale,
background, isRootTransform);
if (recorder.frame_capture(std::move(pixels), glm::ivec2(canvas.size), -1)) continue;
if (recorder.frame_capture(std::move(pixels), glm::ivec2(canvas.size))) continue;
recorder.cancel();
return false;
}
+4 -3
View File
@@ -5,6 +5,7 @@
#include <filesystem>
#include <vector>
#include "audio_data.hpp"
#include "audio_stream.hpp"
#include <glm/glm.hpp>
@@ -162,7 +163,7 @@ namespace anm2ed::render
};
// A render in progress: which animation times to capture, the frames captured so far (written to disk) and the
// trigger sound of each, and assembling the output when done.
// trigger sounds of each, and assembling the output when done.
class Recorder
{
public:
@@ -174,14 +175,14 @@ namespace anm2ed::render
bool is_done() const;
float time_get() const;
bool is_sound_frame() const;
bool frame_capture(std::vector<uint8_t>, glm::ivec2, int);
bool frame_capture(std::vector<uint8_t>, glm::ivec2, std::vector<const resource::AudioData*> = {});
void finish(const Document&, AudioStream&);
void cancel();
private:
std::filesystem::path directory{};
std::vector<std::filesystem::path> frames{};
std::vector<int> soundIds{};
std::vector<std::vector<const resource::AudioData*>> sounds{};
int soundTime{-1};
};
+2 -2
View File
@@ -285,7 +285,7 @@ namespace anm2ed
X(LABEL_ANIMATION, "Animation", "Animación", "Анимация", "动画", "애니메이션") \
X(LABEL_ANIMATIONS_CHILD, "Animations", "Animaciones", "", "动画", "애니메이션") \
X(LABEL_ANIMATIONS_MERGE_POPUP, "Merge Animations", "Combinar Animaciones", "Соединить анимации", "合并多个动画", "애니메이션 병합") \
X(LABEL_AUTO_SPRITESHEET_RELOAD, "Auto Spritesheet Reload", "Recarga Automática de Spritesheets", "Автоперезагрузка спрайт-листов", "自动重新加载图集", "스프라이트 시트 자동 새로고침") \
X(LABEL_AUTO_RESOURCE_RELOAD, "Auto Resource Reload", "Recarga Automática de Recursos", "Автоперезагрузка ресурсов", "自动重新加载资源", "리소스 자동 새로고침") \
X(LABEL_CHILD, "Child", "Hijo", "Дочерняя", "子动画", "자식") \
X(LABEL_CONVERT, "Convert", "Convertir", "Преобразовать", "转换", "변환") \
X(LABEL_CONVERT_SVG_POPUP, "Convert SVG Spritesheets", "Convertir Spritesheets SVG", "Преобразовать SVG спрайт-листы", "转换 SVG 图集", "SVG 스프라이트 시트 변환") \
@@ -573,7 +573,7 @@ namespace anm2ed
X(TEXT_SELECT_FRAME, "Select a frame first!", "¡Selecciona primero un frame!", "Сначала выберите кадр!", "请先选择帧!", "먼저 프레임을 선택하세요!") \
X(TEXT_SELECT_FRAME_OR_REGION, "Select a frame or region first!", "¡Selecciona primero un frame o región!", "Сначала выберите кадр или регион!", "请先选择帧或区域!", "먼저 프레임 또는 영역을 선택하세요!") \
X(TOOLTIP_ADD_TRIGGER_EVENT, "Add another event to the trigger; all of them fire on its frame.\n(Only the first reaches the game.)", "Añade otro evento al trigger; todos se disparan en su Frame.\n(Solo el primero llega al juego.)", "Добавить ещё одно событие в триггер; все срабатывают на его кадре.\n(В игру попадает только первое.)", "向触发器添加另一个事件;它们都会在该帧触发。\n(只有第一个会进入游戏。)", "트리거에 이벤트를 하나 더 추가합니다. 모두 해당 프레임에서 발생합니다.\n(게임에는 첫 번째만 전달됩니다.)") \
X(TOOLTIP_AUTO_SPRITESHEET_RELOAD, "Reload spritesheets automatically when their files change on disk.\n(Spritesheets with unsaved edits are left alone.)", "Recarga los spritesheets automáticamente cuando sus archivos cambian en el disco.\n(Los spritesheets con cambios sin guardar no se tocan.)", "Автоматически перезагружать спрайт-листы при изменении их файлов на диске.\n(Спрайт-листы с несохранёнными изменениями не затрагиваются.)", "当图集文件在磁盘上更改时自动重新加载。\n(有未保存修改的图集不受影响。)", "디스크의 파일이 바뀌면 스프라이트 시트를 자동으로 새로고침합니다.\n(저장하지 않은 수정이 있는 스프라이트 시트는 건드리지 않습니다.)") \
X(TOOLTIP_AUTO_RESOURCE_RELOAD, "Reload spritesheets and libraries automatically when their files change on disk.\n(Spritesheets with unsaved edits are left alone.)", "Recarga los spritesheets y las bibliotecas automáticamente cuando sus archivos cambian en el disco.\n(Los spritesheets con cambios sin guardar no se tocan.)", "Автоматически перезагружать спрайт-листы и библиотеки при изменении их файлов на диске.\n(Спрайт-листы с несохранёнными изменениями не затрагиваются.)", "当图集和库的文件在磁盘上更改时自动重新加载。\n(有未保存编辑的图集不受影响。)", "스프라이트 시트와 라이브러리 파일이 디스크에서 바뀌면 자동으로 다시 불러옵니다.\n(저장하지 않은 편집이 있는 스프라이트 시트는 그대로 둡니다.)") \
X(TOOLTIP_CHILD_ANIMATION, "The animation this keyframe plays; the layer's unless set. Changing it restarts the child.", "La animación que reproduce este keyframe; la de la capa si no se ajusta. Cambiarla reinicia el hijo.", "Анимация этого ключевого кадра; если не задана, то анимация слоя. Смена перезапускает её.", "此关键帧播放的动画;未设置时使用图层的。更改会重新开始子动画。", "이 키프레임이 재생하는 애니메이션입니다. 설정하지 않으면 레이어의 것을 사용합니다. 바꾸면 자식이 다시 시작됩니다.") \
X(TOOLTIP_CHILD_MODE, "Loop the child, play it once and stop on its last frame, or hold it on the start frame.", "Repite el hijo, reprodúcelo una vez y detente en su último frame, o mantenlo en el frame inicial.", "Зациклить дочернюю анимацию, проиграть один раз и остановиться на последнем кадре, или удерживать начальный кадр.", "循环子动画、播放一次并停在最后一帧,或保持在起始帧。", "자식을 반복하거나, 한 번 재생하고 마지막 프레임에서 멈추거나, 시작 프레임에 고정합니다.") \
X(TOOLTIP_CHILD_RESTART, "Restart the child at this keyframe; otherwise it keeps playing from the keyframe before.", "Reinicia el hijo en este keyframe; si no, sigue desde el keyframe anterior.", "Перезапустить дочернюю анимацию на этом ключевом кадре; иначе она продолжается с предыдущего.", "在此关键帧重新开始子动画;否则从上一个关键帧继续播放。", "이 키프레임에서 자식을 다시 시작합니다. 그렇지 않으면 이전 키프레임부터 계속 재생됩니다.") \
+1 -1
View File
@@ -64,7 +64,7 @@ namespace anm2ed
X(FILE_IS_AUTOSAVE, fileIsAutosave, STRING_UNDEFINED, BOOL, true) \
X(FILE_IS_WARN_OVERWRITE, fileIsWarnOverwrite, STRING_UNDEFINED, BOOL, true) \
X(FILE_IS_WARN_ISAAC, fileIsWarnIsaac, STRING_UNDEFINED, BOOL, true) \
X(FILE_IS_AUTO_RELOAD_SPRITESHEETS, fileIsAutoReloadSpritesheets, STRING_UNDEFINED, BOOL, true) \
X(FILE_IS_AUTO_RELOAD_RESOURCES, fileIsAutoReloadResources, STRING_UNDEFINED, BOOL, true) \
X(FILE_IS_EXTENDED_FORMAT, isFileExtendedFormat, STRING_UNDEFINED, BOOL, false) \
X(FILE_SNAPSHOT_STACK_SIZE, fileSnapshotStackSize, STRING_UNDEFINED, INT, 50) \
\
+24
View File
@@ -133,3 +133,27 @@ TEST_CASE("only SVG spritesheets that layers show count against Rebirth")
anm2.content.layers.clear();
CHECK(model::spritesheets_vector_used_get(anm2).empty());
}
TEST_CASE("child animations fire their triggers as they reach them")
{
auto anm2 = model_load(file_load(TEST_DIR / "render" / "nested.anm2"));
auto spin = model_load(file_load(TEST_DIR / "render" / "spin.anm2"));
spin.content.events.push_back({.id = 0, .name = "spun"});
spin.animation_edit(0)->triggers.frames.push_back({.atFrame = 5, .eventIds = {0}});
anm2.content.events.push_back({.id = 0, .name = "inner"});
anm2.animation_edit(1)->triggers.frames.push_back({.atFrame = 0, .eventIds = {0}});
auto library_get = [&](const model::Model&, int id) { return id == 0 ? &spin : nullptr; };
auto sources_get = [&](int time)
{
std::vector<const model::Model*> sources{};
for (const auto& fire : model::animation_triggers_get(anm2, *anm2.animation_get(0), time, library_get))
sources.push_back(fire.source);
return sources;
};
// Inner (held on its first frame) fires once, when the parent starts; the library's Spin, started on its fifth
// frame, reaches its sixth (and its trigger) one frame later.
CHECK(sources_get(0) == std::vector<const model::Model*>{&anm2});
CHECK(sources_get(1) == std::vector<const model::Model*>{&spin});
CHECK(sources_get(2).empty());
}