diff options
author | Linnea Gräf <nea@nea.moe> | 2024-12-08 00:42:01 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-12-08 00:42:01 +0100 |
commit | fa72dd4ce107190cda7bc56234fed650f20e3aa9 (patch) | |
tree | 57a5fa0c224db5bb670e26813c958a768d6bdf90 /src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt | |
parent | 0a2342c015b310172f933df765d8651013c26f16 (diff) | |
download | LocalTransactionLedger-fa72dd4ce107190cda7bc56234fed650f20e3aa9.tar.gz LocalTransactionLedger-fa72dd4ce107190cda7bc56234fed650f20e3aa9.tar.bz2 LocalTransactionLedger-fa72dd4ce107190cda7bc56234fed650f20e3aa9.zip |
feat: Add visitor trading detection
Diffstat (limited to 'src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt')
-rw-r--r-- | src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt | 15 |
1 files changed, 10 insertions, 5 deletions
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 = "(?<amount>$SHORT_NUMBER_PATTERN) Coins?".toPattern() @@ -84,7 +89,7 @@ class ItemIdProvider { .toList() } - fun findStackableItemByName(name: String): Pair<ItemId, Double>? { + fun findStackableItemByName(name: String, fallbackToGenerated: Boolean = false): Pair<ItemId, Double>? { 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 |