Skip to content

Commit 594b8df

Browse files
committed
Integrate plugin system in server
1 parent 1686e0f commit 594b8df

27 files changed

+377
-193
lines changed

.github/workflows/dart.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ jobs:
4747
- name: Analyze project source
4848
run: |
4949
flutter analyze --fatal-infos
50+
- name: Build flutter_rust_bridge bindings
51+
if: matrix.projects == 'plugin'
52+
run: |
53+
cargo install flutter_rust_bridge_codegen
54+
flutter_rust_bridge_codegen generate
5055
- name: Run build_runner
5156
if: matrix.projects == 'api' || matrix.projects == 'app'
5257
run: dart run build_runner build --delete-conflicting-outputs

api/lib/src/event/client.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,12 @@ final class ImagesRequest extends ClientWorldEvent with ImagesRequestMappable {
148148

149149
ImagesRequest(this.ids);
150150
}
151+
152+
@MappableClass()
153+
final class ModeChangeRequest extends ClientWorldEvent
154+
with ModeChangeRequestMappable {
155+
final ItemLocation? location;
156+
157+
ModeChangeRequest(this.location);
158+
ModeChangeRequest.plain() : location = null;
159+
}

api/lib/src/event/event.mapper.dart

Lines changed: 139 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ class WorldInitializedMapper extends SubClassMapperBase<WorldInitialized> {
220220
v.packsSignature;
221221
static const Field<WorldInitialized, List<SignatureMetadata>>
222222
_f$packsSignature = Field('packsSignature', _$packsSignature, opt: true);
223+
static bool _$clearUserInterface(WorldInitialized v) => v.clearUserInterface;
224+
static const Field<WorldInitialized, bool> _f$clearUserInterface =
225+
Field('clearUserInterface', _$clearUserInterface, opt: true, def: false);
223226

224227
@override
225228
final MappableFields<WorldInitialized> fields = const {
@@ -228,6 +231,7 @@ class WorldInitializedMapper extends SubClassMapperBase<WorldInitialized> {
228231
#teamMembers: _f$teamMembers,
229232
#id: _f$id,
230233
#packsSignature: _f$packsSignature,
234+
#clearUserInterface: _f$clearUserInterface,
231235
};
232236

233237
@override
@@ -244,7 +248,8 @@ class WorldInitializedMapper extends SubClassMapperBase<WorldInitialized> {
244248
info: data.dec(_f$info),
245249
teamMembers: data.dec(_f$teamMembers),
246250
id: data.dec(_f$id),
247-
packsSignature: data.dec(_f$packsSignature));
251+
packsSignature: data.dec(_f$packsSignature),
252+
clearUserInterface: data.dec(_f$clearUserInterface));
248253
}
249254

250255
@override
@@ -314,7 +319,8 @@ abstract class WorldInitializedCopyWith<$R, $In extends WorldInitialized, $Out>
314319
GameInfo? info,
315320
Map<String, Set<int>>? teamMembers,
316321
int? id,
317-
List<SignatureMetadata>? packsSignature});
322+
List<SignatureMetadata>? packsSignature,
323+
bool? clearUserInterface});
318324
WorldInitializedCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(
319325
Then<$Out2, $R2> t);
320326
}
@@ -354,21 +360,25 @@ class _WorldInitializedCopyWithImpl<$R, $Out>
354360
Object? info = $none,
355361
Object? teamMembers = $none,
356362
Object? id = $none,
357-
Object? packsSignature = $none}) =>
363+
Object? packsSignature = $none,
364+
bool? clearUserInterface}) =>
358365
$apply(FieldCopyWithData({
359366
if (table != $none) #table: table,
360367
if (info != $none) #info: info,
361368
if (teamMembers != $none) #teamMembers: teamMembers,
362369
if (id != $none) #id: id,
363-
if (packsSignature != $none) #packsSignature: packsSignature
370+
if (packsSignature != $none) #packsSignature: packsSignature,
371+
if (clearUserInterface != null) #clearUserInterface: clearUserInterface
364372
}));
365373
@override
366374
WorldInitialized $make(CopyWithData data) => WorldInitialized(
367375
table: data.get(#table, or: $value.table),
368376
info: data.get(#info, or: $value.info),
369377
teamMembers: data.get(#teamMembers, or: $value.teamMembers),
370378
id: data.get(#id, or: $value.id),
371-
packsSignature: data.get(#packsSignature, or: $value.packsSignature));
379+
packsSignature: data.get(#packsSignature, or: $value.packsSignature),
380+
clearUserInterface:
381+
data.get(#clearUserInterface, or: $value.clearUserInterface));
372382

373383
@override
374384
WorldInitializedCopyWith<$R2, WorldInitialized, $Out2> $chain<$R2, $Out2>(
@@ -1650,6 +1660,7 @@ class ClientWorldEventMapper extends SubClassMapperBase<ClientWorldEvent> {
16501660
BoardMoveRequestMapper.ensureInitialized();
16511661
DialogCloseRequestMapper.ensureInitialized();
16521662
ImagesRequestMapper.ensureInitialized();
1663+
ModeChangeRequestMapper.ensureInitialized();
16531664
HybridWorldEventMapper.ensureInitialized();
16541665
}
16551666
return _instance!;
@@ -3095,6 +3106,129 @@ class _ImagesRequestCopyWithImpl<$R, $Out>
30953106
_ImagesRequestCopyWithImpl($value, $cast, t);
30963107
}
30973108

3109+
class ModeChangeRequestMapper extends SubClassMapperBase<ModeChangeRequest> {
3110+
ModeChangeRequestMapper._();
3111+
3112+
static ModeChangeRequestMapper? _instance;
3113+
static ModeChangeRequestMapper ensureInitialized() {
3114+
if (_instance == null) {
3115+
MapperContainer.globals.use(_instance = ModeChangeRequestMapper._());
3116+
ClientWorldEventMapper.ensureInitialized().addSubMapper(_instance!);
3117+
ItemLocationMapper.ensureInitialized();
3118+
}
3119+
return _instance!;
3120+
}
3121+
3122+
@override
3123+
final String id = 'ModeChangeRequest';
3124+
3125+
static ItemLocation? _$location(ModeChangeRequest v) => v.location;
3126+
static const Field<ModeChangeRequest, ItemLocation> _f$location =
3127+
Field('location', _$location);
3128+
3129+
@override
3130+
final MappableFields<ModeChangeRequest> fields = const {
3131+
#location: _f$location,
3132+
};
3133+
3134+
@override
3135+
final String discriminatorKey = 'type';
3136+
@override
3137+
final dynamic discriminatorValue = 'ModeChangeRequest';
3138+
@override
3139+
late final ClassMapperBase superMapper =
3140+
ClientWorldEventMapper.ensureInitialized();
3141+
3142+
static ModeChangeRequest _instantiate(DecodingData data) {
3143+
return ModeChangeRequest(data.dec(_f$location));
3144+
}
3145+
3146+
@override
3147+
final Function instantiate = _instantiate;
3148+
3149+
static ModeChangeRequest fromMap(Map<String, dynamic> map) {
3150+
return ensureInitialized().decodeMap<ModeChangeRequest>(map);
3151+
}
3152+
3153+
static ModeChangeRequest fromJson(String json) {
3154+
return ensureInitialized().decodeJson<ModeChangeRequest>(json);
3155+
}
3156+
}
3157+
3158+
mixin ModeChangeRequestMappable {
3159+
String toJson() {
3160+
return ModeChangeRequestMapper.ensureInitialized()
3161+
.encodeJson<ModeChangeRequest>(this as ModeChangeRequest);
3162+
}
3163+
3164+
Map<String, dynamic> toMap() {
3165+
return ModeChangeRequestMapper.ensureInitialized()
3166+
.encodeMap<ModeChangeRequest>(this as ModeChangeRequest);
3167+
}
3168+
3169+
ModeChangeRequestCopyWith<ModeChangeRequest, ModeChangeRequest,
3170+
ModeChangeRequest>
3171+
get copyWith => _ModeChangeRequestCopyWithImpl(
3172+
this as ModeChangeRequest, $identity, $identity);
3173+
@override
3174+
String toString() {
3175+
return ModeChangeRequestMapper.ensureInitialized()
3176+
.stringifyValue(this as ModeChangeRequest);
3177+
}
3178+
3179+
@override
3180+
bool operator ==(Object other) {
3181+
return ModeChangeRequestMapper.ensureInitialized()
3182+
.equalsValue(this as ModeChangeRequest, other);
3183+
}
3184+
3185+
@override
3186+
int get hashCode {
3187+
return ModeChangeRequestMapper.ensureInitialized()
3188+
.hashValue(this as ModeChangeRequest);
3189+
}
3190+
}
3191+
3192+
extension ModeChangeRequestValueCopy<$R, $Out>
3193+
on ObjectCopyWith<$R, ModeChangeRequest, $Out> {
3194+
ModeChangeRequestCopyWith<$R, ModeChangeRequest, $Out>
3195+
get $asModeChangeRequest =>
3196+
$base.as((v, t, t2) => _ModeChangeRequestCopyWithImpl(v, t, t2));
3197+
}
3198+
3199+
abstract class ModeChangeRequestCopyWith<$R, $In extends ModeChangeRequest,
3200+
$Out> implements ClientWorldEventCopyWith<$R, $In, $Out> {
3201+
ItemLocationCopyWith<$R, ItemLocation, ItemLocation>? get location;
3202+
@override
3203+
$R call({ItemLocation? location});
3204+
ModeChangeRequestCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(
3205+
Then<$Out2, $R2> t);
3206+
}
3207+
3208+
class _ModeChangeRequestCopyWithImpl<$R, $Out>
3209+
extends ClassCopyWithBase<$R, ModeChangeRequest, $Out>
3210+
implements ModeChangeRequestCopyWith<$R, ModeChangeRequest, $Out> {
3211+
_ModeChangeRequestCopyWithImpl(super.value, super.then, super.then2);
3212+
3213+
@override
3214+
late final ClassMapperBase<ModeChangeRequest> $mapper =
3215+
ModeChangeRequestMapper.ensureInitialized();
3216+
@override
3217+
ItemLocationCopyWith<$R, ItemLocation, ItemLocation>? get location =>
3218+
$value.location?.copyWith.$chain((v) => call(location: v));
3219+
@override
3220+
$R call({Object? location = $none}) =>
3221+
$apply(FieldCopyWithData({if (location != $none) #location: location}));
3222+
@override
3223+
ModeChangeRequest $make(CopyWithData data) =>
3224+
ModeChangeRequest(data.get(#location, or: $value.location));
3225+
3226+
@override
3227+
ModeChangeRequestCopyWith<$R2, ModeChangeRequest, $Out2> $chain<$R2, $Out2>(
3228+
Then<$Out2, $R2> t) =>
3229+
_ModeChangeRequestCopyWithImpl($value, $cast, t);
3230+
}
3231+
30983232
class HybridWorldEventMapper extends SubClassMapperBase<HybridWorldEvent> {
30993233
HybridWorldEventMapper._();
31003234

api/lib/src/event/process/client.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ bool isValidClientEvent(
6969
.tiles
7070
.length -
7171
1),
72+
ModeChangeRequest() => channel == kAuthorityChannel,
7273
_ => true,
7374
};
7475

@@ -271,5 +272,12 @@ ServerResponse? processClientEvent(
271272
return MapEntry(e, image);
272273
}).nonNulls)),
273274
channel);
275+
case ModeChangeRequest():
276+
final location = event.location;
277+
final mode = location == null
278+
? null
279+
: assetManager.getPack(location.namespace)?.getMode(location.id);
280+
return ServerResponse.builder(
281+
WorldInitialized.fromMode(mode, state), channel);
274282
}
275283
}

api/lib/src/event/process/server.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ ServerProcessed processServerEvent(
101101
id: event.id ?? state.id,
102102
teamMembers: event.teamMembers ?? state.teamMembers,
103103
info: event.info ?? state.info,
104+
dialogs: event.clearUserInterface ? [] : state.dialogs,
105+
images: event.clearUserInterface ? {} : state.images,
104106
));
105107
case TeamJoined():
106108
return ServerProcessed(state.copyWith(

api/lib/src/event/server.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,25 @@ final class WorldInitialized extends ServerWorldEvent
1414
final Map<String, Set<Channel>>? teamMembers;
1515
final Channel? id;
1616
final List<SignatureMetadata>? packsSignature;
17+
final bool clearUserInterface;
1718

1819
WorldInitialized({
1920
this.table,
2021
this.info,
2122
this.teamMembers,
2223
this.id,
2324
this.packsSignature,
25+
this.clearUserInterface = false,
2426
});
27+
28+
factory WorldInitialized.fromMode(GameMode? mode, WorldState state) =>
29+
WorldInitialized(
30+
clearUserInterface: true,
31+
info:
32+
state.info.copyWith(teams: mode?.teams ?? {}, script: mode?.script),
33+
table: mode?.tables[state.tableName] ?? GameTable(),
34+
teamMembers: const {},
35+
);
2536
}
2637

2738
@MappableClass()

api/lib/src/models/info.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ part 'info.mapper.dart';
88
class GameInfo with GameInfoMappable {
99
final Map<String, GameTeam> teams;
1010
final List<String> packs;
11+
final String? script;
1112

1213
const GameInfo({
1314
this.teams = const {},
1415
this.packs = const [],
16+
this.script,
1517
});
1618
}
1719

api/lib/src/models/info.mapper.dart

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,22 @@ class GameInfoMapper extends ClassMapperBase<GameInfo> {
109109
static List<String> _$packs(GameInfo v) => v.packs;
110110
static const Field<GameInfo, List<String>> _f$packs =
111111
Field('packs', _$packs, opt: true, def: const []);
112+
static String? _$script(GameInfo v) => v.script;
113+
static const Field<GameInfo, String> _f$script =
114+
Field('script', _$script, opt: true);
112115

113116
@override
114117
final MappableFields<GameInfo> fields = const {
115118
#teams: _f$teams,
116119
#packs: _f$packs,
120+
#script: _f$script,
117121
};
118122

119123
static GameInfo _instantiate(DecodingData data) {
120-
return GameInfo(teams: data.dec(_f$teams), packs: data.dec(_f$packs));
124+
return GameInfo(
125+
teams: data.dec(_f$teams),
126+
packs: data.dec(_f$packs),
127+
script: data.dec(_f$script));
121128
}
122129

123130
@override
@@ -172,7 +179,7 @@ abstract class GameInfoCopyWith<$R, $In extends GameInfo, $Out>
172179
MapCopyWith<$R, String, GameTeam, GameTeamCopyWith<$R, GameTeam, GameTeam>>
173180
get teams;
174181
ListCopyWith<$R, String, ObjectCopyWith<$R, String, String>> get packs;
175-
$R call({Map<String, GameTeam>? teams, List<String>? packs});
182+
$R call({Map<String, GameTeam>? teams, List<String>? packs, String? script});
176183
GameInfoCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t);
177184
}
178185

@@ -193,15 +200,20 @@ class _GameInfoCopyWithImpl<$R, $Out>
193200
ListCopyWith($value.packs, (v, t) => ObjectCopyWith(v, $identity, t),
194201
(v) => call(packs: v));
195202
@override
196-
$R call({Map<String, GameTeam>? teams, List<String>? packs}) =>
203+
$R call(
204+
{Map<String, GameTeam>? teams,
205+
List<String>? packs,
206+
Object? script = $none}) =>
197207
$apply(FieldCopyWithData({
198208
if (teams != null) #teams: teams,
199-
if (packs != null) #packs: packs
209+
if (packs != null) #packs: packs,
210+
if (script != $none) #script: script
200211
}));
201212
@override
202213
GameInfo $make(CopyWithData data) => GameInfo(
203214
teams: data.get(#teams, or: $value.teams),
204-
packs: data.get(#packs, or: $value.packs));
215+
packs: data.get(#packs, or: $value.packs),
216+
script: data.get(#script, or: $value.script));
205217

206218
@override
207219
GameInfoCopyWith<$R2, GameInfo, $Out2> $chain<$R2, $Out2>(

api/lib/src/models/mode.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@ part 'mode.mapper.dart';
99
final class GameMode with GameModeMappable {
1010
final String? script;
1111

12-
final Map<String, GameTable> table;
12+
final Map<String, GameTable> tables;
1313
final String tableName;
14-
final List<GameTeam> teams;
14+
final Map<String, GameTeam> teams;
1515

1616
GameMode({
1717
required this.script,
18-
this.table = const {
19-
'': GameTable(),
20-
},
18+
this.tables = const {},
2119
this.tableName = '',
22-
this.teams = const [],
20+
this.teams = const {},
2321
});
2422
}

0 commit comments

Comments
 (0)