Skip to content

Commit

Permalink
Add hello world filter
Browse files Browse the repository at this point in the history
  • Loading branch information
SirLich committed Dec 19, 2021
1 parent 330953c commit 4aa825d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 30 deletions.
23 changes: 23 additions & 0 deletions regolith/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ func (filter *Filter) RunFilter(absoluteLocation string) error {

// Standard Filter is only filter that doesn't require authentication.
if filter.Filter != "" {

// Special handling for our hello world filter,
// which welcomes new users to Regolith
if filter.Filter == "hello_world" {
return RunHelloWorldFilter(filter)
}

// Otherwise drop down to standard handling
err := RunStandardFilter(*filter)
if err != nil {
return err
Expand Down Expand Up @@ -95,6 +103,21 @@ func RunStandardFilter(filter Filter) error {
return RunRemoteFilter(FilterNameToUrl(StandardLibraryUrl, filter.Filter), filter)
}

func RunHelloWorldFilter(filter *Filter) error {
Logger.Info(
"Hello world!\n" +
"===========================================================\n" +
" Welcome to Regolith!\n" +
"\n" +
" This message is generated from the 'hello_world' filter.\n" +
" You can delete this filter when you're ready, and replace it with" +
" Something more useful!\n" +
"===========================================================\n",
)

return nil
}

// RunRemoteFilter runs loads and runs the content of filter.json from in
// regolith cache. The url is the URL of the filter from which the filter
// was downloaded (used to specify its path in the cache). The parentFilter
Expand Down
60 changes: 30 additions & 30 deletions regolith/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ const GitIgnore = `/build

// TODO implement the rest of the standard config spec
type Config struct {
Name string `json:"name"`
Author string `json:"author"`
Packs `json:"packs"`
RegolithProject `json:"regolith"`
Name string `json:"name,omitempty"`
Author string `json:"author,omitempty"`
Packs `json:"packs,omitempty"`
RegolithProject `json:"regolith,omitempty"`
}

func LoadConfig() (*Config, error) {
Expand All @@ -47,18 +47,18 @@ func LoadConfig() (*Config, error) {
}

type Packs struct {
BehaviorFolder string `json:"behaviorPack"`
ResourceFolder string `json:"resourcePack"`
BehaviorFolder string `json:"behaviorPack,omitempty"`
ResourceFolder string `json:"resourcePack,omitempty"`
}

type RegolithProject struct {
Profiles map[string]Profile `json:"profiles"`
Profiles map[string]Profile `json:"profiles,omitempty"`
}

type Profile struct {
Filters []Filter `json:"filters"`
ExportTarget ExportTarget `json:"export"`
DataPath string `json:"dataPath"`
Filters []Filter `json:"filters,omitempty"`
ExportTarget ExportTarget `json:"export,omitempty"`
DataPath string `json:"dataPath,omitempty"`
}

// LoadFiltersFromPath returns a Profile with list of filters loaded from
Expand Down Expand Up @@ -183,16 +183,16 @@ func (p *Profile) Install(isForced bool, profilePath string) error {
}

type Filter struct {
Name string `json:"name"`
Script string `json:"script"`
Disabled bool `json:"disabled"`
RunWith string `json:"runWith"`
Command string `json:"command"`
Arguments []string `json:"arguments"`
Url string `json:"url"`
Filter string `json:"filter"`
Settings map[string]interface{} `json:"settings"`
VenvSlot int `json:"venvSlot"`
Name string `json:"name,omitempty"`
Script string `json:"script,omitempty"`
Disabled bool `json:"disabled,omitempty"`
RunWith string `json:"runWith,omitempty"`
Command string `json:"command,omitempty"`
Arguments []string `json:"arguments,omitempty"`
Url string `json:"url,omitempty"`
Filter string `json:"filter,omitempty"`
Settings map[string]interface{} `json:"settings,omitempty"`
VenvSlot int `json:"venvSlot,omitempty"`
}

// GetFilterPath returns URL for downloading the filter or empty string
Expand Down Expand Up @@ -308,16 +308,12 @@ func (f *Filter) Download(isForced bool, profileDir string) (string, error) {
}

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
WorldName string `json:"worldName"`
WorldPath string `json:"worldPath"`
Target string `json:"target,omitempty"` // The mode of exporting. "develop" or "exact"
RpPath string `json:"rpPath,omitempty"` // Relative or absolute path to resource pack for "exact" export target
BpPath string `json:"bpPath,omitempty"` // Relative or absolute path to resource pack for "exact" export target
WorldName string `json:"worldName,omitempty"`
WorldPath string `json:"worldPath,omitempty"`
ReadOnly bool `json:"readOnly"` // Whether the exported files should be read-only
// ComMojangPath string `json:"comMojangPath"`
// NOT USED, DISABLED FOR NOW.
// Clean bool `json:"clean"`
// Path string `json:"path"`
}

func IsProjectInitialized() bool {
Expand Down Expand Up @@ -359,7 +355,11 @@ func InitializeRegolithProject(isForced bool) error {
Profiles: map[string]Profile{
"dev": {
DataPath: "./packs/data",
Filters: []Filter{},
Filters: []Filter{
{
Filter: "hello_world",
},
},
ExportTarget: ExportTarget{
Target: "development",
ReadOnly: false,
Expand Down

0 comments on commit 4aa825d

Please sign in to comment.