From 51fd8b47ea7d1a2358116398f3ec00a83c1e4b68 Mon Sep 17 00:00:00 2001 From: Josh Friend Date: Tue, 25 Sep 2018 22:53:29 -0400 Subject: [PATCH] Handle cabbage/radish and water/milk closes #49 --- .../bunnypedia/database/model/Card.kt | 10 +++++----- .../bunnypedia/database/model/FeedTheBunny.kt | 19 +++++++++++++++++++ .../bunnypedia/ui/card/CardDetailFragment.kt | 17 ++++++++++++----- bunnies/src/main/res/values/strings.xml | 5 ++++- database/dbseed.py | 9 ++++++--- database/deck_caramel_swirl.json | 4 ++-- database/deck_creature_feature.json | 8 ++++---- database/deck_fantastic.json | 6 ++++-- 8 files changed, 56 insertions(+), 22 deletions(-) create mode 100644 bunnies/src/main/java/com/fueledbycaffeine/bunnypedia/database/model/FeedTheBunny.kt diff --git a/bunnies/src/main/java/com/fueledbycaffeine/bunnypedia/database/model/Card.kt b/bunnies/src/main/java/com/fueledbycaffeine/bunnypedia/database/model/Card.kt index 5d345b3..5d913b0 100644 --- a/bunnies/src/main/java/com/fueledbycaffeine/bunnypedia/database/model/Card.kt +++ b/bunnies/src/main/java/com/fueledbycaffeine/bunnypedia/database/model/Card.kt @@ -1,5 +1,6 @@ package com.fueledbycaffeine.bunnypedia.database.model +import androidx.room.Embedded import androidx.room.Entity import androidx.room.PrimaryKey @@ -20,10 +21,11 @@ data class Card( val symbols: List, val pawn: Pawn?, val weaponLevel: String?, - val cabbage: Int, - val water: Int, val psi: Psi?, - val specialSeries: SpecialSeries? + val specialSeries: SpecialSeries?, + + @Embedded + val ftb: FeedTheBunny ) { companion object { const val FTB_RANDOM = -1 @@ -34,6 +36,4 @@ data class Card( // var rules: List = emptyList() val imageURI: String get() = "file:///android_asset/card_thumbnails/${String.format("%04d.jpg", canonicalId ?: id)}" - - val isFtb: Boolean get() = cabbage != 0 && water != 0 } diff --git a/bunnies/src/main/java/com/fueledbycaffeine/bunnypedia/database/model/FeedTheBunny.kt b/bunnies/src/main/java/com/fueledbycaffeine/bunnypedia/database/model/FeedTheBunny.kt new file mode 100644 index 0000000..e2e3845 --- /dev/null +++ b/bunnies/src/main/java/com/fueledbycaffeine/bunnypedia/database/model/FeedTheBunny.kt @@ -0,0 +1,19 @@ +package com.fueledbycaffeine.bunnypedia.database.model + +import android.os.Parcelable +import kotlinx.android.parcel.Parcelize + +@Parcelize +data class FeedTheBunny( + val cabbage: Int, + val radish: Int, + val water: Int, + val milk: Int +): Parcelable { + val applicable get() = cabbage != 0 || radish != 0 || water != 0 || milk != 0 + + val cabbageAndWater get() = cabbage > 0 && water > 0 + val radishAndMilk get() = radish > 0 && milk > 0 + val cabbageOrRadish get() = cabbage > 0 && radish > 0 + val waterOrMilk get() = water > 0 && milk > 0 +} diff --git a/bunnies/src/main/java/com/fueledbycaffeine/bunnypedia/ui/card/CardDetailFragment.kt b/bunnies/src/main/java/com/fueledbycaffeine/bunnypedia/ui/card/CardDetailFragment.kt index a91a9ff..2048bcb 100644 --- a/bunnies/src/main/java/com/fueledbycaffeine/bunnypedia/ui/card/CardDetailFragment.kt +++ b/bunnies/src/main/java/com/fueledbycaffeine/bunnypedia/ui/card/CardDetailFragment.kt @@ -169,8 +169,8 @@ class CardDetailFragment: DaggerFragment() { requiresBunny.text = getString(card.bunnyRequirement.description) } - if (card.isFtb) { - setupFtbInfo(card.cabbage, card.water) + if (card.ftb.applicable) { + setupFtbInfo(card.ftb) } if (card.rank != null) { @@ -217,15 +217,22 @@ class CardDetailFragment: DaggerFragment() { pawnName.text = getString(pawn.pawnName) } - private fun setupFtbInfo(cabbage: Int, water: Int) { + private fun setupFtbInfo(ftb: FeedTheBunny) { + val (cabbage, radish, water, milk) = ftb containerFtb.visibility = View.VISIBLE - if (cabbage > 0 && water > 0) { + if (ftb.cabbageAndWater) { ftbRequirement.text = getString(R.string.ftb_cabbage_water, cabbage, water) + } else if (ftb.radishAndMilk) { + ftbRequirement.text = getString(R.string.ftb_radish_milk, radish, milk) + } else if (ftb.cabbageOrRadish) { + ftbRequirement.text = getString(R.string.ftb_cabbage_radish, cabbage) + } else if (ftb.waterOrMilk) { + ftbRequirement.text = getString(R.string.ftb_water_milk, water) } else if (cabbage > 0) { ftbRequirement.text = getString(R.string.ftb_cabbage, cabbage) } else if (water > 0) { ftbRequirement.text = getString(R.string.ftb_water, water) - } else if (cabbage == Card.FTB_RANDOM) { + } else if (cabbage == Card.FTB_RANDOM || radish == Card.FTB_RANDOM) { ftbRequirement.text = getString(R.string.ftb_random) } else if (cabbage == Card.FTB_DATED) { ftbRequirement.text = getString(R.string.ftb_dated_cabbage) diff --git a/bunnies/src/main/res/values/strings.xml b/bunnies/src/main/res/values/strings.xml index 9ddf699..3a38cc3 100644 --- a/bunnies/src/main/res/values/strings.xml +++ b/bunnies/src/main/res/values/strings.xml @@ -37,8 +37,11 @@ Creature Feature Booster Kaballa Dolla Rank - Cabbage/Water Required + Food Units Required %1$d Cabbage & %2$d Water + %1$d Radish & %2$d Milk + %1$d Cabbage or %1$d Radish + %1$d Water or %1$d Milk %1$d Cabbage %1$d Water Roll for amounts diff --git a/database/dbseed.py b/database/dbseed.py index 14a9256..17be175 100755 --- a/database/dbseed.py +++ b/database/dbseed.py @@ -15,7 +15,8 @@ class Card: title TEXT NOT NULL, deck TEXT NOT NULL, type TEXT NOT NULL, rank TEXT, zodiacType TEXT, zodiacAnimal TEXT, bunnyRequirement TEXT NOT NULL, dice TEXT NOT NULL, symbols TEXT NOT NULL, pawn TEXT, weaponLevel TEXT, - cabbage INTEGER NOT NULL, water INTEGER NOT NULL, psi TEXT, + cabbage INTEGER NOT NULL, radish INTEGER NOT NULL, + water INTEGER NOT NULL, milk INTEGER NOT NULL, psi TEXT, specialSeries TEXT ); """, @@ -24,11 +25,11 @@ class Card: INSERT_STMT = """ INSERT INTO Card ( id, canonicalId, title, deck, type, rank, zodiacType, zodiacAnimal, bunnyRequirement, - dice, symbols, pawn, weaponLevel, cabbage, water, psi, specialSeries + dice, symbols, pawn, weaponLevel, cabbage, radish, water, milk, psi, specialSeries ) VALUES ( :id, :canonicalId, :title, :deck, :type, :rank, :zodiacType, :zodiacAnimal, :bunnyRequirement, :dice, :symbols, :pawn, :weaponLevel, - :cabbage, :water, :psi, :specialSeries + :cabbage, :radish, :water, :milk, :psi, :specialSeries ); """ @@ -55,7 +56,9 @@ def __init__(self, **kwargs): self.pawn = kwargs.get('pawn') self.weaponLevel = kwargs.get('weaponLevel') self.cabbage = kwargs.get('cabbage', 0) + self.radish = kwargs.get('radish', 0) self.water = kwargs.get('water', 0) + self.milk = kwargs.get('milk', 0) self.psi = kwargs.get('psi') self.specialSeries = kwargs.get('specialSeries') diff --git a/database/deck_caramel_swirl.json b/database/deck_caramel_swirl.json index 1391114..209258b 100644 --- a/database/deck_caramel_swirl.json +++ b/database/deck_caramel_swirl.json @@ -78,7 +78,7 @@ "type": "RUN", "bunnyRequirement": "PLAY", "cabbage": 2, - "water": 0, + "radish": 2, "rules": [ {"title": "Card Text", "text": "May be placed on any bunny which must feed the amounts shown by the end of its next turn or die."} ] @@ -89,7 +89,7 @@ "deck": "CARAMEL_SWIRL", "type": "RUN", "bunnyRequirement": "PLAY", - "cabbage": 0, + "milk": 1, "water": 1, "rules": [ {"title": "Card Text", "text": "May be placed on any bunny which must feed the amounts shown by the end of its next turn or die."} diff --git a/database/deck_creature_feature.json b/database/deck_creature_feature.json index 6dc7a2d..8c85499 100644 --- a/database/deck_creature_feature.json +++ b/database/deck_creature_feature.json @@ -95,24 +95,24 @@ }, { "id": "1165", - "title": "Feed The Bunny", + "title": "Feed The Bunny 3/0", "type": "RUN", "bunnyRequirement": "PLAY", "deck": "CREATURE_FEATURE", - "water": 0, "cabbage": 3, + "radish": 3, "rules": [ {"title": "Card Text", "text": "May be placed on any bunny which must feed the amounts shown by the end of its next turn or die."} ] }, { "id": "1166", - "title": "Feed The Bunny", + "title": "Feed The Bunny 0/3", "type": "RUN", "bunnyRequirement": "PLAY", "deck": "CREATURE_FEATURE", "water": 3, - "cabbage": 0, + "milk": 3, "rules": [ {"title": "Card Text", "text": "May be placed on any bunny which must feed the amounts shown by the end of its next turn or die."} ] diff --git a/database/deck_fantastic.json b/database/deck_fantastic.json index e701955..a57fb40 100644 --- a/database/deck_fantastic.json +++ b/database/deck_fantastic.json @@ -393,22 +393,24 @@ }, { "id": 1080, - "title": "Feed The Bunny - 1 Cabbage Or Radish", + "title": "Feed The Bunny 1/0", "deck": "FANTASTIC", "type": "RUN", "bunnyRequirement": "PLAY", "cabbage": 1, + "radish": 1, "rules": [ {"title": "Card Text", "text": "May be placed on any bunny which must feed the amounts shown by the end of its next turn or die."} ] }, { "id": 1081, - "title": "Feed The Bunny - 2 Water or Milk", + "title": "Feed The Bunny 0/2", "deck": "FANTASTIC", "type": "RUN", "bunnyRequirement": "PLAY", "water": 2, + "milk": 2, "rules": [ {"title": "Card Text", "text": "May be placed on any bunny which must feed the amounts shown by the end of its next turn or die."} ]