From fa72dd4ce107190cda7bc56234fed650f20e3aa9 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Sun, 8 Dec 2024 00:42:01 +0100 Subject: feat: Add visitor trading detection --- src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt') diff --git a/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt b/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt index d6ca05b..f2906b8 100644 --- a/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt +++ b/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt @@ -68,8 +68,13 @@ class ItemIdProvider { } } - fun findForName(name: String): ItemId? { - return knownNames[name] + // TODO: make use of colour + fun findForName(name: String, fallbackToGenerated: Boolean = true): ItemId? { + var id = knownNames[name] + if (id == null && fallbackToGenerated) { + id = ItemId(name.uppercase().replace(" ", "_")) + } + return id } private val coinRegex = "(?$SHORT_NUMBER_PATTERN) Coins?".toPattern() @@ -84,7 +89,7 @@ class ItemIdProvider { .toList() } - fun findStackableItemByName(name: String): Pair? { + fun findStackableItemByName(name: String, fallbackToGenerated: Boolean = false): Pair? { val properName = name.unformattedString() if (properName == "FREE" || properName == "This Chest is Free!") { return Pair(ItemId.COINS, 0.0) @@ -97,12 +102,12 @@ class ItemIdProvider { parseShortNumber(group("count"))) } stackedItemRegex.useMatcher(properName) { - val item = findForName(group("name")) + var item = findForName(group("name"), fallbackToGenerated) if (item != null) { val count = parseShortNumber(group("count")) return Pair(item, count) } } - return findForName(properName)?.let { Pair(it, 1.0) } + return findForName(properName, fallbackToGenerated)?.let { Pair(it, 1.0) } } } \ No newline at end of file -- cgit