inventory improvements

master
Jordan Orelli 4 years ago
parent 84a92c28f5
commit 505e4952f0

@ -19,6 +19,15 @@ type inventoryView struct {
} }
func (v *inventoryView) handleEvent(e tcell.Event) change { 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 return nil
} }

@ -17,6 +17,7 @@ type player struct {
outbox chan wire.Response outbox chan wire.Response
pending *Request pending *Request
avatar *entity avatar *entity
inventory []*entity
stop chan bool stop chan bool
fullSync bool fullSync bool
} }
@ -25,7 +26,9 @@ func (p *player) start(c chan Request, conn *websocket.Conn, r *room) {
welcome := wire.Welcome{ welcome := wire.Welcome{
Rooms: make(map[string]wire.Room), Rooms: make(map[string]wire.Room),
Players: make(map[string]wire.Player), Players: make(map[string]wire.Player),
Inventory: make([]wire.Entity, 0),
} }
p.inventory = make([]*entity, 0, 16)
ents := make(map[int]wire.Entity) ents := make(map[int]wire.Entity)
for id, e := range r.allEntities() { for id, e := range r.allEntities() {
ents[id] = wire.Entity{ 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)} return result{reply: wire.Errorf("the %s cannot be picked up", e.name)}
} }
nextTile.here = nextTile.here[0:0] nextTile.here = nextTile.here[0:0]
pl.inventory = append(pl.inventory, e)
return result{reply: Pickedup{Name: e.name}} return result{reply: Pickedup{Name: e.name}}
} }
return result{reply: wire.Errorf("nothing here")} return result{reply: wire.Errorf("nothing here")}

@ -3,6 +3,7 @@ package wire
type Welcome struct { type Welcome struct {
Rooms map[string]Room `json:"rooms"` Rooms map[string]Room `json:"rooms"`
Players map[string]Player `json:"players"` Players map[string]Player `json:"players"`
Inventory []Entity `json:"inventory"`
} }
func (Welcome) NetTag() string { return "welcome" } func (Welcome) NetTag() string { return "welcome" }

Loading…
Cancel
Save