Make the previous commit work with mod elements too
For this to work, loading code needed to stop trusting DEFAULT_PT_ identifiers, which it trusted because there have been some identifier changes between vanilla releases. I dug these up and listed them explicitly; they are now taken into account as needed when loading old enough saves.
This commit is contained in:
parent
36800a76cd
commit
73be29aa61
@ -4,6 +4,7 @@
|
|||||||
#include "simulation/Simulation.h"
|
#include "simulation/Simulation.h"
|
||||||
#include "simulation/ElementClasses.h"
|
#include "simulation/ElementClasses.h"
|
||||||
#include "common/tpt-compat.h"
|
#include "common/tpt-compat.h"
|
||||||
|
#include "common/Version.h"
|
||||||
#include "bson/BSON.h"
|
#include "bson/BSON.h"
|
||||||
#include "graphics/Renderer.h"
|
#include "graphics/Renderer.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
@ -641,6 +642,25 @@ void GameSave::readOPS(const std::vector<char> &data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto paletteRemap = [this, saveVersion = Version(majorVersion, minorVersion)](auto maxVersion, ByteString from, ByteString to) {
|
||||||
|
if (saveVersion <= maxVersion)
|
||||||
|
{
|
||||||
|
auto it = std::find_if(palette.begin(), palette.end(), [&from](auto &item) {
|
||||||
|
return item.first == from;
|
||||||
|
});
|
||||||
|
if (it != palette.end())
|
||||||
|
{
|
||||||
|
it->first = to;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
paletteRemap(Version(87, 1), "DEFAULT_PT_TUGN", "DEFAULT_PT_TUNG");
|
||||||
|
paletteRemap(Version(90, 1), "DEFAULT_PT_REPL", "DEFAULT_PT_RPEL");
|
||||||
|
paletteRemap(Version(92, 0), "DEFAULT_PT_E180", "DEFAULT_PT_HEAC");
|
||||||
|
paletteRemap(Version(92, 0), "DEFAULT_PT_E181", "DEFAULT_PT_SAWD");
|
||||||
|
paletteRemap(Version(92, 0), "DEFAULT_PT_E182", "DEFAULT_PT_POLO");
|
||||||
|
paletteRemap(Version(93, 3), "DEFAULT_PT_RAYT", "DEFAULT_PT_LDTC");
|
||||||
|
|
||||||
//Read wall and fan data
|
//Read wall and fan data
|
||||||
if(wallData)
|
if(wallData)
|
||||||
{
|
{
|
||||||
|
32
src/common/Version.h
Normal file
32
src/common/Version.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <array>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
template<size_t ComponentCount>
|
||||||
|
struct Version
|
||||||
|
{
|
||||||
|
std::array<size_t, ComponentCount> components;
|
||||||
|
|
||||||
|
template<class ...Args>
|
||||||
|
constexpr Version(Args ...args) : components{ size_t(args)... }
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr bool operator <(const Version &other) const
|
||||||
|
{
|
||||||
|
return std::lexicographical_compare(components.begin(), components.end(), other.components.begin(), other.components.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr bool operator ==(const Version &other) const
|
||||||
|
{
|
||||||
|
return std::equal(components.begin(), components.end(), other.components.begin(), other.components.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr bool operator <=(const Version &other) const
|
||||||
|
{
|
||||||
|
return *this < other || *this == other;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class ...Args>
|
||||||
|
Version(Args ...args) -> Version<sizeof...(Args)>;
|
@ -32,6 +32,10 @@ std::vector<ByteString> Simulation::Load(const GameSave *save, bool includePress
|
|||||||
}
|
}
|
||||||
if(save->palette.size())
|
if(save->palette.size())
|
||||||
{
|
{
|
||||||
|
for(int i = 0; i < PT_NUM; i++)
|
||||||
|
{
|
||||||
|
partMap[i] = 0;
|
||||||
|
}
|
||||||
for(auto &pi : save->palette)
|
for(auto &pi : save->palette)
|
||||||
{
|
{
|
||||||
if (pi.second > 0 && pi.second < PT_NUM)
|
if (pi.second > 0 && pi.second < PT_NUM)
|
||||||
@ -40,19 +44,17 @@ std::vector<ByteString> Simulation::Load(const GameSave *save, bool includePress
|
|||||||
for (int i = 0; i < PT_NUM; i++)
|
for (int i = 0; i < PT_NUM; i++)
|
||||||
{
|
{
|
||||||
if (elements[i].Enabled && elements[i].Identifier == pi.first)
|
if (elements[i].Enabled && elements[i].Identifier == pi.first)
|
||||||
|
{
|
||||||
myId = i;
|
myId = i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// if this is a custom element, set the ID to the ID we found when comparing identifiers in the palette map
|
if (myId)
|
||||||
// set type to 0 if we couldn't find an element with that identifier present when loading,
|
|
||||||
// unless this is a default element, in which case keep the current ID, because otherwise when an element is renamed it wouldn't show up anymore in older saves
|
|
||||||
if (myId != 0)
|
|
||||||
{
|
{
|
||||||
partMap[pi.second] = myId;
|
partMap[pi.second] = myId;
|
||||||
}
|
}
|
||||||
else if (!pi.first.BeginsWith("DEFAULT_PT_"))
|
else
|
||||||
{
|
{
|
||||||
missingElementTypes.push_back(pi.first);
|
missingElementTypes.push_back(pi.first);
|
||||||
partMap[pi.second] = myId;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user