diff --git a/analyze/df/generate_backend.go b/analyze/df/generate_backend.go index 199c457..a79fbc8 100644 --- a/analyze/df/generate_backend.go +++ b/analyze/df/generate_backend.go @@ -374,7 +374,12 @@ func (f Field) StartAction(obj Object, plus bool) string { gen := fmt.Sprintf("parse%s", *f.ElementType) if f.Type == "array" { - return fmt.Sprintf("parseArray(p, &obj.%s, %s)", f.Name, gen) + if !plus { + return fmt.Sprintf("parseArray(p, &obj.%s, %s)", f.Name, gen) + } else { + gen = fmt.Sprintf("parse%sPlus", *f.ElementType) + return fmt.Sprintf("parseArrayPlus(p, &obj.%s, %s)", f.Name, gen) + } } if f.Type == "map" { diff --git a/analyze/overwrites.json b/analyze/overwrites.json index 90d0ce0..c014960 100644 --- a/analyze/overwrites.json +++ b/analyze/overwrites.json @@ -74,6 +74,12 @@ "Type": "int" } ], + "HistoricalEventAddHfHfLink": [ + { + "Name": "Relationship", + "Type": "HistoricalEventRelationshipRelationship" + } + ], "HistoricalEventCollectionAbduction": [ { "Name": "TargetHfids", diff --git a/backend/model/events.go b/backend/model/events.go index 985cd3c..c947e4c 100644 --- a/backend/model/events.go +++ b/backend/model/events.go @@ -58,12 +58,15 @@ func (x *HistoricalEventAddHfHfLink) Html(c *Context) string { case HistoricalEventAddHfHfLinkLinkType_Master: return h + " began an apprenticeship under " + t case HistoricalEventAddHfHfLinkLinkType_PetOwner: - return h + " became the owner of " + t + return t + " became the owner of " + h case HistoricalEventAddHfHfLinkLinkType_Prisoner: return h + " imprisoned " + t case HistoricalEventAddHfHfLinkLinkType_Spouse: return h + " married " + t default: + if x.Relationship != HistoricalEventRelationshipRelationship_Unknown { + return h + " and " + t + " became " + x.Relationship.String() + "s" // TODO Texts + } return h + " LINKED TO " + t } } @@ -883,7 +886,6 @@ func (x *HistoricalEventHfDied) Html(c *Context) string { if x.SlayerItemId != -1 { slayer += " with " + c.artifact(x.SlayerItemId) - } else { } switch x.Cause { case HistoricalEventHfDiedCause_Behead, HistoricalEventHfDiedCause_ExecBeheaded: diff --git a/backend/model/map.go b/backend/model/map.go index d1a3fac..ea6426b 100644 --- a/backend/model/map.go +++ b/backend/model/map.go @@ -5,7 +5,6 @@ import ( "fmt" "image" "image/png" - _ "image/png" "io/ioutil" "os" "path/filepath" diff --git a/backend/model/model.go b/backend/model/model.go index 4799a80..0578b71 100644 --- a/backend/model/model.go +++ b/backend/model/model.go @@ -3035,9 +3035,10 @@ func (s HistoricalEventAddHfHfLinkLinkType) MarshalJSON() ([]byte, error) { } type HistoricalEventAddHfHfLink struct { - Hfid int `json:"hfid" legend:"base"` // hfid - HfidTarget int `json:"hfidTarget" legend:"base"` // hfid_target - LinkType HistoricalEventAddHfHfLinkLinkType `json:"linkType" legend:"plus"` // link_type + Hfid int `json:"hfid" legend:"base"` // hfid + HfidTarget int `json:"hfidTarget" legend:"base"` // hfid_target + LinkType HistoricalEventAddHfHfLinkLinkType `json:"linkType" legend:"plus"` // link_type + Relationship HistoricalEventRelationshipRelationship `json:"relationship" legend:"add"` // Relationship } func NewHistoricalEventAddHfHfLink() *HistoricalEventAddHfHfLink { @@ -3075,6 +3076,7 @@ func (x *HistoricalEventAddHfHfLink) MarshalJSON() ([]byte, error) { if x.LinkType != 0 { d["linkType"] = x.LinkType } + d["relationship"] = x.Relationship return json.Marshal(d) } @@ -23016,7 +23018,7 @@ func parseDfWorldPlus(p *util.XMLParser, obj *DfWorld) (*DfWorld, error) { case "artifacts": parseMapPlus(p, &obj.Artifacts, parseArtifactPlus) case "creature_raw": - parseArray(p, &obj.CreatureRaw, parseCreature) + parseArrayPlus(p, &obj.CreatureRaw, parseCreaturePlus) case "dance_forms": parseMapPlus(p, &obj.DanceForms, parseDanceFormPlus) case "entities": @@ -23024,13 +23026,13 @@ func parseDfWorldPlus(p *util.XMLParser, obj *DfWorld) (*DfWorld, error) { case "entity_populations": parseMapPlus(p, &obj.EntityPopulations, parseEntityPopulationPlus) case "historical_eras": - parseArray(p, &obj.HistoricalEras, parseHistoricalEra) + parseArrayPlus(p, &obj.HistoricalEras, parseHistoricalEraPlus) case "historical_event_collections": parseMapPlus(p, &obj.HistoricalEventCollections, parseHistoricalEventCollectionPlus) case "historical_event_relationship_supplements": - parseArray(p, &obj.HistoricalEventRelationshipSupplements, parseHistoricalEventRelationshipSupplement) + parseArrayPlus(p, &obj.HistoricalEventRelationshipSupplements, parseHistoricalEventRelationshipSupplementPlus) case "historical_event_relationships": - parseArray(p, &obj.HistoricalEventRelationships, parseHistoricalEventRelationship) + parseArrayPlus(p, &obj.HistoricalEventRelationships, parseHistoricalEventRelationshipPlus) case "historical_events": parseMapPlus(p, &obj.HistoricalEvents, parseHistoricalEventPlus) case "historical_figures": @@ -23054,7 +23056,7 @@ func parseDfWorldPlus(p *util.XMLParser, obj *DfWorld) (*DfWorld, error) { case "regions": parseMapPlus(p, &obj.Regions, parseRegionPlus) case "rivers": - parseArray(p, &obj.Rivers, parseRiver) + parseArrayPlus(p, &obj.Rivers, parseRiverPlus) case "sites": parseMapPlus(p, &obj.Sites, parseSitePlus) case "underground_regions": diff --git a/backend/model/parse.go b/backend/model/parse.go index 193d48e..d6964aa 100644 --- a/backend/model/parse.go +++ b/backend/model/parse.go @@ -166,6 +166,24 @@ func parseArray[T any](p *util.XMLParser, dest *[]T, creator func(*util.XMLParse } } +func parseArrayPlus[T any](p *util.XMLParser, dest *[]T, creator func(*util.XMLParser, T) (T, error)) { + for { + t, _, err := p.Token() + if err != nil { + return // nil, err + } + switch t { + case util.StartElement: + var x T + x, _ = creator(p, x) + *dest = append(*dest, x) + + case util.EndElement: + return + } + } +} + func parseMap[T Identifiable](p *util.XMLParser, dest *map[int]T, creator func(*util.XMLParser) (T, error)) { for { t, _, err := p.Token() diff --git a/backend/model/process.go b/backend/model/process.go index 92bd556..4ed9ad7 100644 --- a/backend/model/process.go +++ b/backend/model/process.go @@ -1,6 +1,7 @@ package model import ( + "fmt" "strings" "github.com/robertjanetzko/LegendsBrowser2/backend/util" @@ -8,6 +9,7 @@ import ( ) func (w *DfWorld) process() { + w.addRelationshipEvents() // set site in structure for _, site := range w.Sites { @@ -139,3 +141,18 @@ 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, + Details: &HistoricalEventAddHfHfLink{ + Hfid: r.SourceHf, + HfidTarget: r.TargetHf, + Relationship: r.Relationship, + }, + } + } +}