same fields

This commit is contained in:
Robert Janetzko 2022-04-18 08:36:29 +00:00
parent cbc9601c33
commit 5f200e7fd5
14 changed files with 16520 additions and 1593 deletions

11888
analyze/analyze.json Normal file

File diff suppressed because it is too large Load diff

View file

@ -24,6 +24,10 @@ func Generate() error {
return err
}
// if err := generateEventsCode(m); err != nil {
// return err
// }
if err := generateFrontendCode(m); err != nil {
return err
}

View file

@ -23,11 +23,34 @@ import (
"fmt"
)
func InitSameFields() {
sameFields = map[string]map[string]map[string]bool{
{{- range $name, $obj := $.Objects }}
"{{$obj.Name}}": {
{{- range $field := ($obj.LegendFields "plus") }}
{{- if ne 0 (len ($obj.LegendFields "base")) }}
"{{$field.Name}}": {
{{- range $field2 := ($obj.LegendFields "base") }}
{{- if eq $field.Type $field2.Type }}
"{{ $field2.Name }}": true,
{{- end }}
{{- end }}
},
{{- end }}
{{- end }}
},
{{- end }}
}
}
{{- range $name, $obj := $.Objects }}
type {{ $obj.Name }} struct {
{{- range $fname, $field := $obj.Fields }}
{{- if not (and (eq $fname "type") (not (not $obj.SubTypes))) }}
{{ $field.TypeLine }}
{{- if not ($field.SameField $obj) }}
{{ $field.TypeLine }} // {{ $fname }}
{{- end }}
{{- end }}
{{- end }}
{{- if not (not $obj.SubTypes) }}
@ -41,7 +64,29 @@ func (x *{{ $obj.Name }}) Id() int { return x.Id_ }
{{- if $obj.Named }}
func (x *{{ $obj.Name }}) Name() string { return x.Name_ }
{{- end }}
func (x *{{ $obj.Name }}) RelatedToHf(id int) bool { return {{ $obj.Related "hfid,hf_id,_hf,hist_figure_id,Hfid,histfig_id,histfig" }} }
func (x *{{ $obj.Name }}) RelatedToEntity(id int) bool { return {{ $obj.Related "civId,civ_id,entity_id,entity" }} }
func (x *{{ $obj.Name }}) RelatedToHf(id int) bool { return {{ $obj.Related "hfid,hf_id,_hf,hist_figure_id,Hfid,histfig_id,histfig,bodies" }} }
func (x *{{ $obj.Name }}) CheckFields() {
{{- range $field := ($obj.LegendFields "plus") }}
{{- if not ($field.SameField $obj) }}
{{- range $field2 := ($obj.LegendFields "base") }}
{{- if eq $field.Type $field2.Type }}
{{- if eq $field.Type "int" }}
if x.{{ $field.Name}} != x.{{ $field2.Name}} && x.{{ $field.Name}} != 0 && x.{{ $field2.Name}} != 0 {
sameFields["{{$obj.Name}}"]["{{ $field.Name}}"]["{{ $field2.Name}}"] = false
}
{{- end }}
{{- if eq $field.Type "string" }}
if x.{{ $field.Name}} != x.{{ $field2.Name}} && x.{{ $field.Name}} != "" && x.{{ $field2.Name}} != "" {
sameFields["{{$obj.Name}}"]["{{ $field.Name}}"]["{{ $field2.Name}}"] = false
}
{{- end }} {{- end }}
{{- end }}
{{- end }}
{{- end }}
}
{{- end }}
// Parser
@ -94,6 +139,7 @@ func parse{{ $obj.Name }}{{ if $plus }}Plus{{ end }}(d *xml.Decoder, start *xml.
case xml.EndElement:
if t.Name.Local == start.Name.Local {
obj.CheckFields()
return obj, nil
}
@ -133,7 +179,7 @@ func parse{{ $obj.Name }}{{ if $plus }}Plus{{ end }}(d *xml.Decoder, start *xml.
return obj, nil
{{- else }}
{{ $field.EndAction }}
{{ $field.EndAction $obj }}
{{- end }}
{{- end }}{{- end }}
default:
@ -146,7 +192,23 @@ func parse{{ $obj.Name }}{{ if $plus }}Plus{{ end }}(d *xml.Decoder, start *xml.
{{- end }}
`))
var sameFields map[string]map[string]string
func LoadSameFields() error {
data, err := ioutil.ReadFile("same.json")
if err != nil {
return err
}
sameFields = make(map[string]map[string]string)
json.Unmarshal(data, &sameFields)
return nil
}
func generateBackendCode(objects *Metadata) error {
LoadSameFields()
fmt.Println(sameFields["HistoricalEventAddHfEntityLink"])
file, _ := json.MarshalIndent(objects, "", " ")
_ = ioutil.WriteFile("model.json", file, 0644)
@ -254,11 +316,13 @@ func (f Field) StartAction(plus bool) string {
return ""
}
func (f Field) EndAction() string {
func (f Field) EndAction(obj Object) string {
n := f.Name
if n == "Id" || n == "Name" {
n = n + "_"
} else {
n = f.CorrectedName(obj)
}
if !f.Multiple {
@ -284,8 +348,12 @@ func (obj Object) Related(fields string) string {
var list []string
fs := strings.Split(fields, ",")
for n, f := range obj.Fields {
if f.Type == "int" && !f.Multiple && util.ContainsAny(n, fs...) {
list = append(list, fmt.Sprintf("x.%s == id", f.Name))
if f.Type == "int" && util.ContainsAny(n, fs...) && !f.SameField(obj) {
if !f.Multiple {
list = append(list, fmt.Sprintf("x.%s == id", f.Name))
} else {
list = append(list, fmt.Sprintf("containsInt(x.%s, id)", f.Name))
}
}
}
if len(list) > 0 {
@ -293,3 +361,33 @@ func (obj Object) Related(fields string) string {
}
return "false"
}
func (obj Object) LegendFields(t string) []Field {
var list []Field
for _, f := range obj.Fields {
if f.Name != "Name" && f.Name != "Id" && f.Name != "Type" && f.Legend == t && f.Type != "object" && !f.Multiple {
list = append(list, f)
}
}
return list
}
func (f Field) SameField(obj Object) bool {
if f.Legend != "plus" {
return false
}
_, ok := sameFields[obj.Name][f.Name]
// fmt.Println(obj.Name, f.Name, ok)
return ok
}
func (f Field) CorrectedName(obj Object) string {
if f.Legend != "plus" {
return f.Name
}
n, ok := sameFields[obj.Name][f.Name]
if ok {
return n
}
return f.Name
}

View file

@ -0,0 +1,55 @@
package df
import (
"bytes"
"encoding/json"
"fmt"
"go/format"
"io/ioutil"
"os"
"text/template"
)
var eventsTemplate = template.Must(template.New("").Parse(`// Code generated by legendsbrowser; DO NOT EDIT.
package model
{{- range $name, $obj := $.Objects }}
{{- if $obj.IsSubTypeOf "HistoricalEvent" }}
func (x *{{ $obj.Name }}) Html() string { return "UNKNWON {{ $obj.Name }}" }
{{- end }}
{{- end }}
`))
func generateEventsCode(objects *Metadata) error {
file, _ := json.MarshalIndent(objects, "", " ")
_ = ioutil.WriteFile("model.json", file, 0644)
f, err := os.Create("../backend/model/events.go")
if err != nil {
return err
}
defer f.Close()
var buf bytes.Buffer
err = eventsTemplate.Execute(&buf, struct {
Objects *Metadata
Modes []bool
}{
Objects: objects,
Modes: []bool{false, true},
})
if err != nil {
return err
}
p, err := format.Source(buf.Bytes())
if err != nil {
fmt.Println("WARN: could not format source", err)
p = buf.Bytes()
}
_, err = f.Write(p)
return err
}
func (o Object) IsSubTypeOf(t string) bool {
return o.SubTypeOf != nil && *o.SubTypeOf == t
}

119
analyze/same.json Normal file
View file

@ -0,0 +1,119 @@
{
"HistoricalEventAddHfEntityLink": {
"Civ": "CivId",
"Histfig": "Hfid",
"LinkType": "Link"
},
"HistoricalEventAddHfHfLink": {
"Hf": "Hfid",
"HfTarget": "HfidTarget"
},
"HistoricalEventAddHfSiteLink": {
"Site": "SiteId"
},
"HistoricalEventArtifactCreated": {
"CreatorHfid": "HistFigureId",
"CreatorUnitId": "UnitId",
"Site": "SiteId"
},
"HistoricalEventAssumeIdentity": {
"IdentityHistfigId": "TricksterHfid",
"IdentityNemesisId": "TricksterHfid",
"Target": "TargetEnid",
"Trickster": "TricksterHfid"
},
"HistoricalEventBodyAbused": {
"Site": "SiteId"
},
"HistoricalEventChangeHfJob": {
"Site": "SiteId"
},
"HistoricalEventChangeHfState": {
"Site": "SiteId"
},
"HistoricalEventChangedCreatureType": {
"Changee": "ChangeeHfid",
"Changer": "ChangerHfid"
},
"HistoricalEventCreatedStructure": {
"BuilderHf": "BuilderHfid",
"Civ": "CivId",
"Site": "SiteId",
"SiteCiv": "SiteCivId"
},
"HistoricalEventCreatureDevoured": {
"Site": "SiteId"
},
"HistoricalEventEntityPrimaryCriminals": {
"Entity": "EntityId",
"Site": "SiteId",
"Structure": "StructureId"
},
"HistoricalEventEntityRelocate": {
"Entity": "EntityId",
"Site": "SiteId",
"Structure": "StructureId"
},
"HistoricalEventHfDied": {
"ArtifactId": "SlayerItemId",
"Item": "SlayerItemId",
"ItemSubtype": "Cause",
"Mat": "Cause",
"Site": "SiteId",
"SlayerHf": "SlayerHfid",
"VictimHf": "Hfid"
},
"HistoricalEventHfDisturbedStructure": {
"Histfig": "HistFigId",
"Site": "SiteId",
"Structure": "StructureId"
},
"HistoricalEventHfDoesInteraction": {
"Doer": "DoerHfid",
"Target": "TargetHfid"
},
"HistoricalEventHfLearnsSecret": {
"Artifact": "ArtifactId",
"Student": "StudentHfid",
"Teacher": "TeacherHfid"
},
"HistoricalEventHfNewPet": {
"Group": "GroupHfid",
"Site": "SiteId"
},
"HistoricalEventHfPrayedInsideStructure": {
"Histfig": "HistFigId",
"Site": "SiteId",
"Structure": "StructureId"
},
"HistoricalEventHfProfanedStructure": {
"Histfig": "HistFigId",
"Site": "SiteId",
"Structure": "StructureId"
},
"HistoricalEventHfWounded": {
"Site": "SiteId",
"Woundee": "WoundeeHfid",
"Wounder": "WounderHfid"
},
"HistoricalEventPeaceAccepted": {
"Site": "SiteId"
},
"HistoricalEventPeaceRejected": {
"Site": "SiteId"
},
"HistoricalEventRemoveHfEntityLink": {
"Civ": "CivId",
"Histfig": "Hfid",
"LinkType": "Link"
},
"HistoricalEventRemoveHfSiteLink": {
"Site": "SiteId"
},
"Structure": {
"Name2": "Subtype"
},
"WrittenContent": {
"Author": "AuthorHfid"
}
}

View file

@ -11,6 +11,7 @@ import (
_ "net/http/pprof"
"os"
"runtime"
"sort"
"strconv"
"strings"
@ -65,6 +66,12 @@ func main() {
id := obj.Id()
var list []*model.HistoricalEvent
switch obj.(type) {
case *model.Entity:
for _, e := range world.HistoricalEvents {
if e.Details.RelatedToEntity(id) {
list = append(list, e)
}
}
case *model.HistoricalFigure:
for _, e := range world.HistoricalEvents {
if e.Details.RelatedToHf(id) {
@ -74,8 +81,33 @@ func main() {
default:
fmt.Printf("unknown type %T\n", obj)
}
sort.Slice(list, func(a, b int) bool { return list[a].Id_ < list[b].Id_ })
return list
},
"season": func(seconds int) string {
r := ""
month := seconds % 100800
if month <= 33600 {
r += "early "
} else if month <= 67200 {
r += "mid"
} else if month <= 100800 {
r += "late "
}
season := seconds % 403200
if season < 100800 {
r += "spring"
} else if season < 201600 {
r += "summer"
} else if season < 302400 {
r += "autumn"
} else if season < 403200 {
r += "winter"
}
return r
},
}
t := templates.New(functions)

209
backend/model/events.go Normal file
View file

@ -0,0 +1,209 @@
// Code generated by legendsbrowser; DO NOT EDIT.
package model
func (x *HistoricalEventAddHfEntityHonor) Html() string {
return "UNKNWON HistoricalEventAddHfEntityHonor"
}
func (x *HistoricalEventAddHfEntityLink) Html() string {
return "UNKNWON HistoricalEventAddHfEntityLink"
}
func (x *HistoricalEventAddHfHfLink) Html() string { return "UNKNWON HistoricalEventAddHfHfLink" }
func (x *HistoricalEventAddHfSiteLink) Html() string { return "UNKNWON HistoricalEventAddHfSiteLink" }
func (x *HistoricalEventAgreementFormed) Html() string {
return "UNKNWON HistoricalEventAgreementFormed"
}
func (x *HistoricalEventArtifactClaimFormed) Html() string {
return "UNKNWON HistoricalEventArtifactClaimFormed"
}
func (x *HistoricalEventArtifactCopied) Html() string { return "UNKNWON HistoricalEventArtifactCopied" }
func (x *HistoricalEventArtifactCreated) Html() string {
return "UNKNWON HistoricalEventArtifactCreated"
}
func (x *HistoricalEventArtifactDestroyed) Html() string {
return "UNKNWON HistoricalEventArtifactDestroyed"
}
func (x *HistoricalEventArtifactFound) Html() string { return "UNKNWON HistoricalEventArtifactFound" }
func (x *HistoricalEventArtifactGiven) Html() string { return "UNKNWON HistoricalEventArtifactGiven" }
func (x *HistoricalEventArtifactLost) Html() string { return "UNKNWON HistoricalEventArtifactLost" }
func (x *HistoricalEventArtifactPossessed) Html() string {
return "UNKNWON HistoricalEventArtifactPossessed"
}
func (x *HistoricalEventArtifactRecovered) Html() string {
return "UNKNWON HistoricalEventArtifactRecovered"
}
func (x *HistoricalEventArtifactStored) Html() string { return "UNKNWON HistoricalEventArtifactStored" }
func (x *HistoricalEventAssumeIdentity) Html() string { return "UNKNWON HistoricalEventAssumeIdentity" }
func (x *HistoricalEventAttackedSite) Html() string { return "UNKNWON HistoricalEventAttackedSite" }
func (x *HistoricalEventBodyAbused) Html() string { return "UNKNWON HistoricalEventBodyAbused" }
func (x *HistoricalEventBuildingProfileAcquired) Html() string {
return "UNKNWON HistoricalEventBuildingProfileAcquired"
}
func (x *HistoricalEventCeremony) Html() string { return "UNKNWON HistoricalEventCeremony" }
func (x *HistoricalEventChangeHfBodyState) Html() string {
return "UNKNWON HistoricalEventChangeHfBodyState"
}
func (x *HistoricalEventChangeHfJob) Html() string { return "UNKNWON HistoricalEventChangeHfJob" }
func (x *HistoricalEventChangeHfState) Html() string { return "UNKNWON HistoricalEventChangeHfState" }
func (x *HistoricalEventChangedCreatureType) Html() string {
return "UNKNWON HistoricalEventChangedCreatureType"
}
func (x *HistoricalEventCompetition) Html() string { return "UNKNWON HistoricalEventCompetition" }
func (x *HistoricalEventCreateEntityPosition) Html() string {
return "UNKNWON HistoricalEventCreateEntityPosition"
}
func (x *HistoricalEventCreatedSite) Html() string { return "UNKNWON HistoricalEventCreatedSite" }
func (x *HistoricalEventCreatedStructure) Html() string {
return "UNKNWON HistoricalEventCreatedStructure"
}
func (x *HistoricalEventCreatedWorldConstruction) Html() string {
return "UNKNWON HistoricalEventCreatedWorldConstruction"
}
func (x *HistoricalEventCreatureDevoured) Html() string {
return "UNKNWON HistoricalEventCreatureDevoured"
}
func (x *HistoricalEventDanceFormCreated) Html() string {
return "UNKNWON HistoricalEventDanceFormCreated"
}
func (x *HistoricalEventDestroyedSite) Html() string { return "UNKNWON HistoricalEventDestroyedSite" }
func (x *HistoricalEventEntityAllianceFormed) Html() string {
return "UNKNWON HistoricalEventEntityAllianceFormed"
}
func (x *HistoricalEventEntityBreachFeatureLayer) Html() string {
return "UNKNWON HistoricalEventEntityBreachFeatureLayer"
}
func (x *HistoricalEventEntityCreated) Html() string { return "UNKNWON HistoricalEventEntityCreated" }
func (x *HistoricalEventEntityDissolved) Html() string {
return "UNKNWON HistoricalEventEntityDissolved"
}
func (x *HistoricalEventEntityEquipmentPurchase) Html() string {
return "UNKNWON HistoricalEventEntityEquipmentPurchase"
}
func (x *HistoricalEventEntityIncorporated) Html() string {
return "UNKNWON HistoricalEventEntityIncorporated"
}
func (x *HistoricalEventEntityLaw) Html() string { return "UNKNWON HistoricalEventEntityLaw" }
func (x *HistoricalEventEntityOverthrown) Html() string {
return "UNKNWON HistoricalEventEntityOverthrown"
}
func (x *HistoricalEventEntityPersecuted) Html() string {
return "UNKNWON HistoricalEventEntityPersecuted"
}
func (x *HistoricalEventEntityPrimaryCriminals) Html() string {
return "UNKNWON HistoricalEventEntityPrimaryCriminals"
}
func (x *HistoricalEventEntityRelocate) Html() string { return "UNKNWON HistoricalEventEntityRelocate" }
func (x *HistoricalEventFailedFrameAttempt) Html() string {
return "UNKNWON HistoricalEventFailedFrameAttempt"
}
func (x *HistoricalEventFailedIntrigueCorruption) Html() string {
return "UNKNWON HistoricalEventFailedIntrigueCorruption"
}
func (x *HistoricalEventFieldBattle) Html() string { return "UNKNWON HistoricalEventFieldBattle" }
func (x *HistoricalEventGamble) Html() string { return "UNKNWON HistoricalEventGamble" }
func (x *HistoricalEventHfAbducted) Html() string { return "UNKNWON HistoricalEventHfAbducted" }
func (x *HistoricalEventHfAttackedSite) Html() string { return "UNKNWON HistoricalEventHfAttackedSite" }
func (x *HistoricalEventHfConfronted) Html() string { return "UNKNWON HistoricalEventHfConfronted" }
func (x *HistoricalEventHfConvicted) Html() string { return "UNKNWON HistoricalEventHfConvicted" }
func (x *HistoricalEventHfDestroyedSite) Html() string {
return "UNKNWON HistoricalEventHfDestroyedSite"
}
func (x *HistoricalEventHfDied) Html() string { return "UNKNWON HistoricalEventHfDied" }
func (x *HistoricalEventHfDisturbedStructure) Html() string {
return "UNKNWON HistoricalEventHfDisturbedStructure"
}
func (x *HistoricalEventHfDoesInteraction) Html() string {
return "UNKNWON HistoricalEventHfDoesInteraction"
}
func (x *HistoricalEventHfEnslaved) Html() string { return "UNKNWON HistoricalEventHfEnslaved" }
func (x *HistoricalEventHfEquipmentPurchase) Html() string {
return "UNKNWON HistoricalEventHfEquipmentPurchase"
}
func (x *HistoricalEventHfGainsSecretGoal) Html() string {
return "UNKNWON HistoricalEventHfGainsSecretGoal"
}
func (x *HistoricalEventHfInterrogated) Html() string { return "UNKNWON HistoricalEventHfInterrogated" }
func (x *HistoricalEventHfLearnsSecret) Html() string { return "UNKNWON HistoricalEventHfLearnsSecret" }
func (x *HistoricalEventHfNewPet) Html() string { return "UNKNWON HistoricalEventHfNewPet" }
func (x *HistoricalEventHfPerformedHorribleExperiments) Html() string {
return "UNKNWON HistoricalEventHfPerformedHorribleExperiments"
}
func (x *HistoricalEventHfPrayedInsideStructure) Html() string {
return "UNKNWON HistoricalEventHfPrayedInsideStructure"
}
func (x *HistoricalEventHfPreach) Html() string { return "UNKNWON HistoricalEventHfPreach" }
func (x *HistoricalEventHfProfanedStructure) Html() string {
return "UNKNWON HistoricalEventHfProfanedStructure"
}
func (x *HistoricalEventHfRecruitedUnitTypeForEntity) Html() string {
return "UNKNWON HistoricalEventHfRecruitedUnitTypeForEntity"
}
func (x *HistoricalEventHfRelationshipDenied) Html() string {
return "UNKNWON HistoricalEventHfRelationshipDenied"
}
func (x *HistoricalEventHfReunion) Html() string { return "UNKNWON HistoricalEventHfReunion" }
func (x *HistoricalEventHfRevived) Html() string { return "UNKNWON HistoricalEventHfRevived" }
func (x *HistoricalEventHfSimpleBattleEvent) Html() string {
return "UNKNWON HistoricalEventHfSimpleBattleEvent"
}
func (x *HistoricalEventHfTravel) Html() string { return "UNKNWON HistoricalEventHfTravel" }
func (x *HistoricalEventHfViewedArtifact) Html() string {
return "UNKNWON HistoricalEventHfViewedArtifact"
}
func (x *HistoricalEventHfWounded) Html() string { return "UNKNWON HistoricalEventHfWounded" }
func (x *HistoricalEventHfsFormedIntrigueRelationship) Html() string {
return "UNKNWON HistoricalEventHfsFormedIntrigueRelationship"
}
func (x *HistoricalEventHfsFormedReputationRelationship) Html() string {
return "UNKNWON HistoricalEventHfsFormedReputationRelationship"
}
func (x *HistoricalEventHolyCityDeclaration) Html() string {
return "UNKNWON HistoricalEventHolyCityDeclaration"
}
func (x *HistoricalEventItemStolen) Html() string { return "UNKNWON HistoricalEventItemStolen" }
func (x *HistoricalEventKnowledgeDiscovered) Html() string {
return "UNKNWON HistoricalEventKnowledgeDiscovered"
}
func (x *HistoricalEventMasterpieceItem) Html() string {
return "UNKNWON HistoricalEventMasterpieceItem"
}
func (x *HistoricalEventMerchant) Html() string { return "UNKNWON HistoricalEventMerchant" }
func (x *HistoricalEventModifiedBuilding) Html() string {
return "UNKNWON HistoricalEventModifiedBuilding"
}
func (x *HistoricalEventMusicalFormCreated) Html() string {
return "UNKNWON HistoricalEventMusicalFormCreated"
}
func (x *HistoricalEventNewSiteLeader) Html() string { return "UNKNWON HistoricalEventNewSiteLeader" }
func (x *HistoricalEventPeaceAccepted) Html() string { return "UNKNWON HistoricalEventPeaceAccepted" }
func (x *HistoricalEventPeaceRejected) Html() string { return "UNKNWON HistoricalEventPeaceRejected" }
func (x *HistoricalEventPerformance) Html() string { return "UNKNWON HistoricalEventPerformance" }
func (x *HistoricalEventPlunderedSite) Html() string { return "UNKNWON HistoricalEventPlunderedSite" }
func (x *HistoricalEventPoeticFormCreated) Html() string {
return "UNKNWON HistoricalEventPoeticFormCreated"
}
func (x *HistoricalEventProcession) Html() string { return "UNKNWON HistoricalEventProcession" }
func (x *HistoricalEventRazedStructure) Html() string { return "UNKNWON HistoricalEventRazedStructure" }
func (x *HistoricalEventReclaimSite) Html() string { return "UNKNWON HistoricalEventReclaimSite" }
func (x *HistoricalEventRegionpopIncorporatedIntoEntity) Html() string {
return "UNKNWON HistoricalEventRegionpopIncorporatedIntoEntity"
}
func (x *HistoricalEventRemoveHfEntityLink) Html() string {
return "UNKNWON HistoricalEventRemoveHfEntityLink"
}
func (x *HistoricalEventRemoveHfHfLink) Html() string { return "UNKNWON HistoricalEventRemoveHfHfLink" }
func (x *HistoricalEventRemoveHfSiteLink) Html() string {
return "UNKNWON HistoricalEventRemoveHfSiteLink"
}
func (x *HistoricalEventReplacedStructure) Html() string {
return "UNKNWON HistoricalEventReplacedStructure"
}
func (x *HistoricalEventSiteDispute) Html() string { return "UNKNWON HistoricalEventSiteDispute" }
func (x *HistoricalEventSiteTakenOver) Html() string { return "UNKNWON HistoricalEventSiteTakenOver" }
func (x *HistoricalEventSquadVsSquad) Html() string { return "UNKNWON HistoricalEventSquadVsSquad" }
func (x *HistoricalEventTacticalSituation) Html() string {
return "UNKNWON HistoricalEventTacticalSituation"
}
func (x *HistoricalEventTrade) Html() string { return "UNKNWON HistoricalEventTrade" }
func (x *HistoricalEventWrittenContentComposed) Html() string {
return "UNKNWON HistoricalEventWrittenContentComposed"
}

View file

@ -10,8 +10,19 @@ func (e *Entity) Position(id int) *EntityPosition {
}
type HistoricalEventDetails interface {
RelatedToEntity(int) bool
RelatedToHf(int) bool
Html() string
}
type HistoricalEventCollectionDetails interface {
}
func containsInt(list []int, id int) bool {
for _, v := range list {
if v == id {
return true
}
}
return false
}

File diff suppressed because it is too large Load diff

View file

@ -1,8 +1,10 @@
package model
import (
"encoding/json"
"encoding/xml"
"fmt"
"io/ioutil"
"log"
"os"
"strconv"
@ -15,6 +17,8 @@ func (e *HistoricalEvent) Name() string { return "" }
func (e *HistoricalEventCollection) Name() string { return "" }
func Parse(file string) (*DfWorld, error) {
InitSameFields()
xmlFile, err := os.Open(file)
if err != nil {
fmt.Println(err)
@ -80,6 +84,12 @@ BaseLoop:
}
}
same, err := json.MarshalIndent(exportSameFields(), "", " ")
if err != nil {
return world, err
}
ioutil.WriteFile("same.json", same, 0644)
return world, nil
}
@ -165,3 +175,31 @@ func parseId(d *xml.Decoder) (int, error) {
}
}
}
var sameFields map[string]map[string]map[string]bool
func exportSameFields() map[string]map[string]string {
export := make(map[string]map[string]string)
for objectType, v := range sameFields {
fields := make(map[string]string)
for field, v2 := range v {
c := 0
f := ""
for field2, same := range v2 {
if same {
c++
f = field2
}
}
if c == 1 {
fields[field] = f
}
}
if len(fields) > 0 {
export[objectType] = fields
}
}
return export
}

49
backend/same.json Normal file
View file

@ -0,0 +1,49 @@
{
"Artifact": {
"Writing": "StructureLocalId"
},
"HistoricalEventAddHfEntityLink": {
"LinkType": "Link"
},
"HistoricalEventAddHfSiteLink": {
"Site": "SiteId"
},
"HistoricalEventCreatedStructure": {
"Structure": "StructureId"
},
"HistoricalEventHfDied": {
"ItemSubtype": "Cause",
"Mat": "Cause"
},
"HistoricalEventHfDoesInteraction": {
"InteractionAction": "Interaction"
},
"HistoricalEventHfLearnsSecret": {
"SecretText": "Interaction"
},
"HistoricalEventMasterpieceItem": {
"Maker": "Hfid",
"MakerEntity": "EntityId",
"Site": "SiteId"
},
"HistoricalEventMerchant": {
"Destination": "DepotEntityId",
"Site": "SiteId",
"Source": "TraderEntityId"
},
"HistoricalEventPeaceAccepted": {
"Site": "SiteId"
},
"HistoricalEventPeaceRejected": {
"Site": "SiteId"
},
"HistoricalEventRemoveHfEntityLink": {
"LinkType": "Link"
},
"HistoricalEventRemoveHfSiteLink": {
"Site": "SiteId"
},
"Structure": {
"Name2": "Subtype"
}
}

View file

@ -3,5 +3,12 @@
{{define "title"}}{{ title .Name }}{{end}}
{{define "content"}}
{{ json . }}
<h1>{{ title .Name }}</h1>
{{ .Race }} {{ .Type }}
<h3>Events</h3>
{{ template "events.html" . }}
<p>{{ json . }}</p>
{{- end }}

View file

@ -1,7 +1,8 @@
<ul>
{{- range $event := events . }}
<li>
{{ $event.Id }} in of {{ $event.Year }} {{ json $event.Details }}
[{{ $event.Id }}] In {{ if gt $event.Seconds72 -1 }}{{ season $event.Seconds72 }} of {{ end }}{{ $event.Year }} {{
$event.Details.Html }} {{ json $event.Details }}
</li>
{{- end}}
</ul>

View file

@ -1461,7 +1461,7 @@ export interface IntriguePlot {
onHold: boolean;
parentPlotHfid: number;
parentPlotId: number;
plotActor: PlotActor;
plotActor: PlotActor[];
type: string;
}
export interface Item {