artform details
This commit is contained in:
parent
0596601ea2
commit
7310cf7872
18 changed files with 1059 additions and 448 deletions
2
analyze/Makefile
Normal file
2
analyze/Makefile
Normal file
|
@ -0,0 +1,2 @@
|
|||
gen:
|
||||
go run analyze.go -g=true
|
|
@ -100,6 +100,7 @@ func CreateMetadata(a *AnalyzeData) (*Metadata, error) {
|
|||
Legend: legend,
|
||||
Base: a.Fields[f].Base,
|
||||
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 {
|
||||
el := typeNames[elements]
|
||||
|
|
|
@ -33,6 +33,7 @@ type Field struct {
|
|||
Base bool
|
||||
Plus bool
|
||||
EnumValues *[]string
|
||||
Related string
|
||||
}
|
||||
|
||||
func (f Field) Active(plus bool) bool {
|
||||
|
|
|
@ -130,12 +130,19 @@ func (x *{{ $obj.Name }}) Name() string { return x.Name_ }
|
|||
{{- if $obj.SubType }}
|
||||
func (x *{{ $obj.Name }}) Type() string { return "{{ $obj.SubType }}" }
|
||||
{{- end }}
|
||||
{{- if $obj.SubType }}
|
||||
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 }}) RelatedToArtifact(id int) bool { return {{ $obj.RelatedToArtifact }} }
|
||||
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 }}) 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() {
|
||||
{{- 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 structureRegex, _ = regexp.Compile("(structure(_id)?)$")
|
||||
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 {
|
||||
return obj.Related(entityRegex, "")
|
||||
return obj.Related("entity", entityRegex, "")
|
||||
}
|
||||
func (obj Object) RelatedToHf() string {
|
||||
return obj.Related(hfRegex, "")
|
||||
return obj.Related("hf", hfRegex, "")
|
||||
}
|
||||
func (obj Object) RelatedToArtifact() string {
|
||||
return obj.Related(artifactRegex, "")
|
||||
return obj.Related("artifact", artifactRegex, "")
|
||||
}
|
||||
func (obj Object) RelatedToSite() string {
|
||||
return obj.Related(siteRegex, "")
|
||||
return obj.Related("site", siteRegex, "")
|
||||
}
|
||||
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 {
|
||||
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
|
||||
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 {
|
||||
list = append(list, fmt.Sprintf("x.%s == id", f.Name))
|
||||
} else {
|
||||
|
|
|
@ -141,6 +141,7 @@ type AdditionalField struct {
|
|||
type Overwrites struct {
|
||||
ForceEnum map[string]bool
|
||||
AdditionalFields map[string][]AdditionalField
|
||||
Relations map[string]string
|
||||
}
|
||||
|
||||
func analyze(file string, a *AnalyzeData) error {
|
||||
|
|
|
@ -4,6 +4,11 @@
|
|||
"df_world|historical_events|historical_event+HfDied|death_cause": true,
|
||||
"df_world|historical_events|historical_event+KnowledgeDiscovered|knowledge": true
|
||||
},
|
||||
"Relations": {
|
||||
"HistoricalEventDanceFormCreated.FormId": "danceForm",
|
||||
"HistoricalEventMusicalFormCreated.FormId": "musicalForm",
|
||||
"HistoricalEventPoeticFormCreated.FormId": "poeticForm"
|
||||
},
|
||||
"AdditionalFields": {
|
||||
"DfWorld": [
|
||||
{
|
||||
|
|
|
@ -23,18 +23,18 @@ func main() {
|
|||
d := flag.Bool("d", false, "debug templates")
|
||||
flag.Parse()
|
||||
|
||||
if *p {
|
||||
defer profile.Start(profile.ProfilePath(".")).Stop()
|
||||
go func() {
|
||||
http.ListenAndServe(":8081", nil)
|
||||
}()
|
||||
}
|
||||
|
||||
templates.DebugTemplates = *d
|
||||
|
||||
var world *model.DfWorld
|
||||
|
||||
if len(*f) > 0 {
|
||||
if *p {
|
||||
defer profile.Start(profile.ProfilePath(".")).Stop()
|
||||
go func() {
|
||||
http.ListenAndServe(":8081", nil)
|
||||
}()
|
||||
}
|
||||
|
||||
w, err := model.Parse(*f, nil)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
|
|
@ -191,21 +191,21 @@ func (c *Context) fullIdentity(id int) string {
|
|||
|
||||
func (c *Context) danceForm(id int) string {
|
||||
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"
|
||||
}
|
||||
|
||||
func (c *Context) musicalForm(id int) string {
|
||||
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"
|
||||
}
|
||||
|
||||
func (c *Context) poeticForm(id int) string {
|
||||
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"
|
||||
}
|
||||
|
|
|
@ -13,6 +13,11 @@ type HistoricalEventDetails interface {
|
|||
RelatedToSite(int) bool
|
||||
RelatedToStructure(int, int) bool
|
||||
RelatedToRegion(int) bool
|
||||
RelatedToWorldConstruction(int) bool
|
||||
RelatedToWrittenContent(int) bool
|
||||
RelatedToDanceForm(int) bool
|
||||
RelatedToMusicalForm(int) bool
|
||||
RelatedToPoeticForm(int) bool
|
||||
Html(*Context) 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()) })
|
||||
case *Region:
|
||||
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:
|
||||
el.Events = x
|
||||
case []int:
|
||||
|
|
|
@ -120,3 +120,60 @@ func containsInt(list []int, id int) bool {
|
|||
}
|
||||
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
|
@ -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.Artifacts, results, "/artifavt")
|
||||
results = searchMap(term, world.WorldConstructions, results, "/worldconstruction")
|
||||
results = searchMap(term, world.DanceForms, results, "/danceForm")
|
||||
results = searchMap(term, world.MusicalForms, results, "/musicalForm")
|
||||
results = searchMap(term, world.PoeticForms, results, "/poeticForm")
|
||||
results = searchMap(term, world.DanceForms, results, "/danceform")
|
||||
results = searchMap(term, world.MusicalForms, results, "/musicalform")
|
||||
results = searchMap(term, world.PoeticForms, results, "/poeticform")
|
||||
results = searchMap(term, world.WrittenContents, results, "/writtencontent")
|
||||
results = searchMap(term, world.Landmasses, results, "/landmass")
|
||||
results = searchMap(term, world.MountainPeaks, results, "/mountain")
|
||||
|
|
|
@ -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.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] })
|
||||
|
|
|
@ -69,6 +69,7 @@ func (srv *DfServer) LoadTemplates() {
|
|||
}
|
||||
return template.HTML("")
|
||||
},
|
||||
"description": func(d string) template.HTML { return model.LinkDescription(srv.context.world, d) },
|
||||
"season": model.Season,
|
||||
"time": model.Time,
|
||||
"url": url.PathEscape,
|
||||
|
|
14
backend/templates/artform.html
Normal file
14
backend/templates/artform.html
Normal 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 }}
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
{{define "content"}}
|
||||
<h3>{{ title .Name }}</h3>
|
||||
{{ .Type_ }}
|
||||
{{ .Type_ }} in {{ site .SiteId }}
|
||||
|
||||
<h5 class="mt-3">Events</h5>
|
||||
{{ template "events.html" events . }}
|
||||
|
|
13
backend/templates/worldconstruction.html
Normal file
13
backend/templates/worldconstruction.html
Normal 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 }}
|
|
@ -5,7 +5,18 @@
|
|||
{{define "content"}}
|
||||
<h3>{{ title .Name }}</h3>
|
||||
<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">
|
||||
{{- if ne 0 (len .Reference) }}
|
||||
<div class="col-md-9">
|
||||
|
|
Loading…
Reference in a new issue