dorfylegends/backend/model/extensions.go

73 lines
1.4 KiB
Go
Raw Normal View History

2022-04-16 23:12:23 +03:00
package model
2022-04-19 12:46:43 +03:00
import "fmt"
2022-04-16 23:12:23 +03:00
func (e *Entity) Position(id int) *EntityPosition {
for _, p := range e.EntityPosition {
if p.Id_ == id {
return p
}
}
return nil
}
2022-04-19 18:46:11 +03:00
func (p *EntityPosition) GenderName(hf *HistoricalFigure) string {
if hf.Female() && p.NameFemale != "" {
return p.NameFemale
} else if hf.Male() && p.NameMale != "" {
return p.NameMale
} else {
return p.Name_
}
}
func (hf *HistoricalFigure) Female() bool {
return hf.Sex == 0 || hf.Caste == "FEMALE"
}
func (hf *HistoricalFigure) Male() bool {
return hf.Sex == 1 || hf.Caste == "MALE"
}
2022-04-16 23:12:23 +03:00
type HistoricalEventDetails interface {
2022-04-18 11:36:29 +03:00
RelatedToEntity(int) bool
2022-04-16 23:12:23 +03:00
RelatedToHf(int) bool
2022-04-18 11:36:29 +03:00
Html() string
2022-04-19 18:46:11 +03:00
Type() string
2022-04-16 23:12:23 +03:00
}
type HistoricalEventCollectionDetails interface {
}
2022-04-18 11:36:29 +03:00
func containsInt(list []int, id int) bool {
for _, v := range list {
if v == id {
return true
}
}
return false
}
2022-04-19 12:46:43 +03:00
var world *DfWorld
2022-04-19 18:46:11 +03:00
func entity(id int) string {
if x, ok := world.Entities[id]; ok {
return fmt.Sprintf(`<a href="/entity/%d">%s</a>`, x.Id(), x.Name())
}
return "UNKNOWN ENTITY"
}
2022-04-19 12:46:43 +03:00
func hf(id int) string {
if x, ok := world.HistoricalFigures[id]; ok {
return fmt.Sprintf(`<a href="/hf/%d">%s</a>`, x.Id(), x.Name())
}
return "UNKNOWN HISTORICAL FIGURE"
}
func site(id int, prefix string) string {
if x, ok := world.Sites[id]; ok {
return fmt.Sprintf(`%s <a href="/site/%d">%s</a>`, prefix, x.Id(), x.Name())
}
return "UNKNOWN SITE"
}