diff --git a/analyze/df/analyze.go b/analyze/df/analyze.go index 8733cfb..31c3798 100644 --- a/analyze/df/analyze.go +++ b/analyze/df/analyze.go @@ -151,15 +151,27 @@ func CreateMetadata(a *AnalyzeData) (*Metadata, error) { } } + additional := make(map[string]Field) + if afs, ok := a.Overwrites.AdditionalFields[typeNames[k]]; ok { + for _, add := range afs { + additional[add.Name] = Field{ + Name: add.Name, + Type: add.Type, + Legend: "add", + } + } + } + objects[typeNames[k]] = Object{ - Name: typeNames[k], - Id: a.Fields[k+PATH_SEPARATOR+"id"] != nil, - Named: a.Fields[k+PATH_SEPARATOR+"name"] != nil, - Typed: a.Fields[k+PATH_SEPARATOR+"type"] != nil, - SubTypes: getSubtypes(a, k), - SubTypeOf: getSubtypeOf(k), - SubType: getSubtype(k), - Fields: objFields, + Name: typeNames[k], + Id: a.Fields[k+PATH_SEPARATOR+"id"] != nil, + Named: a.Fields[k+PATH_SEPARATOR+"name"] != nil, + Typed: a.Fields[k+PATH_SEPARATOR+"type"] != nil, + SubTypes: getSubtypes(a, k), + SubTypeOf: getSubtypeOf(k), + SubType: getSubtype(k), + Fields: objFields, + Additional: additional, } } } diff --git a/analyze/df/generate.go b/analyze/df/generate.go index c9c1967..41edb9d 100644 --- a/analyze/df/generate.go +++ b/analyze/df/generate.go @@ -7,14 +7,15 @@ import ( ) type Object struct { - Name string `json:"name"` - Id bool `json:"id,omitempty"` - Named bool `json:"named,omitempty"` - Typed bool `json:"typed,omitempty"` - SubTypes *[]Subtype `json:"subtypes,omitempty"` - SubTypeOf *string `json:"subtypeof,omitempty"` - SubType *string `json:"subtype,omitempty"` - Fields map[string]Field `json:"fields"` + Name string `json:"name"` + Id bool `json:"id,omitempty"` + Named bool `json:"named,omitempty"` + Typed bool `json:"typed,omitempty"` + SubTypes *[]Subtype `json:"subtypes,omitempty"` + SubTypeOf *string `json:"subtypeof,omitempty"` + SubType *string `json:"subtype,omitempty"` + Fields map[string]Field `json:"fields"` + Additional map[string]Field `json:"additional"` } type Subtype struct { diff --git a/analyze/df/generate_backend.go b/analyze/df/generate_backend.go index 948fbe0..ce932f5 100644 --- a/analyze/df/generate_backend.go +++ b/analyze/df/generate_backend.go @@ -102,6 +102,9 @@ type {{ $obj.Name }} struct { {{- if not (not $obj.SubTypes) }} Details {{ $obj.Name }}Details {{- end }} + {{- range $fname, $field := $obj.Additional }} + {{ $field.TypeLine }} // {{ $fname }} + {{- end }} } func New{{ $obj.Name }}() *{{ $obj.Name }} { diff --git a/analyze/df/structure.go b/analyze/df/structure.go index 1bce9da..0cb7fe2 100644 --- a/analyze/df/structure.go +++ b/analyze/df/structure.go @@ -51,8 +51,9 @@ func NewFieldData() *FieldData { } type AnalyzeData struct { - Fields map[string]*FieldData - SubTypes map[string]*map[string]*Subtype + Fields map[string]*FieldData + SubTypes map[string]*map[string]*Subtype + Overwrites *Overwrites } func NewAnalyzeData() *AnalyzeData { @@ -78,6 +79,16 @@ func LoadAnalyzeData() (*AnalyzeData, error) { a := NewAnalyzeData() json.Unmarshal(data, a) + + data, err = ioutil.ReadFile("overwrites.json") + if err != nil { + return nil, err + } + + overwrites := &Overwrites{} + json.Unmarshal(data, overwrites) + a.Overwrites = overwrites + return a, nil } @@ -120,8 +131,14 @@ type AnalyzeContext struct { overwrites *Overwrites } +type AdditionalField struct { + Name string + Type string +} + type Overwrites struct { - ForceEnum map[string]bool + ForceEnum map[string]bool + AdditionalFields map[string][]AdditionalField } func analyze(file string, a *AnalyzeData) error { diff --git a/analyze/overwrites.json b/analyze/overwrites.json index 78a1142..1ad7da8 100644 --- a/analyze/overwrites.json +++ b/analyze/overwrites.json @@ -2,5 +2,13 @@ "ForceEnum": { "df_world|historical_events|historical_event+HfDied|cause": true, "df_world|historical_events|historical_event+HfDied|death_cause": true + }, + "AdditionalFields": { + "Structure": [ + { + "Name": "SiteId", + "Type": "int" + } + ] } } \ No newline at end of file diff --git a/backend/model/context.go b/backend/model/context.go index 0075cfb..67d11c6 100644 --- a/backend/model/context.go +++ b/backend/model/context.go @@ -112,7 +112,7 @@ func (c *Context) site(id int, prefix string) string { func (c *Context) structure(siteId, structureId int) string { if x, ok := c.World.Sites[siteId]; ok { if y, ok := x.Structures[structureId]; ok { - return fmt.Sprintf(`%s`, siteId, structureId, util.Title(y.Name())) + return fmt.Sprintf(` %s`, siteId, structureId, y.Icon(), util.Title(y.Name())) } } return "UNKNOWN STRUCTURE" diff --git a/backend/model/extensions.go b/backend/model/extensions.go index 3883dbb..cd7faec 100644 --- a/backend/model/extensions.go +++ b/backend/model/extensions.go @@ -144,6 +144,10 @@ func (s *Site) Type() string { return s.Type_.String() } +func (s *Structure) Type() string { + return s.Type_.String() +} + func (w *WorldConstruction) Type() string { return w.Type_.String() } diff --git a/backend/model/functions.go b/backend/model/functions.go index 5d8460d..41db5c6 100644 --- a/backend/model/functions.go +++ b/backend/model/functions.go @@ -10,6 +10,9 @@ import ( var LinkHf = func(w *DfWorld, id int) template.HTML { return template.HTML((&Context{World: w}).hf(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 { + return template.HTML((&Context{World: w}).structure(siteId, id)) +} var LinkRegion = func(w *DfWorld, id int) template.HTML { return template.HTML((&Context{World: w}).region(id)) } var LinkWorldConstruction = func(w *DfWorld, id int) template.HTML { return template.HTML((&Context{World: w}).worldConstruction(id)) diff --git a/backend/model/icons.go b/backend/model/icons.go index f31b162..54548ff 100644 --- a/backend/model/icons.go +++ b/backend/model/icons.go @@ -64,6 +64,36 @@ func (x *Site) Icon() string { return "" } +func (x *Structure) Icon() string { + switch x.Type_ { + case StructureType_CountingHouse: + return "fa-solid fa-coins" + case StructureType_Dungeon: + return "fa-solid fa-dungeon" + case StructureType_Guildhall: + return "fa-solid fa-wrench" + case StructureType_InnTavern: + return "fa-solid fa-utensils" + case StructureType_Keep: + return "fa-brands fa-fort-awesome" + case StructureType_Library: + return "fa-solid fa-book" + case StructureType_Market: + return "fa-solid fa-store" + case StructureType_MeadHall: + return "fa-solid fa-warehouse" + case StructureType_Temple: + return "fa-solid fa-landmark-dome" + case StructureType_Tomb: + return "fa-solid fa-circle-stop" + case StructureType_Tower: + return "fa-solid fa-chess-rook" + case StructureType_UnderworldSpire: + return "fa-solid fa-monument" + } + return "" +} + func (x *WorldConstruction) Icon() string { switch x.Type_ { case WorldConstructionType_Bridge: diff --git a/backend/model/model.go b/backend/model/model.go index 2a3dfbb..21c0913 100644 --- a/backend/model/model.go +++ b/backend/model/model.go @@ -19033,6 +19033,7 @@ type Structure struct { Subtype StructureSubtype `json:"subtype" legend:"base"` // subtype Type_ StructureType `json:"type" legend:"both"` // type WorshipHfid int `json:"worshipHfid" legend:"base"` // worship_hfid + SiteId int `json:"siteId" legend:"add"` // SiteId } func NewStructure() *Structure { diff --git a/backend/model/parse.go b/backend/model/parse.go index db05bee..e30314a 100644 --- a/backend/model/parse.go +++ b/backend/model/parse.go @@ -143,9 +143,7 @@ BaseLoop: } ioutil.WriteFile("same.json", same, 0644) - for _, e := range world.HistoricalEvents { - e.Details.Html(&Context{World: world}) - } + world.Process() return world, nil } diff --git a/backend/model/process.go b/backend/model/process.go new file mode 100644 index 0000000..afb978f --- /dev/null +++ b/backend/model/process.go @@ -0,0 +1,16 @@ +package model + +func (w *DfWorld) Process() { + + // set site in structure + for _, site := range w.Sites { + for _, structure := range site.Structures { + structure.SiteId = site.Id_ + } + } + + // check events texts + for _, e := range w.HistoricalEvents { + e.Details.Html(&Context{World: w}) + } +} diff --git a/backend/server/server.go b/backend/server/server.go index 0121753..7cb63b4 100644 --- a/backend/server/server.go +++ b/backend/server/server.go @@ -54,6 +54,11 @@ func StartServer(world *model.DfWorld, static embed.FS) { srv.RegisterWorldPage("/sites", "sites.html", func(p Parms) any { return grouped(srv.context.world.Sites) }) srv.RegisterWorldResourcePage("/site/{id}", "site.html", func(id int) any { return srv.context.world.Sites[id] }) + srv.RegisterWorldPage("/structures", "structures.html", func(p Parms) any { + return flatGrouped(srv.context.world.Sites, func(s *model.Site) []*model.Structure { return util.Values(s.Structures) }) + }) + srv.RegisterWorldResourcePage("/structure/{id}", "site.html", func(id int) any { return srv.context.world.Sites[id/100].Structures[id%100] }) + srv.RegisterWorldPage("/worldconstructions", "worldconstructions.html", func(p Parms) any { return grouped(srv.context.world.WorldConstructions) }) srv.RegisterWorldResourcePage("/worldconstruction/{id}", "worldconstruction.html", func(id int) any { return srv.context.world.WorldConstructions[id] }) @@ -261,7 +266,26 @@ type namedTyped interface { model.Typed } -func grouped[T namedTyped](input map[int]T) map[string][]T { +func flatGrouped[K comparable, U any, V namedTyped](input map[K]U, mapper func(U) []V) map[string][]V { + output := make(map[string][]V) + + for _, x := range input { + for _, v := range mapper(x) { + k := v.Type() + if v.Name() != "" { + output[k] = append(output[k], v) + } + } + } + + for _, v := range output { + sort.Slice(v, func(i, j int) bool { return v[i].Name() < v[j].Name() }) + } + + return output +} + +func grouped[K comparable, T namedTyped](input map[K]T) map[string][]T { output := make(map[string][]T) for _, v := range input { diff --git a/backend/server/templates.go b/backend/server/templates.go index c5568e2..f1750a8 100644 --- a/backend/server/templates.go +++ b/backend/server/templates.go @@ -29,6 +29,7 @@ func (srv *DfServer) LoadTemplates() { "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) }, "getSite": func(id int) *model.Site { return srv.context.world.Sites[id] }, + "structure": func(siteId, id int) template.HTML { return model.LinkStructure(srv.context.world, siteId, id) }, "region": func(id int) template.HTML { return model.LinkRegion(srv.context.world, id) }, "getRegion": func(id int) *model.Region { return srv.context.world.Regions[id] }, "worldconstruction": func(id int) template.HTML { return model.LinkWorldConstruction(srv.context.world, id) }, diff --git a/backend/templates/hf.html b/backend/templates/hf.html index 66b372a..5278b1a 100644 --- a/backend/templates/hf.html +++ b/backend/templates/hf.html @@ -3,51 +3,131 @@ {{define "title"}}{{ title .Name }}{{end}} {{define "content"}} -
{{ json . }}
diff --git a/backend/templates/structures.html b/backend/templates/structures.html new file mode 100644 index 0000000..56bac9b --- /dev/null +++ b/backend/templates/structures.html @@ -0,0 +1,33 @@ +{{template "layout.html" .}} + +{{define "title"}}Structures{{end}} + +{{define "content"}} +