-
Notifications
You must be signed in to change notification settings - Fork 0
/
IntSetting.cs
39 lines (30 loc) · 996 Bytes
/
IntSetting.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using Newtonsoft.Json.Linq;
using Zenvin.Settings.Framework.Serialization;
namespace Zenvin.Settings.Framework {
public class IntSetting : SettingBase<int>, ISerializable<JObject>, ISerializable<ValuePacket> {
protected override bool TryGetOverrideValue (StringValuePair[] values, out int value) {
var text = values[0].Value?.Trim ();
if (string.IsNullOrEmpty (text)) {
value = default;
return false;
}
return int.TryParse (text, out value);
}
void ISerializable<JObject>.OnDeserialize (JObject value) {
if (value.TryGetValue ("value", out JToken token)) {
SetValue ((int)token);
}
}
void ISerializable<ValuePacket>.OnDeserialize (ValuePacket value) {
if (value.TryRead ("value", out int val)) {
SetValue (val);
}
}
void ISerializable<JObject>.OnSerialize (JObject value) {
value.Add ("value", CurrentValue);
}
void ISerializable<ValuePacket>.OnSerialize (ValuePacket value) {
value.Write ("value", CurrentValue);
}
}
}