Skip to content

Commit

Permalink
Change external game mode start state to indicate gamespaces starte r…
Browse files Browse the repository at this point in the history
…ather than deployed.
  • Loading branch information
sei-bstein committed Oct 27, 2023
1 parent 2c2e6e7 commit 060b6f5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ await _store.DoTransaction(async dbContext =>

// the challenges don't get created upon failure here (thanks to a db transaction)
// but we still need to clean up any created tm gamespaces
foreach (var gamespace in request.State.GamespacesDeployed)
foreach (var gamespace in request.State.GamespacesStarted)
{
try
{
Expand Down Expand Up @@ -302,7 +302,7 @@ private async Task<IDictionary<string, ExternalGameStartTeamGamespace>> DeployGa
GameEngineType = c.GameEngineType
});

request.State.GamespaceIdsStarted.Add(challengeState.Id);
request.State.GamespacesStarted.Add(challengeState);
await _gameHubBus.SendExternalGameGamespacesDeployProgressChange(request.State);
_logger.LogInformation(message: $"""Gamespace started for challenge "{c.Challenge.Id}".""");

Expand Down Expand Up @@ -333,7 +333,6 @@ await _store
.Where(c => c.Id == deployedChallenge.Challenge.Id)
.ExecuteUpdateAsync(up => up.SetProperty(c => c.State, serializedState), cancellationToken);

request.State.GamespacesDeployed.Add(state);
await _gameHubBus.SendExternalGameGamespacesDeployProgressChange(request.State);
}

Expand Down Expand Up @@ -376,7 +375,7 @@ await _store
.Where(c => c.Id == deployedChallenge.Challenge.Id)
.ExecuteUpdateAsync(up => up.SetProperty(c => c.State, serializedState), cancellationToken);

request.State.GamespacesDeployed.Add(challengeState);
request.State.GamespacesStarted.Add(challengeState);
await _gameHubBus.SendExternalGameGamespacesDeployProgressChange(request.State);
}

Expand All @@ -392,7 +391,7 @@ private ExternalGameStartMetaData BuildExternalGameMetaData(GameStartState start
foreach (var team in startState.Teams)
{
var teamChallenges = startState.ChallengesCreated.Where(c => c.TeamId == team.Team.Id).Select(c => c.Challenge);
var teamGameStates = startState.GamespacesDeployed.Where(g => teamChallenges.Select(c => c.Id).Contains(g.Id));
var teamGameStates = startState.GamespacesStarted.Where(g => teamChallenges.Select(c => c.Id).Contains(g.Id));

var teamToReturn = new ExternalGameStartMetaDataTeam
{
Expand Down
5 changes: 2 additions & 3 deletions src/Gameboard.Api/Features/Game/GameStart/GameStartModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ public class GameStartState
public required SimpleEntity Game { get; set; }
public List<GameStartStateChallenge> ChallengesCreated { get; private set; } = new List<GameStartStateChallenge>();
public int ChallengesTotal { get; set; } = 0;
public List<GameEngineGameState> GamespacesDeployed { get; set; } = new List<GameEngineGameState>();
public List<string> GamespaceIdsStarted { get; set; } = new List<string>();
public List<GameEngineGameState> GamespacesStarted { get; set; } = new List<GameEngineGameState>();
public int GamespacesTotal { get; set; } = 0;
public List<GameStartStatePlayer> Players { get; } = new List<GameStartStatePlayer>();
public List<GameStartStateTeam> Teams { get; } = new List<GameStartStateTeam>();
Expand All @@ -25,7 +24,7 @@ public double OverallProgress
if (GamespacesTotal == 0 || ChallengesTotal == 0)
return 0;

var retVal = Math.Round(((0.8 * GamespacesDeployed.Count) / GamespacesTotal) + ((0.2 * ChallengesCreated.Count) / ChallengesTotal));
var retVal = Math.Round(((0.8 * GamespacesStarted.Count) / GamespacesTotal) + ((0.2 * ChallengesCreated.Count) / ChallengesTotal));
return double.IsRealNumber(retVal) ? retVal : 0;
}
}
Expand Down

0 comments on commit 060b6f5

Please sign in to comment.