Skip to content

Commit

Permalink
minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
smsunarto committed Dec 5, 2023
1 parent 6bd37f0 commit e9bbac0
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions cardinal/system/system_player_spawner.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,14 @@ import (
// This provides an example of a system that creates a new entity.
func PlayerSpawnerSystem(world cardinal.WorldContext) error {
msg.CreatePlayer.Each(world, func(create cardinal.TxData[msg.CreatePlayerMsg]) (msg.CreatePlayerResult, error) {
id, err := cardinal.Create(world, comp.Player{}, comp.Health{})
id, err := cardinal.Create(world,
comp.Player{Nickname: create.Msg().Nickname},
comp.Health{HP: 100},
)
if err != nil {
return msg.CreatePlayerResult{}, fmt.Errorf("error creating player: %w", err)
}

err = cardinal.SetComponent[comp.Player](world, id, &comp.Player{Nickname: create.Msg().Nickname})
if err != nil {
return msg.CreatePlayerResult{}, fmt.Errorf("error setting player nickname: %w", err)
}

err = cardinal.SetComponent[comp.Health](world, id, &comp.Health{HP: 100})
if err != nil {
return msg.CreatePlayerResult{}, fmt.Errorf("error setting player health: %w", err)
}

world.EmitEvent(fmt.Sprintf("new player %d created", id))
return msg.CreatePlayerResult{Success: true}, nil
})
Expand Down

0 comments on commit e9bbac0

Please sign in to comment.