-
Notifications
You must be signed in to change notification settings - Fork 29
/
EntityDecoration.cs
102 lines (86 loc) · 2.94 KB
/
EntityDecoration.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System;
using CitizenFX.Core;
using CitizenFX.Core.Native;
using static CitizenFX.Core.Native.API;
namespace FRFuel
{
public enum DecorationType
{
Float = 1,
Bool = 2,
Int = 3,
Time = 5
}
public static class EntityDecoration
{
internal static Type floatType = typeof(float);
internal static Type boolType = typeof(bool);
internal static Type intType = typeof(int);
public static bool ExistOn(Entity entity, string propertyName)
{
return DecorExistOn(entity.Handle, propertyName);
}
public static bool HasDecor(this Entity ent, string propertyName)
{
return ExistOn(ent, propertyName);
}
public static void RegisterProperty(string propertyName, DecorationType type)
{
DecorRegister(propertyName, (int)type);
}
public static void Set(Entity entity, string propertyName, float floatValue)
{
DecorSetFloat(entity.Handle, propertyName, floatValue);
}
public static void Set(Entity entity, string propertyName, int intValue)
{
DecorSetInt(entity.Handle, propertyName, intValue);
}
public static void Set(Entity entity, string propertyName, bool boolValue)
{
DecorSetBool(entity.Handle, propertyName, boolValue);
}
public static void SetDecor(this Entity ent, string propertyName, float value)
{
Set(ent, propertyName, value);
}
public static void SetDecor(this Entity ent, string propertyName, int value)
{
Set(ent, propertyName, value);
}
public static void SetDecor(this Entity ent, string propertyName, bool value)
{
Set(ent, propertyName, value);
}
public static T Get<T>(Entity entity, string propertyName)
{
if (!ExistOn(entity, propertyName))
{
throw new EntityDecorationUnregisteredPropertyException();
}
Type genericType = typeof(T);
if (genericType == floatType)
{
return (T)(object)DecorGetFloat(entity.Handle, propertyName);
}
else if (genericType == intType)
{
return (T)(object)DecorGetInt(entity.Handle, propertyName);
}
else if (genericType == boolType)
{
return (T)(object)DecorGetBool(entity.Handle, propertyName);
}
else
{
throw new EntityDecorationUndefinedTypeException();
}
}
public static T GetDecor<T>(this Entity ent, string propertyName)
{
return Get<T>(ent, propertyName);
}
}
public class EntityDecorationUnregisteredPropertyException : Exception { }
public class EntityDecorationUndefinedTypeException : Exception { }
}