diff options
| author | historia <[not public]> | 2026-06-26 02:52:31 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-06-26 02:52:31 -0400 |
| commit | 3102525d97aa6f1ad152c74b2ccfbd4b3a9b83f5 (patch) | |
| tree | 65610fa4fb8abe1dc7a46d00658e85e0525d397c /internal/net | |
| parent | e2d5b081f27141bb3dd89dbe595860b8a1345d55 (diff) | |
| download | thehouseoficarus-3102525d97aa6f1ad152c74b2ccfbd4b3a9b83f5.tar.gz | |
feat: simplified conversation trees and output won't overwrite prompts now
Diffstat (limited to 'internal/net')
| -rw-r--r-- | internal/net/server.go | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/internal/net/server.go b/internal/net/server.go index 9ae8532..731beef 100644 --- a/internal/net/server.go +++ b/internal/net/server.go @@ -32,6 +32,7 @@ const ( StateGame StateChangeDesc StateTalk + StateTalkSequence StateDropAllConfirm StateRecipeChoice StateHowMany @@ -61,6 +62,7 @@ type Session struct { Disconnecting bool DisconnectTicks int Shop *behavior.ShopConfig + promptVisible bool writeMu sync.Mutex } @@ -346,6 +348,10 @@ func (sess *Session) wrap(msg string) string { func (sess *Session) Write(msg string) { sess.writeMu.Lock() defer sess.writeMu.Unlock() + if sess.promptVisible { + sess.Conn.Write([]byte("\r\n")) + sess.promptVisible = false + } sess.Conn.Write([]byte(msg)) } @@ -353,13 +359,21 @@ func (sess *Session) WriteLine(msg string) { msg = sess.wrap(msg) sess.writeMu.Lock() defer sess.writeMu.Unlock() + if sess.promptVisible { + sess.Conn.Write([]byte("\r\n")) + sess.promptVisible = false + } sess.Conn.Write([]byte(msg + "\r\n")) } func (sess *Session) WriteLines(lines ...string) { sess.writeMu.Lock() defer sess.writeMu.Unlock() - for _, l := range lines { + for i, l := range lines { + if i == 0 && sess.promptVisible { + sess.Conn.Write([]byte("\r\n")) + sess.promptVisible = false + } sess.Conn.Write([]byte(sess.wrap(l) + "\r\n")) } } @@ -368,9 +382,30 @@ func (sess *Session) Writef(format string, args ...interface{}) { msg := sess.wrap(fmt.Sprintf(format, args...)) sess.writeMu.Lock() defer sess.writeMu.Unlock() + if sess.promptVisible { + sess.Conn.Write([]byte("\r\n")) + sess.promptVisible = false + } sess.Conn.Write([]byte(msg)) } +func (sess *Session) WritePrompt(prompt string) { + sess.writeMu.Lock() + defer sess.writeMu.Unlock() + if sess.promptVisible { + return + } + sess.Conn.Write([]byte(prompt)) + sess.promptVisible = true +} + +func (sess *Session) Reprompt(prompt string) { + sess.writeMu.Lock() + defer sess.writeMu.Unlock() + sess.Conn.Write([]byte(prompt)) + sess.promptVisible = true +} + func (sess *Session) Close() error { sess.writeMu.Lock() defer sess.writeMu.Unlock() |
