Skip to content

Commit

Permalink
Clear map data if map has changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyuu17 committed Jul 8, 2024
1 parent b3c86af commit 275bde1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/SWBF2/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,18 @@ namespace SWBF2

void Core::LoadLevel(const godot::String &mapName)
{
m_curMapName = mapName;

if (mapName.is_empty())
{
remove_child(find_child("Level", false));

// TODO reset
GameData::Instance()->ClearMapData();

m_curMapName = mapName;
return;
}

m_curMapName = mapName;

Level *lvl = memnew(Level);
add_child(lvl);
lvl->set_owner(this);
Expand Down
10 changes: 8 additions & 2 deletions src/SWBF2/GameData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@ namespace SWBF2

const GameData::SGameData &GameData::GetMapData()
{
std::string mapName{ DefaultGameMaps.at(Core::Instance()->GetMapName().ascii().get_data()) };
return m_gameData[mapName];
std::string mapPath{ DefaultGameMaps.at(Core::Instance()->GetMapName().ascii().get_data()) };
return m_gameData[mapPath];
}

void GameData::ClearMapData()
{
std::string mapPath{ DefaultGameMaps.at(Core::Instance()->GetMapName().ascii().get_data()) };
m_gameData[mapPath] = {};
}

void GameData::_bind_methods()
Expand Down
1 change: 1 addition & 0 deletions src/SWBF2/GameData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace SWBF2

void ReadLevelFile(const std::string &file);
const SGameData &GetMapData();
void ClearMapData();

void _ready() override;

Expand Down

0 comments on commit 275bde1

Please sign in to comment.