Add ranges to external classes

This commit is contained in:
Ben C 2022-05-22 20:08:12 -04:00
parent 71874669c9
commit 7b49dfff55
13 changed files with 73 additions and 54 deletions

View File

@ -1,4 +1,5 @@
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using Newtonsoft.Json;
namespace NewHorizons.External.Modules
@ -9,7 +10,7 @@ namespace NewHorizons.External.Modules
/// <summary>
/// Amount of asteroids to create.
/// </summary>
[DefaultValue(-1)] public int amount = -1;
[Range(0, 200)] [DefaultValue(-1)] public int amount = -1;
/// <summary>
/// Angle between the rings and the equatorial plane of the planet.
@ -19,7 +20,7 @@ namespace NewHorizons.External.Modules
/// <summary>
/// Lowest distance from the planet asteroids can spawn
/// </summary>
public float innerRadius;
[Range(0f, double.MaxValue)] public float innerRadius;
/// <summary>
/// Angle defining the point where the rings rise up from the planet's equatorial plane if inclination is nonzero.
@ -29,17 +30,19 @@ namespace NewHorizons.External.Modules
/// <summary>
/// Maximum size of the asteroids.
/// </summary>
[DefaultValue(50)] public float maxSize = 50f;
[Range(0f, double.MaxValue)] [DefaultValue(50)]
public float maxSize = 50f;
/// <summary>
/// Minimum size of the asteroids.
/// </summary>
[DefaultValue(20)] public float minSize = 20;
[Range(0f, double.MaxValue)] [DefaultValue(20)]
public float minSize = 20;
/// <summary>
/// Greatest distance from the planet asteroids can spawn
/// </summary>
public float outerRadius;
[Range(0f, double.MaxValue)] public float outerRadius;
/// <summary>
/// How the asteroids are generated

View File

@ -37,14 +37,12 @@ namespace NewHorizons.External.Modules
/// <summary>
/// How dense the fog is, if you put fog.
/// </summary>
[Range(0f, 1f)]
public float fogDensity;
[Range(0f, 1f)] public float fogDensity;
/// <summary>
/// Radius of fog sphere, independent of the atmosphere. This has to be set for there to be fog.
/// </summary>
[Range(0f, float.MaxValue)]
public float fogSize;
[Range(0f, double.MaxValue)] public float fogSize;
/// <summary>
/// Colour of fog on the planet, if you put fog.

View File

@ -1,7 +1,10 @@
using NewHorizons.Utility;
using System.ComponentModel.DataAnnotations;
using NewHorizons.Utility;
using Newtonsoft.Json;
namespace NewHorizons.External.Modules
{
[JsonObject]
public class HeightMapModule
{
/// <summary>
@ -12,12 +15,12 @@ namespace NewHorizons.External.Modules
/// <summary>
/// The highest points on your planet will be at this height.
/// </summary>
public float maxHeight;
[Range(0f, double.MaxValue)] public float maxHeight;
/// <summary>
/// The lowest points on your planet will be at this height.
/// </summary>
public float minHeight;
[Range(0f, double.MaxValue)] public float minHeight;
/// <summary>
/// The scale of the terrain.

View File

@ -1,4 +1,5 @@
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using NewHorizons.Components.Orbital;
using NewHorizons.Utility;
@ -66,6 +67,8 @@ namespace NewHorizons.External.Modules
/// <summary>
/// The semi-major axis of the ellipse that is the body's orbit. For a circular orbit this is the radius.
/// </summary>
[Range(0f, double.MaxValue)]
[DefaultValue(5000f)]
public float SemiMajorAxis { get; set; }
/// <summary>
@ -82,7 +85,7 @@ namespace NewHorizons.External.Modules
/// <summary>
/// At 0 the orbit is a circle. The closer to 1 it is, the more oval-shaped the orbit is.
/// </summary>
// FIXME: Needs Min & Max!
[Range(0f, 0.9999999999f)]
public float Eccentricity { get; set; }
/// <summary>

View File

@ -1,4 +1,5 @@
using NewHorizons.Utility;
using System.ComponentModel.DataAnnotations;
using NewHorizons.Utility;
using Newtonsoft.Json;
namespace NewHorizons.External.Modules
@ -7,6 +8,7 @@ namespace NewHorizons.External.Modules
public class ProcGenModule
{
public MColor color;
public float scale;
[Range(0, double.MaxValue)] public float scale;
}
}

View File

@ -1,4 +1,5 @@
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using NewHorizons.Utility;
using Newtonsoft.Json;
@ -475,7 +476,7 @@ namespace NewHorizons.External.Modules
/// <summary>
/// The z euler angle for this arc.
/// </summary>
public float zRotation;
[Range(0f, 360f)] public float zRotation;
}
[JsonObject]

View File

@ -1,4 +1,5 @@
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using NewHorizons.Utility;
using Newtonsoft.Json;
@ -29,7 +30,7 @@ namespace NewHorizons.External.Modules
/// How close the player must get to the signal to detect it. This is when you get the "Unknown Signal Detected"
/// notification.
/// </summary>
public float detectionRadius;
[Range(0f, double.MaxValue)] public float detectionRadius;
/// <summary>
/// The frequency ID of the signal. The built-in game values are `Default`, `Traveler`, `Quantum`, `EscapePod`,
@ -40,7 +41,8 @@ namespace NewHorizons.External.Modules
/// <summary>
/// How close the player must get to the signal to identify it. This is when you learn its name.
/// </summary>
[DefaultValue(10f)] public float identificationRadius = 10f;
[DefaultValue(10f)] [Range(0f, double.MaxValue)]
public float identificationRadius = 10f;
/// <summary>
/// Only set to `true` if you are putting this signal inside a cloaking field.

View File

@ -1,4 +1,5 @@
using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations;
using Newtonsoft.Json;
namespace NewHorizons.External.Modules.VariableSize
{
@ -18,7 +19,7 @@ namespace NewHorizons.External.Modules.VariableSize
/// <summary>
/// Inner radius of the disk
/// </summary>
public float innerRadius;
[Range(0, double.MaxValue)] public float innerRadius;
/// <summary>
/// Angle defining the point where the rings rise up from the planet's equatorial plane if inclination is nonzero.
@ -28,7 +29,7 @@ namespace NewHorizons.External.Modules.VariableSize
/// <summary>
/// Outer radius of the disk
/// </summary>
public float outerRadius;
[Range(0, double.MaxValue)] public float outerRadius;
/// <summary>
/// Allows the rings to rotate.

View File

@ -1,4 +1,5 @@
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using NewHorizons.Utility;
using Newtonsoft.Json;
@ -36,7 +37,7 @@ namespace NewHorizons.External.Modules.VariableSize
/// Radius of the singularity. Note that this isn't the same as the event horizon, but includes the entire volume that
/// has warped effects in it.
/// </summary>
public float size;
[Range(0f, double.MaxValue)] public float size;
/// <summary>
/// If you want a black hole to load a new star system scene, put its name here.

View File

@ -1,4 +1,5 @@
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using NewHorizons.Utility;
using Newtonsoft.Json;
@ -31,12 +32,14 @@ namespace NewHorizons.External.Modules.VariableSize
/// <summary>
/// Radius of the star.
/// </summary>
[DefaultValue(2000f)] public float size = 2000f;
[DefaultValue(2000f)] [Range(0f, double.MaxValue)]
public float size = 2000f;
/// <summary>
/// Relative strength of the light compared to the sun.
/// </summary>
[DefaultValue(1f)] public float solarLuminosity = 1f;
[DefaultValue(1f)] [Range(0f, double.MaxValue)]
public float solarLuminosity = 1f;
/// <summary>
/// The tint of the supernova this star creates when it dies.

View File

@ -1,4 +1,5 @@
using Newtonsoft.Json;
using System.ComponentModel;
using Newtonsoft.Json;
using UnityEngine;
namespace NewHorizons.Utility
{
@ -34,7 +35,8 @@ namespace NewHorizons.Utility
/// <summary>
/// The alpha (opacity) component of this colour
/// </summary>
[System.ComponentModel.DataAnnotations.Range(0f, int.MaxValue)]
[System.ComponentModel.DataAnnotations.Range(0f, 255f)]
[DefaultValue(255f)]
public int a;
public Color32 ToColor32() => new Color32((byte)r, (byte)g, (byte)b, (byte)a);

View File

@ -4,15 +4,38 @@ using NewHorizons.External.Configs;
using NJsonSchema;
using NJsonSchema.Generation;
namespace SchemaExporter;
public static class SchemaExporter
{
private struct Schema<T>
public static void Main(string[] args)
{
const string folderName = "Schemas";
Directory.CreateDirectory(folderName);
Console.WriteLine("Schema Generator: We're winning!");
var settings = new JsonSchemaGeneratorSettings
{
IgnoreObsoleteProperties = true
};
Console.WriteLine("Outputting Body Schema");
var bodySchema = new Schema<PlanetConfig>("Celestial Body Schema", $"{folderName}/body_schema", settings);
bodySchema.Output();
Console.WriteLine("Outputting Star System Schema");
var systemSchema =
new Schema<StarSystemConfig>("Star System Schema", $"{folderName}/star_system_schema", settings);
systemSchema.Output();
Console.WriteLine("Outputting Translation Schema");
var translationSchema =
new Schema<TranslationConfig>("Translation Schema", $"{folderName}/translation_schema", settings);
translationSchema.Output();
Console.WriteLine("Done!");
}
private readonly struct Schema<T>
{
private readonly JsonSchemaGeneratorSettings _generatorSettings;
private string _title;
private readonly string _title;
private readonly string _outFileName;
public Schema(string schemaTitle, string fileName, JsonSchemaGeneratorSettings settings)
@ -21,7 +44,7 @@ public static class SchemaExporter
_outFileName = fileName;
_generatorSettings = settings;
}
public void Output()
{
File.WriteAllText($"{_outFileName}.json", ToString());
@ -31,7 +54,7 @@ public static class SchemaExporter
{
return GetJsonSchema().ToJson();
}
public JsonSchema GetJsonSchema()
{
var schema = JsonSchema.FromType<T>(_generatorSettings);
@ -39,26 +62,4 @@ public static class SchemaExporter
return schema;
}
}
public static void Main(string[] args)
{
const string folderName = "Schemas";
Directory.CreateDirectory(folderName);
Console.WriteLine("Schema Generator: We're winning!");
var settings = new JsonSchemaGeneratorSettings
{
IgnoreObsoleteProperties = true,
};
Console.WriteLine("Outputting Body Schema");
var bodySchema = new Schema<PlanetConfig>("Celestial Body Schema", "body_schema", settings);
bodySchema.Output();
Console.WriteLine("Outputting Star System Schema");
var systemSchema = new Schema<StarSystemConfig>("Star System Schema", "star_system_schema", settings);
systemSchema.Output();
Console.WriteLine("Outputting Translation Schema");
var translationSchema = new Schema<TranslationConfig>("Translation Schema", "translation_schema", settings);
translationSchema.Output();
Console.WriteLine("Done!");
}
}

View File

@ -22,7 +22,6 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Newtonsoft.Json.Schema" Version="3.0.14" />
<PackageReference Include="NJsonSchema" Version="10.7.1" />
<PackageReference Include="OuterWildsGameLibs" Version="1.1.12.168" IncludeAssets="compile" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />