Commit f1c16ec1 authored by Leeor Dicker's avatar Leeor Dicker

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

parent 87979a90
...@@ -17,8 +17,9 @@ const float MINI_MAP_Y = 65.0f; ...@@ -17,8 +17,9 @@ const float MINI_MAP_Y = 65.0f;
SDL_Surface* MINI_MAP_SURFACE = NULL; // UGLY HACK! SDL_Surface* MINI_MAP_SURFACE = NULL; // UGLY HACK!
std::map<EditState, string> StateStringMap; /**< EditState string table. */ std::map<EditState, string> StateStringMap; /**< EditState string table. */
std::map<int, EditState> StateIntMap; /**< EditState int 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)), EditorState::EditorState(const string& mapPath): mMousePointer(Utility<Configuration>::get().option(CONFIG_UI_MOUSE_POINTER_IMAGE)),
...@@ -78,7 +79,7 @@ void EditorState::initialize() ...@@ -78,7 +79,7 @@ void EditorState::initialize()
initUi(); initUi();
// Fill tables // Fill tables
fillEditStateStringTable(); fillTables();
// Hook up event handlers // Hook up event handlers
Utility<EventHandler>::get().keyUp().Connect(this, &EditorState::onKeyUp); Utility<EventHandler>::get().keyUp().Connect(this, &EditorState::onKeyUp);
...@@ -140,6 +141,13 @@ void EditorState::initUi() ...@@ -140,6 +141,13 @@ void EditorState::initUi()
} }
void EditorState::fillTables()
{
fillEditStateStringTable();
fillStateToLayerTable();
}
/** /**
* Fills a table with Ints and maps them to EditStates. * Fills a table with Ints and maps them to EditStates.
*/ */
...@@ -154,6 +162,17 @@ void EditorState::fillEditStateStringTable() ...@@ -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. * Handler link okay button click.
* *
...@@ -753,39 +772,14 @@ void EditorState::handleMiddleButtonDown() ...@@ -753,39 +772,14 @@ void EditorState::handleMiddleButtonDown()
*/ */
void EditorState::changeTileTexture() void EditorState::changeTileTexture()
{ {
switch(mEditState) auto it = StateToLayer.find(mEditState);
{
case STATE_BASE_TILE_INDEX:
if(mTilePalette.patternFill())
patternFill(Cell::LAYER_BASE);
else
patternStamp(Cell::LAYER_BASE);
break;
case STATE_BASE_DETAIL_TILE_INDEX: if (it == StateToLayer.end())
if(mTilePalette.patternFill()) throw Exception(0, "Bad State", "EditorState::changeTileTExture() called with an invalid state.");
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;
case STATE_FOREGROUND_TILE_INDEX: if (mTilePalette.patternFill()) patternFill(StateToLayer[mEditState]);
if(mTilePalette.patternFill()) else patternStamp(StateToLayer[mEditState]);
patternFill(Cell::LAYER_FOREGROUND);
else
patternStamp(Cell::LAYER_FOREGROUND);
break;
default:
break;
}
} }
...@@ -832,7 +826,6 @@ void EditorState::patternStamp(Cell::TileLayer layer) ...@@ -832,7 +826,6 @@ void EditorState::patternStamp(Cell::TileLayer layer)
} }
/** /**
* Changes the edit mode and unhides the tile palette. * Changes the edit mode and unhides the tile palette.
*/ */
......
...@@ -65,7 +65,9 @@ private: ...@@ -65,7 +65,9 @@ private:
EditorState(); // Explicitly undefined EditorState(); // Explicitly undefined
void fillTables();
void fillEditStateStringTable(); void fillEditStateStringTable();
void fillStateToLayerTable();
void initUi(); 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