Skip to content

Commit 426a5c9

Browse files
committed
Added migration tool for Scripts folder
1 parent f46e86e commit 426a5c9

File tree

5 files changed

+43
-6
lines changed

5 files changed

+43
-6
lines changed

Sources/Overload/OvEditor/include/OvEditor/Core/EditorActions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,11 @@ namespace OvEditor::Core
336336
* Refresh every scripts (Re-interpret)
337337
*/
338338
void RefreshScripts();
339+
340+
/**
341+
* Migrate all scripts from the Scripts/ folder to the Assets/Scripts/ folder
342+
*/
343+
void MigrateScriptsToAssets();
339344
#pragma endregion
340345

341346
#pragma region BUILDING

Sources/Overload/OvEditor/include/OvEditor/Panels/MenuBar.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ namespace OvEditor::Panels
4646
void CreateActorsMenu();
4747
void CreateResourcesMenu();
4848
void CreateSettingsMenu();
49+
void CreateToolsMenu();
4950
void CreateLayoutMenu();
5051
void CreateHelpMenu();
5152

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,27 @@ void OvEditor::Core::EditorActions::RefreshScripts()
134134
OVLOG_INFO("Scripts interpretation succeeded!");
135135
}
136136

137+
void OvEditor::Core::EditorActions::MigrateScriptsToAssets()
138+
{
139+
// Copy all scripts from the project scripts folder to the project assets folder + "Scripts/"
140+
std::filesystem::copy(m_context.projectScriptsPath, m_context.projectAssetsPath + "Scripts\\", std::filesystem::copy_options::recursive);
141+
std::filesystem::remove_all(m_context.projectScriptsPath);
142+
143+
auto previousName = OvTools::Utils::PathParser::MakeNonWindowsStyle(m_context.projectScriptsPath);
144+
auto newName = OvTools::Utils::PathParser::MakeNonWindowsStyle(m_context.projectAssetsPath + "Scripts\\");
145+
146+
for (auto& p : std::filesystem::recursive_directory_iterator(newName))
147+
{
148+
if (!p.is_directory())
149+
{
150+
std::string newFileName = GetResourcePath(OvTools::Utils::PathParser::MakeWindowsStyle(p.path().string()));
151+
std::string previousFileName = std::filesystem::path{ newFileName }.stem().string();
152+
153+
PropagateScriptRename(OvTools::Utils::PathParser::MakeWindowsStyle(previousFileName), OvTools::Utils::PathParser::MakeWindowsStyle(newFileName));
154+
}
155+
}
156+
}
157+
137158
std::optional<std::string> OvEditor::Core::EditorActions::SelectBuildFolder()
138159
{
139160
OvWindowing::Dialogs::SaveFileDialog dialog("Build location");

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,17 +1012,20 @@ OvEditor::Panels::AssetBrowser::AssetBrowser
10121012
);
10131013
}
10141014

1015-
if (!std::filesystem::exists(m_projectScriptFolder))
1015+
if (std::filesystem::exists(m_projectScriptFolder))
10161016
{
1017-
std::filesystem::create_directories(m_projectScriptFolder);
1018-
10191017
OvWindowing::Dialogs::MessageBox message
10201018
(
1021-
"Scripts folder not found",
1022-
"The \"Scripts/\" folders hasn't been found in your project directory.\nIt has been automatically generated",
1019+
"Deprecated scripts folder found.",
1020+
"A \"Scripts/\" folder was found outside of the \"Assets\" folder, which is now deprecated. Migrating your scripts is recommended.\nDo you want to proceed?",
10231021
OvWindowing::Dialogs::MessageBox::EMessageType::WARNING,
1024-
OvWindowing::Dialogs::MessageBox::EButtonLayout::OK
1022+
OvWindowing::Dialogs::MessageBox::EButtonLayout::YES_NO
10251023
);
1024+
1025+
if (message.GetUserAction() == OvWindowing::Dialogs::MessageBox::EUserAction::YES)
1026+
{
1027+
EDITOR_EXEC(MigrateScriptsToAssets());
1028+
}
10261029
}
10271030

10281031
auto& refreshButton = CreateWidget<Buttons::Button>("Rescan assets");

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ OvEditor::Panels::MenuBar::MenuBar()
4444
CreateActorsMenu();
4545
CreateResourcesMenu();
4646
CreateSettingsMenu();
47+
CreateToolsMenu();
4748
CreateLayoutMenu();
4849
CreateHelpMenu();
4950
}
@@ -195,6 +196,12 @@ void OvEditor::Panels::MenuBar::CreateSettingsMenu()
195196
m_settingsMenu = &CreateWidget<MenuList>("Settings");
196197
}
197198

199+
void OvEditor::Panels::MenuBar::CreateToolsMenu()
200+
{
201+
auto& toolsMenu = CreateWidget<MenuList>("Tools");
202+
toolsMenu.CreateWidget<MenuItem>("Migrate Scripts To Assets Folder").ClickedEvent += EDITOR_BIND(MigrateScriptsToAssets);
203+
}
204+
198205
void OvEditor::Panels::MenuBar::CreateLayoutMenu()
199206
{
200207
auto& layoutMenu = CreateWidget<MenuList>("Layout");

0 commit comments

Comments
 (0)