Skip to content

Commit

Permalink
iOS Tournaments
Browse files Browse the repository at this point in the history
Summary:
Adds Tournament functionality to iOS.

Brings the iOS wrappers over to Unity instead. The code has to exist somewhere, but since it only serves Unity, it should be removed from the iOS SDK.

Additionally, they're much more iterable when they exist independent of the iOS SDK.

Reviewed By: Alaeldin513

Differential Revision: D36362409

fbshipit-source-id: 7768d4af215c8b30225db3760478cca97f0a7238
  • Loading branch information
JarWarren authored and facebook-github-bot committed Jun 3, 2022
1 parent 5536d94 commit a23fe45
Show file tree
Hide file tree
Showing 37 changed files with 1,534 additions and 68 deletions.
61 changes: 61 additions & 0 deletions Facebook.Unity.IOS/IOSWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,48 @@ public Profile CurrentProfile()
}
}

public void GetTournaments(int requestId)
{
IOSWrapper.IOSFBGetTournaments(requestId);
}

public void UpdateTournament(string tournamentId, int score, int requestId)
{
IOSWrapper.IOSFBUpdateTournament(tournamentId, score, requestId);
}

public void UpdateAndShareTournament(
string tournamentId,
int score,
int requestId)
{
IOSWrapper.IOSFBUpdateAndShareTournament(
tournamentId,
score,
requestId
);
}

public void CreateAndShareTournament(
int initialScore,
string title,
TournamentSortOrder sortOrder,
TournamentScoreFormat scoreFormat,
long endTime,
string payload,
int requestId)
{
IOSWrapper.IOSFBCreateAndShareTournament(
initialScore,
title,
(int)sortOrder,
(int)scoreFormat,
endTime,
payload,
requestId
);
}

public void UploadImageToMediaLibrary(
int requestId,
string caption,
Expand Down Expand Up @@ -512,6 +554,25 @@ public void RefreshCurrentAccessToken(int requestId)
string caption,
string videoUri);

[DllImport("__Internal")]
private static extern void IOSFBGetTournaments(int requestID);

[DllImport("__Internal")]
private static extern void IOSFBUpdateTournament(string tournamentID, int score, int requestID);

[DllImport("__Internal")]
private static extern void IOSFBUpdateAndShareTournament(string tournamentID, int score, int requestID);

[DllImport("__Internal")]
private static extern void IOSFBCreateAndShareTournament(
int initialScore,
string title,
int sortOrder,
int scoreFormat,
long endTime,
string payload,
int requestID);

[DllImport("__Internal")]
private static extern void IOSFBCreateGamingContext(
int requestID,
Expand Down
30 changes: 30 additions & 0 deletions Facebook.Unity.Tests/Mobile/IOS/MockIOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,36 @@ public void SetDataProcessingOptions(string[] options, int country, int state)
this.MobileFacebook.OnUploadVideoToMediaLibraryComplete(new ResultContainer(result));
}

public void GetTournaments(int requestId)
{
this.LogMethodCall();
}

public void UpdateTournament(string tournamentId, int score, int requestId)
{
this.LogMethodCall();
}

public void UpdateAndShareTournament(
string tournamentId,
int score,
int requestId)
{
this.LogMethodCall();
}

public void CreateAndShareTournament(
int initialScore,
string title,
TournamentSortOrder sortOrder,
TournamentScoreFormat scoreFormat,
long endTime,
string payload,
int requestId)
{
this.LogMethodCall();
}

public void CreateGamingContext(int requestId, string playerID)
{
var result = MockResults.GetGenericResult(requestId, this.ResultExtras);
Expand Down
4 changes: 3 additions & 1 deletion Facebook.Unity/CallbackManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ private static void CallCallback(object callback, IResult result)
CallbackManager.TryCallCallback<ISessionScoreResult>(callback, result) ||
CallbackManager.TryCallCallback<ITournamentResult>(callback, result) ||
CallbackManager.TryCallCallback<ITournamentScoreResult>(callback, result) ||
CallbackManager.TryCallCallback<IGetTournamentsResult>(callback, result) ||
CallbackManager.TryCallCallback<IGroupCreateResult>(callback, result) ||
CallbackManager.TryCallCallback<IGroupJoinResult>(callback, result) ||
CallbackManager.TryCallCallback<IMediaUploadResult>(callback, result) ||
Expand All @@ -95,7 +96,8 @@ private static void CallCallback(object callback, IResult result)
CallbackManager.TryCallCallback<ILoginStatusResult>(callback, result) ||
CallbackManager.TryCallCallback<IProfileResult>(callback, result) ||
CallbackManager.TryCallCallback<IFriendFinderInvitationResult>(callback, result) ||
CallbackManager.TryCallCallback<IVirtualGamepadLayoutResult>(callback, result))
CallbackManager.TryCallCallback<IVirtualGamepadLayoutResult>(callback, result) ||
CallbackManager.TryCallCallback<IDialogResult>(callback, result))
{
return;
}
Expand Down
154 changes: 100 additions & 54 deletions Facebook.Unity/FB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -833,27 +833,27 @@ public static void ShareTournament(int score, Dictionary<string, string> data, F
FacebookDelegate<ITournamentResult> callback)
{
FacebookImpl.CreateTournament(initialScore, title, imageBase64DataUrl, sortOrder, scoreFormat, data, callback);
}


public static void UploadImageToMediaLibrary(string caption, Uri imageUri, bool shouldLaunchMediaDialog, FacebookDelegate<IMediaUploadResult> callback)
{
FacebookImpl.UploadImageToMediaLibrary(caption, imageUri, shouldLaunchMediaDialog, callback);
}

public static void UploadVideoToMediaLibrary(string caption, Uri videoUri, bool shouldLaunchMediaDialog, FacebookDelegate<IMediaUploadResult> callback)
{
FacebookImpl.UploadVideoToMediaLibrary(caption, videoUri, shouldLaunchMediaDialog, callback);
}

public static void UploadImageToMediaLibrary(string caption, Uri imageUri, bool shouldLaunchMediaDialog, string travelId, FacebookDelegate<IMediaUploadResult> callback)
{
FacebookImpl.UploadImageToMediaLibrary(caption, imageUri, shouldLaunchMediaDialog, travelId, callback);
}

public static void UploadVideoToMediaLibrary(string caption, Uri videoUri, bool shouldLaunchMediaDialog, string travelId, FacebookDelegate<IMediaUploadResult> callback)
{
FacebookImpl.UploadVideoToMediaLibrary(caption, videoUri, shouldLaunchMediaDialog, travelId, callback);
}


public static void UploadImageToMediaLibrary(string caption, Uri imageUri, bool shouldLaunchMediaDialog, FacebookDelegate<IMediaUploadResult> callback)
{
FacebookImpl.UploadImageToMediaLibrary(caption, imageUri, shouldLaunchMediaDialog, callback);
}

public static void UploadVideoToMediaLibrary(string caption, Uri videoUri, bool shouldLaunchMediaDialog, FacebookDelegate<IMediaUploadResult> callback)
{
FacebookImpl.UploadVideoToMediaLibrary(caption, videoUri, shouldLaunchMediaDialog, callback);
}

public static void UploadImageToMediaLibrary(string caption, Uri imageUri, bool shouldLaunchMediaDialog, string travelId, FacebookDelegate<IMediaUploadResult> callback)
{
FacebookImpl.UploadImageToMediaLibrary(caption, imageUri, shouldLaunchMediaDialog, travelId, callback);
}

public static void UploadVideoToMediaLibrary(string caption, Uri videoUri, bool shouldLaunchMediaDialog, string travelId, FacebookDelegate<IMediaUploadResult> callback)
{
FacebookImpl.UploadVideoToMediaLibrary(caption, videoUri, shouldLaunchMediaDialog, travelId, callback);
}

/// <summary>
Expand Down Expand Up @@ -1272,36 +1272,70 @@ public static void OpenFriendFinderDialog(FacebookDelegate<IGamingServicesFriend
public static void ScheduleAppToUserNotification(string title, string body, Uri media, int timeInterval, string payload, FacebookDelegate<IScheduleAppToUserNotificationResult> callback)
{
Mobile.MobileFacebookImpl.ScheduleAppToUserNotification(title, body, media, timeInterval, payload, callback);
}

public static void PostSessionScore(int score, FacebookDelegate<ISessionScoreResult> callback)
{
Mobile.MobileFacebookImpl.PostSessionScore(score, callback);
}

public static void PostTournamentScore(int score, FacebookDelegate<ITournamentScoreResult> callback)
{
Mobile.MobileFacebookImpl.PostTournamentScore(score, callback);
}

public static void GetTournament(FacebookDelegate<ITournamentResult> callback)
{
Mobile.MobileFacebookImpl.GetTournament(callback);
}

public static void ShareTournament(int score, Dictionary<string, string> data, FacebookDelegate<ITournamentScoreResult> callback)
{
Mobile.MobileFacebookImpl.ShareTournament(score,data, callback);
}

public static void UploadImageToMediaLibrary(string caption, Uri imageUri, bool shouldLaunchMediaDialog, FacebookDelegate<IMediaUploadResult> callback)
{
Mobile.MobileFacebookImpl.UploadImageToMediaLibrary(caption, imageUri, shouldLaunchMediaDialog, callback);
}

public static void UploadVideoToMediaLibrary(string caption, Uri videoUri, bool shouldLaunchMediaDialog, FacebookDelegate<IMediaUploadResult> callback)
{
Mobile.MobileFacebookImpl.UploadVideoToMediaLibrary(caption, videoUri, shouldLaunchMediaDialog, callback);
}

public static void PostSessionScore(int score, FacebookDelegate<ISessionScoreResult> callback)
{
Mobile.MobileFacebookImpl.PostSessionScore(score, callback);
}

public static void PostTournamentScore(int score, FacebookDelegate<ITournamentScoreResult> callback)
{
Mobile.MobileFacebookImpl.PostTournamentScore(score, callback);
}

public static void GetTournament(FacebookDelegate<ITournamentResult> callback)
{
Mobile.MobileFacebookImpl.GetTournament(callback);
}

public static void ShareTournament(int score, Dictionary<string, string> data, FacebookDelegate<ITournamentScoreResult> callback)
{
Mobile.MobileFacebookImpl.ShareTournament(score,data, callback);
}

public static void GetTournaments(FacebookDelegate<IGetTournamentsResult> callback)
{
Mobile.MobileFacebookImpl.GetTournaments(callback);
}

public static void UpdateTournament(string tournamentID, int score, FacebookDelegate<ITournamentScoreResult> callback)
{
Mobile.MobileFacebookImpl.UpdateTournament(tournamentID, score, callback);
}

public static void UpdateAndShareTournament(string tournamentID, int score, FacebookDelegate<IDialogResult> callback)
{
Mobile.MobileFacebookImpl.UpdateAndShareTournament(tournamentID, score, callback);
}

public static void CreateAndShareTournament(
int initialScore,
string title,
TournamentSortOrder sortOrder,
TournamentScoreFormat scoreFormat,
DateTime endTime,
string payload,
FacebookDelegate<IDialogResult> callback)
{
Mobile.MobileFacebookImpl.CreateAndShareTournament(
initialScore,
title,
sortOrder,
scoreFormat,
(long)endTime.Subtract(new DateTime(1970, 1, 1)).TotalSeconds,
payload,
callback);
}

public static void UploadImageToMediaLibrary(string caption, Uri imageUri, bool shouldLaunchMediaDialog, FacebookDelegate<IMediaUploadResult> callback)
{
Mobile.MobileFacebookImpl.UploadImageToMediaLibrary(caption, imageUri, shouldLaunchMediaDialog, callback);
}

public static void UploadVideoToMediaLibrary(string caption, Uri videoUri, bool shouldLaunchMediaDialog, FacebookDelegate<IMediaUploadResult> callback)
{
Mobile.MobileFacebookImpl.UploadVideoToMediaLibrary(caption, videoUri, shouldLaunchMediaDialog, callback);
}

}
Expand Down Expand Up @@ -1354,9 +1388,9 @@ private static IWindowsFacebook WindowsFacebookImpl
}

return impl;
}
}

}
}

/// <summary>
/// Sets the Virtual Gamepad Layout to use.
/// </summary>
Expand All @@ -1382,3 +1416,15 @@ public void Start()
}
}
}

public enum TournamentSortOrder
{
HigherIsBetter,
LowerIsBetter
}

public enum TournamentScoreFormat
{
Numeric,
Time
}
4 changes: 4 additions & 0 deletions Facebook.Unity/Facebook.Unity.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@
<Compile Include="FBLocation.cs" />
<Compile Include="Results\ITournamentResult.cs" />
<Compile Include="Results\TournamentResult.cs" />
<Compile Include="Results\IGetTournamentsResult.cs" />
<Compile Include="Results\GetTournamentsResult.cs" />
<Compile Include="Results\IDialogResult.cs" />
<Compile Include="Results\AbortDialogResult.cs" />
<Compile Include="Results\ITournamentScoreResult.cs" />
<Compile Include="Results\TournamentScoreResult.cs" />
<Compile Include="Windows\WindowsFacebook.cs" />
Expand Down
15 changes: 15 additions & 0 deletions Facebook.Unity/Mobile/IMobileFacebook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ internal interface IMobileFacebook : IFacebook

void GetPayload(FacebookDelegate<IPayloadResult> callback);

void GetTournaments(FacebookDelegate<IGetTournamentsResult> callback);

void UpdateTournament(string tournamentID, int score, FacebookDelegate<ITournamentScoreResult> callback);

void UpdateAndShareTournament(string tournamentID, int score, FacebookDelegate<IDialogResult> callback);

void CreateAndShareTournament(
int initialScore,
string title,
TournamentSortOrder sortOrder,
TournamentScoreFormat scoreFormat,
long endTime,
string payload,
FacebookDelegate<IDialogResult> callback);

void OpenAppStore(FacebookDelegate<IOpenAppStoreResult> callback);

void CreateGamingContext(string playerID, FacebookDelegate<ICreateGamingContextResult> callback);
Expand Down
10 changes: 10 additions & 0 deletions Facebook.Unity/Mobile/IMobileFacebookCallbackHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ internal interface IMobileFacebookCallbackHandler : IFacebookCallbackHandler

void OnPostTournamentScoreComplete(string message);

void OnGetTournamentsComplete(string message);

void OnUpdateTournamentComplete(string message);

void OnTournamentDialogSuccess(string message);

void OnTournamentDialogCancel(string message);

void OnTournamentDialogError(string message);

void OnOpenAppStoreComplete(string message);

void OnCreateGamingContextComplete(string message);
Expand Down
10 changes: 10 additions & 0 deletions Facebook.Unity/Mobile/IMobileFacebookResultHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ internal interface IMobileFacebookResultHandler : IFacebookResultHandler

void OnPostTournamentScoreComplete(ResultContainer resultContainer);

void OnGetTournamentsComplete(ResultContainer resultContainer);

void OnUpdateTournamentComplete(ResultContainer resultContainer);

void OnTournamentDialogSuccess(ResultContainer resultContainer);

void OnTournamentDialogCancel(ResultContainer resultContainer);

void OnTournamentDialogError(ResultContainer resultContainer);

void OnOpenAppStoreComplete(ResultContainer resultContainer);

void OnCreateGamingContextComplete(ResultContainer resultContainer);
Expand Down

0 comments on commit a23fe45

Please sign in to comment.