summaryrefslogtreecommitdiff
path: root/sw-ui/src
diff options
context:
space:
mode:
authorjoffrey-bion <joffrey.bion@gmail.com>2021-02-09 20:23:22 +0100
committerjoffrey-bion <joffrey.bion@gmail.com>2021-02-09 20:23:22 +0100
commitafe7e429d69051b9b173f2090ca56c17b833388f (patch)
tree7237b4e51e6136aca9fb5bb072bf51b89e36d4a4 /sw-ui/src
parentImprove "join" tooltip for FINISHED games (diff)
downloadseven-wonders-afe7e429d69051b9b173f2090ca56c17b833388f.tar.gz
seven-wonders-afe7e429d69051b9b173f2090ca56c17b833388f.tar.bz2
seven-wonders-afe7e429d69051b9b173f2090ca56c17b833388f.zip
Add random username generation
Resolves: https://github.com/joffrey-bion/seven-wonders/issues/95
Diffstat (limited to 'sw-ui/src')
-rw-r--r--sw-ui/src/main/kotlin/com/palantir/blueprintjs/blueprintjsHelpers.kt2
-rw-r--r--sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/home/ChooseNameForm.kt47
-rw-r--r--sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/home/RandomNameGenerator.kt488
3 files changed, 527 insertions, 10 deletions
diff --git a/sw-ui/src/main/kotlin/com/palantir/blueprintjs/blueprintjsHelpers.kt b/sw-ui/src/main/kotlin/com/palantir/blueprintjs/blueprintjsHelpers.kt
index 347e2170..a134ac8c 100644
--- a/sw-ui/src/main/kotlin/com/palantir/blueprintjs/blueprintjsHelpers.kt
+++ b/sw-ui/src/main/kotlin/com/palantir/blueprintjs/blueprintjsHelpers.kt
@@ -72,12 +72,14 @@ fun RBuilder.bpInputGroup(
large: Boolean = false,
placeholder: String = "",
rightElement: ReactElement? = null,
+ value: String? = null,
onChange: (Event) -> Unit,
): ReactElement = child(InputGroup::class) {
attrs {
this.large = large
this.placeholder = placeholder
this.rightElement = rightElement
+ this.value = value
this.onChange = onChange
}
}
diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/home/ChooseNameForm.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/home/ChooseNameForm.kt
index a63fef08..2ebabcc9 100644
--- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/home/ChooseNameForm.kt
+++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/home/ChooseNameForm.kt
@@ -3,19 +3,16 @@ package org.luxons.sevenwonders.ui.components.home
import com.palantir.blueprintjs.Intent
import com.palantir.blueprintjs.bpButton
import com.palantir.blueprintjs.bpInputGroup
+import kotlinx.css.*
import kotlinx.html.js.onSubmitFunction
import org.luxons.sevenwonders.ui.redux.RequestChooseName
import org.luxons.sevenwonders.ui.redux.connectDispatch
import org.w3c.dom.HTMLInputElement
import org.w3c.dom.events.Event
-import react.RBuilder
-import react.RClass
-import react.RComponent
-import react.RProps
-import react.RState
-import react.ReactElement
-import react.buildElement
-import react.dom.*
+import react.*
+import styled.css
+import styled.styledDiv
+import styled.styledForm
private interface ChooseNameFormProps : RProps {
var chooseUsername: (String) -> Unit
@@ -30,15 +27,22 @@ private class ChooseNameForm(props: ChooseNameFormProps) : RComponent<ChooseName
}
override fun RBuilder.render() {
- form {
+ styledForm {
+ css {
+ display = Display.flex
+ flexDirection = FlexDirection.row
+ }
attrs.onSubmitFunction = { e -> chooseUsername(e) }
+ randomNameButton()
+ spacer()
bpInputGroup(
large = true,
placeholder = "Username",
rightElement = submitButton(),
+ value = state.username,
onChange = { e ->
val input = e.currentTarget as HTMLInputElement
- setState(transformState = { ChooseNameFormState(input.value) })
+ setState(transformState = { ChooseNameFormState(username = input.value) })
},
)
}
@@ -53,10 +57,33 @@ private class ChooseNameForm(props: ChooseNameFormProps) : RComponent<ChooseName
)
}
+ private fun RBuilder.randomNameButton() {
+ bpButton(
+ title = "Generate random name",
+ large = true,
+ icon = "random",
+ intent = Intent.PRIMARY,
+ onClick = { e -> fillRandomUsername() },
+ )
+ }
+
+ private fun fillRandomUsername() {
+ setState(ChooseNameFormState(username = randomGreekName()))
+ }
+
private fun chooseUsername(e: Event) {
e.preventDefault()
props.chooseUsername(state.username)
}
+
+ // TODO this is so bad I'm dying inside
+ private fun RBuilder.spacer() {
+ styledDiv {
+ css {
+ margin(2.px)
+ }
+ }
+ }
}
val chooseNameForm: RClass<RProps> = connectDispatch(ChooseNameForm::class) { dispatch, _ ->
diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/home/RandomNameGenerator.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/home/RandomNameGenerator.kt
new file mode 100644
index 00000000..2394fa20
--- /dev/null
+++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/home/RandomNameGenerator.kt
@@ -0,0 +1,488 @@
+package org.luxons.sevenwonders.ui.components.home
+
+import kotlin.random.Random
+
+internal fun randomGreekName(): String {
+ val randName = prefixes.random() + suffixes.random()
+ return if (Random.nextBoolean()) randName else "$randName of ${cities.random()}"
+}
+
+private val prefixes =
+ listOf(
+ "Aba",
+ "Abde",
+ "Abre",
+ "Aby",
+ "Aca",
+ "Acle",
+ "Acri",
+ "Acro",
+ "Adme",
+ "Adra",
+ "Aea",
+ "Aegi",
+ "Aei",
+ "Aeo",
+ "Aese",
+ "Aeto",
+ "Aga",
+ "Age",
+ "Agi",
+ "Agri",
+ "Aia",
+ "Aka",
+ "Akti",
+ "Ala",
+ "Alco",
+ "Ale",
+ "Alka",
+ "Alki",
+ "Alo",
+ "Alphi",
+ "Ama",
+ "Ame",
+ "Ami",
+ "Amphi",
+ "Ana",
+ "Anchi",
+ "Andro",
+ "Ane",
+ "Anta",
+ "Anthe",
+ "Anti",
+ "Ape",
+ "Aphi",
+ "Apo",
+ "Arca",
+ "Arche",
+ "Arci",
+ "Arga",
+ "Ari",
+ "Arra",
+ "Arte",
+ "Asca",
+ "Asta",
+ "Asty",
+ "Atro",
+ "Atta",
+ "Aute",
+ "Bace",
+ "Bae",
+ "Bali",
+ "Bio",
+ "Boe",
+ "Bria",
+ "Care",
+ "Carpo",
+ "Casto",
+ "Cea",
+ "Cebri",
+ "Cele",
+ "Cephi",
+ "Chae",
+ "Chare",
+ "Chari",
+ "Choe",
+ "Chromi",
+ "Chryso",
+ "Cine",
+ "Cisse",
+ "Clea",
+ "Cleo",
+ "Clyto",
+ "Cnoe",
+ "Coe",
+ "Cordy",
+ "Cory",
+ "Crati",
+ "Creti",
+ "Croe",
+ "Ctea",
+ "Cyre",
+ "Dae",
+ "Dami",
+ "Damo",
+ "Dana",
+ "Daphi",
+ "Davo",
+ "Dei",
+ "Dema",
+ "Demo",
+ "Deo",
+ "Derky",
+ "Dexi",
+ "Dia",
+ "Dio",
+ "Dithy",
+ "Dore",
+ "Dori",
+ "Doro",
+ "Drya",
+ "Dymno",
+ "Eche",
+ "Eio",
+ "Ela",
+ "Elpe",
+ "Empe",
+ "Endy",
+ "Enge",
+ "Epa",
+ "Epe",
+ "Ephi",
+ "Era",
+ "Ere",
+ "Ergi",
+ "Erxa",
+ "Euca",
+ "Euche",
+ "Eudo",
+ "Eue",
+ "Euge",
+ "Euma",
+ "Eune",
+ "Eury",
+ "Euthy",
+ "Eva",
+ "Eve",
+ "Fae",
+ "Gale",
+ "Gany",
+ "Gaua",
+ "Genna",
+ "Gera",
+ "Glau",
+ "Gorgo",
+ "Gyra",
+ "Hae",
+ "Hagi",
+ "Hali",
+ "Harma",
+ "Harmo",
+ "Harpa",
+ "Hege",
+ "Heira",
+ "Heiro",
+ "Helge",
+ "Heli",
+ "Hera",
+ "Hermo",
+ "Hiero",
+ "Hippo",
+ "Hya",
+ "Hype",
+ "Hyrca",
+ "Iatro",
+ "Iby",
+ "Ica",
+ "Ido",
+ "Illy",
+ "Ina",
+ "Iphi",
+ "Iro",
+ "Isa",
+ "Isma",
+ "Iso",
+ "Ithe",
+ "Kae",
+ "Kale",
+ "Kalli",
+ "Kame",
+ "Kapa",
+ "Kari",
+ "Karo",
+ "Kau",
+ "Keo",
+ "Kera",
+ "Kleo",
+ "Krini",
+ "Krito",
+ "Labo",
+ "Lae",
+ "Lama",
+ "Lamu",
+ "Lao",
+ "Laso",
+ "Lea",
+ "Lei",
+ "Leo",
+ "Linu",
+ "Luko",
+ "Lyca",
+ "Lyco",
+ "Lysa",
+ "Lysi",
+ "Maca",
+ "Macha",
+ "Mae",
+ "Maia",
+ "Maka",
+ "Male",
+ "Mante",
+ "Marci",
+ "Marsy",
+ "Mega",
+ "Megi",
+ "Mela",
+ "Mele",
+ "Metho",
+ "Midy",
+ "Mise",
+ "Mono",
+ "Morsi",
+ "Myrsi",
+ "Naste",
+ "Nausi",
+ "Nea",
+ "Nele",
+ "Neri",
+ "Nica",
+ "Nico",
+ "Nire",
+ "Nomi",
+ "Nycti",
+ "Oche",
+ "Ocho",
+ "Oea",
+ "Oene",
+ "Oeno",
+ "Oile",
+ "Ona",
+ "One",
+ "Ophe",
+ "Ori",
+ "Orsi",
+ "Ory",
+ "Pae",
+ "Pala",
+ "Pana",
+ "Pandi",
+ "Pani",
+ "Panta",
+ "Para",
+ "Pata",
+ "Peiri",
+ "Pele",
+ "Peli",
+ "Peri",
+ "Phae",
+ "Phala",
+ "Philo",
+ "Phyla",
+ "Poe",
+ "Poly",
+ "Praxi",
+ "Prota",
+ "Pryta",
+ "Saby",
+ "Saty",
+ "Scama",
+ "Scytha",
+ "Sele",
+ "Sila",
+ "Simo",
+ "Sisy",
+ "Sopho",
+ "Stesa",
+ "Sya",
+ "Sylo",
+ "Syne",
+ "Tala",
+ "Teba",
+ "Tele",
+ "Tene",
+ "Theo",
+ "Therse",
+ "Thrasy",
+ "Tima",
+ "Tiry",
+ "Trio",
+ "Xanthi",
+ "Xena",
+ "Xeno",
+ )
+
+private val suffixesMale =
+ listOf(
+ "ndros",
+ "bios",
+ "bulos",
+ "chus",
+ "cles",
+ "cydes",
+ "damos",
+ "dides",
+ "don",
+ "doros",
+ "dotus",
+ "gnis",
+ "goras",
+ "kles",
+ "kos",
+ "krates",
+ "laktos",
+ "laus",
+ "leon",
+ "llias",
+ "llos",
+ "llus",
+ "machos",
+ "machus",
+ "menes",
+ "menos",
+ "mos",
+ "ndius",
+ "nes",
+ "neus",
+ "nidas",
+ "nides",
+ "nos",
+ "nthius",
+ "patros",
+ "phanes",
+ "phantes",
+ "phimus",
+ "phnus",
+ "phon",
+ "phoros",
+ "phorus",
+ "phus",
+ "pides",
+ "pompos",
+ "pompus",
+ "pon",
+ "ppos",
+ "rax",
+ "reas",
+ "rides",
+ "ros",
+ "sias",
+ "sides",
+ "sius",
+ "stius",
+ "stor",
+ "stos",
+ "stus",
+ "talos",
+ "thenes",
+ "theus",
+ "tios",
+ )
+
+private val suffixesFemale =
+ listOf(
+ "ndria",
+ "boea",
+ "casta",
+ "caste",
+ "cheia",
+ "chis",
+ "cleia",
+ "dee",
+ "deia",
+ "dike",
+ "dina",
+ "doce",
+ "dora",
+ "dusa",
+ "gaea",
+ "kia",
+ "laia",
+ "lea",
+ "line",
+ "llis",
+ "lope",
+ "mache",
+ "mathe",
+ "meda",
+ "mede",
+ "meia",
+ "mela",
+ "mene",
+ "mere",
+ "mia",
+ "mina",
+ "mpias",
+ "ndra",
+ "ne",
+ "neira",
+ "nessa",
+ "nia",
+ "nice",
+ "niera",
+ "nike",
+ "nippe",
+ "nna",
+ "nome",
+ "nope",
+ "nta",
+ "nthia",
+ "pe",
+ "phae",
+ "phana",
+ "phane",
+ "phile",
+ "phobe",
+ "phone",
+ "pia",
+ "polis",
+ "pris",
+ "pyle",
+ "reia",
+ "rine",
+ "ris",
+ "rista",
+ "rpia",
+ "sia",
+ "ssa",
+ "steia",
+ "stis",
+ "syne",
+ "ta",
+ "tea",
+ "thea",
+ "theia",
+ "thia",
+ "thippe",
+ "thra",
+ "thusa",
+ "thyia",
+ "tis",
+ "trite",
+ )
+
+private val suffixes = suffixesMale + suffixesFemale
+
+private val cities =
+ listOf(
+ "Argos",
+ "Assos",
+ "Astypalaia",
+ "Carystus",
+ "Chalcis",
+ "Chios",
+ "Corfu",
+ "Corinth",
+ "Eretria",
+ "Erythrae",
+ "Karpathos",
+ "Kasos",
+ "Kos",
+ "Leros",
+ "Lindos",
+ "Marathon",
+ "Megara",
+ "Miletus",
+ "Mytilene",
+ "Naxos",
+ "Oenoe",
+ "Paros",
+ "Patmos",
+ "Patras",
+ "Phocis",
+ "Rhodes",
+ "Salamis",
+ "Skiathos",
+ "Sparta",
+ "Thasos",
+ "Thebes",
+ )
bgstack15