Repos / gorts / e43f7d0e88
commit e43f7d0e88d51db7ff267da3f82f77d527517ced
Author: Nhân <hi@imnhan.com>
Date:   Tue Jun 20 12:35:23 2023 +0700

    set available country codes

diff --git a/go.mod b/go.mod
index 11b8bbe..118e815 100644
--- a/go.mod
+++ b/go.mod
@@ -1,3 +1,5 @@
 module go.imnhan.com/gorts
 
 go 1.20
+
+require golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1
diff --git a/go.sum b/go.sum
new file mode 100644
index 0000000..001575f
--- /dev/null
+++ b/go.sum
@@ -0,0 +1,2 @@
+golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc=
+golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
diff --git a/main.go b/main.go
index 0ff2862..e079c2f 100644
--- a/main.go
+++ b/main.go
@@ -14,6 +14,9 @@
 	"os/exec"
 	"runtime"
 	"strconv"
+	"strings"
+
+	"go.imnhan.com/gorts/startgg"
 )
 
 const WebPort = "1337"
@@ -84,7 +87,11 @@ func startGUI() {
 
 	b64icon := base64.StdEncoding.EncodeToString(gortsPngIcon)
 
-	fmt.Fprintf(stdin, "initialize %s %s\n", b64icon, WebPort)
+	fmt.Fprintf(
+		stdin,
+		"initialize %s %s {%s}\n",
+		b64icon, WebPort, strings.Join(startgg.CountryCodes, " "),
+	)
 
 	scanner := bufio.NewScanner(stdout)
 
diff --git a/startgg/countries.go b/startgg/countries.go
index 5d1ed9e..51abdb8 100644
--- a/startgg/countries.go
+++ b/startgg/countries.go
@@ -1,10 +1,16 @@
 package startgg
 
+import (
+	"sort"
+
+	"golang.org/x/exp/maps"
+)
+
 // Startgg only shows (non-standard) country names (ongoing problem for years,
 // probably will never be fixed), so we need this mapping to convert these
 // names to alpha-2 codes.
 // From https://gist.github.com/morleym/a39c43f6544a350c109c5f7b0b055155
-var nameToCode = map[string]string{
+var countryNameToCode = map[string]string{
 	"Bangladesh":                         "bd",
 	"Belgium":                            "be",
 	"Burkina Faso":                       "bf",
@@ -260,3 +266,9 @@
 	"Wales":                                "gb-wls",
 	"Scotland":                             "gb-sct",
 }
+
+var CountryCodes []string = maps.Values(countryNameToCode)
+
+func init() {
+	sort.Strings(CountryCodes)
+}
diff --git a/tcl/main.tcl b/tcl/main.tcl
index 184f97a..2be2888 100644
--- a/tcl/main.tcl
+++ b/tcl/main.tcl
@@ -135,11 +135,14 @@ grid columnconfigure .c.buttons 3 -pad 15
 # The following procs constitute a very simple line-based IPC system where Tcl
 # client talks to Go server via stdin/stdout.
 
-proc initialize {b64icon webport} {
+proc initialize {b64icon webport countrycodes} {
     seticon $b64icon
     set ::mainstatus "Point your OBS browser source to http://localhost:${webport}"
     readstate
     setupdiffcheck
+
+    .c.players.p1country configure -values $countrycodes
+    .c.players.p2country configure -values $countrycodes
 }
 
 proc seticon {b64data} {