dorfylegends/backend/model/eventList.go

84 lines
2.8 KiB
Go
Raw Normal View History

2022-04-26 10:24:16 +03:00
package model
import (
"fmt"
2022-05-03 15:59:47 +03:00
"github.com/robertjanetzko/LegendsBrowser2/backend/util"
2022-04-26 10:24:16 +03:00
)
type HistoricalEventDetails interface {
RelatedToEntity(int) bool
RelatedToHf(int) bool
RelatedToArtifact(int) bool
RelatedToSite(int) bool
2022-04-30 11:25:50 +03:00
RelatedToStructure(int, int) bool
2022-04-26 10:24:16 +03:00
RelatedToRegion(int) bool
2022-05-03 22:39:00 +03:00
RelatedToWorldConstruction(int) bool
RelatedToWrittenContent(int) bool
RelatedToDanceForm(int) bool
RelatedToMusicalForm(int) bool
RelatedToPoeticForm(int) bool
2022-05-04 15:07:35 +03:00
RelatedToMountain(int) bool
2022-05-07 22:17:05 +03:00
RelatedToIdentity(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 {
2022-05-03 15:59:47 +03:00
Type() string
Html(*HistoricalEventCollection, *Context) string
2022-04-26 10:24:16 +03:00
}
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:
2022-05-02 18:22:57 +03:00
el.Context.HfId = x.HolderHfid
2022-04-26 10:24:16 +03:00
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()) })
2022-04-30 11:25:50 +03:00
case *Structure:
el.Events = world.EventsMatching(func(d HistoricalEventDetails) bool { return d.RelatedToStructure(x.SiteId, x.Id()) })
2022-04-26 10:24:16 +03:00
case *Region:
el.Events = world.EventsMatching(func(d HistoricalEventDetails) bool { return d.RelatedToRegion(x.Id()) })
2022-05-03 22:39:00 +03:00
case *WorldConstruction:
el.Events = world.EventsMatching(func(d HistoricalEventDetails) bool { return d.RelatedToWorldConstruction(x.Id()) })
case *WrittenContent:
el.Events = world.EventsMatching(func(d HistoricalEventDetails) bool { return d.RelatedToWrittenContent(x.Id()) })
case *DanceForm:
el.Events = world.EventsMatching(func(d HistoricalEventDetails) bool { return d.RelatedToDanceForm(x.Id()) })
case *MusicalForm:
el.Events = world.EventsMatching(func(d HistoricalEventDetails) bool { return d.RelatedToMusicalForm(x.Id()) })
case *PoeticForm:
el.Events = world.EventsMatching(func(d HistoricalEventDetails) bool { return d.RelatedToPoeticForm(x.Id()) })
2022-05-04 15:07:35 +03:00
case *MountainPeak:
el.Events = world.EventsMatching(func(d HistoricalEventDetails) bool { return d.RelatedToMountain(x.Id()) })
2022-05-07 22:17:05 +03:00
case *Identity:
el.Events = world.EventsMatching(func(d HistoricalEventDetails) bool { return d.RelatedToIdentity(x.Id()) })
2022-04-26 10:24:16 +03:00
case []*HistoricalEvent:
el.Events = x
2022-05-03 15:59:47 +03:00
case []int:
el.Events = util.Map(x, func(id int) *HistoricalEvent { return world.HistoricalEvents[id] })
2022-04-26 10:24:16 +03:00
default:
fmt.Printf("unknown type %T\n", obj)
}
return &el
}