-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix undo/redo Prefab overrides properties UID + Undo/Redo destroy WIP
- Loading branch information
Showing
16 changed files
with
236 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma once | ||
|
||
#include "core/IUndoRedo.h" | ||
#include "core/File/Buffer.h" | ||
|
||
namespace vg::core | ||
{ | ||
class IObject; | ||
class IProperty; | ||
class IDynamicProperty; | ||
|
||
//-------------------------------------------------------------------------------------- | ||
class UndoRedoDestroyEntry final : public UndoRedoEntry | ||
{ | ||
using super = UndoRedoEntry; | ||
|
||
public: | ||
UndoRedoDestroyEntry(IObject * _object, IObject * _parent, uint _indexInParent); | ||
|
||
void BeforeChange() final override; | ||
void AfterChange() final override; | ||
|
||
void Undo() final override; | ||
void Redo() final override; | ||
|
||
string GetEntryName() const final override; | ||
string GetObjectName() const final override; | ||
string GetDescription() const final override; | ||
|
||
IObject * getParent() const; | ||
|
||
private: | ||
io::Buffer m_buffer; | ||
string m_className; | ||
UID m_parentUID; | ||
uint m_indexInParent; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#include "UndoRedoDestroyEntry.h" | ||
#include "core/Kernel.h" | ||
#include "core/Object/Factory.h" | ||
#include "core/IGameObject.h" | ||
#include "core/string/string.h" | ||
|
||
namespace vg::core | ||
{ | ||
//-------------------------------------------------------------------------------------- | ||
UndoRedoDestroyEntry::UndoRedoDestroyEntry(IObject * _object, IObject * _parent, uint _indexInParent) : | ||
UndoRedoEntry(_object) | ||
{ | ||
m_className = _object->GetClassName(); | ||
m_parentUID = _parent->GetUID(); | ||
m_indexInParent = _indexInParent; | ||
} | ||
|
||
//-------------------------------------------------------------------------------------- | ||
void UndoRedoDestroyEntry::BeforeChange() | ||
{ | ||
Factory * factory = (Factory *)Kernel::getFactory(); | ||
if (auto * object = GetObject()) | ||
{ | ||
m_buffer.resetWrite(); | ||
factory->serializeObjectToMemory(object, m_buffer); | ||
} | ||
} | ||
|
||
//-------------------------------------------------------------------------------------- | ||
void UndoRedoDestroyEntry::AfterChange() | ||
{ | ||
|
||
} | ||
|
||
//-------------------------------------------------------------------------------------- | ||
string UndoRedoDestroyEntry::GetEntryName() const | ||
{ | ||
return "Destroy"; | ||
} | ||
|
||
//-------------------------------------------------------------------------------------- | ||
string UndoRedoDestroyEntry::GetObjectName() const | ||
{ | ||
return super::GetObjectName(); | ||
} | ||
|
||
//-------------------------------------------------------------------------------------- | ||
string UndoRedoDestroyEntry::GetDescription() const | ||
{ | ||
return fmt::sprintf("(%s) \"%s\"", m_className, m_objectName); | ||
} | ||
|
||
//-------------------------------------------------------------------------------------- | ||
IObject * UndoRedoDestroyEntry::getParent() const | ||
{ | ||
IFactory * factory = Kernel::getFactory(); | ||
return factory->FindByUID(m_parentUID); | ||
} | ||
|
||
//-------------------------------------------------------------------------------------- | ||
void UndoRedoDestroyEntry::Undo() | ||
{ | ||
VG_INFO("[Undo/Redo] Undo Destroy Object %s (UID=0x%08X)", GetDescription().c_str(), m_objectUID); | ||
|
||
Factory * factory = (Factory *)Kernel::getFactory(); | ||
|
||
if (IGameObject * parent = dynamic_cast<IGameObject*>(getParent())) | ||
{ | ||
IGameObject * obj = (IGameObject*)factory->CreateObject(m_className.c_str(), m_objectName, parent); | ||
m_buffer.resetRead(); | ||
factory->serializeObjectFromMemory(obj, m_buffer); | ||
VG_ASSERT(m_objectUID == obj->GetUID()); | ||
|
||
parent->AddChild(obj); | ||
//obj->OnLoad(); | ||
obj->Release(); | ||
} | ||
} | ||
|
||
//-------------------------------------------------------------------------------------- | ||
void UndoRedoDestroyEntry::Redo() | ||
{ | ||
VG_INFO("[Undo/Redo] Redo Destroy Object \"%s\" (UID=0x%08X)", m_objectName.c_str(), m_objectUID); | ||
|
||
if (auto * obj = dynamic_cast<IGameObject *>(GetObject())) | ||
{ | ||
if (auto * parent = dynamic_cast<IGameObject *>(obj->GetParent())) | ||
parent->RemoveChild(obj); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.