diff --git a/analyze/df/generate_backend.go b/analyze/df/generate_backend.go index a03e5cf..948fbe0 100644 --- a/analyze/df/generate_backend.go +++ b/analyze/df/generate_backend.go @@ -114,6 +114,7 @@ func New{{ $obj.Name }}() *{{ $obj.Name }} { {{- if $obj.Id }} func (x *{{ $obj.Name }}) Id() int { return x.Id_ } +func (x *{{ $obj.Name }}) setId(id int) { x.Id_ = id } {{- end }} {{- if $obj.Named }} func (x *{{ $obj.Name }}) Name() string { return x.Name_ } diff --git a/backend/model/context.go b/backend/model/context.go index 773e7bb..ab1f259 100644 --- a/backend/model/context.go +++ b/backend/model/context.go @@ -229,7 +229,7 @@ func (c *Context) feature(x *Feature) string { case FeatureType_Storytelling: if x.Reference != -1 { if e, ok := c.World.HistoricalEvents[x.Reference]; ok { - return "a telling of the story of " + e.Details.Html(&Context{Story: true}) + " in " + Time(e.Year, e.Seconds72) + return "a telling of the story of " + e.Details.Html(&Context{World: c.World, Story: true}) + " in " + Time(e.Year, e.Seconds72) } } return "a story recital" @@ -249,7 +249,7 @@ func (c *Context) schedule(x *Schedule) string { case ScheduleType_Storytelling: if x.Reference != -1 { if e, ok := c.World.HistoricalEvents[x.Reference]; ok { - return "the story of " + e.Details.Html(&Context{Story: true}) + " in " + Time(e.Year, e.Seconds72) + return "the story of " + e.Details.Html(&Context{World: c.World, Story: true}) + " in " + Time(e.Year, e.Seconds72) } } return "a story recital" diff --git a/backend/model/extensions.go b/backend/model/extensions.go index 22eec6b..0bc7eec 100644 --- a/backend/model/extensions.go +++ b/backend/model/extensions.go @@ -48,6 +48,10 @@ func (w *DfWorld) EventsMatching(f func(HistoricalEventDetails) bool) []*Histori return list } +func (e *Artifact) Type() string { + return e.ItemType +} + func (e *Entity) Type() string { return e.Type_.String() } @@ -121,6 +125,34 @@ func (x *Honor) Requirement() string { return " after " + andList(list) } +func (r *Region) Type() string { + return r.Type_.String() +} + +func (s *Site) Type() string { + return s.Type_.String() +} + +func (w *WorldConstruction) Type() string { + return w.Type_.String() +} + func (w *WrittenContent) Name() string { return w.Title } + +func (w *WrittenContent) Type() string { + return w.Type_.String() +} + +func (w *DanceForm) Type() string { + return "dance form" +} + +func (w *MusicalForm) Type() string { + return "musical form" +} + +func (w *PoeticForm) Type() string { + return "poetic form" +} diff --git a/backend/model/functions.go b/backend/model/functions.go index 63ac9e4..5d8460d 100644 --- a/backend/model/functions.go +++ b/backend/model/functions.go @@ -11,6 +11,14 @@ var LinkHf = func(w *DfWorld, id int) template.HTML { return template.HTML((&Con 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 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)) +} +var LinkArtifact = func(w *DfWorld, id int) template.HTML { return template.HTML((&Context{World: w}).artifact(id)) } +var LinkDanceForm = func(w *DfWorld, id int) template.HTML { return template.HTML((&Context{World: w}).danceForm(id)) } +var LinkMusicalForm = func(w *DfWorld, id int) template.HTML { return template.HTML((&Context{World: w}).musicalForm(id)) } +var LinkPoeticForm = func(w *DfWorld, id int) template.HTML { return template.HTML((&Context{World: w}).poeticForm(id)) } +var LinkWrittenContent = func(w *DfWorld, id int) template.HTML { return template.HTML((&Context{World: w}).writtenContent(id)) } func andList(list []string) string { if len(list) > 1 { diff --git a/backend/model/model.go b/backend/model/model.go index 95c9e10..2a3dfbb 100644 --- a/backend/model/model.go +++ b/backend/model/model.go @@ -1148,6 +1148,7 @@ func NewArtifact() *Artifact { } } func (x *Artifact) Id() int { return x.Id_ } +func (x *Artifact) setId(id int) { x.Id_ = id } func (x *Artifact) Name() string { return x.Name_ } func (x *Artifact) RelatedToEntity(id int) bool { return false } func (x *Artifact) RelatedToHf(id int) bool { return x.HolderHfid == id } @@ -1511,6 +1512,7 @@ func NewDanceForm() *DanceForm { } } func (x *DanceForm) Id() int { return x.Id_ } +func (x *DanceForm) setId(id int) { x.Id_ = id } func (x *DanceForm) Name() string { return x.Name_ } func (x *DanceForm) RelatedToEntity(id int) bool { return false } func (x *DanceForm) RelatedToHf(id int) bool { return false } @@ -1993,6 +1995,7 @@ func NewEntity() *Entity { } } func (x *Entity) Id() int { return x.Id_ } +func (x *Entity) setId(id int) { x.Id_ = id } func (x *Entity) Name() string { return x.Name_ } func (x *Entity) RelatedToEntity(id int) bool { return false } func (x *Entity) RelatedToHf(id int) bool { return containsInt(x.HistfigId, id) } @@ -2196,6 +2199,7 @@ func NewEntityPopulation() *EntityPopulation { } } func (x *EntityPopulation) Id() int { return x.Id_ } +func (x *EntityPopulation) setId(id int) { x.Id_ = id } func (x *EntityPopulation) RelatedToEntity(id int) bool { return x.CivId == id } func (x *EntityPopulation) RelatedToHf(id int) bool { return false } func (x *EntityPopulation) RelatedToArtifact(id int) bool { return false } @@ -2233,6 +2237,7 @@ func NewEntityPosition() *EntityPosition { } } func (x *EntityPosition) Id() int { return x.Id_ } +func (x *EntityPosition) setId(id int) { x.Id_ = id } func (x *EntityPosition) Name() string { return x.Name_ } func (x *EntityPosition) RelatedToEntity(id int) bool { return false } func (x *EntityPosition) RelatedToHf(id int) bool { return false } @@ -2273,6 +2278,7 @@ func NewEntityPositionAssignment() *EntityPositionAssignment { } } func (x *EntityPositionAssignment) Id() int { return x.Id_ } +func (x *EntityPositionAssignment) setId(id int) { x.Id_ = id } func (x *EntityPositionAssignment) RelatedToEntity(id int) bool { return false } func (x *EntityPositionAssignment) RelatedToHf(id int) bool { return x.Histfig == id } func (x *EntityPositionAssignment) RelatedToArtifact(id int) bool { return false } @@ -2798,6 +2804,7 @@ func NewHistoricalEvent() *HistoricalEvent { } } func (x *HistoricalEvent) Id() int { return x.Id_ } +func (x *HistoricalEvent) setId(id int) { x.Id_ = id } func (x *HistoricalEvent) RelatedToEntity(id int) bool { return false } func (x *HistoricalEvent) RelatedToHf(id int) bool { return false } func (x *HistoricalEvent) RelatedToArtifact(id int) bool { return false } @@ -5803,6 +5810,7 @@ func NewHistoricalEventCollection() *HistoricalEventCollection { } } func (x *HistoricalEventCollection) Id() int { return x.Id_ } +func (x *HistoricalEventCollection) setId(id int) { x.Id_ = id } func (x *HistoricalEventCollection) RelatedToEntity(id int) bool { return false } func (x *HistoricalEventCollection) RelatedToHf(id int) bool { return false } func (x *HistoricalEventCollection) RelatedToArtifact(id int) bool { return false } @@ -16372,6 +16380,7 @@ func NewHistoricalFigure() *HistoricalFigure { } } func (x *HistoricalFigure) Id() int { return x.Id_ } +func (x *HistoricalFigure) setId(id int) { x.Id_ = id } func (x *HistoricalFigure) Name() string { return x.Name_ } func (x *HistoricalFigure) RelatedToEntity(id int) bool { return containsInt(x.UsedIdentityId, id) || x.CurrentIdentityId == id @@ -16700,6 +16709,7 @@ func NewHonor() *Honor { } } func (x *Honor) Id() int { return x.Id_ } +func (x *Honor) setId(id int) { x.Id_ = id } func (x *Honor) Name() string { return x.Name_ } func (x *Honor) RelatedToEntity(id int) bool { return false } func (x *Honor) RelatedToHf(id int) bool { return false } @@ -16904,6 +16914,7 @@ func NewIdentity() *Identity { } } func (x *Identity) Id() int { return x.Id_ } +func (x *Identity) setId(id int) { x.Id_ = id } func (x *Identity) Name() string { return x.Name_ } func (x *Identity) RelatedToEntity(id int) bool { return x.EntityId == id } func (x *Identity) RelatedToHf(id int) bool { return x.HistfigId == id } @@ -17409,6 +17420,7 @@ func NewLandmass() *Landmass { } } func (x *Landmass) Id() int { return x.Id_ } +func (x *Landmass) setId(id int) { x.Id_ = id } func (x *Landmass) Name() string { return x.Name_ } func (x *Landmass) RelatedToEntity(id int) bool { return false } func (x *Landmass) RelatedToHf(id int) bool { return false } @@ -17445,6 +17457,7 @@ func NewMountainPeak() *MountainPeak { } } func (x *MountainPeak) Id() int { return x.Id_ } +func (x *MountainPeak) setId(id int) { x.Id_ = id } func (x *MountainPeak) Name() string { return x.Name_ } func (x *MountainPeak) RelatedToEntity(id int) bool { return false } func (x *MountainPeak) RelatedToHf(id int) bool { return false } @@ -17481,6 +17494,7 @@ func NewMusicalForm() *MusicalForm { } } func (x *MusicalForm) Id() int { return x.Id_ } +func (x *MusicalForm) setId(id int) { x.Id_ = id } func (x *MusicalForm) Name() string { return x.Name_ } func (x *MusicalForm) RelatedToEntity(id int) bool { return false } func (x *MusicalForm) RelatedToHf(id int) bool { return false } @@ -17515,6 +17529,7 @@ func NewOccasion() *Occasion { } } func (x *Occasion) Id() int { return x.Id_ } +func (x *Occasion) setId(id int) { x.Id_ = id } func (x *Occasion) Name() string { return x.Name_ } func (x *Occasion) RelatedToEntity(id int) bool { return false } func (x *Occasion) RelatedToHf(id int) bool { return false } @@ -17624,6 +17639,7 @@ func NewPoeticForm() *PoeticForm { } } func (x *PoeticForm) Id() int { return x.Id_ } +func (x *PoeticForm) setId(id int) { x.Id_ = id } func (x *PoeticForm) Name() string { return x.Name_ } func (x *PoeticForm) RelatedToEntity(id int) bool { return false } func (x *PoeticForm) RelatedToHf(id int) bool { return false } @@ -17752,6 +17768,7 @@ func NewReference() *Reference { } } func (x *Reference) Id() int { return x.Id_ } +func (x *Reference) setId(id int) { x.Id_ = id } func (x *Reference) RelatedToEntity(id int) bool { return false } func (x *Reference) RelatedToHf(id int) bool { return false } func (x *Reference) RelatedToArtifact(id int) bool { return false } @@ -17897,6 +17914,7 @@ func NewRegion() *Region { } } func (x *Region) Id() int { return x.Id_ } +func (x *Region) setId(id int) { x.Id_ = id } func (x *Region) Name() string { return x.Name_ } func (x *Region) RelatedToEntity(id int) bool { return false } func (x *Region) RelatedToHf(id int) bool { return false } @@ -18034,6 +18052,7 @@ func NewRelationshipProfileHfIdentity() *RelationshipProfileHfIdentity { } } func (x *RelationshipProfileHfIdentity) Id() int { return x.Id_ } +func (x *RelationshipProfileHfIdentity) setId(id int) { x.Id_ = id } func (x *RelationshipProfileHfIdentity) RelatedToEntity(id int) bool { return false } func (x *RelationshipProfileHfIdentity) RelatedToHf(id int) bool { return false } func (x *RelationshipProfileHfIdentity) RelatedToArtifact(id int) bool { return false } @@ -18490,6 +18509,7 @@ func NewSchedule() *Schedule { } } func (x *Schedule) Id() int { return x.Id_ } +func (x *Schedule) setId(id int) { x.Id_ = id } func (x *Schedule) RelatedToEntity(id int) bool { return false } func (x *Schedule) RelatedToHf(id int) bool { return false } func (x *Schedule) RelatedToArtifact(id int) bool { return false } @@ -18667,6 +18687,7 @@ func NewSite() *Site { } } func (x *Site) Id() int { return x.Id_ } +func (x *Site) setId(id int) { x.Id_ = id } func (x *Site) Name() string { return x.Name_ } func (x *Site) RelatedToEntity(id int) bool { return x.CivId == id } func (x *Site) RelatedToHf(id int) bool { return false } @@ -18848,6 +18869,7 @@ func NewSiteSiteProperty() *SiteSiteProperty { } } func (x *SiteSiteProperty) Id() int { return x.Id_ } +func (x *SiteSiteProperty) setId(id int) { x.Id_ = id } func (x *SiteSiteProperty) RelatedToEntity(id int) bool { return false } func (x *SiteSiteProperty) RelatedToHf(id int) bool { return x.OwnerHfid == id } func (x *SiteSiteProperty) RelatedToArtifact(id int) bool { return false } @@ -19026,6 +19048,7 @@ func NewStructure() *Structure { } } func (x *Structure) Id() int { return x.Id_ } +func (x *Structure) setId(id int) { x.Id_ = id } func (x *Structure) Name() string { return x.Name_ } func (x *Structure) RelatedToEntity(id int) bool { return x.EntityId == id } func (x *Structure) RelatedToHf(id int) bool { return x.WorshipHfid == id } @@ -19162,6 +19185,7 @@ func NewUndergroundRegion() *UndergroundRegion { } } func (x *UndergroundRegion) Id() int { return x.Id_ } +func (x *UndergroundRegion) setId(id int) { x.Id_ = id } func (x *UndergroundRegion) RelatedToEntity(id int) bool { return false } func (x *UndergroundRegion) RelatedToHf(id int) bool { return false } func (x *UndergroundRegion) RelatedToArtifact(id int) bool { return false } @@ -19288,6 +19312,7 @@ func NewWorldConstruction() *WorldConstruction { } } func (x *WorldConstruction) Id() int { return x.Id_ } +func (x *WorldConstruction) setId(id int) { x.Id_ = id } func (x *WorldConstruction) Name() string { return x.Name_ } func (x *WorldConstruction) RelatedToEntity(id int) bool { return false } func (x *WorldConstruction) RelatedToHf(id int) bool { return false } @@ -19630,6 +19655,7 @@ func NewWrittenContent() *WrittenContent { } } func (x *WrittenContent) Id() int { return x.Id_ } +func (x *WrittenContent) setId(id int) { x.Id_ = id } func (x *WrittenContent) RelatedToEntity(id int) bool { return false } func (x *WrittenContent) RelatedToHf(id int) bool { return x.AuthorHfid == id } func (x *WrittenContent) RelatedToArtifact(id int) bool { return false } diff --git a/backend/model/parse.go b/backend/model/parse.go index 2ac5827..db05bee 100644 --- a/backend/model/parse.go +++ b/backend/model/parse.go @@ -143,6 +143,10 @@ BaseLoop: } ioutil.WriteFile("same.json", same, 0644) + for _, e := range world.HistoricalEvents { + e.Details.Html(&Context{World: world}) + } + return world, nil } @@ -193,6 +197,7 @@ func parseMapPlus[T Identifiable](p *util.XMLParser, dest *map[int]T, creator fu log.Fatal(err) } x, err := creator(p, (*dest)[id]) + x.setId(id) if err != nil { return } diff --git a/backend/model/util.go b/backend/model/util.go index 77f0f12..28ba8e9 100644 --- a/backend/model/util.go +++ b/backend/model/util.go @@ -17,6 +17,7 @@ type Named interface { type Identifiable interface { Id() int + setId(int) } type Typed interface { diff --git a/backend/server/server.go b/backend/server/server.go index 22522c8..4a6c6e0 100644 --- a/backend/server/server.go +++ b/backend/server/server.go @@ -48,11 +48,35 @@ func StartServer(world *model.DfWorld, static embed.FS) { srv.RegisterWorldPage("/entities", "entities.html", func(p Parms) any { return grouped(srv.context.world.Entities) }) srv.RegisterWorldResourcePage("/entity/{id}", "entity.html", func(id int) any { return srv.context.world.Entities[id] }) - srv.RegisterWorldResourcePage("/hf/{id}", "hf.html", func(id int) any { return srv.context.world.HistoricalFigures[id] }) + srv.RegisterWorldPage("/regions", "regions.html", func(p Parms) any { return grouped(srv.context.world.Regions) }) srv.RegisterWorldResourcePage("/region/{id}", "region.html", func(id int) any { return srv.context.world.Regions[id] }) + + 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("/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] }) + + srv.RegisterWorldPage("/artifacts", "artifacts.html", func(p Parms) any { return grouped(srv.context.world.Artifacts) }) srv.RegisterWorldResourcePage("/artifact/{id}", "artifact.html", func(id int) any { return srv.context.world.Artifacts[id] }) + srv.RegisterWorldPage("/artforms", "artforms.html", func(p Parms) any { + return struct { + DanceForms map[string][]*model.DanceForm + MusicalForms map[string][]*model.MusicalForm + PoeticForms map[string][]*model.PoeticForm + }{ + DanceForms: grouped(srv.context.world.DanceForms), + MusicalForms: grouped(srv.context.world.MusicalForms), + PoeticForms: grouped(srv.context.world.PoeticForms), + } + }) + + srv.RegisterWorldPage("/writtencontents", "writtencontents.html", func(p Parms) any { return grouped(srv.context.world.WrittenContents) }) + srv.RegisterWorldResourcePage("/writtencontent/{id}", "writtencontent.html", func(id int) any { return srv.context.world.WrittenContents[id] }) + + srv.RegisterWorldResourcePage("/hf/{id}", "hf.html", func(id int) any { return srv.context.world.HistoricalFigures[id] }) + srv.RegisterWorldPage("/", "eventTypes.html", func(p Parms) any { return srv.context.world.AllEventTypes() }) srv.RegisterWorldPage("/events", "eventTypes.html", func(p Parms) any { return srv.context.world.AllEventTypes() }) srv.RegisterWorldPage("/events/{type}", "eventType.html", func(p Parms) any { return srv.context.world.EventsOfType(p["type"]) }) diff --git a/backend/server/templates.go b/backend/server/templates.go index b332b5c..c5568e2 100644 --- a/backend/server/templates.go +++ b/backend/server/templates.go @@ -6,6 +6,7 @@ import ( "net/url" humanize "github.com/dustin/go-humanize" + "github.com/iancoleman/strcase" "github.com/robertjanetzko/LegendsBrowser2/backend/model" "github.com/robertjanetzko/LegendsBrowser2/backend/templates" "github.com/robertjanetzko/LegendsBrowser2/backend/util" @@ -20,15 +21,24 @@ func (srv *DfServer) LoadTemplates() { } return nil }, - "title": util.Title, - "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] }, - "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) }, - "getSite": func(id int) *model.Site { return srv.context.world.Sites[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] }, + "title": util.Title, + "kebab": func(s string) string { return strcase.ToKebab(s) }, + "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] }, + "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) }, + "getSite": func(id int) *model.Site { return srv.context.world.Sites[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) }, + "getWorldconstruction": func(id int) *model.WorldConstruction { return srv.context.world.WorldConstructions[id] }, + "artifact": func(id int) template.HTML { return model.LinkArtifact(srv.context.world, id) }, + "getArtifact": func(id int) *model.Artifact { return srv.context.world.Artifacts[id] }, + "danceForm": func(id int) template.HTML { return model.LinkDanceForm(srv.context.world, id) }, + "musicalForm": func(id int) template.HTML { return model.LinkMusicalForm(srv.context.world, id) }, + "poeticForm": func(id int) template.HTML { return model.LinkPoeticForm(srv.context.world, id) }, + "writtencontent": func(id int) template.HTML { return model.LinkWrittenContent(srv.context.world, id) }, "events": func(obj any) *model.EventList { return model.NewEventList(srv.context.world, obj) }, diff --git a/backend/templates/artforms.html b/backend/templates/artforms.html new file mode 100644 index 0000000..dc57470 --- /dev/null +++ b/backend/templates/artforms.html @@ -0,0 +1,76 @@ +{{template "layout.html" .}} + +{{define "title"}}Artifacts{{end}} + +{{define "content"}} +