-
Notifications
You must be signed in to change notification settings - Fork 0
/
character.hsc
50 lines (45 loc) · 1.47 KB
/
character.hsc
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
mixin Object {
// We don't want to read ids from json, so let's annotate as such.
@no(json)
u32 id = -1;
// You can define custom functions for your data structures. By default they're implemented in c++.
// If you have c++ functions, a separate directory will be generated that will have partially generated code.
// You can fill up the spaces between the markers. Check out the output/src directory.
// The generator will keep your custom code if you regenerate.
func Initialize();
}
@comment('enums can have comments too')
enum Race {
Human = 2;
@comment('enum entries can have comments too')
Elf;
Dwarf;
Hobbit;
}
struct Character : Object {
string name;
Race race;
Armor armor;
Weapon weapon;
}
struct Armor : Object {
// We can use custom setters that do some validation, and getters that compute extra stuff
@field(set=custom)
s8 armorClass;
}
struct Weapon : Object {
@field(set=none)
u8 damageMin;
@field(set=none)
u8 damageMax;
// If we want to set multiple values together to ensure they're consistent, we can disable their setters and write
// a custom function.
// In this example we don't want this called from lua for some reason, so we annotate it with no(lua)
@no(lua)
func SetDamage(u8 min, u8 max);
// here's a function returning a uint8_t:
func GetDamage() -> u8;
// You can also define functions in lua:
@luaFunc
func GetAverageDamage() -> u8;
}