events
This commit is contained in:
parent
b534159a8d
commit
e136b2f8e6
|
@ -103,6 +103,14 @@ type {{ $obj.Name }} struct {
|
|||
{{- end }}
|
||||
}
|
||||
|
||||
func New{{ $obj.Name }}() *{{ $obj.Name }} {
|
||||
return &{{ $obj.Name }}{
|
||||
{{- range $fname, $field := $obj.Fields }}{{- if $field.MustInit }}{{- if not ($field.SameField $obj) }}
|
||||
{{ $field.Init }}
|
||||
{{- end }}{{- end }}{{- end }}
|
||||
}
|
||||
}
|
||||
|
||||
{{- if $obj.Id }}
|
||||
func (x *{{ $obj.Name }}) Id() int { return x.Id_ }
|
||||
{{- end }}
|
||||
|
@ -135,6 +143,14 @@ func (x *{{ $obj.Name }}) CheckFields() {
|
|||
{{- end }}
|
||||
}
|
||||
|
||||
func (x *{{ $obj.Name }}) MarshalJSON() ([]byte, error) {
|
||||
d := make(map[string]any)
|
||||
{{- range $fname, $field := $obj.Fields }}{{- if not ($field.SameField $obj) }}{{- if not (and (eq $fname "type") (not (not $obj.SubTypes))) }}
|
||||
{{ $field.JsonMarshal }}
|
||||
{{- end }}{{- end }}{{- end }}
|
||||
return json.Marshal(d)
|
||||
}
|
||||
|
||||
{{- end }}
|
||||
|
||||
// Parser
|
||||
|
@ -142,21 +158,15 @@ func (x *{{ $obj.Name }}) CheckFields() {
|
|||
{{- range $name, $obj := $.Objects }}
|
||||
{{- range $plus := $.Modes }}
|
||||
func parse{{ $obj.Name }}{{ if $plus }}Plus{{ end }}(p *util.XMLParser{{ if $plus }}, obj *{{ $obj.Name }}{{ end }}) (*{{ $obj.Name }}, error) {
|
||||
var (
|
||||
{{- if not $plus }}
|
||||
obj = &{{ $obj.Name }}{}
|
||||
var obj = New{{ $obj.Name }}()
|
||||
{{- end }}
|
||||
)
|
||||
{{- if $plus }}
|
||||
if obj == nil {
|
||||
obj = &{{ $obj.Name }}{}
|
||||
obj = New{{ $obj.Name }}()
|
||||
}
|
||||
{{- end }}
|
||||
|
||||
{{- range $fname, $field := $obj.Fields }}
|
||||
{{ $field.Init $plus }}
|
||||
{{- end }}
|
||||
|
||||
for {
|
||||
t, n, err := p.Token()
|
||||
if err != nil {
|
||||
|
@ -295,9 +305,21 @@ func (f Field) TypeLine() string {
|
|||
return fmt.Sprintf("%s %s%s %s", n, m, t, j)
|
||||
}
|
||||
|
||||
func (f Field) Init(plus bool) string {
|
||||
if !plus && f.Type == "map" {
|
||||
return fmt.Sprintf("obj.%s = make(map[int]*%s)", f.Name, *f.ElementType)
|
||||
func (f Field) MustInit() bool {
|
||||
return f.Type == "map" || (f.Type == "int" && !f.Multiple)
|
||||
}
|
||||
|
||||
func (f Field) Init() string {
|
||||
n := f.Name
|
||||
if n == "Id" || n == "Name" {
|
||||
n = n + "_"
|
||||
}
|
||||
|
||||
if f.Type == "map" {
|
||||
return fmt.Sprintf("%s: make(map[int]*%s),", n, *f.ElementType)
|
||||
}
|
||||
if f.Type == "int" && !f.Multiple {
|
||||
return fmt.Sprintf("%s: -1,", n)
|
||||
}
|
||||
|
||||
return ""
|
||||
|
@ -439,6 +461,22 @@ func (obj Object) LegendFields(t string) []Field {
|
|||
return list
|
||||
}
|
||||
|
||||
func (f Field) JsonMarshal() string {
|
||||
n := f.Name
|
||||
|
||||
if n == "Id" || n == "Name" {
|
||||
n = n + "_"
|
||||
}
|
||||
|
||||
if f.Type == "int" && !f.Multiple {
|
||||
return fmt.Sprintf(`if x.%s != -1 { d["%s"] = x.%s }`, n, strcase.ToLowerCamel(f.Name), n)
|
||||
}
|
||||
if f.Type == "enum" && !f.Multiple {
|
||||
return fmt.Sprintf(`if x.%s != 0 { d["%s"] = x.%s }`, n, strcase.ToLowerCamel(f.Name), n)
|
||||
}
|
||||
return fmt.Sprintf(`d["%s"] = x.%s`, strcase.ToLowerCamel(f.Name), n)
|
||||
}
|
||||
|
||||
func (f Field) SameField(obj Object) bool {
|
||||
if f.Legend != "plus" {
|
||||
return false
|
||||
|
|
|
@ -135,7 +135,7 @@ func (x *HistoricalEventArtifactClaimFormed) Html() string {
|
|||
case HistoricalEventArtifactClaimFormedClaim_Treasure:
|
||||
c := ""
|
||||
if x.Circumstance != HistoricalEventArtifactClaimFormedCircumstance_Unknown {
|
||||
c = x.Circumstance.String()
|
||||
c = " " + x.Circumstance.String()
|
||||
}
|
||||
if x.HistFigureId != -1 {
|
||||
return a + " was claimed by " + hf(x.HistFigureId) + c
|
||||
|
@ -219,25 +219,64 @@ func (x *HistoricalEventArtifactGiven) Html() string {
|
|||
}
|
||||
func (x *HistoricalEventArtifactLost) Html() string {
|
||||
w := ""
|
||||
if x.SubregionId != -1 {
|
||||
w = region(x.SubregionId)
|
||||
}
|
||||
if x.SiteId != -1 {
|
||||
w = site(x.SiteId, "")
|
||||
}
|
||||
if x.SubregionId != -1 {
|
||||
w = region(x.SubregionId) // TODO optional
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s was lost in %s", artifact(x.ArtifactId), w)
|
||||
}
|
||||
|
||||
func (x *HistoricalEventArtifactPossessed) Html() string {
|
||||
return "UNKNWON HistoricalEventArtifactPossessed"
|
||||
a := artifact(x.ArtifactId)
|
||||
h := hf(x.HistFigureId)
|
||||
w := ""
|
||||
if x.SubregionId != -1 {
|
||||
w = region(x.SubregionId)
|
||||
}
|
||||
if x.SiteId != -1 {
|
||||
w = site(x.SiteId, "")
|
||||
}
|
||||
c := ""
|
||||
switch x.Circumstance {
|
||||
case HistoricalEventArtifactPossessedCircumstance_HfIsDead:
|
||||
c = " after the death of " + hf(x.CircumstanceId)
|
||||
}
|
||||
|
||||
switch x.Reason {
|
||||
case HistoricalEventArtifactPossessedReason_ArtifactIsHeirloomOfFamilyHfid:
|
||||
return fmt.Sprintf("%s was aquired in %s by %s as an heirloom of %s%s", a, w, h, hf(x.ReasonId), c)
|
||||
case HistoricalEventArtifactPossessedReason_ArtifactIsSymbolOfEntityPosition:
|
||||
return fmt.Sprintf("%s was aquired in %s by %s as a symbol of authority within %s%s", a, w, h, entity(x.ReasonId), c)
|
||||
}
|
||||
return fmt.Sprintf("%s was claimed in %s by %s%s", a, w, h, c) // TODO wording
|
||||
}
|
||||
|
||||
func (x *HistoricalEventArtifactRecovered) Html() string {
|
||||
return "UNKNWON HistoricalEventArtifactRecovered"
|
||||
a := artifact(x.ArtifactId)
|
||||
h := hf(x.HistFigureId)
|
||||
w := ""
|
||||
if x.SubregionId != -1 {
|
||||
w = "in " + region(x.SubregionId)
|
||||
}
|
||||
func (x *HistoricalEventArtifactStored) Html() string { return "UNKNWON HistoricalEventArtifactStored" }
|
||||
if x.SiteId != -1 {
|
||||
w = site(x.SiteId, "in ")
|
||||
if x.StructureId != -1 {
|
||||
w = "from " + structure(x.SiteId, x.StructureId) + " " + w
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf("%s was recovered %s by %s", a, w, h)
|
||||
}
|
||||
|
||||
func (x *HistoricalEventArtifactStored) Html() string {
|
||||
return fmt.Sprintf("%s stored %s in %s", hf(x.HistFigureId), artifact(x.ArtifactId), site(x.SiteId, ""))
|
||||
}
|
||||
|
||||
func (x *HistoricalEventArtifactTransformed) Html() string {
|
||||
return "UNKNWON HistoricalEventArtifactTransformed"
|
||||
return fmt.Sprintf("%s was made from %s by %s in %s", artifact(x.NewArtifactId), artifact(x.OldArtifactId), hf(x.HistFigureId), site(x.SiteId, "")) // TODO wording
|
||||
}
|
||||
|
||||
func (x *HistoricalEventAssumeIdentity) Html() string { return "UNKNWON HistoricalEventAssumeIdentity" }
|
||||
func (x *HistoricalEventAttackedSite) Html() string { return "UNKNWON HistoricalEventAttackedSite" }
|
||||
func (x *HistoricalEventBodyAbused) Html() string { return "UNKNWON HistoricalEventBodyAbused" }
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue