map site colors

This commit is contained in:
Robert Janetzko 2022-05-07 15:18:08 +00:00
parent eb269cc580
commit 27483ec834
6 changed files with 40 additions and 16 deletions

View File

@ -110,6 +110,10 @@
} }
], ],
"Site": [ "Site": [
{
"Name": "Owner",
"Type": "int"
},
{ {
"Name": "Ruin", "Name": "Ruin",
"Type": "bool" "Type": "bool"

View File

@ -141,21 +141,9 @@ func (c *Context) artifact(id int) string {
func (c *Context) entity(id int) string { func (c *Context) entity(id int) string {
if x, ok := c.World.Entities[id]; ok { if x, ok := c.World.Entities[id]; ok {
c := "" c := x.Color()
switch x.Race { if c != "" {
case "dwarf": c = fmt.Sprintf(` style="color:%s"`, c)
c = ` style="color:#FFCC33"`
case "elf":
c = ` style="color:#99FF00"`
case "human":
c = ` style="color:#0000CC"`
case "kobold":
c = ` style="color:#333"`
case "goblin":
c = ` style="color:#CC0000"`
}
if x.Necromancer {
c = ` style="color:#A0A"`
} }
return fmt.Sprintf(`<a class="entity" href="/entity/%d"><i class="%s fa-xs" %s></i> %s</a>`, x.Id(), x.Icon(), c, util.Title(x.Name())) return fmt.Sprintf(`<a class="entity" href="/entity/%d"><i class="%s fa-xs" %s></i> %s</a>`, x.Id(), x.Icon(), c, util.Title(x.Name()))
} }

View File

@ -96,6 +96,26 @@ func (e *Entity) Type() string {
return e.Type_.String() return e.Type_.String()
} }
func (x *Entity) Color() string {
c := ""
switch x.Race {
case "dwarf":
c = `#FFCC33`
case "elf":
c = `#99FF00`
case "human":
c = `#0000CC`
case "kobold":
c = `#333`
case "goblin":
c = `#CC0000`
}
if x.Necromancer {
c = `#A0A`
}
return c
}
func (e *Entity) Weapons() []string { func (e *Entity) Weapons() []string {
return util.Map(e.Weapon, func(w EntityWeapon) string { return w.String() }) return util.Map(e.Weapon, func(w EntityWeapon) string { return w.String() })
} }

View File

@ -82,7 +82,11 @@ var AddMapSite = func(w *DfWorld, id int) template.HTML {
c2 := strings.Split(coords[1], ",") c2 := strings.Split(coords[1], ",")
x2, _ := strconv.ParseFloat(c2[0], 32) x2, _ := strconv.ParseFloat(c2[0], 32)
y2, _ := strconv.ParseFloat(c2[1], 32) y2, _ := strconv.ParseFloat(c2[1], 32)
return template.HTML(fmt.Sprintf(`<script>addSite("%s", %f, %f, %f, %f, "#FF0", "")</script>`, site.Name(), x1/16.0, y1/16.0-1, x2/16.0, y2/16.0-1)) c := "#ff0"
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))
} else { } else {
return "" return ""
} }

View File

@ -21131,6 +21131,7 @@ type Site struct {
SiteProperties map[int]*SiteSiteProperty `json:"siteProperties" legend:"base" related:""` // site_properties SiteProperties map[int]*SiteSiteProperty `json:"siteProperties" legend:"base" related:""` // site_properties
Structures map[int]*Structure `json:"structures" legend:"both" related:""` // structures Structures map[int]*Structure `json:"structures" legend:"both" related:""` // structures
Type_ SiteType `json:"type" legend:"base" related:""` // type Type_ SiteType `json:"type" legend:"base" related:""` // type
Owner int `json:"owner" legend:"add" related:""` // Owner
Ruin bool `json:"ruin" legend:"add" related:""` // Ruin Ruin bool `json:"ruin" legend:"add" related:""` // Ruin
} }
@ -21141,6 +21142,7 @@ func NewSite() *Site {
Id_: -1, Id_: -1,
SiteProperties: make(map[int]*SiteSiteProperty), SiteProperties: make(map[int]*SiteSiteProperty),
Structures: make(map[int]*Structure), Structures: make(map[int]*Structure),
Owner: -1,
} }
} }
func (x *Site) Id() int { return x.Id_ } func (x *Site) Id() int { return x.Id_ }
@ -21169,6 +21171,9 @@ func (x *Site) MarshalJSON() ([]byte, error) {
if x.Type_ != 0 { if x.Type_ != 0 {
d["type"] = x.Type_ d["type"] = x.Type_
} }
if x.Owner != -1 {
d["owner"] = x.Owner
}
d["ruin"] = x.Ruin d["ruin"] = x.Ruin
return json.Marshal(d) return json.Marshal(d)
} }

View File

@ -76,6 +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
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)
@ -86,6 +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
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)
@ -94,6 +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
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 {