From 0282977343203fe4f494733a2905a6b2b83b1642 Mon Sep 17 00:00:00 2001 From: Robert Janetzko Date: Fri, 29 Apr 2022 13:33:21 +0000 Subject: [PATCH] site history --- analyze/overwrites.json | 2 +- backend/go.mod | 1 + backend/go.sum | 3 ++- backend/model/model.go | 5 ++--- backend/model/process.go | 8 ++++---- backend/templates/entity.html | 6 +++--- 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/analyze/overwrites.json b/analyze/overwrites.json index fe5c0df..4107f57 100644 --- a/analyze/overwrites.json +++ b/analyze/overwrites.json @@ -23,7 +23,7 @@ "Entity": [ { "Name": "Sites", - "Type": "map[int]*Site" + "Type": "[]int" } ], "Site": [ diff --git a/backend/go.mod b/backend/go.mod index 2d018bf..063a689 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -9,6 +9,7 @@ require ( github.com/iancoleman/strcase v0.2.0 github.com/pkg/profile v1.6.0 github.com/shirou/gopsutil v3.21.11+incompatible + golang.org/x/exp v0.0.0-20220428152302-39d4317da171 ) require ( diff --git a/backend/go.sum b/backend/go.sum index f81c8d3..deba2f4 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -27,10 +27,11 @@ github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKl github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg= github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= +golang.org/x/exp v0.0.0-20220428152302-39d4317da171 h1:TfdoLivD44QwvssI9Sv1xwa5DcL5XQr4au4sZ2F2NV4= +golang.org/x/exp v0.0.0-20220428152302-39d4317da171/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57 h1:F5Gozwx4I1xtr/sr/8CFbb57iKi3297KFs0QDbGN60A= golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 h1:xHms4gcpe1YE7A3yIllJXP16CMAGuqwO2lX1mTyyRRc= golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/backend/model/model.go b/backend/model/model.go index 6f8023e..e1ac854 100644 --- a/backend/model/model.go +++ b/backend/model/model.go @@ -1987,13 +1987,12 @@ type Entity struct { Type_ EntityType `json:"type" legend:"plus"` // type Weapon []EntityWeapon `json:"weapon" legend:"plus"` // weapon WorshipId []int `json:"worshipId" legend:"plus"` // worship_id - Sites map[int]*Site `json:"sites" legend:"add"` // Sites + Sites []int `json:"sites" legend:"add"` // Sites } func NewEntity() *Entity { return &Entity{ - Id_: -1, - Sites: make(map[int]*Site), + Id_: -1, } } func (x *Entity) Id() int { return x.Id_ } diff --git a/backend/model/process.go b/backend/model/process.go index 4a53bc6..8a143b1 100644 --- a/backend/model/process.go +++ b/backend/model/process.go @@ -1,8 +1,9 @@ package model import ( - "fmt" "strings" + + "golang.org/x/exp/slices" ) func (w *DfWorld) process() { @@ -57,10 +58,9 @@ func (w *DfWorld) processEvents() { } func (w *DfWorld) addEntitySite(entityId, siteId int) { - fmt.Println("add site", entityId, siteId) if e, ok := w.Entities[entityId]; ok { - if s, ok := w.Sites[siteId]; ok { - e.Sites[s.Id_] = s + if !slices.Contains(e.Sites, siteId) { + e.Sites = append(e.Sites, siteId) } } } diff --git a/backend/templates/entity.html b/backend/templates/entity.html index e12e58f..2816034 100644 --- a/backend/templates/entity.html +++ b/backend/templates/entity.html @@ -8,10 +8,10 @@
Sites
- {{- range $i, $s := .Sites }} + {{- range .Sites }} - - + + {{- end }}
{{ site $s.Id }} {{ template "events.html" events (history $s.Id) }} {{ site . }} {{ template "events.html" events (history .) }}