Skip to content

Commit

Permalink
Finally resolve issues with game ticks
Browse files Browse the repository at this point in the history
Teach plant model how to deal with null fields, and properly alias to DB
fields
  • Loading branch information
Muirrum committed Oct 26, 2023
1 parent d5eadeb commit 0392a35
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion internal/game/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func RunTick() error {
}

var plants []models.Plant
err = db.Select(&plants, "SELECT * FROM plant WHERE stead_owner=$1", u.Id)
err = db.Select(&plants, "SELECT id,kind,xp,xp_multiplier,next_yield FROM plant WHERE stead_owner=$1", u.Id)
if err != nil {
log.Error(err)
continue
Expand Down
11 changes: 6 additions & 5 deletions internal/models/models.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package models

import (
"database/sql"
"database/sql/driver"
"encoding/json"
"errors"
Expand Down Expand Up @@ -28,11 +29,11 @@ type Craft struct {
}

type Plant struct {
Id int `json:"id"`
Kind string `json:"kind"`
Xp int `json:"xp"`
XpMultiplier float32 `json:"xp_multiplier"`
NextYield float32 `json:"tt_yield"`
Id int `json:"id"`
Kind string `json:"kind"`
Xp int `json:"xp"`
XpMultiplier float32 `json:"xp_multiplier" db:"xp_multiplier"`
NextYield sql.NullFloat64 `json:"tt_yield" db:"next_yield"`
}

type Stead struct {
Expand Down

0 comments on commit 0392a35

Please sign in to comment.