Skip to content

Commit

Permalink
Merge pull request #290 from Bedrock-OSS/update-export-targets
Browse files Browse the repository at this point in the history
Update export targets
  • Loading branch information
stirante authored Aug 22, 2024
2 parents ed8bb81 + ca46b52 commit cea0f11
Show file tree
Hide file tree
Showing 27 changed files with 419 additions and 57 deletions.
1 change: 1 addition & 0 deletions docs/docs/guide/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Example config, with many options explained:
// Export target defines where your files will be exported
"export": {
"target": "development",
"build": "standard",
"readOnly": false
}
}
Expand Down
1 change: 1 addition & 0 deletions docs/docs/guide/create-a-filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ At this point, you need to edit your `config.json` so that `giant_mobs` is regis
],
"export": {
"target": "development",
"build": "standard",
"readOnly": true
}
}
Expand Down
29 changes: 6 additions & 23 deletions docs/docs/guide/export-targets.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ These are the export targets that Regolith offers.

## Development

The development export target will place the compiled packs into your `com.mojang` `development_*_packs` folders.
The development export target will place the compiled packs into your `com.mojang` `development_*_packs` folders of the specified Minecraft build (standard, preview or education endition).

```json
"export": {
"target": "development"
"target": "development",
"build": "standard" // or "preview" or "education"
}
```

Expand All @@ -42,6 +43,7 @@ Optionally, you can use `rpName` and `bpName` to specify the names of the folder
```json
"export": {
"target": "development",
"build": "standard",
"rpName": "'my_rp'",
"bpName": "'my_bp'"
}
Expand Down Expand Up @@ -91,13 +93,14 @@ The exact export target doesn't support using `rpName` and `bpName`. The `rpPath

The World export target will place the compiled files into a specific world. This is useful for teams that prefer working in-world, as opposed to in the development pack folders.

You need to use *either* `worldName` or `worldPath` to select the world. `worldPath` supports environment variables by using the `%VARIABLE_NAME%` syntax.
You need to use *either* `worldName` or `worldPath` to select the world. `worldPath` supports environment variables by using the `%VARIABLE_NAME%` syntax. If you use `worldName`, you have to specify the Minecraft build you're using - `standard`, `preview` or `education`.

Example:

```json
"export": {
"target": "world",
"build": "standard",
"worldName": "..." // This
// "worldPath": "..." // OR this
}
Expand All @@ -114,26 +117,6 @@ Optionally, you can use `rpName` and `bpName` to specify the names of the folder
}
```


## Preview

The development export target will place the compiled packs into your **(minecraft preview)** `com.mojang` `development_*_packs` folder.

```json
"export": {
"target": "preview"
}
```

Optionally, you can use `rpName` and `bpName` to specify the names of the folders that will be created in the `development_*_packs` folders. You can read more about these options at the end of this page of the documentation.
```json
"export": {
"target": "preview",
"rpName": "'my_rp'",
"bpName": "'my_bp'"
}
```

# The `rpName` and `bpName` expressions

The `rpName` and `bpName` are expressions evaulated using the [go-simple-eval](https://github.com/stirante/go-simple-eval/) library. They let you specify the names of the folders of the exported packs in some of the export targets.
Expand Down
4 changes: 3 additions & 1 deletion docs/docs/guide/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Next, open up `config.json`. We will be configuring a few fields here, for your
"filters": [],
"export": {
"target": "development",
"build": "standard",
"readOnly": false
}
}
Expand Down Expand Up @@ -115,7 +116,8 @@ You should adjust the default profile in `config.json` to look like this:
"default": {
"export": {
"readOnly": false,
"target": "development"
"target": "development",
"build": "standard"
},
"filters": [
{
Expand Down
3 changes: 2 additions & 1 deletion docs/docs/guide/installing-filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ After installing, the filter will appear inside of `filter_definitions` of `conf
"default": {
"export": {
"readOnly": false,
"target": "development"
"target": "development",
"build": "standard"
},
"filters": [
{
Expand Down
2 changes: 2 additions & 0 deletions docs/docs/guide/profiles.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Here is an example `config.json` with a second profile called `package`.
],
"export": {
"target": "development",
"build": "standard"
}
},

Expand All @@ -50,6 +51,7 @@ Here is an example `config.json` with a second profile called `package`.
],
"export": {
"target": "development",
"build": "standard"
}
}
},
Expand Down
15 changes: 12 additions & 3 deletions regolith/compatibility_other_os.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package regolith

import (
"os"

"github.com/Bedrock-OSS/go-burrito/burrito"
)

Expand Down Expand Up @@ -50,22 +51,30 @@ func (d *DirWatcher) Close() error {
return burrito.WrappedError(notImplementedOnThisSystemError)
}

func FindMojangDir() (string, error) {
func FindStandardMojangDir() (string, error) {
comMojang := os.Getenv("COM_MOJANG")
if comMojang == "" {
return "", burrito.WrappedError(comMojangEnvUnsetError)
return "", burrito.WrappedError(comMojangEnvUnsetError)
}
return comMojang, nil
}

func FindPreviewDir() (string, error) {
comMojangPreview := os.Getenv("COM_MOJANG_PREVIEW")
if comMojangPreview == "" {
return "", burrito.WrappedError(comMojangPreviewEnvUnsetError)
return "", burrito.WrappedError(comMojangPreviewEnvUnsetError)
}
return comMojangPreview, nil
}

func FindEducationDir() (string, error) {
comMojangEdu := os.Getenv("COM_MOJANG_EDU")
if comMojangEdu == "" {
return "", burrito.WrappedError(comMojangEduEnvUnsetError)
}
return comMojangEdu, nil
}

func CheckSuspiciousLocation() error {
return nil
}
25 changes: 22 additions & 3 deletions regolith/compatibility_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,9 @@ func (d *DirWatcher) Close() error {
return windows.CloseHandle(d.handle)
}

// FindMojangDir returns path to the com.mojang folder.
func FindMojangDir() (string, error) {
// FindStandardMojangDir returns path to the com.mojang folder in the standard
// Minecraft build.
func FindStandardMojangDir() (string, error) {
result := filepath.Join(
os.Getenv("LOCALAPPDATA"), "Packages",
"Microsoft.MinecraftUWP_8wekyb3d8bbwe", "LocalState", "games",
Expand All @@ -161,6 +162,8 @@ func FindMojangDir() (string, error) {
return result, nil
}

// FindPreviewDir returns path to the com.mojang folder in the preview
// Minecraft build.
func FindPreviewDir() (string, error) {
result := filepath.Join(
os.Getenv("LOCALAPPDATA"), "Packages",
Expand All @@ -176,13 +179,29 @@ func FindPreviewDir() (string, error) {
return result, nil
}

// FindEducationDir returns path to the com.mojang folder in the education
// edition Minecraft build.
func FindEducationDir() (string, error) {
result := filepath.Join(
os.Getenv("APPDATA"), "Minecraft Education Edition", "games",
"com.mojang")
if _, err := os.Stat(result); err != nil {
if os.IsNotExist(err) {
return "", burrito.WrapErrorf(err, osStatErrorIsNotExist, result)
}
return "", burrito.WrapErrorf(
err, osStatErrorAny, result)
}
return result, nil
}

func CheckSuspiciousLocation() error {
path, err := os.Getwd()
if err != nil {
return burrito.WrapErrorf(err, osGetwdError)
}
// Check if project directory is within mojang dir
dir, err := FindMojangDir()
dir, err := FindStandardMojangDir()
if err == nil {
dir1 := filepath.Join(dir, "development_behavior_packs")
if isPathWithinDirectory(path, dir1) {
Expand Down
39 changes: 37 additions & 2 deletions regolith/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package regolith

import "github.com/Bedrock-OSS/go-burrito/burrito"
import (
"github.com/Bedrock-OSS/go-burrito/burrito"
"golang.org/x/mod/semver"
)

const latestCompatibleVersion = "1.4.0"

const StandardLibraryUrl = "github.com/Bedrock-OSS/regolith-filters"
const ConfigFilePath = "config.json"
Expand All @@ -26,7 +31,8 @@ type ExportTarget struct {
BpName string `json:"bpName,omitempty"`
WorldName string `json:"worldName,omitempty"`
WorldPath string `json:"worldPath,omitempty"`
ReadOnly bool `json:"readOnly"` // Whether the exported files should be read-only
ReadOnly bool `json:"readOnly"` // Whether the exported files should be read-only
Build string `json:"build,omitempty"` // The type of Minecraft build for the 'develop'
}

// Packs is a part of "config.json" that points to the source behavior and
Expand All @@ -42,6 +48,7 @@ type RegolithProject struct {
Profiles map[string]Profile `json:"profiles,omitempty"`
FilterDefinitions map[string]FilterInstaller `json:"filterDefinitions"`
DataPath string `json:"dataPath,omitempty"`
FormatVersion string `json:"formatVersion,omitempty"`
}

// ConfigFromObject creates a "Config" object from map[string]interface{}
Expand Down Expand Up @@ -109,6 +116,31 @@ func RegolithProjectFromObject(
Profiles: make(map[string]Profile),
FilterDefinitions: make(map[string]FilterInstaller),
}
// FormatVersion
if version, ok := obj["formatVersion"]; !ok {
Logger.Warn("Format version is missing. Defaulting to 1.2.0")
result.FormatVersion = "1.2.0"
} else {
formatVersion, ok := version.(string)
if !ok {
return result, burrito.WrappedErrorf(
jsonPropertyTypeError, "formatVersion", "string")
}
result.FormatVersion = formatVersion
vFormatVersion := "v" + formatVersion
if !semver.IsValid("v" + formatVersion) {
return result, burrito.WrappedErrorf(
"Invalid value of formatVersion. The formatVersion must "+
"be a semver version:\n"+
"Current value: %s", formatVersion)
}
if semver.Compare(vFormatVersion, "v"+latestCompatibleVersion) > 0 {
return result, burrito.WrappedErrorf(
incompatibleFormatVersionError,
formatVersion, latestCompatibleVersion)
}
}

// DataPath
if _, ok := obj["dataPath"]; !ok {
return result, burrito.WrappedErrorf(jsonPropertyMissingError, "dataPath")
Expand Down Expand Up @@ -197,5 +229,8 @@ func ExportTargetFromObject(obj map[string]interface{}) (ExportTarget, error) {
// ReadOnly - can be empty
readOnly, _ := obj["readOnly"].(bool)
result.ReadOnly = readOnly
// Build - can be empty
build, _ := obj["build"].(string)
result.Build = build
return result, nil
}
22 changes: 22 additions & 0 deletions regolith/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ const (
// Error used when env variable COM_MOJANG_PREVIEW is not set on non Windows system
comMojangPreviewEnvUnsetError = "COM_MOJANG_PREVIEW environment variable is not set."

// Error used when env variable COM_MOJANG_EDU is not set on non Windows system
comMojangEduEnvUnsetError = "COM_MOJANG_EDU environment variable is not set."

// Error used when SetupTmpFiles function fails
setupTmpFilesError = "Failed to setup temporary files.\n" +
"Regolith files path: %s" // .regolith
Expand Down Expand Up @@ -222,4 +225,23 @@ const (

resolverResolveUrlError = "Failed to resolve the URL of the resolver file for the download.\n" +
"Short URL: %s"

// findMojangDirError is used when the FindMojangDir function fails
findMojangDirError = "Failed to find \"com.mojang\" directory."

// findPreviewDirError is used when the FindPreviewDir function fails
findPreviewDirError = "Failed to find the preview \"com.mojang\" directory."

// findEducationDirError is used when the FindEducationDir function fails
findEducationDirError = "Failed to find the \"com.mojang\" directory."

invalidExportPathError = "The build property of the export is invalid:\n" +
"Current value: %q\n" +
"Valid values are: %s"

// Error used when the formatVersion of the config file is incompatible
// with the current version of Regolith.
incompatibleFormatVersionError = "Incompatible formatVersion: \n" +
"Version in config: %s\n" +
"Latest compatible version: %s"
)
Loading

0 comments on commit cea0f11

Please sign in to comment.