The Battle for Wesnoth  1.17.0-dev
action_item.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2018 by Fabian Mueller <fabianmueller5@gmx.de>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 /**
16  * @file
17  * Editor action classes. Some important points:
18  * - This is a polymorphic hierarchy of classes, so actions are usually passed around
19  * as editor_action pointers
20  * - The pointers can, in general, be null. Always check for null before doing anything.
21  * The helper functions perform_ that take a pointer do that.
22  * - The perform() functions can throw when an error occurs. Use smart pointers if you
23  * need to ensure the pointer is deleted.
24  */
25 
26 #pragma once
27 
28 #include "editor/action/action.hpp"
29 #include "overlay.hpp"
30 
31 //#include "item_types.hpp"
32 //#include "item.hpp"
33 
34 namespace editor
35 {
36 /**
37  * place a new item on the map
38  *
39  * \todo remove commented-out code (no separate ticket, but editor cleanup is on the roadmap for 1.15.11)
40  * action_item.cpp is full of commented-out code, it seems to be deadweight
41  * with the real implementation to be found in mouse_action_item.cpp.
42  */
44 {
45 public:
48  , item_(item)
49  {
50  }
51 
52  std::unique_ptr<editor_action> clone() const override;
53  std::unique_ptr<editor_action> perform(map_context& mc) const override;
54  void perform_without_undo(map_context& mc) const override;
55  const std::string& get_name() const override;
56 
57 protected:
59 };
60 
61 /**
62  * Remove a item from the map.
63  */
65 {
66 public:
69  {
70  }
71 
72  std::unique_ptr<editor_action> clone() const override;
73  std::unique_ptr<editor_action> perform(map_context& mc) const override;
74  void perform_without_undo(map_context& mc) const override;
75  const std::string& get_name() const override;
76 };
77 
79 {
80 public:
83  , new_loc_(new_loc)
84  {
85  }
86 
87  std::unique_ptr<editor_action> clone() const override;
88  std::unique_ptr<editor_action> perform(map_context& mc) const override;
89  void perform_without_undo(map_context& mc) const override;
90  const std::string& get_name() const override;
91 
92 protected:
94 };
95 
97 {
98 public:
100  map_location loc, map_location::DIRECTION new_direction, map_location::DIRECTION old_direction)
102  , new_direction_(new_direction)
103  , old_direction_(old_direction)
104  {
105  }
106 
107  std::unique_ptr<editor_action> clone() const override;
108  std::unique_ptr<editor_action> perform(map_context& mc) const override;
109  void perform_without_undo(map_context& mc) const override;
110  const std::string& get_name() const override;
111 
112 protected:
115 };
116 
117 } // end namespace editor
place a new item on the map
Definition: action_item.hpp:43
editor_action_item(map_location loc, const overlay &item)
Definition: action_item.hpp:46
Base class for actions which act on a specified location (and possibly on other locations that can be...
Definition: action.hpp:175
editor_action_item_facing(map_location loc, map_location::DIRECTION new_direction, map_location::DIRECTION old_direction)
Definition: action_item.hpp:99
editor_action_item_delete(map_location loc)
Definition: action_item.hpp:67
editor_action_item_replace(map_location loc, map_location new_loc)
Definition: action_item.hpp:81
map_location::DIRECTION new_direction_
std::unique_ptr< editor_action > perform(map_context &mc) const override
Perform the action, returning an undo action that, when performed, shall reverse any effects of this ...
Definition: action_item.cpp:31
void perform_without_undo(map_context &mc) const override
Perform the action without creating an undo action.
Definition: action_item.cpp:38
Editor action classes.
Remove a item from the map.
Definition: action_item.hpp:64
const std::string & get_name() const override
Manage the empty-palette in the editor.
Definition: action.cpp:29
map_location::DIRECTION old_direction_
Encapsulates the map of the game.
Definition: location.hpp:37
DIRECTION
Valid directions which can be moved in our hexagonal world.
Definition: location.hpp:39
std::unique_ptr< editor_action > clone() const override
Action cloning.
This class wraps around a map to provide a concise interface for the editor to work with...
Definition: map_context.hpp:59
std::pair< std::string, unsigned > item
Definition: help_impl.hpp:409