Exemple #1
0
 private void saveAsFile()
 {
     _currentPath = EditorUtility.SaveFilePanel(string.Empty, string.IsNullOrEmpty(_currentPath) ? Application.streamingAssetsPath : _currentPath, "New Card", "thcd");
     if (!string.IsNullOrEmpty(_currentPath))
     {
         CardFileHelper.writeToFile(_currentPath, _card);
     }
 }
Exemple #2
0
 private void saveFile()
 {
     if (!string.IsNullOrEmpty(_currentPath))
     {
         CardFileHelper.writeToFile(_currentPath, _card);
     }
     else
     {
         saveAsFile();
     }
 }
Exemple #3
0
 private void loadFile(string path)
 {
     _currentPath = path;
     _card        = CardFileHelper.readFromFile(_currentPath);
 }
        public HeartStoneRule(IGameEnvironment env, params CardDefine[] cards)
        {
            pool = new CardPool();
            //加载卡池
            //加载内置卡池
            Dictionary <int, CardDefine> dicCards = typeof(HeartStoneRule).Assembly.GetTypes().
                                                    Where(t =>
            {
                return(!t.IsAbstract && t.IsSubclassOf(typeof(CardDefine)) &&
                       (t.GetConstructor(new Type[0]) != null ||
                        t.GetConstructor(new Type[] { typeof(IGameEnvironment) }) != null));
            }).
                                                    Select(t =>
            {
                ConstructorInfo constructor = t.GetConstructor(new Type[0]);
                if (constructor != null)
                {
                    return(constructor.Invoke(new object[0]) as CardDefine);
                }
                else
                {
                    constructor = t.GetConstructor(new Type[] { typeof(IGameEnvironment) });
                    return(constructor.Invoke(new object[] { env }) as CardDefine);
                }
            }).ToDictionary(d =>
            {
                return(d.id);
            });

            //加载参数卡池
            for (int i = 0; i < cards.Length; i++)
            {
                if (!dicCards.ContainsKey(cards[i].id))
                {
                    dicCards.Add(cards[i].id, cards[i]);
                }
                else
                {
                    throw new ArgumentException("存在重复的卡片定义id" + cards[i].id);
                }
            }
            //加载外置卡池
            if (env != null)
            {
                foreach (string path in env.getFiles("Cards", "*.thcd"))
                {
                    using (TextReader reader = env.getFileReader(path))
                    {
                        GeneratedCardDefine card = CardFileHelper.read(reader);
                        if (dicCards.ContainsKey(card.id))
                        {
                            throw new ArgumentException("存在重复的卡片定义id" + card.id);
                        }
                        else
                        {
                            dicCards.Add(card.id, card);
                        }
                    }
                }
            }
            pool = new CardPool(dicCards.Values.ToArray());
        }