Repos / gorts / 49ba0eeae1
commit 49ba0eeae110fa8d1e12ab5705c9bc24b8f480e5
Author: Nhân <hi@imnhan.com>
Date:   Tue Jun 20 16:12:49 2023 +0700

    rename state to scoreboard

diff --git a/main.go b/main.go
index d3f6b51..bc583ac 100644
--- a/main.go
+++ b/main.go
@@ -22,7 +22,7 @@
 
 const WebPort = "1337"
 const WebDir = "web"
-const StateFile = WebDir + "/state.json"
+const ScoreboardFile = WebDir + "/state.json"
 const PlayersFile = "players.csv"
 
 //go:embed tcl/main.tcl
@@ -86,7 +86,7 @@ func startGUI() {
 	println("Loaded main tcl script.")
 
 	allplayers := players.FromFile(PlayersFile)
-	state := initState()
+	scoreboard := initScoreboard()
 	b64icon := base64.StdEncoding.EncodeToString(gortsPngIcon)
 
 	fmt.Fprintf(
@@ -113,31 +113,31 @@ func startGUI() {
 		req := scanner.Text()
 		println("--> " + req)
 		switch req {
-		case "readstate":
+		case "readscoreboard":
 			// TODO: there must be a more... civilized way.
-			respond(state.Description)
-			respond(state.Subtitle)
-			respond(state.P1name)
-			respond(state.P1country)
-			respond(strconv.Itoa(state.P1score))
-			respond(state.P1team)
-			respond(state.P2name)
-			respond(state.P2country)
-			respond(strconv.Itoa(state.P2score))
-			respond(state.P2team)
-
-		case "applystate":
-			state.Description = next()
-			state.Subtitle = next()
-			state.P1name = next()
-			state.P1country = next()
-			state.P1score, _ = strconv.Atoi(next())
-			state.P1team = next()
-			state.P2name = next()
-			state.P2country = next()
-			state.P2score, _ = strconv.Atoi(next())
-			state.P2team = next()
-			state.Write()
+			respond(scoreboard.Description)
+			respond(scoreboard.Subtitle)
+			respond(scoreboard.P1name)
+			respond(scoreboard.P1country)
+			respond(strconv.Itoa(scoreboard.P1score))
+			respond(scoreboard.P1team)
+			respond(scoreboard.P2name)
+			respond(scoreboard.P2country)
+			respond(strconv.Itoa(scoreboard.P2score))
+			respond(scoreboard.P2team)
+
+		case "applyscoreboard":
+			scoreboard.Description = next()
+			scoreboard.Subtitle = next()
+			scoreboard.P1name = next()
+			scoreboard.P1country = next()
+			scoreboard.P1score, _ = strconv.Atoi(next())
+			scoreboard.P1team = next()
+			scoreboard.P2name = next()
+			scoreboard.P2country = next()
+			scoreboard.P2score, _ = strconv.Atoi(next())
+			scoreboard.P2team = next()
+			scoreboard.Write()
 
 		case "readplayernames":
 			for _, player := range allplayers {
@@ -173,7 +173,7 @@ func startGUI() {
 	}
 }
 
-type State struct {
+type Scoreboard struct {
 	Description string `json:"description"`
 	Subtitle    string `json:"subtitle"`
 	P1name      string `json:"p1name"`
@@ -186,26 +186,26 @@ type State struct {
 	P2team      string `json:"p2team"`
 }
 
-func initState() State {
-	var state State
-	file, err := os.Open(StateFile)
+func initScoreboard() Scoreboard {
+	var scoreboard Scoreboard
+	file, err := os.Open(ScoreboardFile)
 	if err == nil {
 		defer file.Close()
 		bytes, err := ioutil.ReadAll(file)
 		if err != nil {
 			panic(err)
 		}
-		json.Unmarshal(bytes, &state)
+		json.Unmarshal(bytes, &scoreboard)
 	}
-	return state
+	return scoreboard
 }
 
-func (s *State) Write() {
+func (s *Scoreboard) Write() {
 	blob, err := json.MarshalIndent(s, "", "    ")
 	if err != nil {
 		panic(err)
 	}
-	err = ioutil.WriteFile(StateFile, blob, 0644)
+	err = ioutil.WriteFile(ScoreboardFile, blob, 0644)
 	if err != nil {
 		panic(err)
 	}
diff --git a/tcl/main.tcl b/tcl/main.tcl
index 8643a1e..8fbc506 100644
--- a/tcl/main.tcl
+++ b/tcl/main.tcl
@@ -81,8 +81,8 @@ ttk::button .c.players.p2win -text "▲ Win" -width 6 -command {incr scoreboard(
 ttk::label .c.players.p2teamlbl -text "Team 2"
 ttk::combobox .c.players.p2team -textvariable scoreboard(p2team)
 ttk::frame .c.buttons
-ttk::button .c.buttons.apply -text "▶ Apply" -command applystate
-ttk::button .c.buttons.discard -text "✖ Discard" -command discardstate
+ttk::button .c.buttons.apply -text "▶ Apply" -command applyscoreboard
+ttk::button .c.buttons.discard -text "✖ Discard" -command discardscoreboard
 ttk::button .c.buttons.reset -text "↶ Reset scores" -command {
     set scoreboard(p1score) 0
     set scoreboard(p2score) 0
@@ -138,7 +138,7 @@ grid columnconfigure .c.buttons 3 -pad 15
 proc initialize {b64icon webport countrycodes} {
     seticon $b64icon
     set ::mainstatus "Point your OBS browser source to http://localhost:${webport}"
-    readstate
+    readscoreboard
     setupdiffcheck
 
     .c.players.p1country configure -values $countrycodes
@@ -155,8 +155,8 @@ proc seticon {b64data} {
     wm iconphoto . -default applicationIcon
 }
 
-proc readstate {} {
-    puts "readstate"
+proc readscoreboard {} {
+    puts "readscoreboard"
     set ::scoreboard(description) [gets stdin]
     set ::scoreboard(subtitle) [gets stdin]
     set ::scoreboard(p1name) [gets stdin]
@@ -167,11 +167,11 @@ proc readstate {} {
     set ::scoreboard(p2country) [gets stdin]
     set ::scoreboard(p2score) [gets stdin]
     set ::scoreboard(p2team) [gets stdin]
-    update_applied_state
+    update_applied_scoreboard
 }
 
-proc applystate {} {
-    puts "applystate"
+proc applyscoreboard {} {
+    puts "applyscoreboard"
     puts $::scoreboard(description)
     puts $::scoreboard(subtitle)
     puts $::scoreboard(p1name)
@@ -182,7 +182,7 @@ proc applystate {} {
     puts $::scoreboard(p2country)
     puts $::scoreboard(p2score)
     puts $::scoreboard(p2team)
-    update_applied_state
+    update_applied_scoreboard
 }
 
 proc readplayernames {} {
@@ -222,13 +222,13 @@ proc searchplayers {query} {
     return $playernames
 }
 
-proc discardstate {} {
+proc discardscoreboard {} {
     foreach key [array names ::scoreboard] {
         set ::scoreboard($key) $::applied_scoreboard($key)
     }
 }
 
-proc update_applied_state {} {
+proc update_applied_scoreboard {} {
     foreach key [array names ::scoreboard] {
         set ::applied_scoreboard($key) $::scoreboard($key)
     }