Initial commit
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user