Skip to content

Commit

Permalink
fix: trim game names
Browse files Browse the repository at this point in the history
The name of games are now trimmed when the user starts a new game.
fixes #7
  • Loading branch information
sellmerfud committed May 15, 2024
1 parent 08da909 commit 5b3c05f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/main/scala/coltwi/ColonialTwilight.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2101,17 +2101,18 @@ object ColonialTwilight {
readLine(prompt) match {
case null => getName
case VALID_NAME(name) =>
if ((gamesDir/name).exists) {
println(s"A game called '$name' already exists.")
val trimmed = name.trim()
if ((gamesDir/trimmed).exists) {
println(s"A game called '$trimmed' already exists.")
if (askYorN(s"Do you want to overwrite the existing game (y/n)? ")) {
(gamesDir/name).rmtree()
name
(gamesDir/trimmed).rmtree()
trimmed
}
else
getName
}
else
name
trimmed
case name =>
println("The name must consist of one or more letters, numbers, spaces, dashes or undercores")
getName
Expand Down

0 comments on commit 5b3c05f

Please sign in to comment.