Skip to content
Permalink
Browse files

Tweak replace mode and specific delete mode (fixes #631)

  • Loading branch information...
LBPHacker committed Mar 30, 2019
1 parent 4cf0fe5 commit 47f898ca5ada23dab99ccbbd7c9ad3e899b77af9
Showing with 91 additions and 35 deletions.
  1. +16 −0 src/gui/game/GameController.cpp
  2. +5 −1 src/gui/game/GameView.cpp
  3. +12 −2 src/lua/LuaScriptInterface.cpp
  4. +58 −32 src/simulation/Simulation.cpp
@@ -1206,6 +1206,22 @@ int GameController::GetReplaceModeFlags()

void GameController::SetReplaceModeFlags(int flags)
{
int old_flags = gameModel->GetSimulation()->replaceModeFlags;
if (!(old_flags & REPLACE_MODE) && (flags & REPLACE_MODE))
{
// if replace mode has just been enabled, disable specific delete
flags &= ~SPECIFIC_DELETE;
}
if (!(old_flags & SPECIFIC_DELETE) && (flags & SPECIFIC_DELETE))
{
// if specific delete has just been enabled, disable replace mode
flags &= ~REPLACE_MODE;
}
if ((flags & SPECIFIC_DELETE) && (flags & REPLACE_MODE))
{
// if both have just been enabled, arbitrarily disable one of them
flags &= ~SPECIFIC_DELETE;
}
gameModel->GetSimulation()->replaceModeFlags = flags;
}

@@ -559,8 +559,12 @@ class GameView::ToolAction: public ui::ButtonAction
else
{
if (v->CtrlBehaviour() && v->AltBehaviour() && !v->ShiftBehaviour())
if (tool->GetIdentifier().BeginsWith("DEFAULT_PT_"))
{
if (tool->GetIdentifier().Contains("_PT_"))
{
sender->SetSelectionState(3);
}
}

if (sender->GetSelectionState() >= 0 && sender->GetSelectionState() <= 3)
v->c->SetActiveTool(sender->GetSelectionState(), tool);
@@ -2581,8 +2581,18 @@ int LuaScriptInterface::elements_allocate(lua_State * l)
group = ByteString(lua_tostring(l, 1)).ToUpper();
id = ByteString(lua_tostring(l, 2)).ToUpper();

if(group == "DEFAULT")
return luaL_error(l, "You cannot create elements in the 'default' group.");
if (id.Contains("_"))
{
return luaL_error(l, "The element name may not contain '_'.");
}
if (group.Contains("_"))
{
return luaL_error(l, "The group name may not contain '_'.");
}
if (group == "DEFAULT")
{
return luaL_error(l, "You cannot create elements in the 'DEFAULT' group.");
}

identifier = group + "_PT_" + id;

@@ -1601,38 +1601,6 @@ int Simulation::CreateParts(int x, int y, int rx, int ry, int c, int flags)
return !created;
}

int Simulation::CreatePartFlags(int x, int y, int c, int flags)
{
//delete
if (c == 0 && !(flags&REPLACE_MODE))
delete_part(x, y);
//specific delete
else if ((flags&SPECIFIC_DELETE) && !(flags&REPLACE_MODE))
{
if (!replaceModeSelected || TYP(pmap[y][x]) == replaceModeSelected || TYP(photons[y][x]) == replaceModeSelected)
delete_part(x, y);
}
//replace mode
else if (flags&REPLACE_MODE)
{
if (x<0 || y<0 || x>=XRES || y>=YRES)
return 0;
if (replaceModeSelected && TYP(pmap[y][x]) != replaceModeSelected && TYP(photons[y][x]) != replaceModeSelected)
return 0;
if ((pmap[y][x]))
{
delete_part(x, y);
if (c!=0)
create_part(-2, x, y, TYP(c), ID(c));
}
}
//normal draw
else
if (create_part(-2, x, y, TYP(c), ID(c)) == -1)
return 1;
return 0;
}

void Simulation::CreateLine(int x1, int y1, int x2, int y2, int c, Brush * cBrush, int flags)
{
int x, y, dx, dy, sy, rx = cBrush->GetRadius().X, ry = cBrush->GetRadius().Y;
@@ -1686,6 +1654,64 @@ void Simulation::CreateLine(int x1, int y1, int x2, int y2, int c, Brush * cBrus
}
}

int Simulation::CreatePartFlags(int x, int y, int c, int flags)
{
if (x < 0 || y < 0 || x >= XRES || y >= YRES)
{
return 0;
}

if (flags & REPLACE_MODE)
{
// if replace whatever and there's something to replace
// or replace X and there's a non-energy particle on top with type X
// or replace X and there's an energy particle on top with type X
if ((!replaceModeSelected && (photons[y][x] || pmap[y][x])) ||
(!photons[y][x] && pmap[y][x] && TYP(pmap[y][x]) == replaceModeSelected) ||
(photons[y][x] && TYP(photons[y][x]) == replaceModeSelected))
{
if (c)
{
part_change_type(photons[y][x] ? ID(photons[y][x]) : ID(pmap[y][x]), x, y, TYP(c));
}
else
{
delete_part(x, y);
}
}
return 0;
}
else if (!c)
{
delete_part(x, y);
return 0;
}
else if (flags & SPECIFIC_DELETE)
{
// if delete whatever and there's something to delete
// or delete X and there's a non-energy particle on top with type X
// or delete X and there's an energy particle on top with type X
if ((!replaceModeSelected && (photons[y][x] || pmap[y][x])) ||
(!photons[y][x] && pmap[y][x] && TYP(pmap[y][x]) == replaceModeSelected) ||
(photons[y][x] && TYP(photons[y][x]) == replaceModeSelected))
{
delete_part(x, y);
}
return 0;
}
else
{
if (create_part(-2, x, y, TYP(c), ID(c)) == -1)
{
return 1;
}
return 0;
}

// I'm sure at least one compiler exists that would complain if this wasn't here
return 0;
}

//Now simply creates a 0 pixel radius line without all the complicated flags / other checks
void Simulation::CreateLine(int x1, int y1, int x2, int y2, int c)
{

0 comments on commit 47f898c

Please sign in to comment.
You can’t perform that action at this time.