Initial Code

This commit is contained in:
Exil Productions
2025-11-11 03:10:52 +01:00
commit 74e53205f4
21 changed files with 2039 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace VMM.ModRegistry.Settings
{
public interface ISettingsElement
{
string Name { get; set; }
object GetValue();
void SetValue(object value);
}
}

View File

@@ -0,0 +1,24 @@
namespace VMM.ModRegistry.Settings
{
public class ModSettings
{
private readonly List<ISettingsElement> settings = new();
public void AddSetting(ISettingsElement newSetting)
{
settings.Add(newSetting);
}
public T GetSetting<T>(string name) where T : class, ISettingsElement
{
foreach (var setting in settings)
{
if(setting.Name == name && setting is T typed)
return typed;
}
return null;
}
public IEnumerable<ISettingsElement> GetAllSettings() => settings;
}
}

View File

@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Text;
using VMM.ModRegistry.Settings;
namespace VMM.ModRegistry.Settings
{
public abstract class SettingsElement<T> : ISettingsElement
{
public string Name { get; set; }
public T Value { get; set; }
public Action<T> OnChanged { get; set; }
public object GetValue() => Value;
public void SetValue(object value)
{
if (value is T typedValue)
{
Value = typedValue;
OnChanged?.Invoke(typedValue);
}
else
{
throw new InvalidCastException($"Invalid value type. Expected {typeof(T)}, got {value?.GetType()}");
}
}
}
}

View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace VMM.ModRegistry.Settings.Types
{
public class SliderSetting : SettingsElement<float>
{
public float Min { get; set; }
public float Max { get; set; }
}
}

View File

@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace VMM.ModRegistry.Settings.Types
{
public class ToggleSetting : SettingsElement<bool>
{
}
}