Skip to content

Commit

Permalink
Add skeleton for project exporting
Browse files Browse the repository at this point in the history
  • Loading branch information
SirLich committed Aug 9, 2021
1 parent 8f5ef3b commit e724db9
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
40 changes: 40 additions & 0 deletions src/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func RunProfile(profileName string) {
project := LoadConfig()
// The first arg specifies the profile of the manifest used
profile := project.Profiles[profileName]

if profile.Unsafe {
Logger.Info("Warning! Profile flagged as unsafe. Exercise caution!")
}
Expand All @@ -65,10 +66,49 @@ func RunProfile(profileName string) {
os.RemoveAll("build")
os.Rename(".regolith/tmp", "build")
Logger.Debug("Done in ", time.Since(start))

// copy the build to the target directory
Logger.Info("Copying build to target directory")
start = time.Now()
ExportProject(profile, project.Name)
Logger.Debug("Done in ", time.Since(start))

//Done!
Logger.Info(color.GreenString("Finished"))
}

func GetExportPaths(export_target ExportTarget, name string) (string, string) {
Logger.Debug(export_target)

if export_target.Target == "development" {
com_mojang := FindMojangDir()
return com_mojang + "/development_behavior_packs/" + name + "_bp", com_mojang + "/development_resource_packs/" + name + "_rp"
}

// Throw fatal error that export target isn't valid
Logger.Fatal("Export target not valid")
return "", ""
}

func ExportProject(profile Profile, name string) {
var err error
export_target := profile.ExportTarget
bp_path, rp_path := GetExportPaths(export_target, name)

Logger.Info("Exporting project to ", bp_path)
Logger.Info("Exporting project to ", rp_path)

err = copy.Copy("build/BP/", bp_path, copy.Options{PreserveTimes: false, Sync: false})
if err != nil {
Logger.Fatal(color.RedString("Couldn't copy BP files to %s", bp_path), err)
}

err = copy.Copy("build/RP/", rp_path, copy.Options{PreserveTimes: false, Sync: false})
if err != nil {
Logger.Fatal(color.RedString("Couldn't copy RP files to %s", rp_path), err)
}
}

// Runs the filter by selecting the correct filter type and running it
func RunFilter(filter Filter, absoluteLocation string) {
Logger.Infof("Running filter '%s'", filter.Name)
Expand Down
15 changes: 13 additions & 2 deletions src/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ import (
const ManifestName = "regolith.json"

type Project struct {
Name string `json:"name"`
Profiles map[string]Profile `json:"profiles"`
}

type Profile struct {
Unsafe bool `json:"unsafe"`
Filters []Filter `json:"filters"`
Unsafe bool `json:"unsafe"`
Filters []Filter `json:"filters"`
ExportTarget ExportTarget `json:"export"`
}

type Filter struct {
Name string `json:"name"`
Location string `json:"location"`
Expand All @@ -28,6 +31,14 @@ type Filter struct {
Filter string `json:"filter"`
}

type ExportTarget struct {
Target string `json:"target"`
ComMojangPath string `json:"com_mojang_path"`
WorldName string `json:"world_name"`
WorldPath string `json:"world_path"`
Path string `json:"path"`
}

func IsConfigExists() bool {
info, err := os.Stat(ManifestName)
if os.IsNotExist(err) {
Expand Down

0 comments on commit e724db9

Please sign in to comment.