mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-23 03:23:17 -04:00
Fix console tile find
for quoted input or filters requiring correct uppercase, expand notification (#13542)
This commit is contained in:
parent
28f8777447
commit
6d3ea5260b
@ -137,7 +137,7 @@ internal class CliInput(
|
|||||||
/** Parses `this` parameter as a Float number.
|
/** Parses `this` parameter as a Float number.
|
||||||
* @throws ConsoleErrorException if the string is not a valid representation of a number. */
|
* @throws ConsoleErrorException if the string is not a valid representation of a number. */
|
||||||
fun toFloat(): Float = content.toFloatOrNull() ?: throw ConsoleErrorException("'$this' is not a valid number.")
|
fun toFloat(): Float = content.toFloatOrNull() ?: throw ConsoleErrorException("'$this' is not a valid number.")
|
||||||
|
|
||||||
/** Parses `this` parameter as a Boolean.
|
/** Parses `this` parameter as a Boolean.
|
||||||
* @throws ConsoleErrorException if the string is not 'true' or 'false'. */
|
* @throws ConsoleErrorException if the string is not 'true' or 'false'. */
|
||||||
fun toBoolean(): Boolean = content.toBooleanStrictOrNull() ?: throw ConsoleErrorException("'$this' is not a valid boolean value.")
|
fun toBoolean(): Boolean = content.toBooleanStrictOrNull() ?: throw ConsoleErrorException("'$this' is not a valid boolean value.")
|
||||||
@ -182,6 +182,15 @@ internal class CliInput(
|
|||||||
* @throws ConsoleErrorException if not found. */
|
* @throws ConsoleErrorException if not found. */
|
||||||
inline fun <reified T: INamed> find(options: Sequence<T>): T = find(options.asIterable())
|
inline fun <reified T: INamed> find(options: Sequence<T>): T = find(options.asIterable())
|
||||||
|
|
||||||
|
/** Representation to include in strings that will pass through tr(), e.g. for notifications repeating a filter:
|
||||||
|
* - Dashed input is returned as [content] wrapped in square brackets
|
||||||
|
* - Quoted input is returned as [originalUnquoted] wrapped in square brackets plus quotes **outside** those.
|
||||||
|
*/
|
||||||
|
fun toStringAsPlaceholder() = when(method) {
|
||||||
|
Method.Dashed -> "[$content]"
|
||||||
|
Method.Quoted -> "\"[${originalUnquoted()}]\""
|
||||||
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -120,11 +120,11 @@ internal class ConsoleTileCommands: ConsoleCommandNode {
|
|||||||
"find" to ConsoleAction("tile find <tileFilter>") { console, params ->
|
"find" to ConsoleAction("tile find <tileFilter>") { console, params ->
|
||||||
val filter = params[0]
|
val filter = params[0]
|
||||||
val locations = console.gameInfo.tileMap.tileList
|
val locations = console.gameInfo.tileMap.tileList
|
||||||
.filter { it.matchesFilter(filter.toString()) }
|
.filter { it.matchesFilter(filter.originalUnquoted()) } // filters are case sensitive
|
||||||
.map { it.position }
|
.map { it.position }
|
||||||
if (locations.isEmpty()) DevConsoleResponse.hint("None found")
|
if (locations.isEmpty()) DevConsoleResponse.hint("None found")
|
||||||
else {
|
else {
|
||||||
val notification = Notification("tile find [$filter]", arrayOf(NotificationIcon.Spy),
|
val notification = Notification("tile find ${filter.toStringAsPlaceholder()}: ${locations.size} matches", arrayOf(NotificationIcon.Spy),
|
||||||
LocationAction(locations).asIterable(), NotificationCategory.General)
|
LocationAction(locations).asIterable(), NotificationCategory.General)
|
||||||
console.screen.notificationsScroll.oneTimeNotification = notification
|
console.screen.notificationsScroll.oneTimeNotification = notification
|
||||||
notification.execute(console.screen)
|
notification.execute(console.screen)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user