Skip to content

Commit

Permalink
Editor/Actions: used helper macro to implement clone() and get_name()…
Browse files Browse the repository at this point in the history
… methods

In two cases, the action names were changed by the use of the macro:
* starting_pos -> starting_position
* resize -> resize_map

However this doesn't seem to have actually affected any editor functionality.
  • Loading branch information
Vultraz committed Sep 13, 2017
1 parent 49d0af3 commit a6c17c1
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 216 deletions.
50 changes: 10 additions & 40 deletions src/editor/action/action.cpp
Expand Up @@ -67,10 +67,7 @@ editor_action* editor_action::perform(map_context& mc) const
return undo.release();
}

editor_action_whole_map* editor_action_whole_map::clone() const
{
return new editor_action_whole_map(*this);
}
IMPLEMENT_ACTION(whole_map)

void editor_action_whole_map::perform_without_undo(map_context& mc) const
{
Expand Down Expand Up @@ -111,10 +108,7 @@ editor_action_chain::~editor_action_chain()
}
}

editor_action_chain* editor_action_chain::clone() const
{
return new editor_action_chain(*this);
}
IMPLEMENT_ACTION(chain)

int editor_action_chain::action_count() const
{
Expand Down Expand Up @@ -191,10 +185,7 @@ void editor_action_area::extend(const editor_map& /*map*/, const std::set<map_lo
area_.insert(locs.begin(), locs.end());
}

editor_action_paste* editor_action_paste::clone() const
{
return new editor_action_paste(*this);
}
IMPLEMENT_ACTION(paste)

void editor_action_paste::extend(const editor_map& map, const std::set<map_location>& locs)
{
Expand All @@ -217,10 +208,7 @@ void editor_action_paste::perform_without_undo(map_context& mc) const
mc.set_needs_terrain_rebuild();
}

editor_action_paint_area* editor_action_paint_area::clone() const
{
return new editor_action_paint_area(*this);
}
IMPLEMENT_ACTION(paint_area)

editor_action_paste* editor_action_paint_area::perform(map_context& mc) const
{
Expand All @@ -237,10 +225,7 @@ void editor_action_paint_area::perform_without_undo(map_context& mc) const
mc.set_needs_terrain_rebuild();
}

editor_action_fill* editor_action_fill::clone() const
{
return new editor_action_fill(*this);
}
IMPLEMENT_ACTION(fill)

editor_action_paint_area* editor_action_fill::perform(map_context& mc) const
{
Expand All @@ -261,10 +246,7 @@ void editor_action_fill::perform_without_undo(map_context& mc) const
mc.set_needs_terrain_rebuild();
}

editor_action_starting_position* editor_action_starting_position::clone() const
{
return new editor_action_starting_position(*this);
}
IMPLEMENT_ACTION(starting_position)

editor_action* editor_action_starting_position::perform(map_context& mc) const
{
Expand Down Expand Up @@ -309,43 +291,31 @@ void editor_action_starting_position::perform_without_undo(map_context& mc) cons
mc.set_needs_labels_reset();
}

editor_action_resize_map* editor_action_resize_map::clone() const
{
return new editor_action_resize_map(*this);
}
IMPLEMENT_ACTION(resize_map)

void editor_action_resize_map::perform_without_undo(map_context& mc) const
{
mc.get_map().resize(x_size_, y_size_, x_offset_, y_offset_, fill_);
mc.set_needs_reload();
}

editor_action_apply_mask* editor_action_apply_mask::clone() const
{
return new editor_action_apply_mask(*this);
}
IMPLEMENT_ACTION(apply_mask)

void editor_action_apply_mask::perform_without_undo(map_context& mc) const
{
mc.get_map().overlay(mask_, config(), {0, 0});
mc.set_needs_terrain_rebuild();
}

editor_action_create_mask* editor_action_create_mask::clone() const
{
return new editor_action_create_mask(*this);
}
IMPLEMENT_ACTION(create_mask)

void editor_action_create_mask::perform_without_undo(map_context& mc) const
{
mc.set_map(editor_map(mc.get_map().mask_to(target_)));
mc.set_needs_terrain_rebuild();
}

editor_action_shuffle_area* editor_action_shuffle_area::clone() const
{
return new editor_action_shuffle_area(*this);
}
IMPLEMENT_ACTION(shuffle_area)

editor_action_paste* editor_action_shuffle_area::perform(map_context& mc) const
{
Expand Down
68 changes: 28 additions & 40 deletions src/editor/action/action.hpp
Expand Up @@ -42,14 +42,13 @@ class editor_action_whole_map : public editor_action
{
}

/** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
editor_action_whole_map* clone() const;

void perform_without_undo(map_context& m) const;

const char* get_name() const
{
return "whole_map";
}
/** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
const char* get_name() const;

protected:
editor_map m_;
Expand Down Expand Up @@ -102,6 +101,7 @@ class editor_action_chain : public editor_action

editor_action_chain& operator=(const editor_action_chain& other);

/** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
editor_action_chain* clone() const;

/**
Expand Down Expand Up @@ -171,10 +171,8 @@ class editor_action_chain : public editor_action
*/
void perform_without_undo(map_context& m) const;

const char* get_name() const
{
return "chain";
}
/** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
const char* get_name() const;

protected:
/**
Expand Down Expand Up @@ -259,6 +257,7 @@ class editor_action_paste : public editor_action_extendable
{
}

/** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
editor_action_paste* clone() const;

editor_action_paste* perform(map_context& mc) const;
Expand All @@ -267,10 +266,8 @@ class editor_action_paste : public editor_action_extendable

void extend(const editor_map& map, const std::set<map_location>& locs);

const char* get_name() const
{
return "paste";
}
/** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
const char* get_name() const;

protected:
map_location offset_;
Expand All @@ -291,16 +288,15 @@ class editor_action_paint_area : public editor_action_area
{
}

/** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
editor_action_paint_area* clone() const;

editor_action_paste* perform(map_context& mc) const;

void perform_without_undo(map_context& mc) const;

const char* get_name() const
{
return "paint_area";
}
/** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
const char* get_name() const;

protected:
t_translation::terrain_code t_;
Expand All @@ -320,16 +316,15 @@ class editor_action_fill : public editor_action_location_terrain
{
}

/** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
editor_action_fill* clone() const;

editor_action_paint_area* perform(map_context& mc) const;

void perform_without_undo(map_context& mc) const;

const char* get_name() const
{
return "fill";
}
/** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
const char* get_name() const;

protected:
bool one_layer_;
Expand All @@ -347,16 +342,15 @@ class editor_action_starting_position : public editor_action_location
{
}

/** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
editor_action_starting_position* clone() const;

editor_action* perform(map_context& mc) const;

void perform_without_undo(map_context& mc) const;

const char* get_name() const
{
return "starting_pos";
}
/** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
const char* get_name() const;

protected:
std::string loc_id_;
Expand All @@ -382,14 +376,13 @@ class editor_action_resize_map : public editor_action
{
}

/** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
editor_action_resize_map* clone() const;

void perform_without_undo(map_context& mc) const;

const char* get_name() const
{
return "resize";
}
/** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
const char* get_name() const;

protected:
int x_size_;
Expand All @@ -408,14 +401,13 @@ class editor_action_apply_mask : public editor_action
{
}

/** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
editor_action_apply_mask* clone() const;

void perform_without_undo(map_context& mc) const;

const char* get_name() const
{
return "apply_mask";
}
/** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
const char* get_name() const;

private:
gamemap mask_;
Expand All @@ -433,10 +425,7 @@ class editor_action_create_mask : public editor_action

void perform_without_undo(map_context& mc) const;

const char* get_name() const
{
return "create_mask";
}
const char* get_name() const;

private:
editor_map target_;
Expand All @@ -453,16 +442,15 @@ class editor_action_shuffle_area : public editor_action_area
{
}

/** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
editor_action_shuffle_area* clone() const;

editor_action_paste* perform(map_context& mc) const;

void perform_without_undo(map_context& mc) const;

const char* get_name() const
{
return "shuffle_area";
}
/** Inherited from editor_action, implemented by IMPLEMENT_ACTION. */
const char* get_name() const;
};

} // end namespace editor
15 changes: 15 additions & 0 deletions src/editor/action/action_base.hpp
Expand Up @@ -117,4 +117,19 @@ struct editor_action_exception : public editor_exception
}
};

/**
* Helper macro to implement common action methods.
*/
#define IMPLEMENT_ACTION(id) \
\
const char* editor_action_##id::get_name() const \
{ \
return #id; \
} \
\
editor_action_##id* editor_action_##id::clone() const \
{ \
return new editor_action_##id(*this); \
} \

} // end namespace editor
20 changes: 4 additions & 16 deletions src/editor/action/action_item.cpp
Expand Up @@ -26,10 +26,7 @@

namespace editor
{
editor_action_item* editor_action_item::clone() const
{
return new editor_action_item(*this);
}
IMPLEMENT_ACTION(item)

editor_action* editor_action_item::perform(map_context& mc) const
{
Expand All @@ -46,10 +43,7 @@ void editor_action_item::perform_without_undo(map_context& /*mc*/) const
// mc.add_changed_location(loc_);
}

editor_action_item_delete* editor_action_item_delete::clone() const
{
return new editor_action_item_delete(*this);
}
IMPLEMENT_ACTION(item_delete)

editor_action* editor_action_item_delete::perform(map_context& /*mc*/) const
{
Expand All @@ -75,10 +69,7 @@ void editor_action_item_delete::perform_without_undo(map_context& /*mc*/) const
// }
}

editor_action_item_replace* editor_action_item_replace::clone() const
{
return new editor_action_item_replace(*this);
}
IMPLEMENT_ACTION(item_replace)

editor_action* editor_action_item_replace::perform(map_context& mc) const
{
Expand Down Expand Up @@ -112,10 +103,7 @@ void editor_action_item_replace::perform_without_undo(map_context& /*mc*/) const
//// resources::screen->draw();
}

editor_action_item_facing* editor_action_item_facing::clone() const
{
return new editor_action_item_facing(*this);
}
IMPLEMENT_ACTION(item_facing)

editor_action* editor_action_item_facing::perform(map_context& mc) const
{
Expand Down

0 comments on commit a6c17c1

Please sign in to comment.