Skip to content

Commit

Permalink
BugFix: Restore ability to create area name entry without a TArea ins…
Browse files Browse the repository at this point in the history
…tance

Before some recent changes it was possible to create a new area name entry
with TLuaInterpreter::setAreaName(...) by supplying an unused area ID and
a name so that it was stored in TRoomDB::areaNamesMap WITHOUT an actual
TArea instance to pair it with.  This fix restores that mode of operation
and the ability to DELETE such an orphan area name which had also been
removed by either the same series of commits or some other recent one that
neglected to continue to provide the latter.

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
  • Loading branch information
SlySven committed Jun 27, 2015
1 parent 384cc19 commit 4d82ea2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/TLuaInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6608,7 +6608,7 @@ int TLuaInterpreter::setCustomEnvColor( lua_State *L )

int TLuaInterpreter::setAreaName( lua_State *L )
{
int id;
int id = -1;
QString existingName;
QString newName;
Host * pHost = TLuaInterpreter::luaInterpreterMap[L];
Expand All @@ -6633,12 +6633,16 @@ int TLuaInterpreter::setAreaName( lua_State *L )
.arg( id ).toUtf8().constData() );
return 2;
}
else if( ! pHost->mpMap->mpRoomDB->getAreaIDList().contains( id ) ) {
lua_pushnil( L );
lua_pushstring( L, tr( "setAreaName: bad argument #1 value (area Id=%1 does not exist)." )
.arg( id ).toUtf8().constData() );
return 2;
}
// Strangely, previous code allowed this command to create a NEW area's name
// with this ID, but without a TArea instance to accompany it (the latter was/is
// instantiated as needed when a room is moved to the relevent area...) and we
// need to continue to allow this - Slysven
// else if( ! pHost->mpMap->mpRoomDB->getAreaIDList().contains( id ) ) {
// lua_pushnil( L );
// lua_pushstring( L, tr( "setAreaName: bad argument #1 value (area Id=%1 does not exist)." )
// .arg( id ).toUtf8().constData() );
// return 2;
// }
}
else if( lua_isstring( L, 1 ) ) {
existingName = QString::fromUtf8( lua_tostring( L, 1 ) );
Expand Down Expand Up @@ -6702,10 +6706,11 @@ int TLuaInterpreter::setAreaName( lua_State *L )

bool isCurrentAreaRenamed = false;
if( pHost->mpMap->mpMapper ) {
if( pHost->mpMap->mpRoomDB->getAreaNamesMap().value( id ) == pHost->mpMap->mpMapper->showArea->currentText() ) {
if( id > 0 && pHost->mpMap->mpRoomDB->getAreaNamesMap().value( id ) == pHost->mpMap->mpMapper->showArea->currentText() ) {
isCurrentAreaRenamed = true;
}
}

bool result = pHost->mpMap->mpRoomDB->setAreaName( id, newName );
if( result ) {
// Update mapper Area names widget, using method designed for it...!
Expand Down Expand Up @@ -6858,7 +6863,8 @@ int TLuaInterpreter::deleteArea( lua_State *L )
.arg( id ).toUtf8().constData() );
return 2;
}
else if( ! pHost->mpMap->mpRoomDB->getAreaIDList().contains( id ) ) {
else if( ! pHost->mpMap->mpRoomDB->getAreaIDList().contains( id )
&& ! pHost->mpMap->mpRoomDB->getAreaNamesMap().contains( id ) ) {
lua_pushnil( L );
lua_pushstring( L, tr( "deleteArea: bad argument #1 value (area Id=%1 does not exist)." )
.arg( id ).toUtf8().constData() );
Expand Down
9 changes: 9 additions & 0 deletions src/TRoomDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ bool TRoomDB::removeArea( int id )
mpMap->mMapGraphNeedsUpdate = true;
return true;
}
else if( areaNamesMap.contains( id ) ) {
// Handle corner case where the area name was created but not used
areaNamesMap.remove( id );
return true;
}
return false;
}

Expand Down Expand Up @@ -279,6 +284,10 @@ bool TRoomDB::setAreaName( int areaID, QString name )
}
}
areaNamesMap[areaID] = name;
// This creates a NEW area name with given areaID if the ID was not
// previously used - but the TArea only gets created if the user manually
// creates it with TLuaInterpreter::addArea(areaId), OR moves a room to the
// area with either a Lua command or GUI action.
return true;
}

Expand Down

0 comments on commit 4d82ea2

Please sign in to comment.