Skip to content

Commit

Permalink
Check active game session by start;
Browse files Browse the repository at this point in the history
  • Loading branch information
mismirnov committed Apr 4, 2024
1 parent 428233f commit bc2b576
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Assets/Scenes/Main.unity
Original file line number Diff line number Diff line change
Expand Up @@ -3161,7 +3161,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -31, y: -213}
m_AnchoredPosition: {x: -31, y: -240}
m_SizeDelta: {x: 686, y: 423}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!95 &369290027
Expand Down
6 changes: 2 additions & 4 deletions Assets/Scripts/Managers/UserDataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public class UserDataManager : MonoBehaviour
public Action<List<Nft>> TokensReceived;
public Action<List<Nft>> RewardsAndTokensLoaded;
public Action GameStarted;
public Action<bool> HasActiveSessionResult;

[SerializeField] private int maxTokenCount = 20;
[SerializeField] private string contract = "KT1TSZfPJ5uZW1GjcnXmvt1npAQ2nh5S1FAj";
Expand Down Expand Up @@ -115,7 +114,6 @@ private void WalletConnected(WalletInfo wallet)
{
GetMenuManager()?.EnableGameMenu();
StartCoroutine(LoadGameNfts());
CheckActiveGameSession();
LoadPlayerStats();
}
}
Expand Down Expand Up @@ -152,10 +150,10 @@ public void StartGame()
CoroutineRunner.Instance.StartWrappedCoroutine(routine);
}

public void CheckActiveGameSession()
public void CheckActiveGameSession(Action<bool> callback)
{
var routine = _api.HasActiveSession(_connectedAddress,
result => HasActiveSessionResult?.Invoke(result));
result => callback?.Invoke(result));
CoroutineRunner.Instance.StartWrappedCoroutine(routine);
}

Expand Down
28 changes: 12 additions & 16 deletions Assets/Scripts/UI/UiMenuManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,8 @@ void Start()
_listener.GetComponent<UiSettingsManager>().soundVolumeChanged += ChangeVolume;

UserDataManager.Instance.GameStarted += StartGameScene;
UserDataManager.Instance.HasActiveSessionResult += EnableIncompleteSessionMenu;

_cameraAnimator = Camera.main

_cameraAnimator = Camera.main
.gameObject.transform
.GetComponent<Animator>();

Expand All @@ -136,11 +135,6 @@ void Start()
vfxs[indexVfx].SetActive(true);
}

private void EnableIncompleteSessionMenu(bool hasActiveSession)
{
_hasActiveGameSession = hasActiveSession;
}

public void EnableGameMenu()
{
var address = PlayerPrefs.GetString("Address", null);
Expand Down Expand Up @@ -229,14 +223,17 @@ public void StartGame()
{
DisableAllMenu();

if (_hasActiveGameSession)
{
incompleteSessionMenu.SetActive(true);
}
else
UserDataManager.Instance.CheckActiveGameSession(result =>
{
playMenu.SetActive(true);
}
if (result)
{
incompleteSessionMenu.SetActive(true);
}
else
{
playMenu.SetActive(true);
}
});
}

public void ReturnMenu()
Expand Down Expand Up @@ -408,7 +405,6 @@ protected void OnDisable()
{
_listener.GetComponent<UiSettingsManager>().soundVolumeChanged -= ChangeVolume;
UserDataManager.Instance.GameStarted -= StartGameScene;
UserDataManager.Instance.HasActiveSessionResult -= EnableIncompleteSessionMenu;
}

private void StartGameScene()
Expand Down

0 comments on commit bc2b576

Please sign in to comment.