Files
JuegoSim/Assets/_Project/Scripts/Code/CommandLayer/CommandDTO.cs
T
2026-07-21 08:56:10 +03:00

62 lines
1.8 KiB
C#

using Newtonsoft.Json;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CommandDTO
{
[JsonProperty]
private string commandName;
[JsonProperty]
private Dictionary<string, object> parameters = new Dictionary<string, object>();
public string CommandName => commandName;
public Dictionary<string, object> Parameters => parameters;
public ICommand converToCommand()
{
// Implementation for converting DTO to Command
switch (commandName)
{
case "CreateCommand":
return new CreateBlockCommand(this);
case "MoveCommand":
return new MoveBlockCommand(this);
case "RotateCommand":
return new RotateblockCommand(this);
case "DeleteCommand":
return new DeleteBlockCommand(this);
case "DeleteGroup":
return new DeleteGroupCommand(this);
default:
Debug.LogWarning($"Unknown command name: {commandName}");
return null;
}
}
public class CommandDTOBuilder
{
private string commandName;
private Dictionary<string, object> parameters = new Dictionary<string, object>();
public CommandDTOBuilder SetCommandName(string name)
{
this.commandName = name;
return this;
}
public CommandDTOBuilder AddParameter(string key, object value)
{
parameters[key] = value;
return this;
}
public CommandDTO Build()
{
CommandDTO commandDTO = new CommandDTO();
commandDTO.commandName = this.commandName;
commandDTO.parameters = this.parameters;
return commandDTO;
}
}
}