BsCmdCloneSO.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsCmdCloneSO.h"
  4. #include "BsSceneObject.h"
  5. namespace BansheeEngine
  6. {
  7. CmdCloneSO::CmdCloneSO(const WString& description, const Vector<HSceneObject>& originals)
  8. :EditorCommand(description), mOriginals(originals)
  9. {
  10. }
  11. CmdCloneSO::~CmdCloneSO()
  12. {
  13. }
  14. HSceneObject CmdCloneSO::execute(const HSceneObject& sceneObject, const WString& description)
  15. {
  16. // Register command and commit it
  17. CmdCloneSO* command = new (bs_alloc<CmdCloneSO>()) CmdCloneSO(description, { sceneObject });
  18. UndoRedo::instance().registerCommand(command);
  19. command->commit();
  20. if (command->mClones.size() > 0)
  21. return command->mClones[0];
  22. return HSceneObject();
  23. }
  24. Vector<HSceneObject> CmdCloneSO::execute(const Vector<HSceneObject>& sceneObjects, const WString& description)
  25. {
  26. // Register command and commit it
  27. CmdCloneSO* command = new (bs_alloc<CmdCloneSO>()) CmdCloneSO(description, sceneObjects);
  28. UndoRedo::instance().registerCommand(command);
  29. command->commit();
  30. return command->mClones;
  31. }
  32. void CmdCloneSO::commit()
  33. {
  34. mClones.clear();
  35. for (auto& original : mOriginals)
  36. {
  37. if (!original.isDestroyed())
  38. mClones.push_back(original->clone());
  39. }
  40. }
  41. void CmdCloneSO::revert()
  42. {
  43. for (auto& clone : mClones)
  44. {
  45. if (!clone.isDestroyed())
  46. clone->destroy(true);
  47. }
  48. mClones.clear();
  49. }
  50. }