Skip to content

Commit 6e36aa9

Browse files
committed
Little more cleanup to (pretend to) save to our savegame .rte instead of the default "Mods/"
1 parent 7918fcc commit 6e36aa9

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

Source/Entities/SceneLayer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ namespace RTE {
7676
/// @return Whether this SceneLayer's bitmap data was loaded from a file or not.
7777
virtual bool IsLoadedFromDisk() const { return !m_BitmapFile.GetDataPath().empty(); }
7878

79-
/// Override's this SceneLayer's datapath. Used for saved games
80-
/// @param dataPath The new datapath to override this SceneLayer to use.
81-
void OverrideDataPath(const std::string& dataPath) { m_BitmapFile.SetDataPath(dataPath); }
79+
/// Gets this SceneLayer's ContentFile. Used for saved games
80+
/// @return This SceneLayer's ContentFile.
81+
ContentFile& GetContentFile() { return m_BitmapFile; }
8282

8383
/// Loads previously specified/created data into memory from an existing BITMAP. Has to be done before using this SceneLayer if the bitmap was not generated at runtime.
8484
/// @param bitmap Pointer to the bitmap to take. Takes ownership!

Source/Managers/ActivityMan.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,11 @@ bool ActivityMan::SaveCurrentGame(const std::string& fileName) {
100100
modifiableScene->GetTerrain()->SetPresetName(fileName);
101101
modifiableScene->GetTerrain()->MigrateToModule(g_PresetMan.GetModuleID(c_UserScriptedSavesModuleName));
102102

103-
modifiableScene->GetTerrain()->OverrideDataPath("Save Mat.png");
104-
modifiableScene->GetTerrain()->GetFGSceneLayer()->OverrideDataPath("Save FG.png");
105-
modifiableScene->GetTerrain()->GetBGSceneLayer()->OverrideDataPath("Save BG.png");
103+
// See our content files to point to our save game location. This won't actually save a file here- but it allows us to set these up as in-memory ContentFiles on load
104+
// Meaning that our loading code doesn't need to care about whether it's loading a savegame or a file- it just sees it as an already loaded, cached bitmap
105+
modifiableScene->GetTerrain()->GetContentFile().SetDataPath(g_PresetMan.GetModuleID(c_UserScriptedSavesModuleName) + "/Save Mat.png");
106+
modifiableScene->GetTerrain()->GetFGSceneLayer()->GetContentFile().SetDataPath(g_PresetMan.GetModuleID(c_UserScriptedSavesModuleName) + "/Save FG.png");
107+
modifiableScene->GetTerrain()->GetBGSceneLayer()->GetContentFile().SetDataPath(g_PresetMan.GetModuleID(c_UserScriptedSavesModuleName) + "/Save BG.png");
106108

107109
std::unique_ptr<std::stringstream> iniStream = std::make_unique<std::stringstream>();
108110

@@ -293,20 +295,20 @@ bool ActivityMan::LoadAndLaunchGame(const std::string& fileName) {
293295
get_palette(palette);
294296

295297
unzipFileIntoBuffer("Save Mat.png");
296-
ContentFile::ManuallyLoadDataBitmap(filePath + "/Save Mat.png", loadMemPngIntoBitmap(buffer, info.uncompressed_size));
298+
ContentFile::ManuallyLoadDataBitmap(g_PresetMan.GetFullModulePath(c_UserScriptedSavesModuleName) + "/Save Mat.png", loadMemPngIntoBitmap(buffer, info.uncompressed_size));
297299
free(buffer);
298300

299301
unzipFileIntoBuffer("Save FG.png");
300-
ContentFile::ManuallyLoadDataBitmap(filePath + "/Save FG.png", loadMemPngIntoBitmap(buffer, info.uncompressed_size));
302+
ContentFile::ManuallyLoadDataBitmap(g_PresetMan.GetFullModulePath(c_UserScriptedSavesModuleName) + "/Save FG.png", loadMemPngIntoBitmap(buffer, info.uncompressed_size));
301303
free(buffer);
302304

303305
unzipFileIntoBuffer("Save BG.png");
304-
ContentFile::ManuallyLoadDataBitmap(filePath + "/Save BG.png", loadMemPngIntoBitmap(buffer, info.uncompressed_size));
306+
ContentFile::ManuallyLoadDataBitmap(g_PresetMan.GetFullModulePath(c_UserScriptedSavesModuleName) + "/Save BG.png", loadMemPngIntoBitmap(buffer, info.uncompressed_size));
305307
free(buffer);
306308

307309
for (int i = 0; i < numberOfTeams; ++i) {
308310
unzipFileIntoBuffer(std::format("Save UST%i.png", i));
309-
ContentFile::ManuallyLoadDataBitmap(filePath + std::format("/Save UST%i", i), loadMemPngIntoBitmap(buffer, info.uncompressed_size));
311+
ContentFile::ManuallyLoadDataBitmap(g_PresetMan.GetFullModulePath(c_UserScriptedSavesModuleName) + std::format("/Save UST%i", i), loadMemPngIntoBitmap(buffer, info.uncompressed_size));
310312
free(buffer);
311313
}
312314

@@ -323,11 +325,11 @@ bool ActivityMan::LoadAndLaunchGame(const std::string& fileName) {
323325
g_SceneMan.SetSceneToLoad(originalScenePresetName, placeObjectsIfSceneIsRestarted, placeUnitsIfSceneIsRestarted);
324326

325327
// Clear out the cache, we don't need it anymore (and don't want a cache reload to look for this file thinking it really exists)
326-
ContentFile::ManuallyClearDataBitmap(filePath + "/Save Mat.png");
327-
ContentFile::ManuallyClearDataBitmap(filePath + "/Save FG.png");
328-
ContentFile::ManuallyClearDataBitmap(filePath + "/Save BG.png");
328+
ContentFile::ManuallyClearDataBitmap(g_PresetMan.GetFullModulePath(c_UserScriptedSavesModuleName) + "/Save Mat.png");
329+
ContentFile::ManuallyClearDataBitmap(g_PresetMan.GetFullModulePath(c_UserScriptedSavesModuleName) + "/Save FG.png");
330+
ContentFile::ManuallyClearDataBitmap(g_PresetMan.GetFullModulePath(c_UserScriptedSavesModuleName) + "/Save BG.png");
329331
for (int i = 0; i < numberOfTeams; ++i) {
330-
ContentFile::ManuallyClearDataBitmap(filePath + std::format("/Save UST%i.png", i));
332+
ContentFile::ManuallyClearDataBitmap(g_PresetMan.GetFullModulePath(c_UserScriptedSavesModuleName) + std::format("/Save UST%i.png", i));
331333
}
332334

333335
g_ConsoleMan.PrintString("SYSTEM: Game \"" + fileName + "\" loaded!");

0 commit comments

Comments
 (0)