コード例 #1
0
 public SideboardingEditorModel(ServicesProvider servicesProvider, GameInfoItem gameItem, DeckItem deck)
 {
     this.ServiceProvider = servicesProvider;
       this.GameItem = gameItem;
       this.originalDeck = deck;
       this.Deck = (DeckItem)deck.Clone();
 }
コード例 #2
0
        public LogicHandler(IViewFactory viewFactory)
        {
            this.viewFactory = viewFactory;

              servicesProvider = new ServicesProvider(SettingsManager.Settings.ClientLanguage, SettingsManager.Settings.GameLanguage);
              gameItem = servicesProvider.GetAllGames().Single(g => g.Code == SettingsManager.Settings.CurrentGameCode);
              servicesProvider.LoadGame(gameItem);
        }
コード例 #3
0
ファイル: GameModel.cs プロジェクト: calvinkwong/pol-the-game
 public GameModel(GameInfoItem gameItem)
     : base(Guid.NewGuid().ToString())
 {
     this.GameItem = gameItem;
       this.Players = new ModelCollection(this);
       this.Lookups = new ModelCollection(this);
       this.Commands = new ModelCollection(this);
       this.CardDisplay = new CardDisplayModel(Guid.NewGuid().ToString());
       this.Console = new ConsoleModel(Guid.NewGuid().ToString());
 }
コード例 #4
0
 public DeckEditorModel(ServicesProvider servicesProvider, GameInfoItem gameItem, DeckItem deck)
 {
     this.ServiceProvider = servicesProvider;
       this.GameItem = gameItem;
       if(deck == null)
     Deck = new DeckItem(gameItem.Code);
       else
       {
     originalDeck = deck;
     Deck = (DeckItem)deck.Clone();
       }
 }
コード例 #5
0
 public DeckRoomModel(ServicesProvider servicesProvider, GameInfoItem gameItem)
 {
     this.ServicesProvider = servicesProvider;
       this.GameItem = gameItem;
       this.SelectedDeck = new ObservableProperty<DeckItem, DeckRoomModel>(this, null);
 }
コード例 #6
0
        void LoadCards(GameInfoItem gameInfoItem, out XmlDocument cardsDatabase, out XmlDocument cardsLangDatabase, out List<GameSetItem> gameSets)
        {
            gameSets = new List<GameSetItem>();
              cardsDatabase = new XmlDocument();
              cardsDatabase.LoadXml("<cards />");
              cardsLangDatabase = new XmlDocument();
              cardsLangDatabase.LoadXml("<cards_lang />");
              var filePaths = Directory.GetFiles(Path.Combine(gameInfoItem.GamePath, "cards"), "*.xml").Where(f => Path.GetFileNameWithoutExtension(f).IndexOf(".") == -1);
              XmlDocument currentSetDoc = new XmlDocument();
              XmlDocument currentSetLangDoc = new XmlDocument();
              foreach(string filePath in filePaths)
              {
            string fileLangPath = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath) + "." + GameLanguageCode + ".xml");
            if(!File.Exists(fileLangPath))
              throw new InvalidSourceException("File " + fileLangPath + " not found.");

            currentSetDoc.Load(filePath);
            currentSetLangDoc.Load(fileLangPath);
            GameSetItem gameSetItem = new GameSetItem()
            {
              Code = currentSetDoc.DocumentElement.Attributes["code"].Value,
              ReleaseDate = XmlConvert.ToDateTime(currentSetDoc.DocumentElement.Attributes["releaseDate"].Value, "yyyy-MM-ddTHH:mm:ss"),
              Name = currentSetLangDoc.DocumentElement.Attributes["name"].Value,
            };
            gameSets.Add(gameSetItem);
            foreach(XmlNode node in currentSetDoc.DocumentElement.SelectNodes("item"))
            {
              XmlNode importedNode = cardsDatabase.ImportNode(node, true);
              var setElement = cardsDatabase.CreateElement("set");
              setElement.InnerText = gameSetItem.Code;
              importedNode.AppendChild(setElement);
              cardsDatabase.DocumentElement.AppendChild(importedNode);
            }
            foreach(XmlNode node in currentSetLangDoc.DocumentElement.SelectNodes("item"))
              cardsLangDatabase.DocumentElement.AppendChild(cardsLangDatabase.ImportNode(node, true));
              }
        }
コード例 #7
0
        public void LoadGame(GameInfoItem gameInfoItem)
        {
            string gameCode = gameInfoItem.Code;

              string gameDataBasePath = Path.Combine(gameInfoItem.GamePath, "game.xml");
              if(!File.Exists(gameDataBasePath))
            throw new InvalidSourceException("File " + gameDataBasePath + " not found.");
              string gameLangDataBasePath = Path.Combine(gameInfoItem.GamePath, "game." + GameLanguageCode + ".xml");
              if(!File.Exists(gameLangDataBasePath))
            throw new InvalidSourceException("File " + gameLangDataBasePath + " not found.");
              string gameStringsDatabasePath = Path.Combine(gameInfoItem.GamePath, "strings." + GameLanguageCode + ".xml");
              if(!File.Exists(gameStringsDatabasePath))
            throw new InvalidSourceException("File " + gameStringsDatabasePath + " not found.");

              string setCodesFilePath = Path.Combine(Path.Combine(SettingsManager.Settings.DataPath, gameCode), "set-codes.xml");

              #region crc
              //SHA256 sha256Encoder = SHA256Managed.Create();
              //try
              //{
              //  using(FileStream fs = File.Open(gameDataBasePath, FileMode.Open, FileAccess.Read, FileShare.Read))
              //    gameDatabaseCrc = Convert.ToBase64String(sha256Encoder.ComputeHash(fs));
              //  using(FileStream fs = File.Open(cardDataBasePath, FileMode.Open, FileAccess.Read, FileShare.Read))
              //    cardDatabaseCrc = Convert.ToBase64String(sha256Encoder.ComputeHash(fs));
              //}
              //finally
              //{
              //  sha256Encoder.Clear();
              //}
              #endregion

              try
              {
            XmlDocument gameDatabase = new XmlDocument();
            gameDatabase.Load(gameDataBasePath);
            XmlDocument gameLangDatabase = new XmlDocument();
            gameLangDatabase.Load(gameLangDataBasePath);
            XmlDocument gameStringsDatabase = new XmlDocument();
            gameStringsDatabase.Load(gameStringsDatabasePath);

            if(File.Exists(setCodesFilePath))
              setCodesMapService = new CodesMapService(setCodesFilePath);
            imagesService = new Services.ImagesService(setCodesMapService);

            typesService = new CardTypesService(gameDatabase.DocumentElement["card_types"], gameLangDatabase.DocumentElement["card_types_lang"]);
            colorsService = new BaseItemService(gameDatabase.DocumentElement["card_colors"], gameLangDatabase.DocumentElement["card_colors_lang"]);
            raritiesService = new BaseItemService(gameDatabase.DocumentElement["card_rarities"], gameLangDatabase.DocumentElement["card_rarities_lang"]);
            stylesService = new BaseItemService(gameDatabase.DocumentElement["card_styles"], gameLangDatabase.DocumentElement["card_styles_lang"]);
            commandsService = new BaseItemService(gameDatabase.DocumentElement["commands"], gameLangDatabase.DocumentElement["commands_lang"]);
            stylesBehaviorsService = new CardStyleBehaviorsService(gameDatabase.DocumentElement["card_style_behaviors"], gameDatabase.DocumentElement["card_styles"]);
            sectorsService = new SectorsService(gameDatabase.DocumentElement["sectors"], gameLangDatabase.DocumentElement["sectors_lang"]);
            numCountersService = new NumCountersService(gameDatabase.DocumentElement["numCounters"], gameLangDatabase.DocumentElement["numCounters_lang"]);

            XmlDocument cardsDatabase;
            XmlDocument cardsLangDatabase;
            List<GameSetItem> gameSets;
            LoadCards(gameInfoItem, out cardsDatabase, out cardsLangDatabase, out gameSets);
            cardService = new CardsService(cardsDatabase, cardsLangDatabase, typesService);

            gameSetsService = new GameSetsService(gameSets);

            deckService = new DecksService(this);
            gameStringsService = new StringService(gameStringsDatabase);
              }
              catch(Exception ex)
              {
            throw new InvalidSourceException("Invalid data source." + Environment.NewLine + ex.Message, ex);
              }
        }
コード例 #8
0
        public List<GameInfoItem> GetAllGames()
        {
            List<GameInfoItem> games = new List<GameInfoItem>();
              foreach(string dir in Directory.GetDirectories(SettingsManager.Settings.DataPath))
              {
            string gameDataBasePath = Path.Combine(dir, "game.xml");
            if(File.Exists(gameDataBasePath))
            {
              string gameLangDataBasePath = Path.Combine(dir, "game." + GameLanguageCode + ".xml");
              if(!File.Exists(gameLangDataBasePath))
            throw new InvalidSourceException("File " + gameLangDataBasePath + " not found.");

              XmlDocument gameDatabase = new XmlDocument();
              gameDatabase.Load(gameDataBasePath);

              XmlDocument gameLangDatabase = new XmlDocument();
              gameLangDatabase.Load(gameLangDataBasePath);

              var gameInfoItem = new GameInfoItem(dir, gameDatabase, gameLangDatabase);
              games.Add(gameInfoItem);
            }
              }
              return games;
        }
コード例 #9
0
        //public void ImportDeckFromText(GameItem gameItem, string text, MappingManager mappingManager)
        //{
        //  DeckItem deck = new DeckItem(gameItem.Code);
        //  deck.Category = "Imported";
        //  deck.Name = "???";
        //  ImportMwsDeck(deck, text, mappingManager);
        //  SaveDeck(deck);
        //}
        public DeckImportStatistics ImportDecksFromFiles(GameInfoItem gameItem, string[] fileNames, CodesMapService mappingManager)
        {
            DeckImportStatistics statistics = new DeckImportStatistics();

              foreach(string fileName in fileNames)
              {
            Dictionary<string, string> discardedLines = new Dictionary<string, string>();
            if(string.Compare(Path.GetExtension(fileName), DECK_FILE_EXTENSION) != 0)
            {
              DeckItem deck = new DeckItem(gameItem.Code);
              deck.Category = "Imported";
              deck.Name = Path.GetFileNameWithoutExtension(fileName);

              ImportMwsDeck(gameItem, deck, File.ReadAllText(fileName), mappingManager, discardedLines);

              SaveDeck(deck);
            }
            else
            {
              File.Copy(fileName, Path.Combine(SettingsManager.Settings.DeckPath, Path.GetFileName(fileName)), true);
            }
            statistics.ImportResults.Add(new DeckImportResult()
            {
              FileName = fileName,
              Successfull = discardedLines.Count == 0,
              DiscardedLines = discardedLines
            });
              }
              return statistics;
        }
コード例 #10
0
        void ImportMwsDeck(GameInfoItem gameItem, DeckItem deck, string text, CodesMapService mappingManager, Dictionary<string, string> discardedLines)
        {
            ServicesProvider engServicesProvider = servicesProvider;
              if(engServicesProvider.GameLanguageCode != "eng")
              {
            engServicesProvider = new ServicesProvider("eng", "eng");
            engServicesProvider.LoadGame(gameItem);
              }
              discardedLines.Clear();
              foreach(string line in text.Split(new string[] {Environment.NewLine}, StringSplitOptions.None).
            Select(e => e.Trim()).Where(e => e.Length > 0 && !e.StartsWith("//")))
              {
            string[] lineParts = line.Split(' ');
            if(lineParts.Length < 3)
              continue;

            try
            {
              var cardList = deck.MainCards;
              int partIndex = 0;
              if(lineParts[0] == "SB:")
              {
            partIndex++;
            cardList = deck.SideboardCards;
              }
              int amount;
              if(int.TryParse(lineParts[partIndex++], out amount))
              {
            string mwsSetCode = string.Empty;
            try
            {
              mwsSetCode = lineParts[partIndex++].Replace("[", string.Empty).Replace("]", string.Empty);
            }
            catch
            {
              throw new Exception("Cannot read set code on this line: " + line);
            }
            string cardName = string.Empty;
            try
            {
              cardName = string.Concat(
                lineParts.Skip(partIndex).Where(e => e != "(1)" && e != "(2)" && e != "(3)" && e != "(4)").Select(
                e => string.Concat(e, " ")).ToArray()).TrimEnd();
              cardName = cardName.Split(new string[] { "--" }, StringSplitOptions.None).First();
            }
            catch
            {
              throw new Exception("Cannot read card name on this line: " + line);
            }
            string internalSetCode = mappingManager.GetCode(mwsSetCode);
            if(string.IsNullOrEmpty(internalSetCode))
              throw new Exception("Set code unknown: " + mwsSetCode);
            CardSearchParams p = new CardSearchParams();
            p.Sets.Add(internalSetCode);
            p.Name = cardName;
            p.Language = "ENG";
            p.NameExact = true;

            CardItem cardItem = engServicesProvider.CardsService.SelectCards(p).FirstOrDefault();
            if(cardItem == null)
              throw new Exception("Card name unknown: " + cardName);
            for(int i = 0; i < amount; i++)
              cardList.Add(cardItem.Clone());
              }
              else
              {
            throw new Exception("Cannot read card amount on this line: " + line);
              }
            }
            catch(Exception ex)
            {
              discardedLines.Add(line, ex.Message);
            }
              }
        }