diff --git a/analyze/overwrites.json b/analyze/overwrites.json index be7ada2..7278bc1 100644 --- a/analyze/overwrites.json +++ b/analyze/overwrites.json @@ -77,12 +77,20 @@ "Name": "VampireSince", "Type": "int" }, + { + "Name": "NecromancerSince", + "Type": "int" + }, { "Name": "NecromancerSince", "Type": "int" } ], "Entity": [ + { + "Name": "Necromancer", + "Type": "bool" + }, { "Name": "Leaders", "Type": "[]*EntityLeader" diff --git a/backend/model/context.go b/backend/model/context.go index 513d2de..d1071cc 100644 --- a/backend/model/context.go +++ b/backend/model/context.go @@ -85,6 +85,18 @@ func hfIcon(x *HistoricalFigure) string { switch { case x.Leader: return ` ` + case x.Deity: + return ` ` + case x.Force: + return ` ` + case x.Adventurer: + return ` ` + case x.Necromancer: + return ` ` + case x.Werebeast: + return ` ` + case x.Vampire: + return ` ` } return "" } diff --git a/backend/model/extensions.go b/backend/model/extensions.go index 8b77ca3..db8ae22 100644 --- a/backend/model/extensions.go +++ b/backend/model/extensions.go @@ -96,6 +96,10 @@ func (e *Entity) Type() string { return e.Type_.String() } +func (e *Entity) Weapons() []string { + return util.Map(e.Weapon, func(w EntityWeapon) string { return w.String() }) +} + func (e *Entity) Position(id int) *EntityPosition { for _, p := range e.EntityPosition { if p.Id_ == id { diff --git a/backend/model/functions.go b/backend/model/functions.go index db20919..f5f9613 100644 --- a/backend/model/functions.go +++ b/backend/model/functions.go @@ -45,6 +45,8 @@ var AddMapSite = func(w *DfWorld, id int) template.HTML { } } +var AndList = func(s []string) template.HTML { return template.HTML(andList(s)) } + func andList(list []string) string { if len(list) > 1 { return strings.Join(list[:len(list)-1], ", ") + " and " + list[len(list)-1] diff --git a/backend/model/model.go b/backend/model/model.go index ba59433..04ec7c3 100644 --- a/backend/model/model.go +++ b/backend/model/model.go @@ -1991,6 +1991,7 @@ type Entity struct { Weapon []EntityWeapon `json:"weapon" legend:"plus" related:""` // weapon WorshipId []int `json:"worshipId" legend:"plus" related:""` // worship_id Leaders []*EntityLeader `json:"leaders" legend:"add" related:""` // Leaders + Necromancer bool `json:"necromancer" legend:"add" related:""` // Necromancer Sites []int `json:"sites" legend:"add" related:""` // Sites Wars []*HistoricalEventCollection `json:"wars" legend:"add" related:""` // Wars } @@ -2031,6 +2032,7 @@ func (x *Entity) MarshalJSON() ([]byte, error) { d["weapon"] = x.Weapon d["worshipId"] = x.WorshipId d["leaders"] = x.Leaders + d["necromancer"] = x.Necromancer d["sites"] = x.Sites d["wars"] = x.Wars return json.Marshal(d) diff --git a/backend/model/process.go b/backend/model/process.go index 6d5fdc7..17e5403 100644 --- a/backend/model/process.go +++ b/backend/model/process.go @@ -5,6 +5,7 @@ import ( "strings" "github.com/robertjanetzko/LegendsBrowser2/backend/util" + "golang.org/x/exp/maps" "golang.org/x/exp/slices" ) @@ -23,6 +24,14 @@ func (w *DfWorld) process() { w.processHistoricalFigures() for _, e := range w.Entities { + if len(e.Sites) > 0 { + if site, ok := w.Sites[e.Sites[0]]; ok { + if site.Type_ == SiteType_Tower { + e.Necromancer = true + } + } + } + idx := slices.Index(e.Child, e.Id_) if idx != -1 { e.Child = append(e.Child[:idx], e.Child[idx+1:]...) @@ -37,7 +46,10 @@ func (w *DfWorld) process() { } func (w *DfWorld) processEvents() { - for _, e := range w.HistoricalEvents { + list := maps.Values(w.HistoricalEvents) + sort.Slice(list, func(i, j int) bool { return list[i].Id_ < list[j].Id_ }) + + for _, e := range list { switch d := e.Details.(type) { case *HistoricalEventHfDoesInteraction: if strings.HasPrefix(d.Interaction, "DEITY_CURSE_WEREBEAST_") { @@ -123,7 +135,10 @@ func (w *DfWorld) processEvents() { } func (w *DfWorld) processCollections() { - for _, col := range w.HistoricalEventCollections { + list := maps.Values(w.HistoricalEventCollections) + sort.Slice(list, func(i, j int) bool { return list[i].Id_ < list[j].Id_ }) + + for _, col := range list { for _, eventId := range col.Event { if e, ok := w.HistoricalEvents[eventId]; ok { e.Collection = col.Id_ diff --git a/backend/server/server.go b/backend/server/server.go index 78d99ab..cc43aba 100644 --- a/backend/server/server.go +++ b/backend/server/server.go @@ -129,8 +129,10 @@ func StartServer(config *Config, world *model.DfWorld, static embed.FS) error { Civilizations map[string][]*model.Entity }{ Civilizations: groupBy(srv.context.world.Entities, - func(e *model.Entity) string { return e.Race }, - func(e *model.Entity) bool { return e.Name() != "" && e.Type_ == model.EntityType_Civilization }, + func(e *model.Entity) string { return util.If(e.Necromancer, "necromancer", e.Race) }, + func(e *model.Entity) bool { + return e.Name() != "" && (e.Type_ == model.EntityType_Civilization || e.Necromancer) + }, func(e *model.Entity) string { return e.Name() }), } }) diff --git a/backend/server/templates.go b/backend/server/templates.go index 26582f4..efcd829 100644 --- a/backend/server/templates.go +++ b/backend/server/templates.go @@ -23,6 +23,7 @@ func (srv *DfServer) LoadTemplates() { }, "title": util.Title, "kebab": func(s string) string { return strcase.ToKebab(s) }, + "andList": model.AndList, "world": func() *model.DfWorld { return srv.context.world }, "context": func(r any) *model.Context { return model.NewContext(srv.context.world, r) }, "initMap": func() template.HTML { diff --git a/backend/static/css/legends.css b/backend/static/css/legends.css index d2c924c..6868ec7 100644 --- a/backend/static/css/legends.css +++ b/backend/static/css/legends.css @@ -1,5 +1,6 @@ a { text-decoration: none; + white-space: nowrap; } .popover { diff --git a/backend/templates/entities.html b/backend/templates/entities.html index 4b4cec0..347332d 100644 --- a/backend/templates/entities.html +++ b/backend/templates/entities.html @@ -18,13 +18,37 @@ diff --git a/backend/templates/popoverEntity.html b/backend/templates/popoverEntity.html index be475ec..b12d6cf 100644 --- a/backend/templates/popoverEntity.html +++ b/backend/templates/popoverEntity.html @@ -1,4 +1,15 @@ {{ .Race }} {{ .Type }} +{{- if .Profession }} +of {{ .Profession }}s +{{- end }} +{{- if and (eq .Type "religion") (gt (len .WorshipId) 0) }} +
centered around the worship of {{ hfList .WorshipId }} +{{- end }} +{{- if eq .Type "militaryunit" }} {{- if gt (len .WorshipId) 0 }} -centered around the worship of {{ hfList .WorshipId }} +
devoted to the worship of {{ hfList .WorshipId }} +{{- end }} +{{- if gt (len .WorshipId) 0 }} +
dedicated to the mastery of {{ andList .Weapons }} +{{- end }} {{- end }} \ No newline at end of file