Skip to content

Commit

Permalink
Integrate plugin system in server
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Feb 5, 2025
1 parent 1686e0f commit 594b8df
Show file tree
Hide file tree
Showing 27 changed files with 377 additions and 193 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ jobs:
- name: Analyze project source
run: |
flutter analyze --fatal-infos
- name: Build flutter_rust_bridge bindings
if: matrix.projects == 'plugin'
run: |
cargo install flutter_rust_bridge_codegen
flutter_rust_bridge_codegen generate
- name: Run build_runner
if: matrix.projects == 'api' || matrix.projects == 'app'
run: dart run build_runner build --delete-conflicting-outputs
Expand Down
9 changes: 9 additions & 0 deletions api/lib/src/event/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,12 @@ final class ImagesRequest extends ClientWorldEvent with ImagesRequestMappable {

ImagesRequest(this.ids);
}

@MappableClass()
final class ModeChangeRequest extends ClientWorldEvent
with ModeChangeRequestMappable {
final ItemLocation? location;

ModeChangeRequest(this.location);
ModeChangeRequest.plain() : location = null;
}
144 changes: 139 additions & 5 deletions api/lib/src/event/event.mapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ class WorldInitializedMapper extends SubClassMapperBase<WorldInitialized> {
v.packsSignature;
static const Field<WorldInitialized, List<SignatureMetadata>>
_f$packsSignature = Field('packsSignature', _$packsSignature, opt: true);
static bool _$clearUserInterface(WorldInitialized v) => v.clearUserInterface;
static const Field<WorldInitialized, bool> _f$clearUserInterface =
Field('clearUserInterface', _$clearUserInterface, opt: true, def: false);

@override
final MappableFields<WorldInitialized> fields = const {
Expand All @@ -228,6 +231,7 @@ class WorldInitializedMapper extends SubClassMapperBase<WorldInitialized> {
#teamMembers: _f$teamMembers,
#id: _f$id,
#packsSignature: _f$packsSignature,
#clearUserInterface: _f$clearUserInterface,
};

@override
Expand All @@ -244,7 +248,8 @@ class WorldInitializedMapper extends SubClassMapperBase<WorldInitialized> {
info: data.dec(_f$info),
teamMembers: data.dec(_f$teamMembers),
id: data.dec(_f$id),
packsSignature: data.dec(_f$packsSignature));
packsSignature: data.dec(_f$packsSignature),
clearUserInterface: data.dec(_f$clearUserInterface));
}

@override
Expand Down Expand Up @@ -314,7 +319,8 @@ abstract class WorldInitializedCopyWith<$R, $In extends WorldInitialized, $Out>
GameInfo? info,
Map<String, Set<int>>? teamMembers,
int? id,
List<SignatureMetadata>? packsSignature});
List<SignatureMetadata>? packsSignature,
bool? clearUserInterface});
WorldInitializedCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(
Then<$Out2, $R2> t);
}
Expand Down Expand Up @@ -354,21 +360,25 @@ class _WorldInitializedCopyWithImpl<$R, $Out>
Object? info = $none,
Object? teamMembers = $none,
Object? id = $none,
Object? packsSignature = $none}) =>
Object? packsSignature = $none,
bool? clearUserInterface}) =>
$apply(FieldCopyWithData({
if (table != $none) #table: table,
if (info != $none) #info: info,
if (teamMembers != $none) #teamMembers: teamMembers,
if (id != $none) #id: id,
if (packsSignature != $none) #packsSignature: packsSignature
if (packsSignature != $none) #packsSignature: packsSignature,
if (clearUserInterface != null) #clearUserInterface: clearUserInterface
}));
@override
WorldInitialized $make(CopyWithData data) => WorldInitialized(
table: data.get(#table, or: $value.table),
info: data.get(#info, or: $value.info),
teamMembers: data.get(#teamMembers, or: $value.teamMembers),
id: data.get(#id, or: $value.id),
packsSignature: data.get(#packsSignature, or: $value.packsSignature));
packsSignature: data.get(#packsSignature, or: $value.packsSignature),
clearUserInterface:
data.get(#clearUserInterface, or: $value.clearUserInterface));

@override
WorldInitializedCopyWith<$R2, WorldInitialized, $Out2> $chain<$R2, $Out2>(
Expand Down Expand Up @@ -1650,6 +1660,7 @@ class ClientWorldEventMapper extends SubClassMapperBase<ClientWorldEvent> {
BoardMoveRequestMapper.ensureInitialized();
DialogCloseRequestMapper.ensureInitialized();
ImagesRequestMapper.ensureInitialized();
ModeChangeRequestMapper.ensureInitialized();
HybridWorldEventMapper.ensureInitialized();
}
return _instance!;
Expand Down Expand Up @@ -3095,6 +3106,129 @@ class _ImagesRequestCopyWithImpl<$R, $Out>
_ImagesRequestCopyWithImpl($value, $cast, t);
}

class ModeChangeRequestMapper extends SubClassMapperBase<ModeChangeRequest> {
ModeChangeRequestMapper._();

static ModeChangeRequestMapper? _instance;
static ModeChangeRequestMapper ensureInitialized() {
if (_instance == null) {
MapperContainer.globals.use(_instance = ModeChangeRequestMapper._());
ClientWorldEventMapper.ensureInitialized().addSubMapper(_instance!);
ItemLocationMapper.ensureInitialized();
}
return _instance!;
}

@override
final String id = 'ModeChangeRequest';

static ItemLocation? _$location(ModeChangeRequest v) => v.location;
static const Field<ModeChangeRequest, ItemLocation> _f$location =
Field('location', _$location);

@override
final MappableFields<ModeChangeRequest> fields = const {
#location: _f$location,
};

@override
final String discriminatorKey = 'type';
@override
final dynamic discriminatorValue = 'ModeChangeRequest';
@override
late final ClassMapperBase superMapper =
ClientWorldEventMapper.ensureInitialized();

static ModeChangeRequest _instantiate(DecodingData data) {
return ModeChangeRequest(data.dec(_f$location));
}

@override
final Function instantiate = _instantiate;

static ModeChangeRequest fromMap(Map<String, dynamic> map) {
return ensureInitialized().decodeMap<ModeChangeRequest>(map);
}

static ModeChangeRequest fromJson(String json) {
return ensureInitialized().decodeJson<ModeChangeRequest>(json);
}
}

mixin ModeChangeRequestMappable {
String toJson() {
return ModeChangeRequestMapper.ensureInitialized()
.encodeJson<ModeChangeRequest>(this as ModeChangeRequest);
}

Map<String, dynamic> toMap() {
return ModeChangeRequestMapper.ensureInitialized()
.encodeMap<ModeChangeRequest>(this as ModeChangeRequest);
}

ModeChangeRequestCopyWith<ModeChangeRequest, ModeChangeRequest,
ModeChangeRequest>
get copyWith => _ModeChangeRequestCopyWithImpl(
this as ModeChangeRequest, $identity, $identity);
@override
String toString() {
return ModeChangeRequestMapper.ensureInitialized()
.stringifyValue(this as ModeChangeRequest);
}

@override
bool operator ==(Object other) {
return ModeChangeRequestMapper.ensureInitialized()
.equalsValue(this as ModeChangeRequest, other);
}

@override
int get hashCode {
return ModeChangeRequestMapper.ensureInitialized()
.hashValue(this as ModeChangeRequest);
}
}

extension ModeChangeRequestValueCopy<$R, $Out>
on ObjectCopyWith<$R, ModeChangeRequest, $Out> {
ModeChangeRequestCopyWith<$R, ModeChangeRequest, $Out>
get $asModeChangeRequest =>
$base.as((v, t, t2) => _ModeChangeRequestCopyWithImpl(v, t, t2));
}

abstract class ModeChangeRequestCopyWith<$R, $In extends ModeChangeRequest,
$Out> implements ClientWorldEventCopyWith<$R, $In, $Out> {
ItemLocationCopyWith<$R, ItemLocation, ItemLocation>? get location;
@override
$R call({ItemLocation? location});
ModeChangeRequestCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(
Then<$Out2, $R2> t);
}

class _ModeChangeRequestCopyWithImpl<$R, $Out>
extends ClassCopyWithBase<$R, ModeChangeRequest, $Out>
implements ModeChangeRequestCopyWith<$R, ModeChangeRequest, $Out> {
_ModeChangeRequestCopyWithImpl(super.value, super.then, super.then2);

@override
late final ClassMapperBase<ModeChangeRequest> $mapper =
ModeChangeRequestMapper.ensureInitialized();
@override
ItemLocationCopyWith<$R, ItemLocation, ItemLocation>? get location =>
$value.location?.copyWith.$chain((v) => call(location: v));
@override
$R call({Object? location = $none}) =>
$apply(FieldCopyWithData({if (location != $none) #location: location}));
@override
ModeChangeRequest $make(CopyWithData data) =>
ModeChangeRequest(data.get(#location, or: $value.location));

@override
ModeChangeRequestCopyWith<$R2, ModeChangeRequest, $Out2> $chain<$R2, $Out2>(
Then<$Out2, $R2> t) =>
_ModeChangeRequestCopyWithImpl($value, $cast, t);
}

class HybridWorldEventMapper extends SubClassMapperBase<HybridWorldEvent> {
HybridWorldEventMapper._();

Expand Down
8 changes: 8 additions & 0 deletions api/lib/src/event/process/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ bool isValidClientEvent(
.tiles
.length -
1),
ModeChangeRequest() => channel == kAuthorityChannel,
_ => true,
};

Expand Down Expand Up @@ -271,5 +272,12 @@ ServerResponse? processClientEvent(
return MapEntry(e, image);
}).nonNulls)),
channel);
case ModeChangeRequest():
final location = event.location;
final mode = location == null
? null
: assetManager.getPack(location.namespace)?.getMode(location.id);
return ServerResponse.builder(
WorldInitialized.fromMode(mode, state), channel);
}
}
2 changes: 2 additions & 0 deletions api/lib/src/event/process/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ ServerProcessed processServerEvent(
id: event.id ?? state.id,
teamMembers: event.teamMembers ?? state.teamMembers,
info: event.info ?? state.info,
dialogs: event.clearUserInterface ? [] : state.dialogs,
images: event.clearUserInterface ? {} : state.images,
));
case TeamJoined():
return ServerProcessed(state.copyWith(
Expand Down
11 changes: 11 additions & 0 deletions api/lib/src/event/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,25 @@ final class WorldInitialized extends ServerWorldEvent
final Map<String, Set<Channel>>? teamMembers;
final Channel? id;
final List<SignatureMetadata>? packsSignature;
final bool clearUserInterface;

WorldInitialized({
this.table,
this.info,
this.teamMembers,
this.id,
this.packsSignature,
this.clearUserInterface = false,
});

factory WorldInitialized.fromMode(GameMode? mode, WorldState state) =>
WorldInitialized(
clearUserInterface: true,
info:
state.info.copyWith(teams: mode?.teams ?? {}, script: mode?.script),
table: mode?.tables[state.tableName] ?? GameTable(),
teamMembers: const {},
);
}

@MappableClass()
Expand Down
2 changes: 2 additions & 0 deletions api/lib/src/models/info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ part 'info.mapper.dart';
class GameInfo with GameInfoMappable {
final Map<String, GameTeam> teams;
final List<String> packs;
final String? script;

const GameInfo({
this.teams = const {},
this.packs = const [],
this.script,
});
}

Expand Down
22 changes: 17 additions & 5 deletions api/lib/src/models/info.mapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,22 @@ class GameInfoMapper extends ClassMapperBase<GameInfo> {
static List<String> _$packs(GameInfo v) => v.packs;
static const Field<GameInfo, List<String>> _f$packs =
Field('packs', _$packs, opt: true, def: const []);
static String? _$script(GameInfo v) => v.script;
static const Field<GameInfo, String> _f$script =
Field('script', _$script, opt: true);

@override
final MappableFields<GameInfo> fields = const {
#teams: _f$teams,
#packs: _f$packs,
#script: _f$script,
};

static GameInfo _instantiate(DecodingData data) {
return GameInfo(teams: data.dec(_f$teams), packs: data.dec(_f$packs));
return GameInfo(
teams: data.dec(_f$teams),
packs: data.dec(_f$packs),
script: data.dec(_f$script));
}

@override
Expand Down Expand Up @@ -172,7 +179,7 @@ abstract class GameInfoCopyWith<$R, $In extends GameInfo, $Out>
MapCopyWith<$R, String, GameTeam, GameTeamCopyWith<$R, GameTeam, GameTeam>>
get teams;
ListCopyWith<$R, String, ObjectCopyWith<$R, String, String>> get packs;
$R call({Map<String, GameTeam>? teams, List<String>? packs});
$R call({Map<String, GameTeam>? teams, List<String>? packs, String? script});
GameInfoCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t);
}

Expand All @@ -193,15 +200,20 @@ class _GameInfoCopyWithImpl<$R, $Out>
ListCopyWith($value.packs, (v, t) => ObjectCopyWith(v, $identity, t),
(v) => call(packs: v));
@override
$R call({Map<String, GameTeam>? teams, List<String>? packs}) =>
$R call(
{Map<String, GameTeam>? teams,
List<String>? packs,
Object? script = $none}) =>
$apply(FieldCopyWithData({
if (teams != null) #teams: teams,
if (packs != null) #packs: packs
if (packs != null) #packs: packs,
if (script != $none) #script: script
}));
@override
GameInfo $make(CopyWithData data) => GameInfo(
teams: data.get(#teams, or: $value.teams),
packs: data.get(#packs, or: $value.packs));
packs: data.get(#packs, or: $value.packs),
script: data.get(#script, or: $value.script));

@override
GameInfoCopyWith<$R2, GameInfo, $Out2> $chain<$R2, $Out2>(
Expand Down
10 changes: 4 additions & 6 deletions api/lib/src/models/mode.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ part 'mode.mapper.dart';
final class GameMode with GameModeMappable {
final String? script;

final Map<String, GameTable> table;
final Map<String, GameTable> tables;
final String tableName;
final List<GameTeam> teams;
final Map<String, GameTeam> teams;

GameMode({
required this.script,
this.table = const {
'': GameTable(),
},
this.tables = const {},
this.tableName = '',
this.teams = const [],
this.teams = const {},
});
}
Loading

0 comments on commit 594b8df

Please sign in to comment.