From d700b27487deae776cbe508659d415d31092dd18 Mon Sep 17 00:00:00 2001 From: Joseph Manley Date: Fri, 21 Aug 2020 01:17:55 -0400 Subject: [PATCH] Read response as float --- server/plugin/entities/entities.go | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/server/plugin/entities/entities.go b/server/plugin/entities/entities.go index 3434166..7f68e71 100644 --- a/server/plugin/entities/entities.go +++ b/server/plugin/entities/entities.go @@ -16,32 +16,21 @@ type PlayerEntity struct { // PlayerPosResponse struct that represents client data type PlayerPosResponse struct { - X string - Y string + X float64 + Y float64 } // ParsePositionRequest parses data from client func (p *PlayerEntity) ParsePositionRequest(data []byte) (PlayerPosResponse, error) { var response PlayerPosResponse err := json.Unmarshal(data, &response) - if err != nil { - fmt.Printf("Failed to parse: %s", string(data[:])) - } return response, err } //UpdateBasedOnResponse updates the player object based on a response object func (p *PlayerEntity) UpdateBasedOnResponse(response PlayerPosResponse) error { - if fx, err := strconv.ParseFloat(response.X, 64); err != nil { - return err - } else { - p.X = fx - if fy, err := strconv.ParseFloat(response.Y, 64); err != nil { - return err - } else { - p.Y = fy - } - } + p.Y = response.Y + p.X = response.X return nil }