This commit is contained in:
Robert Janetzko 2022-04-25 18:59:33 +00:00
parent a30c1515f0
commit 5aa0bc5a8d
5 changed files with 38 additions and 42 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ legendsbrowser
*.png *.png
/*.json /*.json
.DS_Store .DS_Store
bin

10
Makefile Normal file
View File

@ -0,0 +1,10 @@
build:
cd backend && GOOS=linux GOARCH=386 go build -o ../bin/legendsbrowser-linux-386 main.go
cd backend && GOOS=linux GOARCH=amd64 go build -o ../bin/legendsbrowser-linux-x64 main.go
cd backend && GOOS=windows GOARCH=386 go build -o ../bin/legendsbrowser-386.exe main.go
cd backend && GOOS=windows GOARCH=amd64 go build -o ../bin/legendsbrowser-x64.exe main.go
cd backend && GOOS=darwin GOARCH=amd64 go build -o ../bin/legendsbrowser-macos-x64 main.go
cd backend && GOOS=darwin GOARCH=arm64 go build -o ../bin/legendsbrowser-macos-m1 main.go
run:
cd backend && go run main.go

View File

@ -9,6 +9,7 @@ import (
"net/http" "net/http"
_ "net/http/pprof" _ "net/http/pprof"
"os" "os"
"os/exec"
"runtime" "runtime"
"sort" "sort"
"strconv" "strconv"
@ -73,43 +74,7 @@ func main() {
} }
world = w world = w
fmt.Println("Hallo Welt!")
runtime.GC() runtime.GC()
// world.Process()
// model.ListOtherElements("world", &[]*model.World{&world})
// model.ListOtherElements("region", &world.Regions)
// model.ListOtherElements("underground regions", &world.UndergroundRegions)
// model.ListOtherElements("landmasses", &world.Landmasses)
// model.ListOtherElements("sites", &world.Sites)
// model.ListOtherElements("world constructions", &world.WorldConstructions)
// model.ListOtherElements("artifacts", &world.Artifacts)
// model.ListOtherElements("entities", &world.Entities)
// model.ListOtherElements("hf", &world.HistoricalFigures)
// model.ListOtherElements("events", &world.HistoricalEvents)
// model.ListOtherElements("collections", &world.HistoricalEventCollections)
// model.ListOtherElements("era", &world.HistoricalEras)
// model.ListOtherElements("danceForm", &world.DanceForms)
// model.ListOtherElements("musicalForm", &world.MusicalForms)
// model.ListOtherElements("poeticForm", &world.PoeticForms)
// model.ListOtherElements("written", &world.WrittenContents)
// server.RegisterResource(router, "region", world.Regions)
// // server.RegisterResource(router, "undergroundRegion", world.UndergroundRegions)
// server.RegisterResource(router, "landmass", world.Landmasses)
// server.RegisterResource(router, "site", world.Sites)
// server.RegisterResource(router, "worldConstruction", world.WorldConstructions)
// server.RegisterResource(router, "artifact", world.Artifacts)
// server.RegisterResource(router, "hf", world.HistoricalFigures)
// server.RegisterResource(router, "collection", world.HistoricalEventCollections)
// server.RegisterResource(router, "entity", world.Entities)
// server.RegisterResource(router, "event", world.HistoricalEvents)
// // server.RegisterResource(router, "era", world.HistoricalEras)
// server.RegisterResource(router, "danceForm", world.DanceForms)
// server.RegisterResource(router, "musicalForm", world.MusicalForms)
// server.RegisterResource(router, "poeticForm", world.PoeticForms)
// server.RegisterResource(router, "written", world.WrittenContents)
RegisterResourcePage(router, "/entity/{id}", t, "entity.html", func(id int) any { return world.Entities[id] }) RegisterResourcePage(router, "/entity/{id}", t, "entity.html", func(id int) any { return world.Entities[id] })
RegisterResourcePage(router, "/hf/{id}", t, "hf.html", func(id int) any { return world.HistoricalFigures[id] }) RegisterResourcePage(router, "/hf/{id}", t, "hf.html", func(id int) any { return world.HistoricalFigures[id] })
@ -123,10 +88,32 @@ func main() {
spa := spaHandler{staticFS: static, staticPath: "static", indexPath: "index.html"} spa := spaHandler{staticFS: static, staticPath: "static", indexPath: "index.html"}
router.PathPrefix("/").Handler(spa) router.PathPrefix("/").Handler(spa)
openbrowser("http://localhost:8080")
fmt.Println("Serving at :8080") fmt.Println("Serving at :8080")
http.ListenAndServe(":8080", router) http.ListenAndServe(":8080", router)
} }
func openbrowser(url string) {
var err error
switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", url).Start()
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
case "darwin":
err = exec.Command("open", url).Start()
default:
err = fmt.Errorf("unsupported platform")
}
if err != nil {
fmt.Println(err)
fmt.Println("navigate to http://localhost:8080 in your browser")
}
}
func allEventTypes() []string { func allEventTypes() []string {
types := make(map[string]bool) types := make(map[string]bool)
for _, e := range world.HistoricalEvents { for _, e := range world.HistoricalEvents {

View File

@ -933,7 +933,6 @@ func (x *HistoricalEventHfDied) Html(c *context) string {
return hf + " drowned" + loc return hf + " drowned" + loc
case HistoricalEventHfDiedCause_DrownAlt, HistoricalEventHfDiedCause_ExecDrowned: case HistoricalEventHfDiedCause_DrownAlt, HistoricalEventHfDiedCause_ExecDrowned:
return hf + " was drowned" + slayer + loc return hf + " was drowned" + slayer + loc
case HistoricalEventHfDiedCause_DrownAltTwo:
case HistoricalEventHfDiedCause_EncaseIce, HistoricalEventHfDiedCause_FreezingWater: case HistoricalEventHfDiedCause_EncaseIce, HistoricalEventHfDiedCause_FreezingWater:
return hf + " was encased in ice" + loc return hf + " was encased in ice" + loc
case HistoricalEventHfDiedCause_ExecGeneric, HistoricalEventHfDiedCause_ExecutionGeneric: case HistoricalEventHfDiedCause_ExecGeneric, HistoricalEventHfDiedCause_ExecutionGeneric:
@ -949,7 +948,6 @@ func (x *HistoricalEventHfDied) Html(c *context) string {
return hf + " starved" + loc return hf + " starved" + loc
case HistoricalEventHfDiedCause_Infection: case HistoricalEventHfDiedCause_Infection:
return hf + " succumbed to infection" + loc return hf + " succumbed to infection" + loc
case HistoricalEventHfDiedCause_LeaptFromHeight:
case HistoricalEventHfDiedCause_Melt: case HistoricalEventHfDiedCause_Melt:
return hf + " melted" + loc return hf + " melted" + loc
case HistoricalEventHfDiedCause_Murder, HistoricalEventHfDiedCause_Murdered: case HistoricalEventHfDiedCause_Murder, HistoricalEventHfDiedCause_Murdered:
@ -972,9 +970,9 @@ func (x *HistoricalEventHfDied) Html(c *context) string {
return hf + " was struck down" + slayer + loc return hf + " was struck down" + slayer + loc
case HistoricalEventHfDiedCause_Suffocate, HistoricalEventHfDiedCause_Air: case HistoricalEventHfDiedCause_Suffocate, HistoricalEventHfDiedCause_Air:
return hf + " suffocated, slain by " + slayer + loc return hf + " suffocated, slain by " + slayer + loc
case HistoricalEventHfDiedCause_SuicideDrowned: case HistoricalEventHfDiedCause_SuicideDrowned, HistoricalEventHfDiedCause_DrownAltTwo:
return hf + " drowned " + util.If(world.HistoricalFigures[x.Hfid].Female(), "herself ", "himself ") + loc return hf + " drowned " + util.If(world.HistoricalFigures[x.Hfid].Female(), "herself ", "himself ") + loc
case HistoricalEventHfDiedCause_SuicideLeaping: case HistoricalEventHfDiedCause_SuicideLeaping, HistoricalEventHfDiedCause_LeaptFromHeight:
return hf + " leapt from a great height" + loc return hf + " leapt from a great height" + loc
case HistoricalEventHfDiedCause_Thirst: case HistoricalEventHfDiedCause_Thirst:
return hf + " died of thirst" + loc return hf + " died of thirst" + loc

View File

@ -31,7 +31,7 @@ func NewDebug(funcMap template.FuncMap) *Template {
} }
} }
var DebugTemplates = true var DebugTemplates = false
func (t *Template) Render(w io.Writer, name string, data interface{}) error { func (t *Template) Render(w io.Writer, name string, data interface{}) error {
if DebugTemplates { if DebugTemplates {