aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-12-08 00:42:01 +0100
committerLinnea Gräf <nea@nea.moe>2024-12-08 00:42:01 +0100
commitfa72dd4ce107190cda7bc56234fed650f20e3aa9 (patch)
tree57a5fa0c224db5bb670e26813c958a768d6bdf90 /src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt
parent0a2342c015b310172f933df765d8651013c26f16 (diff)
downloadLocalTransactionLedger-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.kt15
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