package weave import ( "tangled.org/cosmeak.tngl.sh/weave/datapack" "tangled.org/cosmeak.tngl.sh/weave/internal/generator" ) type Weaver struct { datapack datapack.Datapack namespace string iconPath string // Icon path relative to the root of the project. Default : ./pack.png features []generator.Feature } func MkDatapack(name string, description string, minFormat int, maxFormat int, flags []string) Weaver { // sanitize datapack name into a namespace rawNamespace := []rune{} for _, r := range name { switch { case r >= 'a' && r <= 'z': rawNamespace = append(rawNamespace, r) case r >= 'A' && r <= 'Z': rawNamespace = append(rawNamespace, r+32) // to lowercase case r >= '0' && r <= '9': rawNamespace = append(rawNamespace, r) case r == '_' || r == '-': rawNamespace = append(rawNamespace, '_') case r == ' ': rawNamespace = append(rawNamespace, '_') } } namespace := "" if len(rawNamespace) == 0 { namespace = "my datapack" } else { namespace = string(rawNamespace) } // construct the weaver return Weaver{ datapack: datapack.MkDatapack( name, description, minFormat, maxFormat, flags, ), namespace: namespace, iconPath: "./pack.png", } } func (w Weaver) Generate(output string) error { features := append(w.Features(), w.datapack) return generator.Generate(w.namespace, features, output) } func (w Weaver) Features() []generator.Feature { features := make([]generator.Feature, len(w.features)) copy(features, w.features) return features } func (w Weaver) AddFeature(feature generator.Feature) Weaver { w.features = append(w.features, feature) return w }