Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 83edd7d

Browse files
committed
Fix AssemblyEditor failing to save
Still pretty much copypasta of SceneEditor::SaveScene
1 parent b54d058 commit 83edd7d

File tree

2 files changed

+65
-103
lines changed

2 files changed

+65
-103
lines changed

Activities/AssemblyEditor.cpp

Lines changed: 58 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -608,107 +608,74 @@ BunkerAssembly * AssemblyEditor::BuildAssembly(std::string saveAsName)
608608
return pBA;
609609
}
610610

611+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
611612

612-
//////////////////////////////////////////////////////////////////////////////////////////
613-
// Method: SaveAssembly
614-
//////////////////////////////////////////////////////////////////////////////////////////
615-
// Description: Saves the current scene to an appropriate ini file, and asks user if
616-
// they want to overwrite first if scene of this name exists.
613+
bool AssemblyEditor::SaveAssembly(const std::string &saveAsName, bool forceOverwrite) {
614+
std::unique_ptr<BunkerAssembly> editedAssembly(BuildAssembly(saveAsName));
617615

618-
bool AssemblyEditor::SaveAssembly(std::string saveAsName, bool forceOverwrite)
619-
{
620-
BunkerAssembly *pBA = BuildAssembly(saveAsName);
616+
std::string dataModuleName = g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName();
617+
bool savingToUserScenesModule = (dataModuleName == c_UserScenesModuleName);
621618

622-
if (g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName() == c_UserScenesModuleName)
623-
{
624-
std::string sceneFilePath(g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName() + "/" + saveAsName + ".ini");
625-
if (g_PresetMan.AddEntityPreset(pBA, m_ModuleSpaceID, forceOverwrite, sceneFilePath))
626-
{
627-
// Does ini already exist? If yes, then no need to add it to a scenes.ini etc
628-
bool sceneFileExisted = System::PathExistsCaseSensitive(sceneFilePath.c_str());
629-
// Create the writer
630-
Writer sceneWriter(sceneFilePath.c_str(), false);
631-
sceneWriter.NewProperty("AddBunkerAssembly");
632-
// Write the scene out to the new ini
633-
sceneWriter << pBA;
634-
delete pBA;
635-
pBA = 0;
636-
return m_HasEverBeenSaved = true;
637-
}
638-
else
639-
{
640-
// Gotto ask if we can overwrite the existing scene
641-
m_PreviousMode = EditorActivity::SAVEDIALOG;
642-
m_EditorMode = EditorActivity::OVERWRITEDIALOG;
643-
m_ModeChange = true;
644-
}
645-
}
646-
else
647-
{
648-
std::string sceneFilePath;
619+
std::string dataModuleFullPath = g_PresetMan.GetFullModulePath(dataModuleName);
620+
std::string assemblySavePath;
649621

650-
// Try to save to the data module
651-
if (g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName() == "Base.rte")
652-
sceneFilePath = g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName() + "/Scenes/Objects/Bunkers/BunkerAssemblies/" + saveAsName + ".ini";
653-
else
654-
{
655-
sceneFilePath = g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName() + "/BunkerAssemblies/" + saveAsName + ".ini";
656-
System::MakeDirectory((g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName() + "/BunkerAssemblies").c_str());
622+
if (savingToUserScenesModule) {
623+
assemblySavePath = dataModuleFullPath + "/" + saveAsName + ".ini";
624+
} else {
625+
if (dataModuleName == "Base.rte") {
626+
assemblySavePath = dataModuleFullPath + "/Scenes/Objects/Bunkers/BunkerAssemblies/" + saveAsName + ".ini";
627+
} else {
628+
System::MakeDirectory((dataModuleFullPath + "/BunkerAssemblies").c_str());
629+
assemblySavePath = dataModuleFullPath + "/BunkerAssemblies/" + saveAsName + ".ini";
657630
}
631+
}
658632

659-
if (g_PresetMan.AddEntityPreset(pBA, m_ModuleSpaceID, forceOverwrite, sceneFilePath))
660-
{
661-
// Does ini already exist? If yes, then no need to add it to a scenes.ini etc
662-
bool sceneFileExisted = System::PathExistsCaseSensitive(sceneFilePath.c_str());
663-
// Create the writer
664-
Writer sceneWriter(sceneFilePath.c_str(), false);
665-
sceneWriter.NewProperty("AddBunkerAssembly");
666-
// Write the scene out to the new ini
667-
BunkerAssembly *pBA = BuildAssembly(saveAsName);
668-
sceneWriter << pBA;
669-
delete pBA;
670-
pBA = 0;
671-
672-
if (!sceneFileExisted)
673-
{
674-
// First find/create a .rte/Scenes.ini file to include the new .ini into
675-
std::string scenesFilePath;
676-
677-
if (g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName() == "Base.rte")
678-
scenesFilePath = g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName() + "/Scenes/Objects/Bunkers/BunkerAssemblies/BunkerAssemblies.ini";
679-
else
680-
scenesFilePath = g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName() + "/BunkerAssemblies/BunkerAssemblies.ini";
681-
682-
bool scenesFileExisted = System::PathExistsCaseSensitive(scenesFilePath.c_str());
683-
Writer scenesWriter(scenesFilePath.c_str(), true);
684-
scenesWriter.NewProperty("\nIncludeFile");
685-
scenesWriter << sceneFilePath;
686-
687-
// Also add a line to the end of the modules' Index.ini to include the newly created Scenes.ini next startup
688-
// If it's already included, it doens't matter, the definitions will just bounce the second time
689-
if (!scenesFileExisted)
690-
{
691-
std::string indexFilePath(g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName() + "/Index.ini");
692-
Writer indexWriter(indexFilePath.c_str(), true);
693-
// Add extra tab since the DataModule has everything indented
694-
indexWriter.NewProperty("\tIncludeFile");
695-
indexWriter << scenesFilePath;
633+
if (g_PresetMan.AddEntityPreset(editedAssembly.get(), m_ModuleSpaceID, forceOverwrite, assemblySavePath)) {
634+
if (Writer assemblyWriter(assemblySavePath, false); !assemblyWriter.WriterOK()) {
635+
RTEError::ShowMessageBox("Failed to create Writer to path:\n\n" + assemblySavePath + "!\n\nTHE EDITED BUNKER ASSEMBLY PRESET WAS NOT SAVED!!!");
636+
} else {
637+
// TODO: Check if the ini file already exists, and then ask if overwrite.
638+
assemblyWriter.NewPropertyWithValue("AddBunkerAssembly", editedAssembly.get());
639+
assemblyWriter.EndWrite();
640+
641+
m_HasEverBeenSaved = true;
642+
643+
if (!savingToUserScenesModule) {
644+
// First find/create a BunkerAssemblies.ini file to include the new .ini into.
645+
std::string assembliesFilePath = dataModuleFullPath + ((dataModuleName == "Base.rte") ? "/Scenes/Objects/Bunkers/BunkerAssemblies/BunkerAssemblies.ini" : "/BunkerAssemblies/BunkerAssemblies.ini");
646+
bool assembliesFileExists = System::PathExistsCaseSensitive(assembliesFilePath);
647+
648+
if (Writer assembliesFileWriter(assembliesFilePath, true); !assembliesFileWriter.WriterOK()) {
649+
RTEError::ShowMessageBox("Failed to create Writer to path:\n\n" + assembliesFilePath + "!\n\nThe edited Scene preset was saved but will not be loaded on next game start!\nPlease include the Scene preset manually!");
650+
} else {
651+
assembliesFileWriter.NewPropertyWithValue("IncludeFile", assemblySavePath);
652+
assembliesFileWriter.EndWrite();
653+
654+
// Append to the end of the modules' Index.ini to include the newly created Scenes.ini next startup.
655+
// If it's somehow already included without actually existing, it doesn't matter, the definitions will just bounce the second time.
656+
if (!assembliesFileExists) {
657+
std::string indexFilePath = dataModuleFullPath + "/Index.ini";
658+
659+
if (Writer indexWriter(indexFilePath, true); !indexWriter.WriterOK()) {
660+
RTEError::ShowMessageBox("Failed to create Writer to path:\n\n" + indexFilePath + "!\n\nThe edited Scene preset was saved but will not be loaded on next game start!\nPlease include the Scene preset manually!");
661+
} else {
662+
// Add extra tab since the DataModule has everything indented.
663+
indexWriter.NewProperty("\tIncludeFile");
664+
indexWriter << assembliesFilePath;
665+
indexWriter.EndWrite();
666+
}
667+
}
696668
}
697669
}
698-
return m_HasEverBeenSaved = true;
699-
}
700-
else
701-
{
702-
// Gotto ask if we can overwrite the existing scene
703-
m_PreviousMode = EditorActivity::SAVEDIALOG;
704-
m_EditorMode = EditorActivity::OVERWRITEDIALOG;
705-
m_ModeChange = true;
670+
return true;
706671
}
672+
} else {
673+
// Got to ask if we can overwrite the existing preset.
674+
m_PreviousMode = EditorMode::SAVEDIALOG;
675+
m_EditorMode = EditorMode::OVERWRITEDIALOG;
676+
m_ModeChange = true;
707677
}
708-
709-
delete pBA;
710-
pBA = 0;
711-
return false;
678+
return false;
712679
}
713680

714681

Activities/AssemblyEditor.h

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -222,18 +222,13 @@ ClassInfoGetters;
222222
BunkerAssembly *BuildAssembly(std::string saveAsName);
223223

224224

225-
//////////////////////////////////////////////////////////////////////////////////////////
226-
// Method: SaveAssembly
227-
//////////////////////////////////////////////////////////////////////////////////////////
228-
// Description: Saves the current assembly to an appropriate ini file, and asks user if
229-
// they want to overwrite first if scene of this name exists.
230-
// Arguments: The name of the new scene to be saved.
231-
// Whetehr to force any existing Scene of that name to be overwritten if
232-
// it already exists.
233-
// Return value: Whether actually managed to save. Will return false both if a scene
234-
// of this name already exists, or if other error.
235-
236-
bool SaveAssembly(std::string saveAsName, bool forceOverwrite = false);
225+
/// <summary>
226+
/// Saves the current BunkerAssembly to an appropriate ini file, and asks user if they want to overwrite first if a BunkerAssembly of this name exists.
227+
/// </summary>
228+
/// <param name="saveAsName">The name of the new BunkerAssembly to be saved.</param>
229+
/// <param name="forceOverwrite">Whether to force any existing BunkerAssembly of that name to be overwritten if it already exists.</param>
230+
/// <returns>Whether actually managed to save. Will return false both if a BunkerAssembly of this name already exists, or if other error.</returns>
231+
bool SaveAssembly(const std::string &saveAsName, bool forceOverwrite = false);
237232

238233

239234
//////////////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)