map popovers

This commit is contained in:
Robert Janetzko 2022-05-07 16:11:24 +00:00
parent 27483ec834
commit ccdef3989d
15 changed files with 50 additions and 15 deletions

View File

@ -86,7 +86,10 @@ var AddMapSite = func(w *DfWorld, id int) template.HTML {
if e, ok := w.Entities[site.Owner]; ok { if e, ok := w.Entities[site.Owner]; ok {
c = e.Color() c = e.Color()
} }
return template.HTML(fmt.Sprintf(`<script>addSite("%s", %f, %f, %f, %f, "%s", "")</script>`, site.Name(), x1/16.0, y1/16.0-1, x2/16.0, y2/16.0-1, c)) if site.Ruin {
c = "#aaa"
}
return template.HTML(fmt.Sprintf(`<script>addSite(%d, %f, %f, %f, %f, "%s", "")</script>`, site.Id_, x1/16.0, y1/16.0-1, x2/16.0, y2/16.0-1, c))
} else { } else {
return "" return ""
} }
@ -97,7 +100,7 @@ var AddMapMountain = func(w *DfWorld, id int) template.HTML {
c1 := strings.Split(m.Coords, ",") c1 := strings.Split(m.Coords, ",")
x, _ := strconv.Atoi(c1[0]) x, _ := strconv.Atoi(c1[0])
y, _ := strconv.Atoi(c1[1]) y, _ := strconv.Atoi(c1[1])
return template.HTML(fmt.Sprintf(`<script>addMountain('%s', %d, %d, '#666')</script>`, m.Name_, x, y)) return template.HTML(fmt.Sprintf(`<script>addMountain(%d, %d, %d, '#666')</script>`, m.Id_, x, y))
} }
return "" return ""
} }
@ -113,7 +116,7 @@ var AddMapWorldConstruction = func(w *DfWorld, id int) template.HTML {
r += "var polyline = L.polyline([" r += "var polyline = L.polyline(["
r += strings.Join(util.Map(x.Line(), func(c Coord) string { return fmt.Sprintf(`coord(%d+0.5,%d-0.5)`, c.X, c.Y) }), ",") r += strings.Join(util.Map(x.Line(), func(c Coord) string { return fmt.Sprintf(`coord(%d+0.5,%d-0.5)`, c.X, c.Y) }), ",")
r += "], {color: '" + color + "', opacity: 1, weight: 3}).addTo(constructionsLayer);\n" r += "], {color: '" + color + "', opacity: 1, weight: 3}).addTo(constructionsLayer);\n"
r += "attachTooltip(polyline, '" + x.Name_ + "');\n" r += fmt.Sprintf(`attachTooltip(polyline, urlToolTip('worldconstruction', %d));`, x.Id_)
r += "polyline.on('mouseover', function (e) { this.setStyle({weight: 10}); });\n" r += "polyline.on('mouseover', function (e) { this.setStyle({weight: 10}); });\n"
r += "polyline.on('mouseout', function (e) { this.setStyle({ weight: 3}); });\n" r += "polyline.on('mouseout', function (e) { this.setStyle({ weight: 3}); });\n"
r += "</script>" r += "</script>"

View File

@ -76,7 +76,7 @@ func (w *DfWorld) processEvents() {
w.addEntitySite(d.CivId, d.SiteId) w.addEntitySite(d.CivId, d.SiteId)
w.addEntitySite(d.SiteCivId, d.SiteId) w.addEntitySite(d.SiteCivId, d.SiteId)
w.Sites[d.SiteId].Ruin = false w.Sites[d.SiteId].Ruin = false
w.Sites[d.SiteId].Owner = d.SiteCivId w.Sites[d.SiteId].Owner = d.CivId
case *HistoricalEventDestroyedSite: case *HistoricalEventDestroyedSite:
w.addEntitySite(d.DefenderCivId, d.SiteId) w.addEntitySite(d.DefenderCivId, d.SiteId)
w.addEntitySite(d.SiteCivId, d.SiteId) w.addEntitySite(d.SiteCivId, d.SiteId)
@ -87,7 +87,7 @@ func (w *DfWorld) processEvents() {
w.addEntitySite(d.DefenderCivId, d.SiteId) w.addEntitySite(d.DefenderCivId, d.SiteId)
w.addEntitySite(d.NewSiteCivId, d.SiteId) w.addEntitySite(d.NewSiteCivId, d.SiteId)
w.Sites[d.SiteId].Ruin = false w.Sites[d.SiteId].Ruin = false
w.Sites[d.SiteId].Owner = d.NewSiteCivId w.Sites[d.SiteId].Owner = d.AttackerCivId
case *HistoricalEventHfDestroyedSite: case *HistoricalEventHfDestroyedSite:
w.addEntitySite(d.SiteCivId, d.SiteId) w.addEntitySite(d.SiteCivId, d.SiteId)
w.addEntitySite(d.DefenderCivId, d.SiteId) w.addEntitySite(d.DefenderCivId, d.SiteId)
@ -96,7 +96,7 @@ func (w *DfWorld) processEvents() {
w.addEntitySite(d.SiteCivId, d.SiteId) w.addEntitySite(d.SiteCivId, d.SiteId)
w.addEntitySite(d.SiteCivId, d.SiteId) w.addEntitySite(d.SiteCivId, d.SiteId)
w.Sites[d.SiteId].Ruin = false w.Sites[d.SiteId].Ruin = false
w.Sites[d.SiteId].Owner = d.SiteCivId w.Sites[d.SiteId].Owner = d.CivId
case *HistoricalEventAddHfEntityLink: case *HistoricalEventAddHfEntityLink:
if d.Link == HistoricalEventAddHfEntityLinkLink_Position { if d.Link == HistoricalEventAddHfEntityLinkLink_Position {
if hf, ok := w.HistoricalFigures[d.Hfid]; ok { if hf, ok := w.HistoricalFigures[d.Hfid]; ok {

View File

@ -61,8 +61,13 @@ func StartServer(config *Config, world *model.DfWorld, static embed.FS) error {
} }
}) })
srv.RegisterWorldResourcePage("/landmass/{id}", "landmass.html", func(id int) any { return srv.context.world.Landmasses[id] }) srv.RegisterWorldResourcePage("/landmass/{id}", "landmass.html", func(id int) any { return srv.context.world.Landmasses[id] })
srv.RegisterWorldResourcePage("/popover/landmass/{id}", "popoverLandmass.html", func(id int) any { return srv.context.world.Landmasses[id] })
srv.RegisterWorldResourcePage("/mountain/{id}", "mountain.html", func(id int) any { return srv.context.world.MountainPeaks[id] }) srv.RegisterWorldResourcePage("/mountain/{id}", "mountain.html", func(id int) any { return srv.context.world.MountainPeaks[id] })
srv.RegisterWorldResourcePage("/popover/mountain/{id}", "popoverMountain.html", func(id int) any { return srv.context.world.MountainPeaks[id] })
srv.RegisterWorldResourcePage("/river/{id}", "river.html", func(id int) any { return srv.context.world.Rivers[id] }) srv.RegisterWorldResourcePage("/river/{id}", "river.html", func(id int) any { return srv.context.world.Rivers[id] })
srv.RegisterWorldResourcePage("/popover/river/{id}", "popoverRiver.html", func(id int) any { return srv.context.world.Rivers[id] })
srv.RegisterWorldPage("/regions", "regions.html", func(p Parms) any { return groupByType(srv.context.world.Regions) }) srv.RegisterWorldPage("/regions", "regions.html", func(p Parms) any { return groupByType(srv.context.world.Regions) })
srv.RegisterWorldResourcePage("/region/{id}", "region.html", func(id int) any { return srv.context.world.Regions[id] }) srv.RegisterWorldResourcePage("/region/{id}", "region.html", func(id int) any { return srv.context.world.Regions[id] })

View File

@ -105,7 +105,18 @@ function attachTooltip(layer, tip) {
layer.bindTooltip(tip, { direction: 'top' }).bindPopup(tip); layer.bindTooltip(tip, { direction: 'top' }).bindPopup(tip);
} }
function addSite(name, y1, x1, y2, x2, color, glyph) { function urlToolTip(type, id) {
return function (layer) {
return $.ajax({
url: "/popover/" + type + "/" + id,
async: false
}).responseText;
}
}
var myIcon = L.divIcon({ className: 'fa-solid fa-mountain fa-xl' });
function addSite(id, y1, x1, y2, x2, color, glyph) {
/* resize tiny sites like lairs */ /* resize tiny sites like lairs */
var MIN_SIZE = .3; var MIN_SIZE = .3;
if (y2 - y1 < MIN_SIZE) { if (y2 - y1 < MIN_SIZE) {
@ -116,7 +127,6 @@ function addSite(name, y1, x1, y2, x2, color, glyph) {
x1 = (x1 + x2) / 2 - MIN_SIZE / 2; x1 = (x1 + x2) / 2 - MIN_SIZE / 2;
x2 = x1 + MIN_SIZE; x2 = x1 + MIN_SIZE;
} }
/* TODO: use glyph of the site instead of a polygon? */
var polygon = L.polygon( var polygon = L.polygon(
[coord(y1, x1), coord(y2, x1), coord(y2, x2), coord(y1, x2)], { [coord(y1, x1), coord(y2, x1), coord(y2, x2), coord(y1, x2)], {
color: color, color: color,
@ -124,17 +134,21 @@ function addSite(name, y1, x1, y2, x2, color, glyph) {
weight: 3 weight: 3
}).addTo(sitesLayer); }).addTo(sitesLayer);
attachTooltip(polygon, name); /* TODO: use glyph of the site instead of a polygon? */
// var marker = L.marker(coord(y1, x1), { icon: myIcon }).addTo(sitesLayer);
// attachTooltip(marker, urlToolTip("site", id));
attachTooltip(polygon, urlToolTip("site", id));
} }
function addWc(name, y, x, color) { function addWc(id, y, x, color) {
var polygon = L.polygon(square(y, x, structureOffset), { var polygon = L.polygon(square(y, x, structureOffset), {
color: color, color: color,
opacity: 1, fillOpacity: 0.7, opacity: 1, fillOpacity: 0.7,
weight: 3 weight: 3
}).addTo(constructionsLayer); }).addTo(constructionsLayer);
attachTooltip(polygon, name); attachTooltip(polygon, urlToolTip("worldconstruction", id));
} }
function addRegion(name, y1, x1, y2, x2, color) { function addRegion(name, y1, x1, y2, x2, color) {
@ -149,7 +163,7 @@ function addRegion(name, y1, x1, y2, x2, color) {
attachTooltip(polygon, name); attachTooltip(polygon, name);
} }
function addMountain(name, y, x, color) { function addMountain(id, y, x, color) {
x = worldWidth - x - 1; x = worldWidth - x - 1;
var polygon = L.polygon( var polygon = L.polygon(
[[x + mountainOffset / 2, y + mountainOffset], [x + mountainOffset / 2, y + 1 - mountainOffset], [x + 1 - mountainOffset, y + 0.5]], { [[x + mountainOffset / 2, y + mountainOffset], [x + mountainOffset / 2, y + 1 - mountainOffset], [x + 1 - mountainOffset, y + 0.5]], {
@ -158,7 +172,7 @@ function addMountain(name, y, x, color) {
weight: 3 weight: 3
}).addTo(mountainsLayer); }).addTo(mountainsLayer);
attachTooltip(polygon, name); attachTooltip(polygon, urlToolTip("mountain", id));
minx = Math.min(x, minx); minx = Math.min(x, minx);
miny = Math.min(y, miny); miny = Math.min(y, miny);

View File

@ -1,3 +1,4 @@
{{ artifact .Id }}<br />
{{- if or (ne .ItemType "") (ne .ItemSubtype "")}} {{- if or (ne .ItemType "") (ne .ItemSubtype "")}}
{{.Mat}} {{if ne .ItemSubtype ""}}{{.ItemSubtype}}{{else}}{{.ItemType}}{{end}} {{.Mat}} {{if ne .ItemSubtype ""}}{{.ItemSubtype}}{{else}}{{.ItemType}}{{end}}
{{- end}} {{- end}}

View File

@ -1,3 +1,4 @@
{{ entity .Id }}<br />
{{ .Race }}{{ if .Necromancer}} necromancer{{end}} {{ .Type }} {{ .Race }}{{ if .Necromancer}} necromancer{{end}} {{ .Type }}
{{- if .Profession }} {{- if .Profession }}
of {{ .Profession }}s of {{ .Profession }}s

View File

@ -1,3 +1,4 @@
{{ hf .Id }}<br />
{{if .Female }} {{if .Female }}
<i class="fa-solid fa-venus fa-xs"></i> <i class="fa-solid fa-venus fa-xs"></i>
{{else}} {{else}}
@ -12,7 +13,6 @@
{{ if not (or .Deity .Force)}} {{ if not (or .Deity .Force)}}
(*{{ .BirthYear }}{{ if ge .DeathYear 0 }} †{{ .DeathYear }}{{ end }}) (*{{ .BirthYear }}{{ if ge .DeathYear 0 }} †{{ .DeathYear }}{{ end }})
{{ end }} {{ end }}
{{- if or (ne 0 (len .EntityFormerPositionLink)) (ne 0 (len .EntityPositionLink)) }} {{- if or (ne 0 (len .EntityFormerPositionLink)) (ne 0 (len .EntityPositionLink)) }}
<ul class="mb-0"> <ul class="mb-0">
{{- range $i := .EntityPositionLink }} {{- range $i := .EntityPositionLink }}

View File

@ -0,0 +1,2 @@
{{ landmass .Id }}<br />
landmass

View File

@ -0,0 +1,2 @@
{{ region .Id }}<br />
{{ if .IsVolcano }}volcano{{else}}mountain{{end}}

View File

@ -1 +1,2 @@
{{ region .Id }}<br />
{{ .Type }} {{ .Type }}

View File

@ -0,0 +1,2 @@
{{ region .Id }}<br />
river

View File

@ -1 +1,2 @@
{{ .Type }}{{if .Ruin}} (ruin){{end}} {{ site .Id }}<br>
{{ .Type }}{{if .Ruin}} (ruin){{end}}{{ if ne .Owner -1}} of {{ entity .Owner }}{{end}}

View File

@ -1 +1,2 @@
{{ structure .SiteId .Id }}<br />
{{ .Type }}{{if .Ruin}} (ruin){{end}} in {{ site .SiteId }} {{ .Type }}{{if .Ruin}} (ruin){{end}} in {{ site .SiteId }}

View File

@ -1 +1,2 @@
{{ worldConstruction .Id }}<br />
{{ .Type }} {{ .Type }}

View File

@ -1 +1,2 @@
{{ writtenContent .Id }}<br />
{{ .Form }} by {{ hf .AuthorHfid }} {{ .Form }} by {{ hf .AuthorHfid }}