Ejemplo n.º 1
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);
 }
        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));
            }
        }
Ejemplo n.º 3
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;
            }
        }
Ejemplo n.º 4
0
 public void ValidateDeckName(string deckName)
 {
     nameInputField.text = UnityExtensionMethods.GetSafeFileName(deckName);
 }