Commit f1c16ec1 authored by Leeor Dicker's avatar Leeor Dicker

Refactored some of the layer edit code to something more readable.

parent 87979a90
......@@ -19,6 +19,7 @@ SDL_Surface* MINI_MAP_SURFACE = NULL; // UGLY HACK!
std::map<EditState, string> StateStringMap; /**< EditState string table. */
std::map<int, EditState> StateIntMap; /**< EditState int table. */
std::map<EditState, Cell::TileLayer> StateToLayer; /**< Translation table between a specific edit state and tile layer. */
EditorState::EditorState(const string& mapPath): mMousePointer(Utility<Configuration>::get().option(CONFIG_UI_MOUSE_POINTER_IMAGE)),
......@@ -78,7 +79,7 @@ void EditorState::initialize()
initUi();
// Fill tables
fillEditStateStringTable();
fillTables();
// Hook up event handlers
Utility<EventHandler>::get().keyUp().Connect(this, &EditorState::onKeyUp);
......@@ -140,6 +141,13 @@ void EditorState::initUi()
}
void EditorState::fillTables()
{
fillEditStateStringTable();
fillStateToLayerTable();
}
/**
* Fills a table with Ints and maps them to EditStates.
*/
......@@ -154,6 +162,17 @@ void EditorState::fillEditStateStringTable()
}
/**
* Fills a table to use as an easy translation from layer edit state to cell layer.
*/
void EditorState::fillStateToLayerTable()
{
StateToLayer[STATE_BASE_TILE_INDEX] = Cell::LAYER_BASE;
StateToLayer[STATE_BASE_DETAIL_TILE_INDEX] = Cell::LAYER_BASE_DETAIL;
StateToLayer[STATE_DETAIL_TILE_INDEX] = Cell::LAYER_DETAIL;
StateToLayer[STATE_FOREGROUND_TILE_INDEX] = Cell::LAYER_FOREGROUND;
}
/**
* Handler link okay button click.
*
......@@ -753,39 +772,14 @@ void EditorState::handleMiddleButtonDown()
*/
void EditorState::changeTileTexture()
{
switch(mEditState)
{
case STATE_BASE_TILE_INDEX:
if(mTilePalette.patternFill())
patternFill(Cell::LAYER_BASE);
else
patternStamp(Cell::LAYER_BASE);
break;
auto it = StateToLayer.find(mEditState);
case STATE_BASE_DETAIL_TILE_INDEX:
if(mTilePalette.patternFill())
patternFill(Cell::LAYER_BASE_DETAIL);
else
patternStamp(Cell::LAYER_BASE_DETAIL);
break;
case STATE_DETAIL_TILE_INDEX:
if(mTilePalette.patternFill())
patternFill(Cell::LAYER_DETAIL);
else
patternStamp(Cell::LAYER_DETAIL);
break;
if (it == StateToLayer.end())
throw Exception(0, "Bad State", "EditorState::changeTileTExture() called with an invalid state.");
case STATE_FOREGROUND_TILE_INDEX:
if(mTilePalette.patternFill())
patternFill(Cell::LAYER_FOREGROUND);
else
patternStamp(Cell::LAYER_FOREGROUND);
break;
if (mTilePalette.patternFill()) patternFill(StateToLayer[mEditState]);
else patternStamp(StateToLayer[mEditState]);
default:
break;
}
}
......@@ -832,7 +826,6 @@ void EditorState::patternStamp(Cell::TileLayer layer)
}
/**
* Changes the edit mode and unhides the tile palette.
*/
......
......@@ -65,7 +65,9 @@ private:
EditorState(); // Explicitly undefined
void fillTables();
void fillEditStateStringTable();
void fillStateToLayerTable();
void initUi();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment