Skip to content

Commit

Permalink
Added 'world' and 'none' export targets for issue #14
Browse files Browse the repository at this point in the history
  • Loading branch information
Nusiq committed Sep 15, 2021
1 parent 2af18d3 commit 58d2dab
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 18 deletions.
13 changes: 12 additions & 1 deletion src/file_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package src

import (
"encoding/json"
"errors"
"fmt"
"io/fs"
"io/ioutil"
"os"
"path/filepath"
)

Expand Down Expand Up @@ -101,7 +103,16 @@ func listFiles(path string) ([]string, error) {
// an error in opposite case.
func checkDeletionSafety(path string, removableFiles []string) error {
i := 0 // current index on the removableFiles list to check
err := filepath.WalkDir(path,
stats, err := os.Stat("path")
if err != nil {
if os.IsNotExist(err) {
return nil // directory doesn't exist there is nothing to check
}
return err // other error
} else if !stats.IsDir() {
return errors.New("output path is a file")
}
err = filepath.WalkDir(path,
func(s string, d fs.DirEntry, e error) error {
if e != nil {
return e
Expand Down
36 changes: 27 additions & 9 deletions src/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,15 @@ func RunProfile(profileName string) error {
Logger.Debug("Done in ", time.Since(start))

// copy the build to the target directory
Logger.Info("Copying build to target directory")
start = time.Now()
err = ExportProject(profile, project.Name)
if err != nil {
return wrapError("Exporting project failed", err)
if profile.ExportTarget.Target != "none" {
Logger.Info("Copying build to target directory")
start = time.Now()
err = ExportProject(profile, project.Name)
if err != nil {
return wrapError("Exporting project failed", err)
}
Logger.Debug("Done in ", time.Since(start))
}
Logger.Debug("Done in ", time.Since(start))
Logger.Info(color.GreenString("Finished"))
return nil
}
Expand All @@ -144,13 +146,29 @@ func GetExportPaths(exportTarget ExportTarget, name string) (bpPath string, rpPa
// I for example always name my packs "0".
bpPath = comMojang + "/development_behavior_packs/" + name + "_bp"
rpPath = comMojang + "/development_resource_packs/" + name + "_rp"
return
} else if exportTarget.Target == "exact" {
bpPath = exportTarget.BpPath
rpPath = exportTarget.RpPath
return
} else if exportTarget.Target == "world" {
if exportTarget.WorldPath != "" {
if exportTarget.WorldName != "" {
Logger.Fatal("Using both \"worldName\" and \"worldPath\" is not allowed.")
}
bpPath = filepath.Join(exportTarget.WorldPath, "behavior_packs", name+"_bp")
rpPath = filepath.Join(exportTarget.WorldPath, "resource_packs", name+"_rp")
} else if exportTarget.WorldName != "" {
for _, world := range ListWorlds(FindMojangDir()) {
if world.Name == exportTarget.WorldName {
bpPath = filepath.Join(world.Path, "behavior_packs", name+"_bp")
rpPath = filepath.Join(world.Path, "resource_packs", name+"_rp")
}
}
} else {
err = errors.New("The \"world\" export target requires either a \"worldName\" or \"worldPath\" property")
}
} else {
err = errors.New(fmt.Sprintf("Export '%s' target not valid", exportTarget.Target))
}
err = errors.New(fmt.Sprintf("Export '%s' target not valid", exportTarget.Target))
return
}

Expand Down
4 changes: 2 additions & 2 deletions src/minecraft_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
)

type World struct {
Id string `json:"id"`
Name string `json:"name"`
Id string `json:"id"` // The name of the world directory
Name string `json:"name"` // The name of the world in levelname.txt
Path string `json:"path"`
}

Expand Down
12 changes: 6 additions & 6 deletions src/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ type Filter struct {
}

type ExportTarget struct {
Target string `json:"target"` // The mode of exporting. "develop" or "exact"
RpPath string `json:"rpPath"` // Relative or absolute path to resource pack for "exact" export target
BpPath string `json:"bpPath"` // Relative or absolute path to resource pack for "exact" export target
Target string `json:"target"` // The mode of exporting. "develop" or "exact"
RpPath string `json:"rpPath"` // Relative or absolute path to resource pack for "exact" export target
BpPath string `json:"bpPath"` // Relative or absolute path to resource pack for "exact" export target
WorldName string `json:"worldName"`
WorldPath string `json:"worldPath"`
// ComMojangPath string `json:"comMojangPath"`
// NOT USED, DISABLED FOR NOW.
// Clean bool `json:"clean"`
// ComMojangPath string `json:"comMojangPath"`
// WorldName string `json:"worldName"`
// WorldPath string `json:"worldPath"`
// Path string `json:"path"`
}

Expand Down

0 comments on commit 58d2dab

Please sign in to comment.