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