Skip to content

Commit f46e86e

Browse files
committed
Scripts are now expected to be in assets folder
1 parent 4d3a657 commit f46e86e

File tree

5 files changed

+20
-38
lines changed

5 files changed

+20
-38
lines changed

Sources/Overload/OvCore/src/OvCore/Scripting/Lua/LuaScriptEngine.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ void OvCore::Scripting::LuaScriptEngine::CreateContext()
115115
std::for_each(m_context.behaviours.begin(), m_context.behaviours.end(),
116116
[this](std::reference_wrapper<OvCore::ECS::Components::Behaviour> behaviour)
117117
{
118-
if (!RegisterBehaviour(*m_context.luaState, behaviour.get(), m_context.scriptRootFolder + behaviour.get().name + GetDefaultExtension()))
118+
if (!RegisterBehaviour(*m_context.luaState, behaviour.get(), m_context.scriptRootFolder + behaviour.get().name))
119119
{
120120
++m_context.errorCount;
121121
}
@@ -180,7 +180,7 @@ void OvCore::Scripting::LuaScriptEngineBase::AddBehaviour(OvCore::ECS::Component
180180

181181
m_context.behaviours.push_back(std::ref(p_toAdd));
182182

183-
if (!RegisterBehaviour(*m_context.luaState, p_toAdd, m_context.scriptRootFolder + p_toAdd.name + GetDefaultExtension()))
183+
if (!RegisterBehaviour(*m_context.luaState, p_toAdd, m_context.scriptRootFolder + p_toAdd.name))
184184
{
185185
++m_context.errorCount;
186186
}
@@ -196,7 +196,7 @@ void OvCore::Scripting::LuaScriptEngineBase::RemoveBehaviour(OvCore::ECS::Compon
196196

197197
m_context.behaviours.erase(
198198
std::remove_if(m_context.behaviours.begin(), m_context.behaviours.end(),
199-
[&p_toRemove](std::reference_wrapper< OvCore::ECS::Components::Behaviour> behaviour) {
199+
[&p_toRemove](std::reference_wrapper<OvCore::ECS::Components::Behaviour> behaviour) {
200200
return &p_toRemove == &behaviour.get();
201201
}
202202
)

Sources/Overload/OvEditor/src/OvEditor/Core/Context.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ OvEditor::Core::Context::Context(const std::string& p_projectPath, const std::st
137137

138138
/* Scripting */
139139
scriptEngine = std::make_unique<OvCore::Scripting::ScriptEngine>();
140-
scriptEngine->SetScriptRootFolder(projectScriptsPath);
140+
scriptEngine->SetScriptRootFolder(projectAssetsPath);
141141

142142
/* Service Locator providing */
143143
ServiceLocator::Provide<OvPhysics::Core::PhysicsEngine>(*physicsEngine);

Sources/Overload/OvEditor/src/OvEditor/Core/EditorActions.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -793,17 +793,12 @@ void OvEditor::Core::EditorActions::PropagateFolderDestruction(std::string p_fol
793793

794794
void OvEditor::Core::EditorActions::PropagateScriptRename(std::string p_previousName, std::string p_newName)
795795
{
796-
p_previousName = GetScriptPath(p_previousName);
797-
p_newName = GetScriptPath(p_newName);
798-
799796
if (auto currentScene = m_context.sceneManager.GetCurrentScene())
800797
for (auto actor : currentScene->GetActors())
801798
if (actor->RemoveBehaviour(p_previousName))
802799
actor->AddBehaviour(p_newName);
803800

804801
PropagateFileRenameThroughSavedFilesOfType(p_previousName, p_newName, OvTools::Utils::PathParser::EFileType::SCENE);
805-
806-
EDITOR_PANEL(Panels::Inspector, "Inspector").Refresh();
807802
}
808803

809804
void OvEditor::Core::EditorActions::PropagateFileRename(std::string p_previousName, std::string p_newName)
@@ -938,6 +933,9 @@ void OvEditor::Core::EditorActions::PropagateFileRename(std::string p_previousNa
938933
case OvTools::Utils::PathParser::EFileType::SOUND:
939934
PropagateFileRenameThroughSavedFilesOfType(p_previousName, p_newName, OvTools::Utils::PathParser::EFileType::SCENE);
940935
break;
936+
case OvTools::Utils::PathParser::EFileType::SCRIPT:
937+
PropagateScriptRename(p_previousName, p_newName);
938+
break;
941939
}
942940

943941
EDITOR_PANEL(Panels::Inspector, "Inspector").Refresh();

Sources/Overload/OvEditor/src/OvEditor/Panels/AssetBrowser.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,7 @@ void OvEditor::Panels::AssetBrowser::ConsiderItem(OvUI::Widgets::Layout::TreeNod
13061306
std::make_pair(resourceFormatPath, &itemGroup)
13071307
);
13081308

1309-
contextMenu->RenamedEvent += [&ddSource, &clickableText, p_scriptFolder](std::string p_prev, std::string p_newPath)
1309+
contextMenu->RenamedEvent += [&ddSource, &clickableText](std::string p_prev, std::string p_newPath)
13101310
{
13111311
if (p_newPath != p_prev)
13121312
{
@@ -1316,16 +1316,9 @@ void OvEditor::Panels::AssetBrowser::ConsiderItem(OvUI::Widgets::Layout::TreeNod
13161316
std::string elementName = OvTools::Utils::PathParser::GetElementName(p_newPath);
13171317
ddSource.data.first = OvTools::Utils::PathParser::GetContainingFolder(ddSource.data.first) + elementName;
13181318

1319-
if (!p_scriptFolder)
1320-
{
1321-
EDITOR_EXEC(PropagateFileRename(p_prev, p_newPath));
1322-
if (EDITOR_CONTEXT(sceneManager).GetCurrentSceneSourcePath() == p_prev) // Modify current scene source path if the renamed file is the current scene
1323-
EDITOR_CONTEXT(sceneManager).StoreCurrentSceneSourcePath(p_newPath);
1324-
}
1325-
else
1326-
{
1327-
EDITOR_EXEC(PropagateScriptRename(p_prev, p_newPath));
1328-
}
1319+
EDITOR_EXEC(PropagateFileRename(p_prev, p_newPath));
1320+
if (EDITOR_CONTEXT(sceneManager).GetCurrentSceneSourcePath() == p_prev) // Modify current scene source path if the renamed file is the current scene
1321+
EDITOR_CONTEXT(sceneManager).StoreCurrentSceneSourcePath(p_newPath);
13291322

13301323
clickableText.content = elementName;
13311324
}

Sources/Overload/OvEditor/src/OvEditor/Panels/Inspector.cpp

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -163,32 +163,23 @@ OvEditor::Panels::Inspector::Inspector
163163
// Add script button state updater
164164
const auto updateAddScriptButton = [&addScriptButton, this](const std::string& p_script)
165165
{
166-
const std::string defaultScriptExtension = OVSERVICE(OvCore::Scripting::ScriptEngine).GetDefaultExtension();
167-
168-
const std::string realScriptPath =
169-
EDITOR_CONTEXT(projectScriptsPath) +
170-
p_script +
171-
defaultScriptExtension;
166+
const auto realPath = EDITOR_EXEC(GetRealPath(m_scriptSelectorWidget->content));
172167

173168
const auto targetActor = GetTargetActor();
174-
const bool isScriptValid = std::filesystem::exists(realScriptPath) && targetActor && !targetActor->GetBehaviour(p_script);
169+
const bool canAddScript = std::filesystem::exists(realPath) && targetActor && !targetActor->GetBehaviour(p_script);
175170

176-
addScriptButton.disabled = !isScriptValid;
177-
addScriptButton.idleBackgroundColor = isScriptValid ? OvUI::Types::Color{ 0.7f, 0.5f, 0.f } : OvUI::Types::Color{ 0.1f, 0.1f, 0.1f };
171+
addScriptButton.disabled = !canAddScript;
172+
addScriptButton.idleBackgroundColor = canAddScript ? OvUI::Types::Color{ 0.7f, 0.5f, 0.f } : OvUI::Types::Color{ 0.1f, 0.1f, 0.1f };
178173
};
179174

180175
m_scriptSelectorWidget->ContentChangedEvent += updateAddScriptButton;
181176

182-
addScriptButton.ClickedEvent += [updateAddScriptButton, this] {
183-
const std::string defaultScriptExtension = OVSERVICE(OvCore::Scripting::ScriptEngine).GetDefaultExtension();
184-
185-
const std::string realScriptPath =
186-
EDITOR_CONTEXT(projectScriptsPath) +
187-
m_scriptSelectorWidget->content +
188-
defaultScriptExtension;
177+
addScriptButton.ClickedEvent += [updateAddScriptButton, this]
178+
{
179+
const auto realPath = EDITOR_EXEC(GetRealPath(m_scriptSelectorWidget->content));
189180

190181
// Ensure that the script is a valid one
191-
if (std::filesystem::exists(realScriptPath))
182+
if (std::filesystem::exists(realPath))
192183
{
193184
GetTargetActor()->AddBehaviour(m_scriptSelectorWidget->content);
194185
updateAddScriptButton(m_scriptSelectorWidget->content);
@@ -197,7 +188,7 @@ OvEditor::Panels::Inspector::Inspector
197188

198189
ddTarget.DataReceivedEvent += [updateAddScriptButton, this](std::pair<std::string, Layout::Group*> p_data)
199190
{
200-
m_scriptSelectorWidget->content = EDITOR_EXEC(GetScriptPath(p_data.first));
191+
m_scriptSelectorWidget->content = p_data.first;
201192
updateAddScriptButton(m_scriptSelectorWidget->content);
202193
};
203194
}

0 commit comments

Comments
 (0)