Skip to content

Commit 7916b61

Browse files
committed
fix: spawn block
1 parent d61eb01 commit 7916b61

File tree

4 files changed

+196
-193
lines changed

4 files changed

+196
-193
lines changed

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

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,48 +49,52 @@ public void CleanUp()
4949

5050
public void GenerateLevel()
5151
{
52-
const int gridSize = 11;
53-
_tileMatrix = new Tile[gridSize, gridSize];
52+
var levelData = _staticDataService.GetLevelData(_currentLevelIndex.ToString());
53+
int width = levelData.Cells.GetLength(0);
54+
int height = levelData.Cells.GetLength(1);
5455

56+
_tileMatrix = new Tile[width, height];
5557
TileBalanceData tileBalanceData = _staticDataService.Balance.TileBalanceData;
5658

5759
float baseDelay = 0.02f;
5860

59-
var levelData = _staticDataService.GetLevelData(_currentLevelIndex.ToString());
60-
61-
for (int y = 0; y < gridSize; y++)
61+
for (int y = 0; y < height; y++)
6262
{
63-
for (int x = 0; x < gridSize; x++)
63+
for (int x = 0; x < width; x++)
6464
{
65+
int invertedY = height - 1 - y; // для перевёрнутого рендера
66+
6567
Vector3 spawnPosition = new Vector3(
66-
x - gridSize / 2,
68+
x - width / 2,
6769
0f,
68-
y - gridSize / 2
70+
y - height / 2
6971
);
7072

7173
Tile tile = _tileFactory.CreateTile(_rootMapHolder);
7274
tile.transform.localPosition = spawnPosition;
73-
75+
7476
bool isEven = (x + y) % 2 == 0;
7577
Color tileColor = isEven ? tileBalanceData.ColorEven : tileBalanceData.ColorNotEven;
7678
tile.SetColor(tileColor);
7779
tile.SetUpScale();
80+
7881
float delay = (x + y) * baseDelay;
7982
DOVirtual.DelayedCall(delay, tile.PlayAnimationShowTile);
8083

81-
LevelCell cellData = levelData.Cells[x, y];
84+
LevelCell cellData = levelData.Cells[x, invertedY];
8285
if (cellData != null && cellData.Block != null)
8386
{
84-
GameObject block = _blockFactory.CreateBlock(cellData.Block.Prefab,tile.gameObject);
87+
GameObject block = _blockFactory.CreateBlock(cellData.Block.Prefab, tile.gameObject);
8588
block.transform.rotation = cellData.Rotation;
86-
89+
8790
tile.SetBlock(block);
8891
DOVirtual.DelayedCall(delay, tile.PlayAnimationShowBlock);
8992
}
90-
93+
9194
_tileMatrix[x, y] = tile;
9295
}
9396
}
9497
}
98+
9599
}
96100
}

Assets/Code/LevelEditor/LevelMatrixEditor.cs

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

@@ -177,9 +176,9 @@ private void ShowContextMenu(LevelCell cell, int x, int y)
177176
{
178177
currentSelection = new List<Vector2Int> { clickedPos };
179178
}
180-
179+
181180
BlockPopupWindow.LevelEditorHelpers.TryGetCell = pos => GetCell(pos);
182-
181+
183182
BlockPopupWindow.ShowPopup(
184183
rect,
185184
cachedLibrary,
@@ -208,7 +207,7 @@ private void ApplyBlock(BlockDataEditor block, LevelCell fallbackCell)
208207
private void ApplyRotation(float angle, LevelCell fallbackCell)
209208
{
210209
Debug.Log($"⟳ Apply Rotation: {angle}°");
211-
210+
212211
Quaternion rotation = Quaternion.Euler(0, angle, 0);
213212

214213
if (currentSelection.Count > 0)
@@ -248,21 +247,21 @@ private void MarkDirty()
248247
UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
249248
}
250249

251-
private LevelCell GetCell(int x, int y) => Grid[y, x];
252-
public override LevelCell GetCell(Vector2Int pos) => Grid[pos.y, pos.x];
250+
private LevelCell GetCell(int x, int y) => Grid[x, y];
251+
public override LevelCell GetCell(Vector2Int pos) => Grid[pos.x, pos.y];
253252
#endif
254253

255254
public LevelDataDTO GetLevelDataDto()
256255
{
257-
var levelData = new LevelDataDTO(Grid,IndexLevel);
256+
var levelData = new LevelDataDTO(Grid, IndexLevel);
258257
return levelData;
259258
}
260-
259+
261260
public IEnumerable<Vector2Int> GetAllOfType(BlockDataEditor type)
262261
{
263-
for (int y = 0; y < Grid.GetLength(1); y++)
264262
for (int x = 0; x < Grid.GetLength(0); x++)
265-
if (Grid[y, x]?.Block == type)
263+
for (int y = 0; y < Grid.GetLength(1); y++)
264+
if (Grid[x, y]?.Block == type)
266265
yield return new Vector2Int(x, y);
267266
}
268267

@@ -294,4 +293,4 @@ private void ResizeGrid()
294293
Grid = newGrid;
295294
}
296295
}
297-
}
296+
}

0 commit comments

Comments
 (0)