Skip to content

Commit a6327bd

Browse files
committed
Add gamemode initialization
1 parent 20b9e3a commit a6327bd

22 files changed

+420
-347
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ Future<ServerResponse?> processClientEvent(
295295
? null
296296
: assetManager.getPack(location.namespace)?.getMode(location.id);
297297
return ServerResponse.builder(
298-
WorldInitialized.fromMode(mode, state), channel);
298+
WorldInitialized.fromMode(location, mode, state), channel);
299299
case AuthenticateRequest():
300300
final challenge = challengeManager?.getChallenge(channel);
301301
if (challenge == null) return null;

api/lib/src/event/server.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ final class WorldInitialized extends ServerWorldEvent
2727
this.clearUserInterface = false,
2828
});
2929

30-
factory WorldInitialized.fromMode(GameMode? mode, WorldState state) =>
30+
factory WorldInitialized.fromMode(
31+
ItemLocation? location, GameMode? mode, WorldState state) =>
3132
WorldInitialized(
3233
clearUserInterface: true,
33-
info:
34-
state.info.copyWith(teams: mode?.teams ?? {}, script: mode?.script),
34+
info: state.info.copyWith(teams: mode?.teams ?? {}, script: location),
3535
table: mode?.tables[state.tableName] ?? GameTable(),
3636
teamMembers: const {},
3737
);

api/lib/src/models/config.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ final class SetonixConfig with SetonixConfigMappable {
4141
final String? endpointSecret;
4242
static const String defaultEndpointSecret = '';
4343
static const String envEndpointSecret = 'SETONIX_ENDPOINT_SECRET';
44+
final String? gameMode;
45+
static const String defaultGameMode = '';
46+
static const String envGameMode = 'SETONIX_GAME_MODE';
4447

4548
const SetonixConfig({
4649
this.host,
@@ -55,6 +58,7 @@ final class SetonixConfig with SetonixConfigMappable {
5558
this.accountRequired,
5659
this.apiEndpoint,
5760
this.endpointSecret,
61+
this.gameMode,
5862
});
5963

6064
static const defaultConfig = SetonixConfig(
@@ -70,6 +74,7 @@ final class SetonixConfig with SetonixConfigMappable {
7074
accountRequired: defaultAccountRequired,
7175
apiEndpoint: defaultApiEndpoint,
7276
endpointSecret: defaultEndpointSecret,
77+
gameMode: defaultGameMode,
7378
);
7479

7580
static SetonixConfig fromEnvironment() {
@@ -116,6 +121,9 @@ final class SetonixConfig with SetonixConfigMappable {
116121
? String.fromEnvironment(envEndpointSecret,
117122
defaultValue: defaultEndpointSecret)
118123
: null,
124+
gameMode: bool.hasEnvironment(envGameMode)
125+
? String.fromEnvironment(envGameMode, defaultValue: defaultGameMode)
126+
: null,
119127
);
120128
}
121129

@@ -132,5 +140,6 @@ final class SetonixConfig with SetonixConfigMappable {
132140
whitelistEnabled: other.whitelistEnabled ?? whitelistEnabled,
133141
apiEndpoint: other.apiEndpoint ?? apiEndpoint,
134142
endpointSecret: other.endpointSecret ?? endpointSecret,
143+
gameMode: other.gameMode ?? gameMode,
135144
);
136145
}

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ class SetonixConfigMapper extends ClassMapperBase<SetonixConfig> {
5656
static String? _$endpointSecret(SetonixConfig v) => v.endpointSecret;
5757
static const Field<SetonixConfig, String> _f$endpointSecret =
5858
Field('endpointSecret', _$endpointSecret, opt: true);
59+
static String? _$gameMode(SetonixConfig v) => v.gameMode;
60+
static const Field<SetonixConfig, String> _f$gameMode =
61+
Field('gameMode', _$gameMode, opt: true);
5962

6063
@override
6164
final MappableFields<SetonixConfig> fields = const {
@@ -71,6 +74,7 @@ class SetonixConfigMapper extends ClassMapperBase<SetonixConfig> {
7174
#accountRequired: _f$accountRequired,
7275
#apiEndpoint: _f$apiEndpoint,
7376
#endpointSecret: _f$endpointSecret,
77+
#gameMode: _f$gameMode,
7478
};
7579

7680
static SetonixConfig _instantiate(DecodingData data) {
@@ -86,7 +90,8 @@ class SetonixConfigMapper extends ClassMapperBase<SetonixConfig> {
8690
whitelistEnabled: data.dec(_f$whitelistEnabled),
8791
accountRequired: data.dec(_f$accountRequired),
8892
apiEndpoint: data.dec(_f$apiEndpoint),
89-
endpointSecret: data.dec(_f$endpointSecret));
93+
endpointSecret: data.dec(_f$endpointSecret),
94+
gameMode: data.dec(_f$gameMode));
9095
}
9196

9297
@override
@@ -154,7 +159,8 @@ abstract class SetonixConfigCopyWith<$R, $In extends SetonixConfig, $Out>
154159
bool? whitelistEnabled,
155160
bool? accountRequired,
156161
String? apiEndpoint,
157-
String? endpointSecret});
162+
String? endpointSecret,
163+
String? gameMode});
158164
SetonixConfigCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t);
159165
}
160166

@@ -179,7 +185,8 @@ class _SetonixConfigCopyWithImpl<$R, $Out>
179185
Object? whitelistEnabled = $none,
180186
Object? accountRequired = $none,
181187
Object? apiEndpoint = $none,
182-
Object? endpointSecret = $none}) =>
188+
Object? endpointSecret = $none,
189+
Object? gameMode = $none}) =>
183190
$apply(FieldCopyWithData({
184191
if (host != $none) #host: host,
185192
if (port != $none) #port: port,
@@ -192,7 +199,8 @@ class _SetonixConfigCopyWithImpl<$R, $Out>
192199
if (whitelistEnabled != $none) #whitelistEnabled: whitelistEnabled,
193200
if (accountRequired != $none) #accountRequired: accountRequired,
194201
if (apiEndpoint != $none) #apiEndpoint: apiEndpoint,
195-
if (endpointSecret != $none) #endpointSecret: endpointSecret
202+
if (endpointSecret != $none) #endpointSecret: endpointSecret,
203+
if (gameMode != $none) #gameMode: gameMode
196204
}));
197205
@override
198206
SetonixConfig $make(CopyWithData data) => SetonixConfig(
@@ -208,7 +216,8 @@ class _SetonixConfigCopyWithImpl<$R, $Out>
208216
data.get(#whitelistEnabled, or: $value.whitelistEnabled),
209217
accountRequired: data.get(#accountRequired, or: $value.accountRequired),
210218
apiEndpoint: data.get(#apiEndpoint, or: $value.apiEndpoint),
211-
endpointSecret: data.get(#endpointSecret, or: $value.endpointSecret));
219+
endpointSecret: data.get(#endpointSecret, or: $value.endpointSecret),
220+
gameMode: data.get(#gameMode, or: $value.gameMode));
212221

213222
@override
214223
SetonixConfigCopyWith<$R2, SetonixConfig, $Out2> $chain<$R2, $Out2>(

0 commit comments

Comments
 (0)