Skip to content

Commit

Permalink
Move WebGL start
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmfinol committed Nov 7, 2023
1 parent 6fbf924 commit 674e2b7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 43 deletions.
80 changes: 47 additions & 33 deletions Assets/Scripts/Cgs/CardGameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityExtensionMethods;
#if UNITY_WEBGL && !UNITY_EDITOR
using System.Runtime.InteropServices;
#endif

#if UNITY_ANDROID && !UNITY_EDITOR
using UnityEngine.Networking;
#endif
Expand All @@ -28,6 +32,10 @@ namespace Cgs
{
public class CardGameManager : MonoBehaviour
{
#if UNITY_WEBGL && !UNITY_EDITOR
[DllImport("__Internal")]
private static extern void GameReady();
#endif
// Show all Debug.Log() to help with debugging?
private const bool IsMessengerDebugLogVerbose = false;
public const string PlayerPrefsDefaultGame = "DefaultGame";
Expand Down Expand Up @@ -185,12 +193,10 @@ private void Awake()

ResetCurrentToDefault();

#if !UNITY_WEBGL
#if !UNITY_WEBGL || UNITY_EDITOR
Debug.Log("CardGameManager::Awake:CheckDeepLinks");
CheckDeepLinks();
#endif

Debug.Log("CardGameManager is Awake!");
}

// ReSharper disable once MemberCanBeMadeStatic.Local
Expand Down Expand Up @@ -342,7 +348,7 @@ private void OnSceneUnloaded(Scene scene)
OnSceneActions.Clear();
}

#if !UNITY_WEBGL
#if !UNITY_WEBGL || UNITY_EDITOR
private void CheckDeepLinks()
{
Application.deepLinkActivated += OnDeepLinkActivated;
Expand Down Expand Up @@ -600,42 +606,21 @@ internal void ResetGameScene()
action();
}

#if UNITY_WEBGL && !UNITY_EDITOR
private void Start()
{
Debug.Log("CardGameManager::Start:GameReady");
GameReady();
}
#endif

private void IgnoreCurrentErroredGame()
{
Current.ClearError();
ResetCurrentToDefault();
ResetGameScene();
}

public void PromptDelete()
{
if (AllCardGames.Count > 1)
Messenger.Prompt(DeletePrompt, Delete);
else
Messenger.Show(DeleteWarningMessage);
}

private void Delete()
{
if (AllCardGames.Count < 1)
{
Debug.LogError(DeleteErrorMessage + DeleteWarningMessage);
return;
}

try
{
Directory.Delete(Current.GameDirectoryPath, true);
AllCardGames.Remove(Current.Id);
ResetCurrentToDefault();
ResetGameScene();
}
catch (Exception ex)
{
Debug.LogError(DeleteErrorMessage + ex.Message);
}
}

public void Share()
{
Debug.Log("CGS Share:: Deep:" + Current.CgsGamesLink + " Auto:" + Current.AutoUpdateUrl);
Expand Down Expand Up @@ -733,6 +718,35 @@ public IEnumerator OpenZip(Uri uri, string gameId)
}
#endif

public void PromptDelete()
{
if (AllCardGames.Count > 1)
Messenger.Prompt(DeletePrompt, Delete);
else
Messenger.Show(DeleteWarningMessage);
}

private void Delete()
{
if (AllCardGames.Count < 1)
{
Debug.LogError(DeleteErrorMessage + DeleteWarningMessage);
return;
}

try
{
Directory.Delete(Current.GameDirectoryPath, true);
AllCardGames.Remove(Current.Id);
ResetCurrentToDefault();
ResetGameScene();
}
catch (Exception ex)
{
Debug.LogError(DeleteErrorMessage + ex.Message);
}
}

private void LateUpdate()
{
Inputs.WasFocusBack = Inputs.IsFocusBack;
Expand Down
10 changes: 0 additions & 10 deletions Assets/Scripts/Cgs/Menu/TitleScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,11 @@
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
#if UNITY_WEBGL && !UNITY_EDITOR
using System.Runtime.InteropServices;
#endif

namespace Cgs.Menu
{
public class TitleScreen : MonoBehaviour
{
#if UNITY_WEBGL && !UNITY_EDITOR
[DllImport("__Internal")]
private static extern void GameReady();
#endif
public const string TouchlessStartMessage = "Press Any Key";

public static string VersionMessage => $"VERSION {Application.version}";
Expand Down Expand Up @@ -100,9 +93,6 @@ private void Start()
centerText.text = TouchlessStartMessage;
#endif
versionText.text = VersionMessage;
#if UNITY_WEBGL && !UNITY_EDITOR
GameReady();
#endif
}

private void Update()
Expand Down

0 comments on commit 674e2b7

Please sign in to comment.