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

Commit 39c2555

Browse files
committed
Fix AreaEditor failing to save
Copypasta of SceneEditor::SaveScene - very bad, but is what it is until someone deals with it
1 parent 3dcc68b commit 39c2555

File tree

2 files changed

+70
-97
lines changed

2 files changed

+70
-97
lines changed

Activities/AreaEditor.cpp

Lines changed: 62 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -594,95 +594,74 @@ void AreaEditor::Draw(BITMAP* pTargetBitmap, const Vector &targetPos)
594594
EditorActivity::Draw(pTargetBitmap, targetPos);
595595
}
596596

597+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
597598

598-
//////////////////////////////////////////////////////////////////////////////////////////
599-
// Method: SaveScene
600-
//////////////////////////////////////////////////////////////////////////////////////////
601-
// Description: Saves the current scene to an appropriate ini file, and asks user if
602-
// they want to overwrite first if scene of this name exists.
599+
bool AreaEditor::SaveScene(const std::string &saveAsName, bool forceOverwrite) {
600+
Scene *editedScene = g_SceneMan.GetScene();
601+
editedScene->SetPresetName(saveAsName);
603602

604-
bool AreaEditor::SaveScene(std::string saveAsName, bool forceOverwrite)
605-
{
606-
// Set the name of the current scene in effect
607-
g_SceneMan.GetScene()->SetPresetName(saveAsName);
603+
std::string dataModuleName = g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName();
604+
bool savingToUserScenesModule = (dataModuleName == c_UserScenesModuleName);
608605

609-
if (g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName() == c_UserScenesModuleName)
610-
{
611-
std::string sceneFilePath(g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName() + "/" + saveAsName + ".ini");
612-
std::string previewFilePath(g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName() + "/" + saveAsName + ".preview.png");
613-
if (g_PresetMan.AddEntityPreset(g_SceneMan.GetScene(), m_ModuleSpaceID, forceOverwrite, sceneFilePath))
614-
{
615-
// Save preview
616-
g_SceneMan.GetScene()->SavePreview(previewFilePath);
617-
618-
// Does ini already exist? If yes, then no need to add it to a scenes.ini etc
619-
bool sceneFileExisted = System::PathExistsCaseSensitive(sceneFilePath.c_str());
620-
// Create the writer
621-
Writer sceneWriter(sceneFilePath.c_str(), false);
622-
sceneWriter.NewProperty("AddScene");
623-
// Write the scene out to the new ini
624-
sceneWriter << g_SceneMan.GetScene();
625-
return m_HasEverBeenSaved = true;
626-
}
627-
else
628-
{
629-
// Gotto ask if we can overwrite the existing scene
630-
m_PreviousMode = EditorActivity::SAVEDIALOG;
631-
m_EditorMode = EditorActivity::OVERWRITEDIALOG;
632-
m_ModeChange = true;
633-
}
606+
std::string dataModuleFullPath = g_PresetMan.GetFullModulePath(dataModuleName);
607+
std::string sceneSavePath;
608+
std::string previewSavePath;
609+
610+
if (savingToUserScenesModule) {
611+
sceneSavePath = dataModuleFullPath + "/" + saveAsName + ".ini";
612+
previewSavePath = dataModuleFullPath + "/" + saveAsName + ".preview.png";
613+
} else {
614+
sceneSavePath = dataModuleFullPath + "/Scenes/" + saveAsName + ".ini";
615+
previewSavePath = dataModuleFullPath + "/Scenes/" + saveAsName + ".preview.png";
634616
}
635-
else
636-
{
637-
// Try to save to the data module
638-
std::string sceneFilePath(g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName() + "/Scenes/" + saveAsName + ".ini");
639-
std::string previewFilePath(g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName() + "/Scenes/" + saveAsName + ".preview.png");
640-
if (g_PresetMan.AddEntityPreset(g_SceneMan.GetScene(), m_ModuleSpaceID, forceOverwrite, sceneFilePath))
641-
{
642-
// Save preview
643-
g_SceneMan.GetScene()->SavePreview(previewFilePath);
644-
645-
// Does ini already exist? If yes, then no need to add it to a scenes.ini etc
646-
bool sceneFileExisted = System::PathExistsCaseSensitive(sceneFilePath.c_str());
647-
// Create the writer
648-
Writer sceneWriter(sceneFilePath.c_str(), false);
649-
sceneWriter.NewProperty("AddScene");
650-
// TODO: Check if the ini file already exists, and then ask if overwrite
651-
// Write the scene out to the new ini
652-
sceneWriter << g_SceneMan.GetScene();
653-
654-
if (!sceneFileExisted)
655-
{
656-
// First find/create a .rte/Scenes.ini file to include the new .ini into
657-
std::string scenesFilePath(g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName() + "/Scenes.ini");
658-
bool scenesFileExisted = System::PathExistsCaseSensitive(scenesFilePath.c_str());
659-
Writer scenesWriter(scenesFilePath.c_str(), true);
660-
scenesWriter.NewProperty("\nIncludeFile");
661-
scenesWriter << sceneFilePath;
662-
663-
// Also add a line to the end of the modules' Index.ini to include the newly created Scenes.ini next startup
664-
// If it's already included, it doens't matter, the definitions will just bounce the second time
665-
if (!scenesFileExisted)
666-
{
667-
std::string indexFilePath(g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName() + "/Index.ini");
668-
Writer indexWriter(indexFilePath.c_str(), true);
669-
// Add extra tab since the DataModule has everything indented
670-
indexWriter.NewProperty("\tIncludeFile");
671-
indexWriter << scenesFilePath;
672-
}
673-
}
674-
return m_HasEverBeenSaved = true;
675-
}
676-
else
677-
{
678-
// Gotto ask if we can overwrite the existing scene
679-
m_PreviousMode = EditorActivity::SAVEDIALOG;
680-
m_EditorMode = EditorActivity::OVERWRITEDIALOG;
681-
m_ModeChange = true;
617+
618+
if (g_PresetMan.AddEntityPreset(editedScene, m_ModuleSpaceID, forceOverwrite, sceneSavePath)) {
619+
if (Writer sceneWriter(sceneSavePath, false); !sceneWriter.WriterOK()) {
620+
RTEError::ShowMessageBox("Failed to create Writer to path:\n\n" + sceneSavePath + "!\n\nTHE EDITED SCENE PRESET WAS NOT SAVED!!!");
621+
} else {
622+
// TODO: Check if the ini file already exists, and then ask if overwrite.
623+
sceneWriter.NewPropertyWithValue("AddScene", editedScene);
624+
sceneWriter.EndWrite();
625+
626+
editedScene->SavePreview(previewSavePath);
627+
m_HasEverBeenSaved = true;
628+
629+
if (!savingToUserScenesModule) {
630+
// First find/create a Scenes.ini file to include the new .ini into.
631+
std::string scenesFilePath(dataModuleFullPath + "/Scenes.ini");
632+
bool scenesFileExists = System::PathExistsCaseSensitive(scenesFilePath);
633+
634+
if (Writer scenesFileWriter(scenesFilePath, true); !scenesFileWriter.WriterOK()) {
635+
RTEError::ShowMessageBox("Failed to create Writer to path:\n\n" + scenesFilePath + "!\n\nThe edited Scene preset was saved but will not be loaded on next game start!\nPlease include the Scene preset manually!");
636+
} else {
637+
scenesFileWriter.NewPropertyWithValue("IncludeFile", sceneSavePath);
638+
scenesFileWriter.EndWrite();
639+
640+
// Append to the end of the modules' Index.ini to include the newly created Scenes.ini next startup.
641+
// If it's somehow already included without actually existing, it doesn't matter, the definitions will just bounce the second time.
642+
if (!scenesFileExists) {
643+
std::string indexFilePath = dataModuleFullPath + "/Index.ini";
644+
645+
if (Writer indexWriter(indexFilePath, true); !indexWriter.WriterOK()) {
646+
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!");
647+
} else {
648+
// Add extra tab since the DataModule has everything indented.
649+
indexWriter.NewProperty("\tIncludeFile");
650+
indexWriter << scenesFilePath;
651+
indexWriter.EndWrite();
652+
}
653+
}
654+
}
655+
}
656+
return true;
682657
}
658+
} else {
659+
// Got to ask if we can overwrite the existing preset.
660+
m_PreviousMode = EditorMode::SAVEDIALOG;
661+
m_EditorMode = EditorMode::OVERWRITEDIALOG;
662+
m_ModeChange = true;
683663
}
684-
685-
return false;
664+
return false;
686665
}
687666

688667

Activities/AreaEditor.h

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -208,19 +208,13 @@ ClassInfoGetters;
208208

209209
protected:
210210

211-
212-
//////////////////////////////////////////////////////////////////////////////////////////
213-
// Method: SaveScene
214-
//////////////////////////////////////////////////////////////////////////////////////////
215-
// Description: Saves the current scene to an appropriate ini file, and asks user if
216-
// they want to overwrite first if scene of this name exists.
217-
// Arguments: The name of the new scene to be saved.
218-
// Whetehr to force any existing Scene of that name to be overwritten if
219-
// it already exists.
220-
// Return value: Whether actually managed to save. Will return false both if a scene
221-
// of this name already exists, or if other error.
222-
223-
bool SaveScene(std::string saveAsName, bool forceOverwrite = false);
211+
/// <summary>
212+
/// Saves the current Scene to an appropriate ini file, and asks user if they want to overwrite first if scene of this name exists.
213+
/// </summary>
214+
/// <param name="saveAsName">The name of the new Scene to be saved.</param>
215+
/// <param name="forceOverwrite">Whether to force any existing Scene of that name to be overwritten if it already exists.</param>
216+
/// <returns>Whether actually managed to save. Will return false both if a scene of this name already exists, or if other error.</returns>
217+
bool SaveScene(const std::string &saveAsName, bool forceOverwrite = false);
224218

225219

226220
//////////////////////////////////////////////////////////////////////////////////////////
@@ -281,7 +275,7 @@ ClassInfoGetters;
281275

282276
// The textbox for entering new Area names
283277
GUITextBox *m_pNewAreaName;
284-
// // Number which
278+
// // Number which
285279
// int m_NewAreaNumber;
286280

287281

0 commit comments

Comments
 (0)