Skip to content

Commit

Permalink
store/players: Added the 'UnitUpdates' logic
Browse files Browse the repository at this point in the history
So now units can be updated infinitley
  • Loading branch information
xescugc committed Apr 4, 2024
1 parent 969360b commit a8db88f
Show file tree
Hide file tree
Showing 15 changed files with 524 additions and 165 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ build:
test: wasm ## Run the tests
@xvfb-run go test ./...

.PHONY: generate
generate: ## Generates code
@go generate ./...

.PHONY: test
ctest: wasm ## Run the tests
@xvfb-run go test ./... -coverprofile=cover.out
Expand Down
34 changes: 31 additions & 3 deletions action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package action
import (
"time"

"github.com/xescugc/maze-wars/unit"
"github.com/xescugc/maze-wars/utils"
"github.com/xescugc/maze-wars/utils/graph"
"nhooyr.io/websocket"
Expand All @@ -16,6 +17,7 @@ type Action struct {
SummonUnit *SummonUnitPayload `json:"summon_unit,omitempty"`
RemoveUnit *RemoveUnitPayload `json:"remove_unit,omitempty"`
ChangeUnitLine *ChangeUnitLinePayload `json:"change_unit_line,omitempty"`
UpdateUnit *UpdateUnitPayload `json:"update_unit,omitempty"`
StealLive *StealLivePayload `json:"steal_live,omitempty"`
CameraZoom *CameraZoomPayload `json:"camera_zoom,omitempty"`
SelectTower *SelectTowerPayload `json:"select_tower,omitempty"`
Expand Down Expand Up @@ -249,15 +251,15 @@ func NewTowerAttack(uid, tt string) *Action {

type UnitKilledPayload struct {
PlayerID string
UnitType string
UnitID string
}

func NewUnitKilled(pid, ut string) *Action {
func NewUnitKilled(pid, uid string) *Action {
return &Action{
Type: UnitKilled,
UnitKilled: &UnitKilledPayload{
PlayerID: pid,
UnitType: ut,
UnitID: uid,
},
}
}
Expand Down Expand Up @@ -498,6 +500,15 @@ type SyncStatePlayerPayload struct {
Gold int
Current bool
Winner bool

UnitUpdates map[string]SyncStatePlayerUnitUpdatePayload
}

type SyncStatePlayerUnitUpdatePayload struct {
Current unit.Stats
Level int
UpdateCost int
Next unit.Stats
}

type SyncStateTowerPayload struct {
Expand All @@ -520,6 +531,8 @@ type SyncStateUnitPayload struct {

Health float64

Level int

Path []graph.Step
HashPath string
CreatedAt time.Time
Expand Down Expand Up @@ -561,3 +574,18 @@ func NewVersionError(err string) *Action {
},
}
}

type UpdateUnitPayload struct {
Type string
PlayerID string
}

func NewUpdateUnit(pid, t string) *Action {
return &Action{
Type: UpdateUnit,
UpdateUnit: &UpdateUnitPayload{
Type: t,
PlayerID: pid,
},
}
}
1 change: 1 addition & 0 deletions action/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const (
CursorMove Type = iota
CameraZoom
SummonUnit
UpdateUnit
TPS
RemoveUnit
StealLive
Expand Down
Loading

0 comments on commit a8db88f

Please sign in to comment.