This commit is contained in:
Robert Janetzko 2022-05-10 07:51:04 +00:00
parent 375eab8e22
commit 52bffc322d
17 changed files with 75 additions and 20 deletions

View File

@ -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() {

View File

@ -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 {

View File

@ -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])

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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)
}

View File

@ -154,6 +154,8 @@
{{ $active = ""}}{{- end}}
</div>
</div>
{{ if world.MapReady }}
{{- if gt (len .Sites) 0 }}
<div class="page-map">
<div id="map" style="width: 300px; height: 300px"></div>
@ -164,6 +166,7 @@
{{- end }}
</div>
{{- end }}
{{- end }}
</div>

View File

@ -16,6 +16,7 @@
{{- end }}
</ul>
{{ if world.MapReady }}
<div id="map" style="height: 400px"></div>
{{initMap}}
{{- range $race, $civs := .Civilizations }}
@ -25,5 +26,6 @@
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}

View File

@ -3,12 +3,14 @@
{{define "title"}}{{ title .Name }}{{end}}
{{define "content"}}
{{ if world.MapReady }}
<div class="object-map">
<div id="map" style="width: 300px; height: 300px"></div>
</div>
{{initMap}}
{{ addLandmass .Id }}
<script>map.addLayer(landmassesLayer);</script>
{{- end }}
<h1>{{ title .Name }}</h1>
<p>landmass</p>

View File

@ -24,18 +24,19 @@
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light mb-4">
<div class="container">
<a class="navbar-brand" href="#">Legends Browser</a>
<a class="navbar-brand" href="#" style="font-weight: 500;">Legends Browser</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
{{ if world }}
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" href="./">Civilizations</a>
</li>
<li class="nav-item">
<a class="nav-link" href="./worldmap">World Map</a>
<a class="nav-link{{if not world.MapReady}} disabled{{end}}" href="./worldmap">World Map</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown"
@ -77,6 +78,7 @@
onSelectItem: ({ label, value }) => window.location = "." + value
});
</script>
{{ end }}
</div>
</div>
</nav>

View File

@ -3,11 +3,14 @@
{{define "title"}}{{ title .Name }}{{end}}
{{define "content"}}
{{ if world.MapReady }}
<div class="object-map">
<div id="map" style="width: 300px; height: 300px"></div>
</div>
{{initMap}}
{{ addMountain .Id false }}
{{- end }}
<h3>{{ title .Name }}</h3>
<p>{{ if .IsVolcano }}volcano{{else}}mountain{{end}}</p>

View File

@ -3,12 +3,15 @@
{{define "title"}}{{ title .Name }}{{end}}
{{define "content"}}
{{ if world.MapReady }}
<div class="object-map">
<div id="map" style="width: 300px; height: 300px"></div>
</div>
{{initMap}}
{{ addRegion .Id }}
<script>map.addLayer(regionsLayer);</script>
{{- end }}
<h3>{{ title .Name }}</h3>
<p>{{ .Type }}</p>

View File

@ -63,12 +63,14 @@
</div>
</div>
</div>
{{ if world.MapReady }}
<div class="page-map">
<div id="map" style="width: 300px; height: 300px"></div>
<!-- <img class="site-map" src="$suburi/sitemap/$site.id" width="300" /> -->
{{initMap}}
{{ addSite .Id false }}
</div>
{{- end }}
</div>
<h5 class="mt-3">Events</h5>

View File

@ -3,11 +3,14 @@
{{define "title"}}{{ title .Name }}{{end}}
{{define "content"}}
{{ if world.MapReady }}
<div class="object-map">
<div id="map" style="width: 300px; height: 300px"></div>
</div>
{{initMap}}
{{ addSite .SiteId false }}
{{- end }}
<h3>{{ title .Name }}</h3>
{{ .Type_ }} in {{ site .SiteId }}

View File

@ -4,6 +4,7 @@
{{define "content"}}
{{ if world.MapReady }}
<div id="map" style="width: 100%; height: 1000px"></div>
{{initMap}}
<script>L.control.layers(null, overlayMaps).addTo(map);</script>
@ -30,5 +31,8 @@
{{- range $id, $r := .Rivers }}
{{ addRiver $id }}
{{- end }}
{{ else }}
No map data available
{{- end }}
{{- end }}

View File

@ -3,11 +3,14 @@
{{define "title"}}{{ title .Name }}{{end}}
{{define "content"}}
{{ if world.MapReady }}
<div class="object-map">
<div id="map" style="width: 300px; height: 300px"></div>
</div>
{{initMap}}
{{ addWorldConstruction .Id }}
{{- end }}
<h3>{{ title .Name }}</h3>
<p>{{ .Type }}</p>