Initial commit
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class DeleteBlockCommand : ICommand
|
||||
{
|
||||
private string blockId;
|
||||
private string prefabDeletedId;
|
||||
private Vector3 blockInitialPosition;
|
||||
private Quaternion blockInitialRotation;
|
||||
private BlockFactory factory;
|
||||
private Environment environment;
|
||||
|
||||
public DeleteBlockCommand(string blockId)
|
||||
{
|
||||
this.blockId = blockId;
|
||||
this.factory = BlockFactory.getInstance();
|
||||
this.environment = Environment.getInstance();
|
||||
}
|
||||
|
||||
public DeleteBlockCommand(CommandDTO commandDTO)
|
||||
{
|
||||
this.blockId = commandDTO.Parameters["blockId"].ToString();
|
||||
this.factory = BlockFactory.getInstance();
|
||||
this.environment = Environment.getInstance();
|
||||
}
|
||||
|
||||
public void execute()
|
||||
{
|
||||
Block block = environment.getBlock(blockId);
|
||||
if (block != null)
|
||||
{
|
||||
blockInitialPosition = block.transform.position;
|
||||
blockInitialRotation = block.transform.rotation;
|
||||
prefabDeletedId = block.getBlockData()?.blockName;
|
||||
environment.removeBlock(blockId);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("DeleteblockCommand: block with ID " + blockId + " not found.");
|
||||
}
|
||||
}
|
||||
|
||||
public void undo()
|
||||
{
|
||||
factory.createblock(prefabDeletedId, blockInitialPosition, blockInitialRotation, blockId);
|
||||
}
|
||||
public CommandDTO toDTO()
|
||||
{
|
||||
return new CommandDTO.CommandDTOBuilder()
|
||||
.SetCommandName("DeleteCommand")
|
||||
.AddParameter("blockId", blockId)
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user