public ClassPageViewModel(ClassPageModel model) : base("Classes")
 {
     _Model = model;
     foreach (FilterGroup group in _Model.FilterGroups)
     {
         _FilterGroups.Add(new FilterGroupViewModel(group));
     }
     //_Classes = new ObservableList<ClassHeaderViewModel>();
     //foreach (var c in _Model.Content)
     //    if (c.ShowInClassList) _Classes.Add(new ClassHeaderViewModel(c, _Model.Selection));
 }
Ejemplo n.º 2
0
        //public object CharacterVM => ViewModel(() => new CharacterViewModel(_Compendium, _CharacterSelection));


        public ViewModelLocator()
        {
            _Compendium = new CompendiumModel();
            _SpellPage  = new SpellPageModel(_Compendium);
            _ClassPage  = new ClassPageModel(_Compendium);
            _AllPagesVM = new List <Page>();

            if (DesignMode)
            {
            }
            else
            {
                string dataDir = Path.Combine(
                    Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                    DATA_FOLDER);
                string indexFile = Path.Combine(dataDir, INDEX);

                if (!File.Exists(indexFile))
                {
                    throw new ArgumentNullException(indexFile + " not found.");
                }

                // Parse the index file that contains all the other pages that will be loaded
                //dynamic index = JsonConvert.DeserializeObject(ResourceHelper.ReadTextFromFile(indexFile));
                Index_Json index = JsonConvert.DeserializeObject <Index_Json>(ResourceHelper.ReadTextFromFile(indexFile));

                // Load spells and supporting info
                if (index.spells != null)
                {
                    _Compendium.AddContentPage(LoadSpellInfo(dataDir, index));
                }

                // Load classes
                if (index.classes != null && index.classSpells != null)
                {
                }

                // Load all other pages
                if (index.otherPages != null)
                {
                    foreach (var page in index.otherPages)
                    {
                        // TODO: More error checking
                        if (page.title == null || page.content == null)
                        {
                            continue;
                        }

                        ContentPageModel cpm = new ContentPageModel(_Compendium)
                        {
                            Header = page.title
                        };
                        cpm.DeserializeContent(
                            dataDir,
                            JsonConvert.DeserializeObject <ContentPage_Json>(
                                ReadFileFromIndex(Path.Combine(dataDir, page.content))));

                        _Compendium.OtherPages.Add(cpm);
                    }
                }

                #region old
                // Load the content sources first, so that other content can use the sources.
                // Sources being PHB, EE, Volo's, SCAG, etc.
                //_Compendium.DeserializeContentSources(
                //    JsonConvert.DeserializeObject<Sources_Json>(
                //        ReadFileFromIndex(
                //            Path.Combine(dataDir, index.sources))));

                //// If all of the spell json files are present, load the spells
                //if (index.spells != null && index.spellSchools != null && index.spellComponents != null)
                //{
                //    // Do schools and components first since the spells rely on those
                //    _SpellPage.DeserializeSchools(
                //        JsonConvert.DeserializeObject<Schools_Json>(
                //            ReadFileFromIndex(
                //                Path.Combine(dataDir, index.spellSchools))));
                //    _SpellPage.DeserializeComponents(
                //        JsonConvert.DeserializeObject<Components_Json>(
                //            ReadFileFromIndex(
                //                Path.Combine(dataDir, index.spellComponents))));
                //    _SpellPage.DeserializeSpells(
                //        JsonConvert.DeserializeObject<Spells_Json>(
                //            ReadFileFromIndex(Path.Combine(dataDir, index.spells))));
                //}

                //// If both class json files are present, load the classe
                //if (index.classes != null && index.classSpells != null)
                //{
                //    // Load classes firest since they need to be loaded before binding classes with their spell lists
                //    _ClassPage.DeserializeContent(
                //        dataDir,
                //        JsonConvert.DeserializeObject<Classes_Json>(
                //            ReadFileFromIndex(Path.Combine(dataDir, index.classes))));
                //    _ClassPage.DeserializeClassSpells(
                //        ReadFileFromIndex(Path.Combine(dataDir, index.classSpells)));
                //}

                //// Load the rest of the content from the "otherPages" into their own content viewers
                //if (index.otherPages != null)
                //{
                //    foreach (var page in index.otherPages)
                //    {
                //        // TODO: Add dialog about incorrect json
                //        if (page.title == null || page.content == null)
                //            continue;

                //        ContentPageModel cpm = new ContentPageModel(_Compendium)
                //        {
                //            Header = page.title
                //        };
                //        cpm.DeserializeContent(
                //            dataDir,
                //            JsonConvert.DeserializeObject<ContentPage_Json>(
                //                ReadFileFromIndex(Path.Combine(dataDir, page.content))));

                //        _Compendium.OtherPages.Add(cpm);
                //    }
                //}
                #endregion
            }
        }