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

Commit ae7df49

Browse files
committed
Fix GibEditor failing to save and refactor to save only relevant data
1 parent 3fbead9 commit ae7df49

File tree

3 files changed

+66
-95
lines changed

3 files changed

+66
-95
lines changed

Activities/GibEditor.cpp

Lines changed: 57 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -703,93 +703,69 @@ void GibEditor::Draw(BITMAP *pTargetBitmap, const Vector &targetPos)
703703
EditorActivity::Draw(pTargetBitmap, targetPos);
704704
}
705705

706+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
706707

707-
//////////////////////////////////////////////////////////////////////////////////////////
708-
// Method: SaveObject
709-
//////////////////////////////////////////////////////////////////////////////////////////
710-
// Description: Saves the current object to an appropriate ini file, and asks user if
711-
// they want to overwrite first if object of this name exists.
712-
713-
bool GibEditor::SaveObject(std::string saveAsName, bool forceOverwrite)
714-
{
715-
if (!m_pEditedObject)
716-
return false;
717-
718-
// Set the name of the current object in effect
719-
m_pEditedObject->SetPresetName(saveAsName);
720-
721-
// Replace the gibs of the object with the proxies that have been edited in the gui
722-
StuffEditedGibs(m_pEditedObject);
708+
bool GibEditor::SaveObject(const std::string &saveAsName, bool forceOverwrite) {
709+
if (!m_pEditedObject) {
710+
return false;
711+
}
712+
m_pEditedObject->SetPresetName(saveAsName);
723713

724-
// TODO: do proper overwriting looking at the files etc
725-
// Try to add to the isntance man
726-
std::string objectFilePath(g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName() + "/NewData/" + saveAsName + ".ini");
714+
// Replace the gibs of the object with the proxies that have been edited in the GUI.
715+
StuffEditedGibs(m_pEditedObject);
727716

728-
// Check if file exists
729-
bool newDataFileExisted = System::PathExistsCaseSensitive(objectFilePath.c_str());
717+
std::string dataModuleName = g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName();
718+
std::string dataModuleFullPath = g_PresetMan.GetFullModulePath(dataModuleName);
719+
std::string newDataDir = dataModuleFullPath + "/NewData";
720+
std::string objectSavePath = newDataDir + "/" + saveAsName + ".ini";
730721

731-
// Try to create NewData directory if file does not exist
732-
if (!newDataFileExisted)
733-
{
734-
System::MakeDirectory(g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName() + "/NewData");
722+
if (!System::PathExistsCaseSensitive(newDataDir) && !System::MakeDirectory(newDataDir)) {
723+
RTEError::ShowMessageBox("Failed to create NewData directory in:\n\n" + dataModuleFullPath + "\n\nTHE EDITED OBJECT PRESET WAS NOT SAVED!!!");
724+
return false;
735725
}
736726

737-
if (g_PresetMan.AddEntityPreset(m_pEditedObject, m_ModuleSpaceID, forceOverwrite, objectFilePath))
738-
// TEMP always overwrite for now until proper save system is in place
739-
// if (g_PresetMan.AddEntityPreset(m_pEditedObject, m_ModuleSpaceID, true))
740-
{
741-
// Does ini already exist? If yes, then no need to add it to a objects.ini etc
742-
bool objectFileExisted = System::PathExistsCaseSensitive(objectFilePath.c_str());
743-
// If the ini file already exists, and then ask if overwrite first
744-
if (objectFileExisted && !forceOverwrite)
745-
{
746-
// Gotto ask if we can overwrite the existing object/file
747-
m_PreviousMode = EditorActivity::SAVEDIALOG;
748-
m_EditorMode = EditorActivity::OVERWRITEDIALOG;
749-
m_ModeChange = true;
750-
return false;
751-
}
752-
// Create the writer
753-
Writer objectWriter(objectFilePath.c_str(), false);
754-
RTEAssert(objectWriter.WriterOK(), "Couldn't open file " + objectFilePath + "to write to! Check if directory exists..?");
755-
objectWriter.NewProperty("AddObject");
756-
// Write the object out to the new ini
757-
m_pEditedObject->MOSRotating::Save(objectWriter);
758-
objectWriter.ObjectEnd();
759-
// TODO: Make system for saving into/over the existing definition read originally from the ini's, wherever it was
760-
/*
761-
if (!objectFileExisted)
762-
{
763-
// First find/create a .rte/Scenes.ini file to include the new .ini into
764-
string objectsFilePath(g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName() + "/Scenes.ini");
765-
bool objectsFileExisted = System::PathExistsCaseSensitive(objectsFilePath.c_str());
766-
Writer objectsWriter(objectsFilePath.c_str(), true);
767-
objectsWriter.NewProperty("\nIncludeFile");
768-
objectsWriter << objectFilePath;
769-
770-
// Also add a line to the end of the modules' Index.ini to include the newly created Scenes.ini next startup
771-
// If it's already included, it doens't matter, the definitions will just bounce the second time
772-
if (!objectsFileExisted)
773-
{
774-
string indexFilePath(g_PresetMan.GetDataModule(m_ModuleSpaceID)->GetFileName() + "/Index.ini");
775-
Writer indexWriter(indexFilePath.c_str(), true);
776-
// Add extra tab since the DataModule has everything indented
777-
indexWriter.NewProperty("\tIncludeFile");
778-
indexWriter << objectsFilePath;
779-
}
780-
}
781-
*/
782-
return m_HasEverBeenSaved = true;
783-
}
784-
else
785-
{
786-
// Gotto ask if we can overwrite the existing object
787-
m_PreviousMode = EditorActivity::SAVEDIALOG;
788-
m_EditorMode = EditorActivity::OVERWRITEDIALOG;
789-
m_ModeChange = true;
790-
}
791-
792-
return false;
727+
// Force overwrite the stored preset so we aren't prompted to every time for every preset. This doesn't screw with the original ini because there's no system for that in place
728+
// and doesn't actually get loaded on the next game start either, so any changes will be discarded at the end of the current runtime.
729+
if (g_PresetMan.AddEntityPreset(m_pEditedObject, m_ModuleSpaceID, true, objectSavePath)) {
730+
// Show the overwrite dialog only when actually overwriting a saved ini in NewData or forcing an overwrite.
731+
if (!System::PathExistsCaseSensitive(objectSavePath) || forceOverwrite) {
732+
if (Writer objectWriter(objectSavePath, false); !objectWriter.WriterOK()) {
733+
RTEError::ShowMessageBox("Failed to create Writer to path:\n\n" + objectSavePath + "\n\nTHE EDITED OBJECT PRESET WAS NOT SAVED!!!");
734+
} else {
735+
std::string addObjectType;
736+
switch (m_pEditedObject->GetMOType()) {
737+
case MovableObject::MOType::TypeActor:
738+
addObjectType = "AddActor";
739+
break;
740+
case MovableObject::MOType::TypeHeldDevice:
741+
case MovableObject::MOType::TypeThrownDevice:
742+
addObjectType = "AddDevice";
743+
break;
744+
default:
745+
addObjectType = "AddEffect";
746+
}
747+
objectWriter.NewProperty(addObjectType);
748+
m_pEditedObject->Entity::Save(objectWriter);
749+
for (const Gib &gib : *m_pEditedObject->GetGibList()) {
750+
objectWriter.NewPropertyWithValue("AddGib", gib);
751+
}
752+
objectWriter.ObjectEnd();
753+
objectWriter.EndWrite();
754+
755+
m_HasEverBeenSaved = true;
756+
757+
// TODO: Maybe make system for saving into/over the existing definition read originally from the ini's, wherever it was.
758+
759+
return true;
760+
}
761+
} else {
762+
// Got to ask if we can overwrite the existing object.
763+
m_PreviousMode = EditorMode::SAVEDIALOG;
764+
m_EditorMode = EditorMode::OVERWRITEDIALOG;
765+
m_ModeChange = true;
766+
}
767+
}
768+
return false;
793769
}
794770

795771

Activities/GibEditor.h

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -210,19 +210,13 @@ ClassInfoGetters;
210210

211211
protected:
212212

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

227221

228222
//////////////////////////////////////////////////////////////////////////////////////////

Entities/Gib.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ namespace RTE {
7777
// All of this is needed to make a preset look like not original and save as CopyOf instead of separate preset.
7878
std::unique_ptr<Entity> gibEntity(m_GibParticle->Clone());
7979
gibEntity->ResetOriginalPresetFlag();
80-
writer << gibEntity.get();
80+
gibEntity->Entity::Save(writer);
81+
writer.ObjectEnd();
8182

8283
writer.NewProperty("Offset");
8384
writer << m_Offset;

0 commit comments

Comments
 (0)