56 lines
1.6 KiB
C#
56 lines
1.6 KiB
C#
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();
|
|
}
|
|
}
|