Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Team Picks refactor #595

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions Refresh.GameServer/Database/GameDatabaseContext.Levels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ public GameLevel GetStoryLevelById(int id)
newLevel.Publisher = author;
newLevel.PublishDate = oldLevel.PublishDate;
newLevel.UpdateDate = this._time.TimestampMilliseconds; // Set the last modified date
newLevel.DateTeamPicked = oldLevel.DateTeamPicked;

// If the actual contents of the level haven't changed, extract some extra information
if (oldLevel.RootResource == newLevel.RootResource)
{
newLevel.TeamPicked = oldLevel.TeamPicked;
newLevel.GameVersion = oldLevel.GameVersion;
}

Expand Down Expand Up @@ -319,9 +319,9 @@ public DatabaseList<GameLevel> GetHighestRatedLevels(int count, int skip, GameUs
[Pure]
public DatabaseList<GameLevel> GetTeamPickedLevels(int count, int skip, GameUser? user, LevelFilterSettings levelFilterSettings) =>
new(this.GetLevelsByGameVersion(levelFilterSettings.GameVersion)
.Where(l => l.TeamPicked)
.Where(l => l.DateTeamPicked != null)
.FilterByLevelFilterSettings(user, levelFilterSettings)
.OrderByDescending(l => l.PublishDate), skip, count);
.OrderByDescending(l => l.DateTeamPicked), skip, count);

[Pure]
public DatabaseList<GameLevel> GetDeveloperLevels(int count, int skip, LevelFilterSettings levelFilterSettings) =>
Expand Down Expand Up @@ -424,16 +424,21 @@ public int GetTotalLevelsPublishedByUser(GameUser user, TokenGame game)
[Pure]
public GameLevel? GetLevelById(int id) => this.GameLevels.FirstOrDefault(l => l.LevelId == id);

private void SetLevelPickStatus(GameLevel level, bool status)
public void AddTeamPickToLevel(GameLevel level)
{
this.Write(() =>
{
level.TeamPicked = status;
level.DateTeamPicked = this._time.Now;
});
}

public void AddTeamPickToLevel(GameLevel level) => this.SetLevelPickStatus(level, true);
public void RemoveTeamPickFromLevel(GameLevel level) => this.SetLevelPickStatus(level, false);
public void RemoveTeamPickFromLevel(GameLevel level)
{
this.Write(() =>
{
level.DateTeamPicked = null;
});
}

public void SetLevelScores(Dictionary<GameLevel, float> scoresToSet)
{
Expand Down
12 changes: 11 additions & 1 deletion Refresh.GameServer/Database/GameDatabaseProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected GameDatabaseProvider(IDateTimeProvider time)
this._time = time;
}

protected override ulong SchemaVersion => 136;
protected override ulong SchemaVersion => 137;

protected override string Filename => "refreshGameServer.realm";

Expand Down Expand Up @@ -300,6 +300,16 @@ protected override void Migrate(Migration migration, ulong oldVersion)
});
}
}

// In version 137 we started storing the date at which levels were picked instead of just that they are picked.
// Since this is new information, let's set this to the date of the last update.
if (oldVersion < 137)
{
if (oldLevel.TeamPicked)
newLevel.DateTeamPicked = DateTimeOffset.FromUnixTimeMilliseconds(oldLevel.UpdateDate);
else
newLevel.DateTeamPicked = null;
}
}

// In version 22, tokens added expiry and types so just wipe them all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class ApiGameLevelResponse : IApiResponse, IDataConvertableFrom<ApiGameLe

public required int UniquePlays { get; set; }
public required bool TeamPicked { get; set; }
public required DateTimeOffset? DateTeamPicked { get; set; }
public required GameLevelType LevelType { get; set; }
public required bool IsLocked { get; set; }
public required bool IsSubLevel { get; set; }
Expand Down Expand Up @@ -77,6 +78,7 @@ public class ApiGameLevelResponse : IApiResponse, IDataConvertableFrom<ApiGameLe
Hearts = dataContext.Database.GetFavouriteCountForLevel(level),
UniquePlays = dataContext.Database.GetUniquePlaysForLevel(level),
TeamPicked = level.TeamPicked,
DateTeamPicked = level.DateTeamPicked,
RootLevelHash = level.RootResource,
GameVersion = level.GameVersion,
LevelType = level.LevelType,
Expand Down
4 changes: 3 additions & 1 deletion Refresh.GameServer/Types/Levels/GameLevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ public partial class GameLevel : IRealmObject, ISequentialId
public bool EnforceMinMaxPlayers { get; set; }

public bool SameScreenGame { get; set; }
public bool TeamPicked { get; set; }
[Ignored]
public bool TeamPicked => this.DateTeamPicked != null;
public DateTimeOffset? DateTeamPicked { get; set; }

/// <summary>
/// The GUID of the background, this seems to only be used by LBP PSP
Expand Down
Loading