mirror of
https://github.com/kwsch/NHSE.git
synced 2026-07-18 16:21:41 -05:00
Allow mutating the player house item (door, etc)
This commit is contained in:
parent
5f7585ca0f
commit
7c7a4fe86f
|
|
@ -1,8 +1,10 @@
|
|||
using System.Runtime.InteropServices;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace NHSE.Core
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, Size = SIZE, Pack = 1)]
|
||||
[TypeConverter(typeof(ValueTypeTypeConverter))]
|
||||
public struct GSaveItemName
|
||||
{
|
||||
public const int SIZE = 0x08;
|
||||
|
|
@ -17,5 +19,7 @@ public struct GSaveItemName
|
|||
public bool Equals(GSaveItemName obj) => obj.UniqueID == UniqueID && obj.SystemParam == SystemParam && obj.AdditionalParam == AdditionalParam;
|
||||
public static bool operator ==(GSaveItemName left, GSaveItemName right) => left.Equals(right);
|
||||
public static bool operator !=(GSaveItemName left, GSaveItemName right) => !(left == right);
|
||||
|
||||
public override string ToString() => UniqueID.ToString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
26
NHSE.Core/Structures/Misc/ValueTypeTypeConverter.cs
Normal file
26
NHSE.Core/Structures/Misc/ValueTypeTypeConverter.cs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace NHSE.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Used for allowing a struct to be mutated in a PropertyGrid.
|
||||
/// </summary>
|
||||
public class ValueTypeTypeConverter : ExpandableObjectConverter
|
||||
{
|
||||
public override bool GetCreateInstanceSupported(ITypeDescriptorContext context) => true;
|
||||
|
||||
public override object CreateInstance(ITypeDescriptorContext context, IDictionary propertyValues)
|
||||
{
|
||||
object boxed = context.PropertyDescriptor.GetValue(context.Instance);
|
||||
foreach (DictionaryEntry entry in propertyValues)
|
||||
{
|
||||
var pi = context.PropertyDescriptor.PropertyType.GetProperty(entry.Key.ToString());
|
||||
if (pi?.CanWrite == true)
|
||||
pi.SetValue(boxed, Convert.ChangeType(entry.Value, pi.PropertyType), null);
|
||||
}
|
||||
return boxed;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user