Skip to content

Commit

Permalink
Add support for new config type
Browse files Browse the repository at this point in the history
  • Loading branch information
SirLich committed Aug 28, 2021
1 parent eee381f commit ad68289
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 10 deletions.
Binary file removed docs/assets/images/homepage/.fast.png-autosave.kra
Binary file not shown.
Binary file not shown.
Binary file not shown.
18 changes: 17 additions & 1 deletion src/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,17 @@ func Setup() error {

// Copy the contents of the `regolith` folder to `.regolith/tmp`
Logger.Debug("Copying project files to .regolith/tmp")
err = copy.Copy("regolith", ".regolith/tmp", copy.Options{PreserveTimes: false, Sync: false})

err = copy.Copy(LoadConfig().Packs.BehaviorFolder, ".regolith/tmp/BP", copy.Options{PreserveTimes: false, Sync: false})
if err != nil {
return err
}

err = copy.Copy(LoadConfig().Packs.ResourceFolder, ".regolith/tmp/RP", copy.Options{PreserveTimes: false, Sync: false})
if err != nil {
return err
}

Logger.Debug("Setup done in ", time.Since(start))
return nil
}
Expand Down Expand Up @@ -128,6 +135,15 @@ func ExportProject(profile Profile, name string) {
exportTarget := profile.ExportTarget
bpPath, rpPath := GetExportPaths(exportTarget, name)

// Allow clearing output locations, before writing
// TODO Uncomment this. Is it safe? Can we send to recycle bin?
// if exportTarget.Clean {
// os.RemoveAll(bpPath")
// os.MkdirAll(bpPath", 0777)
// os.RemoveAll(rpPath")
// os.MkdirAll(rpPath", 0777)
// }

Logger.Info("Exporting project to ", bpPath)
Logger.Info("Exporting project to ", rpPath)

Expand Down
30 changes: 21 additions & 9 deletions src/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,20 @@ import (
"github.com/fatih/color"
)

const ManifestName = "regolith.json"
const ManifestName = "config.json"

// TODO implement the rest of the standard config spec
type Config struct {
Name string `json:"name"`
Author string `json:"author"`
Packs struct {
BehaviorFolder string `json:"behaviorPack"`
ResourceFolder string `json:"resourcePack"`
}
RegolithProject `json:"regolith"`
}

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

Expand All @@ -35,27 +45,29 @@ type Filter struct {
}

type ExportTarget struct {
Clean bool `json:"clean"`
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 {
func IsProjectConfigured() bool {
// TODO: Write a better system here, that checks all possible files.
info, err := os.Stat(ManifestName)
if os.IsNotExist(err) {
return false
}
return !info.IsDir()
}

func LoadConfig() Project {
func LoadConfig() Config {
file, err := ioutil.ReadFile(ManifestName)
if err != nil {
Logger.Fatalf("Couldn't find %s! Consider running 'regolith init'", ManifestName)
}
var result Project
var result Config
err = json.Unmarshal(file, &result)
if err != nil {
Logger.Fatal(fmt.Sprintf("Couldn't load %s: ", ManifestName), err)
Expand All @@ -66,14 +78,14 @@ func LoadConfig() Project {
func InitializeRegolithProject(isForced bool) bool {

// Do not attempt to initialize if project is already initialized (can be forced)
if !isForced && IsConfigExists() {
if !isForced && IsProjectConfigured() {
Logger.Errorf("Could not initialize Regolith project. File %s already exists.", ManifestName)
return false
} else {
Logger.Info("Initializing Regolith project...")

if isForced {
Logger.Warn("Warning: Initialization forced. Data may be lost.")
Logger.Warn("Initialization forced. Data may be lost.")
}

// Delete old configuration
Expand All @@ -92,7 +104,7 @@ func InitializeRegolithProject(isForced bool) bool {
}(file)

// Write default configuration
jsonData := Project{
jsonData := RegolithProject{
Profiles: map[string]Profile{
"default": {
Unsafe: false,
Expand Down

0 comments on commit ad68289

Please sign in to comment.