Skip to content

Commit

Permalink
See Argus-Labs/world-engine@78ec35b from refs/heads/main
Browse files Browse the repository at this point in the history
  • Loading branch information
Argus-Labs committed Feb 5, 2024
1 parent 74790b3 commit 62c5a8f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions cardinal/system/system_regen.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import (
// RegenSystem replenishes the player's HP at every tick.
// This provides an example of a system that doesn't rely on a transaction to update a component.
func RegenSystem(world cardinal.WorldContext) error {
search := world.NewSearch(cardinal.Exact(comp.Player{}, comp.Health{}))
search, err := world.NewSearch(cardinal.Exact(comp.Player{}, comp.Health{}))
if err != nil {
return err
}

err := search.Each(world, func(id cardinal.EntityID) bool {
err = search.Each(world, func(id cardinal.EntityID) bool {
health, err := cardinal.GetComponent[comp.Health](world, id)
if err != nil {
return true
Expand Down
7 changes: 5 additions & 2 deletions cardinal/system/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import (

// queryTargetPlayer queries for the target player's entity ID and health component.
func queryTargetPlayer(world cardinal.WorldContext, targetNickname string) (cardinal.EntityID, *comp.Health, error) {
search := world.NewSearch(cardinal.Exact(comp.Player{}, comp.Health{}))
search, err := world.NewSearch(cardinal.Exact(comp.Player{}, comp.Health{}))
if err != nil {
return 0, nil, err
}

var playerID cardinal.EntityID
var playerHealth *comp.Health
err := search.Each(world, func(id cardinal.EntityID) bool {
err = search.Each(world, func(id cardinal.EntityID) bool {
player, err := cardinal.GetComponent[comp.Player](world, id)
if err != nil {
return false
Expand Down

0 comments on commit 62c5a8f

Please sign in to comment.