Example #1
0
        public DelveInfoBuilder WithName(string name)
        {
            NameInput = name;

            if (randomAliases.Any(alias => alias.Equals(NameInput, StringComparison.OrdinalIgnoreCase)) && Domains.Count > 0)
            {
                var roller = new OracleRoller(Oracles, GameName.Ironsworn);
                roller.BuildRollResults("Site Name Format");
                Name = roller.RollResultList.First().Result.Description;
                string place = roller.BuildRollResults($"Site Name Place {Domains.First().DelveSiteDomain}").RollResultList.First().Result.Description;
                Name = Name.Replace("{Place}", place);
            }
            else
            {
                Name = name;
            }

            return(this);
        }
Example #2
0
 internal Domain <T> GetDomain(string key) => Domains.First(d => d.Key == key);
Example #3
0
        private void Load(string Path)
        {
            if (File.Exists(Path))
            {
                canNetwork.Items.Clear();
                NetworkParameters = Newtonsoft.Json.JsonConvert.DeserializeObject <SimulationParameters>(File.ReadAllText(Path));

                var networkDir = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Path), System.IO.Path.GetFileNameWithoutExtension(Path));

                try
                {
                    var nodes = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Node> >(File.ReadAllText(System.IO.Path.Combine(networkDir, "nodes.json")));
                    canNetwork.AddItems(nodes);
                    NodeStore.Nodes = nodes;

                    try
                    {
                        var links = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Link> >(File.ReadAllText(System.IO.Path.Combine(networkDir, "links.json")));
                        canNetwork.AddItems(links);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Links are corrupt.");
                    }

                    try
                    {
                        var streams = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Stream> >(File.ReadAllText(System.IO.Path.Combine(networkDir, "streams.json")));
                        canNetwork.AddItems(streams);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Streams are corrupt.");
                    }

                    try
                    {
                        var domains = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Domain> >(File.ReadAllText(System.IO.Path.Combine(networkDir, "domains.json")));
                        canNetwork.AddItems(domains);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Domains are corrupt.");
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Nodes are corrupt.");
                }

                try
                {
                    DisplayProperties.Reset();
                    var displayProperties = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, Tuple <Type, object> > >(File.ReadAllText(System.IO.Path.Combine(networkDir, "display.json")));

                    foreach (var property in displayProperties)
                    {
                        if (property.Value.Item1.IsEnum)
                        {
                            dynamic value = Enum.ToObject(property.Value.Item1, property.Value.Item2);

                            var field = typeof(DisplayProperties).GetField(property.Key);
                            field.SetValue(null, value);
                        }
                        else
                        {
                            var field = typeof(DisplayProperties).GetField(property.Key);
                            field.SetValue(null, property.Value.Item2);
                        }
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Display properties are corrupt.");
                }

                // JSON can't store circular reference to parent or reference to actual Node / Link / Stream / Domain object.
                foreach (var trace in NetworkParameters.Traces)
                {
                    foreach (var attribute in trace.Attributes)
                    {
                        attribute.Parent = trace;
                        if (attribute.Element is Node)
                        {
                            attribute.Element = NodeStore.Nodes.First((x) => x.Name == (attribute.Element as Node).Name);
                        }
                        else if (attribute.Element is Link)
                        {
                            attribute.Element = Links.First((x) => x.Name == (attribute.Element as Link).Name);
                        }
                        else if (attribute.Element is Stream)
                        {
                            attribute.Element = Streams.First((x) => x.Name == (attribute.Element as Stream).Name);
                        }
                        else if (attribute.Element is Domain)
                        {
                            attribute.Element = Domains.First((x) => x.Name == (attribute.Element as Domain).Name);
                        }
                    }
                }

                // Fix up the links in plot attributes.
                foreach (var plot in NetworkParameters.Plots)
                {
                    foreach (var attribute in plot.Attributes)
                    {
                        attribute.TraceParameter = NetworkParameters.Traces.First((x) => x.Name == attribute.TraceParameter.Name);
                    }
                }

                canNetwork.Invalidate();
                NodeStore.Nodes = null;
                SetTitle();
            }
            else
            {
                MessageBox.Show($"Cannot find file \"{Path}\"");
            }
        }