Skip to content

Commit

Permalink
Merge pull request #109 from alwaysintreble/race_mode
Browse files Browse the repository at this point in the history
DataStorage: implement race mode helper
  • Loading branch information
Jarno458 authored Nov 22, 2024
2 parents 054752a + a283287 commit 0d15540
Showing 1 changed file with 25 additions and 0 deletions.
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
}
}

0 comments on commit 0d15540

Please sign in to comment.