rbxcompiler/cmd/rbxcompiler/rbxcompiler.go

97 lines
2.0 KiB
Go

package main
import (
"bytes"
"flag"
"fmt"
"git.itzana.me/itzaname/go-roblox"
"git.itzana.me/itzaname/rbxcompiler/internal/rbxbuilder"
"os"
)
var script = flag.Bool("script", false, "If the target is a script.")
var doUpload = flag.Bool("upload", false, "If the model should be uploaded.")
var output = flag.String("output", "d", "Output path.")
var input = flag.String("input", "", "Input path.")
var assetId = flag.Int("asset", 0, "Upload asset ID")
var groupId = flag.Int("group", 0, "Group ID")
var doGenerate = flag.Bool("generate", false, "If a place file should be dumped")
func build() {
settings := &rbxbuilder.BuildSettings{
Source: *input,
Output: *output,
}
buffer := &bytes.Buffer{}
if *doUpload {
settings.Writer = buffer
}
if *script {
if err := rbxbuilder.BuildScript(settings); err != nil {
fmt.Printf("Failed to build script: %s\n", err)
os.Exit(1)
return
}
} else {
if err := rbxbuilder.BuildPlace(settings); err != nil {
fmt.Printf("Failed to build place: %s\n", err)
os.Exit(1)
return
}
}
if *doUpload {
rbx, err := roblox.New(os.Getenv("RBXCOOKIE"))
if err != nil {
fmt.Printf("Failed to start roblox api client: %s\n", err)
os.Exit(1)
return
}
fmt.Printf("Logged in as %s...\n", rbx.Username)
fmt.Printf("Uploading file to roblox...\n")
resp, err := rbx.CreateAsset(&roblox.AssetUploadOptions{
AssetID: *assetId,
Group: *groupId,
}, buffer)
if err != nil {
fmt.Printf("Failed to upload place: %s\n", err)
os.Exit(1)
return
}
fmt.Printf("Uploaded ID %d VERSION %d\n", resp.AssetID, resp.AssetVersionID)
}
fmt.Println("Complete!")
}
func generate() {
if *script {
fmt.Println("Model not supported for generation.")
os.Exit(2)
}
if err := rbxbuilder.DumpPlace(&rbxbuilder.DumpSettings{
Source: *input,
Output: *output,
}); err != nil {
fmt.Printf("Failed to dump place file to disk: %s\n", err)
os.Exit(2)
}
fmt.Println("Complete!")
}
func main() {
flag.Parse()
if *doGenerate {
generate()
} else {
build()
}
}