more details

This commit is contained in:
Robert Janetzko 2022-05-06 11:11:12 +00:00
parent b63c76f48c
commit 185a62dcc0
14 changed files with 105 additions and 18 deletions

View file

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

View file

@ -85,6 +85,18 @@ func hfIcon(x *HistoricalFigure) string {
switch {
case x.Leader:
return `<i class="fa-solid fa-crown fa-xs"></i> `
case x.Deity:
return `<i class="fa-solid fa-hands-holding fa-xs"></i> `
case x.Force:
return `<i class="fa-solid fa-hands-holding-circle fa-xs"></i> `
case x.Adventurer:
return `<i class="fa-solid fa-person-hiking fa-xs"></i> `
case x.Necromancer:
return `<i class="fa-solid fa-book-skull fa-xs"></i> `
case x.Werebeast:
return `<i class="fa-solid fa-moon fa-xs"></i> `
case x.Vampire:
return `<i class="fa-solid fa-droplet fa-xs"></i> `
}
return ""
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,5 +1,6 @@
a {
text-decoration: none;
white-space: nowrap;
}
.popover {

View file

@ -18,13 +18,37 @@
<div class="tab-pane{{ ifFirst $ $t " active" }}" id="nav-{{kebab $t}}" role="tabpanel" aria-labelledby="nav-home-tab">
<table class="table table-hover table-sm table-borderless object-table">
<tr>
<th width="100%">Name</th>
<th>Race</th>
<th>Name</th>
<th>
{{- if eq $t "guild" }}
Profession
{{- else if eq $t "religion" }}
Worshpipping
{{- else }}
Race
{{- end }}
</th>
{{- if eq $t "militaryunit" }}
<th width="50%">Worshpipping</th>
<th width="50%">Weapons</th>
{{- end }}
</tr>
{{- range $v }}{{- if not (eq .Name "") }}
<tr>
<td>{{ entity .Id }}</td>
<td>{{ .Race }}</td>
<td>
{{- if eq $t "guild" }}
{{ .Profession }}s
{{- else if eq $t "religion" }}
{{ hfList .WorshipId }}
{{- else }}
{{ .Race }}
{{- end }}
</td>
{{- if eq $t "militaryunit" }}
<td style="white-space: normal;">{{ hfList .WorshipId }}</td>
<td style="white-space: normal;">{{ andList .Weapons }}</td>
{{- end }}
</tr>
{{- end}}{{- end}}
</table>

View file

@ -5,10 +5,21 @@
{{define "content"}}
<h3>{{ title .Name }}</h3>
<p>
{{ .Race }} {{ .Type }}
{{- if gt (len .WorshipId) 0 }}
{{ .Race }}{{ if .Necromancer}} necromancer{{end}} {{ .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 }}
devoted to the worship of {{ hfList .WorshipId }}
{{- end }}
{{- if gt (len .WorshipId) 0 }}
, dedicated to the mastery of {{ andList .Weapons }}
{{- end }}
{{- end }}
</p>
<nav>

View file

@ -127,7 +127,8 @@
<ul>
{{- range $i := .IntriguePlot }}
<li>
{{ .Type_ }}{{if .OnHold}} (on hold){{end}}
{{ .Type_ }} {{ if ne .ArtifactId -1 }}{{ artifact .ArtifactId}}{{end}}
{{if .OnHold}} (on hold){{end}}
</li>
{{- end }}
</ul>

View file

@ -73,13 +73,6 @@
onInput: value => $.get("/search?term=" + value, data => ac.setData(data)),
onSelectItem: ({ label, value }) => window.location = value
});
// later, when you need to change the dataset
ac.setData([
{ label: 'New York JFK', value: 'JFK' },
{ label: 'Moscow SVO', value: 'SVO' },
]);
</script>
</div>
</div>

View file

@ -1,4 +1,15 @@
{{ .Race }} {{ .Type }}
{{- if .Profession }}
of {{ .Profession }}s
{{- end }}
{{- if and (eq .Type "religion") (gt (len .WorshipId) 0) }}
<br />centered around the worship of {{ hfList .WorshipId }}
{{- end }}
{{- if eq .Type "militaryunit" }}
{{- if gt (len .WorshipId) 0 }}
centered around the worship of {{ hfList .WorshipId }}
<br />devoted to the worship of {{ hfList .WorshipId }}
{{- end }}
{{- if gt (len .WorshipId) 0 }}
<br />dedicated to the mastery of {{ andList .Weapons }}
{{- end }}
{{- end }}