forked from wario-land/WL4Editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Operation.h
161 lines (147 loc) · 4.92 KB
/
Operation.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#ifndef OPERATION_H
#define OPERATION_H
#include "Dialog/RoomConfigDialog.h"
#include "Dialog/TilesetEditDialog.h"
#include "Dialog/CreditsEditDialog.h"
#include "Dialog/SpritesEditorDialog.h"
#include "LevelComponents/Tile.h"
// Enumerate the type of operations that can be performed and undone
enum OperationType
{
ChangeTileOperation,
ChangeRoomConfigOperation,
ObjectMoveOperation,
ChangeTilesetOperation,
ChangeSpritesAndSpritesetsOperation,
};
// The parameters specific to a tile change operation
struct TileChangeParams
{
// Fields
int tileX;
int tileY;
int targetLayer;
unsigned short newTile;
unsigned short oldTile;
// Create an instance of TileChangeParams on the heap, which represents a single changed tile
static TileChangeParams *Create(int X, int Y, int target, unsigned short nt, unsigned short ot)
{
struct TileChangeParams *p = new struct TileChangeParams;
p->tileX = X;
p->tileY = Y;
p->targetLayer = target;
p->newTile = nt;
p->oldTile = ot;
return p;
}
};
// The parameters specific to an object move operation
struct ObjectMoveParams
{
int previousPositionX;
int previousPositionY;
int nextPositionX;
int nextPositionY;
int type; // DOOR_TYPE or ENTITY_TYPE
int objectID;
const static int DOOR_TYPE=1;
const static int ENTITY_TYPE=2;
// Create an instance of ObjectMoveParams on the heap, which represents a moved obect
static ObjectMoveParams *Create(int pX, int pY, int nX, int nY, int type, int objectID)
{
struct ObjectMoveParams *om = new struct ObjectMoveParams;
om->previousPositionX = pX;
om->previousPositionY = pY;
om->nextPositionX = nX;
om->nextPositionY = nY;
om->type = type;
om->objectID = objectID;
return om;
}
};
// The parameters that pertain to a single operation which can be undone atomically
struct OperationParams;
struct OperationParams
{
// Fields
enum OperationType type; // TODO: this seems not needed or those following bools are not needed -- ssp
std::vector<struct TileChangeParams *> tileChangeParams;
ObjectMoveParams *objectMoveParams;
DialogParams::RoomConfigParams *lastRoomConfigParams;
DialogParams::RoomConfigParams *newRoomConfigParams;
DialogParams::TilesetEditParams *lastTilesetEditParams;
DialogParams::TilesetEditParams *newTilesetEditParams;
DialogParams::CreditsEditParams *lastCreditsEditParams;
DialogParams::CreditsEditParams *newCreditsEditParams;
DialogParams::EntitiesAndEntitySetsEditParams *lastSpritesAndSetParam;
DialogParams::EntitiesAndEntitySetsEditParams *newSpritesAndSetParam;
bool tileChange;
bool roomConfigChange;
bool objectPositionChange;
bool TilesetChange;
bool CreditChange;
bool SpritesSpritesetChange;
OperationParams() :
lastRoomConfigParams(nullptr),
newRoomConfigParams(nullptr),
tileChange(false),
roomConfigChange(false),
objectPositionChange(false),
TilesetChange(false),
CreditChange(false),
SpritesSpritesetChange(false)
{}
// Clean up the struct when it is deconstructed
~OperationParams()
{
if (tileChange)
{
for (unsigned int i = 0; i < tileChangeParams.size(); ++i)
{
struct TileChangeParams *p = tileChangeParams[i];
delete p;
}
}
if (roomConfigChange)
{
if (lastRoomConfigParams)
delete lastRoomConfigParams;
if (newRoomConfigParams)
delete newRoomConfigParams;
}
if (TilesetChange)
{
if (lastTilesetEditParams)
delete lastTilesetEditParams;
if (newTilesetEditParams)
{
delete newTilesetEditParams->newTileset;
delete newTilesetEditParams;
}
}
if (SpritesSpritesetChange)
{
if (lastSpritesAndSetParam)
delete lastSpritesAndSetParam;
if (newSpritesAndSetParam)
{
for (LevelComponents::Entity *entityIter: lastSpritesAndSetParam->entities)
delete entityIter;
for (LevelComponents::EntitySet *entitySetIter: lastSpritesAndSetParam->entitySets)
delete entitySetIter;
delete newSpritesAndSetParam;
}
}
}
};
// Operation function prototypes
void ExecuteOperation(struct OperationParams *operation);
void ExecuteOperationGlobal(struct OperationParams *operation);
void PerformOperation(struct OperationParams *operation);
void BackTrackOperation(struct OperationParams *operation);
void UndoOperation();
void UndoOperationGlobal();
void RedoOperation();
void RedoOperationGlobal();
void ResetUndoHistory();
#endif // OPERATION_H