random sound selection for triggers

This commit is contained in:
2026-01-06 16:26:57 -05:00
parent b41b6df19e
commit 5124f77817
12 changed files with 104 additions and 59 deletions
+2 -2
View File
@@ -236,7 +236,6 @@ namespace anm2ed::anm2
for (auto& [sourceID, sourceEvent] : source.content.events)
{
auto event = sourceEvent;
event.soundID = remap_id(soundRemap, event.soundID);
int destinationID = find_by_name(content.events, event.name);
if (destinationID != -1)
@@ -253,7 +252,8 @@ namespace anm2ed::anm2
{
for (auto& frame : item.frames)
{
frame.soundID = remap_id(soundRemap, frame.soundID);
for (auto& soundID : frame.soundIDs)
soundID = remap_id(soundRemap, soundID);
frame.eventID = remap_id(eventRemap, frame.eventID);
}
};
+2 -1
View File
@@ -34,7 +34,8 @@ namespace anm2ed::anm2
std::set<int> used;
for (auto& animation : animations.items)
for (auto& trigger : animation.triggers.frames)
if (content.sounds.contains(trigger.soundID)) used.insert(trigger.soundID);
for (auto& soundID : trigger.soundIDs)
if (content.sounds.contains(soundID)) used.insert(soundID);
std::set<int> unused;
for (auto& [id, sound] : content.sounds)
-1
View File
@@ -9,7 +9,6 @@ namespace anm2ed::anm2
{
public:
std::string name{};
int soundID{-1};
Event() = default;
Event(tinyxml2::XMLElement*, int&);
+18 -2
View File
@@ -40,7 +40,17 @@ namespace anm2ed::anm2
else
{
element->QueryIntAttribute("EventId", &eventID);
element->QueryIntAttribute("SoundId", &soundID);
int soundID{};
// Backwards compatibility with old formats
if (element->QueryIntAttribute("SoundId", &soundID) == XML_SUCCESS) soundIDs.push_back(soundID);
for (auto child = element->FirstChildElement("Sound"); child; child = child->NextSiblingElement("Sound"))
{
child->QueryIntAttribute("Id", &soundID);
soundIDs.push_back(soundID);
}
element->QueryIntAttribute("AtFrame", &atFrame);
}
}
@@ -94,7 +104,13 @@ namespace anm2ed::anm2
break;
case TRIGGER:
element->SetAttribute("EventId", eventID);
element->SetAttribute("SoundId", soundID);
for (auto& id : soundIDs)
{
auto soundChild = element->InsertNewChildElement("Sound");
soundChild->SetAttribute("Id", id);
}
element->SetAttribute("AtFrame", atFrame);
break;
default:
+14 -23
View File
@@ -12,30 +12,23 @@ namespace anm2ed::anm2
constexpr auto FRAME_DURATION_MIN = 1;
constexpr auto FRAME_DURATION_MAX = 1000000;
#define MEMBERS \
X(isVisible, bool, true) \
X(isInterpolated, bool, false) \
X(rotation, float, 0.0f) \
X(duration, int, FRAME_DURATION_MIN) \
X(atFrame, int, -1) \
X(eventID, int, -1) \
X(soundID, int, -1) \
X(pivot, glm::vec2, {}) \
X(crop, glm::vec2, {}) \
X(position, glm::vec2, {}) \
X(size, glm::vec2, {}) \
X(scale, glm::vec2, glm::vec2(100.0f)) \
X(colorOffset, glm::vec3, glm::vec3()) \
X(tint, glm::vec4, types::color::WHITE)
class Frame
{
public:
#define X(name, type, ...) type name = __VA_ARGS__;
MEMBERS
#undef X
#undef MEMBERS
bool isVisible{true};
bool isInterpolated{false};
float rotation{};
int duration{FRAME_DURATION_MIN};
int atFrame{-1};
int eventID{-1};
std::vector<int> soundIDs{};
glm::vec2 pivot{};
glm::vec2 crop{};
glm::vec2 position{};
glm::vec2 size{};
glm::vec2 scale{};
glm::vec3 colorOffset{};
glm::vec4 tint{types::color::WHITE};
Frame() = default;
Frame(tinyxml2::XMLElement*, Type);
@@ -52,8 +45,6 @@ namespace anm2ed::anm2
std::optional<bool> isInterpolated{};
std::optional<float> rotation{};
std::optional<int> duration{};
std::optional<int> atFrame{};
std::optional<int> eventID{};
std::optional<float> pivotX{};
std::optional<float> pivotY{};
std::optional<float> cropX{};