-
Notifications
You must be signed in to change notification settings - Fork 10
Start adding merge strategy, closes #57 #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
dbfbde2
4767c38
840c2e4
24f553e
54cf85e
9cc83df
f58d3fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,6 +57,8 @@ bool isValidServerEvent(ServerWorldEvent event, WorldState state) => | |
| .length - | ||
| 1, | ||
| ), | ||
| CellMergeStrategyChanged() => | ||
| event.span > 0 && event.span <= GameTable.maxMergeSpan, | ||
| DialogOpened() => event.dialog.isValid(), | ||
| _ => true, | ||
| }; | ||
|
|
@@ -313,6 +315,88 @@ ServerProcessed processServerEvent( | |
| teamMembers: Map.from(state.teamMembers)..remove(event.team), | ||
| ), | ||
| ); | ||
| case CellMergeStrategyChanged(): | ||
| return ServerProcessed( | ||
| state.mapTableOrDefault(event.cell.table, (table) { | ||
| final cell = table.getCell(event.cell.position); | ||
| final cells = Map<VectorDefinition, TableCell>.from(table.cells); | ||
|
|
||
| CellMergeDirection? getDirection(CellMergeStrategy? strategy) { | ||
| if (strategy is LayoutCellMergeStrategy) return strategy.direction; | ||
| return null; | ||
| } | ||
|
|
||
| // Cleanup old neighbors | ||
| final oldCell = cells[event.cell.position]; | ||
| final oldStrategy = oldCell?.merge; | ||
| final oldDirection = getDirection(oldStrategy); | ||
| if (oldDirection != null) { | ||
| final oldSpan = table.calculateSpan( | ||
| event.cell.position, | ||
| oldDirection, | ||
| ); | ||
| if (oldSpan > 1) { | ||
| var current = event.cell.position; | ||
| for (var i = 1; i < oldSpan; i++) { | ||
| current = oldDirection == CellMergeDirection.horizontal | ||
| ? VectorDefinition(current.x + 1, current.y) | ||
| : VectorDefinition(current.x, current.y + 1); | ||
|
|
||
| final neighbor = cells[current] ?? TableCell(); | ||
| if (neighbor.merge is MergedCellStrategy && | ||
| (neighbor.merge as MergedCellStrategy).direction == | ||
| oldDirection) { | ||
| final updatedNeighbor = neighbor.copyWith(merge: null); | ||
| if (updatedNeighbor.isEmpty) { | ||
| cells.remove(current); | ||
| } else { | ||
| cells[current] = updatedNeighbor; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Update target cell | ||
| var newCell = cell.copyWith(merge: event.strategy); | ||
|
|
||
| // Expand new neighbors | ||
|
|
||
| final strategy = event.strategy; | ||
|
|
||
| final span = event.span; | ||
|
|
||
|
CodeDoctorDE marked this conversation as resolved.
|
||
| if (strategy != null) { | ||
| final direction = getDirection(strategy); | ||
|
|
||
| if (direction != null) { | ||
| var current = event.cell.position; | ||
| final allObjects = (cells[current] ?? TableCell()).objects | ||
| .toList(); | ||
|
|
||
| for (var i = 1; i < span; i++) { | ||
| current = direction == CellMergeDirection.horizontal | ||
| ? VectorDefinition(current.x + 1, current.y) | ||
| : VectorDefinition(current.x, current.y + 1); | ||
|
|
||
| final neighbor = cells[current] ?? TableCell(); | ||
| if (neighbor.objects.isNotEmpty) { | ||
| allObjects.addAll(neighbor.objects); | ||
| } | ||
|
|
||
| cells[current] = neighbor.copyWith( | ||
| merge: MergedCellStrategy(direction), | ||
| objects: [], | ||
| ); | ||
| } | ||
|
Comment on lines
+382
to
+391
|
||
| newCell = newCell.copyWith(objects: allObjects); | ||
| } | ||
| } | ||
| cells[event.cell.position] = newCell; | ||
|
|
||
| return table.copyWith.cellsBox(content: cells); | ||
| }), | ||
| ); | ||
| case MetadataChanged(): | ||
| return ServerProcessed(state.copyWith(metadata: event.metadata)); | ||
| case MessageSent(): | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.