Decompose command.go; command keys become a handler table (step 7)
The ordinary command keys move into gameData.commandHandlers (method expressions and small literals); dispatchKey keeps only re-dispatching prefixes (runCommand/fightCommand/repeatCommand/moveOnCommand) and the wizard fallthrough. command() splits into playTurn/turnUpkeep/ readCommand/executeCommand/countPrefix/ringTurnEffects; search gains searchSpot/searchFloor; help gains helpOne/helpAll/helpLines; call gains callTarget/callPrelude; wizardCommand splits in two plus wizardKit; uLevel and current flatten to early returns. command.go is complexity-clean. Behavior and RNG call order unchanged.
This commit is contained in:
1114
game/command.go
1114
game/command.go
File diff suppressed because it is too large
Load Diff
139
game/tables.go
139
game/tables.go
@@ -142,6 +142,11 @@ type gameData struct {
|
||||
// lands, indexed by monster letter - 'A': the cases of the fight.c
|
||||
// attack switch. A true return means the monster removed itself.
|
||||
hitHandlers [26]func(g *RogueGame, mp *Monster, mname string) bool
|
||||
|
||||
// commandHandlers dispatches the ordinary command keys: the simple
|
||||
// cases of the big command.c switch. Keys that re-dispatch (runs,
|
||||
// fight, repeat, move-on) and wizard keys stay in dispatchKey.
|
||||
commandHandlers map[byte]func(g *RogueGame)
|
||||
}
|
||||
|
||||
// ripWall is the repeated blank wall line of the tombstone art.
|
||||
@@ -672,6 +677,140 @@ func newGameData() *gameData {
|
||||
'V' - 'A': (*RogueGame).hitLifeDrainer,
|
||||
'W' - 'A': (*RogueGame).hitLifeDrainer,
|
||||
},
|
||||
|
||||
commandHandlers: map[byte]func(*RogueGame){
|
||||
',': (*RogueGame).pickupCommand,
|
||||
'!': (*RogueGame).shell,
|
||||
'h': func(g *RogueGame) { g.moveHero(0, -1) },
|
||||
'j': func(g *RogueGame) { g.moveHero(1, 0) },
|
||||
'k': func(g *RogueGame) { g.moveHero(-1, 0) },
|
||||
'l': func(g *RogueGame) { g.moveHero(0, 1) },
|
||||
'y': func(g *RogueGame) { g.moveHero(-1, -1) },
|
||||
'u': func(g *RogueGame) { g.moveHero(-1, 1) },
|
||||
'b': func(g *RogueGame) { g.moveHero(1, -1) },
|
||||
'n': func(g *RogueGame) { g.moveHero(1, 1) },
|
||||
'H': func(g *RogueGame) { g.startRun('h') },
|
||||
'J': func(g *RogueGame) { g.startRun('j') },
|
||||
'K': func(g *RogueGame) { g.startRun('k') },
|
||||
'L': func(g *RogueGame) { g.startRun('l') },
|
||||
'Y': func(g *RogueGame) { g.startRun('y') },
|
||||
'U': func(g *RogueGame) { g.startRun('u') },
|
||||
'B': func(g *RogueGame) { g.startRun('b') },
|
||||
'N': func(g *RogueGame) { g.startRun('n') },
|
||||
't': func(g *RogueGame) {
|
||||
if !g.promptDirection() {
|
||||
g.After = false
|
||||
} else {
|
||||
g.missile(g.Delta.Y, g.Delta.X)
|
||||
}
|
||||
},
|
||||
'q': (*RogueGame).quaff,
|
||||
'Q': func(g *RogueGame) {
|
||||
g.After = false
|
||||
g.QComm = true
|
||||
g.quit(0)
|
||||
g.QComm = false
|
||||
},
|
||||
'i': func(g *RogueGame) {
|
||||
g.After = false
|
||||
g.inventory(g.Player.Pack, 0)
|
||||
},
|
||||
'I': func(g *RogueGame) {
|
||||
g.After = false
|
||||
g.pickyInven()
|
||||
},
|
||||
'd': (*RogueGame).dropIt,
|
||||
'r': (*RogueGame).readScroll,
|
||||
'e': (*RogueGame).eat,
|
||||
'w': (*RogueGame).wield,
|
||||
'W': (*RogueGame).wear,
|
||||
'T': (*RogueGame).takeOff,
|
||||
'P': (*RogueGame).ringOn,
|
||||
'R': (*RogueGame).ringOff,
|
||||
'o': func(g *RogueGame) {
|
||||
g.option()
|
||||
g.After = false
|
||||
},
|
||||
'c': func(g *RogueGame) {
|
||||
g.call()
|
||||
g.After = false
|
||||
},
|
||||
'>': func(g *RogueGame) {
|
||||
g.After = false
|
||||
g.dLevel()
|
||||
},
|
||||
'<': func(g *RogueGame) {
|
||||
g.After = false
|
||||
g.uLevel()
|
||||
},
|
||||
'?': func(g *RogueGame) {
|
||||
g.After = false
|
||||
g.help()
|
||||
},
|
||||
'/': func(g *RogueGame) {
|
||||
g.After = false
|
||||
g.identify()
|
||||
},
|
||||
's': (*RogueGame).search,
|
||||
'z': func(g *RogueGame) {
|
||||
if g.promptDirection() {
|
||||
g.doZap()
|
||||
} else {
|
||||
g.After = false
|
||||
}
|
||||
},
|
||||
'D': func(g *RogueGame) {
|
||||
g.After = false
|
||||
g.discovered()
|
||||
},
|
||||
CTRL('P'): func(g *RogueGame) {
|
||||
g.After = false
|
||||
g.msg("%s", g.Msgs.Huh)
|
||||
},
|
||||
CTRL('R'): func(g *RogueGame) {
|
||||
g.After = false
|
||||
g.refresh()
|
||||
},
|
||||
'v': func(g *RogueGame) {
|
||||
g.After = false
|
||||
g.msg("version %s. (mctesq was here)", Release)
|
||||
},
|
||||
'S': func(g *RogueGame) {
|
||||
g.After = false
|
||||
g.saveGame()
|
||||
},
|
||||
'.': func(*RogueGame) {
|
||||
// rest command
|
||||
},
|
||||
' ': func(g *RogueGame) {
|
||||
g.After = false // "legal" illegal command
|
||||
},
|
||||
'^': (*RogueGame).identifyTrapCommand,
|
||||
Escape: func(g *RogueGame) {
|
||||
g.DoorStop = false
|
||||
g.Count = 0
|
||||
g.After = false
|
||||
g.Again = false
|
||||
},
|
||||
')': func(g *RogueGame) {
|
||||
g.current(g.Player.CurWeapon, "wielding", "")
|
||||
},
|
||||
']': func(g *RogueGame) {
|
||||
g.current(g.Player.CurArmor, "wearing", "")
|
||||
},
|
||||
'=': func(g *RogueGame) {
|
||||
g.current(g.Player.CurRing[Left], "wearing",
|
||||
g.chooseTerse("(L)", "on left hand"))
|
||||
g.current(g.Player.CurRing[Right], "wearing",
|
||||
g.chooseTerse("(R)", "on right hand"))
|
||||
},
|
||||
'@': func(g *RogueGame) {
|
||||
g.StatMsg = true
|
||||
g.status()
|
||||
g.StatMsg = false
|
||||
g.After = false
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user