Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
CommandHistory.cpp
Go to the documentation of this file.
1/**
2 * @file CommandHistory.cpp
3 * @brief Implementation of CommandHistory
4 * @author Olympe Engine
5 */
6
7#include "CommandHistory.h"
8
9namespace Olympe
10{
14
16 {
17 if (!command)
18 return false;
19
20 // Execute the command
21 if (!command->Execute())
22 return false;
23
24 // Clear redo stack (new action invalidates redo history)
25 m_redoStack.clear();
26
27 // Add to undo stack
28 m_undoStack.push_back(std::move(command));
29
30 return true;
31 }
32
34 {
35 if (m_undoStack.empty())
36 return false;
37
38 // Get last command
39 GraphCommand* cmd = m_undoStack.back().get();
40
41 // Execute undo
42 if (!cmd->Undo())
43 return false;
44
45 // Move from undo to redo stack
46 m_redoStack.push_back(std::move(m_undoStack.back()));
47 m_undoStack.pop_back();
48
49 return true;
50 }
51
53 {
54 if (m_redoStack.empty())
55 return false;
56
57 // Get last undone command
58 GraphCommand* cmd = m_redoStack.back().get();
59
60 // Execute forward (re-execute)
61 if (!cmd->Execute())
62 return false;
63
64 // Move from redo to undo stack
65 m_undoStack.push_back(std::move(m_redoStack.back()));
66 m_redoStack.pop_back();
67
68 return true;
69 }
70
72 {
73 return !m_undoStack.empty();
74 }
75
77 {
78 return !m_redoStack.empty();
79 }
80
82 {
83 if (m_undoStack.empty())
84 return "";
85 return "Undo: " + m_undoStack.back()->GetDescription();
86 }
87
89 {
90 if (m_redoStack.empty())
91 return "";
92 return "Redo: " + m_redoStack.back()->GetDescription();
93 }
94
96 {
97 m_undoStack.clear();
98 m_redoStack.clear();
99 }
100
101} // namespace Olympe
Undo/redo history manager for graph commands.
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
bool CanRedo() const
Check if redo is available.
std::string GetRedoDescription() const
Get description of next redo command.
bool Undo()
Undo the last command.
std::vector< GraphCommandPtr > m_redoStack
bool ExecuteCommand(GraphCommandPtr command)
Execute a new command and add it to history.
void Clear()
Clear all undo/redo history.
bool Redo()
Redo the last undone command.
std::vector< GraphCommandPtr > m_undoStack
bool CanUndo() const
Check if undo is available.
std::string GetUndoDescription() const
Get description of next undo command.
Abstract base class for all graph modification commands.
virtual std::string GetDescription() const =0
Get a human-readable description of the command.
< Provides AssetID and INVALID_ASSET_ID
std::unique_ptr< GraphCommand > GraphCommandPtr