Skip to content

Commit a5a7735

Browse files
authored
Merge pull request #579 from sdslabs/reservedEntityNames
Added Reserved Entity Names
2 parents cfc5f8f + fd44773 commit a5a7735

File tree

5 files changed

+34
-9
lines changed

5 files changed

+34
-9
lines changed

editor/editor_system.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ void EditorSystem::drawDefaultUI(float deltaMilliseconds)
319319
if (ImGui::BeginMenu("Create Scene"))
320320
{
321321
ImGui::InputText("Scene Name", &newSceneName, ImGuiInputTextFlags_AlwaysInsertMode);
322-
if (!newSceneName.empty() && ImGui::Button("Create"))
322+
if (!newSceneName.empty() && ImGui::Button("Create") && !Scene::isReservedName(newSceneName))
323323
{
324324
if (SceneLoader::GetSingleton()->getCurrentScene())
325325
{
@@ -449,7 +449,7 @@ void EditorSystem::drawDefaultUI(float deltaMilliseconds)
449449
}
450450
if (ImGui::BeginMenu("Scene"))
451451
{
452-
ImGui::Checkbox("Autosave", &m_Autosave);
452+
ImGui::Checkbox("Autosave", &m_Autosave);
453453

454454
if (SceneLoader::GetSingleton()->getCurrentScene())
455455
{
@@ -871,8 +871,8 @@ Variant EditorSystem::autoSave(const Event* event)
871871
PRINT("Auto-saving current scene...");
872872
saveAll(nullptr);
873873
return true;
874-
}
875-
874+
}
875+
876876
return false;
877877
}
878878

editor/gui/inspector_dock.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,10 @@ void InspectorDock::draw(float deltaMilliseconds)
193193
{
194194
if (ImGui::InputText("Scene Name", &m_OpenedSceneName, ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll))
195195
{
196-
m_OpenedScene->setName(m_OpenedSceneName);
196+
if (!Scene::isReservedName(m_OpenedSceneName))
197+
{
198+
m_OpenedScene->setName(m_OpenedSceneName);
199+
}
197200
m_IsNameBeingEdited = false;
198201
}
199202
if (!ImGui::IsItemHovered() && ImGui::IsMouseClicked(ImGuiMouseButton_Left))

game/game_application.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ Ref<Application> CreateRootexApplication()
2222
Optional<String> GameApplication::getSceneNameFromCommandLine(const char* s)
2323
{
2424
String cmdLine = s;
25-
size_t found = cmdLine.find("game/assets/");
26-
if (found != String::npos)
25+
if (!Scene::isReservedName(cmdLine))
2726
{
28-
return cmdLine.substr(found, cmdLine.size() - 1);
27+
size_t found = cmdLine.find("game/assets/");
28+
if (found != String::npos)
29+
{
30+
return cmdLine.substr(found, cmdLine.size() - 1);
31+
}
2932
}
3033
return {};
3134
}
@@ -47,7 +50,11 @@ GameApplication::GameApplication()
4750
}
4851
else
4952
{
50-
SceneLoader::GetSingleton()->loadScene(m_ApplicationSettings->getJSON()["startScene"], {});
53+
String sceneName = m_ApplicationSettings->getJSON()["startScene"];
54+
if (Scene::isReservedName(sceneName))
55+
{
56+
SceneLoader::GetSingleton()->loadScene(sceneName, {});
57+
}
5158
}
5259

5360
GameRenderSystem::GetSingleton()->initialize({});

rootex/framework/scene.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,20 @@ bool Scene::removeChild(Scene* toRemove)
309309
return false;
310310
}
311311

312+
bool Scene::isReservedName(const String& sceneName)
313+
{
314+
static Vector<String> reservedNames { "pause", "pauseUI" };
315+
for (auto& reservedName : reservedNames)
316+
{
317+
if (reservedName == sceneName)
318+
{
319+
WARN("Cannot use reserved scene names");
320+
return true;
321+
}
322+
}
323+
return false;
324+
}
325+
312326
void Scene::setName(const String& name)
313327
{
314328
m_Name = name;

rootex/framework/scene.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class Scene
6363
static Ptr<Scene> CreateEmpty();
6464
static Ptr<Scene> CreateEmptyAtPath(const String& sceneFile);
6565
static Ptr<Scene> CreateRootScene();
66+
static bool isReservedName(const String& sceneName);
6667

6768
static Vector<Scene*> FindScenesByName(const String& name);
6869
static Scene* FindSceneByID(const SceneID& id);

0 commit comments

Comments
 (0)