dorfylegends/backend/model/eventList.go

53 lines
1.3 KiB
Go
Raw Normal View History

2022-04-26 10:24:16 +03:00
package model
import (
"fmt"
)
type HistoricalEventDetails interface {
RelatedToEntity(int) bool
RelatedToHf(int) bool
RelatedToArtifact(int) bool
RelatedToSite(int) bool
RelatedToRegion(int) bool
2022-04-26 18:39:24 +03:00
Html(*Context) string
2022-04-26 10:24:16 +03:00
Type() string
}
type HistoricalEventCollectionDetails interface {
}
type EventList struct {
Events []*HistoricalEvent
2022-04-26 18:39:24 +03:00
Context *Context
2022-04-26 10:24:16 +03:00
}
func NewEventList(world *DfWorld, obj any) *EventList {
el := EventList{
2022-04-26 21:06:21 +03:00
Context: &Context{
World: world,
HfId: -1,
},
2022-04-26 10:24:16 +03:00
}
switch x := obj.(type) {
case *Entity:
el.Events = world.EventsMatching(func(d HistoricalEventDetails) bool { return d.RelatedToEntity(x.Id()) })
case *HistoricalFigure:
2022-04-26 18:39:24 +03:00
el.Context.HfId = x.Id()
2022-04-26 10:24:16 +03:00
el.Events = world.EventsMatching(func(d HistoricalEventDetails) bool { return d.RelatedToHf(x.Id()) })
case *Artifact:
el.Events = world.EventsMatching(func(d HistoricalEventDetails) bool { return d.RelatedToArtifact(x.Id()) })
case *Site:
el.Events = world.EventsMatching(func(d HistoricalEventDetails) bool { return d.RelatedToSite(x.Id()) })
case *Region:
el.Events = world.EventsMatching(func(d HistoricalEventDetails) bool { return d.RelatedToRegion(x.Id()) })
case []*HistoricalEvent:
el.Events = x
default:
fmt.Printf("unknown type %T\n", obj)
}
return &el
}