This commit is contained in:
Robert Janetzko 2022-04-30 12:27:42 +00:00
parent 6f3f13bdb7
commit 87451e7357
10 changed files with 54 additions and 15 deletions

View File

@ -201,7 +201,7 @@ func (c *Context) poeticForm(id int) string {
func (c *Context) worldConstruction(id int) string { func (c *Context) worldConstruction(id int) string {
if x, ok := c.World.WorldConstructions[id]; ok { if x, ok := c.World.WorldConstructions[id]; ok {
return fmt.Sprintf(`<a class="worldconstruction" href="/wc/%d"><i class="%s fa-xs"></i>&nbsp;%s</a>`, id, x.Icon(), util.Title(x.Name())) return fmt.Sprintf(`<a class="worldconstruction" href="/worldconstruction/%d"><i class="%s fa-xs"></i>&nbsp;%s</a>`, id, x.Icon(), util.Title(x.Name()))
} }
return "UNKNOWN WORLD CONSTRUCTION" return "UNKNOWN WORLD CONSTRUCTION"
} }

View File

@ -42,36 +42,29 @@ func StartServer(world *model.DfWorld, static embed.FS) {
srv.RegisterWorldPage("/entities", "entities.html", func(p Parms) any { return grouped(srv.context.world.Entities) }) srv.RegisterWorldPage("/entities", "entities.html", func(p Parms) any { return grouped(srv.context.world.Entities) })
srv.RegisterWorldResourcePage("/entity/{id}", "entity.html", func(id int) any { return srv.context.world.Entities[id] }) srv.RegisterWorldResourcePage("/entity/{id}", "entity.html", func(id int) any { return srv.context.world.Entities[id] })
srv.RegisterWorldResourcePage("/popover/entity/{id}", "popoverEntity.html", func(id int) any { return srv.context.world.Entities[id] })
srv.RegisterWorldPage("/regions", "regions.html", func(p Parms) any { return grouped(srv.context.world.Regions) }) srv.RegisterWorldPage("/regions", "regions.html", func(p Parms) any { return grouped(srv.context.world.Regions) })
srv.RegisterWorldResourcePage("/region/{id}", "region.html", func(id int) any { return srv.context.world.Regions[id] }) srv.RegisterWorldResourcePage("/region/{id}", "region.html", func(id int) any { return srv.context.world.Regions[id] })
srv.RegisterWorldResourcePage("/popover/region/{id}", "popoverRegion.html", func(id int) any { return srv.context.world.Regions[id] })
srv.RegisterWorldPage("/sites", "sites.html", func(p Parms) any { return grouped(srv.context.world.Sites) }) srv.RegisterWorldPage("/sites", "sites.html", func(p Parms) any { return grouped(srv.context.world.Sites) })
srv.RegisterWorldResourcePage("/site/{id}", "site.html", func(id int) any { return srv.context.world.Sites[id] }) srv.RegisterWorldResourcePage("/site/{id}", "site.html", func(id int) any { return srv.context.world.Sites[id] })
srv.RegisterWorldResourcePage("/popover/site/{id}", "popoverSite.html", func(id int) any { return srv.context.world.Sites[id] })
srv.RegisterWorldPage("/structures", "structures.html", func(p Parms) any { srv.RegisterWorldPage("/structures", "structures.html", func(p Parms) any {
return flatGrouped(srv.context.world.Sites, func(s *model.Site) []*model.Structure { return util.Values(s.Structures) }) return flatGrouped(srv.context.world.Sites, func(s *model.Site) []*model.Structure { return util.Values(s.Structures) })
}) })
srv.RegisterWorldPage("/site/{siteId}/structure/{id}", "structure.html", func(p Parms) any { srv.RegisterWorldPage("/site/{siteId}/structure/{id}", "structure.html", srv.findStructure)
siteId, err := strconv.Atoi(p["siteId"]) srv.RegisterWorldPage("/popover/site/{siteId}/structure/{id}", "popoverStructure.html", srv.findStructure)
if err != nil {
return nil
}
structureId, err := strconv.Atoi(p["id"])
if err != nil {
return nil
}
if site, ok := srv.context.world.Sites[siteId]; ok {
return site.Structures[structureId]
}
return nil
})
srv.RegisterWorldPage("/worldconstructions", "worldconstructions.html", func(p Parms) any { return grouped(srv.context.world.WorldConstructions) }) srv.RegisterWorldPage("/worldconstructions", "worldconstructions.html", func(p Parms) any { return grouped(srv.context.world.WorldConstructions) })
srv.RegisterWorldResourcePage("/worldconstruction/{id}", "worldconstruction.html", func(id int) any { return srv.context.world.WorldConstructions[id] }) srv.RegisterWorldResourcePage("/worldconstruction/{id}", "worldconstruction.html", func(id int) any { return srv.context.world.WorldConstructions[id] })
srv.RegisterWorldResourcePage("/popover/worldconstruction/{id}", "popoverWorldconstruction.html", func(id int) any { return srv.context.world.WorldConstructions[id] })
srv.RegisterWorldPage("/artifacts", "artifacts.html", func(p Parms) any { return grouped(srv.context.world.Artifacts) }) srv.RegisterWorldPage("/artifacts", "artifacts.html", func(p Parms) any { return grouped(srv.context.world.Artifacts) })
srv.RegisterWorldResourcePage("/artifact/{id}", "artifact.html", func(id int) any { return srv.context.world.Artifacts[id] }) srv.RegisterWorldResourcePage("/artifact/{id}", "artifact.html", func(id int) any { return srv.context.world.Artifacts[id] })
srv.RegisterWorldResourcePage("/popover/artifact/{id}", "popoverArtifact.html", func(id int) any { return srv.context.world.Artifacts[id] })
srv.RegisterWorldPage("/artforms", "artforms.html", func(p Parms) any { srv.RegisterWorldPage("/artforms", "artforms.html", func(p Parms) any {
return &struct { return &struct {
@ -87,8 +80,10 @@ func StartServer(world *model.DfWorld, static embed.FS) {
srv.RegisterWorldPage("/writtencontents", "writtencontents.html", func(p Parms) any { return grouped(srv.context.world.WrittenContents) }) srv.RegisterWorldPage("/writtencontents", "writtencontents.html", func(p Parms) any { return grouped(srv.context.world.WrittenContents) })
srv.RegisterWorldResourcePage("/writtencontent/{id}", "writtencontent.html", func(id int) any { return srv.context.world.WrittenContents[id] }) srv.RegisterWorldResourcePage("/writtencontent/{id}", "writtencontent.html", func(id int) any { return srv.context.world.WrittenContents[id] })
srv.RegisterWorldResourcePage("/popover/writtencontent/{id}", "popoverWrittencontent.html", func(id int) any { return srv.context.world.WrittenContents[id] })
srv.RegisterWorldResourcePage("/hf/{id}", "hf.html", func(id int) any { return srv.context.world.HistoricalFigures[id] }) srv.RegisterWorldResourcePage("/hf/{id}", "hf.html", func(id int) any { return srv.context.world.HistoricalFigures[id] })
srv.RegisterWorldResourcePage("/popover/hf/{id}", "popoverHf.html", func(id int) any { return srv.context.world.HistoricalFigures[id] })
srv.RegisterWorldPage("/", "eventTypes.html", func(p Parms) any { return srv.context.world.AllEventTypes() }) srv.RegisterWorldPage("/", "eventTypes.html", func(p Parms) any { return srv.context.world.AllEventTypes() })
srv.RegisterWorldPage("/events", "eventTypes.html", func(p Parms) any { return srv.context.world.AllEventTypes() }) srv.RegisterWorldPage("/events", "eventTypes.html", func(p Parms) any { return srv.context.world.AllEventTypes() })
@ -107,6 +102,21 @@ func StartServer(world *model.DfWorld, static embed.FS) {
http.ListenAndServe(":8080", srv.router) http.ListenAndServe(":8080", srv.router)
} }
func (srv *DfServer) findStructure(p Parms) any {
siteId, err := strconv.Atoi(p["siteId"])
if err != nil {
return nil
}
structureId, err := strconv.Atoi(p["id"])
if err != nil {
return nil
}
if site, ok := srv.context.world.Sites[siteId]; ok {
return site.Structures[structureId]
}
return nil
}
type spaHandler struct { type spaHandler struct {
server *DfServer server *DfServer
staticFS embed.FS staticFS embed.FS

6
backend/static/js/popper.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -11,6 +11,7 @@
<link href="/css/all.min.css" rel="stylesheet"> <link href="/css/all.min.css" rel="stylesheet">
<link href="/css/legends.css" rel="stylesheet"> <link href="/css/legends.css" rel="stylesheet">
<script src="/js/jquery-3.6.0.min.js"></script> <script src="/js/jquery-3.6.0.min.js"></script>
<script src="/js/popper.min.js"></script>
<script src="/js/bootstrap.min.js"></script> <script src="/js/bootstrap.min.js"></script>
<script src="/js/autocomplete.js"></script> <script src="/js/autocomplete.js"></script>
</head> </head>
@ -96,6 +97,17 @@
$('.nav-tabs button').on('click', function (e) { $('.nav-tabs button').on('click', function (e) {
window.location.hash = $(this).data("bs-target") window.location.hash = $(this).data("bs-target")
}); });
function loadLinkPopoverData() {
return $.ajax({
url: "/popover" + this.getAttribute("href"),
async: false
}).responseText;
}
$('a.entity,a.hf,a.region,a.site,a.structure,a.worldconstruction').each(function () {
var popover = new bootstrap.Popover($(this), { content: loadLinkPopoverData, trigger: "hover", placement: "top", html: true })
})
</script> </script>
</body> </body>

View File

@ -0,0 +1 @@
{{ .Race }} {{ .Type }}

View File

@ -0,0 +1,6 @@
{{if .Female }}
<i class="fa-solid fa-venus fa-xs"></i>
{{else}}
<i class="fa-solid fa-mars fa-xs"></i>
{{end}}
{{ .Race }} (*{{ .BirthYear }}{{ if ge .DeathYear 0 }} †{{ .DeathYear }}{{ end }})

View File

@ -0,0 +1 @@
{{ .Type }}

View File

@ -0,0 +1 @@
{{ .Type }}{{if .Ruin}} (ruin){{end}}

View File

@ -0,0 +1 @@
{{ .Type }} in {{ site .SiteId }}

View File

@ -0,0 +1 @@
{{ .Type }}