diff --git a/internal/app/inventory.go b/internal/app/inventory.go index 66f6460..464587a 100644 --- a/internal/app/inventory.go +++ b/internal/app/inventory.go @@ -19,6 +19,15 @@ type inventoryView struct { } func (v *inventoryView) handleEvent(e tcell.Event) change { + if k, ok := e.(*tcell.EventKey); ok { + if k.Key() == tcell.KeyESC { + return changeFn(func(ui *UI) { + if ui.root == inGameView { + inGameView.focus(0) + } + }) + } + } return nil } diff --git a/internal/sim/player.go b/internal/sim/player.go index a5e4169..bf34c7a 100644 --- a/internal/sim/player.go +++ b/internal/sim/player.go @@ -13,19 +13,22 @@ import ( type player struct { *blammo.Log - name string - outbox chan wire.Response - pending *Request - avatar *entity - stop chan bool - fullSync bool + name string + outbox chan wire.Response + pending *Request + avatar *entity + inventory []*entity + stop chan bool + fullSync bool } func (p *player) start(c chan Request, conn *websocket.Conn, r *room) { welcome := wire.Welcome{ - Rooms: make(map[string]wire.Room), - Players: make(map[string]wire.Player), + Rooms: make(map[string]wire.Room), + Players: make(map[string]wire.Player), + Inventory: make([]wire.Entity, 0), } + p.inventory = make([]*entity, 0, 16) ents := make(map[int]wire.Entity) for id, e := range r.allEntities() { ents[id] = wire.Entity{ @@ -262,6 +265,7 @@ func (pu *Pickup) exec(w *world, r *room, pl *player, seq int) result { return result{reply: wire.Errorf("the %s cannot be picked up", e.name)} } nextTile.here = nextTile.here[0:0] + pl.inventory = append(pl.inventory, e) return result{reply: Pickedup{Name: e.name}} } return result{reply: wire.Errorf("nothing here")} diff --git a/internal/wire/welcome.go b/internal/wire/welcome.go index 02ee6e9..24dd840 100644 --- a/internal/wire/welcome.go +++ b/internal/wire/welcome.go @@ -1,8 +1,9 @@ package wire type Welcome struct { - Rooms map[string]Room `json:"rooms"` - Players map[string]Player `json:"players"` + Rooms map[string]Room `json:"rooms"` + Players map[string]Player `json:"players"` + Inventory []Entity `json:"inventory"` } func (Welcome) NetTag() string { return "welcome" }