Sound is now working, and the animator tools will play them and also has mute.

This commit is contained in:
Zed A. Shaw 2026-02-06 13:39:34 -05:00
parent a4ffacdb18
commit 46f34828e4
5 changed files with 38 additions and 19 deletions

View file

@ -5,6 +5,7 @@
#include "rand.hpp"
#include <iostream>
#include <fstream>
#include "sound.hpp"
constexpr float SUB_FRAME_SENSITIVITY = 0.999f;
@ -43,14 +44,23 @@ namespace animate2 {
// need one for each kind of thing to animate
// NOTE: possibly find a way to only run apply on frame change?
void Animate2::apply(sf::Sprite& sprite) {
dbc::check(!transform.simple, "can't call ::apply() on a simple animation, only ::motion()");
dbc::check(sequence.current < $frame_rects.size(), "current frame past $frame_rects");
// NOTE: pos is not updated yet
auto& rect = $frame_rects.at(sequence.current);
sprite.setTextureRect(rect);
}
void Animate2::play_sound() {
if(sounds.contains(form_name)) {
fmt::println("Playing sound for {}", form_name);
for(auto& [at_frame, sound_name] : sounds.at(form_name)) {
if(sequence.current == at_frame) {
sound::play(sound_name);
}
}
}
}
// replaces step
void Animate2::update_frame() {
dbc::check(playing, "attempt to update animation that's not playing");
@ -76,6 +86,8 @@ namespace animate2 {
playing = onLoop(sequence, transform);
}
if(frame_change) play_sound();
if(frame_change && onFrame != nullptr) onFrame();
dbc::check(sequence.current < sequence.frame_count, "onLoop fail: current frame out of frames.size()");