|
@@ -16,7 +16,7 @@ import (
|
|
|
|
|
|
var Config map[string]string
|
|
|
|
|
|
-func press_a_key(d *door.Door) int {
|
|
|
+func press_a_key(d *door.Door) rune {
|
|
|
green := door.ColorText("BOLD GREEN")
|
|
|
blue := door.ColorText("BOLD BLUE")
|
|
|
yellow := door.ColorText("BOLD YELLOW")
|
|
@@ -50,7 +50,9 @@ func press_a_key(d *door.Door) int {
|
|
|
|
|
|
d.Write(door.Reset + any_color(text))
|
|
|
|
|
|
- var r int = -1
|
|
|
+ var r rune
|
|
|
+ var ex door.Extended
|
|
|
+ var err error
|
|
|
var t int
|
|
|
sleep_ms := 250
|
|
|
ms_sleep := 0
|
|
@@ -61,9 +63,9 @@ func press_a_key(d *door.Door) int {
|
|
|
current_word := text[words[word][0]:words[word][1]]
|
|
|
t = 0
|
|
|
|
|
|
- r = d.WaitKey(0, int64(sleep_ms)*1000)
|
|
|
+ r, ex, err = d.WaitKey(time.Duration(sleep_ms) * time.Millisecond) // 0, int64(sleep_ms)*1000)
|
|
|
|
|
|
- for r == -1 {
|
|
|
+ for err == door.ErrTimeout && ex == door.NOP { // r == -1 {
|
|
|
ms_sleep += sleep_ms
|
|
|
|
|
|
if ms_sleep > 1000 {
|
|
@@ -122,7 +124,7 @@ func press_a_key(d *door.Door) int {
|
|
|
d.Write(any_color(string(work_text)))
|
|
|
|
|
|
READKEY:
|
|
|
- r = d.WaitKey(0, int64(sleep_ms)*1000)
|
|
|
+ r, ex, err = d.WaitKey(time.Duration(sleep_ms) * time.Millisecond) // 0, int64(sleep_ms)*1000)
|
|
|
}
|
|
|
|
|
|
d.Write(strings.Repeat("\b", len(text)))
|
|
@@ -356,6 +358,98 @@ func About() door.Panel {
|
|
|
return about
|
|
|
}
|
|
|
|
|
|
+func MakeScoresRender(dateColor string, datelen int, nickColor string, nicklen int, scoreColor string) func(string) string {
|
|
|
+ renderF := func(text string) string {
|
|
|
+ var r door.Render = door.Render{Line: text}
|
|
|
+ r.Append(dateColor, datelen)
|
|
|
+ r.Append(nickColor, nicklen)
|
|
|
+ r.Append(scoreColor, len(text)-(datelen+nicklen))
|
|
|
+ return r.Result
|
|
|
+ }
|
|
|
+ return renderF
|
|
|
+}
|
|
|
+
|
|
|
+func DisplayScores(Door *door.Door, db *DBData, config *map[string]string) {
|
|
|
+ // Scores::score()
|
|
|
+
|
|
|
+ // make_top_scores_panel()
|
|
|
+ W := 38
|
|
|
+ var top_scores_panel door.Panel = door.Panel{Width: W,
|
|
|
+ Style: door.DOUBLE,
|
|
|
+ BorderColor: door.ColorText("CYAN ON BLUE"),
|
|
|
+ Title: "[ The TOP Monthly Scores: ]",
|
|
|
+ }
|
|
|
+
|
|
|
+ const nick_len int = 17 // Max Nick Length
|
|
|
+
|
|
|
+ var date_monthly string
|
|
|
+ var ok bool
|
|
|
+ date_monthly, ok = (*config)["date_monthly"]
|
|
|
+
|
|
|
+ if !ok {
|
|
|
+ date_monthly = "January"
|
|
|
+ }
|
|
|
+ var longest_month int = len(FormatDate(1631280600, date_monthly))
|
|
|
+
|
|
|
+ monthly := db.GetMonthlyScores(15)
|
|
|
+ if len(monthly) == 0 {
|
|
|
+ top_scores_panel.Lines = append(top_scores_panel.Lines,
|
|
|
+ door.Line{Text: fmt.Sprintf("%*s", -W, "No, Not Yet!"),
|
|
|
+ DefaultColor: door.ColorText("BRI YELLOW ON BLUE"),
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ ScoresRender := MakeScoresRender(door.ColorText("BOLD WHITE ON BLUE"),
|
|
|
+ longest_month,
|
|
|
+ door.ColorText("CYAN ON BLUE"),
|
|
|
+ nick_len,
|
|
|
+ door.ColorText("BOLD CYAN ON BLUE"))
|
|
|
+ YourScoresRender := MakeScoresRender(
|
|
|
+ door.ColorText("BOLD WHITE ON BLUE"),
|
|
|
+ longest_month,
|
|
|
+ door.ColorText("BOLD GREEN ON BLUE"),
|
|
|
+ nick_len,
|
|
|
+ door.ColorText("BOLD YELLOW ON BLUE"))
|
|
|
+
|
|
|
+ for idx := range monthly {
|
|
|
+ var result string = fmt.Sprintf("%*s", -longest_month,
|
|
|
+ FormatDate(monthly[idx].Date, date_monthly))
|
|
|
+ result += " " + fmt.Sprintf("%*s", -(nick_len-1), monthly[idx].User)
|
|
|
+ result += fmt.Sprintf(" %d", monthly[idx].Score)
|
|
|
+ result += strings.Repeat(" ", W-len(result))
|
|
|
+ if monthly[idx].User == Door.Config.Real_name || monthly[idx].User == Door.Config.Handle {
|
|
|
+ top_scores_panel.Lines = append(top_scores_panel.Lines,
|
|
|
+ door.Line{Text: result, RenderF: YourScoresRender})
|
|
|
+ } else {
|
|
|
+ top_scores_panel.Lines = append(top_scores_panel.Lines,
|
|
|
+ door.Line{Text: result, RenderF: ScoresRender})
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ // end make_top_scores_panel
|
|
|
+
|
|
|
+ // make_top_this_month_panel()
|
|
|
+ W = 38
|
|
|
+ var title string = fmt.Sprintf("[ The TOP Scores for %s: ]",
|
|
|
+ FormatDate(time.Now().Unix(), date_monthly))
|
|
|
+ var top_month_panel door.Panel = door.Panel{Width: W,
|
|
|
+ Style: door.DOUBLE,
|
|
|
+ BorderColor: door.ColorText(""),
|
|
|
+ Title: fmt.Sprintf("%*s", -W, title),
|
|
|
+ }
|
|
|
+ scores := db.GetScores(15)
|
|
|
+ if len(scores) == 0 {
|
|
|
+ top_month_panel.Lines = append(top_month_panel.Lines,
|
|
|
+ door.Line{Text: fmt.Sprintf("%*s", -W, "No, Not Yet!"),
|
|
|
+ DefaultColor: door.ColorText("BRI YELLOW ON BLUE"),
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
+ // Scores.display_scores()
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
func main() {
|
|
|
var message string
|
|
|
|
|
@@ -371,6 +465,7 @@ func main() {
|
|
|
|
|
|
d := door.Door{}
|
|
|
d.Init("space-ace")
|
|
|
+ defer d.Close()
|
|
|
|
|
|
db := DBData{}
|
|
|
db.Open("space-database.db")
|
|
@@ -481,6 +576,8 @@ func main() {
|
|
|
|
|
|
case 'S':
|
|
|
// View Scores
|
|
|
+ DisplayScores(&d, &db, &Config)
|
|
|
+ press_a_key(&d)
|
|
|
case 'C':
|
|
|
// Configure
|
|
|
Configure(&d, &db)
|