This commit is contained in:
mfeemster
2015-05-15 18:45:15 -07:00
parent e005b4c20e
commit 2561708ae0
14 changed files with 463 additions and 152 deletions

View File

@ -231,6 +231,10 @@ public:
if (ember.UseFinalXform())
os << ToString(*ember.NonConstFinalXform(), ember.XformCount(), true, false);//Final, don't do motion.
//Note that only embedded palettes are saved. The old style of specifying a palette index to look up in a default palette file
//is no longer supported, as it makes no sense when using multiple palette files. The only way it could work is if the index was
//always meant to refer to the default file, or if the filename was embedded as well. It's easier, more straightforward and
//less error prone to just embed the palette.
if (hexPalette)
{
os << " <palette count=\"256\" format=\"RGB\">\n";

View File

@ -145,6 +145,7 @@ public:
{
m_Index = palette.m_Index;
m_Name = palette.m_Name;
m_Filename = palette.m_Filename;
CopyVec(m_Entries, palette.m_Entries);
return *this;
@ -204,6 +205,7 @@ public:
{
palette.m_Index = m_Index;
palette.m_Name = m_Name;
palette.m_Filename = m_Filename;
palette.m_Entries.resize(Size());
for (uint i = 0; i < Size(); i++)
@ -263,6 +265,7 @@ public:
}
palette.m_Name = m_Name;
palette.m_Filename = m_Filename;
}
else
{
@ -340,6 +343,7 @@ public:
{
palette.m_Index = m_Index;
palette.m_Name = m_Name;
palette.m_Filename = m_Filename;
if (palette.Size() != Size())
palette.m_Entries.resize(Size());
@ -574,6 +578,7 @@ public:
int m_Index;//Index in the xml palette file of this palette, use -1 for random.
string m_Name;//Name of this palette.
string m_Filename;//Name of the parent file this palette came from, can be empty.
vector<v4T> m_Entries;//Storage for the color values.
};
}

View File

@ -55,7 +55,7 @@ public:
palettes.clear();
palettes.reserve(buf.size() / 2048);//Roughly what it takes per palette.
ParsePalettes(rootNode, palettes);
ParsePalettes(rootNode, filename, palettes);
xmlFreeDoc(doc);
added = true;
}
@ -81,6 +81,7 @@ public:
auto p = m_Palettes.begin();
int i = 0, paletteFileIndex = QTIsaac<ISAAC_SIZE, ISAAC_INT>::GlobalRand->Rand() % Size();
//Move p forward i elements.
while (i < paletteFileIndex && p != m_Palettes.end())
{
++i;
@ -218,13 +219,14 @@ public:
private:
/// <summary>
/// Parses an Xml node for all palettes present and store in the passed in palette vector.
/// Parses an Xml node for all palettes present and stores them in the passed in palette vector.
/// Note that although the Xml color values are expected to be 0-255, they are converted and
/// stored as normalized colors, with values from 0-1.
/// </summary>
/// <param name="node">The parent note of all palettes in the Xml file.</param>
/// <param name="filename">The name of the Xml file.</param>
/// <param name="palettes">The vector to store the paresed palettes associated with this file in.</param>
void ParsePalettes(xmlNode* node, vector<Palette<T>>& palettes)
void ParsePalettes(xmlNode* node, const string& filename, vector<Palette<T>>& palettes)
{
bool hexError = false;
char* val;
@ -287,12 +289,13 @@ private:
if (!hexError)
{
palette.m_Filename = filename;
palettes.push_back(palette);
}
}
else
{
ParsePalettes(node->children, palettes);
ParsePalettes(node->children, filename, palettes);
}
node = node->next;