Initial commit

This commit is contained in:
HussienX72u
2026-07-21 08:56:10 +03:00
commit 4017028111
9410 changed files with 2150500 additions and 0 deletions
@@ -0,0 +1,65 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CreateBlockCommand : ICommand
{
private string prefabId;
private Vector3 position;
private Quaternion rotation;
private GameObject objectCreated;
private string blockId;
private bool layerDiff;
private BlockFactory factory;
private Environment environment;
public CreateBlockCommand(string prefabId, Vector3 position, Quaternion rotation, bool LayerDiff = false)
{
this.prefabId = prefabId;
this.position = position;
this.rotation = rotation;
this.layerDiff = LayerDiff;
this.factory = BlockFactory.getInstance();
this.environment = Environment.getInstance();
}
public CreateBlockCommand(CommandDTO commandDTO)
{
this.prefabId = commandDTO.Parameters["prefabId"].ToString();
this.position = (Vector3)commandDTO.Parameters["position"];
this.rotation = (Quaternion)commandDTO.Parameters["rotation"];
this.layerDiff = (bool)commandDTO.Parameters["layerDiff"];
this.factory = BlockFactory.getInstance();
this.environment = Environment.getInstance();
}
public void execute()
{
objectCreated = factory.createblock(prefabId, position, rotation, blockId, layerDiff);
if (objectCreated != null)
{
Block blockComponent = objectCreated.GetComponent<Block>();
blockId = blockComponent.getBlockId();
}
else
{
Debug.LogWarning("CreateblockCommand: Could not create block with prefab ID " + prefabId);
}
}
public void undo()
{
environment.removeBlock(blockId);
}
public CommandDTO toDTO()
{
return new CommandDTO.CommandDTOBuilder()
.SetCommandName("CreateCommand")
.AddParameter("prefabId", prefabId)
.AddParameter("position", position)
.AddParameter("rotation", rotation)
.AddParameter("layerDiff", layerDiff)
.Build();
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6846488550ca76e49ab5a48c410f5f00
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -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();
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8631dad80687e2b45a2d8ec6ca40f879
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,50 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DeleteGroupCommand : ICommand
{
private List<string> blocksId;
private List<DeleteBlockCommand> deleteBlockCommands;
public DeleteGroupCommand(List<string> blocksId)
{
this.blocksId = blocksId;
deleteBlockCommands = new List<DeleteBlockCommand>();
}
public DeleteGroupCommand(CommandDTO commandDTO)
{
this.blocksId = (List<string>)commandDTO.Parameters["blocksId"];
deleteBlockCommands = new List<DeleteBlockCommand>();
}
public void execute()
{
deleteBlockCommands.Clear();
foreach (string id in blocksId)
{
DeleteBlockCommand command = new DeleteBlockCommand(id);
command.execute();
deleteBlockCommands.Add(command);
}
}
public void undo()
{
foreach (DeleteBlockCommand command in deleteBlockCommands)
{
command.undo();
}
}
public CommandDTO toDTO()
{
return new CommandDTO.CommandDTOBuilder()
.SetCommandName("DeleteGroup")
.AddParameter("blocksId", blocksId)
.Build();
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e09c34ca40233944e8c2702acea7eb90
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,6 @@
public interface ICommand
{
void execute();
void undo();
CommandDTO toDTO();
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: da8cfd5f6fb13e2479900c9d4caafa4c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,64 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveBlockCommand : ICommand
{
private string blockId;
private Vector3 previousPosition;
private Quaternion previousRotation;
private Vector3 newPosition;
private Quaternion newRotation;
private Environment environment;
private Transform blockTransform;
public MoveBlockCommand(string blockId, Vector3 previousPosition, Vector3 newPosition, Quaternion previousRotation, Quaternion newRotation)
{
this.blockId = blockId;
this.newPosition = newPosition;
this.previousPosition = previousPosition;
this.environment = Environment.getInstance();
this.previousRotation = previousRotation;
this.newRotation = newRotation;
}
public MoveBlockCommand(CommandDTO commandDTO)
{
this.blockId = commandDTO.Parameters["blockId"].ToString();
this.newPosition = (Vector3)commandDTO.Parameters["newPosition"];
this.previousPosition = (Vector3)commandDTO.Parameters["previousPosition"];
this.newRotation = (Quaternion)commandDTO.Parameters["newRotation"];
this.previousRotation = (Quaternion)commandDTO.Parameters["previousRotation"];
this.environment = Environment.getInstance();
}
public void execute()
{
Block block = environment.getBlock(blockId);
if (block != null)
environment.moveBlock(block, previousPosition, previousRotation, newPosition, newRotation);
else
Debug.LogWarning("MoveblockCommand: block with ID " + blockId + " not found.");
}
public void undo()
{
Block block = environment.getBlock(blockId);
if (block != null)
environment.moveBlock(block, newPosition, newRotation, previousPosition, previousRotation);
else
Debug.LogWarning("MoveblockCommand: block with ID " + blockId + " not found.");
}
public CommandDTO toDTO()
{
return new CommandDTO.CommandDTOBuilder()
.SetCommandName("MoveCommand")
.AddParameter("blockId", blockId)
.AddParameter("newPosition", newPosition)
.AddParameter("previousPosition", previousPosition)
.AddParameter("newRotation", newRotation)
.AddParameter("previousRotation", previousRotation)
.Build();
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: eb9209f3464c8224eb210299f2a742ea
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,57 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RotateblockCommand : ICommand
{
private string blockId;
private Quaternion newRotation;
private Quaternion previousRotation;
private Environment environment;
private Transform blockTransform;
public RotateblockCommand(string blockId, Quaternion newRotation)
{
this.blockId = blockId;
this.newRotation = newRotation;
this.environment = Environment.getInstance();
}
public RotateblockCommand(CommandDTO commandDTO)
{
this.blockId = commandDTO.Parameters["blockId"].ToString();
this.newRotation = (Quaternion)commandDTO.Parameters["newRotation"];
this.environment = Environment.getInstance();
}
public void execute()
{
blockTransform = environment.getBlock(blockId)?.transform;
if (blockTransform != null)
{
previousRotation = blockTransform.rotation;
blockTransform.rotation = newRotation;
}
else
{
Debug.LogWarning("RotateblockCommand: block with ID " + blockId + " not found.");
}
}
public void undo()
{
blockTransform = environment.getBlock(blockId)?.transform;
if (blockTransform != null)
{
blockTransform.rotation = previousRotation;
}
}
public CommandDTO toDTO()
{
return new CommandDTO.CommandDTOBuilder()
.SetCommandName("RotateCommand")
.AddParameter("blockId", blockId)
.AddParameter("newRotation", newRotation)
.Build();
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e8100c36e75da6e42a8d788015b34543
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: