file chooser, entities

This commit is contained in:
Robert Janetzko 2022-04-27 19:44:39 +00:00
parent 75208cfe85
commit 51d4ae08a7
17 changed files with 1987 additions and 128 deletions

View file

@ -279,12 +279,16 @@ func GenerateBackendCode(objects *Metadata) error {
return err
}
func (f Field) TypeLine() string {
func (f Field) FixedName() string {
n := f.Name
if n == "Id" || n == "Name" {
if n == "Id" || n == "Name" || n == "Type" {
n = n + "_"
}
return n
}
func (f Field) TypeLine() string {
n := f.FixedName()
m := ""
if f.Multiple {
@ -312,10 +316,7 @@ func (f Field) MustInit() bool {
}
func (f Field) Init() string {
n := f.Name
if n == "Id" || n == "Name" {
n = n + "_"
}
n := f.FixedName()
if f.Type == "map" {
return fmt.Sprintf("%s: make(map[int]*%s),", n, *f.ElementType)
@ -328,11 +329,7 @@ func (f Field) Init() string {
}
func (f Field) StartAction(obj Object, plus bool) string {
n := f.Name
if n == "Id" || n == "Name" {
n = n + "_"
}
n := f.FixedName()
if f.Type == "object" {
var p string
@ -366,11 +363,9 @@ func (f Field) StartAction(obj Object, plus bool) string {
}
if f.Type == "int" || f.Type == "string" || f.Type == "bool" || f.Type == "enum" {
n := f.Name
n := f.FixedName()
if n == "Id" || n == "Name" {
n = n + "_"
} else {
if f.Name == n {
n = f.CorrectedName(obj)
}
@ -385,7 +380,7 @@ func (f Field) StartAction(obj Object, plus bool) string {
s := "_, err := p.Value()\nif err != nil { return nil, err }\n"
return fmt.Sprintf("%sobj.%s = true", s, n)
} else if f.Type == "enum" {
return fmt.Sprintf("%sobj.%s = parse%s%s(txt(data))", s, n, obj.Name, n)
return fmt.Sprintf("%sobj.%s = parse%s%s(txt(data))", s, n, obj.Name, f.CorrectedName(obj))
}
} else {
if f.Type == "int" {
@ -393,7 +388,7 @@ func (f Field) StartAction(obj Object, plus bool) string {
} else if f.Type == "string" {
return fmt.Sprintf("%sobj.%s = append(obj.%s, txt(data))", s, n, n)
} else if f.Type == "enum" {
return fmt.Sprintf("%sobj.%s = append(obj.%s, parse%s%s(txt(data)))", s, n, n, obj.Name, n)
return fmt.Sprintf("%sobj.%s = append(obj.%s, parse%s%s(txt(data)))", s, n, n, obj.Name, f.CorrectedName(obj))
}
}
}
@ -402,11 +397,9 @@ func (f Field) StartAction(obj Object, plus bool) string {
}
func (f Field) EndAction(obj Object) string {
n := f.Name
n := f.FixedName()
if n == "Id" || n == "Name" {
n = n + "_"
} else {
if f.Name == n {
n = f.CorrectedName(obj)
}
@ -418,7 +411,7 @@ func (f Field) EndAction(obj Object) string {
} else if f.Type == "bool" {
return fmt.Sprintf("obj.%s = true", n)
} else if f.Type == "enum" {
return fmt.Sprintf("obj.%s = parse%s%s(string(data))", n, obj.Name, n)
return fmt.Sprintf("obj.%s = parse%s%s(string(data))", n, obj.Name, f.CorrectedName(obj))
}
} else {
if f.Type == "int" {
@ -426,7 +419,7 @@ func (f Field) EndAction(obj Object) string {
} else if f.Type == "string" {
return fmt.Sprintf("obj.%s = append(obj.%s, string(data))", n, n)
} else if f.Type == "enum" {
return fmt.Sprintf("obj.%s = append(obj.%s, parse%s%s(string(data)))", n, n, obj.Name, n)
return fmt.Sprintf("obj.%s = append(obj.%s, parse%s%s(string(data)))", n, n, obj.Name, f.CorrectedName(obj))
}
}
@ -485,11 +478,7 @@ func (obj Object) LegendFields(t string) []Field {
}
func (f Field) JsonMarshal() string {
n := f.Name
if n == "Id" || n == "Name" {
n = n + "_"
}
n := f.FixedName()
if f.Type == "int" && !f.Multiple {
return fmt.Sprintf(`if x.%s != -1 { d["%s"] = x.%s }`, n, strcase.ToLowerCamel(f.Name), n)

View file

@ -4,17 +4,21 @@ go 1.18
require (
github.com/cheggaaa/pb/v3 v3.0.8
github.com/dustin/go-humanize v1.0.0
github.com/gorilla/mux v1.8.0
github.com/iancoleman/strcase v0.2.0
github.com/pkg/profile v1.6.0
github.com/shirou/gopsutil v3.21.11+incompatible
)
require (
github.com/VividCortex/ewma v1.1.1 // indirect
github.com/fatih/color v1.10.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/mattn/go-runewidth v0.0.12 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57 // indirect
)

View file

@ -2,8 +2,12 @@ github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdc
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
github.com/cheggaaa/pb/v3 v3.0.8 h1:bC8oemdChbke2FHIIGy9mn4DPJ2caZYQnfbRqwmdCoA=
github.com/cheggaaa/pb/v3 v3.0.8/go.mod h1:UICbiLec/XO6Hw6k+BHEtHeQFzzBH4i2/qk/ow1EJTA=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg=
github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0=
@ -19,6 +23,11 @@ github.com/pkg/profile v1.6.0/go.mod h1:qBsxPvzyUincmltOk6iyRVxHYg4adc0OFOv72ZdL
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg=
github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57 h1:F5Gozwx4I1xtr/sr/8CFbb57iKi3297KFs0QDbGN60A=

View file

@ -124,7 +124,7 @@ func (c *Context) property(siteId, propertyId int) string {
if y.StructureId != -1 {
return c.structure(siteId, y.StructureId)
}
return articled(y.Type.String())
return articled(y.Type_.String())
}
}
return "UNKNOWN PROPERTY"
@ -214,7 +214,7 @@ func (c *Context) writtenContent(id int) string {
}
func (c *Context) feature(x *Feature) string {
switch x.Type {
switch x.Type_ {
case FeatureType_DancePerformance:
return "a perfomance of " + c.danceForm(x.Reference)
case FeatureType_Images:
@ -234,12 +234,12 @@ func (c *Context) feature(x *Feature) string {
}
return "a story recital"
default:
return strcase.ToDelimited(x.Type.String(), ' ')
return strcase.ToDelimited(x.Type_.String(), ' ')
}
}
func (c *Context) schedule(x *Schedule) string {
switch x.Type {
switch x.Type_ {
case ScheduleType_DancePerformance:
return "a perfomance of " + c.danceForm(x.Reference)
case ScheduleType_MusicalPerformance:
@ -254,7 +254,7 @@ func (c *Context) schedule(x *Schedule) string {
}
return "a story recital"
default:
return strcase.ToDelimited(x.Type.String(), ' ')
return strcase.ToDelimited(x.Type_.String(), ' ')
}
}

View file

@ -178,7 +178,7 @@ func (x *HistoricalEventArtifactCreated) Html(c *Context) string {
}
e := ""
if x.Circumstance != nil {
switch x.Circumstance.Type {
switch x.Circumstance.Type_ {
case HistoricalEventArtifactCreatedCircumstanceType_Defeated:
e = " after defeating " + c.hf(x.Circumstance.Defeated)
case HistoricalEventArtifactCreatedCircumstanceType_Favoritepossession:
@ -500,7 +500,7 @@ func (x *HistoricalEventCompetition) Html(c *Context) string {
e := c.World.Entities[x.CivId]
o := e.Occasion[x.OccasionId]
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() +
return c.entity(x.CivId) + " held a " + strcase.ToDelimited(s.Type_.String(), ' ') + c.site(x.SiteId, " in") + " as part of the " + o.Name() +
". Competing " + util.If(len(x.CompetitorHfid) > 1, "were ", "was ") + c.hfList(x.CompetitorHfid) + ". " +
util.Capitalize(c.hf(x.WinnerHfid)) + " was the victor"
}
@ -1236,7 +1236,7 @@ func (x *HistoricalEventItemStolen) Html(c *Context) string {
i := util.If(x.Item != -1, c.artifact(x.Item), articled(x.Mat+" "+x.ItemType))
circumstance := ""
if x.Circumstance != nil {
switch x.Circumstance.Type {
switch x.Circumstance.Type_ {
case HistoricalEventItemStolenCircumstanceType_Defeated:
circumstance = " after defeating " + c.hfRelated(x.Circumstance.Defeated, x.Histfig)
case HistoricalEventItemStolenCircumstanceType_Histeventcollection: // TODO during ...

View file

@ -48,6 +48,10 @@ func (w *DfWorld) EventsMatching(f func(HistoricalEventDetails) bool) []*Histori
return list
}
func (e *Entity) Type() string {
return e.Type_.String()
}
func (e *Entity) Position(id int) *EntityPosition {
for _, p := range e.EntityPosition {
if p.Id_ == id {

View file

@ -1982,7 +1982,7 @@ type Entity struct {
Occasion []*Occasion `json:"occasion" legend:"plus"` // occasion
Profession EntityProfession `json:"profession" legend:"plus"` // profession
Race string `json:"race" legend:"plus"` // race
Type EntityType `json:"type" legend:"plus"` // type
Type_ EntityType `json:"type" legend:"plus"` // type
Weapon []EntityWeapon `json:"weapon" legend:"plus"` // weapon
WorshipId []int `json:"worshipId" legend:"plus"` // worship_id
}
@ -2021,8 +2021,8 @@ func (x *Entity) MarshalJSON() ([]byte, error) {
d["profession"] = x.Profession
}
d["race"] = x.Race
if x.Type != 0 {
d["type"] = x.Type
if x.Type_ != 0 {
d["type"] = x.Type_
}
d["weapon"] = x.Weapon
d["worshipId"] = x.WorshipId
@ -2069,7 +2069,7 @@ func (s EntityEntityLinkType) MarshalJSON() ([]byte, error) {
type EntityEntityLink struct {
Strength int `json:"strength" legend:"plus"` // strength
Target int `json:"target" legend:"plus"` // target
Type EntityEntityLinkType `json:"type" legend:"plus"` // type
Type_ EntityEntityLinkType `json:"type" legend:"plus"` // type
}
func NewEntityEntityLink() *EntityEntityLink {
@ -2095,8 +2095,8 @@ func (x *EntityEntityLink) MarshalJSON() ([]byte, error) {
if x.Target != -1 {
d["target"] = x.Target
}
if x.Type != 0 {
d["type"] = x.Type
if x.Type_ != 0 {
d["type"] = x.Type_
}
return json.Marshal(d)
}
@ -2566,7 +2566,7 @@ func (s FeatureType) MarshalJSON() ([]byte, error) {
type Feature struct {
Reference int `json:"reference" legend:"plus"` // reference
Type FeatureType `json:"type" legend:"plus"` // type
Type_ FeatureType `json:"type" legend:"plus"` // type
}
func NewFeature() *Feature {
@ -2588,8 +2588,8 @@ func (x *Feature) MarshalJSON() ([]byte, error) {
if x.Reference != -1 {
d["reference"] = x.Reference
}
if x.Type != 0 {
d["type"] = x.Type
if x.Type_ != 0 {
d["type"] = x.Type_
}
return json.Marshal(d)
}
@ -4203,7 +4203,7 @@ func (s HistoricalEventArtifactCreatedCircumstanceType) MarshalJSON() ([]byte, e
type HistoricalEventArtifactCreatedCircumstance struct {
Defeated int `json:"defeated" legend:"plus"` // defeated
Type HistoricalEventArtifactCreatedCircumstanceType `json:"type" legend:"plus"` // type
Type_ HistoricalEventArtifactCreatedCircumstanceType `json:"type" legend:"plus"` // type
}
func NewHistoricalEventArtifactCreatedCircumstance() *HistoricalEventArtifactCreatedCircumstance {
@ -4225,8 +4225,8 @@ func (x *HistoricalEventArtifactCreatedCircumstance) MarshalJSON() ([]byte, erro
if x.Defeated != -1 {
d["defeated"] = x.Defeated
}
if x.Type != 0 {
d["type"] = x.Type
if x.Type_ != 0 {
d["type"] = x.Type_
}
return json.Marshal(d)
}
@ -12595,7 +12595,7 @@ type HistoricalEventItemStolenCircumstance struct {
Defeated int `json:"defeated" legend:"plus"` // defeated
HistEventCollection int `json:"histEventCollection" legend:"plus"` // hist_event_collection
Murdered int `json:"murdered" legend:"plus"` // murdered
Type HistoricalEventItemStolenCircumstanceType `json:"type" legend:"plus"` // type
Type_ HistoricalEventItemStolenCircumstanceType `json:"type" legend:"plus"` // type
}
func NewHistoricalEventItemStolenCircumstance() *HistoricalEventItemStolenCircumstance {
@ -12625,8 +12625,8 @@ func (x *HistoricalEventItemStolenCircumstance) MarshalJSON() ([]byte, error) {
if x.Murdered != -1 {
d["murdered"] = x.Murdered
}
if x.Type != 0 {
d["type"] = x.Type
if x.Type_ != 0 {
d["type"] = x.Type_
}
return json.Marshal(d)
}
@ -17298,7 +17298,7 @@ type IntriguePlot struct {
ParentPlotHfid int `json:"parentPlotHfid" legend:"base"` // parent_plot_hfid
ParentPlotId int `json:"parentPlotId" legend:"base"` // parent_plot_id
PlotActor []*PlotActor `json:"plotActor" legend:"base"` // plot_actor
Type IntriguePlotType `json:"type" legend:"base"` // type
Type_ IntriguePlotType `json:"type" legend:"base"` // type
}
func NewIntriguePlot() *IntriguePlot {
@ -17352,8 +17352,8 @@ func (x *IntriguePlot) MarshalJSON() ([]byte, error) {
d["parentPlotId"] = x.ParentPlotId
}
d["plotActor"] = x.PlotActor
if x.Type != 0 {
d["type"] = x.Type
if x.Type_ != 0 {
d["type"] = x.Type_
}
return json.Marshal(d)
}
@ -17742,8 +17742,8 @@ func (s ReferenceType) MarshalJSON() ([]byte, error) {
}
type Reference struct {
Id_ int `json:"id" legend:"plus"` // id
Type ReferenceType `json:"type" legend:"plus"` // type
Id_ int `json:"id" legend:"plus"` // id
Type_ ReferenceType `json:"type" legend:"plus"` // type
}
func NewReference() *Reference {
@ -17766,8 +17766,8 @@ func (x *Reference) MarshalJSON() ([]byte, error) {
if x.Id_ != -1 {
d["id"] = x.Id_
}
if x.Type != 0 {
d["type"] = x.Type
if x.Type_ != 0 {
d["type"] = x.Type_
}
return json.Marshal(d)
}
@ -17887,7 +17887,7 @@ type Region struct {
ForceId int `json:"forceId" legend:"plus"` // force_id
Id_ int `json:"id" legend:"both"` // id
Name_ string `json:"name" legend:"base"` // name
Type RegionType `json:"type" legend:"base"` // type
Type_ RegionType `json:"type" legend:"base"` // type
}
func NewRegion() *Region {
@ -17920,8 +17920,8 @@ func (x *Region) MarshalJSON() ([]byte, error) {
d["id"] = x.Id_
}
d["name"] = x.Name_
if x.Type != 0 {
d["type"] = x.Type
if x.Type_ != 0 {
d["type"] = x.Type_
}
return json.Marshal(d)
}
@ -18479,7 +18479,7 @@ type Schedule struct {
ItemType ScheduleItemType `json:"itemType" legend:"plus"` // item_type
Reference int `json:"reference" legend:"plus"` // reference
Reference2 int `json:"reference2" legend:"plus"` // reference2
Type ScheduleType `json:"type" legend:"plus"` // type
Type_ ScheduleType `json:"type" legend:"plus"` // type
}
func NewSchedule() *Schedule {
@ -18517,8 +18517,8 @@ func (x *Schedule) MarshalJSON() ([]byte, error) {
if x.Reference2 != -1 {
d["reference2"] = x.Reference2
}
if x.Type != 0 {
d["type"] = x.Type
if x.Type_ != 0 {
d["type"] = x.Type_
}
return json.Marshal(d)
}
@ -18654,7 +18654,7 @@ type Site struct {
Rectangle string `json:"rectangle" legend:"base"` // rectangle
SiteProperties map[int]*SiteSiteProperty `json:"siteProperties" legend:"base"` // site_properties
Structures map[int]*Structure `json:"structures" legend:"both"` // structures
Type SiteType `json:"type" legend:"base"` // type
Type_ SiteType `json:"type" legend:"base"` // type
}
func NewSite() *Site {
@ -18693,8 +18693,8 @@ func (x *Site) MarshalJSON() ([]byte, error) {
d["rectangle"] = x.Rectangle
d["siteProperties"] = x.SiteProperties
d["structures"] = x.Structures
if x.Type != 0 {
d["type"] = x.Type
if x.Type_ != 0 {
d["type"] = x.Type_
}
return json.Marshal(d)
}
@ -18837,7 +18837,7 @@ type SiteSiteProperty struct {
Id_ int `json:"id" legend:"base"` // id
OwnerHfid int `json:"ownerHfid" legend:"base"` // owner_hfid
StructureId int `json:"structureId" legend:"base"` // structure_id
Type SiteSitePropertyType `json:"type" legend:"base"` // type
Type_ SiteSitePropertyType `json:"type" legend:"base"` // type
}
func NewSiteSiteProperty() *SiteSiteProperty {
@ -18868,8 +18868,8 @@ func (x *SiteSiteProperty) MarshalJSON() ([]byte, error) {
if x.StructureId != -1 {
d["structureId"] = x.StructureId
}
if x.Type != 0 {
d["type"] = x.Type
if x.Type_ != 0 {
d["type"] = x.Type_
}
return json.Marshal(d)
}
@ -19009,7 +19009,7 @@ type Structure struct {
Name2 string `json:"name2" legend:"plus"` // name2
Religion int `json:"religion" legend:"plus"` // religion
Subtype StructureSubtype `json:"subtype" legend:"base"` // subtype
Type StructureType `json:"type" legend:"both"` // type
Type_ StructureType `json:"type" legend:"both"` // type
WorshipHfid int `json:"worshipHfid" legend:"base"` // worship_hfid
}
@ -19102,8 +19102,8 @@ func (x *Structure) MarshalJSON() ([]byte, error) {
if x.Subtype != 0 {
d["subtype"] = x.Subtype
}
if x.Type != 0 {
d["type"] = x.Type
if x.Type_ != 0 {
d["type"] = x.Type_
}
if x.WorshipHfid != -1 {
d["worshipHfid"] = x.WorshipHfid
@ -19152,7 +19152,7 @@ type UndergroundRegion struct {
Coords string `json:"coords" legend:"plus"` // coords
Depth int `json:"depth" legend:"base"` // depth
Id_ int `json:"id" legend:"both"` // id
Type UndergroundRegionType `json:"type" legend:"base"` // type
Type_ UndergroundRegionType `json:"type" legend:"base"` // type
}
func NewUndergroundRegion() *UndergroundRegion {
@ -19180,8 +19180,8 @@ func (x *UndergroundRegion) MarshalJSON() ([]byte, error) {
if x.Id_ != -1 {
d["id"] = x.Id_
}
if x.Type != 0 {
d["type"] = x.Type
if x.Type_ != 0 {
d["type"] = x.Type_
}
return json.Marshal(d)
}
@ -19279,7 +19279,7 @@ type WorldConstruction struct {
Coords string `json:"coords" legend:"plus"` // coords
Id_ int `json:"id" legend:"plus"` // id
Name_ string `json:"name" legend:"plus"` // name
Type WorldConstructionType `json:"type" legend:"plus"` // type
Type_ WorldConstructionType `json:"type" legend:"plus"` // type
}
func NewWorldConstruction() *WorldConstruction {
@ -19305,8 +19305,8 @@ func (x *WorldConstruction) MarshalJSON() ([]byte, error) {
d["id"] = x.Id_
}
d["name"] = x.Name_
if x.Type != 0 {
d["type"] = x.Type
if x.Type_ != 0 {
d["type"] = x.Type_
}
return json.Marshal(d)
}
@ -19616,7 +19616,7 @@ type WrittenContent struct {
Reference []*Reference `json:"reference" legend:"plus"` // reference
Style []string `json:"style" legend:"both"` // style
Title string `json:"title" legend:"both"` // title
Type WrittenContentType `json:"type" legend:"plus"` // type
Type_ WrittenContentType `json:"type" legend:"plus"` // type
}
func NewWrittenContent() *WrittenContent {
@ -19683,8 +19683,8 @@ func (x *WrittenContent) MarshalJSON() ([]byte, error) {
d["reference"] = x.Reference
d["style"] = x.Style
d["title"] = x.Title
if x.Type != 0 {
d["type"] = x.Type
if x.Type_ != 0 {
d["type"] = x.Type_
}
return json.Marshal(d)
}
@ -20900,7 +20900,7 @@ func parseEntityPlus(p *util.XMLParser, obj *Entity) (*Entity, error) {
if err != nil {
return nil, err
}
obj.Type = parseEntityType(txt(data))
obj.Type_ = parseEntityType(txt(data))
case "weapon":
data, err := p.Value()
if err != nil {
@ -20976,7 +20976,7 @@ func parseEntityEntityLinkPlus(p *util.XMLParser, obj *EntityEntityLink) (*Entit
if err != nil {
return nil, err
}
obj.Type = parseEntityEntityLinkType(txt(data))
obj.Type_ = parseEntityEntityLinkType(txt(data))
default:
// fmt.Println("unknown field", n)
p.Skip()
@ -21672,7 +21672,7 @@ func parseFeaturePlus(p *util.XMLParser, obj *Feature) (*Feature, error) {
if err != nil {
return nil, err
}
obj.Type = parseFeatureType(txt(data))
obj.Type_ = parseFeatureType(txt(data))
default:
// fmt.Println("unknown field", n)
p.Skip()
@ -23399,7 +23399,7 @@ func parseHistoricalEventArtifactCreatedCircumstancePlus(p *util.XMLParser, obj
if err != nil {
return nil, err
}
obj.Type = parseHistoricalEventArtifactCreatedCircumstanceType(txt(data))
obj.Type_ = parseHistoricalEventArtifactCreatedCircumstanceType(txt(data))
default:
// fmt.Println("unknown field", n)
p.Skip()
@ -32226,7 +32226,7 @@ func parseHistoricalEventItemStolenCircumstancePlus(p *util.XMLParser, obj *Hist
if err != nil {
return nil, err
}
obj.Type = parseHistoricalEventItemStolenCircumstanceType(txt(data))
obj.Type_ = parseHistoricalEventItemStolenCircumstanceType(txt(data))
default:
// fmt.Println("unknown field", n)
p.Skip()
@ -36530,7 +36530,7 @@ func parseIntriguePlot(p *util.XMLParser) (*IntriguePlot, error) {
if err != nil {
return nil, err
}
obj.Type = parseIntriguePlotType(txt(data))
obj.Type_ = parseIntriguePlotType(txt(data))
default:
// fmt.Println("unknown field", n)
p.Skip()
@ -37105,7 +37105,7 @@ func parseReferencePlus(p *util.XMLParser, obj *Reference) (*Reference, error) {
if err != nil {
return nil, err
}
obj.Type = parseReferenceType(txt(data))
obj.Type_ = parseReferenceType(txt(data))
default:
// fmt.Println("unknown field", n)
p.Skip()
@ -37145,7 +37145,7 @@ func parseRegion(p *util.XMLParser) (*Region, error) {
if err != nil {
return nil, err
}
obj.Type = parseRegionType(txt(data))
obj.Type_ = parseRegionType(txt(data))
default:
// fmt.Println("unknown field", n)
p.Skip()
@ -37726,7 +37726,7 @@ func parseSchedulePlus(p *util.XMLParser, obj *Schedule) (*Schedule, error) {
if err != nil {
return nil, err
}
obj.Type = parseScheduleType(txt(data))
obj.Type_ = parseScheduleType(txt(data))
default:
// fmt.Println("unknown field", n)
p.Skip()
@ -37782,7 +37782,7 @@ func parseSite(p *util.XMLParser) (*Site, error) {
if err != nil {
return nil, err
}
obj.Type = parseSiteType(txt(data))
obj.Type_ = parseSiteType(txt(data))
default:
// fmt.Println("unknown field", n)
p.Skip()
@ -37948,7 +37948,7 @@ func parseSiteSiteProperty(p *util.XMLParser) (*SiteSiteProperty, error) {
if err != nil {
return nil, err
}
obj.Type = parseSiteSitePropertyType(txt(data))
obj.Type_ = parseSiteSitePropertyType(txt(data))
default:
// fmt.Println("unknown field", n)
p.Skip()
@ -38030,7 +38030,7 @@ func parseStructure(p *util.XMLParser) (*Structure, error) {
if err != nil {
return nil, err
}
obj.Type = parseStructureType(txt(data))
obj.Type_ = parseStructureType(txt(data))
case "worship_hfid":
data, err := p.Value()
if err != nil {
@ -38114,7 +38114,7 @@ func parseStructurePlus(p *util.XMLParser, obj *Structure) (*Structure, error) {
if err != nil {
return nil, err
}
obj.Type = parseStructureType(txt(data))
obj.Type_ = parseStructureType(txt(data))
default:
// fmt.Println("unknown field", n)
p.Skip()
@ -38154,7 +38154,7 @@ func parseUndergroundRegion(p *util.XMLParser) (*UndergroundRegion, error) {
if err != nil {
return nil, err
}
obj.Type = parseUndergroundRegionType(txt(data))
obj.Type_ = parseUndergroundRegionType(txt(data))
default:
// fmt.Println("unknown field", n)
p.Skip()
@ -38390,7 +38390,7 @@ func parseWorldConstructionPlus(p *util.XMLParser, obj *WorldConstruction) (*Wor
if err != nil {
return nil, err
}
obj.Type = parseWorldConstructionType(txt(data))
obj.Type_ = parseWorldConstructionType(txt(data))
default:
// fmt.Println("unknown field", n)
p.Skip()
@ -38523,7 +38523,7 @@ func parseWrittenContentPlus(p *util.XMLParser, obj *WrittenContent) (*WrittenCo
if err != nil {
return nil, err
}
obj.Type = parseWrittenContentType(txt(data))
obj.Type_ = parseWrittenContentType(txt(data))
default:
// fmt.Println("unknown field", n)
p.Skip()

View file

@ -19,12 +19,6 @@ type Identifiable interface {
Id() int
}
type TypedObject struct {
Type_ string `xml:"type" json:"type"`
}
func (r *TypedObject) Type() string { return r.Type_ }
type Typed interface {
Type() string
}

View file

@ -8,11 +8,15 @@ import (
"io/ioutil"
"net/http"
"os"
"path/filepath"
"runtime"
"strings"
"github.com/gorilla/mux"
"github.com/robertjanetzko/LegendsBrowser2/backend/model"
"github.com/robertjanetzko/LegendsBrowser2/backend/templates"
"github.com/robertjanetzko/LegendsBrowser2/backend/util"
"github.com/shirou/gopsutil/disk"
)
type DfServerContext struct {
@ -40,7 +44,9 @@ func StartServer(world *model.DfWorld, static embed.FS) {
srv.loader = &loadHandler{server: srv}
srv.LoadTemplates()
srv.RegisterWorldPage("/entities", "entities.html", func(p Parms) any { return grouped(srv.context.world.Entities) })
srv.RegisterWorldResourcePage("/entity/{id}", "entity.html", func(id int) any { return srv.context.world.Entities[id] })
srv.RegisterWorldResourcePage("/hf/{id}", "hf.html", func(id int) any { return srv.context.world.HistoricalFigures[id] })
srv.RegisterWorldResourcePage("/region/{id}", "region.html", func(id int) any { return srv.context.world.Regions[id] })
srv.RegisterWorldResourcePage("/site/{id}", "site.html", func(id int) any { return srv.context.world.Sites[id] })
@ -140,31 +146,46 @@ func (h loadHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
var partitions []string
if runtime.GOOS == "windows" {
ps, _ := disk.Partitions(false)
partitions = util.Map(ps, func(p disk.PartitionStat) string { return p.Mountpoint + `\` })
} else {
partitions = append(partitions, "/")
}
path := r.URL.Query().Get("p")
p := &paths{
Current: path,
Partitions: partitions,
Current: path,
}
if p.Current == "" {
p.Current = "."
}
var err error
p.Current, err = filepath.Abs(p.Current)
if err != nil {
httpError(w, err)
return
}
if f, err := os.Stat(p.Current); err == nil {
if f.IsDir() {
p.List, err = ioutil.ReadDir(p.Current)
if err != nil {
fmt.Fprintln(w, err)
fmt.Println(err)
httpError(w, err)
return
}
err = h.server.templates.Render(w, "load.html", p)
if err != nil {
fmt.Fprintln(w, err)
fmt.Println(err)
httpError(w, err)
}
return
} else {
h.server.context.isLoading = true
h.server.context.world = nil
go loadWorld(h.server, p.Current)
http.Redirect(w, r, "/", http.StatusSeeOther)
return
@ -178,24 +199,41 @@ func isLegendsXml(f fs.FileInfo) bool {
}
func loadWorld(server *DfServer, file string) {
runtime.GC()
wrld, _ := model.Parse(file, server.context.progress)
server.context.world = wrld
server.context.isLoading = false
}
type paths struct {
Current string
List []fs.FileInfo
Current string
List []fs.FileInfo
Partitions []string
}
func (srv *DfServer) renderLoading(w http.ResponseWriter, r *http.Request) {
if srv.context.isLoading {
err := srv.templates.Render(w, "loading.html", srv.loader.Progress())
if err != nil {
fmt.Fprintln(w, err)
fmt.Println(err)
httpError(w, err)
}
} else {
http.Redirect(w, r, "/load", http.StatusSeeOther)
}
}
func httpError(w http.ResponseWriter, err error) {
fmt.Fprintln(w, err)
fmt.Println(err)
}
func grouped[T model.Typed](input map[int]T) map[string][]T {
output := make(map[string][]T)
for _, v := range input {
k := v.Type()
output[k] = append(output[k], v)
}
return output
}

View file

@ -5,6 +5,7 @@ import (
"html/template"
"net/url"
humanize "github.com/dustin/go-humanize"
"github.com/robertjanetzko/LegendsBrowser2/backend/model"
"github.com/robertjanetzko/LegendsBrowser2/backend/templates"
"github.com/robertjanetzko/LegendsBrowser2/backend/util"
@ -39,6 +40,7 @@ func (srv *DfServer) LoadTemplates() {
"html": func(value any) template.HTML {
return template.HTML(fmt.Sprint(value))
},
"bytes": func(s int64) string { return humanize.Bytes(uint64(s)) },
}
srv.templates = templates.New(functions)
}

1704
backend/static/css/bootstrap-icons.css vendored Normal file

File diff suppressed because it is too large Load diff

View file

@ -50,6 +50,10 @@ a {
color: #600000;
}
.loadable {
color: #009933;
}
.battle {
color: #900000;
}

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,34 @@
{{template "layout.html" .}}
{{define "title"}}Entities{{end}}
{{define "content"}}
<h3>Entities</h3>
<nav>
<div class="nav nav-tabs" id="nav-tab" role="tablist">
{{- range $t, $v := .}}
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#nav-{{$t}}" type="button" role="tab">{{$t}}</button>
{{- end}}
</div>
</nav>
<div class="tab-content" id="nav-tabContent">
{{- range $t, $v := . }}
<div class="tab-pane" id="nav-{{$t}}" role="tabpanel" aria-labelledby="nav-home-tab">
<table>
<tr>
<th>Name</th>
<th>Race</th>
</tr>
{{- range $v }}{{- if not (eq .Name "") }}
<tr>
<td>{{ entity .Id }}</td>
<td>{{ .Race }}</td>
</tr>
{{- end}}{{- end}}
</table>
</div>
{{- end}}
</div>
{{- end }}

View file

@ -7,13 +7,61 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{block "title" .}}{{end}}</title>
<link href="/css/bootstrap.min.css" rel="stylesheet">
<link href="/css/bootstrap-icons.css" rel="stylesheet">
<link href="/css/legends.css" rel="stylesheet">
<script src="/js/jquery-3.6.0.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
</head>
<body>
<div class="main">{{block "content" .}}{{end}}</div>
<nav class="navbar navbar-expand-lg navbar-light bg-light mb-4">
<div class="container">
<a class="navbar-brand" href="#">Legends Browser</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" href="/">Civilizations</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/worldmap">World Map</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown"
aria-expanded="false">
Objects
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="/entities">Entities</a></li>
<li><a class="dropdown-item" href="/hfs">Historical Figures</a></li>
<li><a class="dropdown-item" href="/regions">Regions</a></li>
<li><a class="dropdown-item" href="/sites">Sites</a></li>
<li><a class="dropdown-item" href="/structures">Structures</a></li>
<li><a class="dropdown-item" href="/worldconstructions">World Constructions</a></li>
<li><a class="dropdown-item" href="/artifacts">Artifacts</a></li>
<li><a class="dropdown-item" href="/artforms">Art Forms</a></li>
<li><a class="dropdown-item" href="/writtencontents">Written Contents</a></li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link" href="/years">Years</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/collections">Collections</a>
</li>
</ul>
<form class="d-flex">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
</div>
</div>
</nav>
<div class="container">{{block "content" .}}{{end}}</div>
</body>
</html>

View file

@ -3,21 +3,50 @@
{{define "title"}}Loading{{end}}
{{define "content"}}
<h1>Loading</h1>
<h3>Load World</h3>
<p>Current Path: {{ .Current }}</p>
<table class="table table-hover object-table" style="white-space: nowrap;">
<tr>
<th width="100%">File</th>
<th>Size</th>
<th>Date</th>
</tr>
<ul>
<li><a href="/load?p={{ (printf `%s/..` $.Current) }}&x=1">..</a></li>
{{- range $f := .List }}
{{- if $f.IsDir }}
<li><a href="/load?p={{ (printf `%s/%s` $.Current $f.Name) }}&x=1">{{$f.Name}}</a></li>
{{- range .Partitions }}
<tr>
<td><a href="/load?p={{ . }}"><i class="bi bi-hdd"></i> {{ . }}</a></td>
<td></td>
<td></td>
</tr>
{{- end }}
{{- end }}
{{- range $f := .List }}
{{- if isLegendsXml $f }}
<li>+<a href="/load?p={{ (printf `%s/%s` $.Current $f.Name) }}&x=1">{{$f.Name}}</a></li>
{{- end }}
{{- end }}
</ul>
<tr>
<td><a href="/load?p={{ (printf `%s/..` $.Current) }}&x=1"><i class="bi bi-folder2"></i> ..</a></td>
<td></td>
<td></td>
</tr>
{{- range $f := .List }}{{- if $f.IsDir }}
<tr>
<td>
<a href="/load?p={{ (printf `%s/%s` $.Current $f.Name) }}"><i class="bi bi-folder2"></i> {{$f.Name}}</a>
</td>
<td></td>
<td></td>
</tr>
{{- end }}{{- end }}
{{- range $f := .List }}{{- if isLegendsXml $f }}
<tr>
<td>
<a class="loadable" href="/load?p={{ (printf `%s/%s` $.Current $f.Name) }}"><i class="bi bi-filetype-xml"></i> {{$f.Name}}</a>
</td>
<td>{{ bytes $f.Size }}</td>
<td>{{ $f.ModTime.Format "02 Jan 06 15:04" }}</td>
</tr>
{{- end }}{{- end }}
</table>
<p>{{ json . }}</p>
{{- end }}