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 {
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
}

@ -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")}

@ -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" }

Loading…
Cancel
Save