gameobj_props_change_command.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Flexlay - A Generic 2D Game Editor
  2. # Copyright (C) 2016 Karkus476 <karkus476@yahoo.com>
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See this
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. from typing import Any, TYPE_CHECKING
  17. from flexlay.commands.command import Command
  18. if TYPE_CHECKING:
  19. from supertux.gameobj import GameObj
  20. class GameObjPropsChangeCommand(Command):
  21. """
  22. This Command is run when a set of properties of an object are
  23. changed.
  24. """
  25. def __init__(self, gameobj: 'GameObj', prop_diff: list[tuple[Any, Any, Any]]) -> None:
  26. """It's probably not a good idea to use this for non-directly
  27. editable properties.
  28. Warning: This will accept any value
  29. :param gameobj: GameObj this affects
  30. :param prop_diff: list of tuples of the form:
  31. (prop_index, execute_value, undo_value)
  32. """
  33. super().__init__()
  34. self.gameobj = gameobj
  35. self.prop_diff = prop_diff
  36. def execute(self) -> None:
  37. for diff in self.prop_diff:
  38. print(self.gameobj.properties[diff[0]].value, "=", diff[1])
  39. self.gameobj.properties[diff[0]].value = diff[1]
  40. def redo(self) -> None:
  41. for diff in self.prop_diff:
  42. self.gameobj.properties[diff[0]].value = diff[1]
  43. def undo(self) -> None:
  44. for diff in self.prop_diff:
  45. self.gameobj.properties[diff[0]].value = diff[2]
  46. # EOF #