Skip to content

Commit

Permalink
Remove Refresh.Analyzers project (#531)
Browse files Browse the repository at this point in the history
Closes #528 and closes #88.

`Refresh.Analyzers` has been causing issues since it was implemented.
Whether it be `CodeAnalysis.CSharp` updating and breaking workflows, the
challenge that comes with implementing new events, or causing hacky
naming in `EventType`, it's never been good and probably never will be.

It was intended to alleviate copy+pasting when making new events but
it's caused more pain than it's helped. So, let's just remove it.

To do this I copied the output of the generated classes, cleaned them up
a bit to keep things more in-line with the rest of the codebase, moved
the database partials for recent activity to their own subfolder, and
then deleted the `Refresh.Analyzers` project entirely. I also took the
opportunity to fix the somewhat cursed naming of the `EventType` enum
for consistency.
  • Loading branch information
jvyden authored Jun 18, 2024
2 parents 3b2c746 + b899e4f commit 9e0ffcd
Show file tree
Hide file tree
Showing 13 changed files with 331 additions and 274 deletions.
173 changes: 0 additions & 173 deletions Refresh.Analyzers/ActivityGenerator.cs

This file was deleted.

16 changes: 0 additions & 16 deletions Refresh.Analyzers/Refresh.Analyzers.csproj

This file was deleted.

20 changes: 0 additions & 20 deletions Refresh.Analyzers/SyntaxReceivers/EnumNameReceiver.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public DatabaseList<Event> GetUserRecentActivity(ActivityQueryParameters paramet
userFriends.Contains(e.User.UserId) ||
userFriends.Contains(e.StoredObjectId) ||
this.GetLevelById(e.StoredSequentialId ?? int.MaxValue)?.Publisher?.UserId == parameters.User.UserId ||
e.EventType == EventType.Level_TeamPick ||
e.EventType == EventType.User_FirstLogin
e.EventType == EventType.LevelTeamPick ||
e.EventType == EventType.UserFirstLogin
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Diagnostics;
using Refresh.GameServer.Types.Activity;
using Refresh.GameServer.Types.Levels;
using Refresh.GameServer.Types.Relations;
using Refresh.GameServer.Types.UserData;
using Refresh.GameServer.Types.UserData.Leaderboard;

namespace Refresh.GameServer.Database;

public partial class GameDatabaseContext // ActivityRead
{
public GameUser? GetUserFromEvent(Event e)
{
if (e.StoredDataType != EventDataType.User)
throw new InvalidOperationException($"Event does not store the correct data type (expected {nameof(EventDataType.User)})");

Debug.Assert(e.StoredObjectId != null);

return this.GetUserByObjectId(e.StoredObjectId);
}

public GameLevel? GetLevelFromEvent(Event e)
{
if (e.StoredDataType != EventDataType.Level)
throw new InvalidOperationException($"Event does not store the correct data type (expected {nameof(EventDataType.Level)})");

Debug.Assert(e.StoredSequentialId != null);

return this.GetLevelById(e.StoredSequentialId.Value);
}

public GameSubmittedScore? GetScoreFromEvent(Event e)
{
if (e.StoredDataType != EventDataType.Score)
throw new InvalidOperationException($"Event does not store the correct data type (expected {nameof(EventDataType.Score)})");

Debug.Assert(e.StoredObjectId != null);

return this.GetScoreByObjectId(e.StoredObjectId);
}

public RateLevelRelation? GetRateLevelRelationFromEvent(Event e)
{
if (e.StoredDataType != EventDataType.RateLevelRelation)
throw new InvalidOperationException($"Event does not store the correct data type (expected {nameof(EventDataType.RateLevelRelation)})");

Debug.Assert(e.StoredObjectId != null);

return this._realm.All<RateLevelRelation>()
.FirstOrDefault(l => l.RateLevelRelationId == e.StoredObjectId);
}
}
Loading

0 comments on commit 9e0ffcd

Please sign in to comment.