Command processing

This commit is contained in:
itzaname 2020-09-29 18:25:53 -04:00
parent 7c630474ef
commit 478b907071
5 changed files with 89 additions and 12 deletions

View File

@ -1,18 +1,88 @@
package main
import (
"bytes"
"ci.itzana.me/itzaname/go-roblox"
"ci.itzana.me/itzaname/rbxcompiler/internal/rbxbuilder"
"flag"
"fmt"
"os"
)
func main() {
/*fmt.Println(rbxbuilder.NewPlaceDump(&rbxbuilder.DumpSettings{
Source: "surf.rbxlx",
Output: "source",
}))*/
var isModel = flag.Bool("model", false, "If the target is a model.")
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")
fmt.Println(rbxbuilder.NewPlaceBuilder(&rbxbuilder.BuildSettings{
Source: "source",
Output: "build.rbxlx",
}))
func build() {
settings := &rbxbuilder.BuildSettings{
Source: *input,
Output: *output,
}
buffer := &bytes.Buffer{}
if *doUpload {
settings.Writer = buffer
}
if err := rbxbuilder.BuildPlace(settings); err != nil {
fmt.Println("Failed to start build place.")
os.Exit(1)
return
}
if *doUpload {
rbx, err := roblox.New(os.Getenv("RBXCOOKIE"))
if err != nil {
fmt.Println("Failed to start roblox api client.")
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.Println("Failed to upload place.")
os.Exit(1)
return
}
fmt.Printf("Uploaded ID %d VERSION %d\n", resp.AssetID, resp.AssetVersionID)
}
fmt.Println("Complete!")
}
func generate() {
if *isModel {
fmt.Println("Model not supported for generation.")
os.Exit(2)
}
if err := rbxbuilder.DumpPlace(&rbxbuilder.DumpSettings{
Source: *input,
Output: *output,
}); err != nil {
fmt.Println("Failed to dump place file to disk.")
os.Exit(2)
}
fmt.Println("Complete!")
}
func main() {
flag.Parse()
if *doGenerate {
generate()
} else {
build()
}
}

1
go.mod
View File

@ -3,6 +3,7 @@ module ci.itzana.me/itzaname/rbxcompiler
go 1.15
require (
ci.itzana.me/itzaname/go-roblox v0.0.0-20200922163025-9652a2630ec6
ci.itzana.me/itzaname/rbxfile v0.0.0-20200929185118-23ef9783a53e
github.com/google/uuid v1.1.2
)

2
go.sum
View File

@ -1,3 +1,5 @@
ci.itzana.me/itzaname/go-roblox v0.0.0-20200922163025-9652a2630ec6 h1:baGWHDYDYo7Q1P6UYIGW+4zm8YKBFILeOY7ExIADQoM=
ci.itzana.me/itzaname/go-roblox v0.0.0-20200922163025-9652a2630ec6/go.mod h1:ttaofy5pZVEozl+/s5k4y53dk3uorpHUtLWya0VIpZ0=
ci.itzana.me/itzaname/rbxapi v0.1.0 h1:8tMoEvelXgxGJd71BXGBpGn/K18mWaWQvCsQqY7lnn4=
ci.itzana.me/itzaname/rbxapi v0.1.0/go.mod h1:CRPbR/U4RqL4rqSGsEaYYr9wld3ctP+vClwgj/wGLsE=
ci.itzana.me/itzaname/rbxfile v0.0.0-20200929185118-23ef9783a53e h1:xLqVw9gkdqKgywmEccJsXIJDM4bDgJ2g86ACe2iA7rA=

View File

@ -146,6 +146,10 @@ func (b PlaceBuilder) Build() error {
return err
}
if b.Options.Writer != nil {
return xml.Serialize(b.Options.Writer, nil, b.root)
}
file, err := os.OpenFile(b.Options.Output, os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return fmt.Errorf("failed to open output file")

View File

@ -15,7 +15,7 @@ type DumpSettings struct {
type BuildSettings struct {
Source string
Output string
Writer *io.Writer
Writer io.Writer
}
type Manifest struct {
@ -28,13 +28,13 @@ type Script struct {
Class string
}
func NewPlaceDump(options *DumpSettings) error {
func DumpPlace(options *DumpSettings) error {
return PlaceDumper{
Options: options,
}.Dump()
}
func NewPlaceBuilder(options *BuildSettings) error {
func BuildPlace(options *BuildSettings) error {
return PlaceBuilder{
Options: options,
}.Build()