prevent errors on unknown events - generator - fixes #13

This commit is contained in:
Robert Janetzko 2023-11-17 16:16:34 +01:00
parent bd631ebff9
commit 5120a19a28
4 changed files with 25 additions and 3 deletions

View File

@ -1,2 +1,5 @@
gen:
go run analyze.go -g=true
analyze:
go run analyze.go -l -a /workspaces/LegendsBrowser2/inputs4

View File

@ -4281,6 +4281,7 @@
"Base": true,
"Plus": false,
"Values": {
"as a symbol of everlasting peace": true,
"part of trade negotiation": true
},
"Enum": true
@ -12296,7 +12297,8 @@
"Values": {
"Autumn": true,
"Spring": true,
"Summer": true
"Summer": true,
"Winter": true
},
"Enum": true
},

View File

@ -21,9 +21,14 @@ func enumValue(s string) string {
}
func enumString(s string) string { return strcase.ToDelimited(s, ' ') }
func startswith(str, prefix string) bool {
return strings.HasPrefix(str, prefix)
}
var backendTemplate = template.Must(template.New("").Funcs(template.FuncMap{
"enum": enumValue,
"enumString": enumString,
"startswith": startswith,
}).Parse(`// Code generated by legendsbrowser; DO NOT EDIT.
package model
@ -234,7 +239,9 @@ func parse{{ $obj.Name }}{{ if $plus }}Plus{{ end }}(p *util.XMLParser{{ if $plu
{{- end }}
{{- end }}
default:
{{- if not (startswith $obj.Name "HistoricalEventCollection") }}
obj.Details = NewHistoricalEventUnknown(string(data))
{{- end }}
p.Skip()
}
if err != nil {

View File

@ -4431,11 +4431,14 @@ type HistoricalEventArtifactGivenReason int
const (
HistoricalEventArtifactGivenReason_Unknown HistoricalEventArtifactGivenReason = iota
HistoricalEventArtifactGivenReason_AsASymbolOfEverlastingPeace
HistoricalEventArtifactGivenReason_PartOfTradeNegotiation
)
func parseHistoricalEventArtifactGivenReason(s string) HistoricalEventArtifactGivenReason {
switch s {
case "as a symbol of everlasting peace":
return HistoricalEventArtifactGivenReason_AsASymbolOfEverlastingPeace
case "part of trade negotiation":
return HistoricalEventArtifactGivenReason_PartOfTradeNegotiation
}
@ -4444,6 +4447,8 @@ func parseHistoricalEventArtifactGivenReason(s string) HistoricalEventArtifactGi
func (s HistoricalEventArtifactGivenReason) String() string {
switch s {
case HistoricalEventArtifactGivenReason_AsASymbolOfEverlastingPeace:
return "as a symbol of everlasting peace"
case HistoricalEventArtifactGivenReason_PartOfTradeNegotiation:
return "part of trade negotiation"
}
@ -18617,6 +18622,7 @@ const (
HistoricalEventSiteTributeForcedSeason_Autumn
HistoricalEventSiteTributeForcedSeason_Spring
HistoricalEventSiteTributeForcedSeason_Summer
HistoricalEventSiteTributeForcedSeason_Winter
)
func parseHistoricalEventSiteTributeForcedSeason(s string) HistoricalEventSiteTributeForcedSeason {
@ -18627,6 +18633,8 @@ func parseHistoricalEventSiteTributeForcedSeason(s string) HistoricalEventSiteTr
return HistoricalEventSiteTributeForcedSeason_Spring
case "Summer":
return HistoricalEventSiteTributeForcedSeason_Summer
case "Winter":
return HistoricalEventSiteTributeForcedSeason_Winter
}
return HistoricalEventSiteTributeForcedSeason_Unknown
}
@ -18639,6 +18647,8 @@ func (s HistoricalEventSiteTributeForcedSeason) String() string {
return "spring"
case HistoricalEventSiteTributeForcedSeason_Summer:
return "summer"
case HistoricalEventSiteTributeForcedSeason_Winter:
return "winter"
}
return "unknown"
}
@ -25187,7 +25197,6 @@ func parseHistoricalEvent(p *util.XMLParser) (*HistoricalEvent, error) {
case "written content composed":
obj.Details, err = parseHistoricalEventWrittenContentComposed(p)
default:
obj.Details = NewHistoricalEventUnknown(string(data))
p.Skip()
}
@ -25332,6 +25341,7 @@ func parseHistoricalEventPlus(p *util.XMLParser, obj *HistoricalEvent) (*Histori
case "war_peace_rejected":
obj.Details, err = parseHistoricalEventPeaceRejectedPlus(p, obj.Details.(*HistoricalEventPeaceRejected))
default:
obj.Details = NewHistoricalEventUnknown(string(data))
p.Skip()
}
if err != nil {