Skip to content
New issue

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

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

Already on GitHub? # to your account

DataStorage: implement race mode helper #109

Merged
merged 1 commit into from
Nov 22, 2024
Merged
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
25 changes: 25 additions & 0 deletions Archipelago.MultiClient.Net/Helpers/DataStorageWrappers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,20 @@ void TrackHints(Action<Hint[]> onHintsUpdated,
/// <param name="team">the team id of the player to request the status for, defaults to the current player's team if left empty</param>
void TrackClientStatus(Action<ArchipelagoClientState> onStatusUpdated,
bool retrieveCurrentClientStatus = true, int? slot = null, int? team = null);

#if NET35
/// <summary>
/// Retrieves the server's race mode setting. 0 for disabled, 1 for enabled
/// </summary>
/// <param name="onRaceModeRetrieved"> the method to call with the retrieved race mode setting</param>
void GetRaceModeAsync(Action<int> onRaceModeRetrieved);
#else
/// <summary>
/// Retrieves the server's race mode setting. 0 for disabled, 1 for enabled
/// </summary>
/// <param name="onRaceModeRetrieved"> the method to call with the retrieved race mode setting</param>
Task<int> GetRaceModeAsync();
#endif
}

public partial class DataStorageHelper : IDataStorageWrapper
Expand All @@ -197,6 +211,7 @@ DataStorageElement GetLocationNameGroupsElement(string game = null) =>
this[Scope.ReadOnly, $"location_name_groups_{game ?? connectionInfoProvider.Game}"];
DataStorageElement GetClientStatusElement(int? slot = null, int? team = null) =>
this[Scope.ReadOnly, $"client_status_{team ?? connectionInfoProvider.Team}_{slot ?? connectionInfoProvider.Slot}"];
DataStorageElement GetRaceModeElement() => this[Scope.ReadOnly, "race_mode"];

/// <inheritdoc />
public Hint[] GetHints(int? slot = null, int? team = null) =>
Expand Down Expand Up @@ -302,5 +317,15 @@ public void TrackClientStatus(Action<ArchipelagoClientState> onStatusUpdated,
GetClientStatusAsync(slot, team).ContinueWith(t => onStatusUpdated(t.Result));
#endif
}

#if NET35
/// <inheritdoc />
public void GetRaceModeAsync(Action<int> onRaceModeRetrieved) =>
GetRaceModeElement().GetAsync(t => onRaceModeRetrieved(t.ToObject<int?>() ?? 0));
#else
/// <inheritdoc />
public Task<int> GetRaceModeAsync() => GetRaceModeElement().GetAsync<int?>()
.ContinueWith(t => t.Result ?? 0);
#endif
}
}
Loading