diff --git a/src/supertux/sector.cpp b/src/supertux/sector.cpp index 1f59723fcfe..3672a5d621c 100644 --- a/src/supertux/sector.cpp +++ b/src/supertux/sector.cpp @@ -71,7 +71,8 @@ Sector::Sector(Level& parent) : m_gravity(10.0f), m_collision_system(new CollisionSystem(*this)), m_text_object(add("Text")), - m_init_script_run() + m_init_script_run(), + m_init_script_run_once() { add("Effect"); add("TextArray"); @@ -288,7 +289,8 @@ Sector::activate(const Vector& player_pos) } // Run init script - if (!m_init_script.empty() && !Editor::is_active() && !m_init_script_run) { + if (!m_init_script.empty() && !Editor::is_active() && + ((m_init_script_run_once && !m_init_script_run) || !m_init_script_run_once)) { run_script(m_init_script, "init-script"); m_init_script_run = true; } @@ -798,6 +800,10 @@ Sector::save(Writer &writer) writer.write("init-script", m_init_script,false); } + if (m_init_script_run_once) { + writer.write("init-script-run-once", m_init_script_run_once); + } + // saving objects; std::vector objects(get_objects().size()); std::transform(get_objects().begin(), get_objects().end(), objects.begin(), [] (auto& obj) { diff --git a/src/supertux/sector.hpp b/src/supertux/sector.hpp index 6dc9dcd47a7..00504cfc733 100644 --- a/src/supertux/sector.hpp +++ b/src/supertux/sector.hpp @@ -85,6 +85,14 @@ class Sector final : public Base::Sector Level& get_level() const { return m_level; } TileSet* get_tileset() const override; bool in_worldmap() const override; + void set_init_script_run_once(bool run_once) + { + m_init_script_run_once = run_once; + } + bool get_init_script_run_once() const + { + return m_init_script_run_once; + } /** activates this sector (change music, initialize player class, ...) */ void activate(const std::string& spawnpoint); @@ -261,6 +269,7 @@ class Sector final : public Base::Sector float m_last_scale; float m_last_dt; bool m_init_script_run; + bool m_init_script_run_once; private: Sector(const Sector&) = delete; diff --git a/src/supertux/sector_parser.cpp b/src/supertux/sector_parser.cpp index 43fb63190fe..65d4608fe5a 100644 --- a/src/supertux/sector_parser.cpp +++ b/src/supertux/sector_parser.cpp @@ -142,6 +142,14 @@ SectorParser::parse(const ReaderMapping& reader) iter.get(value); m_sector.set_init_script(value); } + else if(iter.get_key() == "init-script-run-once") + { + auto sector = dynamic_cast(&m_sector); + if (!sector) continue; + bool value; + iter.get(value); + sector->set_init_script_run_once(value); + } else if (iter.get_key() == "ambient-light") { const auto& sx = iter.get_sexp();