mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-07 00:41:39 +07:00
Autofix Multiplayer Server URL on input (#6743)
* Autofix Multiplayer Server URL on input, resolves #6583 * some improvements
This commit is contained in:

committed by
GitHub

parent
8fcfbf752b
commit
531906f5ba
@ -41,6 +41,7 @@ import com.unciv.ui.utils.UncivTooltip.Companion.addTooltip
|
|||||||
import com.unciv.ui.worldscreen.WorldScreen
|
import com.unciv.ui.worldscreen.WorldScreen
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
import kotlin.math.floor
|
import kotlin.math.floor
|
||||||
|
import kotlin.text.Regex
|
||||||
import com.badlogic.gdx.utils.Array as GdxArray
|
import com.badlogic.gdx.utils.Array as GdxArray
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -280,7 +281,7 @@ class OptionsPopup(
|
|||||||
multiplayerServerTextField.text = Gdx.app.clipboard.contents
|
multiplayerServerTextField.text = Gdx.app.clipboard.contents
|
||||||
}).row()
|
}).row()
|
||||||
multiplayerServerTextField.onChange {
|
multiplayerServerTextField.onChange {
|
||||||
settings.multiplayerServer = multiplayerServerTextField.text
|
settings.multiplayerServer = formatMultiplayerUrlInput(multiplayerServerTextField.text)
|
||||||
settings.save()
|
settings.save()
|
||||||
connectionToServerButton.isEnabled = multiplayerServerTextField.text != Constants.dropboxMultiplayerServer
|
connectionToServerButton.isEnabled = multiplayerServerTextField.text != Constants.dropboxMultiplayerServer
|
||||||
}
|
}
|
||||||
@ -954,5 +955,21 @@ class OptionsPopup(
|
|||||||
add(checkbox).colspan(2).left().row()
|
add(checkbox).colspan(2).left().row()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun formatMultiplayerUrlInput(input: String): String {
|
||||||
|
var result : String
|
||||||
|
|
||||||
|
// remove all whitespaces
|
||||||
|
result = Regex("\\s+").replace(input, "")
|
||||||
|
|
||||||
|
// replace multiple slash with a single one
|
||||||
|
result = Regex("/{2,}").replace(result, "/")
|
||||||
|
|
||||||
|
// remove trailing slash, reinstate protocol & return
|
||||||
|
// all the formatting above makes "https://" -> "http:/"
|
||||||
|
// also people might leave a slash at end my mistake
|
||||||
|
// so we need to fix those before returning
|
||||||
|
return result.trimEnd('/').replaceFirst(":/", "://")
|
||||||
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user