using Newtonsoft.Json; using System.Collections; using System.Collections.Generic; using UnityEngine; public class CommandDTO { [JsonProperty] private string commandName; [JsonProperty] private Dictionary parameters = new Dictionary(); public string CommandName => commandName; public Dictionary 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 parameters = new Dictionary(); 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; } } }