@@ -594,95 +594,74 @@ void AreaEditor::Draw(BITMAP* pTargetBitmap, const Vector &targetPos)
594
594
EditorActivity::Draw (pTargetBitmap, targetPos);
595
595
}
596
596
597
+ // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
597
598
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);
603
602
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);
608
605
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" ;
634
616
}
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 (" \n IncludeFile" );
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 (" \t IncludeFile" );
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\n THE 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\n The edited Scene preset was saved but will not be loaded on next game start!\n Please 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\n The edited Scene preset was saved but will not be loaded on next game start!\n Please include the Scene preset manually!" );
647
+ } else {
648
+ // Add extra tab since the DataModule has everything indented.
649
+ indexWriter.NewProperty (" \t IncludeFile" );
650
+ indexWriter << scenesFilePath;
651
+ indexWriter.EndWrite ();
652
+ }
653
+ }
654
+ }
655
+ }
656
+ return true ;
682
657
}
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 ;
683
663
}
684
-
685
- return false ;
664
+ return false ;
686
665
}
687
666
688
667
0 commit comments