Fix removing Gameplay Globals

This commit is contained in:
Wojtek Figat
2022-07-23 16:58:16 +02:00
parent 47b255ed3e
commit 74e3d1ad8f
2 changed files with 7 additions and 31 deletions

View File

@@ -74,20 +74,11 @@ Dictionary<String, Variant> GameplayGlobals::GetValues() const
void GameplayGlobals::SetValues(const Dictionary<String, Variant>& values)
{
ScopeLock lock(Locker);
for (auto& e : values)
for (auto it = Variables.Begin(); it.IsNotEnd(); ++it)
{
bool hasKey = false;
for (auto& q : values)
if (!values.ContainsKey(it->Key))
{
if (e.Key == q.Key)
{
hasKey = true;
break;
}
}
if (!hasKey)
{
Variables.Remove(e.Key);
Variables.Remove(it);
}
}
for (auto i = values.Begin(); i.IsNotEnd(); ++i)
@@ -114,20 +105,11 @@ Dictionary<String, Variant> GameplayGlobals::GetDefaultValues() const
void GameplayGlobals::SetDefaultValues(const Dictionary<String, Variant>& values)
{
ScopeLock lock(Locker);
for (auto& e : values)
for (auto it = Variables.Begin(); it.IsNotEnd(); ++it)
{
bool hasKey = false;
for (auto& q : values)
if (!values.ContainsKey(it->Key))
{
if (e.Key == q.Key)
{
hasKey = true;
break;
}
}
if (!hasKey)
{
Variables.Remove(e.Key);
Variables.Remove(it);
}
}
for (auto i = values.Begin(); i.IsNotEnd(); ++i)

View File

@@ -11,9 +11,8 @@
/// </summary>
API_CLASS(NoSpawn) class FLAXENGINE_API GameplayGlobals : public BinaryAsset
{
DECLARE_BINARY_ASSET_HEADER(GameplayGlobals, 2);
DECLARE_BINARY_ASSET_HEADER(GameplayGlobals, 2);
public:
/// <summary>
/// The variable data.
/// </summary>
@@ -31,14 +30,12 @@ public:
};
public:
/// <summary>
/// The collection of gameplay global variables identified by the name.
/// </summary>
Dictionary<String, Variable> Variables;
public:
/// <summary>
/// Gets the values (run-time).
/// </summary>
@@ -64,7 +61,6 @@ public:
API_PROPERTY() void SetDefaultValues(const Dictionary<String, Variant>& values);
public:
/// <summary>
/// Gets the value of the global variable (it must be added first).
/// </summary>
@@ -96,12 +92,10 @@ public:
#endif
public:
// [BinaryAsset]
void InitAsVirtual() override;
protected:
// [BinaryAsset]
LoadResult load() override;
void unload(bool isReloading) override;