Example #1
0
 private void Load()
 {
     try
     {
         _plotElements = DataSerializer.DeserializeFileData(_directoryPath);
     }
     catch (Exception e)
     {
         throw new Exception("An Error occured while loading data from files. Please review the files to make sure the data is in proper JSON format.", e);
     }
 }
Example #2
0
 /// <summary>
 /// Copy constructor
 /// </summary>
 /// <param name="viewModel">The viewmodel to copy.</param>
 public DiagramViewModel(DiagramViewModel viewModel)
 {
     Id   = viewModel.Id;
     Name = viewModel.Name;
     Characters.AddRange(viewModel.Characters);
     Storylines.AddRange(viewModel.Storylines);
     PlotElements.AddRange(viewModel.PlotElements);
     Relationships.AddRange(viewModel.Relationships);
     StorylineCharacterConnections.AddRange(viewModel.StorylineCharacterConnections);
     StorylinePlotElementConnections.AddRange(viewModel.StorylinePlotElementConnections);
     CharacterPlotElementConnections.AddRange(viewModel.CharacterPlotElementConnections);
 }
        public RandomSelector(PlotElements plotElements)
        {
            _plotElements = plotElements;

            _constructs = typeof(PlotElements)
                          .GetProperties()
                          .ToDictionary(
                propertyInfo => propertyInfo.PropertyType.Name,
                propertyInfo =>
            {
                var propertyValue = propertyInfo.GetValue(_plotElements);
                return(propertyValue.GetType().GetProperties().Where(propInfo => propInfo.PropertyType == typeof(List <string>))
                       .ToDictionary(listInfo => listInfo.Name,
                                     listInfo => (List <string>)listInfo.GetValue(propertyValue)));
            });
        }
Example #4
0
        public static PlotElements DeserializeFileData(string directory)
        {
            var files = Directory.EnumerateFiles(directory, "*.json").ToDictionary(Path.GetFileNameWithoutExtension, File.ReadAllText);

            var elements = new PlotElements
            {
                Adjective  = JsonConvert.DeserializeObject <Adjective>(files[nameof(Adjective)]),
                Adverb     = JsonConvert.DeserializeObject <Adverb>(files[nameof(Adverb)]),
                Age        = JsonConvert.DeserializeObject <Age>(files[nameof(Age)]),
                Noun       = JsonConvert.DeserializeObject <Noun>(files[nameof(Noun)]),
                StoryParts = JsonConvert.DeserializeObject <StoryParts>(files[nameof(StoryParts)]),
                Verb       = JsonConvert.DeserializeObject <Verb>(files[nameof(Verb)])
            };

            return(elements);
        }