예제 #1
0
        public void CreateBoard(GameBoard board)
        {
            if (board == null)
            {
                return;
            }

            GameObject    newBoard = new GameObject(board.Id, typeof(RectTransform));
            RectTransform rt       = (RectTransform)newBoard.transform;

            rt.SetParent(playAreaContent);
            rt.anchorMin = Vector2.zero;
            rt.anchorMax = Vector2.zero;
            rt.offsetMin = board.OffsetMin * CardGameManager.PixelsPerInch;
            rt.offsetMax = board.Size * CardGameManager.PixelsPerInch + rt.offsetMin;

            string boardFilepath = CardGameManager.Current.GameBoardsFilePath + "/" + board.Id + "." +
                                   CardGameManager.Current.GameBoardFileType;
            Sprite boardImageSprite = UnityExtensionMethods.CreateSprite(boardFilepath);

            if (boardImageSprite != null)
            {
                newBoard.AddComponent <Image>().sprite = boardImageSprite;
            }

            rt.localScale = Vector3.one;
        }
예제 #2
0
        private void CreateBoard(GameBoard board)
        {
            var newBoard           = new GameObject(board.Id, typeof(RectTransform));
            var boardRectTransform = (RectTransform)newBoard.transform;

            boardRectTransform.SetParent(playArea.transform);
            boardRectTransform.anchorMin = Vector2.zero;
            boardRectTransform.anchorMax = Vector2.zero;
            boardRectTransform.offsetMin =
                new Vector2(board.OffsetMin.X, board.OffsetMin.Y) * CardGameManager.PixelsPerInch;
            boardRectTransform.offsetMax =
                new Vector2(board.OffsetMin.X, board.OffsetMin.Y) * CardGameManager.PixelsPerInch +
                boardRectTransform.offsetMin;

            string boardFilepath = CardGameManager.Current.GameBoardsDirectoryPath + "/" + board.Id + "." +
                                   CardGameManager.Current.GameBoardImageFileType;
            Sprite boardImageSprite = File.Exists(boardFilepath)
                ? UnityExtensionMethods.CreateSprite(boardFilepath)
                : null;

            if (boardImageSprite != null)
            {
                newBoard.AddComponent <Image>().sprite = boardImageSprite;
            }

            boardRectTransform.localScale = Vector3.one;
        }
    private void assert(PlayerImplementation Player, Context context)
    {
        int    PlayerCount   = context.playersToGetAction.Count;
        int    Pot           = context.CurrentPot;
        int    bigBlind      = context.BigBlind;
        string status        = context.currentAction.ToString();
        float  HandStrength  = Player.HandStrength;
        float  HandPotential = Player.HandPotential;
        string state         = context.state().ToString();
        int    callAmount    = context.CallAmount;
        int    PlayerMoney   = Player.Chips;

        Debug.Log(PlayerCount);
        Debug.Log(Pot);
        Debug.Log(bigBlind);
        Debug.Log(status);
        Debug.Log(HandStrength);
        Debug.Log(HandPotential);
        Debug.Log(state);
        Debug.Log(callAmount);
        Debug.Log(PlayerMoney);
        Debug.Log("*******");

        string goal = "decisionResult(" + PlayerCount + "," +
                      Pot + "," + bigBlind + "," + status + "," + HandStrength + "," +
                      HandPotential + "," + state + "," + callAmount + "," + PlayerMoney + ").";

        UnityExtensionMethods.IsTrueParsed(kB, goal);
    }
예제 #4
0
        // Returns true iff the entity type matched and
        public bool TryToApplyPosition(Position positionData)
        {
            if (positionData.entityType != (int)Entity_Type.objects)
            {
                return(false);
            }

            int entityId = positionData.entityId;

            if (!networkedObjectFromEntityId.ContainsKey(entityId))
            {
                Debug.LogWarning("Entity ID : " + positionData.entityId + "not found in Dictionary dropping object movement packet");

                return(false);
            }

            Transform netObjTransform = networkedObjectFromEntityId[entityId].transform;

            if (!netObjTransform)
            {
                Debug.LogError($"TryToApplyPosition: NetObj with entityID {entityId} had no Transform component");

                return(false);
            }

            netObjTransform.position = positionData.pos;

            netObjTransform.rotation = positionData.rot;

            UnityExtensionMethods.SetGlobalScale(netObjTransform, Vector3.one * positionData.scaleFactor);

            return(true);
        }
예제 #5
0
        public void Load(bool didDownload = false)
        {
            try
            {
                if (!didDownload)
                {
                    JsonConvert.PopulateObject(File.ReadAllText(ConfigFilePath), this);
                }

                CreateEnumLookups();

                if (CoroutineRunner != null)
                {
                    CoroutineRunner.StartCoroutine(CGS.CardGameManager.Instance.LoadCards());
                }
                LoadSets();

                BackgroundImageSprite = UnityExtensionMethods.CreateSprite(BackgroundImageFilePath);
                CardBackImageSprite   = UnityExtensionMethods.CreateSprite(CardBackImageFilePath);

                IsLoaded = true;

                // Kick off auto-update in the background, even though it won't load until next time the app restarts
                if (AutoUpdate && !didDownload && CoroutineRunner != null)
                {
                    CoroutineRunner.StartCoroutine(Download());
                }
            }
            catch (Exception e)
            {
                Error   += e.Message + e.StackTrace + Environment.NewLine;
                IsLoaded = false;
            }
        }
        public void ApplyPositionToStart(Position positionData)
        {
            //alternate kinematic to allow for sending non physics transform updates;
            if (NetworkedObjectsManager.Instance.networkedObjectFromEntityId.ContainsKey(positionData.entityId))
            {
                if (!rigidbodyFromEntityId.ContainsKey(positionData.entityId))
                {
                    rigidbodyFromEntityId.Add(positionData.entityId, NetworkedObjectsManager.Instance.networkedObjectFromEntityId[positionData.entityId].GetComponent <Rigidbody>());
                }

                var rb = rigidbodyFromEntityId[positionData.entityId];

                if (!rb)
                {
                    Debug.LogError("There is no rigidbody in netobject entity id: " + positionData.entityId);

                    return;
                }

                rb.isKinematic = true;

                NetworkedObjectsManager.Instance.networkedObjectFromEntityId[positionData.entityId].transform.position = positionData.pos;

                NetworkedObjectsManager.Instance.networkedObjectFromEntityId[positionData.entityId].transform.rotation = positionData.rot;

                UnityExtensionMethods.SetGlobalScale(NetworkedObjectsManager.Instance.networkedObjectFromEntityId[positionData.entityId].transform, Vector3.one * positionData.scaleFactor);
            }
            else
            {
                Debug.LogWarning("Entity ID : " + positionData.entityId + "not found in Dictionary dropping physics object movement packet");
            }
        }
예제 #7
0
    public EvaluatedHand evaluateHand(List <Card> cards)
    {
        if (cards.Count <= 2)
        {
            return(null);
        }

        assert(cards);
        string goal   = "X:evaluate(X).";
        string result = UnityExtensionMethods.SolveForParsed(kB, goal).ToString();

        List <Card> EvaluatedCards = new List <Card> ();

        for (int i = 1; i < 6; i++)
        {
            string cardValue = "X:cardValue(X," + i.ToString() + ").";
            string cardSuit  = "Y:cardSuit(Y," + i.ToString() + ").";
            int    v         = int.Parse(UnityExtensionMethods.SolveForParsed(kB, cardValue).ToString());
            var    s         = UnityExtensionMethods.SolveForParsed(kB, cardSuit);
            EvaluatedCards.Add(new Card(v, s.ToString()));
        }

        string straightPotentialCase = "Y:straightPotential(Y).";
        int    straightPotential     = int.Parse(UnityExtensionMethods.SolveForParsed(kB, straightPotentialCase).ToString());

        string flushPotentialCase = "Y:flushPotential(Y).";
        int    flushPotential     = int.Parse(UnityExtensionMethods.SolveForParsed(kB, flushPotentialCase).ToString());

        EvaluatedHand evaluatedhand = new EvaluatedHand(result, EvaluatedCards, straightPotential, flushPotential);

        retract();
        return(evaluatedhand);
    }
예제 #8
0
        private void CreateDefaultCardGames()
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            UnityExtensionMethods.ExtractAndroidStreamingAssets(CardGame.GamesDirectoryPath);
#else
            UnityExtensionMethods.CopyDirectory(Application.streamingAssetsPath, CardGame.GamesDirectoryPath);
#endif
        }
 private void retract(bool raised)
 {
     UnityExtensionMethods.IsTrueParsed(kB, "retractall(finalDecision(X)).");
     if (raised)
     {
         UnityExtensionMethods.IsTrueParsed(kB, "retractall(raiseAmount(X)).");
     }
 }
예제 #10
0
 private void retract()
 {
     UnityExtensionMethods.IsTrueParsed(kB, "retractall(player(card(value(X),suit(Y)))).");
     UnityExtensionMethods.IsTrueParsed(kB, "retractall(cardSuit(X,Y)).");
     UnityExtensionMethods.IsTrueParsed(kB, "retractall(cardValue(X,Y)).");
     UnityExtensionMethods.IsTrueParsed(kB, "retractall(flushPotential(X)).");
     UnityExtensionMethods.IsTrueParsed(kB, "retractall(straightPotential(Y)).");
 }
예제 #11
0
 private void assert(List <Card> cards)
 {
     foreach (Card card in cards)
     {
         string goal = "assert(player(card(value(" + card.CardValue.ToString() + "),suit(" + card.suitValue + ")))).";
         UnityExtensionMethods.IsTrueParsed(kB, goal);
     }
 }
예제 #12
0
 public string UpdateDeckName(string newName)
 {
     if (newName == null)
     {
         newName = string.Empty;
     }
     newName       = UnityExtensionMethods.GetSafeFileName(newName);
     nameText.text = newName + (HasChanged ? ChangeIndicator : string.Empty);
     return(newName);
 }
예제 #13
0
 private void LoadSets()
 {
     if (AllSetsUrlZipped)
     {
         UnityExtensionMethods.ExtractZip(SetsFilePath + UnityExtensionMethods.ZipExtension, GameFolderPath);
     }
     if (AllSetsUrlWrapped)
     {
         UnityExtensionMethods.UnwrapFile(SetsFilePath);
     }
     LoadJsonFromFile(SetsFilePath, LoadSetFromJToken, SetDataIdentifier);
 }
예제 #14
0
        public void Load(CardGameCoroutineDelegate updateCoroutine, CardGameCoroutineDelegate loadCardsCoroutine)
        {
            // We should have already read the *Game:Name*.json, but we need to be sure
            if (!HasReadProperties)
            {
                ReadProperties();
                if (!HasReadProperties)
                {
                    // ReadProperties() should have already populated the Error
                    HasLoaded = false;
                    return;
                }
            }

            // Don't waste time loading if we need to update first
            int daysSinceUpdate = 0;

            try { daysSinceUpdate = (int)DateTime.Today.Subtract(File.GetLastWriteTime(GameFilePath).Date).TotalDays; } catch { };
            if (AutoUpdate >= 0 && daysSinceUpdate >= AutoUpdate && CoroutineRunner != null)
            {
                CoroutineRunner.StartCoroutine(updateCoroutine(this));
                return;
            }

            // These enum lookups need to be initialized before we load cards and sets
            foreach (EnumDef enumDef in Enums)
            {
                enumDef.InitializeLookups();
            }

            // The main load action is to load cards and sets
            if (CoroutineRunner != null)
            {
                CoroutineRunner.StartCoroutine(loadCardsCoroutine(this));
            }
            LoadSets();

            // We also re-load the banner and cardback images now in case they've changed since we ReadProperties
            if (File.Exists(BannerImageFilePath))
            {
                BannerImageSprite = UnityExtensionMethods.CreateSprite(BannerImageFilePath);
            }
            if (File.Exists(CardBackImageFilePath))
            {
                CardBackImageSprite = UnityExtensionMethods.CreateSprite(CardBackImageFilePath);
            }

            // Only considered as loaded if none of the steps failed
            if (string.IsNullOrEmpty(Error))
            {
                HasLoaded = true;
            }
        }
        private IEnumerator LoadSetCards(UnityCardGame cardGame)
        {
            if (cardGame == null)
            {
                cardGame = Current;
            }

            var setCardsLoaded = false;

            foreach (Set set in cardGame.Sets.Values)
            {
                if (string.IsNullOrEmpty(set.CardsUrl))
                {
                    continue;
                }
                if (!setCardsLoaded)
                {
                    Messenger.Show(string.Format(SetCardsLoadingMessage, cardGame.Name));
                }
                setCardsLoaded = true;
                string setCardsFilePath = Path.Combine(cardGame.SetsDirectoryPath,
                                                       UnityExtensionMethods.GetSafeFileName(set.Code + UnityExtensionMethods.JsonExtension));
                if (!File.Exists(setCardsFilePath))
                {
                    yield return(UnityExtensionMethods.SaveUrlToFile(set.CardsUrl, setCardsFilePath));
                }
                if (File.Exists(setCardsFilePath))
                {
                    cardGame.LoadCards(setCardsFilePath, set.Code);
                }
                else
                {
                    Debug.LogError(LoadErrorMessage + set.CardsUrl);
                    yield break;
                }
            }

            if (!string.IsNullOrEmpty(cardGame.Error))
            {
                Debug.LogError(LoadErrorMessage + cardGame.Error);
            }
            else if (setCardsLoaded)
            {
                Messenger.Show(string.Format(SetCardsLoadedMessage, cardGame.Name));
            }
        }
예제 #16
0
        public IEnumerator GetAndSetImageSprite()
        {
            if (IsLoadingImage)
            {
                yield break;
            }

            IsLoadingImage = true;
            UnityEngine.Sprite newSprite = null;
            yield return(UnityExtensionMethods.RunOutputCoroutine <UnityEngine.Sprite>(
                             UnityExtensionMethods.CreateAndOutputSpriteFromImageFile(ImageFilePath, ImageWebUrl)
                             , output => newSprite = output));

            if (newSprite != null)
            {
                ImageSprite = newSprite;
            }
            IsLoadingImage = false;
        }
예제 #17
0
        public void UpdatePosition()
        {
#if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
            if (SecondaryDragAction != Rotate && IsProcessingSecondaryDragAction)
            {
                return;
            }
#else
            if (Input.GetMouseButton(1) || Input.GetMouseButtonUp(1) || Input.GetMouseButton(2) || Input.GetMouseButtonUp(2))
            {
                return;
            }
#endif
            if (PointerPositions.Count < 1 || PointerDragOffsets.Count < 1 || (IsOnline && !hasAuthority))
            {
                return;
            }

            Vector2 targetPosition = UnityExtensionMethods.CalculateMean(PointerPositions.Values.ToList());
            targetPosition = targetPosition + UnityExtensionMethods.CalculateMean(PointerDragOffsets.Values.ToList());
            if (ParentCardStack != null)
            {
                UpdateCardStackPosition(targetPosition);
            }
            else if (!IsStatic)
            {
                transform.position = targetPosition;
            }

            if (!IsStatic)
            {
                if (PlaceHolderCardStack != null)
                {
                    PlaceHolderCardStack.UpdateLayout(PlaceHolder, targetPosition);
                }

                if (IsOnline)
                {
                    CmdUpdatePosition(((RectTransform)transform).anchoredPosition);
                }
            }
        }
        private void CreateDefaultCardGames()
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            UnityExtensionMethods.ExtractAndroidStreamingAssets(UnityCardGame.GamesDirectoryPath);
#elif UNITY_WEBGL
            if (!Directory.Exists(UnityCardGame.GamesDirectoryPath))
            {
                Directory.CreateDirectory(UnityCardGame.GamesDirectoryPath);
            }
            string standardPlayingCardsDirectory =
                UnityCardGame.GamesDirectoryPath + "/" + Tags.StandardPlayingCardsDirectoryName;
            if (!Directory.Exists(standardPlayingCardsDirectory))
            {
                Directory.CreateDirectory(standardPlayingCardsDirectory);
            }
            File.WriteAllText(standardPlayingCardsDirectory + "/" + Tags.StandardPlayingCardsJsonFileName, Tags.StandPlayingCardsJsonFileContent);
            string dominoesDirectory = UnityCardGame.GamesDirectoryPath + "/" + Tags.DominoesDirectoryName;
            if (!Directory.Exists(dominoesDirectory))
            {
                Directory.CreateDirectory(dominoesDirectory);
            }
            File.WriteAllText(dominoesDirectory + "/" + Tags.DominoesJsonFileName, Tags.DominoesJsonFileContent);
            StartCoroutine(UnityExtensionMethods.SaveUrlToFile(Tags.DominoesCardBackUrl, dominoesDirectory + "/CardBack.png"));
            string mahjongDirectory = UnityCardGame.GamesDirectoryPath + "/" + Tags.MahjongDirectoryName;
            if (!Directory.Exists(mahjongDirectory))
            {
                Directory.CreateDirectory(mahjongDirectory);
            }
            File.WriteAllText(mahjongDirectory + "/" + Tags.MahjongJsonFileName, Tags.MahjongJsonFileContent);
            StartCoroutine(UnityExtensionMethods.SaveUrlToFile(Tags.MahjongCardBackUrl, mahjongDirectory + "/CardBack.png"));
            string arcmageDirectory = UnityCardGame.GamesDirectoryPath + "/" + Tags.ArcmageDirectoryName;
            if (!Directory.Exists(arcmageDirectory))
            {
                Directory.CreateDirectory(arcmageDirectory);
            }
            File.WriteAllText(arcmageDirectory + "/" + Tags.ArcmageJsonFileName, Tags.ArcmageJsonFileContent);
            StartCoroutine(UnityExtensionMethods.SaveUrlToFile(Tags.ArcmageCardBackUrl, arcmageDirectory + "/CardBack.png"));
#else
            UnityExtensionMethods.CopyDirectory(Application.streamingAssetsPath, UnityCardGame.GamesDirectoryPath);
#endif
        }
예제 #19
0
        private void LoadCards(int page)
        {
            string cardsFilePath = CardsFilePath + (page != AllCardsUrlPageCountStartIndex ? page.ToString() : string.Empty);

            try
            {
                if (AllCardsUrlZipped)
                {
                    UnityExtensionMethods.ExtractZip(cardsFilePath + UnityExtensionMethods.ZipExtension, GameFolderPath);
                }
                if (AllCardsUrlWrapped)
                {
                    UnityExtensionMethods.UnwrapFile(cardsFilePath);
                }
                LoadJsonFromFile(cardsFilePath, LoadCardFromJToken, CardDataIdentifier);
            }
            catch (Exception e)
            {
                Error += e.Message + e.StackTrace + Environment.NewLine;
            }
        }
예제 #20
0
    public int compareTwoHands(PlayerImplementation player1, PlayerImplementation player2)
    {
        int rank1 = HandStrengthEvaluater.rank(player1.evaluatedCards.name);
        int rank2 = HandStrengthEvaluater.rank(player2.evaluatedCards.name);

        string cardsEvaluated1 = "[";

        for (int i = 0; i < player1.evaluatedCards.Cards.Count; i++)
        {
            if (i < player1.evaluatedCards.Cards.Count - 1)
            {
                cardsEvaluated1 += player1.evaluatedCards.Cards [i].CardValue + ",";
            }
            else
            {
                cardsEvaluated1 += player1.evaluatedCards.Cards [i].CardValue + "]";
            }
        }

        string cardsEvaluated2 = "[";

        for (int i = 0; i < player2.evaluatedCards.Cards.Count; i++)
        {
            if (i < player2.evaluatedCards.Cards.Count - 1)
            {
                cardsEvaluated2 += player2.evaluatedCards.Cards [i].CardValue + ",";
            }
            else
            {
                cardsEvaluated2 += player2.evaluatedCards.Cards [i].CardValue + "]";
            }
        }

        string query  = "X:result(" + rank1 + "," + rank2 + "," + cardsEvaluated1 + "," + cardsEvaluated2 + ",X).";
        int    result = int.Parse(UnityExtensionMethods.SolveForParsed(kB, query).ToString());

        return(result);
    }
    public PlayerAction MakeDecision(PlayerImplementation Player, Context context)
    {
        PlayerAction playerAction = new PlayerAction();

        assert(Player, context);
        bool   raised = false;
        int    raiseAmount;
        string decision = "Y:finalDecision(Y).";
        string result   = UnityExtensionMethods.SolveForParsed(kB, decision).ToString();

        if (result.Equals("fold"))
        {
            playerAction.set(PlayerAction.Action.Fold);
        }
        if (result.Equals("call"))
        {
            playerAction.set(PlayerAction.Action.Call);
        }
        if (result.Equals("raise"))
        {
            raised = true;
            string raiseAmountQuery = "X:raiseAmount(X).";
            raiseAmount = int.Parse(UnityExtensionMethods.SolveForParsed(kB, raiseAmountQuery).ToString());
            if (raiseAmount == 0)
            {
                playerAction.set(PlayerAction.Action.Check);
            }
            else
            {
                playerAction.raise(new PlayerAction.Raise(raiseAmount));
            }
        }

        retract(raised);

        return(playerAction);
    }
예제 #22
0
        public void ReadProperties()
        {
            try
            {
                // We need to read the *Game:Name*.json file, but reading it can cause *Game:Name* to change, so account for that
                string gameFilePath      = GameFilePath;
                string gameDirectoryPath = GameDirectoryPath;
                ClearDefinitionLists();
                JsonConvert.PopulateObject(File.ReadAllText(GameFilePath), this);
                if (!gameFilePath.Equals(GameFilePath) && File.Exists(gameFilePath))
                {
                    string tempGameFilePath = gameDirectoryPath + "/" + UnityExtensionMethods.GetSafeFileName(Name) + ".json";
                    File.Move(gameFilePath, tempGameFilePath);
                }
                if (!gameDirectoryPath.Equals(GameDirectoryPath) && Directory.Exists(gameDirectoryPath))
                {
                    Directory.Move(gameDirectoryPath, GameDirectoryPath);
                }

                // We're being greedy about loading these now, since these could be shown before the game is selected
                if (File.Exists(BannerImageFilePath))
                {
                    BannerImageSprite = UnityExtensionMethods.CreateSprite(BannerImageFilePath);
                }
                if (File.Exists(CardBackImageFilePath))
                {
                    CardBackImageSprite = UnityExtensionMethods.CreateSprite(CardBackImageFilePath);
                }

                HasReadProperties = true;
            }
            catch (Exception e)
            {
                Error            += e.Message + e.StackTrace + Environment.NewLine;
                HasReadProperties = false;
            }
        }
예제 #23
0
        public IEnumerator Download()
        {
            if (IsDownloading)
            {
                yield break;
            }
            IsDownloading = true;

            string initialDirectory = GameFolderPath;

            yield return(UnityExtensionMethods.SaveUrlToFile(AutoUpdateUrl, ConfigFilePath));

            try
            {
                if (!IsLoaded)
                {
                    JsonConvert.PopulateObject(File.ReadAllText(ConfigFilePath), this);
                }
            }
            catch (Exception e)
            {
                Error        += e.Message;
                IsDownloading = false;
                yield break;
            }

            // If the name of the game doesn't match our initial game name, we need to move to the new directory and delete the old one
            if (!initialDirectory.Equals(GameFolderPath))
            {
                // Downloading the config file twice is slightly inefficient, but it shouldn't cause a noticeable difference for the user
                yield return(UnityExtensionMethods.SaveUrlToFile(AutoUpdateUrl, ConfigFilePath));

                Directory.Delete(initialDirectory, true);
            }

            for (int page = AllCardsUrlPageCountStartIndex; page < AllCardsUrlPageCountStartIndex + AllCardsUrlPageCount; page++)
            {
                string cardsUrl = AllCardsUrl;
                if (AllCardsUrlPageCount > 1 && string.IsNullOrEmpty(AllCardsUrlPostBodyContent))
                {
                    cardsUrl += AllCardsUrlPageIdentifier + page;
                }
                string cardsFile = CardsFilePath;
                if (page != AllCardsUrlPageCountStartIndex)
                {
                    cardsFile += page.ToString();
                }
                if (AllCardsUrlZipped)
                {
                    cardsFile += UnityExtensionMethods.ZipExtension;
                }
                string jsonBody = null;
                if (!string.IsNullOrEmpty(AllCardsUrlPostBodyContent))
                {
                    jsonBody  = "{" + AllCardsUrlPostBodyContent;
                    jsonBody += AllCardsUrlPageIdentifier + page;
                    jsonBody += "}";
                }
                yield return(UnityExtensionMethods.SaveUrlToFile(cardsUrl, cardsFile, jsonBody));

                // Sometimes, we need to get the AllCardsUrlPageCount from the first page of AllCardsUrl
                if (page == AllCardsUrlPageCountStartIndex && !string.IsNullOrEmpty(AllCardsUrlPageCountIdentifier))
                {
                    LoadCards(page);
                }
            }

            string setsFilePath = SetsFilePath + (AllSetsUrlZipped ? UnityExtensionMethods.ZipExtension : string.Empty);

            if (!string.IsNullOrEmpty(AllSetsUrl))
            {
                yield return(UnityExtensionMethods.SaveUrlToFile(AllSetsUrl, setsFilePath));
            }

            yield return(UnityExtensionMethods.SaveUrlToFile(BackgroundImageUrl, BackgroundImageFilePath));

            yield return(UnityExtensionMethods.SaveUrlToFile(CardBackImageUrl, CardBackImageFilePath));

            foreach (GameBoardUrl boardUrl in GameBoardUrls)
            {
                yield return(UnityExtensionMethods.SaveUrlToFile(boardUrl.Url, GameBoardsFilePath + "/" + boardUrl.Id + "." + GameBoardFileType));
            }

            foreach (DeckUrl deckUrl in DeckUrls)
            {
                yield return(UnityExtensionMethods.SaveUrlToFile(deckUrl.Url, DecksFilePath + "/" + deckUrl.Name + "." + DeckFileType));
            }

            if (!IsLoaded)
            {
                Load(true);
            }

            IsDownloading = false;
        }
예제 #24
0
 public void ValidateDeckName(string deckName)
 {
     nameInputField.text = UnityExtensionMethods.GetSafeFileName(deckName);
 }
예제 #25
0
        public IEnumerator Download()
        {
            if (IsDownloading)
            {
                yield break;
            }
            IsDownloading = true;

            // We should always first get the *Game:Name*.json file and read it before doing anything else
            DownloadProgress = 0f / (7f + AllCardsUrlPageCount);
            DownloadStatus   = "Downloading: CardGameDef...";
            yield return(UnityExtensionMethods.SaveUrlToFile(AutoUpdateUrl, GameFilePath));

            ReadProperties();
            if (!HasReadProperties)
            {
                // ReadProperties() should have already populated the Error
                IsDownloading = false;
                HasDownloaded = false;
                yield break;
            }

            DownloadProgress = 1f / (7f + AllCardsUrlPageCount);
            DownloadStatus   = "Downloading: Banner";
            if (!string.IsNullOrEmpty(BannerImageUrl))
            {
                yield return(UnityExtensionMethods.SaveUrlToFile(BannerImageUrl, BannerImageFilePath));
            }

            DownloadProgress = 2f / (7f + AllCardsUrlPageCount);
            DownloadStatus   = "Downloading: CardBack";
            if (!string.IsNullOrEmpty(CardBackImageUrl))
            {
                yield return(UnityExtensionMethods.SaveUrlToFile(CardBackImageUrl, CardBackImageFilePath));
            }

            DownloadProgress = 3f / (7f + AllCardsUrlPageCount);
            DownloadStatus   = "Downloading: Boards";
            foreach (GameBoardUrl boardUrl in GameBoardUrls)
            {
                yield return(UnityExtensionMethods.SaveUrlToFile(boardUrl.Url, GameBoardsFilePath + "/" + boardUrl.Id + "." + GameBoardFileType));
            }

            DownloadProgress = 4f / (7f + AllCardsUrlPageCount);
            DownloadStatus   = "Downloading: Decks";
            foreach (DeckUrl deckUrl in DeckUrls)
            {
                yield return(UnityExtensionMethods.SaveUrlToFile(deckUrl.Url, DecksFilePath + "/" + deckUrl.Name + "." + DeckFileType));
            }

            DownloadProgress = 5f / (7f + AllCardsUrlPageCount);
            DownloadStatus   = "Downloading: AllSets.json";
            string setsFilePath = SetsFilePath + (AllSetsUrlZipped ? UnityExtensionMethods.ZipExtension : string.Empty);

            if (!string.IsNullOrEmpty(AllSetsUrl))
            {
                yield return(UnityExtensionMethods.SaveUrlToFile(AllSetsUrl, setsFilePath));
            }
            if (AllSetsUrlZipped)
            {
                UnityExtensionMethods.ExtractZip(setsFilePath, GameDirectoryPath);
            }
            if (AllSetsUrlWrapped)
            {
                UnityExtensionMethods.UnwrapFile(SetsFilePath);
            }

            if (!string.IsNullOrEmpty(AllCardsUrl))
            {
                for (int page = AllCardsUrlPageCountStartIndex; page < AllCardsUrlPageCountStartIndex + AllCardsUrlPageCount; page++)
                {
                    DownloadProgress = (6f + page - AllCardsUrlPageCountStartIndex) / (7f + AllCardsUrlPageCount - AllCardsUrlPageCountStartIndex);
                    DownloadStatus   = $"Downloading: Cards: {page,5} / {AllCardsUrlPageCountStartIndex + AllCardsUrlPageCount}";
                    string cardsUrl = AllCardsUrl;
                    if (AllCardsUrlPageCount > 1 && string.IsNullOrEmpty(AllCardsUrlPostBodyContent))
                    {
                        cardsUrl += AllCardsUrlPageIdentifier + page;
                    }
                    string cardsFile = CardsFilePath;
                    if (page != AllCardsUrlPageCountStartIndex)
                    {
                        cardsFile += page.ToString();
                    }
                    if (AllCardsUrlZipped)
                    {
                        cardsFile += UnityExtensionMethods.ZipExtension;
                    }
                    string jsonBody = null;
                    if (!string.IsNullOrEmpty(AllCardsUrlPostBodyContent))
                    {
                        jsonBody  = "{" + AllCardsUrlPostBodyContent;
                        jsonBody += AllCardsUrlPageIdentifier + page;
                        jsonBody += "}";
                    }
                    yield return(UnityExtensionMethods.SaveUrlToFile(cardsUrl, cardsFile, jsonBody));

                    if (AllCardsUrlZipped)
                    {
                        UnityExtensionMethods.ExtractZip(cardsFile, GameDirectoryPath);
                    }
                    if (AllCardsUrlWrapped)
                    {
                        UnityExtensionMethods.UnwrapFile(cardsFile.EndsWith(UnityExtensionMethods.ZipExtension)
                            ? cardsFile.Remove(cardsFile.Length - UnityExtensionMethods.ZipExtension.Length) : cardsFile);
                    }
                    // Sometimes, we need to get the AllCardsUrlPageCount from the first page of AllCardsUrl
                    if (page == AllCardsUrlPageCountStartIndex && !string.IsNullOrEmpty(AllCardsUrlPageCountIdentifier))
                    {
                        LoadCards(page);
                    }
                }
            }

            IsDownloading  = false;
            DownloadStatus = "Complete!";
            HasDownloaded  = true;
            HasLoaded      = false;
        }