diff --git a/internal/app/game_view.go b/internal/app/game_view.go index e1eba8e..ab43b74 100644 --- a/internal/app/game_view.go +++ b/internal/app/game_view.go @@ -6,6 +6,7 @@ import ( "github.com/gdamore/tcell/v2" "github.com/jordanorelli/astro-domu/internal/math" "github.com/jordanorelli/astro-domu/internal/sim" + "github.com/jordanorelli/astro-domu/internal/wire" "github.com/jordanorelli/blammo" ) @@ -225,19 +226,24 @@ func (p pickup) exec(ui *UI) { go func() { res, err := ui.client.Send(sim.Pickup{p.x, p.y}) if err != nil { - ui.Error("look error: %v", err) - return - } - - pickedup, ok := res.Body.(*sim.Pickedup) - if !ok { - ui.Error("pickup response is not pickedup: %v", res.Body) + ui.state.detail = textView(err.Error()) return } - ui.misc <- func(ui *UI) { - ui.state.detail = textView(fmt.Sprintf("you picked up: %s", pickedup.Name)) - ui.state.inventory.items = append(ui.state.inventory.items, item{name: pickedup.Name}) + switch v := res.Body.(type) { + case *sim.Pickedup: + ui.misc <- func(ui *UI) { + ui.state.detail = textView(fmt.Sprintf("you picked up: %s", v.Name)) + ui.state.inventory.items = append(ui.state.inventory.items, item{name: v.Name}) + } + case wire.Error: + ui.misc <- func(ui *UI) { + ui.state.detail = textView(v.Error()) + } + default: + ui.misc <- func(ui *UI) { + ui.state.detail = textView(fmt.Sprintf("unexpected pickup response type: %T", res.Body)) + } } }() } diff --git a/internal/sim/entity.go b/internal/sim/entity.go index 16a22c8..1faa833 100644 --- a/internal/sim/entity.go +++ b/internal/sim/entity.go @@ -14,6 +14,7 @@ type entity struct { description string solid bool `json:"-"` overlapped map[int]*entity + pickupable bool behavior } diff --git a/internal/sim/player.go b/internal/sim/player.go index 11979ea..a5e4169 100644 --- a/internal/sim/player.go +++ b/internal/sim/player.go @@ -258,6 +258,9 @@ func (pu *Pickup) exec(w *world, r *room, pl *player, seq int) result { nextTile := r.getTile(target) if len(nextTile.here) == 1 { e := nextTile.here[0] + if !e.pickupable { + return result{reply: wire.Errorf("the %s cannot be picked up", e.name)} + } nextTile.here = nextTile.here[0:0] return result{reply: Pickedup{Name: e.name}} } diff --git a/internal/sim/world.go b/internal/sim/world.go index ab33dd6..5dc4cc8 100644 --- a/internal/sim/world.go +++ b/internal/sim/world.go @@ -40,28 +40,15 @@ func newWorld(log *blammo.Log) *world { } foyer.addEntity(&entity{ - ID: -1, - Position: math.Vec{5, 4}, - Glyph: 'o', - solid: true, - name: "a rock", - behavior: doNothing{}, + ID: -1, + Position: math.Vec{5, 4}, + Glyph: 'o', + solid: true, + pickupable: true, + name: "a rock", + behavior: doNothing{}, }) - // foyer.addEntity(&entity{ - // ID: -2, - // Position: math.Vec{9, 0}, - // Glyph: '+', - // behavior: doNothing{}, - // }) - - // foyer.addEntity(&entity{ - // ID: -3, - // Position: math.Vec{9, 1}, - // Glyph: '-', - // behavior: doNothing{}, - // }) - foyer.addEntity(&entity{ ID: -4, Position: math.Vec{9, 5},