Cogs.Core
EditorCommand.h
1#pragma once
2
3#include "../EditorExtension.h"
4#include "../EditorState.h"
5
6#include "Editor/EditorCommand.h"
7
8#include "Utilities/Parsing.h"
9
10#include "CommandParseHelpers.h"
11
12#include "Serialization/JsonParser.h"
13
14#include "Services/PropertiesManager.h"
15
16#include <vector>
17
18namespace Cogs::Core
19{
20 class Context;
21 class MeshComponent;
22
23 // Remove children from entityIds if any ancestor is in the list as well
24 void RemoveEntitiesWithAncestors(Context* context, const EntityIds& entityIds, EntityIds& output);
25
27 struct COGSCORE_EDITOR_API PostCommand : public EditorCommand
28 {
29 explicit PostCommand(EditorState * state) : EditorCommand(state, state->context) {}
30 // Must have destructor as having DLL interface.
31 ~PostCommand() override;
32
33 virtual void applyPost() = 0;
34
35 PropertyStore properties;
36 };
37
40 {
41 ModalEditorCommand(EditorState * state) : EditorCommand(state, state->context) {}
42
44 virtual void beginModal() = 0;
45
47 virtual void showGui() = 0;
48
50 virtual bool continueModal() = 0;
51 };
52
54 {
55 ChangeEditingModeCommand(EditorState * state, EditingMode newMode) : EditorCommand(state, state->context), newMode(newMode) {}
56
57 void apply() override;
58 void undo() override;
59
60 private:
61 EditingMode newMode = EditingMode::None;
62 EditingMode previousMode = EditingMode::None;
63 };
64
65 struct COGSCORE_EDITOR_API CreateEntityCommand : public EditorCommand
66 {
67 CreateEntityCommand(EditorState* state, const StringView& type, const StringView& name, bool openInRoot);
68
69 void apply() override;
70 void undo() override;
71
72 private:
73 std::string type;
74 std::string name;
75 bool openInRoot;
76
77 EntityId entityId = NoEntity;
78 EntityId parentId = NoEntity;
79
80 EntityIds previousSelection;
81 };
82
84 {
85 PasteEntityCommand(EditorState * state) : EditorCommand(state, state->context) {}
86
87 void apply() override;
88 void undo() override;
89
90 private:
91 EntityIds entityIds;
92
93 EntityIds previousSelection;
94 };
95
97 {
98 DestroyCommand(EditorState * state, const EntityIds& entityIds, bool allowUndo) : EditorCommand(state, state->context), allowUndo(allowUndo)
99 {
100 RemoveEntitiesWithAncestors(context, entityIds, this->entityIds);
101 }
102
103 void apply() override;
104 void undo() override;
105
106 private:
107 bool allowUndo;
108 EntityIds entityIds;
109 EntityIds parentIds;
110 rapidjson::Document copied;
111 };
112
113 class COGSCORE_EDITOR_API SelectCommand : public EditorCommand
114 {
115 public:
116 SelectCommand(EditorState * state, const EntityIds& selectedIds, SelectMode mode = SelectMode::Exclusive, int pickId = -1)
117 : EditorCommand(state, state->context), pickId(pickId), selectedIds(selectedIds), mode(mode)
118 {
119 }
120
121 SelectCommand(EditorState * state, const EntityId& selectedId, SelectMode mode = SelectMode::Exclusive, int pickId = -1)
122 : SelectCommand(state, EntityIds{ selectedId }, mode, pickId)
123 {
124 }
125
126 void apply() override;
127 void undo() override;
128
130 int pickId = -1;
131 private:
132 EntityIds selectedIds;
133 SelectMode mode = SelectMode::Exclusive;
134
135 EntityIds previousSelection;
136 };
137
139 {
140 AddComponentCommand(EditorState * state, EntityId entityId, const StringView & type) : EditorCommand(state, state->context), entityId(entityId), type(type.to_string()) {}
141
142 void apply() override;
143 void undo() override;
144
145 private:
146 EntityId entityId = NoEntity;
147 std::string type;
148 };
149
151 {
152 TranslateCommand(EditorState * state, const EntityIds& entityIds, glm::vec3 translation) : EditorCommand(state, state->context), entityIds(entityIds), translation(translation) {}
153
154 void apply() override;
155 void undo() override;
156
157 bool mergeWith(const EditorCommand * command) override;
158
159 private:
160 EntityIds entityIds;
161 glm::vec3 translation;
162
163 std::vector<glm::vec3> previousTranslations;
164 };
165
167 {
168 RotateCommand(EditorState * state, const EntityIds& entityIds, glm::quat rotation) : EditorCommand(state, state->context), entityIds(entityIds), rotation(rotation) {}
169
170 void apply() override;
171 void undo() override;
172
173 bool mergeWith(const EditorCommand * command) override;
174
175 private:
176 EntityIds entityIds;
177 glm::quat rotation;
178
179 std::vector<glm::quat> previousRotations;
180 };
181
183 {
184 ScaleCommand(EditorState * state, const EntityIds& entityIds, glm::vec3 scale) : EditorCommand(state, state->context), entityIds(entityIds), scale(scale) {}
185
186 void apply() override;
187 void undo() override;
188
189 bool mergeWith(const EditorCommand * command) override;
190
191 private:
192 EntityIds entityIds;
193 glm::vec3 scale;
194
195 std::vector<glm::vec3> previousScales;
196 };
197
199 {
200 ScaleToUnitCubeCommand(EditorState* state, EntityId entityId) : EditorCommand(state, state->context), entityId(entityId) {}
201
202 void apply() override;
203 void undo() override;
204
205 private:
206 EntityId entityId;
207
208 glm::vec3 previousScale;
209 glm::vec3 previousPosition;
210 };
211
213 {
214 GroupCommand(EditorState * state, const EntityIds& entityIds) : EditorCommand(state, state->context)
215 {
216 RemoveEntitiesWithAncestors(context, entityIds, this->entityIds);
217 }
218
219 void apply() override;
220 void undo() override;
221
222 private:
223 EntityIds entityIds;
224 EntityId groupId = NoEntity;
225 };
226}
Provides a weakly referenced view over the contents of a string.
Definition: StringView.h:24
std::string to_string() const
String conversion method.
Definition: StringView.cpp:9
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
void apply() override
Run the command.
void apply() override
Run the command.
void apply() override
Run the command.
Base class for Cogs Editor commands.
Definition: EditorCommand.h:19
void apply() override
Run the command.
Abstract base class for all editor commands showing GUI in interactive mode.
Definition: EditorCommand.h:40
virtual void beginModal()=0
Called when the command is initiated.
virtual void showGui()=0
Display custom ImGUI.
virtual bool continueModal()=0
Shall return true while the GUI should still be shown. False when.
void apply() override
Run the command.
Abstract base class for all editor batch Post commands.
Definition: EditorCommand.h:28
void apply() override
Run the command.
bool mergeWith(const EditorCommand *command) override
bool mergeWith(const EditorCommand *command) override
void apply() override
Run the command.
void apply() override
Run the command.
bool mergeWith(const EditorCommand *command) override
void apply() override
Run the command.