From 12652cccb24e7f55e0e7c73816e2555a17f149b8 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Sat, 4 Jan 2020 01:17:50 +0100 Subject: [PATCH] Fix: Also ignore empty targets Signed-off-by: Knut Ahlers --- cmd/sii-editor/api_saves.go | 11 ++++++----- datatypes.go | 2 ++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/cmd/sii-editor/api_saves.go b/cmd/sii-editor/api_saves.go index 62ccdc1..6394460 100644 --- a/cmd/sii-editor/api_saves.go +++ b/cmd/sii-editor/api_saves.go @@ -7,10 +7,11 @@ import ( "strings" "time" - "github.com/Luzifer/go_helpers/v2/str" - "github.com/Luzifer/sii" "github.com/gorilla/mux" "github.com/pkg/errors" + + "github.com/Luzifer/go_helpers/v2/str" + "github.com/Luzifer/sii" ) const ( @@ -79,7 +80,7 @@ func handleAddJob(w http.ResponseWriter, r *http.Request) { for _, jp := range company.JobOffer { j := jp.Resolve().(*sii.JobOfferData) - if j.CompanyTruck.Target == "null" || j.TrailerVariant.Target == "null" || j.TrailerDefinition.Target == "null" || len(j.TrailerPlace) < 1 { + if j.CompanyTruck.IsNull() || j.TrailerVariant.IsNull() || j.TrailerDefinition.IsNull() || len(j.TrailerPlace) < 1 { continue } cTruck, cTV, cTD = j.CompanyTruck.Target, j.TrailerVariant.Target, j.TrailerDefinition.Target @@ -87,11 +88,11 @@ func handleAddJob(w http.ResponseWriter, r *http.Request) { break } - if cTP == nil { + if cTP == nil || len(cTP) < 1 { // The company did not have any valid job offers to steal from, lets search globally for _, jb := range game.BlocksByClass("job_offer_data") { j := jb.(*sii.JobOfferData) - if j.CompanyTruck.Target == "null" || j.TrailerVariant.Target == "null" || j.TrailerDefinition.Target == "null" || len(j.TrailerPlace) < 1 { + if j.CompanyTruck.IsNull() || j.TrailerVariant.IsNull() || j.TrailerDefinition.IsNull() || len(j.TrailerPlace) < 1 { continue } cTruck, cTV, cTD = j.CompanyTruck.Target, j.TrailerVariant.Target, j.TrailerDefinition.Target diff --git a/datatypes.go b/datatypes.go index c3b7752..5c93e79 100644 --- a/datatypes.go +++ b/datatypes.go @@ -81,6 +81,8 @@ type Ptr struct { unit *Unit } +func (p Ptr) IsNull() bool { return p.Target == "null" || p.Target == "" } + func (p Ptr) MarshalSII() []byte { return []byte(p.Target) } func (p Ptr) Resolve() Block {