Skip to content

Commit

Permalink
Merge pull request #257 from finol-digital/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
davidmfinol authored Feb 27, 2025
2 parents 5dc12b1 + b3b0312 commit 605fc31
Show file tree
Hide file tree
Showing 16 changed files with 232 additions and 58 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ jobs:
- name: Firebase Deploy
uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: ${{ secrets.CGS_PAT }}
repoToken: "${{ secrets.GITHUB_TOKEN }}"
firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_CARD_GAME_SIMULATOR }}
channelId: preview
projectId: card-game-simulator
Expand Down Expand Up @@ -1025,7 +1025,6 @@ jobs:
with:
args: ${{ steps.prepare.outputs.ANNOUNCEMENT }}
- name: Bluesky Announcement
if: github.ref == 'refs/heads/main'
uses: myConsciousness/bluesky-post@v5
with:
text: ${{ steps.prepare.outputs.ANNOUNCEMENT }}
Expand Down
51 changes: 45 additions & 6 deletions Assets/Prefabs/Menus/Deck Load Menu.prefab

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions Assets/Scripts/Cgs/CardGameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public static CardGameManager Instance
private static CardGameManager _instance;

public static UnityCardGame Current { get; private set; } = UnityCardGame.UnityInvalid;
public static bool IsCurrentReady { get; private set; }
public static bool IsQuitting { get; private set; }

public bool IsSearchingForServer { get; set; }
Expand Down Expand Up @@ -386,13 +387,16 @@ private IEnumerator Start()
Debug.Log("CardGameManager::Start");

#if UNITY_WEBGL && CGS_SINGLEGAME
yield return GetCardGame("/cgs.json");
var uri = new Uri(Application.absoluteURL);
yield return GetCardGame("https://" + uri.Host + "/cgs.json");
#elif UNITY_WEBGL
var isMissingGame =
Current == null || Current == UnityCardGame.UnityInvalid || !string.IsNullOrEmpty(Current.Error) || !Current.HasLoaded;
if (isMissingGame)
yield return StartGetDefaultCardGames();
#endif

IsCurrentReady = true;
}

// ReSharper disable once UnusedMember.Local
Expand Down Expand Up @@ -630,7 +634,7 @@ private static void ExportGame()
Debug.Log("CGS Share::subContainer: " + subContainer);
UnityFileMethods.CopyDirectory(Current.GameDirectoryPath, subContainer);

var zipFileName = UnityFileMethods.GetSafeFileName(Current.Id + ".zip");
var zipFileName = UnityFileMethods.GetSafeFileName(Current.Id + ".cgszip");
Debug.Log("CGS Share::zipFileName: " + zipFileName);
UnityFileMethods.CreateZip(container, UnityCardGame.GamesExportPath, zipFileName);
Directory.Delete(container, true);
Expand Down
10 changes: 5 additions & 5 deletions Assets/Scripts/Cgs/Menu/GamesManagementMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ namespace Cgs.Menu
[RequireComponent(typeof(Modal))]
public class GamesManagementMenu : SelectionPanel
{
public const string ImportGamePrompt = "Download from Web URL,\n or Load from ZIP File?";
public const string DownloadFromWeb = "Download from Web URL";
public const string LoadFromFile = "Load from ZIP File";
public const string SelectZipFilePrompt = "Select ZIP File";
public const string ImportGamePrompt = "Download from Web AutoUpdate URL,\n or Load from CGS ZIP File?";
public const string DownloadFromWeb = "Download from Web AutoUpdate URL";
public const string LoadFromFile = "Load from CGS ZIP File";
public const string SelectZipFilePrompt = "Select CGS ZIP File";

public const string DownloadLabel = "Download Game";
public const string DownloadPrompt = "Enter CGS AutoUpdate URL...";
Expand Down Expand Up @@ -83,7 +83,7 @@ private void OnEnable()
private void Start()
{
#if UNITY_ANDROID || UNITY_IOS
_zipFileType = NativeFilePicker.ConvertExtensionToFileType("zip");
_zipFileType = NativeFilePicker.ConvertExtensionToFileType(".cgszip");
#endif
}

Expand Down
31 changes: 20 additions & 11 deletions Assets/Scripts/Cgs/Play/PlayController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,23 +169,18 @@ private void OnEnable()
CardGameManager.Instance.OnSceneActions.Add(ResetPlayArea);
}

private void Start()
private IEnumerator Start()
{
CardGameManager.Instance.CardCanvases.Add(GetComponent<Canvas>());

playAreaCardZone.OnAddCardActions.Add(AddCardToPlayArea);
playDropZones.ForEach(dropZone => dropZone.DropHandler = this);

if (CardGameManager.Instance.IsSearchingForServer)
Lobby.Show();
else
{
Lobby.IsLanConnectionSource = true;
#if !UNITY_WEBGL
Lobby.Host();
#endif
StartDecks();
}
yield return null;
while (!CardGameManager.IsCurrentReady)
yield return null;

StartLobby();
}

private void Update()
Expand Down Expand Up @@ -255,6 +250,20 @@ public void ResetPlayArea()
scoreboard.ChangePoints(CardGameManager.Current.GameStartPointsCount.ToString());
}

private void StartLobby()
{
if (CardGameManager.Instance.IsSearchingForServer)
Lobby.Show();
else
{
Lobby.IsLanConnectionSource = true;
#if !UNITY_WEBGL
Lobby.Host();
#endif
StartDecks();
}
}

private void StartDecks()
{
if (CardGameManager.Current.GameStartDecks.Count > 0)
Expand Down
4 changes: 1 addition & 3 deletions Assets/WebGLSupport/WebGLInput/Detail/RebuildChecker.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine;

namespace WebGLSupport.Detail
{
Expand Down
6 changes: 6 additions & 0 deletions Assets/WebGLSupport/WebGLInput/Mobile/WebGLInputMobile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public class WebGLInputMobile : MonoBehaviour, IPointerDownHandler
{
static Dictionary<int, WebGLInputMobile> instances = new Dictionary<int, WebGLInputMobile>();

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
static void Init()
{
instances = new Dictionary<int, WebGLInputMobile>();
}

int id = -1;

private void Awake()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using UnityEngine;
using UnityEngine.UIElements;
using UnityEngine.Windows;

namespace WebGLSupport
{
Expand Down
15 changes: 14 additions & 1 deletion Assets/WebGLSupport/WebGLInput/WebGLInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal class WebGLInputPlugin

[DllImport("__Internal")]
public static extern void WebGLInputOnValueChange(int id, Action<int, string> cb);

[DllImport("__Internal")]
public static extern void WebGLInputOnEditEnd(int id, Action<int, string> cb);

Expand Down Expand Up @@ -110,6 +110,13 @@ public class WebGLInput : MonoBehaviour, IComparable<WebGLInput>
public static event KeyboardEventHandler OnKeyboardUp;

static Dictionary<int, WebGLInput> instances = new Dictionary<int, WebGLInput>();

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
static void Init()
{
instances = new Dictionary<int, WebGLInput>();
}

public static string CanvasId { get; set; }

#if WEBGLINPUT_TAB
Expand Down Expand Up @@ -455,6 +462,12 @@ static class WebGLInputTabFocus
{
static List<WebGLInput> inputs = new List<WebGLInput>();

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
static void Init()
{
inputs = new List<WebGLInput>();
}

public static void Add(WebGLInput input)
{
inputs.Add(input);
Expand Down
18 changes: 10 additions & 8 deletions Assets/WebGLSupport/WebGLInput/WebGLInput.jslib
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,16 @@ var WebGLInput = {
WebGLInputOnKeyboardEvent:function(id, cb){
var input = instances[id];
var func = function(mode, e) {
var bufferSize = lengthBytesUTF8(e.key) + 1;
var key = _malloc(bufferSize);
stringToUTF8(e.key, key, bufferSize);
var code = e.code;
var shift = e.shiftKey ? 1 : 0;
var ctrl = e.ctrlKey ? 1 : 0;
var alt = e.altKey ? 1 : 0;
(!!Runtime.dynCall) ? Runtime.dynCall("viiiiiii", cb, [id, mode, key, code, shift, ctrl, alt]) : {{{ makeDynCall("viiiiiii", "cb") }}}(id, mode, key, code, shift, ctrl, alt);
if (e instanceof KeyboardEvent){
var bufferSize = lengthBytesUTF8(e.key) + 1;
var key = _malloc(bufferSize);
stringToUTF8(e.key, key, bufferSize);
var code = e.code;
var shift = e.shiftKey ? 1 : 0;
var ctrl = e.ctrlKey ? 1 : 0;
var alt = e.altKey ? 1 : 0;
(!!Runtime.dynCall) ? Runtime.dynCall("viiiiiii", cb, [id, mode, key, code, shift, ctrl, alt]) : {{{ makeDynCall("viiiiiii", "cb") }}}(id, mode, key, code, shift, ctrl, alt);
}
}
input.addEventListener('keydown', function(e) { func(1, e); });
input.addEventListener('keyup', function(e) { func(2, e); });
Expand Down
19 changes: 19 additions & 0 deletions Assets/WebGLSupport/WebGLWindow/WebGLWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ static class WebGLWindowPlugin
#if UNITY_WEBGL && !UNITY_EDITOR
[DllImport("__Internal")]
public static extern void WebGLWindowInit();
[DllImport("__Internal")]
public static extern void WebGLWindowUninit();

[DllImport("__Internal")]
public static extern void WebGLWindowOnFocus(Action cb);

Expand All @@ -35,6 +38,7 @@ static class WebGLWindowPlugin
public static extern bool IsFullscreen();
#else
public static void WebGLWindowInit() { }
public static void WebGLWindowUninit() { }
public static void WebGLWindowOnFocus(Action cb) { }
public static void WebGLWindowOnBlur(Action cb) { }
public static void WebGLWindowOnResize(Action cb) { }
Expand All @@ -58,14 +62,29 @@ static WebGLWindow()
public static event Action OnBlurEvent = () => { };
public static event Action OnResizeEvent = () => { };

#pragma warning disable CS0414 // Field is assigned but its value is never used
static string ViewportContent;
#pragma warning restore CS0414 // Field is assigned but its value is never used
static void Init()
{
Focus = true;
WebGLWindowPlugin.WebGLWindowOnFocus(OnWindowFocus);
WebGLWindowPlugin.WebGLWindowOnBlur(OnWindowBlur);
WebGLWindowPlugin.WebGLWindowOnResize(OnWindowResize);
WebGLWindowPlugin.WebGLWindowInjectFullscreen();

Application.quitting += Uninit;
}
[RuntimeInitializeOnLoadMethod]
static void RunOnStart()
{
ViewportContent = null;
Application.quitting -= Uninit;
}
static void Uninit()
{
WebGLWindowPlugin.WebGLWindowUninit();
Application.quitting -= Uninit;
}

[MonoPInvokeCallback(typeof(Action))]
Expand Down
Loading

0 comments on commit 605fc31

Please sign in to comment.