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": [
{
"Name": "Owner",
"Type": "int"
},
{
"Name": "Ruin",
"Type": "bool"

View File

@ -141,21 +141,9 @@ func (c *Context) artifact(id int) string {
func (c *Context) entity(id int) string {
if x, ok := c.World.Entities[id]; ok {
c := ""
switch x.Race {
case "dwarf":
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"`
c := x.Color()
if c != "" {
c = fmt.Sprintf(` style="color:%s"`, c)
}
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()
}
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 {
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], ",")
x2, _ := strconv.ParseFloat(c2[0], 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 {
return ""
}

View File

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

View File

@ -76,6 +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
case *HistoricalEventDestroyedSite:
w.addEntitySite(d.DefenderCivId, 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.NewSiteCivId, d.SiteId)
w.Sites[d.SiteId].Ruin = false
w.Sites[d.SiteId].Owner = d.NewSiteCivId
case *HistoricalEventHfDestroyedSite:
w.addEntitySite(d.SiteCivId, 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.Sites[d.SiteId].Ruin = false
w.Sites[d.SiteId].Owner = d.SiteCivId
case *HistoricalEventAddHfEntityLink:
if d.Link == HistoricalEventAddHfEntityLinkLink_Position {
if hf, ok := w.HistoricalFigures[d.Hfid]; ok {