Skip to content

Commit c8e69bf

Browse files
committed
refactoring
1 parent 4fc61bc commit c8e69bf

File tree

16 files changed

+1730
-204
lines changed

16 files changed

+1730
-204
lines changed

Assets/Plugins/TextMesh Pro/Resources/Fonts & Materials/LiberationSans SDF - Fallback.asset

Lines changed: 1386 additions & 27 deletions
Large diffs are not rendered by default.

Assets/ScriptableObjects/Levels/Levels.asset

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ MonoBehaviour:
1313
m_Name: Levels
1414
m_EditorClassIdentifier:
1515
_levels:
16+
- {fileID: 11400000, guid: 969abf9905e44c34a83e9618e313130d, type: 2}
17+
- {fileID: 11400000, guid: a38ad66e62dc02740aa4725e1ffce7a5, type: 2}
18+
- {fileID: 11400000, guid: 5e3ee75d318f63344ba7c75e0f39c67a, type: 2}
1619
- {fileID: 11400000, guid: ab2e9c59beb93e44a876e6e79d14934e, type: 2}
1720
- {fileID: 11400000, guid: a555c1d7d7ddacc4887a07dabd9976d2, type: 2}
1821
- {fileID: 11400000, guid: f9db246a5941ff645a083ac5150ce1e7, type: 2}
@@ -25,11 +28,8 @@ MonoBehaviour:
2528
- {fileID: 11400000, guid: dae7e9792f8d5774292a944bd2ad1250, type: 2}
2629
- {fileID: 11400000, guid: d6aeb77fa82a2a0488dea096946304c0, type: 2}
2730
- {fileID: 11400000, guid: b36d6b4ce759c264f8931759d122b2ef, type: 2}
28-
- {fileID: 11400000, guid: 5e3ee75d318f63344ba7c75e0f39c67a, type: 2}
2931
- {fileID: 11400000, guid: 713ba49b5dd872345a9c0a43e045ef9f, type: 2}
30-
- {fileID: 11400000, guid: 969abf9905e44c34a83e9618e313130d, type: 2}
3132
- {fileID: 11400000, guid: 15a99b2ddf32a1a478a2ae41a0d15119, type: 2}
3233
- {fileID: 11400000, guid: b15f35c4fb114e9479c5e1fe3cd7f096, type: 2}
3334
- {fileID: 11400000, guid: 920b6c1885d43fb439798895a4ec91a2, type: 2}
34-
- {fileID: 11400000, guid: a38ad66e62dc02740aa4725e1ffce7a5, type: 2}
3535
- {fileID: 11400000, guid: 8d8ac44a2d8598042926097d963d74a7, type: 2}

Assets/Scripts/Board/BoardSolver.cs

Lines changed: 13 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,23 @@
11
using Cysharp.Threading.Tasks;
2-
using UnityEngine;
32
using UnityEngine.Events;
43

5-
6-
7-
public class RegularBoardFiller
8-
{
9-
private ConfigFactory<int, IItem> _itemFactory;
10-
private ItemInCellInjector _itemInCellInjector;
11-
12-
public RegularBoardFiller(ConfigFactory<int, IItem> itemFactory)
13-
{
14-
_itemFactory = itemFactory;
15-
_itemInCellInjector = new();
16-
}
17-
18-
public async UniTask TryFillCellRegularItem(ICell cell, params Vector3[] path)
19-
{
20-
bool isNeedToFill = cell.HasItem == false && cell.CanContainsItem;
21-
if (isNeedToFill)
22-
{
23-
await FillCellRegularItem(cell, path);
24-
}
25-
}
26-
private async UniTask FillCellRegularItem(ICell cell, params Vector3[] path)
27-
{
28-
var item = _itemFactory.Get(cell.GridPosition.ColumnIndex);
29-
await _itemInCellInjector.InjectItemInCell(item, cell, path);
30-
}
31-
}
32-
33-
34-
35-
36-
37-
38-
39-
40-
41-
42-
43-
44-
454
public class BoardSolver
465
{
47-
private SolveSlotsDetecor _solveSlotsDetecor;
48-
private ItemSwaper _itemSwaper;
49-
private IBoardFaller _boardFaller;
50-
private IBoardFiller _boardFiller;
516
private BoostExicuter _boostExicuter;
52-
private PositionMemory _positionMemory;
53-
private ItemNextStateMover _itemStateMover;
54-
private ObstilcleSolver _obstilcleSolver;
55-
private BoardClearer _boardClearer;
7+
private SequenceSolver _sequenceSolver;
8+
private ISwapSolwer _regularSwapSolver;
9+
private ISwapSolwer _boostSwapSolver;
5610

5711
public event UnityAction CountedSwapMaked;
5812

59-
public BoardSolver(SolveSlotsDetecor solveSlotsDetecor, ItemSwaper itemSwaper, IBoardFiller boardFiller, Board board, BoostExicuter boostExicuter)
13+
public BoardSolver(Workers workers, ItemSwaper itemSwaper, BoostExicuter boostExicuter)
6014
{
61-
_solveSlotsDetecor = solveSlotsDetecor;
62-
_itemSwaper = itemSwaper;
63-
_boardFiller = boardFiller;
64-
65-
_boardFaller = new DownBoardFaller(board);
66-
_boardClearer = new(board);
67-
_positionMemory = new(board);
68-
_itemStateMover = new();
6915
_boostExicuter = boostExicuter;
70-
_obstilcleSolver = new(board);
16+
_sequenceSolver = new(workers);
17+
18+
_regularSwapSolver = new RegularSwapSolwer(workers.SolveSlotsDetecor, itemSwaper, _sequenceSolver, () => CountedSwapMaked?.Invoke());
19+
_boostSwapSolver = new BoostSwapSolver(_boostExicuter, () => CountedSwapMaked?.Invoke());
20+
7121
}
7222

7323
public async UniTask SolveSwap(ICell selectedCell, ICell cell)
@@ -76,131 +26,23 @@ public async UniTask SolveSwap(ICell selectedCell, ICell cell)
7626

7727
if (isBoostSwap)
7828
{
79-
await SolveBoostSwap(selectedCell, cell);
29+
await _boostSwapSolver.SolveSwap(selectedCell, cell);
30+
await SolveBoard();
8031
}
8132
else
8233
{
83-
await SolveRegularSwap(selectedCell, cell);
34+
await _regularSwapSolver.SolveSwap(selectedCell, cell);
8435
}
8536
}
8637

87-
private async UniTask SolveBoostSwap(ICell selectedCell, ICell cell)
88-
{
89-
CountedSwapMaked?.Invoke();
90-
91-
if (selectedCell.Item is IBoostItem selectedBoost)
92-
{
93-
selectedBoost.SwapWith = cell.Item;
94-
await _boostExicuter.Execute(selectedBoost);//ToDo: await нужно ожидать паралельно у обоих бустов?
95-
}
96-
97-
if (cell.Item is IBoostItem boost)
98-
{
99-
boost.SwapWith = selectedCell.Item;
100-
await _boostExicuter.Execute(boost);//ToDo: await нужно ожидать паралельно у обоих бустов?
101-
}
102-
103-
_boardClearer.ClearBordFromDeadItems();
104-
105-
await _boardFaller.FallBoard();
106-
await _boardFiller.FillBoard();
107-
await SolveAllSequence();
108-
}
10938

11039
public async UniTask SolveBoard()
11140
{
112-
_boardClearer.ClearBordFromDeadItems();
113-
await _boardFaller.FallBoard();
114-
await _boardFiller.FillBoard();
115-
await SolveAllSequence();
41+
await _sequenceSolver.FallAndSolve();
11642
}
11743

118-
private async UniTask SolveRegularSwap(ICell selectedCell, ICell cell)
119-
{
120-
bool isMatchExist = _solveSlotsDetecor.TryGetSequence(selectedCell.GridPosition, out var sequence) ||
121-
_solveSlotsDetecor.TryGetSequence(cell.GridPosition, out sequence);
122-
123-
if (isMatchExist)
124-
{
125-
await CreateRegularSwapWithExistingMath(sequence);
126-
}
127-
else
128-
{
129-
await _itemSwaper.SwapItems(cell, selectedCell);
130-
}
131-
}
132-
133-
private async UniTask CreateRegularSwapWithExistingMath(MatchSequence sequence)
134-
{
135-
CountedSwapMaked?.Invoke();
136-
137-
await SolveSequence(sequence);
138-
139-
await SolveAllSequence();
140-
}
141-
142-
private async UniTask SolveAllSequence()
143-
{
144-
var positions = _positionMemory.GetUppdatedGridPositions();
145-
146-
while (_solveSlotsDetecor.TryGetBestSequence(positions, out var sequence))
147-
{
148-
await SolveSequence(sequence);
149-
150-
positions = _positionMemory.GetUppdatedGridPositions();
151-
}
15244

153-
_positionMemory.RememorizeAllPositions();
154-
}
155-
156-
private async UniTask SolveSequence(MatchSequence sequence)
157-
{
158-
await _obstilcleSolver.SolveAll(sequence);
159-
await SolveItemInSequence(sequence);
160-
161-
_boardClearer.ClearBordFromDeadItems();
162-
await _boardFaller.FallBoard();
163-
await _boardFiller.FillBoard();
164-
}
16545

166-
private async UniTask SolveItemInSequence(MatchSequence sequence)
167-
{
168-
await _itemStateMover.SetNextStateSequence(sequence);
169-
170-
bool isNeedToSpawnBoost = sequence.Type != SequenceTypes.Three;
171-
if (isNeedToSpawnBoost)
172-
{
173-
SpawnBoostIn(sequence);
174-
}
175-
}
176-
177-
private void SpawnBoostIn(MatchSequence sequence)
178-
{
179-
var origin = sequence.Origin;
180-
var type = sequence.Type;
181-
182-
_boardFiller.FillBoostInCell(ConvertCequenceToBoost(type), origin);
183-
}
184-
185-
private BoostTypes ConvertCequenceToBoost(SequenceTypes boostTypes)
186-
{
187-
switch (boostTypes)
188-
{
189-
case SequenceTypes.FourHorisontal:
190-
return BoostTypes.Vertical;
191-
case SequenceTypes.FourVertical:
192-
return BoostTypes.Horizontal;
193-
case SequenceTypes.FiveLine:
194-
return BoostTypes.Rainbow;
195-
case SequenceTypes.TShape:
196-
case SequenceTypes.LShape:
197-
return BoostTypes.Bomb;
198-
case SequenceTypes.Square:
199-
return BoostTypes.Rocket;
200-
default:
201-
return BoostTypes.None;
202-
}
203-
}
20446

20547

20648
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using Cysharp.Threading.Tasks;
2+
using UnityEngine.Events;
3+
4+
public class BoostSwapSolver : ISwapSolwer
5+
{
6+
private BoostExicuter _boostExicuter;
7+
private UnityAction _swapCallback;
8+
9+
public BoostSwapSolver(BoostExicuter boostExicuter, UnityAction swapCallback)
10+
{
11+
_boostExicuter = boostExicuter;
12+
_swapCallback = swapCallback;
13+
}
14+
15+
public async UniTask SolveSwap(ICell selectedCell, ICell cell)
16+
{
17+
_swapCallback?.Invoke();
18+
19+
if (selectedCell.Item is IBoostItem selectedBoost)
20+
{
21+
selectedBoost.SwapWith = cell.Item;
22+
await _boostExicuter.Execute(selectedBoost);//ToDo: await нужно ожидать паралельно у обоих бустов?
23+
}
24+
25+
if (cell.Item is IBoostItem boost)
26+
{
27+
boost.SwapWith = selectedCell.Item;
28+
await _boostExicuter.Execute(boost);//ToDo: await нужно ожидать паралельно у обоих бустов?
29+
}
30+
}
31+
32+
33+
}
34+
35+
36+
37+

Assets/Scripts/Board/BoostSwapSolver.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Cysharp.Threading.Tasks;
2+
using UnityEngine.Events;
3+
4+
public interface ISwapSolwer
5+
{
6+
UniTask SolveSwap(ICell selectedCell, ICell cell);
7+
}
8+
9+
10+
11+

Assets/Scripts/Board/ISwapSolwer.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Cysharp.Threading.Tasks;
2+
using UnityEngine;
3+
4+
public class RegularBoardFiller
5+
{
6+
private ConfigFactory<int, IItem> _itemFactory;
7+
private ItemInCellInjector _itemInCellInjector;
8+
9+
public RegularBoardFiller(ConfigFactory<int, IItem> itemFactory)
10+
{
11+
_itemFactory = itemFactory;
12+
_itemInCellInjector = new();
13+
}
14+
15+
public async UniTask TryFillCellRegularItem(ICell cell, params Vector3[] path)
16+
{
17+
bool isNeedToFill = cell.HasItem == false && cell.CanContainsItem;
18+
if (isNeedToFill)
19+
{
20+
await FillCellRegularItem(cell, path);
21+
}
22+
}
23+
private async UniTask FillCellRegularItem(ICell cell, params Vector3[] path)
24+
{
25+
var item = _itemFactory.Get(cell.GridPosition.ColumnIndex);
26+
await _itemInCellInjector.InjectItemInCell(item, cell, path);
27+
}
28+
}
29+
30+
31+
32+

Assets/Scripts/Board/RegularBoardFiller.cs.meta

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

0 commit comments

Comments
 (0)