diff --git a/backend/model/context.go b/backend/model/context.go index e2a1d9a..514497c 100644 --- a/backend/model/context.go +++ b/backend/model/context.go @@ -170,21 +170,34 @@ func (c *Context) place(structureId, siteId int, sitePrefix string, regionId int func (c *Context) mountain(id int) string { if x, ok := c.World.MountainPeaks[id]; ok { - return fmt.Sprintf(`%s`, x.Id(), util.Title(x.Name())) + return fmt.Sprintf(` %s`, + x.Id(), util.If(x.IsVolcano, "fa-volcano", "fa-mountain"), util.Title(x.Name())) } return "UNKNOWN MOUNTAIN" } +func (c *Context) landmass(id int) string { + if x, ok := c.World.Landmasses[id]; ok { + return fmt.Sprintf(`%s`, x.Id(), util.Title(x.Name())) + } + return "UNKNOWN LANDMASS" +} + +func (c *Context) river(id int) string { + x := c.World.Rivers[id] + return fmt.Sprintf(`%s`, id, util.Title(x.Name())) +} + func (c *Context) identity(id int) string { if x, ok := c.World.Identities[id]; ok { - return fmt.Sprintf(`%s`, x.Id(), util.Title(x.Name())) + return fmt.Sprintf(`%s`, x.Id(), util.Title(x.Name())) } return "UNKNOWN IDENTITY" } func (c *Context) fullIdentity(id int) string { if x, ok := c.World.Identities[id]; ok { - return fmt.Sprintf(`"the %s %s of %s"`, x.Profession.String(), x.Id(), util.Title(x.Name()), c.entity(x.EntityId)) + return fmt.Sprintf(`"the %s %s of %s"`, x.Profession.String(), x.Id(), util.Title(x.Name()), c.entity(x.EntityId)) } return "UNKNOWN IDENTITY" } diff --git a/backend/model/extensions.go b/backend/model/extensions.go index c02bd52..8b77ca3 100644 --- a/backend/model/extensions.go +++ b/backend/model/extensions.go @@ -105,6 +105,10 @@ func (e *Entity) Position(id int) *EntityPosition { return &EntityPosition{Name_: "UNKNOWN POSITION"} } +func (e *Entity) PositionByIndex(index int) *EntityPosition { + return e.EntityPosition[len(e.EntityPosition)-1-index] +} + func (p *EntityPosition) GenderName(hf *HistoricalFigure) string { if hf.Female() && p.NameFemale != "" { return p.NameFemale diff --git a/backend/model/functions.go b/backend/model/functions.go index 5a4b840..604fb4c 100644 --- a/backend/model/functions.go +++ b/backend/model/functions.go @@ -24,6 +24,9 @@ var LinkMusicalForm = func(w *DfWorld, id int) template.HTML { return template.H var LinkPoeticForm = func(w *DfWorld, id int) template.HTML { return template.HTML((&Context{World: w}).poeticForm(id)) } var LinkWrittenContent = func(w *DfWorld, id int) template.HTML { return template.HTML((&Context{World: w}).writtenContent(id)) } var LinkCollection = func(w *DfWorld, id int) template.HTML { return template.HTML((&Context{World: w}).collection(id)) } +var LinkMountain = func(w *DfWorld, id int) template.HTML { return template.HTML((&Context{World: w}).mountain(id)) } +var LinkLandmass = func(w *DfWorld, id int) template.HTML { return template.HTML((&Context{World: w}).landmass(id)) } +var LinkRiver = func(w *DfWorld, id int) template.HTML { return template.HTML((&Context{World: w}).river(id)) } var AddMapSite = func(w *DfWorld, id int) template.HTML { if site, ok := w.Sites[id]; ok { diff --git a/backend/model/process.go b/backend/model/process.go index 4ed9ad7..3f12d8d 100644 --- a/backend/model/process.go +++ b/backend/model/process.go @@ -1,7 +1,6 @@ package model import ( - "fmt" "strings" "github.com/robertjanetzko/LegendsBrowser2/backend/util" @@ -57,6 +56,21 @@ func (w *DfWorld) processEvents() { w.addEntitySite(d.SiteCivId, d.SiteId) w.addEntitySite(d.SiteCivId, d.SiteId) w.Sites[d.SiteId].Ruin = false + case *HistoricalEventAddHfEntityLink: + if d.Link == HistoricalEventAddHfEntityLinkLink_Position { + if hf, ok := w.HistoricalFigures[d.Hfid]; ok { + for _, l := range hf.EntityPositionLink { + if l.EntityId == d.CivId && l.StartYear == e.Year { + l.PositionProfileId = d.PositionId + } + } + for _, l := range hf.EntityFormerPositionLink { + if l.EntityId == d.CivId && l.StartYear == e.Year { + l.PositionProfileId = d.PositionId + } + } + } + } } } } @@ -144,7 +158,6 @@ func (w *DfWorld) addEntitySite(entityId, siteId int) { func (w *DfWorld) addRelationshipEvents() { for _, r := range w.HistoricalEventRelationships { - fmt.Println(r) w.HistoricalEvents[r.Event] = &HistoricalEvent{ Id_: r.Event, Year: r.Year, diff --git a/backend/server/server.go b/backend/server/server.go index 0711f7a..5ed4fed 100644 --- a/backend/server/server.go +++ b/backend/server/server.go @@ -50,6 +50,22 @@ func StartServer(world *model.DfWorld, static embed.FS) error { 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("/geography", "geography.html", func(p Parms) any { + return &struct { + Regions map[string][]*model.Region + Landmasses map[string][]*model.Landmass + MountainPeaks map[string][]*model.MountainPeak + Rivers map[string][]*model.River + }{ + Regions: singleGroup(srv.context.world.Regions, "region"), + Landmasses: singleGroup(srv.context.world.Landmasses, "landmass"), + MountainPeaks: singleGroup(srv.context.world.MountainPeaks, "mountain"), + Rivers: map[string][]*model.River{ + "rivers": srv.context.world.Rivers, + }, + } + }) + srv.RegisterWorldPage("/regions", "regions.html", func(p Parms) any { return groupByType(srv.context.world.Regions) }) 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] }) @@ -194,6 +210,10 @@ func flatGrouped[K comparable, U any, V namedTyped](input map[K]U, mapper func(U return output } +func singleGroup[K comparable, T model.Named](input map[K]T, group string) map[string][]T { + return groupBy(input, func(t T) string { return group }, func(t T) bool { return t.Name() != "" }, func(t T) string { return t.Name() }) +} + func groupByType[K comparable, T namedTyped](input map[K]T) map[string][]T { return groupBy(input, func(t T) string { return t.Type() }, func(t T) bool { return t.Name() != "" }, func(t T) string { return t.Name() }) } diff --git a/backend/server/templates.go b/backend/server/templates.go index 074a285..33a8758 100644 --- a/backend/server/templates.go +++ b/backend/server/templates.go @@ -47,8 +47,9 @@ func (srv *DfServer) LoadTemplates() { "musicalForm": func(id int) template.HTML { return model.LinkMusicalForm(srv.context.world, id) }, "poeticForm": func(id int) template.HTML { return model.LinkPoeticForm(srv.context.world, id) }, "writtenContent": func(id int) template.HTML { return model.LinkWrittenContent(srv.context.world, id) }, - "landmass": func(id int) template.HTML { return model.LinkWrittenContent(srv.context.world, id) }, // TODO - "mountain": func(id int) template.HTML { return model.LinkWrittenContent(srv.context.world, id) }, // TODO + "landmass": func(id int) template.HTML { return model.LinkLandmass(srv.context.world, id) }, + "mountain": func(id int) template.HTML { return model.LinkMountain(srv.context.world, id) }, + "river": func(id int) template.HTML { return model.LinkRiver(srv.context.world, id) }, "events": func(obj any) *model.EventList { return model.NewEventList(srv.context.world, obj) }, diff --git a/backend/static/css/legends.css b/backend/static/css/legends.css index c04af5e..99762d6 100644 --- a/backend/static/css/legends.css +++ b/backend/static/css/legends.css @@ -2,6 +2,10 @@ a { text-decoration: none; } +.popover { + max-width: fit-content; +} + .object-table td { white-space: nowrap; } diff --git a/backend/templates/artforms.html b/backend/templates/artforms.html index 84ffc22..002087f 100644 --- a/backend/templates/artforms.html +++ b/backend/templates/artforms.html @@ -1,9 +1,9 @@ {{template "layout.html" .}} -{{define "title"}}Artifacts{{end}} +{{define "title"}}Art Forms{{end}} {{define "content"}} -

Artifacts

+

Art Forms