diff --git a/README.md b/README.md index 554c63b..ba532a4 100644 --- a/README.md +++ b/README.md @@ -35,30 +35,33 @@ The player-facing command set is intentionally melee-focused. | `h` `j` `k` `l` | move west / south / north / east | | `.` | wait one turn | | arrows | move (or move the cursor in look/throw mode) | -| `f` + `h/j/k/l` | bash an adjacent small obstacle | +| `x` + `h/j/k/l` | bash an adjacent small obstacle | | `a` | use the Hands item / report the weapon ready | +| `b` | use the Head item | +| `c` `d` `e` `f` `g` | use Robe slots 1–5 | | `r` / `t` | use the first / second known Rite | -| `A` `H` `C` `D` `R` | drop Hands, Head, Robe 1–3 | -| `g` | get the item from the ground | -| `e` | equipment overlay | +| `p` | pick up the item from the ground | +| `i` | inventory / equipment screen | | `v` | view / look around | | `~` | expand/collapse latest messages | | `@` | character information | -| `O` | options | +| `o` | options | | `?` | help / key bindings | -| `S` | save and quit | +| `s` | save and quit | | `>` | use portal / stairs / elevator | | `]` or `F7` | jump directly to the next map | | `[` or `F8` | jump directly to the previous map | | `Space` | close a modal screen without taking an action | -| `Q` | quit | +| `q` or `z` | quit | Walking into a monster attacks it. Player and monster movement and attacks are cardinal only (`hjkl`); there are no diagonal attacks. Bashing is intentional: -use `f` and a direction. A bash takes a turn, and some containers such as +use `x` and a direction. A bash takes a turn, and some containers such as barrels or crates may drop supplies when smashed. -Screens generally close with `z`, `q`, `Space`, or `Esc`. The player is +On the inventory screen lowercase `a`–`g` use slots and uppercase `A`–`G` drop +them. Uppercase letters do nothing on the map. Screens generally close with +`i`, `z`, `q`, `Space`, or `Esc`. The player is defenceless without a melee weapon; there is no unarmed attack. Flask throwing is deferred for now. @@ -111,7 +114,7 @@ grants a second Rite is not implemented yet. * blood, corpses and limbs * Hands, Head and a permanently worn Robe with three starting slots * one-line HUD with HP/AP, the ready weapon and Rite charges; one-line message bar -* `~` expands the latest eight messages; `e` opens a non-scrolling equipment overlay +* `~` expands the latest eight messages; `i` opens the non-scrolling inventory/equipment overlay * one item maximum per ground tile; dropping onto an occupied tile is refused * experience is stored for now; player levels and skill points are removed * auto-opening doors, portals, bashing, acid/fire/smoke, rain diff --git a/internal/game/controls_test.go b/internal/game/controls_test.go index 5fdafe5..c1a67ae 100644 --- a/internal/game/controls_test.go +++ b/internal/game/controls_test.go @@ -33,14 +33,14 @@ func TestActiveBindingsUseNewKeys(t *testing.T) { for _, b := range ActiveKeyBindings { found[rune(b.Key)] = true } - for _, key := range []rune{'h', 'j', 'k', 'l', '.', 'e', 'v', '~', 'g', 'r', 'R'} { + for _, key := range []rune{'h', 'j', 'k', 'l', '.', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'i', 'p', 'r', 'v', '~'} { if !found[key] { t.Fatalf("active key bindings missing %q", key) } } - for _, key := range []rune{'1', '2', '3', '4', '5', '6', '7', '8', '9'} { + for _, key := range []rune{'1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G'} { if found[key] { - t.Fatalf("active key bindings still contain numpad key %q", key) + t.Fatalf("active key bindings still contain removed key %q", key) } } } @@ -208,3 +208,43 @@ func TestBarrelBashDropsLoot(t *testing.T) { t.Fatalf("missing bash loot message: %v", msgs) } } + +func TestSlotKeysAndUppercaseDrops(t *testing.T) { + want := map[rune]int{ + 'a': SlotHands, + 'b': SlotHead, + 'c': SlotRobe1, + 'd': SlotRobe2, + 'e': SlotRobe3, + 'f': SlotRobe4, + 'g': SlotRobe5, + } + for key, slot := range want { + got, ok := slotForKey(key) + if !ok || got != slot { + t.Fatalf("slotForKey(%q) = %d,%v, want %d,true", key, got, ok, slot) + } + } + + g := NewGame(7308) + g.SetupNewGame(0, "tester") + g.Items = nil + g.Critters = nil + g.State = StatePlaying + weapon := &Item{Proto: itemProtoByName("sickle"), X: -1, Y: -1} + g.Player.Slots.Hands = weapon + u := &UI{g: g} + u.handlePlaying(tcell.NewEventKey(tcell.KeyRune, 'A', tcell.ModNone)) + if g.Player.Slots.Hands != weapon { + t.Fatal("uppercase A dropped an item on the map") + } + + g.State = StateInventory + u.handleInventory(tcell.NewEventKey(tcell.KeyRune, 'A', tcell.ModNone)) + if g.Player.Slots.Hands != nil { + t.Fatal("uppercase A did not drop the Hands item in inventory") + } + if g.ItemAt(g.Player.X, g.Player.Y) == nil { + t.Fatal("dropped Hands item is not on the ground") + } +} diff --git a/internal/game/player_experience_test.go b/internal/game/player_experience_test.go index 911af28..5270c6d 100644 --- a/internal/game/player_experience_test.go +++ b/internal/game/player_experience_test.go @@ -236,7 +236,7 @@ func TestInventoryGetPicksUpItem(t *testing.T) { it := &Item{Proto: 48, X: g.Player.X, Y: g.Player.Y, Charges: 5} g.Items = append(g.Items, it) u := &UI{g: g} - u.handleInventory(tcell.NewEventKey(tcell.KeyRune, 'g', tcell.ModNone)) + u.handleInventory(tcell.NewEventKey(tcell.KeyRune, 'p', tcell.ModNone)) if g.ItemAt(g.Player.X, g.Player.Y) != nil { t.Fatal("item was not removed from the ground") } diff --git a/internal/game/scope.go b/internal/game/scope.go index 1bfe15b..d765087 100644 --- a/internal/game/scope.go +++ b/internal/game/scope.go @@ -114,28 +114,29 @@ var ActiveKeyBindings = []KeyBind{ {Key: 'k', Name: "move to north", Desc: "move player north"}, {Key: 'l', Name: "move to east", Desc: "move player east"}, {Key: '.', Name: "wait", Desc: "wait one turn"}, - {Key: 'f', Name: "bash", Desc: "choose a direction and bash an adjacent small obstacle"}, + {Key: 'x', Name: "bash", Desc: "choose a direction and bash an adjacent small obstacle"}, {Key: 'a', Name: "hands action", Desc: "use the Hands item (tool) or report the weapon ready"}, + {Key: 'b', Name: "head action", Desc: "wear or inspect the Head item"}, + {Key: 'c', Name: "robe slot 1", Desc: "use or consume robe slot 1"}, + {Key: 'd', Name: "robe slot 2", Desc: "use or consume robe slot 2"}, + {Key: 'e', Name: "robe slot 3", Desc: "use or consume robe slot 3"}, + {Key: 'f', Name: "robe slot 4", Desc: "use or consume robe slot 4"}, + {Key: 'g', Name: "robe slot 5", Desc: "use or consume robe slot 5"}, {Key: 'r', Name: "use rite", Desc: "use the first known rite"}, {Key: 't', Name: "use second rite", Desc: "use the second known rite"}, - {Key: 'A', Name: "drop hands", Desc: "drop the Hands item"}, - {Key: 'H', Name: "drop head", Desc: "drop the Head item"}, - {Key: 'C', Name: "drop robe 1", Desc: "drop robe slot 1"}, - {Key: 'D', Name: "drop robe 2", Desc: "drop robe slot 2"}, - {Key: 'R', Name: "drop robe 3", Desc: "drop robe slot 3"}, - {Key: 'g', Name: "get item", Desc: "pick up items from the current tile"}, - {Key: 'e', Name: "equipment", Desc: "display the equipment overlay"}, + {Key: 'p', Name: "pick up item", Desc: "pick up items from the current tile"}, + {Key: 'i', Name: "inventory", Desc: "display equipment; uppercase A-G drop slots"}, {Key: 'v', Name: "view / look", Desc: "look around and examine the surroundings"}, {Key: '~', Name: "message log", Desc: "expand or collapse the latest eight messages"}, {Key: '@', Name: "player screen", Desc: "display character information"}, - {Key: 'O', Name: "options", Desc: "display the options screen"}, + {Key: 'o', Name: "options", Desc: "display the options screen"}, {Key: '?', Name: "help", Desc: "display this key binding screen"}, {Key: ' ', Name: "close overlay", Desc: "close a modal screen without taking an action"}, - {Key: 'S', Name: "save and quit", Desc: "save the game and quit"}, + {Key: 's', Name: "save and quit", Desc: "save the game and quit"}, {Key: '>', Name: "use portal", Desc: "use a portal, stairs or elevator"}, {Key: ']', Name: "next map", Desc: "jump directly to the next map"}, {Key: '[', Name: "previous map", Desc: "jump directly to the previous map"}, - {Key: 'Q', Name: "quit", Desc: "quit the game"}, + {Key: 'q', Name: "quit", Desc: "quit the game"}, } // ActiveHints is the melee-focused hint list. The recovered hints that refer @@ -148,5 +149,5 @@ var ActiveHints = []string{ Hints[7], // acid ignores armor "you are defenceless without a weapon; keep a melee weapon equipped.", "grenades and molotovs can only be thrown at tiles within your sight range.", - "bash small obstacles with f and a direction; barrels and crates may hide supplies.", + "bash small obstacles with x and a direction; barrels and crates may hide supplies.", } diff --git a/internal/game/screens.go b/internal/game/screens.go index 3cfb3a3..018246e 100644 --- a/internal/game/screens.go +++ b/internal/game/screens.go @@ -48,21 +48,41 @@ func slotKey(slot int) string { case SlotHands: return "a" case SlotHead: - return "h" + return "b" case SlotRobe1: return "c" case SlotRobe2: return "d" case SlotRobe3: - return "r" + return "e" case SlotRobe4: - return "4" + return "f" case SlotRobe5: - return "5" + return "g" } return "-" } +func slotForKey(key rune) (int, bool) { + switch key { + case 'a': + return SlotHands, true + case 'b': + return SlotHead, true + case 'c': + return SlotRobe1, true + case 'd': + return SlotRobe2, true + case 'e': + return SlotRobe3, true + case 'f': + return SlotRobe4, true + case 'g': + return SlotRobe5, true + } + return 0, false +} + func itemSummary(it *Item) string { if it == nil { return "empty" @@ -127,18 +147,18 @@ func (u *UI) drawInventory() { y++ } - u.putStr(16, 10, "a use hands h head", 8, 0) - u.putStr(16, 11, "c/d/r use robe slot 1-3", 8, 0) - u.putStr(16, 12, "A/H/C/D/R drop slot", 8, 0) - u.putStr(16, 13, "j/k select enter use e/z/space close", 8, 0) + u.putStr(16, 10, "a hands b head c-g robe slots", 8, 0) + u.putStr(16, 11, "A-G drop the corresponding slot", 8, 0) + u.putStr(16, 12, "j/k select enter use p pick up", 8, 0) + u.putStr(16, 13, "i/z/q/space close", 8, 0) u.putStr(16, 14, g.RiteSummary(), 11, 0) ground := g.ItemAt(g.Player.X, g.Player.Y) - u.putStr(1, 17, "[ g ] item here: "+itemSummary(ground), 10, 0) + u.putStr(1, 17, "[ p ] item here: "+itemSummary(ground), 10, 0) u.fill(0, 22, screenW, 2, ' ', 8, 0) u.putStr(1, 22, "Robe slots hold vials, shards and small items; the robe cannot be removed.", 8, 0) - u.putStr(1, 23, "g get e/z/space close", 8, 0) + u.putStr(1, 23, "lowercase use uppercase drop p pick up i close", 8, 0) } func slotStats(it *Item) string { @@ -226,30 +246,21 @@ func (u *UI) handleInventory(e *tcell.EventKey) { u.slotSel = (u.slotSel + 1) % len(slots) case 'k': u.slotSel = (u.slotSel + len(slots) - 1) % len(slots) - case 'a': - g.UseSlot(SlotHands) - case 'h': - g.UseSlot(SlotHead) - case 'c': - g.UseSlot(SlotRobe1) - case 'd': - g.UseSlot(SlotRobe2) - case 'r': - g.UseSlot(SlotRobe3) - case 'A': - g.DropSlot(SlotHands) - case 'H': - g.DropSlot(SlotHead) - case 'C': - g.DropSlot(SlotRobe1) - case 'D': - g.DropSlot(SlotRobe2) - case 'R': - g.DropSlot(SlotRobe3) - case 'g': - g.PickUp() - case 'z', 'q', 'e', ' ': + case 'i', 'z', 'q', ' ': g.State = StatePlaying + case 'p': + g.PickUp() + default: + key := e.Rune() + if slot, ok := slotForKey(key); ok { + g.UseSlot(slot) + return + } + if key >= 'A' && key <= 'G' { + if slot, ok := slotForKey(key - 'A' + 'a'); ok { + g.DropSlot(slot) + } + } } } @@ -296,7 +307,7 @@ func (u *UI) drawPlayerScreen() { } u.fill(0, 22, screenW, 3, ' ', 8, 0) u.putStr(1, 23, "z/space quit screen", 8, 0) - u.putStr(1, 24, "e equipment", 8, 0) + u.putStr(1, 24, "i inventory", 8, 0) } func skillLevelName(v int) string { diff --git a/internal/game/ui.go b/internal/game/ui.go index b2cde48..a7f9d59 100644 --- a/internal/game/ui.go +++ b/internal/game/ui.go @@ -982,33 +982,25 @@ func (u *UI) handlePlaying(e *tcell.EventKey) { return } r := e.Rune() + if slot, ok := slotForKey(r); ok { + g.UseSlot(slot) + return + } switch r { case '.': g.WaitTurn() - case 'a': - g.UseSlot(SlotHands) case 'r': g.UseRite(0) case 't': g.UseRite(1) - case 'A': - g.DropSlot(SlotHands) - case 'H': - g.DropSlot(SlotHead) - case 'C': - g.DropSlot(SlotRobe1) - case 'D': - g.DropSlot(SlotRobe2) - case 'R': - g.DropSlot(SlotRobe3) - case 'g': + case 'p': g.PickUp() - case 'f': + case 'x': u.bashPending = true g.Msg("bash in which direction? (esc cancels)", 8) case '?': g.State = StateHelp - case 'e': + case 'i': g.State = StateInventory u.slotSel = 0 case 'v': @@ -1016,13 +1008,13 @@ func (u *UI) handlePlaying(e *tcell.EventKey) { g.LookX, g.LookY = g.Player.X, g.Player.Y case '~': u.msgExpanded = true - case 'O': + case 'o': g.State = StateOptions u.optSel = 0 u.optScroll = 0 case '@': g.State = StatePlayerScreen - case 'S': + case 's': g.SaveAndQuit() case '>': g.UsePortal() @@ -1030,11 +1022,7 @@ func (u *UI) handlePlaying(e *tcell.EventKey) { g.ChangeLevelRelative(1) case '[': g.ChangeLevelRelative(-1) - case 'Q': - g.State = StateQuitConfirm - case 'z': - g.State = StateQuitConfirm - case 'Z': + case 'q', 'z': g.State = StateQuitConfirm } if e.Key() == tcell.KeyEscape {