relationship events

This commit is contained in:
Robert Janetzko 2022-05-04 07:26:26 +00:00
parent 849349b7fd
commit 97cdf624be
7 changed files with 61 additions and 12 deletions

View file

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

View file

@ -74,6 +74,12 @@
"Type": "int"
}
],
"HistoricalEventAddHfHfLink": [
{
"Name": "Relationship",
"Type": "HistoricalEventRelationshipRelationship"
}
],
"HistoricalEventCollectionAbduction": [
{
"Name": "TargetHfids",

View file

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

View file

@ -5,7 +5,6 @@ import (
"fmt"
"image"
"image/png"
_ "image/png"
"io/ioutil"
"os"
"path/filepath"

View file

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

View file

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

View file

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