diff options
author | Linnea Gräf <nea@nea.moe> | 2024-12-08 03:42:07 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-12-08 03:42:07 +0100 |
commit | ef11dd51a61d25bc8722cc844358869b00a5369c (patch) | |
tree | 8545e3e1724bb08dba316dd26b0d5edd9918a6e8 /src/main/kotlin/moe/nea/ledger/ItemChange.kt | |
parent | fa72dd4ce107190cda7bc56234fed650f20e3aa9 (diff) | |
download | LocalTransactionLedger-ef11dd51a61d25bc8722cc844358869b00a5369c.tar.gz LocalTransactionLedger-ef11dd51a61d25bc8722cc844358869b00a5369c.tar.bz2 LocalTransactionLedger-ef11dd51a61d25bc8722cc844358869b00a5369c.zip |
feat: Add query command
Diffstat (limited to 'src/main/kotlin/moe/nea/ledger/ItemChange.kt')
-rw-r--r-- | src/main/kotlin/moe/nea/ledger/ItemChange.kt | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/ledger/ItemChange.kt b/src/main/kotlin/moe/nea/ledger/ItemChange.kt index a8bb7e8..834cd2b 100644 --- a/src/main/kotlin/moe/nea/ledger/ItemChange.kt +++ b/src/main/kotlin/moe/nea/ledger/ItemChange.kt @@ -1,16 +1,52 @@ package moe.nea.ledger +import moe.nea.ledger.database.DBItemEntry +import moe.nea.ledger.database.ResultRow +import net.minecraft.event.HoverEvent +import net.minecraft.util.ChatComponentText +import net.minecraft.util.ChatStyle +import net.minecraft.util.EnumChatFormatting +import net.minecraft.util.IChatComponent + data class ItemChange( val itemId: ItemId, val count: Double, val direction: ChangeDirection, ) { + fun formatChat(): IChatComponent { + return ChatComponentText(" ") + .appendSibling(direction.chatFormat) + .appendText(" ") + .appendSibling(ChatComponentText("$count").setChatStyle(ChatStyle().setColor(EnumChatFormatting.WHITE))) + .appendSibling(ChatComponentText("x").setChatStyle(ChatStyle().setColor(EnumChatFormatting.DARK_GRAY))) + .appendText(" ") + .appendSibling(ChatComponentText(itemId.string).setChatStyle(ChatStyle().setParentStyle(ChatStyle().setColor( + EnumChatFormatting.WHITE)))) + } + enum class ChangeDirection { GAINED, TRANSFORM, SYNC, CATALYST, LOST; + + val chatFormat by lazy { formatChat0() } + private fun formatChat0(): IChatComponent { + val (text, color) = when (this) { + GAINED -> "+" to EnumChatFormatting.GREEN + TRANSFORM -> "~" to EnumChatFormatting.YELLOW + SYNC -> "=" to EnumChatFormatting.BLUE + CATALYST -> "*" to EnumChatFormatting.DARK_PURPLE + LOST -> "-" to EnumChatFormatting.RED + } + return ChatComponentText(text) + .setChatStyle( + ChatStyle() + .setColor(color) + .setChatHoverEvent(HoverEvent(HoverEvent.Action.SHOW_TEXT, + ChatComponentText(name).setChatStyle(ChatStyle().setColor(color))))) + } } companion object { @@ -29,5 +65,13 @@ data class ItemChange( fun loseCoins(number: Double): ItemChange { return lose(ItemId.COINS, number) } + + fun from(result: ResultRow): ItemChange { + return ItemChange( + result[DBItemEntry.itemId], + result[DBItemEntry.size], + result[DBItemEntry.mode], + ) + } } }
\ No newline at end of file |