Skip to content

Commit

Permalink
WIP change for bugfix help
Browse files Browse the repository at this point in the history
  • Loading branch information
shantanu-argus committed Nov 14, 2024
1 parent 7244207 commit 7aab0b3
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 16 deletions.
9 changes: 9 additions & 0 deletions cardinal/system/default_spawner.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,18 @@ import (
func SpawnDefaultPlayersSystem(world cardinal.WorldContext) error {
for i := 0; i < 10; i++ {
name := fmt.Sprintf("default-%d", i)
fmt.Println("Creating entity for ", name)

Check failure on line 16 in cardinal/system/default_spawner.go

View workflow job for this annotation

GitHub Actions / Go

use of `fmt.Println` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` (forbidigo)
_, err := cardinal.Create(world,
comp.Player{Nickname: name},
comp.Health{HP: InitialHP},
comp.Movement{
CurrentLocation: comp.Location{X: InitialXLocation, Y: InitialYLocation},
Velocity: InitialVelocity,
CurrentDirection: comp.Direction{
comp.Directions[InitialDirection].X,
comp.Directions[InitialDirection].Y,
},
},
)
if err != nil {
return err
Expand Down
53 changes: 39 additions & 14 deletions cardinal/system/movement_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,69 @@ import (

// MovementSystem updates the player's location based on its velocity and direction.
func MovementSystem(world cardinal.WorldContext) error {
fmt.Println("Hello from movement system")

Check failure on line 15 in cardinal/system/movement_system.go

View workflow job for this annotation

GitHub Actions / Go

use of `fmt.Println` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` (forbidigo)
return cardinal.NewSearch().Entity(
filter.Exact(filter.Component[comp.Player](), filter.Component[comp.Movement]())).
Each(world, func(id types.EntityID) bool {
movement, err := cardinal.GetComponent[comp.Movement](world, id)
if err != nil {
fmt.Println("Error in movement system", err)

Check failure on line 21 in cardinal/system/movement_system.go

View workflow job for this annotation

GitHub Actions / Go

use of `fmt.Println` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` (forbidigo)
return true
}

// TODO: How to get delta time?
movement.CurrentLocation.X += movement.Velocity * float64(movement.CurrentDirection.X)
movement.CurrentLocation.Y += movement.Velocity * float64(movement.CurrentDirection.Y)

fmt.Println(movement)

Check failure on line 24 in cardinal/system/movement_system.go

View workflow job for this annotation

GitHub Actions / Go

use of `fmt.Println` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` (forbidigo)
if err := cardinal.SetComponent[comp.Movement](world, id, movement); err != nil {
return true
}
return true
})
//return cardinal.NewSearch().Entity(

Check failure on line 30 in cardinal/system/movement_system.go

View workflow job for this annotation

GitHub Actions / Go

commentFormatting: put a space between `//` and comment text (gocritic)
// filter.Exact(filter.Component[comp.Movement]())).
// Each(world, func(id types.EntityID) bool {
// fmt.Println("Hello from movement system")
// movement, err := cardinal.GetComponent[comp.Movement](world, id)
// if err != nil {
// fmt.Println("Error in movement system")
// return true
// }
// velocity := 5.0
// movement.CurrentLocation.X += velocity * float64(movement.CurrentDirection.X) * 0.2
// movement.CurrentLocation.Y += velocity * float64(movement.CurrentDirection.Y) * 0.2
//
// if err := cardinal.SetComponent[comp.Movement](world, id, movement); err != nil {
// return true
// }
// return true
// })
}

func MovementValidationSystem(world cardinal.WorldContext) error {
return cardinal.EachMessage[msg.MovementPlayerMsg, msg.MovementPlayerMsgReply](
world,
func(movement cardinal.TxData[msg.MovementPlayerMsg]) (msg.MovementPlayerMsgReply, error) {
fmt.Println("Hello from movement validation system", movement)

Check failure on line 54 in cardinal/system/movement_system.go

View workflow job for this annotation

GitHub Actions / Go

use of `fmt.Println` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` (forbidigo)
playerID, playerMovementData, err := queryTargetPlayerMovementData(world, movement.Msg.TargetNickname)
if err != nil {
return msg.MovementPlayerMsgReply{}, fmt.Errorf("failed to update movement: %w", err)
}
const errorTolerance float64 = 0.001
const errorTolerance float64 = 0.2
if math.Abs(playerMovementData.CurrentLocation.X-movement.Msg.LocationX) > errorTolerance ||
math.Abs(playerMovementData.CurrentLocation.Y-movement.Msg.LocationY) > errorTolerance {
return msg.MovementPlayerMsgReply{IsValid: false, LocationX: playerMovementData.CurrentLocation.X, LocationY: playerMovementData.CurrentLocation.Y}, nil
} else {
playerMovementData.CurrentLocation.X = movement.Msg.LocationX
playerMovementData.CurrentLocation.Y = movement.Msg.LocationY
if err := cardinal.SetComponent[comp.Movement](world, playerID, playerMovementData); err != nil {
return msg.MovementPlayerMsgReply{IsValid: false, LocationX: playerMovementData.CurrentLocation.X, LocationY: playerMovementData.CurrentLocation.Y}, fmt.Errorf("failed to update movement: %w", err)
}
return msg.MovementPlayerMsgReply{IsValid: true, LocationX: playerMovementData.CurrentLocation.X, LocationY: playerMovementData.CurrentLocation.Y}, nil
return msg.MovementPlayerMsgReply{IsValid: false,
LocationX: playerMovementData.CurrentLocation.X,
LocationY: playerMovementData.CurrentLocation.Y},
nil
}
playerMovementData.CurrentLocation.X = movement.Msg.LocationX
playerMovementData.CurrentLocation.Y = movement.Msg.LocationY
if err := cardinal.SetComponent[comp.Movement](world, playerID, playerMovementData); err != nil {
return msg.MovementPlayerMsgReply{IsValid: false,
LocationX: playerMovementData.CurrentLocation.X,
LocationY: playerMovementData.CurrentLocation.Y},
fmt.Errorf("failed to update movement: %w", err)
}
return msg.MovementPlayerMsgReply{IsValid: true,
LocationX: playerMovementData.CurrentLocation.X,
LocationY: playerMovementData.CurrentLocation.Y},
nil
})
}
2 changes: 2 additions & 0 deletions cardinal/system/regen.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package system

import (
"fmt"
"pkg.world.dev/world-engine/cardinal"
"pkg.world.dev/world-engine/cardinal/search/filter"
"pkg.world.dev/world-engine/cardinal/types"
Expand All @@ -18,6 +19,7 @@ func RegenSystem(world cardinal.WorldContext) error {
if err != nil {
return true
}
fmt.Println(id)

Check failure on line 22 in cardinal/system/regen.go

View workflow job for this annotation

GitHub Actions / Go

use of `fmt.Println` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` (forbidigo)
health.HP++
if err := cardinal.SetComponent[comp.Health](world, id, health); err != nil {
return true
Expand Down
5 changes: 3 additions & 2 deletions cardinal/system/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ func queryTargetPlayerMovementData(world cardinal.WorldContext, targetNickname s
var playerMovementComponent *comp.Movement
var err error
searchErr := cardinal.NewSearch().Entity(
filter.Exact(filter.Component[comp.Player](), filter.Component[comp.Movement]())).Each(world,
filter.Exact(filter.Component[comp.Player]())).Each(world,
func(id types.EntityID) bool {
var player *comp.Player
player, err = cardinal.GetComponent[comp.Player](world, id)
if err != nil {
return false
}

fmt.Println(player)

Check failure on line 65 in cardinal/system/utils.go

View workflow job for this annotation

GitHub Actions / Go

use of `fmt.Println` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` (forbidigo)
// Terminates the search if the player is found
if player.Nickname == targetNickname {
playerID = id
Expand All @@ -76,6 +76,7 @@ func queryTargetPlayerMovementData(world cardinal.WorldContext, targetNickname s
// Continue searching if the player is not the target player
return true
})
fmt.Println("finding ", targetNickname)

Check failure on line 79 in cardinal/system/utils.go

View workflow job for this annotation

GitHub Actions / Go

use of `fmt.Println` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` (forbidigo)
if searchErr != nil {
return 0, nil, err
}
Expand Down

0 comments on commit 7aab0b3

Please sign in to comment.