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",
"Type": "int"
},
{
"Name": "Plus",
"Type": "bool"
}
],
"Structure": [

View File

@ -81,6 +81,7 @@ func (x *HistoricalEventCollectionCeremony) Html(e *HistoricalEventCollection, c
if event, ok := c.World.HistoricalEvents[e.Event[0]]; ok {
if d, ok := event.Details.(*HistoricalEventCeremony); ok {
if entity, ok := c.World.Entities[d.CivId]; ok {
if d.OccasionId < len(entity.Occasion) {
occ := entity.Occasion[d.OccasionId]
if len(occ.Schedule) > 1 {
switch d.ScheduleId {
@ -96,6 +97,7 @@ func (x *HistoricalEventCollectionCeremony) Html(e *HistoricalEventCollection, c
}
}
}
}
return "the " + e.Link(ord(x.Ordinal)+r) + " of " + c.collection(x.OccasionEventcol)
}
@ -105,12 +107,16 @@ func (x *HistoricalEventCollectionCompetition) Html(e *HistoricalEventCollection
if event, ok := c.World.HistoricalEvents[e.Event[0]]; ok {
if d, ok := event.Details.(*HistoricalEventCompetition); ok {
if entity, ok := c.World.Entities[d.CivId]; ok {
if d.OccasionId < len(entity.Occasion) {
occ := entity.Occasion[d.OccasionId]
if d.ScheduleId < len(occ.Schedule) {
r = occ.Schedule[d.ScheduleId].Type_.String()
}
}
}
}
}
}
return "the " + e.Link(ord(x.Ordinal)+r) + " of " + c.collection(x.OccasionEventcol)
}
@ -137,9 +143,11 @@ func (x *HistoricalEventCollectionJourney) Html(e *HistoricalEventCollection, c
func (x *HistoricalEventCollectionOccasion) Html(e *HistoricalEventCollection, c *Context) string {
if civ, ok := c.World.Entities[x.CivId]; ok {
if x.OccasionId < len(civ.Occasion) {
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")
}
@ -149,12 +157,16 @@ func (x *HistoricalEventCollectionPerformance) Html(e *HistoricalEventCollection
if event, ok := c.World.HistoricalEvents[e.Event[0]]; ok {
if d, ok := event.Details.(*HistoricalEventPerformance); ok {
if entity, ok := c.World.Entities[d.CivId]; ok {
if d.OccasionId < len(entity.Occasion) {
occ := entity.Occasion[d.OccasionId]
if d.ScheduleId < len(occ.Schedule) {
r = occ.Schedule[d.ScheduleId].Type_.String()
}
}
}
}
}
}
return "the " + e.Link(ord(x.Ordinal)+r) + " of " + c.collection(x.OccasionEventcol)
}

View File

@ -425,6 +425,7 @@ func (x *HistoricalEventBuildingProfileAcquired) Html(c *Context) string {
func (x *HistoricalEventCeremony) Html(c *Context) string {
r := c.entity(x.CivId) + " held a ceremony in " + c.site(x.SiteId, "")
if e, ok := c.World.Entities[x.CivId]; ok {
if x.OccasionId < len(e.Occasion) {
o := e.Occasion[x.OccasionId]
r += " as part of " + o.Name()
s := o.Schedule[x.ScheduleId]
@ -432,6 +433,7 @@ func (x *HistoricalEventCeremony) Html(c *Context) string {
r += ". The event featured " + andList(util.Map(s.Feature, c.feature))
}
}
}
return r
}
@ -449,16 +451,12 @@ func (x *HistoricalEventChangeHfBodyState) Html(c *Context) string {
}
func (x *HistoricalEventChangeHfJob) Html(c *Context) string {
w := ""
if x.SubregionId != -1 {
w = " in " + c.region(x.SubregionId)
}
if x.SiteId != -1 {
w = " in " + c.site(x.SiteId, "")
}
w := c.location(x.SiteId, " in", x.SubregionId, " in")
old := articled(strcase.ToDelimited(x.OldJob, ' '))
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
} else if x.NewJob == "standard" {
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")
case HistoricalEventChangeHfStateReason_ConvictionExile, HistoricalEventChangeHfStateReason_ExiledAfterConviction:
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")
}
case HistoricalEventChangeHfStateState_Visiting:
@ -543,10 +541,19 @@ func (x *HistoricalEventChangedCreatureType) Html(c *Context) string {
}
func (x *HistoricalEventCompetition) Html(c *Context) string {
e := c.World.Entities[x.CivId]
oName := "UNKNOWN OCCASION"
sType := "competition"
if e, ok := c.World.Entities[x.CivId]; ok {
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]
return c.entity(x.CivId) + " held a " + strcase.ToDelimited(s.Type_.String(), ' ') + c.site(x.SiteId, " in") + " as part of the " + o.Name() +
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) + ". " +
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 {
r := c.entity(x.CivId) + " held "
oName := "UNKNOWN OCCASION"
sType := "a performance"
if e, ok := c.World.Entities[x.CivId]; ok {
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]
r += c.schedule(s)
r += " as part of " + o.Name()
r += c.site(x.SiteId, " in")
r += string(util.Json(s))
sType = c.schedule(s)
}
}
}
r += sType
r += " as part of " + oName
r += c.site(x.SiteId, " in")
return r
}
@ -2005,6 +2019,7 @@ func (x *HistoricalEventPoeticFormCreated) Html(c *Context) string {
func (x *HistoricalEventProcession) Html(c *Context) string {
r := c.entity(x.CivId) + " held a procession in " + c.site(x.SiteId, "")
if e, ok := c.World.Entities[x.CivId]; ok {
if x.OccasionId < len(e.Occasion) {
o := e.Occasion[x.OccasionId]
r += " as part of " + o.Name()
s := o.Schedule[x.ScheduleId]
@ -2021,6 +2036,7 @@ func (x *HistoricalEventProcession) Html(c *Context) string {
}
r += string(util.Json(s))
}
}
return r
}

View File

@ -49,6 +49,7 @@ var AddMapLandmass = func(w *DfWorld, id int) template.HTML {
var AddMapRegion = func(w *DfWorld, id int) template.HTML {
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) }), ",")
if len(coords) > 0 {
fillColor := "transparent"
switch x.Evilness {
case RegionEvilness_Evil:
@ -58,6 +59,7 @@ var AddMapRegion = func(w *DfWorld, id int) template.HTML {
}
return template.HTML(fmt.Sprintf(`<script>addRegion(%d, [%s], '%s')</script>`, x.Id_, coords, fillColor))
}
}
return ""
}

View File

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

View File

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

View File

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

View File

@ -4,6 +4,7 @@ import (
"sort"
"strings"
"github.com/iancoleman/strcase"
"github.com/robertjanetzko/LegendsBrowser2/backend/util"
"golang.org/x/exp/maps"
"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_ })
}
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
// for _, e := range w.HistoricalEvents {
// e.Details.Html(&Context{World: w})
// }
for _, e := range w.HistoricalEvents {
e.Details.Html(&Context{World: w})
}
for _, e := range w.HistoricalEventCollections {
e.Details.Html(e, &Context{World: w})
}
}