map popovers
This commit is contained in:
parent
27483ec834
commit
ccdef3989d
15 changed files with 50 additions and 15 deletions
|
@ -86,7 +86,10 @@ var AddMapSite = func(w *DfWorld, id int) template.HTML {
|
|||
if e, ok := w.Entities[site.Owner]; ok {
|
||||
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 {
|
||||
return ""
|
||||
}
|
||||
|
@ -97,7 +100,7 @@ var AddMapMountain = func(w *DfWorld, id int) template.HTML {
|
|||
c1 := strings.Split(m.Coords, ",")
|
||||
x, _ := strconv.Atoi(c1[0])
|
||||
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 ""
|
||||
}
|
||||
|
@ -113,7 +116,7 @@ var AddMapWorldConstruction = func(w *DfWorld, id int) template.HTML {
|
|||
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 += "], {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('mouseout', function (e) { this.setStyle({ weight: 3}); });\n"
|
||||
r += "</script>"
|
||||
|
|
|
@ -76,7 +76,7 @@ func (w *DfWorld) processEvents() {
|
|||
w.addEntitySite(d.CivId, d.SiteId)
|
||||
w.addEntitySite(d.SiteCivId, d.SiteId)
|
||||
w.Sites[d.SiteId].Ruin = false
|
||||
w.Sites[d.SiteId].Owner = d.SiteCivId
|
||||
w.Sites[d.SiteId].Owner = d.CivId
|
||||
case *HistoricalEventDestroyedSite:
|
||||
w.addEntitySite(d.DefenderCivId, 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.NewSiteCivId, d.SiteId)
|
||||
w.Sites[d.SiteId].Ruin = false
|
||||
w.Sites[d.SiteId].Owner = d.NewSiteCivId
|
||||
w.Sites[d.SiteId].Owner = d.AttackerCivId
|
||||
case *HistoricalEventHfDestroyedSite:
|
||||
w.addEntitySite(d.SiteCivId, 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.Sites[d.SiteId].Ruin = false
|
||||
w.Sites[d.SiteId].Owner = d.SiteCivId
|
||||
w.Sites[d.SiteId].Owner = d.CivId
|
||||
case *HistoricalEventAddHfEntityLink:
|
||||
if d.Link == HistoricalEventAddHfEntityLinkLink_Position {
|
||||
if hf, ok := w.HistoricalFigures[d.Hfid]; ok {
|
||||
|
|
|
@ -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("/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("/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("/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.RegisterWorldResourcePage("/region/{id}", "region.html", func(id int) any { return srv.context.world.Regions[id] })
|
||||
|
|
|
@ -105,7 +105,18 @@ function attachTooltip(layer, 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 */
|
||||
var MIN_SIZE = .3;
|
||||
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;
|
||||
x2 = x1 + MIN_SIZE;
|
||||
}
|
||||
/* TODO: use glyph of the site instead of a polygon? */
|
||||
var polygon = L.polygon(
|
||||
[coord(y1, x1), coord(y2, x1), coord(y2, x2), coord(y1, x2)], {
|
||||
color: color,
|
||||
|
@ -124,17 +134,21 @@ function addSite(name, y1, x1, y2, x2, color, glyph) {
|
|||
weight: 3
|
||||
}).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), {
|
||||
color: color,
|
||||
opacity: 1, fillOpacity: 0.7,
|
||||
weight: 3
|
||||
}).addTo(constructionsLayer);
|
||||
|
||||
attachTooltip(polygon, name);
|
||||
attachTooltip(polygon, urlToolTip("worldconstruction", id));
|
||||
}
|
||||
|
||||
function addRegion(name, y1, x1, y2, x2, color) {
|
||||
|
@ -149,7 +163,7 @@ function addRegion(name, y1, x1, y2, x2, color) {
|
|||
attachTooltip(polygon, name);
|
||||
}
|
||||
|
||||
function addMountain(name, y, x, color) {
|
||||
function addMountain(id, y, x, color) {
|
||||
x = worldWidth - x - 1;
|
||||
var polygon = L.polygon(
|
||||
[[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
|
||||
}).addTo(mountainsLayer);
|
||||
|
||||
attachTooltip(polygon, name);
|
||||
attachTooltip(polygon, urlToolTip("mountain", id));
|
||||
|
||||
minx = Math.min(x, minx);
|
||||
miny = Math.min(y, miny);
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
{{ artifact .Id }}<br />
|
||||
{{- if or (ne .ItemType "") (ne .ItemSubtype "")}}
|
||||
{{.Mat}} {{if ne .ItemSubtype ""}}{{.ItemSubtype}}{{else}}{{.ItemType}}{{end}}
|
||||
{{- end}}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
{{ entity .Id }}<br />
|
||||
{{ .Race }}{{ if .Necromancer}} necromancer{{end}} {{ .Type }}
|
||||
{{- if .Profession }}
|
||||
of {{ .Profession }}s
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
{{ hf .Id }}<br />
|
||||
{{if .Female }}
|
||||
<i class="fa-solid fa-venus fa-xs"></i>
|
||||
{{else}}
|
||||
|
@ -12,7 +13,6 @@
|
|||
{{ if not (or .Deity .Force)}}
|
||||
(*{{ .BirthYear }}{{ if ge .DeathYear 0 }} †{{ .DeathYear }}{{ end }})
|
||||
{{ end }}
|
||||
|
||||
{{- if or (ne 0 (len .EntityFormerPositionLink)) (ne 0 (len .EntityPositionLink)) }}
|
||||
<ul class="mb-0">
|
||||
{{- range $i := .EntityPositionLink }}
|
||||
|
|
2
backend/templates/popoverLandmass.html
Normal file
2
backend/templates/popoverLandmass.html
Normal file
|
@ -0,0 +1,2 @@
|
|||
{{ landmass .Id }}<br />
|
||||
landmass
|
2
backend/templates/popoverMountain.html
Normal file
2
backend/templates/popoverMountain.html
Normal file
|
@ -0,0 +1,2 @@
|
|||
{{ region .Id }}<br />
|
||||
{{ if .IsVolcano }}volcano{{else}}mountain{{end}}
|
|
@ -1 +1,2 @@
|
|||
{{ region .Id }}<br />
|
||||
{{ .Type }}
|
2
backend/templates/popoverRiver.html
Normal file
2
backend/templates/popoverRiver.html
Normal file
|
@ -0,0 +1,2 @@
|
|||
{{ region .Id }}<br />
|
||||
river
|
|
@ -1 +1,2 @@
|
|||
{{ .Type }}{{if .Ruin}} (ruin){{end}}
|
||||
{{ site .Id }}<br>
|
||||
{{ .Type }}{{if .Ruin}} (ruin){{end}}{{ if ne .Owner -1}} of {{ entity .Owner }}{{end}}
|
|
@ -1 +1,2 @@
|
|||
{{ structure .SiteId .Id }}<br />
|
||||
{{ .Type }}{{if .Ruin}} (ruin){{end}} in {{ site .SiteId }}
|
|
@ -1 +1,2 @@
|
|||
{{ worldConstruction .Id }}<br />
|
||||
{{ .Type }}
|
|
@ -1 +1,2 @@
|
|||
{{ writtenContent .Id }}<br />
|
||||
{{ .Form }} by {{ hf .AuthorHfid }}
|
Loading…
Reference in a new issue