Skip to content

Commit

Permalink
Merge branch 'save_metadata' into 'master'
Browse files Browse the repository at this point in the history
Add additional fields to save metadata

See merge request OpenMW/openmw!3493
  • Loading branch information
psi29a committed Oct 15, 2023
2 parents 03fa273 + fc74cc4 commit febfa35
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
Feature #7499: OpenMW-CS: Generate record filters by drag & dropping cell content to the filters field
Feature #7546: Start the game on Fredas
Feature #7568: Uninterruptable scripted music
Feature #7618: Show the player character's health in the save details
Task #5896: Do not use deprecated MyGUI properties
Task #7113: Move from std::atoi to std::from_char
Task #7117: Replace boost::scoped_array with std::vector
Expand Down
7 changes: 7 additions & 0 deletions apps/openmw/mwgui/savegamedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,10 @@ namespace MWGui

text << Misc::fileTimeToString(mCurrentSlot->mTimeStamp, "%Y.%m.%d %T") << "\n";

if (mCurrentSlot->mProfile.mMaximumHealth > 0)
text << std::fixed << std::setprecision(0) << "#{sHealth} " << mCurrentSlot->mProfile.mCurrentHealth << "/"
<< mCurrentSlot->mProfile.mMaximumHealth << "\n";

text << "#{sLevel} " << mCurrentSlot->mProfile.mPlayerLevel << "\n";
text << "#{sCell=" << mCurrentSlot->mProfile.mPlayerCellName << "}\n";

Expand All @@ -422,6 +426,9 @@ namespace MWGui
if (hour == 0)
hour = 12;

if (mCurrentSlot->mProfile.mCurrentDay > 0)
text << "#{Calendar:day} " << mCurrentSlot->mProfile.mCurrentDay << "\n";

text << mCurrentSlot->mProfile.mInGameTime.mDay << " "
<< MWBase::Environment::get().getWorld()->getTimeManager()->getMonthName(
mCurrentSlot->mProfile.mInGameTime.mMonth)
Expand Down
5 changes: 5 additions & 0 deletions apps/openmw/mwstate/statemanagerimp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,15 @@ void MWState::StateManager::saveGame(std::string_view description, const Slot* s
else
profile.mPlayerClassId = classId;

const MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player);

profile.mPlayerCellName = world.getCellName();
profile.mInGameTime = world.getTimeManager()->getEpochTimeStamp();
profile.mTimePlayed = mTimePlayed;
profile.mDescription = description;
profile.mCurrentDay = world.getTimeManager()->getTimeStamp().getDay();
profile.mCurrentHealth = stats.getHealth().getCurrent();
profile.mMaximumHealth = stats.getHealth().getModified();

Log(Debug::Info) << "Making a screenshot for saved game '" << description << "'";
writeScreenshot(profile.mScreenshot);
Expand Down
2 changes: 1 addition & 1 deletion components/esm3/formatversion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace ESM
inline constexpr FormatVersion MaxNameIsRefIdOnlyFormatVersion = 25;
inline constexpr FormatVersion MaxUseEsmCellIdFormatVersion = 26;
inline constexpr FormatVersion MaxActiveSpellSlotIndexFormatVersion = 27;
inline constexpr FormatVersion CurrentSaveGameFormatVersion = 28;
inline constexpr FormatVersion CurrentSaveGameFormatVersion = 29;
}

#endif
8 changes: 8 additions & 0 deletions components/esm3/savedgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ namespace ESM
esm.getSubHeader();
mScreenshot.resize(esm.getSubSize());
esm.getExact(mScreenshot.data(), mScreenshot.size());

esm.getHNOT(mCurrentDay, "CDAY");
esm.getHNOT(mCurrentHealth, "CHLT");
esm.getHNOT(mMaximumHealth, "MHLT");
}

void SavedGame::save(ESMWriter& esm) const
Expand All @@ -51,6 +55,10 @@ namespace ESM
esm.startSubRecord("SCRN");
esm.write(mScreenshot.data(), mScreenshot.size());
esm.endRecord("SCRN");

esm.writeHNT("CDAY", mCurrentDay);
esm.writeHNT("CHLT", mCurrentHealth);
esm.writeHNT("MHLT", mMaximumHealth);
}

}
4 changes: 4 additions & 0 deletions components/esm3/savedgame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ namespace ESM
std::string mDescription;
std::vector<char> mScreenshot; // raw jpg-encoded data

int mCurrentDay = 0;
float mCurrentHealth = 0;
float mMaximumHealth = 0;

void load(ESMReader& esm);
void save(ESMWriter& esm) const;
};
Expand Down

0 comments on commit febfa35

Please sign in to comment.