diff --git a/backend/main.go b/backend/main.go index 9aa2e4d..39c93e0 100644 --- a/backend/main.go +++ b/backend/main.go @@ -29,6 +29,14 @@ var rootCmd = &cobra.Command{ Use: "legendsbrowser", Short: "A Legends Browser for Dwarf Fortress", Run: func(cmd *cobra.Command, args []string) { + fmt.Println(` + __ __ ____ + / / ___ ____ ___ ____ ____/ /____ / __ )_________ _ __________ _____ + / / / _ \/ __ \/ _ \/ __ \/ __ / ___/ / __ / ___/ __ \ | /| / / ___/ _ \/ ___/ + / /___/ __/ /_/ / __/ / / / /_/ (__ ) / /_/ / / / /_/ / |/ |/ (__ ) __/ / + /_____/\___/\__, /\___/_/ /_/\__,_/____/ /_____/_/ \____/|__/|__/____/\___/_/ + /____/ ` + "\n ") + if *p { defer profile.Start(profile.ProfilePath(".")).Stop() go func() { diff --git a/backend/model/history.go b/backend/model/history.go index d86e8f4..2b77850 100644 --- a/backend/model/history.go +++ b/backend/model/history.go @@ -1,8 +1,10 @@ package model import ( + "errors" "fmt" "io/ioutil" + "os" "regexp" "strconv" "strings" @@ -17,15 +19,20 @@ type EntityLeader struct { } func (w *DfWorld) LoadHistory() { - w.LoadDimensions() + fmt.Println("") path := strings.ReplaceAll(w.FilePath, "-legends.xml", "-world_history.txt") data, err := ioutil.ReadFile(path) if err != nil { - fmt.Println(err) + if errors.Is(err, os.ErrNotExist) { + fmt.Println("no world history found") + } else { + fmt.Println(err) + } return } + fmt.Println("found world history", path) leaderRegEx := regexp.MustCompile(` \[\*\] (.+?) \(.*?Reign Began: (-?\d+)\)`) results := regexp.MustCompile(`\n([^ ].*?), [^\n]+(?:\n [^\n]+)*`).FindAllStringSubmatch(util.ConvertCp473(data), -1) for _, result := range results { diff --git a/backend/model/map.go b/backend/model/map.go index 500874c..6cbf67b 100644 --- a/backend/model/map.go +++ b/backend/model/map.go @@ -18,6 +18,8 @@ import ( func (w *DfWorld) LoadMap() { w.LoadDimensions() + fmt.Println("") + path := "" files, err := filepath.Glob(strings.ReplaceAll(w.FilePath, "-legends.xml", "-world_map.*")) if err == nil && len(files) > 0 { @@ -29,6 +31,7 @@ func (w *DfWorld) LoadMap() { } if path == "" { + fmt.Println("no world map found") return } @@ -38,13 +41,13 @@ func (w *DfWorld) LoadMap() { return } - fmt.Println("Found Map", path) + fmt.Println("found world map", path) img, format, err := image.Decode(mapImage) if err != nil { fmt.Println(err) return } - fmt.Println("loaded img", format) + fmt.Println("loaded world map imgage as", format) buf := new(bytes.Buffer) err = png.Encode(buf, img) if err != nil { @@ -56,6 +59,8 @@ func (w *DfWorld) LoadMap() { } func (w *DfWorld) LoadDimensions() { + fmt.Println("") + files, err := filepath.Glob(filepath.Join(filepath.Dir(w.FilePath), "*-world_gen_param.txt")) if err != nil { fmt.Println(err) @@ -70,18 +75,21 @@ func (w *DfWorld) LoadDimensions() { } } if path == "" { + fmt.Println("no worldgen params found") return } - fmt.Println("Found Worldgen", path) + fmt.Println("found worldgen params", path) content, err := ioutil.ReadFile(path) if err != nil { + fmt.Println(err) return } r := regexp.MustCompile(`\[DIM:(\d+):(\d+)\]`) result := r.FindAllStringSubmatch(string(content), 1) if result == nil { + fmt.Println("no world dimensions found") return } w.Width, _ = strconv.Atoi(result[0][2]) diff --git a/backend/model/parse.go b/backend/model/parse.go index a44bf3d..e8138a6 100644 --- a/backend/model/parse.go +++ b/backend/model/parse.go @@ -28,7 +28,7 @@ func NewLegendsDecoder(file string) (*xml.Decoder, *os.File, *pb.ProgressBar, er fmt.Println(err) } - fmt.Println("Successfully Opened", file) + fmt.Println("Loading:", file) converter := util.NewConvertReader(xmlFile) barReader := bar.NewProxyReader(converter) @@ -50,7 +50,7 @@ func NewLegendsParser(file string) (*util.XMLParser, *os.File, *pb.ProgressBar, fmt.Println(err) } - fmt.Println("Successfully Opened", file) + fmt.Println("\nLoading:", file) barReader := bar.NewProxyReader(xmlFile) d := util.NewXMLParser(bufio.NewReader(barReader)) @@ -100,10 +100,14 @@ BaseLoop: bar.Finish() plus := false + file = strings.Replace(file, "-legends.xml", "-legends_plus.xml", 1) + if _, err := os.Stat(file); err == nil { + plus = true + } else { + fmt.Println("\nno legends_plus.xml found") + } if plus { - file = strings.Replace(file, "-legends.xml", "-legends_plus.xml", 1) - p, xmlFile, bar, err = NewLegendsParser(file) if lp != nil { lp.Message = "Loading " + file diff --git a/backend/server/config.go b/backend/server/config.go index 9a7b6df..0f97e28 100644 --- a/backend/server/config.go +++ b/backend/server/config.go @@ -2,7 +2,6 @@ package server import ( "encoding/json" - "fmt" "io/ioutil" "os" "path/filepath" @@ -31,9 +30,7 @@ func LoadConfig(path string) (*Config, error) { data, err := ioutil.ReadFile(path) if err != nil { - fmt.Println("OPEN", err) if os.IsNotExist(err) { - fmt.Println("EX", err) home, err := os.UserHomeDir() if err != nil { return nil, err diff --git a/backend/server/static.go b/backend/server/static.go index bc1ed24..f9059cb 100644 --- a/backend/server/static.go +++ b/backend/server/static.go @@ -1,7 +1,6 @@ package server import ( - "fmt" "io/fs" "io/ioutil" "net/http" @@ -28,13 +27,9 @@ func (h spaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // prepend the path with the path to the static directory path = h.staticPath + path - fmt.Println(path) - _, err := h.staticFS.Open(path) if os.IsNotExist(err) { - fmt.Println("ERR") // file does not exist, serve index.html - fmt.Println(path) file, err := h.staticFS.Open(h.staticPath + "/" + h.indexPath) if err != nil { h.server.notFound(w) diff --git a/backend/server/util.go b/backend/server/util.go index d47bc9c..e6fec27 100644 --- a/backend/server/util.go +++ b/backend/server/util.go @@ -4,11 +4,14 @@ import ( "fmt" "os/exec" "runtime" + "strings" ) func OpenBrowser(url string) { var err error + fmt.Println() + switch runtime.GOOS { case "linux": err = exec.Command("xdg-open", url).Start() @@ -21,7 +24,13 @@ func OpenBrowser(url string) { } if err != nil { fmt.Println(err) - fmt.Println("navigate to " + url + " in your browser") } + s := "If your web browser doesn't open automatically, navigate to " + url + " manually" + t := strings.Repeat("=", len(s)) + fmt.Println() + fmt.Println(t) + fmt.Println(s) + fmt.Println(t) + } diff --git a/backend/templates/entity.html b/backend/templates/entity.html index f05799d..930f5c1 100644 --- a/backend/templates/entity.html +++ b/backend/templates/entity.html @@ -154,6 +154,8 @@ {{ $active = ""}}{{- end}} + + {{ if world.MapReady }} {{- if gt (len .Sites) 0 }}
@@ -164,6 +166,7 @@ {{- end }}
{{- end }} + {{- end }} diff --git a/backend/templates/index.html b/backend/templates/index.html index c7d0ba8..b1e78f3 100644 --- a/backend/templates/index.html +++ b/backend/templates/index.html @@ -16,6 +16,7 @@ {{- end }} +{{ if world.MapReady }}
{{initMap}} {{- range $race, $civs := .Civilizations }} @@ -25,5 +26,6 @@ {{- end }} {{- end }} {{- end }} +{{- end }} {{- end }} \ No newline at end of file diff --git a/backend/templates/landmass.html b/backend/templates/landmass.html index 2606e8c..611c9f4 100644 --- a/backend/templates/landmass.html +++ b/backend/templates/landmass.html @@ -3,12 +3,14 @@ {{define "title"}}{{ title .Name }}{{end}} {{define "content"}} +{{ if world.MapReady }}
{{initMap}} {{ addLandmass .Id }} +{{- end }}

{{ title .Name }}

landmass

diff --git a/backend/templates/layout.html b/backend/templates/layout.html index ef537d1..9a24346 100644 --- a/backend/templates/layout.html +++ b/backend/templates/layout.html @@ -24,18 +24,19 @@ diff --git a/backend/templates/mountain.html b/backend/templates/mountain.html index cf66119..2e90c6f 100644 --- a/backend/templates/mountain.html +++ b/backend/templates/mountain.html @@ -3,11 +3,14 @@ {{define "title"}}{{ title .Name }}{{end}} {{define "content"}} + +{{ if world.MapReady }}
{{initMap}} {{ addMountain .Id false }} +{{- end }}

{{ title .Name }}

{{ if .IsVolcano }}volcano{{else}}mountain{{end}}

diff --git a/backend/templates/region.html b/backend/templates/region.html index 30af3b0..b576577 100644 --- a/backend/templates/region.html +++ b/backend/templates/region.html @@ -3,12 +3,15 @@ {{define "title"}}{{ title .Name }}{{end}} {{define "content"}} + +{{ if world.MapReady }}
{{initMap}} {{ addRegion .Id }} +{{- end }}

{{ title .Name }}

{{ .Type }}

diff --git a/backend/templates/site.html b/backend/templates/site.html index e3e74c1..c2d1951 100644 --- a/backend/templates/site.html +++ b/backend/templates/site.html @@ -63,12 +63,14 @@ + {{ if world.MapReady }}
{{initMap}} {{ addSite .Id false }}
+ {{- end }}
Events
diff --git a/backend/templates/structure.html b/backend/templates/structure.html index 7d212d7..82ab864 100644 --- a/backend/templates/structure.html +++ b/backend/templates/structure.html @@ -3,11 +3,14 @@ {{define "title"}}{{ title .Name }}{{end}} {{define "content"}} + +{{ if world.MapReady }}
{{initMap}} {{ addSite .SiteId false }} +{{- end }}

{{ title .Name }}

{{ .Type_ }} in {{ site .SiteId }} diff --git a/backend/templates/worldMap.html b/backend/templates/worldMap.html index 2cbcc10..22602c7 100644 --- a/backend/templates/worldMap.html +++ b/backend/templates/worldMap.html @@ -4,6 +4,7 @@ {{define "content"}} +{{ if world.MapReady }}
{{initMap}} @@ -30,5 +31,8 @@ {{- range $id, $r := .Rivers }} {{ addRiver $id }} {{- end }} +{{ else }} +No map data available +{{- end }} {{- end }} \ No newline at end of file diff --git a/backend/templates/worldconstruction.html b/backend/templates/worldconstruction.html index f60679f..9ff9299 100644 --- a/backend/templates/worldconstruction.html +++ b/backend/templates/worldconstruction.html @@ -3,11 +3,14 @@ {{define "title"}}{{ title .Name }}{{end}} {{define "content"}} + +{{ if world.MapReady }}
{{initMap}} {{ addWorldConstruction .Id }} +{{- end }}

{{ title .Name }}

{{ .Type }}