3 Copyright (C) 2012 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #ifndef ROLLBACK_INTERFACE_HEADER
21 #define ROLLBACK_INTERFACE_HEADER
26 #include "exceptions.h"
31 class InventoryManager;
40 bool operator==(const RollbackNode &other)
42 return (name == other.name && param1 == other.param1 &&
43 param2 == other.param2 && meta == other.meta);
45 bool operator!=(const RollbackNode &other)
47 return !(*this == other);
55 RollbackNode(Map *map, v3s16 p, IGameDef *gamedef);
63 TYPE_MODIFY_INVENTORY_STACK,
73 std::string inventory_location;
74 std::string inventory_list;
77 std::string inventory_stack;
83 void setSetNode(v3s16 p_, const RollbackNode &n_old_,
84 const RollbackNode &n_new_)
92 void setModifyInventoryStack(const std::string &inventory_location_,
93 const std::string &inventory_list_, int index_,
94 bool add_, const std::string &inventory_stack_)
96 type = TYPE_MODIFY_INVENTORY_STACK;
97 inventory_location = inventory_location_;
98 inventory_list = inventory_list_;
99 inventory_index = index_;
100 inventory_add = add_;
101 inventory_stack = inventory_stack_;
104 // String should not contain newlines or nulls
105 std::string toString() const;
106 void fromStream(std::istream &is) throw(SerializationError);
108 // Eg. flowing water level changes are not important
109 bool isImportant(IGameDef *gamedef) const;
111 bool applyRevert(Map *map, InventoryManager *imgr, IGameDef *gamedef) const;
114 class IRollbackReportSink
117 virtual ~IRollbackReportSink(){}
118 virtual void reportAction(const RollbackAction &action) = 0;
119 virtual std::string getActor() = 0;
120 virtual void setActor(const std::string &actor) = 0;
123 class RollbackScopeActor
126 RollbackScopeActor(IRollbackReportSink *sink, const std::string &actor):
130 m_actor_was = m_sink->getActor();
131 m_sink->setActor(actor);
134 ~RollbackScopeActor()
137 m_sink->setActor(m_actor_was);
141 IRollbackReportSink *m_sink;
142 std::string m_actor_was;