Skip to content

Commit ef4e57e

Browse files
committed
Add waypoint display
1 parent f692214 commit ef4e57e

File tree

7 files changed

+308
-55
lines changed

7 files changed

+308
-55
lines changed

app/lib/bloc/world/bloc.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ class WorldBloc extends Bloc<PlayableWorldEvent, ClientWorldState> {
133133
on<SwitchCellOnMoveChanged>((event, emit) {
134134
emit(state.copyWith(switchCellOnMove: event.value));
135135
});
136+
on<WaypointVisibilityChanged>((event, emit) {
137+
emit(state.copyWith(showWaypoints: event.value));
138+
});
136139
on<TableSwitched>((event, emit) {
137140
emit(
138141
state.copyWith.world(

app/lib/bloc/world/local.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ final class SwitchCellOnMoveChanged extends LocalWorldEvent
3131
SwitchCellOnMoveChanged(this.value);
3232
}
3333

34+
@MappableClass()
35+
final class WaypointVisibilityChanged extends LocalWorldEvent
36+
with WaypointVisibilityChangedMappable {
37+
final bool value;
38+
39+
WaypointVisibilityChanged(this.value);
40+
}
41+
3442
@MappableClass()
3543
final class TableSwitched extends LocalWorldEvent with TableSwitchedMappable {
3644
final String name;

app/lib/bloc/world/local.mapper.dart

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

app/lib/bloc/world/state.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ final class ClientWorldState with ClientWorldStateMappable {
2222
final ColorScheme colorScheme;
2323
final VectorDefinition? selectedCell;
2424
final ItemLocation? selectedDeck;
25-
final bool showHand, switchCellOnMove;
25+
final bool showHand, switchCellOnMove, showWaypoints;
2626
final DrawerView drawerView;
2727
final String searchTerm;
2828
final bool showDuplicates;
@@ -36,6 +36,7 @@ final class ClientWorldState with ClientWorldStateMappable {
3636
this.selectedDeck,
3737
this.showHand = false,
3838
this.switchCellOnMove = false,
39+
this.showWaypoints = false,
3940
this.drawerView = DrawerView.chat,
4041
this.searchTerm = '',
4142
this.showDuplicates = false,

app/lib/bloc/world/state.mapper.dart

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

app/lib/board/cell.dart

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:flame/collisions.dart';
44
import 'package:flame/components.dart';
55
import 'package:flame/effects.dart';
66
import 'package:flame/events.dart';
7+
import 'package:flame/text.dart';
78
import 'package:flame_bloc/flame_bloc.dart';
89
import 'package:flutter/material.dart';
910
import 'package:flutter_bloc/flutter_bloc.dart';
@@ -38,6 +39,7 @@ class GameCell extends PositionComponent
3839
ScrollCallbacks {
3940
late final SpriteComponent _selectionComponent;
4041
SpriteComponent? _cardComponent, _boardComponent;
42+
TextElementComponent? _waypointComponent;
4143
late final BoardGrid grid;
4244
List<Effect>? _effects;
4345

@@ -61,6 +63,66 @@ class GameCell extends PositionComponent
6163
}
6264
}
6365

66+
void _buildWaypointComponent(ClientWorldState state) {
67+
final visible = state.showWaypoints;
68+
_waypointComponent?.removeFromParent();
69+
_waypointComponent = null;
70+
if (!visible) {
71+
return;
72+
}
73+
final global = toGlobalDefinition(state);
74+
final globalWaypoints = state.info.waypoints
75+
.where((waypoint) => waypoint.position == global)
76+
.map<InlineTextNode>((e) => PlainTextNode(e.name))
77+
.toList();
78+
final teamWaypoints = state.world.getTeams().expand((name) {
79+
final team = state.info.teams[name];
80+
if (team == null) return Iterable<InlineTextNode>.empty();
81+
return team.waypoints
82+
.where((waypoint) => waypoint.position == global)
83+
.map<InlineTextNode>(
84+
(e) => CustomInlineTextNode(
85+
PlainTextNode(e.name),
86+
styleName: 'team-$name',
87+
),
88+
);
89+
}).toList();
90+
if (globalWaypoints.isEmpty && teamWaypoints.isEmpty) {
91+
return;
92+
}
93+
final blocks = <BlockNode>[
94+
ParagraphNode.group(globalWaypoints),
95+
ParagraphNode.group(teamWaypoints),
96+
];
97+
final document = DocumentRoot(blocks);
98+
final component = _waypointComponent = TextElementComponent.fromDocument(
99+
document: document,
100+
size: size,
101+
priority: 2,
102+
style: DocumentStyle(
103+
paragraph: BlockStyle(textAlign: TextAlign.center),
104+
customStyles: {
105+
for (final entry in state.world.getTeams())
106+
'team-$entry': InlineTextStyle(
107+
color:
108+
state.info.teams[entry]?.color?.color ??
109+
state.colorScheme.primary,
110+
),
111+
},
112+
text: InlineTextStyle(
113+
shadows: [
114+
Shadow(
115+
color: Colors.black,
116+
offset: const Offset(0, 0),
117+
blurRadius: 2,
118+
),
119+
],
120+
),
121+
),
122+
);
123+
add(component);
124+
}
125+
64126
@override
65127
void onLoad() {
66128
super.onLoad();
@@ -82,7 +144,8 @@ class GameCell extends PositionComponent
82144
previousState.table.cells[definition] !=
83145
newState.table.cells[definition] ||
84146
previousState.teamMembers != newState.teamMembers ||
85-
previousState.colorScheme != newState.colorScheme;
147+
previousState.colorScheme != newState.colorScheme ||
148+
previousState.showWaypoints != newState.showWaypoints;
86149
}
87150

88151
bool get isSelected => isMounted && bloc.state.selectedCell == toDefinition();
@@ -134,6 +197,7 @@ class GameCell extends PositionComponent
134197
@override
135198
void onInitialState(ClientWorldState state) {
136199
if (state.selectedCell != toDefinition()) _selectionComponent.opacity = 0;
200+
_buildWaypointComponent(state);
137201
}
138202

139203
bool isClaimed(ClientWorldState state) => state.info.teams.entries.any(
@@ -178,6 +242,7 @@ class GameCell extends PositionComponent
178242
),
179243
]);
180244
}
245+
_buildWaypointComponent(state);
181246
}
182247

183248
Future<void> _updateTop() async {

0 commit comments

Comments
 (0)