Permalink
Browse files

palette now used for default elements again, with some fixes

palette now used in VIRS, fixes #460
  • Loading branch information...
jacob1 committed Jun 18, 2017
1 parent c1e9126 commit 67b87b1dab9f48a97ba3e175a6986b7d32035268
Showing with 15 additions and 9 deletions.
  1. +15 −8 src/simulation/Simulation.cpp
  2. +0 −1 src/simulation/Simulation.h
@@ -62,16 +62,19 @@ int Simulation::Load(int fullX, int fullY, GameSave * save)
for(std::vector<GameSave::PaletteItem>::iterator iter = save->palette.begin(), end = save->palette.end(); iter != end; ++iter)
{
GameSave::PaletteItem pi = *iter;
//This makes it only apply to lua elements (greater than the default number of elements), because if not it glitches for default elements when they change name
if(pi.second >= DEFAULT_PT_NUM && pi.second < PT_NUM)
if (pi.second > 0 && pi.second < PT_NUM)
{
int myId = 0;//pi.second;
for(int i = 0; i < PT_NUM; i++)
int myId = 0;
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;
}
partMap[pi.second] = myId;
// if this is a custom element, set the ID to the ID we found when comparing identifiers in the palette map
// 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 || pi.first.find("DEFAULT_PT_") != 0)
partMap[pi.second] = myId;
}
}
}
@@ -106,6 +109,11 @@ int Simulation::Load(int fullX, int fullY, GameSave * save)
{
tempPart.tmp = partMap[tempPart.tmp&0xFF] | (tempPart.tmp&~0xFF);
}

This comment has been minimized.

@iczero

iczero Jun 18, 2017

Contributor

WHY CAN'T YOU PR THIS
see #462
that took...... 6 seconds

if (tempPart.type == PT_VIRS || tempPart.type == PT_VRSG || tempPart.type == PT_VRSS)
{
if (tempPart.tmp2 > 0 && tempPart.tmp2 < PT_NUM)
tempPart.tmp2 = partMap[tempPart.tmp2];
}
//Replace existing
if ((r = pmap[y][x]))
@@ -271,7 +279,7 @@ GameSave * Simulation::Save(int fullX, int fullY, int fullX2, int fullY2)
if(storedParts)
{
for(int i = DEFAULT_PT_NUM; i < PT_NUM; i++)
for(int i = 0; i < PT_NUM; i++)
{
if(elements[i].Enabled && elementCount[i])
{
@@ -5320,7 +5328,6 @@ Simulation::Simulation():
free(platentT);
std::vector<Element> elementList = GetElements();
DEFAULT_PT_NUM = elementList.size();
for(int i = 0; i < PT_NUM; i++)
{
if (i < (int)elementList.size())
@@ -113,7 +113,6 @@ class Simulation
int pretty_powder;
int sandcolour;
int sandcolour_frame;
int DEFAULT_PT_NUM;
int Load(GameSave * save);
int Load(int x, int y, GameSave * save);

0 comments on commit 67b87b1

Please sign in to comment.