Skip to content

Commit

Permalink
Remove recovery example, rename tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jerargus committed Apr 16, 2024
1 parent ea58c70 commit 4a9402c
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 152 deletions.
6 changes: 3 additions & 3 deletions cardinal/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
"github.com/argus-labs/starter-game-template/cardinal/component"
)

// TestDefaultPlayersAreCreatedOnInit ensures a set of default players are created in the SpawnDefaultPlayersSystem.
// These players should only be created on tick 0.
func TestDefaultPlayersAreCreatedOnInit(t *testing.T) {
// TestInitSystem_SpawnDefaultPlayersSystem_DefaultPlayersAreSpawned ensures a set of default players are created in the
// SpawnDefaultPlayersSystem. These players should only be created on tick 0.
func TestInitSystem_SpawnDefaultPlayersSystem_DefaultPlayersAreSpawned(t *testing.T) {
tf := testutils.NewTestFixture(t, nil)
MustInitWorld(tf.World)

Expand Down
1 change: 0 additions & 1 deletion cardinal/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ func MustInitWorld(w *cardinal.World) {
// For example, you may want to run the attack system before the regen system
// so that the player's HP is subtracted (and player killed if it reaches 0) before HP is regenerated.
Must(cardinal.RegisterSystems(w,
system.RecoverPlayersSystem,
system.AttackSystem,
system.RegenSystem,
system.PlayerSpawnerSystem,
Expand Down
83 changes: 0 additions & 83 deletions cardinal/recover_test.go

This file was deleted.

7 changes: 6 additions & 1 deletion cardinal/system/default_spanwer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ import (
"fmt"

"pkg.world.dev/world-engine/cardinal"

comp "github.com/argus-labs/starter-game-template/cardinal/component"
)

// SpawnDefaultPlayersSystem creates 10 players with nicknames "default-[0-9]". This System is registered as an
// Init system, meaning it will be executed exactly one time on tick 0.
func SpawnDefaultPlayersSystem(world cardinal.WorldContext) error {
for i := 0; i < 10; i++ {
name := fmt.Sprintf("default-%d", i)
_, err := createPlayer(world, name)
_, err := cardinal.Create(world,
comp.Player{Nickname: name},
comp.Health{HP: InitialHP},
)
if err != nil {
return err
}
Expand Down
23 changes: 4 additions & 19 deletions cardinal/system/player_spawner.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"pkg.world.dev/world-engine/cardinal"
"pkg.world.dev/world-engine/cardinal/message"
"pkg.world.dev/world-engine/cardinal/types"

comp "github.com/argus-labs/starter-game-template/cardinal/component"
"github.com/argus-labs/starter-game-template/cardinal/msg"
Expand All @@ -21,7 +20,10 @@ func PlayerSpawnerSystem(world cardinal.WorldContext) error {
return cardinal.EachMessage[msg.CreatePlayerMsg, msg.CreatePlayerResult](
world,
func(create message.TxData[msg.CreatePlayerMsg]) (msg.CreatePlayerResult, error) {
id, err := createPlayer(world, create.Msg.Nickname)
id, err := cardinal.Create(world,
comp.Player{Nickname: create.Msg.Nickname},
comp.Health{HP: InitialHP},
)
if err != nil {
return msg.CreatePlayerResult{}, fmt.Errorf("error creating player: %w", err)
}
Expand All @@ -36,20 +38,3 @@ func PlayerSpawnerSystem(world cardinal.WorldContext) error {
return msg.CreatePlayerResult{Success: true}, nil
})
}

// createPlayer creates a player with the given name, and sets the player's HP to the InitialHP value.
// It also updates the PlayerNameToID global variable that maintains a mapping of player names to Entity IDs.
func createPlayer(world cardinal.WorldContext, name string) (types.EntityID, error) {
id, err := cardinal.Create(world,
comp.Player{Nickname: name},
comp.Health{HP: InitialHP},
)
if err != nil {
return 0, err
}
if PlayerNameToID == nil {
PlayerNameToID = map[string]types.EntityID{}
}
PlayerNameToID[name] = id
return id, nil
}
36 changes: 0 additions & 36 deletions cardinal/system/recover.go

This file was deleted.

18 changes: 9 additions & 9 deletions cardinal/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const (
createMsgName = "game.create-player"
)

// TestErrorWhenAttackTargetDoesNotExist ensures the attack message results in an error when the given target does
// not exist. Note, message errors are stored in receipts; they are NOT returned from the relevant system.
func TestErrorWhenAttackTargetDoesNotExist(t *testing.T) {
// TestSystem_AttackSystem_ErrorWhenTargetDoesNotExist ensures the attack message results in an error when the given
// target does not exist. Note, message errors are stored in receipts; they are NOT returned from the relevant system.
func TestSystem_AttackSystem_ErrorWhenTargetDoesNotExist(t *testing.T) {
tf := testutils.NewTestFixture(t, nil)
MustInitWorld(tf.World)

Expand All @@ -36,9 +36,9 @@ func TestErrorWhenAttackTargetDoesNotExist(t *testing.T) {
}
}

// TestCanCreatePlayer ensure the CreatePlayer message can be used to create a new player with the default amount of
// health. cardinal.NewSearch is used to find the newly created player.
func TestCanCreatePlayers(t *testing.T) {
// TestSystem_PlayerSpawnerSystem_CanCreatePlayer ensures the CreatePlayer message can be used to create a new player
// with the default amount of health. cardinal.NewSearch is used to find the newly created player.
func TestSystem_PlayerSpawnerSystem_CanCreatePlayer(t *testing.T) {
tf := testutils.NewTestFixture(t, nil)
MustInitWorld(tf.World)

Expand Down Expand Up @@ -75,9 +75,9 @@ func TestCanCreatePlayers(t *testing.T) {
}
}

// TestAttackingTargetReducesTheirHealth ensures an attack message can find an existing target the reduce the target's
// health.
func TestAttackingTargetReducesTheirHealth(t *testing.T) {
// TestSystem_AttackSystem_AttackingTargetReducesTheirHealth ensures an attack message can find an existing target the
// reduce the target's health.
func TestSystem_AttackSystem_AttackingTargetReducesTheirHealth(t *testing.T) {
tf := testutils.NewTestFixture(t, nil)
MustInitWorld(tf.World)

Expand Down

0 comments on commit 4a9402c

Please sign in to comment.