MCPcopy Create free account
hub / github.com/diasurgical/DevilutionX / LoadHotkeys

Function LoadHotkeys

Source/loadsave.cpp:2186–2226  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2184}
2185
2186void LoadHotkeys()
2187{
2188 LoadHelper file(OpenSaveArchive(gSaveNumber), "hotkeys");
2189 if (!file.IsValid())
2190 return;
2191
2192 Player &myPlayer = *MyPlayer;
2193 size_t nHotkeys = 4; // Defaults to old save format number
2194
2195 // Refill the spell arrays with no selection
2196 std::fill(myPlayer._pSplHotKey, myPlayer._pSplHotKey + NumHotkeys, SpellID::Invalid);
2197 std::fill(myPlayer._pSplTHotKey, myPlayer._pSplTHotKey + NumHotkeys, SpellType::Invalid);
2198
2199 // Checking if the save file has the old format with only 4 hotkeys and no header
2200 if (file.IsValid(HotkeysSize(nHotkeys))) {
2201 // The file contains a header byte and at least 4 entries, so we can assume it's a new format save
2202 nHotkeys = file.NextLE<uint8_t>();
2203 }
2204
2205 // Read all hotkeys in the file
2206 for (size_t i = 0; i < nHotkeys; i++) {
2207 // Do not load hotkeys past the size of the spell types array, discard the rest
2208 if (i < NumHotkeys) {
2209 myPlayer._pSplHotKey[i] = static_cast<SpellID>(file.NextLE<int32_t>());
2210 } else {
2211 file.Skip<int32_t>();
2212 }
2213 }
2214 for (size_t i = 0; i < nHotkeys; i++) {
2215 // Do not load hotkeys past the size of the spells array, discard the rest
2216 if (i < NumHotkeys) {
2217 myPlayer._pSplTHotKey[i] = static_cast<SpellType>(file.NextLE<uint8_t>());
2218 } else {
2219 file.Skip<uint8_t>();
2220 }
2221 }
2222
2223 // Load the selected spell last
2224 myPlayer._pRSpell = static_cast<SpellID>(file.NextLE<int32_t>());
2225 myPlayer._pRSplType = static_cast<SpellType>(file.NextLE<uint8_t>());
2226}
2227
2228void SaveHotkeys(SaveWriter &saveWriter, const Player &player)
2229{

Callers 1

InitPlayerFunction · 0.85

Calls 3

OpenSaveArchiveFunction · 0.85
HotkeysSizeFunction · 0.85
IsValidMethod · 0.45

Tested by

no test coverage detected