events
This commit is contained in:
parent
fe5cca0c5c
commit
f76d92be9a
|
@ -15,7 +15,7 @@ package model
|
||||||
|
|
||||||
{{- range $name, $obj := $.Objects }}
|
{{- range $name, $obj := $.Objects }}
|
||||||
{{- if $obj.IsSubTypeOf "HistoricalEvent" }}
|
{{- 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 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
`))
|
`))
|
||||||
|
|
|
@ -49,46 +49,7 @@ func main() {
|
||||||
"getSite": func(id int) *model.Site { return world.Sites[id] },
|
"getSite": func(id int) *model.Site { return world.Sites[id] },
|
||||||
"region": model.LinkRegion,
|
"region": model.LinkRegion,
|
||||||
"getRegion": func(id int) *model.Region { return world.Regions[id] },
|
"getRegion": func(id int) *model.Region { return world.Regions[id] },
|
||||||
"events": func(obj model.Identifiable) []*model.HistoricalEvent {
|
"events": model.NewEventList,
|
||||||
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
|
|
||||||
},
|
|
||||||
"season": func(seconds int) string {
|
"season": func(seconds int) string {
|
||||||
r := ""
|
r := ""
|
||||||
month := seconds % 100800
|
month := seconds % 100800
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/iancoleman/strcase"
|
"github.com/iancoleman/strcase"
|
||||||
|
@ -61,13 +62,93 @@ type HistoricalEventDetails interface {
|
||||||
RelatedToArtifact(int) bool
|
RelatedToArtifact(int) bool
|
||||||
RelatedToSite(int) bool
|
RelatedToSite(int) bool
|
||||||
RelatedToRegion(int) bool
|
RelatedToRegion(int) bool
|
||||||
Html() string
|
Html(*context) string
|
||||||
Type() string
|
Type() string
|
||||||
}
|
}
|
||||||
|
|
||||||
type HistoricalEventCollectionDetails interface {
|
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 {
|
func containsInt(list []int, id int) bool {
|
||||||
for _, v := range list {
|
for _, v := range list {
|
||||||
if v == id {
|
if v == id {
|
||||||
|
@ -160,14 +241,6 @@ func hfRelated(id, to int) string {
|
||||||
return "UNKNOWN HISTORICAL FIGURE"
|
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 {
|
func pronoun(id int) string {
|
||||||
if x, ok := world.HistoricalFigures[id]; ok {
|
if x, ok := world.HistoricalFigures[id]; ok {
|
||||||
return x.Pronoun()
|
return x.Pronoun()
|
||||||
|
@ -244,6 +317,13 @@ func identity(id int) string {
|
||||||
return "UNKNOWN IDENTITY"
|
return "UNKNOWN IDENTITY"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fullIdentity(id int) string {
|
||||||
|
if x, ok := world.Identities[id]; ok {
|
||||||
|
return fmt.Sprintf(`"the %s <a class="identity" href="/region/%d">%s</a> of %s"`, x.Profession.String(), x.Id(), util.Title(x.Name()), entity(x.EntityId))
|
||||||
|
}
|
||||||
|
return "UNKNOWN IDENTITY"
|
||||||
|
}
|
||||||
|
|
||||||
func feature(x *Feature) string {
|
func feature(x *Feature) string {
|
||||||
switch x.Type {
|
switch x.Type {
|
||||||
case FeatureType_DancePerformance:
|
case FeatureType_DancePerformance:
|
||||||
|
|
|
@ -5,7 +5,19 @@
|
||||||
"HistoricalEventAddHfSiteLink": {
|
"HistoricalEventAddHfSiteLink": {
|
||||||
"Site": "SiteId"
|
"Site": "SiteId"
|
||||||
},
|
},
|
||||||
|
"HistoricalEventAgreementMade": {
|
||||||
|
"Destination": "SiteId",
|
||||||
|
"Site": "SiteId",
|
||||||
|
"Source": "SiteId"
|
||||||
|
},
|
||||||
|
"HistoricalEventAgreementRejected": {
|
||||||
|
"Destination": "SiteId",
|
||||||
|
"Site": "SiteId",
|
||||||
|
"Source": "SiteId"
|
||||||
|
},
|
||||||
"HistoricalEventDiplomatLost": {
|
"HistoricalEventDiplomatLost": {
|
||||||
|
"Entity": "SiteId",
|
||||||
|
"Involved": "SiteId",
|
||||||
"Site": "SiteId"
|
"Site": "SiteId"
|
||||||
},
|
},
|
||||||
"HistoricalEventHfDied": {
|
"HistoricalEventHfDied": {
|
||||||
|
|
|
@ -4,6 +4,6 @@
|
||||||
|
|
||||||
{{define "content"}}
|
{{define "content"}}
|
||||||
|
|
||||||
{{ template "events.html" .Events }}
|
{{ template "events.html" events .Events }}
|
||||||
|
|
||||||
{{- end }}
|
{{- end }}
|
|
@ -1,8 +1,8 @@
|
||||||
<ul>
|
<ul>
|
||||||
{{- range $event := . }}
|
{{- range $event := .Events }}
|
||||||
<li>
|
<li>
|
||||||
[{{ $event.Id }}] In {{ if gt $event.Seconds72 -1 }}{{ season $event.Seconds72 }} of {{ end }}{{ $event.Year }}, {{
|
[{{ $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>
|
</li>
|
||||||
{{- end}}
|
{{- end}}
|
||||||
</ul>
|
</ul>
|
Loading…
Reference in New Issue