/
main.go
98 lines (91 loc) · 3.31 KB
/
main.go
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
package main
import (
"bytes"
_ "embed"
"go/format"
"log"
"os"
"strings"
"text/template"
"unicode"
)
type EnumProperty struct {
Name string
TrimPrefix bool
Values []string
}
var EnumProperties = []EnumProperty{
{Name: "AttachFace", Values: []string{"floor", "wall", "ceiling"}},
{Name: "BambooLeaves", Values: []string{"none", "small", "large"}},
{Name: "BedPart", Values: []string{"head", "foot"}},
{Name: "BellAttachType", Values: []string{"floor", "ceiling", "single_wall", "double_wall"}},
{Name: "ChestType", Values: []string{"single", "left", "right"}},
{Name: "ComparatorMode", Values: []string{"compare", "subtract"}},
{Name: "Direction", TrimPrefix: true, Values: []string{"down", "up", "north", "south", "west", "east"}},
{Name: "Axis", TrimPrefix: true, Values: []string{"x", "y", "z"}},
{Name: "DoorHingeSide", Values: []string{"left", "right"}},
{Name: "DoubleBlockHalf", Values: []string{"upper", "lower"}},
{Name: "DripstoneThickness", Values: []string{"tip_merge", "tip", "frustum", "middle", "base"}},
{Name: "Half", TrimPrefix: true, Values: []string{"top", "bottom"}},
{Name: "NoteBlockInstrument", Values: []string{
"harp", "basedrum", "snare", "hat", "bass", "flute", "bell",
"guitar", "chime", "xylophone", "iron_xylophone", "cow_bell",
"didgeridoo", "bit", "banjo", "pling", "zombie", "skeleton",
"creeper", "dragon", "wither_skeleton", "piglin", "custom_head",
}},
{Name: "PistonType", Values: []string{"normal", "sticky"}},
{Name: "RailShape", Values: []string{
"north_south", "east_west",
"ascending_east", "ascending_west", "ascending_north", "ascending_south",
"south_east", "south_west", "north_west", "north_east",
}},
{Name: "RedstoneSide", Values: []string{"up", "side", "none"}},
{Name: "SculkSensorPhase", Values: []string{"inactive", "active", "cooldown"}},
{Name: "SlabType", Values: []string{"top", "bottom", "double"}},
{Name: "StairsShape", Values: []string{"straight", "inner_left", "inner_right", "outer_left", "outer_right"}},
{Name: "StructureMode", Values: []string{"save", "load", "corner", "data"}},
{Name: "Tilt", Values: []string{"none", "unstable", "partial", "full"}},
{Name: "WallSide", Values: []string{"none", "low", "tall"}},
{Name: "FrontAndTop", TrimPrefix: true, Values: []string{
"down_east", "down_north", "down_south", "down_west",
"up_east", "up_north", "up_south", "up_west",
"west_up", "east_up", "north_up", "south_up",
}},
}
//go:embed properties_enum.go.tmpl
var tempSource string
func main() {
var source bytes.Buffer
err := template.Must(template.
New("properties_enum").
Funcs(template.FuncMap{
"UpperTheFirst": UpperTheFirst,
"ToLower": strings.ToLower,
"Generator": func() string { return "generator/properties/main.go" },
}).
Parse(tempSource)).
Execute(&source, EnumProperties)
if err != nil {
log.Panic(err)
}
formattedSource, err := format.Source(source.Bytes())
if err != nil {
log.Panic(err)
}
err = os.WriteFile("properties_enum.go", formattedSource, 0o666)
if err != nil {
log.Panic(err)
}
log.Print("Generated properties_enum.go")
}
func UpperTheFirst(word string) string {
var sb strings.Builder
for _, word := range strings.Split(word, "_") {
runes := []rune(word)
if len(runes) > 0 {
runes[0] = unicode.ToUpper(runes[0])
}
sb.WriteString(string(runes))
}
return sb.String()
}