Skip to content

Commit

Permalink
🐛 Also unload default terrain script when used.
Browse files Browse the repository at this point in the history
  • Loading branch information
ohlidalp authored and Petr Ohlídal committed Feb 21, 2022
1 parent 1db14cd commit f26e5a7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions source/main/scripting/ScriptEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

#define TRIGGER_EVENT(x, y) App::GetScriptEngine()->triggerEvent((x), (y))

#define DEFAULT_TERRAIN_SCRIPT "default.as" // Used when map creator doesn't provide custom script.

#include "Application.h"
#include "GameScript.h"
#include "InterThreadStoreVector.h"
Expand Down
13 changes: 10 additions & 3 deletions source/main/terrain/TerrainManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,16 @@ TerrainManager::~TerrainManager()
m_collisions = nullptr;
}

for (std::string as_filename : m_def.as_files)
if (m_def.as_files.size() != 0)
{
for (std::string as_filename : m_def.as_files)
{
App::GetScriptEngine()->unloadScript(as_filename, ScriptCategory::TERRAIN);
}
}
else
{
App::GetScriptEngine()->unloadScript(as_filename, ScriptCategory::TERRAIN);
App::GetScriptEngine()->unloadScript(DEFAULT_TERRAIN_SCRIPT, ScriptCategory::TERRAIN);
}
}

Expand Down Expand Up @@ -474,7 +481,7 @@ void TerrainManager::initScripting()
if (!loaded)
{
// load a default script that does the most basic things
App::GetScriptEngine()->loadScript("default.as");
App::GetScriptEngine()->loadScript(DEFAULT_TERRAIN_SCRIPT);
}
// finally activate AS logging, so we dont spam the users screen with initialization messages
App::GetScriptEngine()->activateLogging();
Expand Down

0 comments on commit f26e5a7

Please # to comment.