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

Commit

Permalink
Fixed avatars not being added to history when not using change button.
Browse files Browse the repository at this point in the history
  • Loading branch information
RequiDev committed Aug 18, 2021
1 parent 34c0bf2 commit cb80e1c
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions ReModCE/Components/AvatarHistoryComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using ReModCE.Core;
using ReModCE.Managers;
using ReModCE.UI;
using ReModCE.VRChat;
using UnityEngine;
using UnityEngine.UI;
using VRC.Core;
Expand All @@ -33,6 +34,7 @@ public AvatarHistoryComponent()
_recentAvatars = new List<ReAvatar>();
}
}

public override void OnUiManagerInit(UiManager uiManager)
{
_avatarList = new ReAvatarList("Recently Used", this, false);
Expand All @@ -41,26 +43,39 @@ public override void OnUiManagerInit(UiManager uiManager)
changeButton.GetComponent<Button>().onClick.AddListener(new Action(OnChangeAvatar));
}

private void OnChangeAvatar()
public override void OnAvatarIsReady(VRCPlayer vrcPlayer)
{
var apiAvatar = _avatarList.AvatarPedestal.field_Internal_ApiAvatar_0;
if (_recentAvatars.FirstOrDefault(a => a.Id == apiAvatar.id) != null)
if (vrcPlayer.gameObject == VRCPlayer.field_Internal_Static_VRCPlayer_0.gameObject)
{
AddAvatarToHistory(vrcPlayer.GetPlayer().GetApiAvatar());
}
}

private void AddAvatarToHistory(ApiAvatar avatar)
{
if (_recentAvatars.FirstOrDefault(a => a.Id == avatar.id) != null)
{
_recentAvatars.RemoveAll(a => a.Id == apiAvatar.id);
_recentAvatars.RemoveAll(a => a.Id == avatar.id);
}

_recentAvatars.Insert(0, new ReAvatar(apiAvatar));
_recentAvatars.Insert(0, new ReAvatar(avatar));

if (_recentAvatars.Count > 100)
if (_recentAvatars.Count > 25)
{
_recentAvatars.Remove(_recentAvatars.Last());
}

SaveAvatarsToDisk();

_avatarList.Refresh(GetAvatars());
}

private void OnChangeAvatar()
{
var apiAvatar = _avatarList.AvatarPedestal.field_Internal_ApiAvatar_0;
AddAvatarToHistory(apiAvatar);
}

private void SaveAvatarsToDisk()
{
Directory.CreateDirectory("UserData/ReModCE");
Expand Down

0 comments on commit cb80e1c

Please sign in to comment.