Initial commit
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class MoveBlockCommand : ICommand
|
||||
{
|
||||
private string blockId;
|
||||
private Vector3 previousPosition;
|
||||
private Quaternion previousRotation;
|
||||
private Vector3 newPosition;
|
||||
private Quaternion newRotation;
|
||||
private Environment environment;
|
||||
private Transform blockTransform;
|
||||
|
||||
public MoveBlockCommand(string blockId, Vector3 previousPosition, Vector3 newPosition, Quaternion previousRotation, Quaternion newRotation)
|
||||
{
|
||||
this.blockId = blockId;
|
||||
this.newPosition = newPosition;
|
||||
this.previousPosition = previousPosition;
|
||||
this.environment = Environment.getInstance();
|
||||
this.previousRotation = previousRotation;
|
||||
this.newRotation = newRotation;
|
||||
}
|
||||
|
||||
public MoveBlockCommand(CommandDTO commandDTO)
|
||||
{
|
||||
this.blockId = commandDTO.Parameters["blockId"].ToString();
|
||||
this.newPosition = (Vector3)commandDTO.Parameters["newPosition"];
|
||||
this.previousPosition = (Vector3)commandDTO.Parameters["previousPosition"];
|
||||
this.newRotation = (Quaternion)commandDTO.Parameters["newRotation"];
|
||||
this.previousRotation = (Quaternion)commandDTO.Parameters["previousRotation"];
|
||||
this.environment = Environment.getInstance();
|
||||
}
|
||||
|
||||
public void execute()
|
||||
{
|
||||
Block block = environment.getBlock(blockId);
|
||||
if (block != null)
|
||||
environment.moveBlock(block, previousPosition, previousRotation, newPosition, newRotation);
|
||||
else
|
||||
Debug.LogWarning("MoveblockCommand: block with ID " + blockId + " not found.");
|
||||
}
|
||||
|
||||
public void undo()
|
||||
{
|
||||
Block block = environment.getBlock(blockId);
|
||||
if (block != null)
|
||||
environment.moveBlock(block, newPosition, newRotation, previousPosition, previousRotation);
|
||||
else
|
||||
Debug.LogWarning("MoveblockCommand: block with ID " + blockId + " not found.");
|
||||
}
|
||||
|
||||
public CommandDTO toDTO()
|
||||
{
|
||||
return new CommandDTO.CommandDTOBuilder()
|
||||
.SetCommandName("MoveCommand")
|
||||
.AddParameter("blockId", blockId)
|
||||
.AddParameter("newPosition", newPosition)
|
||||
.AddParameter("previousPosition", previousPosition)
|
||||
.AddParameter("newRotation", newRotation)
|
||||
.AddParameter("previousRotation", previousRotation)
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user