From 6d3ea5260b53c8d10c94ac7e712c090235405320 Mon Sep 17 00:00:00 2001 From: SomeTroglodyte <63000004+SomeTroglodyte@users.noreply.github.com> Date: Sun, 29 Jun 2025 17:02:27 +0200 Subject: [PATCH] Fix console `tile find` for quoted input or filters requiring correct uppercase, expand notification (#13542) --- core/src/com/unciv/ui/screens/devconsole/CliInput.kt | 11 ++++++++++- .../ui/screens/devconsole/ConsoleTileCommands.kt | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/core/src/com/unciv/ui/screens/devconsole/CliInput.kt b/core/src/com/unciv/ui/screens/devconsole/CliInput.kt index 723632cadf..654b3ba2af 100644 --- a/core/src/com/unciv/ui/screens/devconsole/CliInput.kt +++ b/core/src/com/unciv/ui/screens/devconsole/CliInput.kt @@ -137,7 +137,7 @@ internal class CliInput( /** Parses `this` parameter as a Float 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.") - + /** Parses `this` parameter as a Boolean. * @throws ConsoleErrorException if the string is not 'true' or 'false'. */ 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. */ inline fun find(options: Sequence): 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 companion object { diff --git a/core/src/com/unciv/ui/screens/devconsole/ConsoleTileCommands.kt b/core/src/com/unciv/ui/screens/devconsole/ConsoleTileCommands.kt index 1236f3d3e3..751e61812a 100644 --- a/core/src/com/unciv/ui/screens/devconsole/ConsoleTileCommands.kt +++ b/core/src/com/unciv/ui/screens/devconsole/ConsoleTileCommands.kt @@ -120,11 +120,11 @@ internal class ConsoleTileCommands: ConsoleCommandNode { "find" to ConsoleAction("tile find ") { console, params -> val filter = params[0] val locations = console.gameInfo.tileMap.tileList - .filter { it.matchesFilter(filter.toString()) } + .filter { it.matchesFilter(filter.originalUnquoted()) } // filters are case sensitive .map { it.position } if (locations.isEmpty()) DevConsoleResponse.hint("None found") 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) console.screen.notificationsScroll.oneTimeNotification = notification notification.execute(console.screen)