using System.Collections; using System.Collections.Generic; using UnityEngine; public class RotateblockCommand : ICommand { private string blockId; private Quaternion newRotation; private Quaternion previousRotation; private Environment environment; private Transform blockTransform; public RotateblockCommand(string blockId, Quaternion newRotation) { this.blockId = blockId; this.newRotation = newRotation; this.environment = Environment.getInstance(); } public RotateblockCommand(CommandDTO commandDTO) { this.blockId = commandDTO.Parameters["blockId"].ToString(); this.newRotation = (Quaternion)commandDTO.Parameters["newRotation"]; this.environment = Environment.getInstance(); } public void execute() { blockTransform = environment.getBlock(blockId)?.transform; if (blockTransform != null) { previousRotation = blockTransform.rotation; blockTransform.rotation = newRotation; } else { Debug.LogWarning("RotateblockCommand: block with ID " + blockId + " not found."); } } public void undo() { blockTransform = environment.getBlock(blockId)?.transform; if (blockTransform != null) { blockTransform.rotation = previousRotation; } } public CommandDTO toDTO() { return new CommandDTO.CommandDTOBuilder() .SetCommandName("RotateCommand") .AddParameter("blockId", blockId) .AddParameter("newRotation", newRotation) .Build(); } }