Fix console tile find for quoted input or filters requiring correct uppercase, expand notification (#13542)

This commit is contained in:
SomeTroglodyte 2025-06-29 17:02:27 +02:00 committed by GitHub
parent 28f8777447
commit 6d3ea5260b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 3 deletions

View File

@ -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 <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
companion object {

View File

@ -120,11 +120,11 @@ internal class ConsoleTileCommands: ConsoleCommandNode {
"find" to ConsoleAction("tile find <tileFilter>") { 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)