@@ -647,95 +647,74 @@ void SceneEditor::Draw(BITMAP* pTargetBitmap, const Vector &targetPos)
647
647
EditorActivity::Draw (pTargetBitmap, targetPos);
648
648
}
649
649
650
+ // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
650
651
651
- // ////////////////////////////////////////////////////////////////////////////////////////
652
- // Method: SaveScene
653
- // ////////////////////////////////////////////////////////////////////////////////////////
654
- // Description: Saves the current scene to an appropriate ini file, and asks user if
655
- // they want to overwrite first if scene of this name exists.
652
+ bool SceneEditor::SaveScene (const std::string &saveAsName, bool forceOverwrite) {
653
+ Scene *editedScene = g_SceneMan.GetScene ();
654
+ editedScene->SetPresetName (saveAsName);
656
655
657
- bool SceneEditor::SaveScene (std::string saveAsName, bool forceOverwrite)
658
- {
659
- // Set the name of the current scene in effect
660
- g_SceneMan.GetScene ()->SetPresetName (saveAsName);
656
+ std::string dataModuleName = g_PresetMan.GetDataModule (m_ModuleSpaceID)->GetFileName ();
657
+ bool savingToUserScenesModule = (dataModuleName == c_UserScenesModuleName);
661
658
662
- if (g_PresetMan.GetDataModule (m_ModuleSpaceID)->GetFileName () == c_UserScenesModuleName)
663
- {
664
- std::string sceneFilePath (g_PresetMan.GetDataModule (m_ModuleSpaceID)->GetFileName () + " /" + saveAsName + " .ini" );
665
- std::string previewFilePath (g_PresetMan.GetDataModule (m_ModuleSpaceID)->GetFileName () + " /" + saveAsName + " .preview.png" );
666
- if (g_PresetMan.AddEntityPreset (g_SceneMan.GetScene (), m_ModuleSpaceID, forceOverwrite, sceneFilePath))
667
- {
668
- // Save preview
669
- g_SceneMan.GetScene ()->SavePreview (previewFilePath);
670
-
671
- // Does ini already exist? If yes, then no need to add it to a scenes.ini etc
672
- bool sceneFileExisted = System::PathExistsCaseSensitive (sceneFilePath.c_str ());
673
- // Create the writer
674
- Writer sceneWriter (sceneFilePath.c_str (), false );
675
- sceneWriter.NewProperty (" AddScene" );
676
- // Write the scene out to the new ini
677
- sceneWriter << g_SceneMan.GetScene ();
678
- return m_HasEverBeenSaved = true ;
679
- }
680
- else
681
- {
682
- // Gotto ask if we can overwrite the existing scene
683
- m_PreviousMode = EditorActivity::SAVEDIALOG;
684
- m_EditorMode = EditorActivity::OVERWRITEDIALOG;
685
- m_ModeChange = true ;
686
- }
659
+ std::string dataModuleFullPath = g_PresetMan.GetFullModulePath (dataModuleName);
660
+ std::string sceneSavePath;
661
+ std::string previewSavePath;
662
+
663
+ if (savingToUserScenesModule) {
664
+ sceneSavePath = dataModuleFullPath + " /" + saveAsName + " .ini" ;
665
+ previewSavePath = dataModuleFullPath + " /" + saveAsName + " .preview.png" ;
666
+ } else {
667
+ sceneSavePath = dataModuleFullPath + " /Scenes/" + saveAsName + " .ini" ;
668
+ previewSavePath = dataModuleFullPath + " /Scenes/" + saveAsName + " .preview.png" ;
687
669
}
688
- else
689
- {
690
- // Try to save to the data module
691
- std::string sceneFilePath (g_PresetMan.GetDataModule (m_ModuleSpaceID)->GetFileName () + " /Scenes/" + saveAsName + " .ini" );
692
- std::string previewFilePath (g_PresetMan.GetDataModule (m_ModuleSpaceID)->GetFileName () + " /Scenes/" + saveAsName + " .preview.png" );
693
- if (g_PresetMan.AddEntityPreset (g_SceneMan.GetScene (), m_ModuleSpaceID, forceOverwrite, sceneFilePath))
694
- {
695
- // Save preview
696
- g_SceneMan.GetScene ()->SavePreview (previewFilePath);
697
-
698
- // Does ini already exist? If yes, then no need to add it to a scenes.ini etc
699
- bool sceneFileExisted = System::PathExistsCaseSensitive (sceneFilePath.c_str ());
700
- // Create the writer
701
- Writer sceneWriter (sceneFilePath.c_str (), false );
702
- sceneWriter.NewProperty (" AddScene" );
703
- // TODO: Check if the ini file already exists, and then ask if overwrite
704
- // Write the scene out to the new ini
705
- sceneWriter << g_SceneMan.GetScene ();
706
-
707
- if (!sceneFileExisted)
708
- {
709
- // First find/create a .rte/Scenes.ini file to include the new .ini into
710
- std::string scenesFilePath (g_PresetMan.GetDataModule (m_ModuleSpaceID)->GetFileName () + " /Scenes.ini" );
711
- bool scenesFileExisted = System::PathExistsCaseSensitive (scenesFilePath.c_str ());
712
- Writer scenesWriter (scenesFilePath.c_str (), true );
713
- scenesWriter.NewProperty (" \n IncludeFile" );
714
- scenesWriter << sceneFilePath;
715
-
716
- // Also add a line to the end of the modules' Index.ini to include the newly created Scenes.ini next startup
717
- // If it's already included, it doens't matter, the definitions will just bounce the second time
718
- if (!scenesFileExisted)
719
- {
720
- std::string indexFilePath (g_PresetMan.GetDataModule (m_ModuleSpaceID)->GetFileName () + " /Index.ini" );
721
- Writer indexWriter (indexFilePath.c_str (), true );
722
- // Add extra tab since the DataModule has everything indented
723
- indexWriter.NewProperty (" \t IncludeFile" );
724
- indexWriter << scenesFilePath;
725
- }
726
- }
727
- return m_HasEverBeenSaved = true ;
728
- }
729
- else
730
- {
731
- // Gotto ask if we can overwrite the existing scene
732
- m_PreviousMode = EditorActivity::SAVEDIALOG;
733
- m_EditorMode = EditorActivity::OVERWRITEDIALOG;
734
- m_ModeChange = true ;
670
+
671
+ if (g_PresetMan.AddEntityPreset (editedScene, m_ModuleSpaceID, forceOverwrite, sceneSavePath)) {
672
+ if (Writer sceneWriter (sceneSavePath, false ); !sceneWriter.WriterOK ()) {
673
+ RTEError::ShowMessageBox (" Failed to create Writer to path:\n\n " + sceneSavePath + " !\n\n THE EDITED SCENE PRESET WAS NOT SAVED!!!" );
674
+ } else {
675
+ // TODO: Check if the ini file already exists, and then ask if overwrite.
676
+ sceneWriter.NewPropertyWithValue (" AddScene" , editedScene);
677
+ sceneWriter.EndWrite ();
678
+
679
+ editedScene->SavePreview (previewSavePath);
680
+ m_HasEverBeenSaved = true ;
681
+
682
+ if (!savingToUserScenesModule) {
683
+ // First find/create a Scenes.ini file to include the new .ini into.
684
+ std::string scenesFilePath (dataModuleFullPath + " /Scenes.ini" );
685
+ bool scenesFileExists = System::PathExistsCaseSensitive (scenesFilePath);
686
+
687
+ if (Writer scenesFileWriter (scenesFilePath, true ); !scenesFileWriter.WriterOK ()) {
688
+ 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!" );
689
+ } else {
690
+ scenesFileWriter.NewPropertyWithValue (" IncludeFile" , sceneSavePath);
691
+ scenesFileWriter.EndWrite ();
692
+
693
+ // Append to the end of the modules' Index.ini to include the newly created Scenes.ini next startup.
694
+ // If it's somehow already included without actually existing, it doesn't matter, the definitions will just bounce the second time.
695
+ if (!scenesFileExists) {
696
+ std::string indexFilePath = dataModuleFullPath + " /Index.ini" ;
697
+
698
+ if (Writer indexWriter (indexFilePath, true ); !indexWriter.WriterOK ()) {
699
+ 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!" );
700
+ } else {
701
+ // Add extra tab since the DataModule has everything indented.
702
+ indexWriter.NewProperty (" \t IncludeFile" );
703
+ indexWriter << scenesFilePath;
704
+ indexWriter.EndWrite ();
705
+ }
706
+ }
707
+ }
708
+ }
709
+ return true ;
735
710
}
711
+ } else {
712
+ // Got to ask if we can overwrite the existing preset.
713
+ m_PreviousMode = EditorMode::SAVEDIALOG;
714
+ m_EditorMode = EditorMode::OVERWRITEDIALOG;
715
+ m_ModeChange = true ;
736
716
}
737
-
738
- return false ;
717
+ return false ;
739
718
}
740
719
741
720
0 commit comments