Skip to content

Commit be8293c

Browse files
committed
feat: spawn blocks
1 parent 8d43938 commit be8293c

File tree

9 files changed

+67
-13
lines changed

9 files changed

+67
-13
lines changed

Assets/Code/Infrastructure/BootstrapInstaller.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ private void BindFactory()
2929
{
3030
Container.BindInterfacesTo<UIFactory>().AsSingle();
3131
Container.BindInterfacesTo<TileFactory>().AsSingle();
32+
Container.BindInterfacesTo<BlockFactory>().AsSingle();
3233
}
3334

3435
private void BindSaveLoad() =>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using UnityEngine;
2+
using Zenject;
3+
4+
namespace Code.Infrastructure.Generator.Factory
5+
{
6+
public class BlockFactory : Infrastructure.Factory.Factory, IBlockFactory
7+
{
8+
private const string TilePrefabPath = "Tile/Tile";
9+
10+
public BlockFactory(IInstantiator instantiator) : base(instantiator)
11+
{
12+
13+
}
14+
15+
public GameObject CreateBlock(GameObject prefab,GameObject parent)
16+
{
17+
var blockGameObject = Instantiate(prefab, parent.transform);
18+
return blockGameObject;
19+
}
20+
}
21+
}

Assets/Code/Infrastructure/Generator/Factory/BlockFactory.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using UnityEngine;
2+
3+
namespace Code.Infrastructure.Generator.Factory
4+
{
5+
public interface IBlockFactory
6+
{
7+
GameObject CreateBlock(GameObject prefab,GameObject parent);
8+
}
9+
}

Assets/Code/Infrastructure/Generator/Factory/IBlockFactory.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Code/Infrastructure/Generator/Services/LevelGeneratorService.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Code.Infrastructure.Generator.Factory;
22
using Code.Infrastructure.Services.StaticData;
33
using Code.Infrastructure.StaticData;
4+
using Code.LevelEditor;
45
using DG.Tweening;
56
using UnityEngine;
67

@@ -14,13 +15,16 @@ public class LevelGeneratorService : ILevelGeneratorService
1415

1516
private readonly IStaticDataService _staticDataService;
1617
private readonly ITileFactory _tileFactory;
18+
private readonly IBlockFactory _blockFactory;
1719

1820
public LevelGeneratorService(
1921
IStaticDataService staticDataService,
20-
ITileFactory tileFactory)
22+
ITileFactory tileFactory,
23+
IBlockFactory blockFactory)
2124
{
2225
_staticDataService = staticDataService;
2326
_tileFactory = tileFactory;
27+
_blockFactory = blockFactory;
2428
}
2529

2630
public void SetUpRootMapHolder(GameObject rootMapHolder)
@@ -45,15 +49,15 @@ public void CleanUp()
4549

4650
public void GenerateLevel()
4751
{
48-
CleanUp(); // 👈 очищаем предыдущую генерацию
49-
5052
const int gridSize = 11;
5153
_tileMatrix = new Tile[gridSize, gridSize];
5254

5355
TileBalanceData tileBalanceData = _staticDataService.Balance.TileBalanceData;
5456

5557
float baseDelay = 0.02f;
5658

59+
var levelData = _staticDataService.GetLevelData(_currentLevelIndex.ToString());
60+
5761
for (int y = 0; y < gridSize; y++)
5862
{
5963
for (int x = 0; x < gridSize; x++)
@@ -66,14 +70,24 @@ public void GenerateLevel()
6670

6771
Tile tile = _tileFactory.CreateTile(_rootMapHolder);
6872
tile.transform.localPosition = spawnPosition;
69-
73+
7074
bool isEven = (x + y) % 2 == 0;
7175
Color tileColor = isEven ? tileBalanceData.ColorEven : tileBalanceData.ColorNotEven;
7276
tile.SetColor(tileColor);
7377
tile.SetUpScale();
7478
float delay = (x + y) * baseDelay;
7579
DOVirtual.DelayedCall(delay, tile.PlayAnimationShowTile);
7680

81+
LevelCell cellData = levelData.Cells[x, y];
82+
if (cellData != null && cellData.Block != null)
83+
{
84+
GameObject block = _blockFactory.CreateBlock(cellData.Block.Prefab,tile.gameObject);
85+
block.transform.rotation = cellData.Rotation;
86+
87+
tile.SetBlock(block);
88+
DOVirtual.DelayedCall(delay, tile.PlayAnimationShowBlock);
89+
}
90+
7791
_tileMatrix[x, y] = tile;
7892
}
7993
}

Assets/Code/LevelEditor/LevelCell.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ namespace Code.LevelEditor
77
public class LevelCell
88
{
99
public BlockDataEditor Block;
10-
public Quaternion Rotation = Quaternion.identity;
10+
[SerializeField] public Quaternion Rotation = Quaternion.identity;
1111
}
1212
}

Assets/Code/LevelEditor/LevelHegsagonEditor.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,6 @@ private void DrawCellContent(Rect rect, LevelCell cell)
9393
DrawBlockId(rect, cell.Block.ID);
9494
DrawRotationArrow(rect, cell.Rotation);
9595
}
96-
else
97-
{
98-
// EditorGUI.DrawRect(rect.Padding(4), Color.gray);
99-
}
10096
}
10197

10298
private void DrawHexagonOutline(Rect rect)
@@ -136,17 +132,20 @@ private void DrawRotationArrow(Rect rect, Quaternion rotation)
136132
{
137133
var oldMatrix = GUI.matrix;
138134
Vector2 center = rect.center;
139-
GUIUtility.RotateAroundPivot(rotation.eulerAngles.z, center);
135+
136+
float angle = rotation.eulerAngles.y;
137+
GUIUtility.RotateAroundPivot(angle, center);
138+
140139
GUI.Label(new Rect(center.x - 10, rect.yMin - 4, 25, 25), "↑", new GUIStyle(GUI.skin.label)
141140
{
142141
alignment = TextAnchor.UpperCenter,
143142
fontSize = 25,
144143
normal = { textColor = Color.green },
145144
fontStyle = FontStyle.Bold
146145
});
146+
147147
GUI.matrix = oldMatrix;
148148
}
149-
150149
private void DrawSelectionOverlay(Rect rect, int x, int y)
151150
{
152151
if (_currentSelection.Contains(new Vector2Int(x, y)))

Assets/Code/LevelEditor/LevelMatrixEditor.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ private void DrawRotationArrow(Rect rect, Quaternion rotation)
9292
{
9393
var oldMatrix = GUI.matrix;
9494
Vector2 center = rect.center;
95-
GUIUtility.RotateAroundPivot(rotation.eulerAngles.z, center);
95+
96+
float angle = rotation.eulerAngles.y;
97+
GUIUtility.RotateAroundPivot(angle, center);
9698

9799
GUI.Label(new Rect(center.x - 10, rect.yMin - 4, 25, 25), "↑", new GUIStyle(GUI.skin.label)
98100
{
@@ -205,7 +207,9 @@ private void ApplyBlock(BlockDataEditor block, LevelCell fallbackCell)
205207

206208
private void ApplyRotation(float angle, LevelCell fallbackCell)
207209
{
208-
Quaternion rotation = Quaternion.Euler(0, 0, angle);
210+
Debug.Log($"⟳ Apply Rotation: {angle}°");
211+
212+
Quaternion rotation = Quaternion.Euler(0, angle, 0);
209213

210214
if (currentSelection.Count > 0)
211215
{

0 commit comments

Comments
 (0)