Skip to content

Commit a6327bd

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

File tree

22 files changed

+420
-347
lines changed

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
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)