-
-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring of activity tracker handling
this will either go really well or horribly wrong
- Loading branch information
1 parent
dfcd5b6
commit 26b7cbd
Showing
13 changed files
with
340 additions
and
211 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using System.Web; | ||
using System.Windows.Input; | ||
|
||
using CommunityToolkit.Mvvm.Input; | ||
|
||
namespace Bloxstrap.Models | ||
{ | ||
public class ActivityData | ||
{ | ||
private long _universeId = 0; | ||
|
||
/// <summary> | ||
/// If the current activity stems from an in-universe teleport, then this will be | ||
/// set to the activity that corresponds to the initial game join | ||
/// </summary> | ||
public ActivityData? RootActivity; | ||
|
||
public long UniverseId | ||
{ | ||
get => _universeId; | ||
set | ||
{ | ||
_universeId = value; | ||
UniverseDetails.LoadFromCache(value); | ||
} | ||
} | ||
|
||
public long PlaceId { get; set; } = 0; | ||
|
||
public string JobId { get; set; } = String.Empty; | ||
|
||
/// <summary> | ||
/// This will be empty unless the server joined is a private server | ||
/// </summary> | ||
public string AccessCode { get; set; } = String.Empty; | ||
|
||
public string MachineAddress { get; set; } = String.Empty; | ||
|
||
public bool IsTeleport { get; set; } = false; | ||
|
||
public ServerType ServerType { get; set; } = ServerType.Public; | ||
|
||
public DateTime TimeJoined { get; set; } | ||
|
||
public DateTime? TimeLeft { get; set; } | ||
|
||
/// <summary> | ||
/// This gets set to true if this activity is from a same-universe teleport, whether public or reserved | ||
/// </summary> | ||
public bool IsRetainedUniverse { get; set; } = false; | ||
|
||
// everything below here is optional strictly for bloxstraprpc, discord rich presence, or game history | ||
|
||
/// <summary> | ||
/// This is intended only for other people to use, i.e. context menu invite link, rich presence joining | ||
/// </summary> | ||
public string RPCLaunchData { get; set; } = String.Empty; | ||
|
||
public UniverseDetails? UniverseDetails { get; set; } | ||
|
||
public string GameHistoryDescription | ||
{ | ||
get | ||
{ | ||
string desc = String.Format("{0} • {1} - {2}", UniverseDetails?.Data.Creator.Name, TimeJoined.ToString("h:mm tt"), TimeLeft?.ToString("h:mm tt")); | ||
|
||
if (ServerType != ServerType.Public) | ||
desc += " • " + ServerType.ToTranslatedString(); | ||
|
||
return desc; | ||
} | ||
} | ||
|
||
public ICommand RejoinServerCommand => new RelayCommand(RejoinServer); | ||
|
||
public string GetInviteDeeplink(bool launchData = true) | ||
{ | ||
string deeplink = $"roblox://experiences/start?placeId={PlaceId}"; | ||
|
||
if (ServerType == ServerType.Private) | ||
deeplink += "&accessCode=" + AccessCode; | ||
else | ||
deeplink += "&gameInstanceId=" + JobId; | ||
|
||
if (launchData && !String.IsNullOrEmpty(RPCLaunchData)) | ||
deeplink += "&launchData=" + HttpUtility.UrlEncode(RPCLaunchData); | ||
|
||
return deeplink; | ||
} | ||
|
||
private void RejoinServer() | ||
{ | ||
string playerPath = Path.Combine(Paths.Versions, App.State.Prop.PlayerVersionGuid, "RobloxPlayerBeta.exe"); | ||
|
||
Process.Start(playerPath, GetInviteDeeplink(false)); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
namespace Bloxstrap.Models | ||
{ | ||
public class UniverseDetails | ||
{ | ||
private static List<UniverseDetails> _cache { get; set; } = new(); | ||
|
||
public GameDetailResponse Data { get; set; } = null!; | ||
|
||
/// <summary> | ||
/// Returns data for a 128x128 icon | ||
/// </summary> | ||
public ThumbnailResponse Thumbnail { get; set; } = null!; | ||
|
||
public static UniverseDetails? LoadFromCache(long id) | ||
{ | ||
var cacheQuery = _cache.Where(x => x.Data?.Id == id); | ||
|
||
if (cacheQuery.Any()) | ||
return cacheQuery.First(); | ||
|
||
return null; | ||
} | ||
|
||
public static Task<bool> FetchSingle(long id) => FetchBulk(id.ToString()); | ||
|
||
public static async Task<bool> FetchBulk(string ids) | ||
{ | ||
var gameDetailResponse = await Http.GetJson<ApiArrayResponse<GameDetailResponse>>($"https://games.roblox.com/v1/games?universeIds={ids}"); | ||
if (gameDetailResponse is null || !gameDetailResponse.Data.Any()) | ||
return false; | ||
|
||
var universeThumbnailResponse = await Http.GetJson<ApiArrayResponse<ThumbnailResponse>>($"https://thumbnails.roblox.com/v1/games/icons?universeIds={ids}&returnPolicy=PlaceHolder&size=128x128&format=Png&isCircular=false"); | ||
if (universeThumbnailResponse is null || !universeThumbnailResponse.Data.Any()) | ||
return false; | ||
|
||
foreach (string strId in ids.Split(',')) | ||
{ | ||
long id = long.Parse(strId); | ||
|
||
_cache.Add(new UniverseDetails | ||
{ | ||
Data = gameDetailResponse.Data.Where(x => x.Id == id).First(), | ||
Thumbnail = universeThumbnailResponse.Data.Where(x => x.TargetId == id).First(), | ||
}); | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.