Don't reset position when reloading the music

This commit is contained in:
Stepland 2022-01-06 22:38:51 +01:00
parent 797c6142b7
commit c9a4937a92
2 changed files with 13 additions and 8 deletions

View File

@ -7,6 +7,7 @@
## 🍒 Small improvements 🍒
- Frendlier error message when the UI font is not found in the assets folder
- Playback position is kept instead of being reset to zero when you change charts or reload the audio file
## 🚧 Small Changes 🚧
- Force using the asset folder next to the executable

View File

@ -1,5 +1,6 @@
#include "editor_state.hpp"
#include <algorithm>
#include <cmath>
#include <filesystem>
#include <imgui-SFML.h>
@ -44,10 +45,11 @@ void EditorState::reloadMusic() {
) {
music.reset();
}
playbackPosition = sf::seconds(-(fumen.offset));
previousPos = playbackPosition;
reloadPreviewEnd();
auto seconds_position = std::clamp(playbackPosition.asSeconds(), -(fumen.offset), previewEnd.asSeconds());
playbackPosition = sf::seconds(seconds_position);
previousPos = playbackPosition;
}
void EditorState::reloadPreviewEnd() {
@ -92,11 +94,13 @@ void EditorState::reloadAlbumCover() {
void EditorState::setPlaybackAndMusicPosition(sf::Time newPosition) {
reloadPreviewEnd();
if (newPosition.asSeconds() < -fumen.offset) {
newPosition = sf::seconds(-fumen.offset);
} else if (newPosition > previewEnd) {
newPosition = previewEnd;
}
newPosition = sf::seconds(
std::clamp(
newPosition.asSeconds(),
-fumen.offset,
previewEnd.asSeconds()
)
);
previousPos = sf::seconds(newPosition.asSeconds() - 1.f / 60.f);
playbackPosition = newPosition;
if (music) {