Elin Decompiled Documentation EA 23.315 Nightly
Loading...
Searching...
No Matches
ElinGameIOPropertyAttribute Class Reference
Inheritance diagram for ElinGameIOPropertyAttribute:
ElinGameIOEventAttribute ElinEventBaseAttribute

Public Member Functions

 ElinGameIOPropertyAttribute (string chunkName)
 
override void Register (PropertyInfo property)
 
- Public Member Functions inherited from ElinEventBaseAttribute
virtual void Register (MethodInfo method)
 
virtual void Register (PropertyInfo property)
 

Properties

string ChunkName [get]
 

Static Private Member Functions

static Action< object > CreateSetterDelegate (MethodInfo method)
 
static void LoadGameIOProperty (GameIOContext context)
 
static void SaveGameIOProperty (GameIOContext context)
 

Static Private Attributes

static bool _registered
 
static readonly Dictionary< string,(PropertyInfo property, Func< object > getter, Action< object > setter)> _contextVars = new Dictionary<string, (PropertyInfo, Func<object>, Action<object>)>()
 

Detailed Description

Definition at line 9 of file ElinGameIOPropertyAttribute.cs.

Constructor & Destructor Documentation

◆ ElinGameIOPropertyAttribute()

ElinGameIOPropertyAttribute.ElinGameIOPropertyAttribute ( string  chunkName)
inline

Definition at line 17 of file ElinGameIOPropertyAttribute.cs.

18 {
19 ChunkName = chunkName;
20 }

References ChunkName.

Member Function Documentation

◆ CreateSetterDelegate()

static Action< object > ElinGameIOPropertyAttribute.CreateSetterDelegate ( MethodInfo  method)
inlinestaticprivate

Definition at line 41 of file ElinGameIOPropertyAttribute.cs.

42 {
43 Type parameterType = method.GetParameters()[0].ParameterType;
44 ParameterExpression parameterExpression = Expression.Parameter(typeof(object), "obj");
45 UnaryExpression arg = Expression.Convert(parameterExpression, parameterType);
46 return Expression.Lambda<Action<object>>(Expression.Call(method, arg), new ParameterExpression[1] { parameterExpression }).Compile();
47 }

Referenced by Register().

◆ LoadGameIOProperty()

static void ElinGameIOPropertyAttribute.LoadGameIOProperty ( GameIOContext  context)
inlinestaticprivate

Definition at line 49 of file ElinGameIOPropertyAttribute.cs.

50 {
51 if (!context.Load<Dictionary<string, object>>("context_vars", out var data))
52 {
53 data = new Dictionary<string, object>();
54 }
55 KeyValuePair<string, (PropertyInfo, Func<object>, Action<object>)>[] array = _contextVars.ToArray();
56 foreach (KeyValuePair<string, (PropertyInfo, Func<object>, Action<object>)> keyValuePair in array)
57 {
58 keyValuePair.Deconstruct(out var key, out var value);
59 (PropertyInfo, Func<object>, Action<object>) tuple = value;
60 string text = key;
61 var (propertyInfo, _, action) = tuple;
62 try
63 {
64 string key2 = propertyInfo.DeclaringType.FullName + ":" + text;
65 object valueOrDefault = data.GetValueOrDefault(key2);
66 action(valueOrDefault);
67 }
68 catch (Exception arg)
69 {
70 Debug.LogError($"#io failed to populate context var {text}\n{arg}");
71 _contextVars.Remove(text);
72 }
73 }
74 }
static readonly Dictionary< string,(PropertyInfo property, Func< object > getter, Action< object > setter)> _contextVars

References $, _contextVars, and Debug.

Referenced by Register().

◆ Register()

override void ElinGameIOPropertyAttribute.Register ( PropertyInfo  property)
inlinevirtual

Reimplemented from ElinEventBaseAttribute.

Definition at line 22 of file ElinGameIOPropertyAttribute.cs.

23 {
24 if (!_registered)
25 {
26 BaseModManager.SubscribeEvent<GameIOContext>("elin.game.post_load", LoadGameIOProperty);
27 BaseModManager.SubscribeEvent<GameIOContext>("elin.game.post_save", SaveGameIOProperty);
28 _registered = true;
29 }
30 MethodInfo getMethod = property.GetMethod;
31 MethodInfo setMethod = property.SetMethod;
32 if (!(getMethod == null) && !(setMethod == null) && setMethod.IsStatic)
33 {
34 Func<object> item = getMethod.CreateDelegate<Func<object>>();
35 Action<object> item2 = CreateSetterDelegate(setMethod);
36 Type declaringType = property.DeclaringType;
37 _contextVars[declaringType.FullName + ":" + ChunkName] = (property, item, item2);
38 }
39 }
static void SubscribeEvent(string eventId, Action< object > handler)
static void SaveGameIOProperty(GameIOContext context)
static Action< object > CreateSetterDelegate(MethodInfo method)
static void LoadGameIOProperty(GameIOContext context)

References _contextVars, _registered, ChunkName, CreateSetterDelegate(), item, LoadGameIOProperty(), SaveGameIOProperty(), and BaseModManager.SubscribeEvent().

◆ SaveGameIOProperty()

static void ElinGameIOPropertyAttribute.SaveGameIOProperty ( GameIOContext  context)
inlinestaticprivate

Definition at line 76 of file ElinGameIOPropertyAttribute.cs.

77 {
78 Dictionary<string, object> dictionary = new Dictionary<string, object>(StringComparer.Ordinal);
79 KeyValuePair<string, (PropertyInfo, Func<object>, Action<object>)>[] array = _contextVars.ToArray();
80 foreach (KeyValuePair<string, (PropertyInfo, Func<object>, Action<object>)> keyValuePair in array)
81 {
82 keyValuePair.Deconstruct(out var key, out var value);
83 (PropertyInfo, Func<object>, Action<object>) tuple = value;
84 string text = key;
85 var (propertyInfo, func, _) = tuple;
86 try
87 {
88 object value2 = func();
89 string key2 = propertyInfo.DeclaringType.FullName + ":" + text;
90 dictionary[key2] = value2;
91 }
92 catch (Exception arg)
93 {
94 Debug.LogError($"#io failed to save context var {text}\n{arg}");
95 _contextVars.Remove(text);
96 }
97 }
98 context.Save("context_vars", dictionary);
99 }

References $, _contextVars, and Debug.

Referenced by Register().

Member Data Documentation

◆ _contextVars

readonly Dictionary<string, (PropertyInfo property, Func<object> getter, Action<object> setter)> ElinGameIOPropertyAttribute._contextVars = new Dictionary<string, (PropertyInfo, Func<object>, Action<object>)>()
staticprivate

Definition at line 13 of file ElinGameIOPropertyAttribute.cs.

Referenced by LoadGameIOProperty(), Register(), and SaveGameIOProperty().

◆ _registered

bool ElinGameIOPropertyAttribute._registered
staticprivate

Definition at line 11 of file ElinGameIOPropertyAttribute.cs.

Referenced by Register().

Property Documentation

◆ ChunkName

string ElinGameIOPropertyAttribute.ChunkName
get

Definition at line 15 of file ElinGameIOPropertyAttribute.cs.

15{ get; }

Referenced by ElinGameIOPropertyAttribute(), and Register().


The documentation for this class was generated from the following file: