Skip to content

Commit

Permalink
Save worldmap music in worldmap state (#2965)
Browse files Browse the repository at this point in the history
This saves the current worldmap music in the worldmap state and should make sure that music changed using scripts gets loaded properly.

Fixes #2932
  • Loading branch information
tobbi authored Jun 6, 2024
1 parent 91b9417 commit ec06d2e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/worldmap/worldmap_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "worldmap/worldmap_state.hpp"

#include "math/vector.hpp"
#include "object/music_object.hpp"
#include "object/tilemap.hpp"
#include "squirrel/squirrel_util.hpp"
#include "supertux/constants.hpp"
Expand Down Expand Up @@ -89,6 +90,13 @@ WorldMapState::load_state()
throw std::runtime_error("No sector set.");
}

if (vm.has_property("music"))
{
const std::string music = vm.read_string("music");
auto& music_object = m_worldmap.get_sector().get_singleton_by_type<MusicObject>();
music_object.set_music(music);
}

/** Load objects. **/
load_tux();
load_levels();
Expand Down Expand Up @@ -290,6 +298,9 @@ WorldMapState::save_state() const
vm.delete_table_entry(sector.get_name().c_str());
vm.begin_table(sector.get_name().c_str());

auto& music_object = m_worldmap.get_sector().get_singleton_by_type<MusicObject>();
vm.store_string("music", music_object.get_music());

/** Save objects. **/
save_tux();
save_levels();
Expand Down

0 comments on commit ec06d2e

Please sign in to comment.