-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathKV3Object.cs
77 lines (64 loc) · 1.73 KB
/
KV3Object.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ValveKeyValue;
namespace KVSurfaceUpdater
{
internal class KV3Object
{
public static string Prefix = "";
public string Name { get; set; }
public KV3Object(KVObject sourceObject)
{
SetupWithKVObject(sourceObject);
}
protected virtual void SetupWithKVObject(KVObject sourceObject)
{
}
protected static float TryParseFloatOrDefault(KVValue? value)
{
if(value != null)
{
if (float.TryParse((string)value, out float val))
{
return val;
}
}
return 0f;
}
protected static float FloatOrDefault(KVValue? value)
{
return value == null ? 0f : (float)value;
}
protected static string StringOrDefault(KVValue? value)
{
return value == null ? "" : (string)value;
}
protected static float[] GetFloatArray(string values)
{
var splitValues = values.Split(",");
float[] floats = new float[splitValues.Length];
for (int i = 0; i < splitValues.Length; i++)
{
floats[i] = float.Parse(splitValues[i]);
}
return floats;
}
protected static string ArrayOrNull(IEnumerable<string> input)
{
if(input == null || input.Count() == 0)
{
return "null";
}
else
{
return @$"
[
{string.Join("\n", input)}
]";
}
}
}
}