Example #1
0
 private static T Update <T>(TomlTable table, string key, T obj)
     where T : TomlObject
 {
     if (table.TryGetValue(key, out var _))
     {
         table.SetRow(new TomlKey(key), obj);
         return(obj);
     }
     else
     {
         throw new InvalidOperationException($"Cannot update because row with key '{key}' does not exist.");
     }
 }
Example #2
0
            public LayerPoints(Nett.TomlTable table)
            {
                if (table.TryGetValue("seed", out var tomlObject))
                {
                    Seed = tomlObject.Get <int>();
                }

                if (table.TryGetValue("count", out tomlObject))
                {
                    PointCount = tomlObject.Get <int>();
                }

                if (table.TryGetValue("sourcefactor", out tomlObject))
                {
                    SrcFactor = (BlendFactor)Enum.Parse(typeof(BlendFactor), tomlObject.Get <string>());
                }
                if (table.TryGetValue("destfactor", out tomlObject))
                {
                    DstFactor = (BlendFactor)Enum.Parse(typeof(BlendFactor), tomlObject.Get <string>());
                }

                if (table.TryGetValue("farcolor", out tomlObject))
                {
                    FarColor = Util.ColorFromHex(tomlObject.Get <string>());
                }
                if (table.TryGetValue("closecolor", out tomlObject))
                {
                    CloseColor = Util.ColorFromHex(tomlObject.Get <string>());
                }
                if (table.TryGetValue("pointsize", out tomlObject))
                {
                    PointSize = tomlObject.Get <int>();
                }

                // Noise mask stuff.
                if (table.TryGetValue("mask", out tomlObject))
                {
                    Masked = tomlObject.Get <bool>();
                }

                if (table.TryGetValue("maskseed", out tomlObject))
                {
                    MaskSeed = (uint)tomlObject.Get <int>();
                }
                if (table.TryGetValue("maskpersistence", out tomlObject))
                {
                    MaskPersistence = double.Parse(tomlObject.Get <string>(), System.Globalization.CultureInfo.InvariantCulture);
                }
                if (table.TryGetValue("masklacunarity", out tomlObject))
                {
                    MaskLacunarity = double.Parse(tomlObject.Get <string>(), System.Globalization.CultureInfo.InvariantCulture);
                }
                if (table.TryGetValue("maskfrequency", out tomlObject))
                {
                    MaskFrequency = double.Parse(tomlObject.Get <string>(), System.Globalization.CultureInfo.InvariantCulture);
                }
                if (table.TryGetValue("maskoctaves", out tomlObject))
                {
                    MaskOctaves = (uint)tomlObject.Get <int>();
                }
                if (table.TryGetValue("maskthreshold", out tomlObject))
                {
                    MaskThreshold = double.Parse(tomlObject.Get <string>(), System.Globalization.CultureInfo.InvariantCulture);
                }
                if (table.TryGetValue("masknoise_type", out tomlObject))
                {
                    switch (tomlObject.Get <string>())
                    {
                    case "fbm":
                        MaskNoiseType = RustNoise.NoiseType.Fbm;
                        break;

                    case "ridged":
                        MaskNoiseType = RustNoise.NoiseType.Ridged;
                        break;

                    default:
                        throw new InvalidOperationException();
                    }
                }
                if (table.TryGetValue("maskpower", out tomlObject))
                {
                    MaskPower = double.Parse(tomlObject.Get <string>(), System.Globalization.CultureInfo.InvariantCulture);
                }
            }
Example #3
0
            public LayerNoise(Nett.TomlTable table)
            {
                if (table.TryGetValue("innercolor", out var tomlObject))
                {
                    InnerColor = Util.ColorFromHex(tomlObject.Get <string>());
                }
                if (table.TryGetValue("outercolor", out tomlObject))
                {
                    OuterColor = Util.ColorFromHex(tomlObject.Get <string>());
                }
                if (table.TryGetValue("seed", out tomlObject))
                {
                    Seed = (uint)tomlObject.Get <int>();
                }
                if (table.TryGetValue("persistence", out tomlObject))
                {
                    Persistence = double.Parse(tomlObject.Get <string>(), System.Globalization.CultureInfo.InvariantCulture);
                }
                if (table.TryGetValue("lacunarity", out tomlObject))
                {
                    Lacunarity = double.Parse(tomlObject.Get <string>(), System.Globalization.CultureInfo.InvariantCulture);
                }
                if (table.TryGetValue("frequency", out tomlObject))
                {
                    Frequency = double.Parse(tomlObject.Get <string>(), System.Globalization.CultureInfo.InvariantCulture);
                }
                if (table.TryGetValue("octaves", out tomlObject))
                {
                    Octaves = (uint)tomlObject.Get <int>();
                }
                if (table.TryGetValue("threshold", out tomlObject))
                {
                    Threshold = double.Parse(tomlObject.Get <string>(), System.Globalization.CultureInfo.InvariantCulture);
                }
                if (table.TryGetValue("sourcefactor", out tomlObject))
                {
                    SrcFactor = (BlendFactor)Enum.Parse(typeof(BlendFactor), tomlObject.Get <string>());
                }
                if (table.TryGetValue("destfactor", out tomlObject))
                {
                    DstFactor = (BlendFactor)Enum.Parse(typeof(BlendFactor), tomlObject.Get <string>());
                }
                if (table.TryGetValue("power", out tomlObject))
                {
                    Power = double.Parse(tomlObject.Get <string>(), System.Globalization.CultureInfo.InvariantCulture);
                }
                if (table.TryGetValue("noise_type", out tomlObject))
                {
                    switch (tomlObject.Get <string>())
                    {
                    case "fbm":
                        NoiseType = RustNoise.NoiseType.Fbm;
                        break;

                    case "ridged":
                        NoiseType = RustNoise.NoiseType.Ridged;
                        break;

                    default:
                        throw new InvalidOperationException();
                    }
                }
            }