gas-station-sim/system/newemployee.go

60 lines
1.4 KiB
Go

package system
import (
"code.rocketnine.space/tslocum/gas-station-sim/asset"
"code.rocketnine.space/tslocum/gas-station-sim/world"
"code.rocketnine.space/tslocum/gohan"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
)
type NewEmployee struct {
confirmTicks int
keys []ebiten.Key
}
func (r *NewEmployee) Update(_ gohan.Entity) error {
if !world.GameStarted {
return nil
}
if r.confirmTicks != 0 {
r.confirmTicks--
if r.confirmTicks == world.TPS*2.25 {
asset.SoundHelloAndWelcome.Play()
} else if r.confirmTicks == 0 {
world.Name = world.NameInput
world.NameInput = ""
}
return nil
}
if world.Name == "" {
if inpututil.IsKeyJustPressed(ebiten.KeyEnter) || inpututil.IsKeyJustPressed(ebiten.KeyKPEnter) {
r.confirmTicks = world.TPS * 2.75
return nil
}
if inpututil.IsKeyJustPressed(ebiten.KeyBackspace) && len(world.NameInput) > 0 {
world.NameInput = world.NameInput[:len(world.NameInput)-1]
}
r.keys = inpututil.AppendPressedKeys(r.keys[:0])
for _, key := range r.keys {
if key >= ebiten.KeyA && key <= ebiten.KeyZ && inpututil.IsKeyJustPressed(key) {
char := 'a'
if ebiten.IsKeyPressed(ebiten.KeyShift) {
char = 'A'
}
world.NameInput += string(char + rune(key))
}
}
}
return nil
}
func (r *NewEmployee) Draw(_ gohan.Entity, screen *ebiten.Image) error {
return nil
}