fixes if no plus xml

This commit is contained in:
Robert Janetzko 2022-05-08 14:38:38 +00:00
parent 3b15a952ac
commit b561de2d0f
8 changed files with 124 additions and 63 deletions

View File

@ -41,6 +41,10 @@
{ {
"Name": "EndYear", "Name": "EndYear",
"Type": "int" "Type": "int"
},
{
"Name": "Plus",
"Type": "bool"
} }
], ],
"Structure": [ "Structure": [

View File

@ -81,15 +81,17 @@ func (x *HistoricalEventCollectionCeremony) Html(e *HistoricalEventCollection, c
if event, ok := c.World.HistoricalEvents[e.Event[0]]; ok { if event, ok := c.World.HistoricalEvents[e.Event[0]]; ok {
if d, ok := event.Details.(*HistoricalEventCeremony); ok { if d, ok := event.Details.(*HistoricalEventCeremony); ok {
if entity, ok := c.World.Entities[d.CivId]; ok { if entity, ok := c.World.Entities[d.CivId]; ok {
occ := entity.Occasion[d.OccasionId] if d.OccasionId < len(entity.Occasion) {
if len(occ.Schedule) > 1 { occ := entity.Occasion[d.OccasionId]
switch d.ScheduleId { if len(occ.Schedule) > 1 {
case 0: switch d.ScheduleId {
r = "opening ceremony" case 0:
case len(occ.Schedule) - 1: r = "opening ceremony"
r = "closing ceremony" case len(occ.Schedule) - 1:
default: r = "closing ceremony"
r = "main ceremony" default:
r = "main ceremony"
}
} }
} }
} }
@ -105,8 +107,12 @@ func (x *HistoricalEventCollectionCompetition) Html(e *HistoricalEventCollection
if event, ok := c.World.HistoricalEvents[e.Event[0]]; ok { if event, ok := c.World.HistoricalEvents[e.Event[0]]; ok {
if d, ok := event.Details.(*HistoricalEventCompetition); ok { if d, ok := event.Details.(*HistoricalEventCompetition); ok {
if entity, ok := c.World.Entities[d.CivId]; ok { if entity, ok := c.World.Entities[d.CivId]; ok {
occ := entity.Occasion[d.OccasionId] if d.OccasionId < len(entity.Occasion) {
r = occ.Schedule[d.ScheduleId].Type_.String() occ := entity.Occasion[d.OccasionId]
if d.ScheduleId < len(occ.Schedule) {
r = occ.Schedule[d.ScheduleId].Type_.String()
}
}
} }
} }
} }
@ -137,8 +143,10 @@ func (x *HistoricalEventCollectionJourney) Html(e *HistoricalEventCollection, c
func (x *HistoricalEventCollectionOccasion) Html(e *HistoricalEventCollection, c *Context) string { func (x *HistoricalEventCollectionOccasion) Html(e *HistoricalEventCollection, c *Context) string {
if civ, ok := c.World.Entities[x.CivId]; ok { if civ, ok := c.World.Entities[x.CivId]; ok {
occ := civ.Occasion[x.OccasionId] if x.OccasionId < len(civ.Occasion) {
return util.If(x.Ordinal > 1, "the "+ord(x.Ordinal)+"occasion of ", "") + e.Link(occ.Name_) occ := civ.Occasion[x.OccasionId]
return util.If(x.Ordinal > 1, "the "+ord(x.Ordinal)+"occasion of ", "") + e.Link(occ.Name_)
}
} }
return util.If(x.Ordinal > 1, "the "+ord(x.Ordinal)+"occasion of ", "") + e.Link("UNKNOWN OCCASION") return util.If(x.Ordinal > 1, "the "+ord(x.Ordinal)+"occasion of ", "") + e.Link("UNKNOWN OCCASION")
} }
@ -149,8 +157,12 @@ func (x *HistoricalEventCollectionPerformance) Html(e *HistoricalEventCollection
if event, ok := c.World.HistoricalEvents[e.Event[0]]; ok { if event, ok := c.World.HistoricalEvents[e.Event[0]]; ok {
if d, ok := event.Details.(*HistoricalEventPerformance); ok { if d, ok := event.Details.(*HistoricalEventPerformance); ok {
if entity, ok := c.World.Entities[d.CivId]; ok { if entity, ok := c.World.Entities[d.CivId]; ok {
occ := entity.Occasion[d.OccasionId] if d.OccasionId < len(entity.Occasion) {
r = occ.Schedule[d.ScheduleId].Type_.String() occ := entity.Occasion[d.OccasionId]
if d.ScheduleId < len(occ.Schedule) {
r = occ.Schedule[d.ScheduleId].Type_.String()
}
}
} }
} }
} }

View File

@ -425,11 +425,13 @@ func (x *HistoricalEventBuildingProfileAcquired) Html(c *Context) string {
func (x *HistoricalEventCeremony) Html(c *Context) string { func (x *HistoricalEventCeremony) Html(c *Context) string {
r := c.entity(x.CivId) + " held a ceremony in " + c.site(x.SiteId, "") r := c.entity(x.CivId) + " held a ceremony in " + c.site(x.SiteId, "")
if e, ok := c.World.Entities[x.CivId]; ok { if e, ok := c.World.Entities[x.CivId]; ok {
o := e.Occasion[x.OccasionId] if x.OccasionId < len(e.Occasion) {
r += " as part of " + o.Name() o := e.Occasion[x.OccasionId]
s := o.Schedule[x.ScheduleId] r += " as part of " + o.Name()
if len(s.Feature) > 0 { s := o.Schedule[x.ScheduleId]
r += ". The event featured " + andList(util.Map(s.Feature, c.feature)) if len(s.Feature) > 0 {
r += ". The event featured " + andList(util.Map(s.Feature, c.feature))
}
} }
} }
return r return r
@ -449,16 +451,12 @@ func (x *HistoricalEventChangeHfBodyState) Html(c *Context) string {
} }
func (x *HistoricalEventChangeHfJob) Html(c *Context) string { func (x *HistoricalEventChangeHfJob) Html(c *Context) string {
w := "" w := c.location(x.SiteId, " in", x.SubregionId, " in")
if x.SubregionId != -1 {
w = " in " + c.region(x.SubregionId)
}
if x.SiteId != -1 {
w = " in " + c.site(x.SiteId, "")
}
old := articled(strcase.ToDelimited(x.OldJob, ' ')) old := articled(strcase.ToDelimited(x.OldJob, ' '))
new := articled(strcase.ToDelimited(x.NewJob, ' ')) new := articled(strcase.ToDelimited(x.NewJob, ' '))
if x.OldJob == "standard" { if x.OldJob == "" && x.NewJob == "" {
return c.hf(x.Hfid) + " became a UNKNOWN JOB" + w
} else if x.OldJob == "standard" {
return c.hf(x.Hfid) + " became " + new + w return c.hf(x.Hfid) + " became " + new + w
} else if x.NewJob == "standard" { } else if x.NewJob == "standard" {
return c.hf(x.Hfid) + " stopped being " + old + w return c.hf(x.Hfid) + " stopped being " + old + w
@ -502,7 +500,7 @@ func (x *HistoricalEventChangeHfState) Html(c *Context) string {
return c.hf(x.Hfid) + " fled " + c.site(x.SiteId, "to") return c.hf(x.Hfid) + " fled " + c.site(x.SiteId, "to")
case HistoricalEventChangeHfStateReason_ConvictionExile, HistoricalEventChangeHfStateReason_ExiledAfterConviction: case HistoricalEventChangeHfStateReason_ConvictionExile, HistoricalEventChangeHfStateReason_ExiledAfterConviction:
return c.hf(x.Hfid) + " departed " + c.site(x.SiteId, "to") + r return c.hf(x.Hfid) + " departed " + c.site(x.SiteId, "to") + r
case HistoricalEventChangeHfStateReason_None: default:
return c.hf(x.Hfid) + " settled " + c.location(x.SiteId, "in", x.SubregionId, "in") return c.hf(x.Hfid) + " settled " + c.location(x.SiteId, "in", x.SubregionId, "in")
} }
case HistoricalEventChangeHfStateState_Visiting: case HistoricalEventChangeHfStateState_Visiting:
@ -543,10 +541,19 @@ func (x *HistoricalEventChangedCreatureType) Html(c *Context) string {
} }
func (x *HistoricalEventCompetition) Html(c *Context) string { func (x *HistoricalEventCompetition) Html(c *Context) string {
e := c.World.Entities[x.CivId] oName := "UNKNOWN OCCASION"
o := e.Occasion[x.OccasionId] sType := "competition"
s := o.Schedule[x.ScheduleId] if e, ok := c.World.Entities[x.CivId]; ok {
return c.entity(x.CivId) + " held a " + strcase.ToDelimited(s.Type_.String(), ' ') + c.site(x.SiteId, " in") + " as part of the " + o.Name() + if x.OccasionId < len(e.Occasion) {
o := e.Occasion[x.OccasionId]
oName = o.Name_
if x.ScheduleId < len(o.Schedule) {
s := o.Schedule[x.ScheduleId]
sType = strcase.ToDelimited(s.Type_.String(), ' ')
}
}
}
return c.entity(x.CivId) + " held a " + sType + c.site(x.SiteId, " in") + " as part of the " + oName +
". Competing " + util.If(len(x.CompetitorHfid) > 1, "were ", "was ") + c.hfList(x.CompetitorHfid) + ". " + ". Competing " + util.If(len(x.CompetitorHfid) > 1, "were ", "was ") + c.hfList(x.CompetitorHfid) + ". " +
util.Capitalize(c.hf(x.WinnerHfid)) + " was the victor" util.Capitalize(c.hf(x.WinnerHfid)) + " was the victor"
} }
@ -1976,14 +1983,21 @@ func (x *HistoricalEventPeaceRejected) Html(c *Context) string {
func (x *HistoricalEventPerformance) Html(c *Context) string { func (x *HistoricalEventPerformance) Html(c *Context) string {
r := c.entity(x.CivId) + " held " r := c.entity(x.CivId) + " held "
oName := "UNKNOWN OCCASION"
sType := "a performance"
if e, ok := c.World.Entities[x.CivId]; ok { if e, ok := c.World.Entities[x.CivId]; ok {
o := e.Occasion[x.OccasionId] if x.OccasionId < len(e.Occasion) {
s := o.Schedule[x.ScheduleId] o := e.Occasion[x.OccasionId]
r += c.schedule(s) oName = o.Name_
r += " as part of " + o.Name() if x.ScheduleId < len(o.Schedule) {
r += c.site(x.SiteId, " in") s := o.Schedule[x.ScheduleId]
r += string(util.Json(s)) sType = c.schedule(s)
}
}
} }
r += sType
r += " as part of " + oName
r += c.site(x.SiteId, " in")
return r return r
} }
@ -2005,21 +2019,23 @@ func (x *HistoricalEventPoeticFormCreated) Html(c *Context) string {
func (x *HistoricalEventProcession) Html(c *Context) string { func (x *HistoricalEventProcession) Html(c *Context) string {
r := c.entity(x.CivId) + " held a procession in " + c.site(x.SiteId, "") r := c.entity(x.CivId) + " held a procession in " + c.site(x.SiteId, "")
if e, ok := c.World.Entities[x.CivId]; ok { if e, ok := c.World.Entities[x.CivId]; ok {
o := e.Occasion[x.OccasionId] if x.OccasionId < len(e.Occasion) {
r += " as part of " + o.Name() o := e.Occasion[x.OccasionId]
s := o.Schedule[x.ScheduleId] r += " as part of " + o.Name()
if s.Reference != -1 { s := o.Schedule[x.ScheduleId]
r += ". It started at " + c.structure(x.SiteId, s.Reference) if s.Reference != -1 {
if s.Reference2 != -1 && s.Reference2 != s.Reference { r += ". It started at " + c.structure(x.SiteId, s.Reference)
r += " and ended at " + c.structure(x.SiteId, s.Reference2) if s.Reference2 != -1 && s.Reference2 != s.Reference {
} else { r += " and ended at " + c.structure(x.SiteId, s.Reference2)
r += " and returned there after following its route" } else {
r += " and returned there after following its route"
}
} }
if len(s.Feature) > 0 {
r += ". The event featured " + andList(util.Map(s.Feature, c.feature))
}
r += string(util.Json(s))
} }
if len(s.Feature) > 0 {
r += ". The event featured " + andList(util.Map(s.Feature, c.feature))
}
r += string(util.Json(s))
} }
return r return r
} }

View File

@ -49,14 +49,16 @@ var AddMapLandmass = func(w *DfWorld, id int) template.HTML {
var AddMapRegion = func(w *DfWorld, id int) template.HTML { var AddMapRegion = func(w *DfWorld, id int) template.HTML {
if x, ok := w.Regions[id]; ok { if x, ok := w.Regions[id]; ok {
coords := strings.Join(util.Map(x.Outline(), func(c Coord) string { return fmt.Sprintf(`coord(%d,%d)`, c.X, c.Y-1) }), ",") coords := strings.Join(util.Map(x.Outline(), func(c Coord) string { return fmt.Sprintf(`coord(%d,%d)`, c.X, c.Y-1) }), ",")
fillColor := "transparent" if len(coords) > 0 {
switch x.Evilness { fillColor := "transparent"
case RegionEvilness_Evil: switch x.Evilness {
fillColor = "fuchsia" case RegionEvilness_Evil:
case RegionEvilness_Good: fillColor = "fuchsia"
fillColor = "aqua" case RegionEvilness_Good:
fillColor = "aqua"
}
return template.HTML(fmt.Sprintf(`<script>addRegion(%d, [%s], '%s')</script>`, x.Id_, coords, fillColor))
} }
return template.HTML(fmt.Sprintf(`<script>addRegion(%d, [%s], '%s')</script>`, x.Id_, coords, fillColor))
} }
return "" return ""
} }

View File

@ -121,6 +121,10 @@ func maxCoords(coords []Coord) Coord {
func (r *Region) Outline() []Coord { func (r *Region) Outline() []Coord {
var outline []Coord var outline []Coord
if r.Coords == "" {
return outline
}
// if (cacheOutline != null) // if (cacheOutline != null)
// return cacheOutline; // return cacheOutline;

View File

@ -1548,6 +1548,7 @@ type DfWorld struct {
Height int `json:"height" legend:"add" related:""` // Height Height int `json:"height" legend:"add" related:""` // Height
MapData []byte `json:"mapData" legend:"add" related:""` // MapData MapData []byte `json:"mapData" legend:"add" related:""` // MapData
MapReady bool `json:"mapReady" legend:"add" related:""` // MapReady MapReady bool `json:"mapReady" legend:"add" related:""` // MapReady
Plus bool `json:"plus" legend:"add" related:""` // Plus
PlusFilePath string `json:"plusFilePath" legend:"add" related:""` // PlusFilePath PlusFilePath string `json:"plusFilePath" legend:"add" related:""` // PlusFilePath
Width int `json:"width" legend:"add" related:""` // Width Width int `json:"width" legend:"add" related:""` // Width
} }
@ -1616,6 +1617,7 @@ func (x *DfWorld) MarshalJSON() ([]byte, error) {
} }
d["mapData"] = x.MapData d["mapData"] = x.MapData
d["mapReady"] = x.MapReady d["mapReady"] = x.MapReady
d["plus"] = x.Plus
d["plusFilePath"] = x.PlusFilePath d["plusFilePath"] = x.PlusFilePath
if x.Width != -1 { if x.Width != -1 {
d["width"] = x.Width d["width"] = x.Width

View File

@ -99,7 +99,7 @@ BaseLoop:
bar.Finish() bar.Finish()
plus := true plus := false
if plus { if plus {
file = strings.Replace(file, "-legends.xml", "-legends_plus.xml", 1) file = strings.Replace(file, "-legends.xml", "-legends_plus.xml", 1)
@ -131,6 +131,7 @@ BaseLoop:
} }
} }
} }
world.Plus = true
world.PlusFilePath = file world.PlusFilePath = file
bar.Finish() bar.Finish()

View File

@ -4,6 +4,7 @@ import (
"sort" "sort"
"strings" "strings"
"github.com/iancoleman/strcase"
"github.com/robertjanetzko/LegendsBrowser2/backend/util" "github.com/robertjanetzko/LegendsBrowser2/backend/util"
"golang.org/x/exp/maps" "golang.org/x/exp/maps"
"golang.org/x/exp/slices" "golang.org/x/exp/slices"
@ -49,10 +50,29 @@ func (w *DfWorld) process() {
sort.Slice(e.Wars, func(i, j int) bool { return e.Wars[i].Id_ < e.Wars[j].Id_ }) sort.Slice(e.Wars, func(i, j int) bool { return e.Wars[i].Id_ < e.Wars[j].Id_ })
} }
if !w.Plus {
for _, hf := range w.HistoricalFigures {
hf.Race = strings.Trim(strcase.ToDelimited(hf.Race, ' '), " 0123456789")
}
for _, a := range w.DanceForms {
a.Name_ = a.Description[:strings.Index(a.Description, " is a ")]
}
for _, a := range w.MusicalForms {
a.Name_ = a.Description[:strings.Index(a.Description, " is a ")]
}
for _, a := range w.PoeticForms {
a.Name_ = a.Description[:strings.Index(a.Description, " is a ")]
}
}
// check events texts // check events texts
// for _, e := range w.HistoricalEvents { for _, e := range w.HistoricalEvents {
// e.Details.Html(&Context{World: w}) e.Details.Html(&Context{World: w})
// } }
for _, e := range w.HistoricalEventCollections {
e.Details.Html(e, &Context{World: w})
}
} }