This commit is contained in:
Robert Janetzko 2022-04-23 19:38:03 +00:00
parent fe5cca0c5c
commit f76d92be9a
7 changed files with 582 additions and 339 deletions

View File

@ -15,7 +15,7 @@ package model
{{- range $name, $obj := $.Objects }}
{{- if $obj.IsSubTypeOf "HistoricalEvent" }}
func (x *{{ $obj.Name }}) Html() string { return "UNKNWON {{ $obj.Name }}" }
func (x *{{ $obj.Name }}) Html(c *context) string { return "UNKNWON {{ $obj.Name }}" }
{{- end }}
{{- end }}
`))

View File

@ -49,46 +49,7 @@ func main() {
"getSite": func(id int) *model.Site { return world.Sites[id] },
"region": model.LinkRegion,
"getRegion": func(id int) *model.Region { return world.Regions[id] },
"events": func(obj model.Identifiable) []*model.HistoricalEvent {
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) {
list = append(list, e)
}
}
case *model.Artifact:
for _, e := range world.HistoricalEvents {
if e.Details.RelatedToArtifact(id) {
list = append(list, e)
}
}
case *model.Site:
for _, e := range world.HistoricalEvents {
if e.Details.RelatedToSite(id) {
list = append(list, e)
}
}
case *model.Region:
for _, e := range world.HistoricalEvents {
if e.Details.RelatedToRegion(id) {
list = append(list, e)
}
}
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
},
"events": model.NewEventList,
"season": func(seconds int) string {
r := ""
month := seconds % 100800

File diff suppressed because it is too large Load Diff

View File

@ -4,6 +4,7 @@ import (
"fmt"
"html/template"
"regexp"
"sort"
"strings"
"github.com/iancoleman/strcase"
@ -61,13 +62,93 @@ type HistoricalEventDetails interface {
RelatedToArtifact(int) bool
RelatedToSite(int) bool
RelatedToRegion(int) bool
Html() string
Html(*context) string
Type() string
}
type HistoricalEventCollectionDetails interface {
}
type EventList struct {
Events []*HistoricalEvent
Context *context
}
func filter(f func(HistoricalEventDetails) bool) []*HistoricalEvent {
var list []*HistoricalEvent
for _, e := range world.HistoricalEvents {
if f(e.Details) {
list = append(list, e)
}
}
sort.Slice(list, func(a, b int) bool { return list[a].Id_ < list[b].Id_ })
return list
}
func NewEventList(obj any) *EventList {
el := EventList{
Context: &context{HfId: -1},
}
switch x := obj.(type) {
case *Entity:
el.Events = filter(func(d HistoricalEventDetails) bool { return d.RelatedToEntity(x.Id()) })
case *HistoricalFigure:
el.Context.HfId = x.Id()
el.Events = filter(func(d HistoricalEventDetails) bool { return d.RelatedToHf(x.Id()) })
case *Artifact:
el.Events = filter(func(d HistoricalEventDetails) bool { return d.RelatedToArtifact(x.Id()) })
case *Site:
el.Events = filter(func(d HistoricalEventDetails) bool { return d.RelatedToSite(x.Id()) })
case *Region:
el.Events = filter(func(d HistoricalEventDetails) bool { return d.RelatedToRegion(x.Id()) })
case []*HistoricalEvent:
el.Events = x
default:
fmt.Printf("unknown type %T\n", obj)
}
return &el
}
type context struct {
HfId int
}
func (c *context) hf(id int) string {
if c.HfId != -1 {
if c.HfId == id {
return hfShort(id)
} else {
return hfRelated(id, c.HfId)
}
}
return hf(id)
}
func (c *context) hfShort(id int) string {
return hfShort(id)
}
func (c *context) hfRelated(id, to int) string {
if c.HfId != -1 {
if c.HfId == id {
return hfShort(id)
} else {
return hfRelated(id, c.HfId)
}
}
return hfRelated(id, to)
}
func (c *context) hfList(ids []int) string {
return andList(util.Map(ids, func(id int) string { return c.hf(id) }))
}
func (c *context) hfListRelated(ids []int, to int) string {
return andList(util.Map(ids, func(id int) string { return c.hfRelated(id, to) }))
}
func containsInt(list []int, id int) bool {
for _, v := range list {
if v == id {
@ -160,14 +241,6 @@ func hfRelated(id, to int) string {
return "UNKNOWN HISTORICAL FIGURE"
}
func hfList(ids []int) string {
return andList(util.Map(ids, hf))
}
func hfListRelated(ids []int, to int) string {
return andList(util.Map(ids, func(id int) string { return hfRelated(id, to) }))
}
func pronoun(id int) string {
if x, ok := world.HistoricalFigures[id]; ok {
return x.Pronoun()
@ -244,6 +317,13 @@ func identity(id int) string {
return "UNKNOWN IDENTITY"
}
func fullIdentity(id int) string {
if x, ok := world.Identities[id]; ok {
return fmt.Sprintf(`&quot;the %s <a class="identity" href="/region/%d">%s</a> of %s&quot;`, x.Profession.String(), x.Id(), util.Title(x.Name()), entity(x.EntityId))
}
return "UNKNOWN IDENTITY"
}
func feature(x *Feature) string {
switch x.Type {
case FeatureType_DancePerformance:

View File

@ -5,7 +5,19 @@
"HistoricalEventAddHfSiteLink": {
"Site": "SiteId"
},
"HistoricalEventAgreementMade": {
"Destination": "SiteId",
"Site": "SiteId",
"Source": "SiteId"
},
"HistoricalEventAgreementRejected": {
"Destination": "SiteId",
"Site": "SiteId",
"Source": "SiteId"
},
"HistoricalEventDiplomatLost": {
"Entity": "SiteId",
"Involved": "SiteId",
"Site": "SiteId"
},
"HistoricalEventHfDied": {

View File

@ -4,6 +4,6 @@
{{define "content"}}
{{ template "events.html" .Events }}
{{ template "events.html" events .Events }}
{{- end }}

View File

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