Skip to content

Commit 1f8bd02

Browse files
committed
Changed: Split native mod config schema models into Schema subnamespace
- Move 7 schema models plus internal Keys/JsonNodeExtensions out of ModConfigSchema.cs into Native/Schema/, shrinking it 742 to 68 lines - Rename moved types to prefix-free names (Configuration, Property, Slider, FilePicker, FolderPicker, Enum, EnumMember) in the new Native.Schema namespace - Point ModConfigSchema and ConfigTypeEmitter at the moved types via Schema.* qualification; all other callers unchanged The renamed types were public but unused outside Launcher.Lib's Native folder, so no caller migration is needed.
1 parent 756a7a8 commit 1f8bd02

11 files changed

Lines changed: 719 additions & 692 deletions

File tree

‎source/Reloaded.Mod.Launcher.Lib/Models/Model/Configuration/Native/ConfigTypeEmitter.cs‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static class ConfigTypeEmitter
3535
/// Thrown when a property's Type is unknown, or a control does not match
3636
/// the property type.
3737
/// </exception>
38-
public static ConfigurableBase CreateInstance(ConfigSchemaConfiguration configuration, string cacheKey)
38+
public static ConfigurableBase CreateInstance(Schema.Configuration configuration, string cacheKey)
3939
{
4040
Type type;
4141
lock (BuildLock)
@@ -50,7 +50,7 @@ public static ConfigurableBase CreateInstance(ConfigSchemaConfiguration configur
5050
return (ConfigurableBase)Activator.CreateInstance(type)!;
5151
}
5252

53-
private static Type BuildType(ConfigSchemaConfiguration configuration, string cacheKey)
53+
private static Type BuildType(Schema.Configuration configuration, string cacheKey)
5454
{
5555
var module = GetModule();
5656
var typeBuilder = module.DefineType($"NativeModConfig_{Interlocked.Increment(ref _typeCounter)}_{MakeIdentifier(cacheKey)}", TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.Sealed, typeof(ConfigurableBase));
@@ -114,43 +114,43 @@ private static Type BuildType(ConfigSchemaConfiguration configuration, string ca
114114
/// <summary>
115115
/// Declared enums plus one per property with inline <c>Values</c>.
116116
/// </summary>
117-
private static IEnumerable<ConfigSchemaEnum> CollectEnums(ConfigSchemaConfiguration configuration)
117+
private static IEnumerable<Schema.Enum> CollectEnums(Schema.Configuration configuration)
118118
{
119119
foreach (var schemaEnum in configuration.Enums)
120120
yield return schemaEnum;
121121

122122
foreach (var property in configuration.Properties)
123123
{
124124
if (property.Values.Count > 0)
125-
yield return new ConfigSchemaEnum() { Name = property.Name, Members = property.Values };
125+
yield return new Schema.Enum() { Name = property.Name, Members = property.Values };
126126
}
127127
}
128128

129-
private static (Type propertyType, object? defaultValue) ResolveTypeAndDefault(ConfigSchemaProperty property, Dictionary<string, Type> enums)
129+
private static (Type propertyType, object? defaultValue) ResolveTypeAndDefault(Schema.Property property, Dictionary<string, Type> enums)
130130
{
131131
switch (property.Type)
132132
{
133-
case ConfigSchemaProperty.SupportedTypes.Bool:
133+
case Schema.Property.SupportedTypes.Bool:
134134
return (typeof(bool), property.DefaultValue is bool b ? b : false);
135135

136-
case ConfigSchemaProperty.SupportedTypes.Int:
136+
case Schema.Property.SupportedTypes.Int:
137137
return (typeof(int), property.DefaultValue == null ? 0 : Convert.ToInt32(property.DefaultValue));
138138

139-
case ConfigSchemaProperty.SupportedTypes.Float:
139+
case Schema.Property.SupportedTypes.Float:
140140
return (typeof(float), property.DefaultValue == null ? 0.0f : Convert.ToSingle(property.DefaultValue));
141141

142-
case ConfigSchemaProperty.SupportedTypes.Double:
142+
case Schema.Property.SupportedTypes.Double:
143143
return (typeof(double), property.DefaultValue == null ? 0.0 : Convert.ToDouble(property.DefaultValue));
144144

145-
case ConfigSchemaProperty.SupportedTypes.String:
145+
case Schema.Property.SupportedTypes.String:
146146
return (typeof(string), property.DefaultValue?.ToString());
147147

148148
default:
149149
if (!enums.TryGetValue(property.Type, out var enumType))
150150
{
151151
var hint = string.Equals(property.Type, "enum", StringComparison.OrdinalIgnoreCase)
152-
? $"Inline enums need a '{Keys.Values}' array on the property."
153-
: $"Declare an enum with this name under '{Keys.Enums}'.";
152+
? $"Inline enums need a '{Schema.Keys.Values}' array on the property."
153+
: $"Declare an enum with this name under '{Schema.Keys.Enums}'.";
154154

155155
throw new InvalidOperationException($"Property '{property.Name}' has unknown Type '{property.Type}'. {hint}");
156156
}
@@ -159,7 +159,7 @@ private static (Type propertyType, object? defaultValue) ResolveTypeAndDefault(C
159159
}
160160
}
161161

162-
private static object GetEnumDefault(ConfigSchemaProperty property, Type enumType)
162+
private static object GetEnumDefault(Schema.Property property, Type enumType)
163163
{
164164
if (property.DefaultValue is string memberName)
165165
{
@@ -214,7 +214,7 @@ private static void EmitFieldInit(ILGenerator il, FieldBuilder field, Type prope
214214
il.Emit(OpCodes.Stfld, field);
215215
}
216216

217-
private static IEnumerable<CustomAttributeBuilder> BuildAttributes(ConfigSchemaProperty property, Type propertyType, object? defaultValue)
217+
private static IEnumerable<CustomAttributeBuilder> BuildAttributes(Schema.Property property, Type propertyType, object? defaultValue)
218218
{
219219
if (property.DisplayName != null)
220220
yield return new CustomAttributeBuilder(GetCtor(typeof(DisplayNameAttribute), 1), new object[] { property.DisplayName });

0 commit comments

Comments
 (0)