Cogs.Core
EditorCommand.h
1#pragma once
2
3#include "Base.h"
4
5#include "Resources/Resources.h"
6
7#include "Utilities/Parsing.h"
8
9namespace Cogs::Core
10{
11 struct EditorState;
12 class Context;
13
18 struct COGSCORE_DLL_API EditorCommand
19 {
20 EditorCommand(EditorState * state, Context * context);
21 virtual ~EditorCommand() = default;
22
29 virtual void apply() = 0;
30 virtual void undo() = 0;
31 virtual void redo()
32 {
33 apply();
34 }
35
39 virtual bool mergeWith(const EditorCommand * /*command*/) { return false; }
40
42 virtual MeshHandle applyMesh(MeshHandle /*mesh*/) { return {}; }
43
45 virtual void close()
46 {
47 closed = true;
48 }
49
50 bool isClosed() const { return closed; }
51
53 bool merge(const EditorCommand * command)
54 {
55 if (closed) return false;
56
57 return mergeWith(command);
58 }
59
61 std::vector<ParsedValue> options;
62
64 bool permanentUndo = false;
65
66 protected:
67 EditorState * state = nullptr;
68 Context * context = nullptr;
69
70 private:
71 bool closed = false;
72 };
73}
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Definition: Context.h:83
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
Base class for Cogs Editor commands.
Definition: EditorCommand.h:19
virtual bool mergeWith(const EditorCommand *)
Definition: EditorCommand.h:39
bool merge(const EditorCommand *command)
Merge into this if not this is closed.
Definition: EditorCommand.h:53
virtual void apply()=0
Run the command.
virtual MeshHandle applyMesh(MeshHandle)
Workaround for having extendable mesh processing available without linking (e.g command -> RR).
Definition: EditorCommand.h:42
std::vector< ParsedValue > options
Options passed to the command when running in batch mode.
Definition: EditorCommand.h:61
virtual void close()
Close command, i.e. prevent merging with another command.
Definition: EditorCommand.h:45