artform details

This commit is contained in:
Robert Janetzko 2022-05-03 19:39:00 +00:00
parent 0596601ea2
commit 7310cf7872
18 changed files with 1059 additions and 448 deletions

2
analyze/Makefile Normal file
View File

@ -0,0 +1,2 @@
gen:
go run analyze.go -g=true

View File

@ -100,6 +100,7 @@ func CreateMetadata(a *AnalyzeData) (*Metadata, error) {
Legend: legend, Legend: legend,
Base: a.Fields[f].Base, Base: a.Fields[f].Base,
Plus: a.Fields[f].Plus, Plus: a.Fields[f].Plus,
Related: a.Overwrites.Relations[fmt.Sprintf("%s.%s", typeNames[k], strcase.ToCamel(fn))],
} }
if ok, elements := isArray(f, fs); ok { if ok, elements := isArray(f, fs); ok {
el := typeNames[elements] el := typeNames[elements]

View File

@ -33,6 +33,7 @@ type Field struct {
Base bool Base bool
Plus bool Plus bool
EnumValues *[]string EnumValues *[]string
Related string
} }
func (f Field) Active(plus bool) bool { func (f Field) Active(plus bool) bool {

View File

@ -130,12 +130,19 @@ func (x *{{ $obj.Name }}) Name() string { return x.Name_ }
{{- if $obj.SubType }} {{- if $obj.SubType }}
func (x *{{ $obj.Name }}) Type() string { return "{{ $obj.SubType }}" } func (x *{{ $obj.Name }}) Type() string { return "{{ $obj.SubType }}" }
{{- end }} {{- end }}
{{- if $obj.SubType }}
func (x *{{ $obj.Name }}) RelatedToEntity(id int) bool { return {{ $obj.RelatedToEntity }} } func (x *{{ $obj.Name }}) RelatedToEntity(id int) bool { return {{ $obj.RelatedToEntity }} }
func (x *{{ $obj.Name }}) RelatedToHf(id int) bool { return {{ $obj.RelatedToHf }} } func (x *{{ $obj.Name }}) RelatedToHf(id int) bool { return {{ $obj.RelatedToHf }} }
func (x *{{ $obj.Name }}) RelatedToArtifact(id int) bool { return {{ $obj.RelatedToArtifact }} } func (x *{{ $obj.Name }}) RelatedToArtifact(id int) bool { return {{ $obj.RelatedToArtifact }} }
func (x *{{ $obj.Name }}) RelatedToSite(id int) bool { return {{ $obj.RelatedToSite }} } func (x *{{ $obj.Name }}) RelatedToSite(id int) bool { return {{ $obj.RelatedToSite }} }
func (x *{{ $obj.Name }}) RelatedToStructure(siteId, id int) bool { return {{ $obj.RelatedToStructure }} } func (x *{{ $obj.Name }}) RelatedToStructure(siteId, id int) bool { return {{ $obj.RelatedToStructure }} }
func (x *{{ $obj.Name }}) RelatedToRegion(id int) bool { return {{ $obj.RelatedToRegion }} } func (x *{{ $obj.Name }}) RelatedToRegion(id int) bool { return {{ $obj.RelatedToRegion }} }
func (x *{{ $obj.Name }}) RelatedToWorldConstruction(id int) bool { return {{ $obj.RelatedToWorldConstruction }} }
func (x *{{ $obj.Name }}) RelatedToWrittenContent(id int) bool { return {{ $obj.RelatedToWrittenContent }} }
func (x *{{ $obj.Name }}) RelatedToDanceForm(id int) bool { return {{ $obj.RelatedToDanceForm }} }
func (x *{{ $obj.Name }}) RelatedToMusicalForm(id int) bool { return {{ $obj.RelatedToMusicalForm }} }
func (x *{{ $obj.Name }}) RelatedToPoeticForm(id int) bool { return {{ $obj.RelatedToPoeticForm }} }
{{- end }}
func (x *{{ $obj.Name }}) CheckFields() { func (x *{{ $obj.Name }}) CheckFields() {
{{- range $field := ($obj.LegendFields "plus") }} {{- range $field := ($obj.LegendFields "plus") }}
@ -453,30 +460,49 @@ var artifactRegex, _ = regexp.Compile("(item(_id)?|artifact_id)$")
var siteRegex, _ = regexp.Compile("(site_id|site)[0-9]?$") var siteRegex, _ = regexp.Compile("(site_id|site)[0-9]?$")
var structureRegex, _ = regexp.Compile("(structure(_id)?)$") var structureRegex, _ = regexp.Compile("(structure(_id)?)$")
var regionRegex, _ = regexp.Compile("(region_id|srid)$") var regionRegex, _ = regexp.Compile("(region_id|srid)$")
var worldConstructionRegex, _ = regexp.Compile("(wcid)$")
var writtenContentRegex, _ = regexp.Compile("^wc_id$")
var noRegex, _ = regexp.Compile("^XXXXX$")
func (obj Object) RelatedToEntity() string { func (obj Object) RelatedToEntity() string {
return obj.Related(entityRegex, "") return obj.Related("entity", entityRegex, "")
} }
func (obj Object) RelatedToHf() string { func (obj Object) RelatedToHf() string {
return obj.Related(hfRegex, "") return obj.Related("hf", hfRegex, "")
} }
func (obj Object) RelatedToArtifact() string { func (obj Object) RelatedToArtifact() string {
return obj.Related(artifactRegex, "") return obj.Related("artifact", artifactRegex, "")
} }
func (obj Object) RelatedToSite() string { func (obj Object) RelatedToSite() string {
return obj.Related(siteRegex, "") return obj.Related("site", siteRegex, "")
} }
func (obj Object) RelatedToStructure() string { func (obj Object) RelatedToStructure() string {
return obj.Related(structureRegex, "x.RelatedToSite(siteId)") return obj.Related("structure", structureRegex, "x.RelatedToSite(siteId)")
} }
func (obj Object) RelatedToRegion() string { func (obj Object) RelatedToRegion() string {
return obj.Related(regionRegex, "") return obj.Related("region", regionRegex, "")
}
func (obj Object) RelatedToWorldConstruction() string {
return obj.Related("worldConstruction", worldConstructionRegex, "")
}
func (obj Object) RelatedToWrittenContent() string {
return obj.Related("writtenContent", writtenContentRegex, "")
}
func (obj Object) RelatedToDanceForm() string {
return obj.Related("danceForm", noRegex, "")
}
func (obj Object) RelatedToMusicalForm() string {
return obj.Related("musicalForm", noRegex, "")
}
func (obj Object) RelatedToPoeticForm() string {
return obj.Related("poeticForm", noRegex, "")
} }
func (obj Object) Related(regex *regexp.Regexp, init string) string { func (obj Object) Related(relation string, regex *regexp.Regexp, init string) string {
var list []string var list []string
for n, f := range obj.Fields { for n, f := range obj.Fields {
if f.Type == "int" && !f.SameField(obj) && regex.MatchString(n) { if f.Type == "int" && !f.SameField(obj) && (relation == f.Related || regex.MatchString(n)) {
if !f.Multiple { if !f.Multiple {
list = append(list, fmt.Sprintf("x.%s == id", f.Name)) list = append(list, fmt.Sprintf("x.%s == id", f.Name))
} else { } else {

View File

@ -141,6 +141,7 @@ type AdditionalField struct {
type Overwrites struct { type Overwrites struct {
ForceEnum map[string]bool ForceEnum map[string]bool
AdditionalFields map[string][]AdditionalField AdditionalFields map[string][]AdditionalField
Relations map[string]string
} }
func analyze(file string, a *AnalyzeData) error { func analyze(file string, a *AnalyzeData) error {

View File

@ -4,6 +4,11 @@
"df_world|historical_events|historical_event+HfDied|death_cause": true, "df_world|historical_events|historical_event+HfDied|death_cause": true,
"df_world|historical_events|historical_event+KnowledgeDiscovered|knowledge": true "df_world|historical_events|historical_event+KnowledgeDiscovered|knowledge": true
}, },
"Relations": {
"HistoricalEventDanceFormCreated.FormId": "danceForm",
"HistoricalEventMusicalFormCreated.FormId": "musicalForm",
"HistoricalEventPoeticFormCreated.FormId": "poeticForm"
},
"AdditionalFields": { "AdditionalFields": {
"DfWorld": [ "DfWorld": [
{ {

View File

@ -23,18 +23,18 @@ func main() {
d := flag.Bool("d", false, "debug templates") d := flag.Bool("d", false, "debug templates")
flag.Parse() flag.Parse()
if *p {
defer profile.Start(profile.ProfilePath(".")).Stop()
go func() {
http.ListenAndServe(":8081", nil)
}()
}
templates.DebugTemplates = *d templates.DebugTemplates = *d
var world *model.DfWorld var world *model.DfWorld
if len(*f) > 0 { if len(*f) > 0 {
if *p {
defer profile.Start(profile.ProfilePath(".")).Stop()
go func() {
http.ListenAndServe(":8081", nil)
}()
}
w, err := model.Parse(*f, nil) w, err := model.Parse(*f, nil)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -191,21 +191,21 @@ func (c *Context) fullIdentity(id int) string {
func (c *Context) danceForm(id int) string { func (c *Context) danceForm(id int) string {
if x, ok := c.World.DanceForms[id]; ok { if x, ok := c.World.DanceForms[id]; ok {
return fmt.Sprintf(`<a class="artform" href="/danceForm/%d"><i class="fa-solid fa-shoe-prints fa-xs"></i> %s</a>`, id, util.Title(x.Name())) return fmt.Sprintf(`<a class="artform" href="/danceform/%d"><i class="fa-solid fa-shoe-prints fa-xs"></i> %s</a>`, id, util.Title(x.Name()))
} }
return "UNKNOWN DANCE FORM" return "UNKNOWN DANCE FORM"
} }
func (c *Context) musicalForm(id int) string { func (c *Context) musicalForm(id int) string {
if x, ok := c.World.MusicalForms[id]; ok { if x, ok := c.World.MusicalForms[id]; ok {
return fmt.Sprintf(`<a class="artform" href="/musicalForm/%d"><i class="fa-solid fa-music fa-xs"></i> %s</a>`, id, util.Title(x.Name())) return fmt.Sprintf(`<a class="artform" href="/musicalform/%d"><i class="fa-solid fa-music fa-xs"></i> %s</a>`, id, util.Title(x.Name()))
} }
return "UNKNOWN MUSICAL FORM" return "UNKNOWN MUSICAL FORM"
} }
func (c *Context) poeticForm(id int) string { func (c *Context) poeticForm(id int) string {
if x, ok := c.World.PoeticForms[id]; ok { if x, ok := c.World.PoeticForms[id]; ok {
return fmt.Sprintf(`<a class="artform" href="/poeticForm/%d"><i class="fa-solid fa-comment-dots fa-xs"></i> %s</a>`, id, util.Title(x.Name())) return fmt.Sprintf(`<a class="artform" href="/poeticform/%d"><i class="fa-solid fa-comment-dots fa-xs"></i> %s</a>`, id, util.Title(x.Name()))
} }
return "UNKNOWN POETIC FORM" return "UNKNOWN POETIC FORM"
} }

View File

@ -13,6 +13,11 @@ type HistoricalEventDetails interface {
RelatedToSite(int) bool RelatedToSite(int) bool
RelatedToStructure(int, int) bool RelatedToStructure(int, int) bool
RelatedToRegion(int) bool RelatedToRegion(int) bool
RelatedToWorldConstruction(int) bool
RelatedToWrittenContent(int) bool
RelatedToDanceForm(int) bool
RelatedToMusicalForm(int) bool
RelatedToPoeticForm(int) bool
Html(*Context) string Html(*Context) string
Type() string Type() string
} }
@ -50,6 +55,16 @@ func NewEventList(world *DfWorld, obj any) *EventList {
el.Events = world.EventsMatching(func(d HistoricalEventDetails) bool { return d.RelatedToStructure(x.SiteId, x.Id()) }) el.Events = world.EventsMatching(func(d HistoricalEventDetails) bool { return d.RelatedToStructure(x.SiteId, x.Id()) })
case *Region: case *Region:
el.Events = world.EventsMatching(func(d HistoricalEventDetails) bool { return d.RelatedToRegion(x.Id()) }) el.Events = world.EventsMatching(func(d HistoricalEventDetails) bool { return d.RelatedToRegion(x.Id()) })
case *WorldConstruction:
el.Events = world.EventsMatching(func(d HistoricalEventDetails) bool { return d.RelatedToWorldConstruction(x.Id()) })
case *WrittenContent:
el.Events = world.EventsMatching(func(d HistoricalEventDetails) bool { return d.RelatedToWrittenContent(x.Id()) })
case *DanceForm:
el.Events = world.EventsMatching(func(d HistoricalEventDetails) bool { return d.RelatedToDanceForm(x.Id()) })
case *MusicalForm:
el.Events = world.EventsMatching(func(d HistoricalEventDetails) bool { return d.RelatedToMusicalForm(x.Id()) })
case *PoeticForm:
el.Events = world.EventsMatching(func(d HistoricalEventDetails) bool { return d.RelatedToPoeticForm(x.Id()) })
case []*HistoricalEvent: case []*HistoricalEvent:
el.Events = x el.Events = x
case []int: case []int:

View File

@ -120,3 +120,60 @@ func containsInt(list []int, id int) bool {
} }
return false return false
} }
func LinkDescription(w *DfWorld, desc string) template.HTML {
c := &Context{World: w}
desc = replaceNameDescription(desc, "originating in ", `\.`, w.Entities, c.entity)
desc = replaceNameDescription(desc, "grew out of the performances of ", `\.`, w.Entities, c.entity)
desc = replaceNameDescription(desc, "accompanied by(?: any composition of)? ", `(?: as |\.)`, w.MusicalForms, c.musicalForm)
desc = replaceNameDescription(desc, "(?:recites?|acts? out)(?: any composition of)? ", `(?: while |\.)`, w.PoeticForms, c.poeticForm)
desc = replacHfDescription(desc, "devised by ", `\.`, w.HistoricalFigures, c.hf)
desc = replacHfDescription(desc, "the story of ", `\.`, w.HistoricalFigures, c.hf)
desc = replaceNameDescription(desc, "the words of ", `(?: while |\.)`, w.WrittenContents, c.writtenContent)
desc = replacHfDescription(desc, "express pleasure with ", " originally", w.HistoricalFigures, c.hf)
s := strings.Split(desc, "[B]")
if len(s) > 1 {
desc = s[0] + "<ul><li>" + strings.Join(s[1:], "</li><li>") + "</li></ul>"
}
return template.HTML(desc)
}
type NamedIdentifiable interface {
Id() int
Name() string
}
func replaceNameDescription[T NamedIdentifiable](s, prefix, suffix string, input map[int]T, mapper func(int) string) string {
return replaceDescription(s, prefix, suffix, input, func(t T) string { return t.Name() }, mapper)
}
func replacHfDescription(s, prefix, suffix string, input map[int]*HistoricalFigure, mapper func(int) string) string {
return replaceDescription(s, prefix, suffix, input,
func(hf *HistoricalFigure) string {
if hf.Race != "" && !hf.Deity && !hf.Force {
return fmt.Sprintf("the %s %s", hf.Race, hf.Name())
} else {
return hf.Name()
}
}, mapper)
}
func replaceDescription[T NamedIdentifiable](s, prefix, suffix string, input map[int]T, namer func(T) string, mapper func(int) string) string {
r := "(" + prefix + `)([^.]+?)(` + suffix + ")"
fmt.Println(">", r)
reg := regexp.MustCompile(r)
res := reg.FindStringSubmatch(s)
if res == nil {
return s
}
fmt.Println(strings.Join(res, " / "))
name := strings.ToLower(res[2])
for id, v := range input {
if strings.ToLower(namer(v)) == name {
return reg.ReplaceAllString(s, res[1]+mapper(id)+" ("+name+")"+res[3])
}
}
return s
}

File diff suppressed because it is too large Load Diff

View File

@ -40,9 +40,9 @@ func (h searchHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
results = searchMap(term, world.Regions, results, "/region") results = searchMap(term, world.Regions, results, "/region")
results = searchMap(term, world.Artifacts, results, "/artifavt") results = searchMap(term, world.Artifacts, results, "/artifavt")
results = searchMap(term, world.WorldConstructions, results, "/worldconstruction") results = searchMap(term, world.WorldConstructions, results, "/worldconstruction")
results = searchMap(term, world.DanceForms, results, "/danceForm") results = searchMap(term, world.DanceForms, results, "/danceform")
results = searchMap(term, world.MusicalForms, results, "/musicalForm") results = searchMap(term, world.MusicalForms, results, "/musicalform")
results = searchMap(term, world.PoeticForms, results, "/poeticForm") results = searchMap(term, world.PoeticForms, results, "/poeticform")
results = searchMap(term, world.WrittenContents, results, "/writtencontent") results = searchMap(term, world.WrittenContents, results, "/writtencontent")
results = searchMap(term, world.Landmasses, results, "/landmass") results = searchMap(term, world.Landmasses, results, "/landmass")
results = searchMap(term, world.MountainPeaks, results, "/mountain") results = searchMap(term, world.MountainPeaks, results, "/mountain")

View File

@ -84,6 +84,10 @@ func StartServer(world *model.DfWorld, static embed.FS) error {
} }
}) })
srv.RegisterWorldResourcePage("/danceform/{id}", "artform.html", func(id int) any { return srv.context.world.DanceForms[id] })
srv.RegisterWorldResourcePage("/musicalform/{id}", "artform.html", func(id int) any { return srv.context.world.MusicalForms[id] })
srv.RegisterWorldResourcePage("/poeticform/{id}", "artform.html", func(id int) any { return srv.context.world.PoeticForms[id] })
srv.RegisterWorldPage("/writtencontents", "writtencontents.html", func(p Parms) any { return groupByType(srv.context.world.WrittenContents) }) srv.RegisterWorldPage("/writtencontents", "writtencontents.html", func(p Parms) any { return groupByType(srv.context.world.WrittenContents) })
srv.RegisterWorldResourcePage("/writtencontent/{id}", "writtencontent.html", func(id int) any { return srv.context.world.WrittenContents[id] }) srv.RegisterWorldResourcePage("/writtencontent/{id}", "writtencontent.html", func(id int) any { return srv.context.world.WrittenContents[id] })
srv.RegisterWorldResourcePage("/popover/writtencontent/{id}", "popoverWrittencontent.html", func(id int) any { return srv.context.world.WrittenContents[id] }) srv.RegisterWorldResourcePage("/popover/writtencontent/{id}", "popoverWrittencontent.html", func(id int) any { return srv.context.world.WrittenContents[id] })

View File

@ -69,6 +69,7 @@ func (srv *DfServer) LoadTemplates() {
} }
return template.HTML("") return template.HTML("")
}, },
"description": func(d string) template.HTML { return model.LinkDescription(srv.context.world, d) },
"season": model.Season, "season": model.Season,
"time": model.Time, "time": model.Time,
"url": url.PathEscape, "url": url.PathEscape,

View File

@ -0,0 +1,14 @@
{{template "layout.html" .}}
{{define "title"}}{{ title .Name }}{{end}}
{{define "content"}}
<h1>{{ title .Name }}</h1>
<p>{{ description .Description }}</p>
<h3>Events</h3>
{{ template "events.html" events . }}
<p>{{ json . }}</p>
{{- end }}

View File

@ -4,7 +4,7 @@
{{define "content"}} {{define "content"}}
<h3>{{ title .Name }}</h3> <h3>{{ title .Name }}</h3>
{{ .Type_ }} {{ .Type_ }} in {{ site .SiteId }}
<h5 class="mt-3">Events</h5> <h5 class="mt-3">Events</h5>
{{ template "events.html" events . }} {{ template "events.html" events . }}

View File

@ -0,0 +1,13 @@
{{template "layout.html" .}}
{{define "title"}}{{ title .Name }}{{end}}
{{define "content"}}
<h3>{{ title .Name }}</h3>
<p>{{ .Type }}</p>
<h5>Events</h5>
{{ template "events.html" events . }}
<p>{{ json . }}</p>
{{- end }}

View File

@ -5,7 +5,18 @@
{{define "content"}} {{define "content"}}
<h3>{{ title .Name }}</h3> <h3>{{ title .Name }}</h3>
<p>{{ .Type_ }} by {{ hf .AuthorHfid }}</p> <p>{{ .Type_ }} by {{ hf .AuthorHfid }}</p>
{{- if ne .FormId -1 }}
<p>
an example of
{{- if eq .Form.String "musical composition" }}
{{ musicalForm .FormId }}
{{- else if eq .Form.String "choreography" }}
{{ danceForm .FormId }}
{{- else }}
{{ poeticForm .FormId }}
{{- end }}
</p>
{{- end }}
<div class="row"> <div class="row">
{{- if ne 0 (len .Reference) }} {{- if ne 0 (len .Reference) }}
<div class="col-md-9"> <div class="col-md-9">