From 28d2573000c1f24077bc3d1cee2faa7ea09d76b4 Mon Sep 17 00:00:00 2001 From: cosmeak Date: Wed, 14 Jan 2026 09:58:17 +0100 Subject: [PATCH] feat: functions --- function/emitter.go | 14 ++++++++++++++ function/function.go | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 function/emitter.go create mode 100644 function/function.go 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 +} -- 2.51.2