Skip to content

Commit

Permalink
Editor: cleaned up a bunch of accessors
Browse files Browse the repository at this point in the history
Map Context:
* Removed get_team() in favor of non-const local team() overload.
* Removeded get_map() (both overloads) in favor of map() and a local non-const overload of the same.
* Made both overloads of map() return editor_map instead of gamemap (former inherits from the latter).

Context Manager:
* Removed team, unit, and label accessors that only fetched the same info from the current map_context.
  Having more functions of this name only made things a lot more confusing.

Editor Controller:
* Change all instances of the three intermediate accessors mentioned above to data queries directly
  from the current map context via editor_controller::get_current_map_context. The result is the same,
  we just no longer have three levels of indirection.
  • Loading branch information
Vultraz committed Jan 28, 2018
1 parent b0bb9d9 commit 69cd664
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 126 deletions.
40 changes: 20 additions & 20 deletions src/editor/action/action.cpp
Expand Up @@ -62,7 +62,7 @@ std::string editor_action::get_description() const

editor_action* editor_action::perform(map_context& mc) const
{
editor_action_ptr undo(new editor_action_whole_map(mc.get_map()));
editor_action_ptr undo(new editor_action_whole_map(mc.map()));
perform_without_undo(mc);
return undo.release();
}
Expand Down Expand Up @@ -194,7 +194,7 @@ void editor_action_paste::extend(const editor_map& map, const std::set<map_locat

editor_action_paste* editor_action_paste::perform(map_context& mc) const
{
map_fragment mf(mc.get_map(), paste_.get_offset_area(offset_));
map_fragment mf(mc.map(), paste_.get_offset_area(offset_));
std::unique_ptr<editor_action_paste> undo(new editor_action_paste(mf));

perform_without_undo(mc);
Expand All @@ -203,7 +203,7 @@ editor_action_paste* editor_action_paste::perform(map_context& mc) const

void editor_action_paste::perform_without_undo(map_context& mc) const
{
paste_.paste_into(mc.get_map(), offset_);
paste_.paste_into(mc.map(), offset_);
mc.add_changed_location(paste_.get_offset_area(offset_));
mc.set_needs_terrain_rebuild();
}
Expand All @@ -212,7 +212,7 @@ IMPLEMENT_ACTION(paint_area)

editor_action_paste* editor_action_paint_area::perform(map_context& mc) const
{
map_fragment mf(mc.get_map(), area_);
map_fragment mf(mc.map(), area_);
std::unique_ptr<editor_action_paste> undo(new editor_action_paste(mf));

perform_without_undo(mc);
Expand All @@ -229,9 +229,9 @@ IMPLEMENT_ACTION(fill)

editor_action_paint_area* editor_action_fill::perform(map_context& mc) const
{
std::set<map_location> to_fill = mc.get_map().get_contiguous_terrain_tiles(loc_);
std::set<map_location> to_fill = mc.map().get_contiguous_terrain_tiles(loc_);
std::unique_ptr<editor_action_paint_area> undo(
new editor_action_paint_area(to_fill, mc.get_map().get_terrain(loc_)));
new editor_action_paint_area(to_fill, mc.map().get_terrain(loc_)));

mc.draw_terrain(t_, to_fill, one_layer_);
mc.set_needs_terrain_rebuild();
Expand All @@ -241,7 +241,7 @@ editor_action_paint_area* editor_action_fill::perform(map_context& mc) const

void editor_action_fill::perform_without_undo(map_context& mc) const
{
std::set<map_location> to_fill = mc.get_map().get_contiguous_terrain_tiles(loc_);
std::set<map_location> to_fill = mc.map().get_contiguous_terrain_tiles(loc_);
mc.draw_terrain(t_, to_fill, one_layer_);
mc.set_needs_terrain_rebuild();
}
Expand All @@ -252,8 +252,8 @@ editor_action* editor_action_starting_position::perform(map_context& mc) const
{
editor_action_ptr undo;

const std::string* old_loc_id = mc.get_map().is_starting_position(loc_);
map_location old_loc = mc.get_map().special_location(loc_id_);
const std::string* old_loc_id = mc.map().is_starting_position(loc_);
map_location old_loc = mc.map().special_location(loc_id_);

if(old_loc_id != nullptr) {
// If another player was starting at the location, we actually perform two actions, so the undo is an
Expand All @@ -267,59 +267,59 @@ editor_action* editor_action_starting_position::perform(map_context& mc) const

LOG_ED << "ssp actual: " << *old_loc_id << " to " << map_location() << "\n";

mc.get_map().set_special_location(*old_loc_id, map_location());
mc.map().set_special_location(*old_loc_id, map_location());
} else {
undo.reset(new editor_action_starting_position(old_loc, loc_id_));
}

LOG_ED << "ssp actual: " << loc_id_ << " to " << loc_ << "\n";

mc.get_map().set_special_location(loc_id_, loc_);
mc.map().set_special_location(loc_id_, loc_);
mc.set_needs_labels_reset();

return undo.release();
}

void editor_action_starting_position::perform_without_undo(map_context& mc) const
{
const std::string* old_id = mc.get_map().is_starting_position(loc_);
const std::string* old_id = mc.map().is_starting_position(loc_);
if(old_id != nullptr) {
mc.get_map().set_special_location(*old_id, map_location());
mc.map().set_special_location(*old_id, map_location());
}

mc.get_map().set_special_location(loc_id_, loc_);
mc.map().set_special_location(loc_id_, loc_);
mc.set_needs_labels_reset();
}

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.map().resize(x_size_, y_size_, x_offset_, y_offset_, fill_);
mc.set_needs_reload();
}

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.map().overlay(mask_, config(), {0, 0});
mc.set_needs_terrain_rebuild();
}

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_map(editor_map(mc.map().mask_to(target_)));
mc.set_needs_terrain_rebuild();
}

IMPLEMENT_ACTION(shuffle_area)

editor_action_paste* editor_action_shuffle_area::perform(map_context& mc) const
{
map_fragment mf(mc.get_map(), area_);
map_fragment mf(mc.map(), area_);
std::unique_ptr<editor_action_paste> undo(new editor_action_paste(mf));

perform_without_undo(mc);
Expand All @@ -337,9 +337,9 @@ void editor_action_shuffle_area::perform_without_undo(map_context& mc) const
std::set<map_location>::const_iterator orig_it = area_.begin();

while(orig_it != area_.end()) {
t_translation::terrain_code tmp = mc.get_map().get_terrain(*orig_it);
t_translation::terrain_code tmp = mc.map().get_terrain(*orig_it);

mc.draw_terrain(mc.get_map().get_terrain(*shuffle_it), *orig_it);
mc.draw_terrain(mc.map().get_terrain(*shuffle_it), *orig_it);
mc.draw_terrain(tmp, *shuffle_it);

++orig_it;
Expand Down
2 changes: 1 addition & 1 deletion src/editor/action/action_item.cpp
Expand Up @@ -93,7 +93,7 @@ void editor_action_item_replace::perform_without_undo(map_context& /*mc*/) const
// mc.add_changed_location(new_loc_);
//
// /* @todo
// if (mc.get_map().is_village(new_loc_)) {
// if (mc.map().is_village(new_loc_)) {
// (*(resources::gameboard->teams()))[u.side()].get_village(new_loc_);
// }
// */
Expand Down
22 changes: 11 additions & 11 deletions src/editor/action/action_select.cpp
Expand Up @@ -48,7 +48,7 @@ editor_action* editor_action_select::perform(map_context& mc) const
void editor_action_select::perform_without_undo(map_context& mc) const
{
for(const map_location& loc : area_) {
mc.get_map().add_to_selection(loc);
mc.map().add_to_selection(loc);
mc.add_changed_location(loc);
}
}
Expand All @@ -70,7 +70,7 @@ editor_action* editor_action_deselect::perform(map_context& mc) const
{
std::set<map_location> undo_locs;
for(const map_location& loc : area_) {
if(mc.get_map().in_selection(loc)) {
if(mc.map().in_selection(loc)) {
undo_locs.insert(loc);
mc.add_changed_location(loc);
}
Expand All @@ -83,7 +83,7 @@ editor_action* editor_action_deselect::perform(map_context& mc) const
void editor_action_deselect::perform_without_undo(map_context& mc) const
{
for(const map_location& loc : area_) {
mc.get_map().remove_from_selection(loc);
mc.map().remove_from_selection(loc);
mc.add_changed_location(loc);
}
}
Expand All @@ -92,10 +92,10 @@ IMPLEMENT_ACTION(select_all)

editor_action_select* editor_action_select_all::perform(map_context& mc) const
{
std::set<map_location> current = mc.get_map().selection();
mc.get_map().select_all();
std::set<map_location> current = mc.map().selection();
mc.map().select_all();

std::set<map_location> all = mc.get_map().selection();
std::set<map_location> all = mc.map().selection();
std::set<map_location> undo_locs;

std::set_difference(
Expand All @@ -107,23 +107,23 @@ editor_action_select* editor_action_select_all::perform(map_context& mc) const

void editor_action_select_all::perform_without_undo(map_context& mc) const
{
mc.get_map().select_all();
mc.map().select_all();
mc.set_everything_changed();
}

IMPLEMENT_ACTION(select_none)

editor_action_select* editor_action_select_none::perform(map_context& mc) const
{
std::set<map_location> current = mc.get_map().selection();
mc.get_map().clear_selection();
std::set<map_location> current = mc.map().selection();
mc.map().clear_selection();
mc.set_everything_changed();
return new editor_action_select(current);
}

void editor_action_select_none::perform_without_undo(map_context& mc) const
{
mc.get_map().clear_selection();
mc.map().clear_selection();
mc.set_everything_changed();
}

Expand All @@ -137,7 +137,7 @@ editor_action_select_inverse* editor_action_select_inverse::perform(map_context&

void editor_action_select_inverse::perform_without_undo(map_context& mc) const
{
mc.get_map().invert_selection();
mc.map().invert_selection();
mc.set_everything_changed();
}

Expand Down
2 changes: 1 addition & 1 deletion src/editor/action/action_unit.cpp
Expand Up @@ -97,7 +97,7 @@ void editor_action_unit_replace::perform_without_undo(map_context& mc) const
mc.add_changed_location(new_loc_);

/* @todo
if (mc.get_map().is_village(new_loc_)) {
if (mc.map().is_village(new_loc_)) {
(*(resources::gameboard->teams()))[u.side()].get_village(new_loc_);
}
*/
Expand Down
10 changes: 5 additions & 5 deletions src/editor/action/action_village.cpp
Expand Up @@ -29,11 +29,11 @@ IMPLEMENT_ACTION(village)

editor_action* editor_action_village::perform(map_context& mc) const
{
if(!mc.get_map().is_village(loc_)) {
if(!mc.map().is_village(loc_)) {
return nullptr;
}

std::vector<team>& teams = mc.get_teams();
std::vector<team>& teams = mc.teams();

try {
if(teams.at(side_number_).owns_village(loc_)) {
Expand All @@ -57,7 +57,7 @@ editor_action* editor_action_village::perform(map_context& mc) const

void editor_action_village::perform_without_undo(map_context& mc) const
{
std::vector<team>& teams = mc.get_teams();
std::vector<team>& teams = mc.teams();

for(team& t : teams) {
if(t.owns_village(loc_)) {
Expand All @@ -75,7 +75,7 @@ editor_action* editor_action_village_delete::perform(map_context& mc) const
{
editor_action_ptr undo;

for(const team& t : mc.get_teams()) {
for(const team& t : mc.teams()) {
if(t.owns_village(loc_)) {
perform_without_undo(mc);
undo.reset(new editor_action_village(loc_, t.side() - 1));
Expand All @@ -87,7 +87,7 @@ editor_action* editor_action_village_delete::perform(map_context& mc) const

void editor_action_village_delete::perform_without_undo(map_context& mc) const
{
for(team& t : mc.get_teams()) {
for(team& t : mc.teams()) {
if(t.owns_village(loc_)) {
t.lose_village(loc_);
mc.add_changed_location(loc_);
Expand Down

0 comments on commit 69cd664

Please sign in to comment.