Refactor settings types to use scripting API
This commit is contained in:
@@ -8,7 +8,6 @@
|
||||
#include "Prefabs/Prefab.h"
|
||||
#include "Prefabs/PrefabManager.h"
|
||||
#include "Engine/Core/Log.h"
|
||||
#include "Engine/Core/Config/LayersTagsSettings.h"
|
||||
#include "Engine/Scripting/Script.h"
|
||||
#include "Engine/Scripting/ManagedCLR/MClass.h"
|
||||
#include "Engine/Threading/Threading.h"
|
||||
@@ -386,21 +385,19 @@ Actor* Actor::GetChildByPrefabObjectId(const Guid& prefabObjectId) const
|
||||
|
||||
bool Actor::HasTag(const StringView& tag) const
|
||||
{
|
||||
return HasTag() && tag == LayersAndTagsSettings::Instance()->Tags[_tag];
|
||||
return HasTag() && tag == Level::Tags[_tag];
|
||||
}
|
||||
|
||||
const String& Actor::GetLayerName() const
|
||||
{
|
||||
const auto settings = LayersAndTagsSettings::Instance();
|
||||
return settings->Layers[_layer];
|
||||
return Level::Layers[_layer];
|
||||
}
|
||||
|
||||
const String& Actor::GetTag() const
|
||||
{
|
||||
if (HasTag())
|
||||
{
|
||||
const auto settings = LayersAndTagsSettings::Instance();
|
||||
return settings->Tags[_tag];
|
||||
return Level::Tags[_tag];
|
||||
}
|
||||
return String::Empty;
|
||||
}
|
||||
@@ -420,13 +417,13 @@ void Actor::SetTagIndex(int32 tagIndex)
|
||||
if (tagIndex == ACTOR_TAG_INVALID)
|
||||
{
|
||||
}
|
||||
else if (LayersAndTagsSettings::Instance()->Tags.IsEmpty())
|
||||
else if (Level::Tags.IsEmpty())
|
||||
{
|
||||
tagIndex = ACTOR_TAG_INVALID;
|
||||
}
|
||||
else
|
||||
{
|
||||
tagIndex = tagIndex < 0 ? ACTOR_TAG_INVALID : Math::Min(tagIndex, LayersAndTagsSettings::Instance()->Tags.Count() - 1);
|
||||
tagIndex = tagIndex < 0 ? ACTOR_TAG_INVALID : Math::Min(tagIndex, Level::Tags.Count() - 1);
|
||||
}
|
||||
if (tagIndex == _tag)
|
||||
return;
|
||||
@@ -444,7 +441,7 @@ void Actor::SetTag(const StringView& tagName)
|
||||
}
|
||||
else
|
||||
{
|
||||
tagIndex = LayersAndTagsSettings::Instance()->Tags.Find(tagName);
|
||||
tagIndex = Level::Tags.Find(tagName);
|
||||
if (tagIndex == -1)
|
||||
{
|
||||
LOG(Error, "Cannot change actor tag. Given value is invalid.");
|
||||
@@ -971,7 +968,7 @@ void Actor::Deserialize(DeserializeStream& stream, ISerializeModifier* modifier)
|
||||
if (tag->value.IsString() && tag->value.GetStringLength())
|
||||
{
|
||||
const String tagName = tag->value.GetText();
|
||||
_tag = LayersAndTagsSettings::Instance()->GetOrAddTag(tagName);
|
||||
_tag = Level::GetOrAddTag(tagName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "Engine/Core/Cache.h"
|
||||
#include "Engine/Core/Collections/CollectionPoolCache.h"
|
||||
#include "Engine/Core/ObjectsRemovalService.h"
|
||||
#include "Engine/Core/Config/LayersTagsSettings.h"
|
||||
#include "Engine/Debug/Exceptions/ArgumentException.h"
|
||||
#include "Engine/Debug/Exceptions/ArgumentNullException.h"
|
||||
#include "Engine/Debug/Exceptions/InvalidOperationException.h"
|
||||
@@ -97,6 +98,7 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
bool Init() override;
|
||||
void Update() override;
|
||||
void LateUpdate() override;
|
||||
void FixedUpdate() override;
|
||||
@@ -124,6 +126,8 @@ Delegate<Scene*, const Guid&> Level::SceneUnloaded;
|
||||
Action Level::ScriptsReloadStart;
|
||||
Action Level::ScriptsReload;
|
||||
Action Level::ScriptsReloadEnd;
|
||||
Array<String> Level::Tags;
|
||||
String Level::Layers[32];
|
||||
|
||||
bool LevelImpl::spawnActor(Actor* actor, Actor* parent)
|
||||
{
|
||||
@@ -158,6 +162,15 @@ bool LevelImpl::deleteActor(Actor* actor)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LevelService::Init()
|
||||
{
|
||||
auto& settings = *LayersAndTagsSettings::Get();
|
||||
Level::Tags = settings.Tags;
|
||||
for (int32 i = 0; i < ARRAY_COUNT(Level::Layers); i++)
|
||||
Level::Layers[i] = settings.Layers[i];
|
||||
return false;
|
||||
}
|
||||
|
||||
void LevelService::Update()
|
||||
{
|
||||
PROFILE_CPU();
|
||||
@@ -642,6 +655,25 @@ void LevelImpl::CallSceneEvent(SceneEventType eventType, Scene* scene, Guid scen
|
||||
}
|
||||
}
|
||||
|
||||
int32 Level::GetOrAddTag(const StringView& tag)
|
||||
{
|
||||
int32 index = Tags.Find(tag);
|
||||
if (index == INVALID_INDEX)
|
||||
{
|
||||
index = Tags.Count();
|
||||
Tags.AddOne() = tag;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
int32 Level::GetNonEmptyLayerNamesCount()
|
||||
{
|
||||
int32 result = 31;
|
||||
while (result >= 0 && Layers[result].IsEmpty())
|
||||
result--;
|
||||
return result + 1;
|
||||
}
|
||||
|
||||
void Level::callActorEvent(ActorEventType eventType, Actor* a, Actor* b)
|
||||
{
|
||||
PROFILE_CPU();
|
||||
|
||||
@@ -420,6 +420,31 @@ public:
|
||||
/// <param name="output">Output array with only parents</param>
|
||||
static void ConstructParentActorsTreeList(const Array<Actor*>& input, Array<Actor*>& output);
|
||||
|
||||
public:
|
||||
|
||||
/// <summary>
|
||||
/// The tags names.
|
||||
/// </summary>
|
||||
static Array<String> Tags;
|
||||
|
||||
/// <summary>
|
||||
/// The layers names.
|
||||
/// </summary>
|
||||
static String Layers[32];
|
||||
|
||||
/// <summary>
|
||||
/// Gets or adds the tag (returns the tag index).
|
||||
/// </summary>
|
||||
/// <param name="tag">The tag.</param>
|
||||
/// <returns>The tag index.</returns>
|
||||
static int32 GetOrAddTag(const StringView& tag);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the amount of non empty layer names (from the beginning, trims the last ones).
|
||||
/// </summary>
|
||||
/// <returns>The layers count.</returns>
|
||||
static int32 GetNonEmptyLayerNamesCount();
|
||||
|
||||
private:
|
||||
|
||||
// Actor API
|
||||
|
||||
Reference in New Issue
Block a user