diff --git a/function/emitter.go b/function/emitter.go new file mode 100644 index 0000000..1fd85b9 --- /dev/null +++ b/function/emitter.go @@ -0,0 +1,14 @@ +package function + +import ( + "strings" + "tangled.org/cosmeak.tngl.sh/weave/internal/generator" +) + +func (f Function) Emit()(generator.File, error) { + content := strings.Join(f.commands, "/n") + return generator.File{ + Path: "data/%namespace%/function/" + f.name + ".mcfunction", + Content: []byte(content), + }, nil +} diff --git a/function/function.go b/function/function.go new file mode 100644 index 0000000..69cb800 --- /dev/null +++ b/function/function.go @@ -0,0 +1,37 @@ +package function + +type Function struct { + name string + commands []string +} + +func MkFunction(name string, commands ...string) Function { + return Function{ + name: name, + commands: commands, + } +} + +func (f Function) Type() string { + return "function" +} + +func (f Function) Name() string { + return f.name +} + +func (f Function) Commands() []string { + commands := make([]string, len(f.commands)) + copy(commands, f.commands) + return commands +} + +func (f Function) AddCommand(command string) Function { + f.commands = append(f.commands, command) + return f +} + +func (f Function) AddCommands(commands ...string) Function { + f.commands = append(f.commands, commands...) + return f +}