public static GameConfigurationViewModel GetDefaultConfigurationViewModel()
        {
            var item = new GameConfigurationDataModel
            {
                Name          = ModuleConstants.DefaultConfigurationName,
                PlayerPresets = new[]
                {
                    new PlayerPresetDataModel {
                        Race = Races.Random
                    },
                    new PlayerPresetDataModel {
                        Race = Races.Random
                    },
                    new PlayerPresetDataModel {
                        Race = Races.Random
                    }
                },
                LoyaltyTrackerSize  = 8,
                WinPointTrackerSize = 50
            }.ToViewModel();

            item.IsNotEditable = true;

            return(item);
        }
Esempio n. 2
0
        public IEnumerable <GameConfigurationDataModel> Load()
        {
            var files = Directory.GetFiles(GetConfigurationDirectoryPath());

            foreach (var file in files)
            {
                var json = File.ReadAllText(file);

                GameConfigurationDataModel dataModel = null;

                try
                {
                    dataModel = JsonConvert.DeserializeObject <GameConfigurationDataModel>(json);
                }
                catch (Exception e)
                {
                    this.LogCriticalException(e);
                }

                if (dataModel != null)
                {
                    yield return(dataModel);
                }
            }
        }
Esempio n. 3
0
        public void Save(GameConfigurationDataModel dataModel)
        {
            var filePath = GetFileName(dataModel.Id);
            var json     = JsonConvert.SerializeObject(dataModel);

            File.WriteAllText(filePath, json);
        }
Esempio n. 4
0
        public static GameConfigurationViewModel ToViewModel(this GameConfigurationDataModel item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            var viewModel = ServiceLocator.Container.Resolve <GameConfigurationViewModel>();

            // TODO: Copy fields here.
            viewModel.Id               = item.Id;
            viewModel.SaveTime         = item.SaveTime;
            viewModel.Name             = item.Name;
            viewModel.MaxWinPoints     = item.WinPointTrackerSize;
            viewModel.MaxLoyaltyPoints = item.LoyaltyTrackerSize;

            viewModel.PlayerPresets.ReplaceAll(item.PlayerPresets.Select(x =>
            {
                var vm = ServiceLocator.Container.Resolve <PlayerPresetViewModel>();

                // TODO: Copy fields here.
                vm.Race  = viewModel.RaceMap[x.Race];
                vm.Color = x.Color;

                return(vm);
            }));

            return(viewModel);
        }