Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/v0.2.1' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
rYuuk authored Apr 21, 2023
2 parents 28f5f7e + ea9f0a7 commit 65ab1e1
Show file tree
Hide file tree
Showing 16 changed files with 165 additions and 47 deletions.
23 changes: 23 additions & 0 deletions .githooks/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh

COMMIT_MESSAGE="$(head -n1 "$1")"
COMMIT_MESSAGE_REGEX="^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\([a-z ]+\))?: .+$"
AUTO_COMMIT_MESSAGE_REGEX="^Merge (pull request|branch) [a-zA-Z0-9#'_/-]+ (of [a-zA-Z0-9#':_. /-]+ )?(from|into) [a-zA-Z0-9#':_. /-]+$"


if [[ $COMMIT_MESSAGE =~ $COMMIT_MESSAGE_REGEX || $COMMIT_MESSAGE =~ $AUTO_COMMIT_MESSAGE_REGEX ]]; then
exit 0
else
echo "Invalid commit message format:"
echo "Your message: '${COMMIT_MESSAGE}'"
echo ""
echo "Please use the following format:"
echo "<type>(<scope>): <subject>"
echo ""
echo " the (<scope>) part is optional"
echo ""
echo "Examples:"
echo "feat(login): add support for email login"
echo "fix: fix issue with user profile image upload"
exit 1
fi
30 changes: 30 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh

# Gitflow branching and naming strategy enforcement for Windows and Mac

protected_branches="^(main|develop|hotfix/|release/|feature/)"
current_branch=$(git symbolic-ref HEAD | sed 's!refs/heads/!!')

# Ensure the branch name adheres to the Gitflow naming strategy
if ! [[ ${current_branch} =~ ${protected_branches} ]]; then
echo "Error: The current branch '${current_branch}' does not adhere to the Gitflow naming strategy."
echo "Branch names must match the following patterns: main, develop, hotfix/*, release/*, feature/*."
exit 1
fi

# Check if pushing to the correct remote branch
remote_branch=$(git for-each-ref --format='%(upstream:short)' $(git symbolic-ref -q HEAD))
if [[ -z "${remote_branch}" ]]; then
echo "Error: The current branch '${current_branch}' has no tracking remote branch."
exit 1
fi

remote_name=$(echo ${remote_branch} | cut -d/ -f1)
remote_branch_name=$(echo ${remote_branch} | cut -d/ -f2-)

if [[ "${current_branch}" != "${remote_branch_name}" ]]; then
echo "Error: The current branch '${current_branch}' must be pushed to a remote branch with the same name: '${remote_name}/${current_branch}'."
exit 1
fi

exit 0
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<!-- Add link for the ticket here editing the TICKETID-->

## [TICKETID](https://ready-player-me.monday.com/boards/2563815861/pulses/TICKETID)
## [TICKETID](https://ready-player-me.atlassian.net/browse/TICKETID)

## Description

Expand Down
9 changes: 9 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ Scan through our [existing issues](https://github.com/github/docs/issues) to fin

### Commit your update

We encourage following the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) format when it comes to writing commit messages. Our package repositories come with a .githooks folder that has a commit-msg file that can enforce this.
To set this up you just need to configure git's hookspath folder to point there.

You can do this by
1. Open the terminal
2. Navigate to the root folder of this repository
3. Run the following command
`git config core.hooksPath .githooks`

Commit the changes once you are happy with them. Don't forget to [self-review](#self-review) to speed up the review process:zap:.

### Self review
Expand Down
18 changes: 14 additions & 4 deletions Runtime/AuthManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public static class AuthManager
public static Action<UserSession> OnSignedIn;
public static Action<UserSession> OnSessionRefreshed;
public static Action OnSignedOut;
public static Action<string> OnSignInError;

static AuthManager()
{
Expand All @@ -41,11 +42,20 @@ public static async void SendEmailCode(string email)
await AuthenticationRequests.SendCodeToEmail(email);
}

public static async Task LoginWithCode(string otp)
public static async Task<bool> LoginWithCode(string otp)
{
userSession = await AuthenticationRequests.LoginWithCode(otp);
IsSignedIn = true;
OnSignedIn?.Invoke(userSession);
try
{
userSession = await AuthenticationRequests.LoginWithCode(otp);
IsSignedIn = true;
OnSignedIn?.Invoke(userSession);
return true;
}
catch (Exception e)
{
OnSignInError?.Invoke(e.Message);
return false;
}
}

public static async Task RefreshToken()
Expand Down
19 changes: 15 additions & 4 deletions Runtime/AvatarManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,33 @@ public AvatarManager(BodyType bodyType, OutfitGender gender, AvatarConfig avatar
/// </summary>
/// <param name="avatarProperties">Properties which describes avatar</param>
/// <returns>Avatar gameObject</returns>
public async Task<GameObject> Create(AvatarProperties avatarProperties)
public async Task<AvatarProperties> CreateNewAvatar(AvatarProperties avatarProperties)
{
try
{
avatarId = await avatarAPIRequests.CreateNewAvatar(avatarProperties);
avatarProperties = await avatarAPIRequests.CreateNewAvatar(avatarProperties);
avatarId = avatarProperties.Id;
}
catch (Exception e)
{
OnError?.Invoke(e.Message);
return null;
return avatarProperties;
}

if (ctxSource.IsCancellationRequested)
{
return avatarProperties;
}

return avatarProperties;
}

public async Task<GameObject> GetPreviewAvatar(string id)
{
byte[] data;
try
{
data = await avatarAPIRequests.GetPreviewAvatar(avatarId, avatarConfigParameters);
data = await avatarAPIRequests.GetPreviewAvatar(id, avatarConfigParameters);
}
catch (Exception e)
{
Expand Down
14 changes: 14 additions & 0 deletions Runtime/Utils/ResponseExtension.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Newtonsoft.Json.Linq;
using ReadyPlayerMe.Core;

namespace ReadyPlayerMe.AvatarCreator
Expand All @@ -12,5 +13,18 @@ public static void ThrowIfError(this IResponse response)
throw new Exception(response.Error);
}
}

public static void ThrowIfError(this Response response)
{
if (!response.IsSuccess)
{
if (!string.IsNullOrEmpty(response.Text))
{
var json = JObject.Parse(response.Text);
throw new Exception(json["message"]!.ToString());
}
throw new Exception(response.Error);
}
}
}
}
10 changes: 5 additions & 5 deletions Runtime/WebRequests/AvatarAPIRequests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -74,7 +75,7 @@ public async Task<AvatarProperties> GetAvatarMetadata(string avatarId)
return JsonConvert.DeserializeObject<AvatarProperties>(data);
}

public async Task<string> CreateNewAvatar(AvatarProperties avatarProperties)
public async Task<AvatarProperties> CreateNewAvatar(AvatarProperties avatarProperties)
{
var response = await authorizedRequest.SendRequest<Response>(
new RequestData
Expand All @@ -85,12 +86,11 @@ public async Task<string> CreateNewAvatar(AvatarProperties avatarProperties)
},
ctx: ctx
);

response.ThrowIfError();

var metadata = JObject.Parse(response.Text);
var avatarId = metadata["data"]?["id"]?.ToString();
return avatarId;
var data = metadata["data"]!.ToString();
return JsonConvert.DeserializeObject<AvatarProperties>(data);
}

public async Task<byte[]> GetPreviewAvatar(string avatarId, string parameters = null)
Expand Down
2 changes: 1 addition & 1 deletion Samples~/Prefabs/Selections/CameraPhotoSelection.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastTarget: 0
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
Expand Down
16 changes: 8 additions & 8 deletions Samples~/Scenes/AvatarCreatorExample.unity
Original file line number Diff line number Diff line change
Expand Up @@ -2361,8 +2361,8 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 175, y: -27.173203}
m_SizeDelta: {x: 350, y: 50}
m_AnchoredPosition: {x: 200.97995, y: -33.423203}
m_SizeDelta: {x: 402.2054, y: 66.8464}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &446309240
MonoBehaviour:
Expand All @@ -2388,9 +2388,9 @@ MonoBehaviour:
m_Font: {fileID: 12800000, guid: 12aac7490fc6e5b41a811cc24c825f5e, type: 3}
m_FontSize: 25
m_FontStyle: 0
m_BestFit: 0
m_BestFit: 1
m_MinSize: 0
m_MaxSize: 40
m_MaxSize: 25
m_Alignment: 4
m_AlignByGeometry: 0
m_RichText: 1
Expand Down Expand Up @@ -6962,8 +6962,8 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 174.99997, y: -76.51961}
m_SizeDelta: {x: 200, y: 40}
m_AnchoredPosition: {x: 200.97995, y: -82.76961}
m_SizeDelta: {x: 200, y: 31.846405}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &895232620
MonoBehaviour:
Expand Down Expand Up @@ -16609,8 +16609,8 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: -4.8062}
m_SizeDelta: {x: -151.96, y: -51.9072}
m_AnchoredPosition: {x: -0.000030517578, y: -4.806198}
m_SizeDelta: {x: -100.000046, y: -51.9072}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1869745903
MonoBehaviour:
Expand Down
16 changes: 8 additions & 8 deletions Samples~/Scripts/UI/SelectionScreens/AvatarCreatorSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private async void Setup()
AvatarCreatorData.AvatarProperties.Gender,
inCreatorConfig,
ctxSource.Token);
avatarManager.OnError = OnErrorCallback;
avatarManager.OnError += OnErrorCallback;

await LoadAssets();
currentAvatar = await LoadAvatar();
Expand All @@ -63,6 +63,7 @@ private async void Setup()
return;

await LoadAvatarColors();
assetButtonCreator.SetSelectedAssets(AvatarCreatorData.AvatarProperties.Assets);
LoadingManager.DisableLoading();
}

Expand All @@ -80,8 +81,8 @@ private void Cleanup()

private void OnErrorCallback(string error)
{
avatarManager.OnError = null;
partnerAssetManager.OnError = null;
avatarManager.OnError -= OnErrorCallback;
partnerAssetManager.OnError -= OnErrorCallback;

ctxSource?.Cancel();
StateMachine.Back();
Expand All @@ -97,7 +98,7 @@ private async Task LoadAssets()
AvatarCreatorData.AvatarProperties.Gender,
ctxSource.Token);

partnerAssetManager.OnError = OnErrorCallback;
partnerAssetManager.OnError += OnErrorCallback;

var assetIconDownloadTasks = await partnerAssetManager.GetAllAssets();

Expand All @@ -115,7 +116,9 @@ private async Task<GameObject> LoadAvatar()
if (string.IsNullOrEmpty(AvatarCreatorData.AvatarProperties.Id))
{
AvatarCreatorData.AvatarProperties.Assets ??= GetDefaultAssets();
avatar = await avatarManager.Create(AvatarCreatorData.AvatarProperties);

AvatarCreatorData.AvatarProperties = await avatarManager.CreateNewAvatar(AvatarCreatorData.AvatarProperties);
avatar = await avatarManager.GetPreviewAvatar(AvatarCreatorData.AvatarProperties.Id);
}
else
{
Expand All @@ -127,8 +130,6 @@ private async Task<GameObject> LoadAvatar()
return null;
}

AvatarCreatorData.AvatarProperties.Id = avatarManager.AvatarId;

ProcessAvatar(avatar);

DebugPanel.AddLogWithDuration("Avatar loaded", Time.time - startTime);
Expand Down Expand Up @@ -162,7 +163,6 @@ private void CreateUI(BodyType bodyType, Dictionary<string, AssetType> assets)
assetTypeUICreator.CreateUI(bodyType, AssetTypeHelper.GetAssetTypeList(bodyType));
assetButtonCreator.CreateAssetButtons(assets, UpdateAvatar);
assetButtonCreator.CreateClearButton(UpdateAvatar);
assetButtonCreator.SetSelectedAssets(AvatarCreatorData.AvatarProperties.Assets);
saveButton.gameObject.SetActive(true);
}

Expand Down
2 changes: 2 additions & 0 deletions Samples~/Scripts/UI/SelectionScreens/CameraPhotoSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ private void OnCameraButton()
texture.Apply();

var bytes = texture.EncodeToPNG();

AvatarCreatorData.AvatarProperties.Id = string.Empty;
AvatarCreatorData.AvatarProperties.Base64Image = Convert.ToBase64String(bytes);

StateMachine.SetState(StateType.Editor);
Expand Down
19 changes: 15 additions & 4 deletions Samples~/Scripts/UI/SelectionScreens/LoginWithEmailSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,20 @@ private void OnChangeEmail()
private async void OnLogin()
{
LoadingManager.EnableLoading("Signing In");
await AuthManager.LoginWithCode(codeField.text);
OnChangeEmail();
LoadingManager.DisableLoading();
StateMachine.SetState(StateType.AvatarSelection);

AuthManager.OnSignInError += OnSignInError;

if (await AuthManager.LoginWithCode(codeField.text))
{
OnChangeEmail();
LoadingManager.DisableLoading();
StateMachine.SetState(StateType.AvatarSelection);
}
}

private void OnSignInError(string error)
{
AuthManager.OnSignInError -= OnSignInError;
LoadingManager.EnableLoading(error, LoadingManager.LoadingType.Popup, false);
}
}
1 change: 0 additions & 1 deletion Tests/Editor/AuthTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public async Task Login_As_Anonymous()
{
await AuthManager.LoginAsAnonymous();
Assert.False(string.IsNullOrEmpty(AuthManager.UserSession.Id));
Assert.False(string.IsNullOrEmpty(AuthManager.UserSession.RefreshToken));
}
}
}
Loading

0 comments on commit 65ab1e1

Please sign in to comment.