Decompose io.go End and status (refactor step 7)
End's --More-- handling moves into promptMore; status's redraw-skip check moves into statusUnchanged. io.go is complexity-clean. Behavior unchanged.
This commit is contained in:
71
game/io.go
71
game/io.go
@@ -58,29 +58,8 @@ func (m *MessageLine) End() int {
|
||||
m.Huh = m.buf.String()
|
||||
}
|
||||
|
||||
if m.Mpos != 0 {
|
||||
m.look(false)
|
||||
m.scr.Std.MvAddStr(0, m.Mpos, "--More--")
|
||||
m.scr.Refresh()
|
||||
|
||||
if !m.MsgEsc {
|
||||
m.waitForSpace()
|
||||
} else {
|
||||
for {
|
||||
ch := m.readChar()
|
||||
if ch == ' ' {
|
||||
break
|
||||
}
|
||||
|
||||
if ch == Escape {
|
||||
m.buf.Reset()
|
||||
m.Mpos = 0
|
||||
m.newpos = 0
|
||||
|
||||
return Escape
|
||||
}
|
||||
}
|
||||
}
|
||||
if m.Mpos != 0 && m.promptMore() == Escape {
|
||||
return Escape
|
||||
}
|
||||
// All messages should start with uppercase, except ones that start
|
||||
// with a pack addressing character
|
||||
@@ -101,6 +80,36 @@ func (m *MessageLine) End() int {
|
||||
return ^Escape
|
||||
}
|
||||
|
||||
// promptMore shows the --More-- prompt and waits for the reader to
|
||||
// acknowledge; Escape means the player bailed out (the Mpos block of
|
||||
// io.c endmsg).
|
||||
func (m *MessageLine) promptMore() int {
|
||||
m.look(false)
|
||||
m.scr.Std.MvAddStr(0, m.Mpos, "--More--")
|
||||
m.scr.Refresh()
|
||||
|
||||
if !m.MsgEsc {
|
||||
m.waitForSpace()
|
||||
|
||||
return ^Escape
|
||||
}
|
||||
|
||||
for {
|
||||
ch := m.readChar()
|
||||
if ch == ' ' {
|
||||
return ^Escape
|
||||
}
|
||||
|
||||
if ch == Escape {
|
||||
m.buf.Reset()
|
||||
m.Mpos = 0
|
||||
m.newpos = 0
|
||||
|
||||
return Escape
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// attach wires the message line to its display and input; NewGame and
|
||||
// Restore call it once the screen and game exist.
|
||||
func (m *MessageLine) attach(scr *Screen, look func(bool), readChar func() byte) {
|
||||
@@ -193,9 +202,7 @@ func (g *RogueGame) status() {
|
||||
temp = p.CurArmor.ArmorClass
|
||||
}
|
||||
|
||||
if s.init && s.hp == p.Stats.HP && s.exp == p.Stats.Exp &&
|
||||
s.pur == p.Purse && s.arm == temp && s.str == p.Stats.Str &&
|
||||
s.lvl == g.Depth && s.hungry == p.HungryState && !g.StatMsg {
|
||||
if g.statusUnchanged(temp) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -238,6 +245,18 @@ func (g *RogueGame) status() {
|
||||
g.move(oy, ox)
|
||||
}
|
||||
|
||||
// statusUnchanged reports whether the status line still shows current
|
||||
// values, so it need not be redrawn (the shadow-variable check of io.c
|
||||
// status). temp is the effective armor class.
|
||||
func (g *RogueGame) statusUnchanged(temp int) bool {
|
||||
s := &g.statusCache
|
||||
p := &g.Player
|
||||
|
||||
return s.init && s.hp == p.Stats.HP && s.exp == p.Stats.Exp &&
|
||||
s.pur == p.Purse && s.arm == temp && s.str == p.Stats.Str &&
|
||||
s.lvl == g.Depth && s.hungry == p.HungryState && !g.StatMsg
|
||||
}
|
||||
|
||||
// waitFor sits around until the guy types the right key (io.c wait_for).
|
||||
func (g *RogueGame) waitFor(ch byte) {
|
||||
if ch == '\n' {
|
||||
|
||||
Reference in New Issue
Block a user