From e9cde0f17cfb5047405e903dfcc3b7bfcc6d4cfd Mon Sep 17 00:00:00 2001 From: Robert Janetzko Date: Thu, 5 May 2022 14:55:57 +0000 Subject: [PATCH] entity details --- analyze/df/generate_backend.go | 2 +- analyze/overwrites.json | 20 +++++ backend/conf.json | 4 +- backend/model/context.go | 41 +++++++++- backend/model/events.go | 6 +- backend/model/functions.go | 1 + backend/model/model.go | 65 +++++++++------ backend/model/process.go | 40 +++++++++ backend/server/templates.go | 1 + backend/templates/entity.html | 116 +++++++++++++++++++++++---- backend/templates/events.html | 2 +- backend/templates/hf.html | 6 +- backend/templates/popoverEntity.html | 5 +- backend/templates/site.html | 2 +- 14 files changed, 260 insertions(+), 51 deletions(-) diff --git a/analyze/df/generate_backend.go b/analyze/df/generate_backend.go index 9864cd3..6d013f3 100644 --- a/analyze/df/generate_backend.go +++ b/analyze/df/generate_backend.go @@ -460,7 +460,7 @@ func (f Field) EndAction(obj Object) string { return "" } -var entityRegex, _ = regexp.Compile("(civ|civ_id|enid|[^d]*entity(_id)?|^entity(_id)?|^source|^destination|^involved)(_?[0-9])?$") +var entityRegex, _ = regexp.Compile("(civ|civ_id|enid|(^|[^d])entity(_id)?|^entity(_id)?|^source|^destination|^involved)(_?[0-9])?$") var hfRegex, _ = regexp.Compile("(hfid|hf_id|hist_figure_id|histfig_id|histfig|bodies|_hf)") var artifactRegex, _ = regexp.Compile("(item(_id)?|artifact_id)$") var siteRegex, _ = regexp.Compile("(site_id|site)[0-9]?$") diff --git a/analyze/overwrites.json b/analyze/overwrites.json index 3476422..5db4fee 100644 --- a/analyze/overwrites.json +++ b/analyze/overwrites.json @@ -60,12 +60,32 @@ { "Name": "Vampire", "Type": "bool" + }, + { + "Name": "Necromancer", + "Type": "bool" + }, + { + "Name": "WerebeastSince", + "Type": "int" + }, + { + "Name": "VampireSince", + "Type": "int" + }, + { + "Name": "NecromancerSince", + "Type": "int" } ], "Entity": [ { "Name": "Sites", "Type": "[]int" + }, + { + "Name": "Wars", + "Type": "[]*HistoricalEventCollection" } ], "Site": [ diff --git a/backend/conf.json b/backend/conf.json index 22910a3..4615bf9 100644 --- a/backend/conf.json +++ b/backend/conf.json @@ -1,5 +1,5 @@ { - "LastPath": "/workspaces/legendsbrowser/inputs", - "LastFile": "/workspaces/legendsbrowser/inputs/Stalkmatches-00254-08-26-legends.xml", + "LastPath": "/workspaces/legendsbrowser/inputs/legends-Runlance-01510-01-01", + "LastFile": "/workspaces/legendsbrowser/inputs/legends-Runlance-01510-01-01/Runlance-01510-01-01-legends.xml", "DebugTemplates": true } \ No newline at end of file diff --git a/backend/model/context.go b/backend/model/context.go index 8aaad42..33266f9 100644 --- a/backend/model/context.go +++ b/backend/model/context.go @@ -11,6 +11,7 @@ type Context struct { World *DfWorld HfId int Story bool + Event *HistoricalEvent } func NewContext(w *DfWorld, ref any) *Context { @@ -24,6 +25,12 @@ func NewContext(w *DfWorld, ref any) *Context { return c } +func (c *Context) WithEvent(e *HistoricalEvent) *Context { + c2 := *c + c2.Event = e + return &c2 +} + func (c *Context) hf(id int) string { if c.HfId != -1 { if c.HfId == id { @@ -33,7 +40,17 @@ func (c *Context) hf(id int) string { } } if x, ok := c.World.HistoricalFigures[id]; ok { - return fmt.Sprintf(`the %s %s`, x.Race+util.If(x.Deity, " deity", "")+util.If(x.Force, " force", ""), x.Id(), util.Title(x.Name())) + return hf(x) + } + return "UNKNOWN HISTORICAL FIGURE" +} + +func (c *Context) hfUnrelated(id int) string { + if c.HfId != -1 && c.HfId == id { + return c.hfShort(id) + } + if x, ok := c.World.HistoricalFigures[id]; ok { + return hf(x) } return "UNKNOWN HISTORICAL FIGURE" } @@ -59,11 +76,31 @@ func (c *Context) hfRelated(id, to int) string { return fmt.Sprintf(`%s %s %s`, t.PossesivePronoun(), y.LinkType, x.Id(), util.Title(x.Name())) } } - return fmt.Sprintf(`the %s %s`, x.Race+util.If(x.Deity, " deity", "")+util.If(x.Force, " force", ""), x.Id(), util.Title(x.Name())) + return hf(x) } return "UNKNOWN HISTORICAL FIGURE" } +func hf(x *HistoricalFigure) string { + r := x.Race + if x.Deity { + r += " deity" + } + if x.Force { + r += " deity" + } + if x.Necromancer { + r += " necromancer" + } + if x.Werebeast { + r += " werebeast" + } + if x.Vampire { + r += " vampire" + } + return fmt.Sprintf(`the %s %s`, r, x.Id(), util.Title(x.Name())) +} + func (c *Context) hfList(ids []int) string { return andList(util.Map(ids, func(id int) string { return c.hf(id) })) } diff --git a/backend/model/events.go b/backend/model/events.go index 90559dc..b1851f0 100644 --- a/backend/model/events.go +++ b/backend/model/events.go @@ -44,8 +44,8 @@ func (x *HistoricalEventAddHfEntityLink) Html(c *Context) string { } func (x *HistoricalEventAddHfHfLink) Html(c *Context) string { - h := c.hf(x.Hfid) - t := c.hf(x.HfidTarget) + h := c.hfUnrelated(x.Hfid) + t := c.hfUnrelated(x.HfidTarget) switch x.LinkType { case HistoricalEventAddHfHfLinkLinkType_Apprentice: return h + " became the master of " + t @@ -2056,7 +2056,7 @@ func (x *HistoricalEventRemoveHfEntityLink) Html(c *Context) string { } func (x *HistoricalEventRemoveHfHfLink) Html(c *Context) string { - return c.hf(x.Hfid) + " divorced " + c.hfRelated(x.HfidTarget, x.Hfid) + return c.hfUnrelated(x.Hfid) + " divorced " + c.hfUnrelated(x.HfidTarget) } func (x *HistoricalEventRemoveHfSiteLink) Html(c *Context) string { diff --git a/backend/model/functions.go b/backend/model/functions.go index 604fb4c..99815b4 100644 --- a/backend/model/functions.go +++ b/backend/model/functions.go @@ -9,6 +9,7 @@ import ( ) var LinkHf = func(w *DfWorld, id int) template.HTML { return template.HTML((&Context{World: w}).hf(id)) } +var LinkHfList = func(w *DfWorld, id []int) template.HTML { return template.HTML((&Context{World: w}).hfList(id)) } var LinkEntity = func(w *DfWorld, id int) template.HTML { return template.HTML((&Context{World: w}).entity(id)) } var LinkSite = func(w *DfWorld, id int) template.HTML { return template.HTML((&Context{World: w}).site(id, "")) } var LinkStructure = func(w *DfWorld, siteId, id int) template.HTML { diff --git a/backend/model/model.go b/backend/model/model.go index d36fde7..b05594b 100644 --- a/backend/model/model.go +++ b/backend/model/model.go @@ -1975,22 +1975,23 @@ func (s EntityWeapon) MarshalJSON() ([]byte, error) { } type Entity struct { - Child []int `json:"child" legend:"plus" related:""` // child - Claims string `json:"claims" legend:"plus" related:""` // claims - EntityLink []*EntityEntityLink `json:"entityLink" legend:"plus" related:""` // entity_link - EntityPosition []*EntityPosition `json:"entityPosition" legend:"plus" related:""` // entity_position - EntityPositionAssignment []*EntityPositionAssignment `json:"entityPositionAssignment" legend:"plus" related:""` // entity_position_assignment - HistfigId []int `json:"histfigId" legend:"plus" related:""` // histfig_id - Honor []*Honor `json:"honor" legend:"base" related:""` // honor - Id_ int `json:"id" legend:"both" related:""` // id - Name_ string `json:"name" legend:"base" related:""` // name - Occasion []*Occasion `json:"occasion" legend:"plus" related:""` // occasion - Profession EntityProfession `json:"profession" legend:"plus" related:""` // profession - Race string `json:"race" legend:"plus" related:""` // race - Type_ EntityType `json:"type" legend:"plus" related:""` // type - Weapon []EntityWeapon `json:"weapon" legend:"plus" related:""` // weapon - WorshipId []int `json:"worshipId" legend:"plus" related:""` // worship_id - Sites []int `json:"sites" legend:"add" related:""` // Sites + Child []int `json:"child" legend:"plus" related:""` // child + Claims string `json:"claims" legend:"plus" related:""` // claims + EntityLink []*EntityEntityLink `json:"entityLink" legend:"plus" related:""` // entity_link + EntityPosition []*EntityPosition `json:"entityPosition" legend:"plus" related:""` // entity_position + EntityPositionAssignment []*EntityPositionAssignment `json:"entityPositionAssignment" legend:"plus" related:""` // entity_position_assignment + HistfigId []int `json:"histfigId" legend:"plus" related:""` // histfig_id + Honor []*Honor `json:"honor" legend:"base" related:""` // honor + Id_ int `json:"id" legend:"both" related:""` // id + Name_ string `json:"name" legend:"base" related:""` // name + Occasion []*Occasion `json:"occasion" legend:"plus" related:""` // occasion + Profession EntityProfession `json:"profession" legend:"plus" related:""` // profession + Race string `json:"race" legend:"plus" related:""` // race + Type_ EntityType `json:"type" legend:"plus" related:""` // type + Weapon []EntityWeapon `json:"weapon" legend:"plus" related:""` // weapon + WorshipId []int `json:"worshipId" legend:"plus" related:""` // worship_id + Sites []int `json:"sites" legend:"add" related:""` // Sites + Wars []*HistoricalEventCollection `json:"wars" legend:"add" related:""` // Wars } func NewEntity() *Entity { @@ -2029,6 +2030,7 @@ func (x *Entity) MarshalJSON() ([]byte, error) { d["weapon"] = x.Weapon d["worshipId"] = x.WorshipId d["sites"] = x.Sites + d["wars"] = x.Wars return json.Marshal(d) } @@ -4818,10 +4820,8 @@ func NewHistoricalEventAssumeIdentity() *HistoricalEventAssumeIdentity { TricksterHfid: -1, } } -func (x *HistoricalEventAssumeIdentity) Type() string { return "assume identity" } -func (x *HistoricalEventAssumeIdentity) RelatedToEntity(id int) bool { - return x.IdentityId == id || x.TargetEnid == id -} +func (x *HistoricalEventAssumeIdentity) Type() string { return "assume identity" } +func (x *HistoricalEventAssumeIdentity) RelatedToEntity(id int) bool { return x.TargetEnid == id } func (x *HistoricalEventAssumeIdentity) RelatedToHf(id int) bool { return x.TricksterHfid == id } func (x *HistoricalEventAssumeIdentity) RelatedToArtifact(id int) bool { return false } func (x *HistoricalEventAssumeIdentity) RelatedToSite(id int) bool { return false } @@ -9064,7 +9064,7 @@ func NewHistoricalEventFailedIntrigueCorruption() *HistoricalEventFailedIntrigue } func (x *HistoricalEventFailedIntrigueCorruption) Type() string { return "failed intrigue corruption" } func (x *HistoricalEventFailedIntrigueCorruption) RelatedToEntity(id int) bool { - return x.CorruptorIdentity == id || x.RelevantEntityId == id || x.TargetIdentity == id + return x.RelevantEntityId == id } func (x *HistoricalEventFailedIntrigueCorruption) RelatedToHf(id int) bool { return x.CorruptorHfid == id || x.LureHfid == id || x.TargetHfid == id @@ -12879,7 +12879,7 @@ func (x *HistoricalEventHfsFormedIntrigueRelationship) Type() string { return "hfs formed intrigue relationship" } func (x *HistoricalEventHfsFormedIntrigueRelationship) RelatedToEntity(id int) bool { - return x.CorruptorIdentity == id || x.RelevantEntityId == id || x.TargetIdentity == id + return x.RelevantEntityId == id } func (x *HistoricalEventHfsFormedIntrigueRelationship) RelatedToHf(id int) bool { return x.CorruptorHfid == id || x.LureHfid == id || x.TargetHfid == id @@ -13086,9 +13086,7 @@ func NewHistoricalEventHfsFormedReputationRelationship() *HistoricalEventHfsForm func (x *HistoricalEventHfsFormedReputationRelationship) Type() string { return "hfs formed reputation relationship" } -func (x *HistoricalEventHfsFormedReputationRelationship) RelatedToEntity(id int) bool { - return x.IdentityId1 == id || x.IdentityId2 == id -} +func (x *HistoricalEventHfsFormedReputationRelationship) RelatedToEntity(id int) bool { return false } func (x *HistoricalEventHfsFormedReputationRelationship) RelatedToHf(id int) bool { return x.Hfid1 == id || x.Hfid2 == id } @@ -18902,8 +18900,12 @@ type HistoricalFigure struct { Sphere []string `json:"sphere" legend:"base" related:""` // sphere UsedIdentityId []int `json:"usedIdentityId" legend:"base" related:""` // used_identity_id VagueRelationship []*VagueRelationship `json:"vagueRelationship" legend:"base" related:""` // vague_relationship + Necromancer bool `json:"necromancer" legend:"add" related:""` // Necromancer + NecromancerSince int `json:"necromancerSince" legend:"add" related:""` // NecromancerSince Vampire bool `json:"vampire" legend:"add" related:""` // Vampire + VampireSince int `json:"vampireSince" legend:"add" related:""` // VampireSince Werebeast bool `json:"werebeast" legend:"add" related:""` // Werebeast + WerebeastSince int `json:"werebeastSince" legend:"add" related:""` // WerebeastSince } func NewHistoricalFigure() *HistoricalFigure { @@ -18918,6 +18920,9 @@ func NewHistoricalFigure() *HistoricalFigure { EntPopId: -1, Id_: -1, Sex: -1, + NecromancerSince: -1, + VampireSince: -1, + WerebeastSince: -1, } } func (x *HistoricalFigure) Id() int { return x.Id_ } @@ -19017,8 +19022,18 @@ func (x *HistoricalFigure) MarshalJSON() ([]byte, error) { d["sphere"] = x.Sphere d["usedIdentityId"] = x.UsedIdentityId d["vagueRelationship"] = x.VagueRelationship + d["necromancer"] = x.Necromancer + if x.NecromancerSince != -1 { + d["necromancerSince"] = x.NecromancerSince + } d["vampire"] = x.Vampire + if x.VampireSince != -1 { + d["vampireSince"] = x.VampireSince + } d["werebeast"] = x.Werebeast + if x.WerebeastSince != -1 { + d["werebeastSince"] = x.WerebeastSince + } return json.Marshal(d) } diff --git a/backend/model/process.go b/backend/model/process.go index fd9c24a..6d5fdc7 100644 --- a/backend/model/process.go +++ b/backend/model/process.go @@ -1,6 +1,7 @@ package model import ( + "sort" "strings" "github.com/robertjanetzko/LegendsBrowser2/backend/util" @@ -19,6 +20,15 @@ func (w *DfWorld) process() { w.processEvents() w.processCollections() + w.processHistoricalFigures() + + for _, e := range w.Entities { + idx := slices.Index(e.Child, e.Id_) + if idx != -1 { + e.Child = append(e.Child[:idx], e.Child[idx+1:]...) + } + sort.Slice(e.Wars, func(i, j int) bool { return e.Wars[i].Id_ < e.Wars[j].Id_ }) + } // check events texts for _, e := range w.HistoricalEvents { @@ -32,9 +42,16 @@ func (w *DfWorld) processEvents() { case *HistoricalEventHfDoesInteraction: if strings.HasPrefix(d.Interaction, "DEITY_CURSE_WEREBEAST_") { w.HistoricalFigures[d.TargetHfid].Werebeast = true + w.HistoricalFigures[d.TargetHfid].WerebeastSince = e.Year } if strings.HasPrefix(d.Interaction, "DEITY_CURSE_VAMPIRE_") { w.HistoricalFigures[d.TargetHfid].Vampire = true + w.HistoricalFigures[d.TargetHfid].VampireSince = e.Year + } + case *HistoricalEventHfLearnsSecret: + if strings.HasPrefix(d.Interaction, "SECRET_") { + w.HistoricalFigures[d.StudentHfid].Necromancer = true + w.HistoricalFigures[d.StudentHfid].NecromancerSince = e.Year } case *HistoricalEventCreatedSite: w.addEntitySite(d.CivId, d.SiteId) @@ -174,6 +191,13 @@ func (w *DfWorld) processCollections() { } } } + case *HistoricalEventCollectionWar: + if e, ok := w.Entities[cd.AggressorEntId]; ok { + e.Wars = append(e.Wars, col) + } + if e, ok := w.Entities[cd.DefenderEntId]; ok { + e.Wars = append(e.Wars, col) + } } } } @@ -202,3 +226,19 @@ func (w *DfWorld) addRelationshipEvents() { } } } + +func (w *DfWorld) processHistoricalFigures() { + // for _, hf := range w.HistoricalFigures { + // for _, i := range hf.ActiveInteraction { + // if strings.HasPrefix(i, "DEITY_CURSE_WEREBEAST_") { + // hf.Werebeast = true + // } + // if strings.HasPrefix(i, "DEITY_CURSE_VAMPIRE_") { + // hf.Vampire = true + // } + // if strings.HasPrefix(i, "SECRET_") { + // hf.Necromancer = true + // } + // } + // } +} diff --git a/backend/server/templates.go b/backend/server/templates.go index 941f807..791dd58 100644 --- a/backend/server/templates.go +++ b/backend/server/templates.go @@ -31,6 +31,7 @@ func (srv *DfServer) LoadTemplates() { }, "hf": func(id int) template.HTML { return model.LinkHf(srv.context.world, id) }, "getHf": func(id int) *model.HistoricalFigure { return srv.context.world.HistoricalFigures[id] }, + "hfList": func(ids []int) template.HTML { return model.LinkHfList(srv.context.world, ids) }, "entity": func(id int) template.HTML { return model.LinkEntity(srv.context.world, id) }, "getEntity": func(id int) *model.Entity { return srv.context.world.Entities[id] }, "site": func(id int) template.HTML { return model.LinkSite(srv.context.world, id) }, diff --git a/backend/templates/entity.html b/backend/templates/entity.html index 949616a..7e0f00d 100644 --- a/backend/templates/entity.html +++ b/backend/templates/entity.html @@ -3,22 +3,110 @@ {{define "title"}}{{ title .Name }}{{end}} {{define "content"}} -

{{ title .Name }}

-{{ .Race }} {{ .Type }} - -
Sites
- - {{- range .Sites }} - - - - +

{{ title .Name }}

+

+ {{ .Race }} {{ .Type }} + {{- if gt (len .WorshipId) 0 }} + centered around the worship of {{ hfList .WorshipId }} {{- end }} -

{{ site . }} {{ template "events.html" events (history .) }}
-{{- if ne 0 (len .Sites) }} -{{- end }} +

-

Events

+ + + +
Events
{{ template "events.html" events . }} diff --git a/backend/templates/events.html b/backend/templates/events.html index 79852e3..8fbcff9 100644 --- a/backend/templates/events.html +++ b/backend/templates/events.html @@ -2,7 +2,7 @@ {{- range $event := .Events }}
  • [{{ $event.Id }}] In {{ time $event.Year $event.Seconds72 }}, - {{ html ($event.Details.Html $.Context) }} + {{ html ($event.Details.Html ($.Context.WithEvent $event)) }} {{ if ne .Collection -1 }} {{end}} {{ json $event.Details }} diff --git a/backend/templates/hf.html b/backend/templates/hf.html index 075140f..96615d4 100644 --- a/backend/templates/hf.html +++ b/backend/templates/hf.html @@ -9,7 +9,11 @@ {{else}} {{end}} -{{ .Race }} (*{{ .BirthYear }}{{ if ge .DeathYear 0 }} †{{ .DeathYear }}{{ end }}) +{{ .Race }} +{{ if .Vampire}}vampire{{end}} +{{ if .Werebeast}}werebeast{{end}} +{{ if .Necromancer}}necromancer{{end}} +(*{{ .BirthYear }}{{ if ge .DeathYear 0 }} †{{ .DeathYear }}{{ end }})
    diff --git a/backend/templates/popoverEntity.html b/backend/templates/popoverEntity.html index 0505acd..be475ec 100644 --- a/backend/templates/popoverEntity.html +++ b/backend/templates/popoverEntity.html @@ -1 +1,4 @@ -{{ .Race }} {{ .Type }} \ No newline at end of file +{{ .Race }} {{ .Type }} +{{- if gt (len .WorshipId) 0 }} +centered around the worship of {{ hfList .WorshipId }} +{{- end }} \ No newline at end of file diff --git a/backend/templates/site.html b/backend/templates/site.html index d129cec..98b138b 100644 --- a/backend/templates/site.html +++ b/backend/templates/site.html @@ -27,7 +27,7 @@ {{- range .Structures }} {{ structure $.Id .Id }} - {{ .Type }} + {{ .Type }}{{if .Ruin}} (ruin){{end}} {{- end}}