mirror of
https://github.com/nacabaro/vbhelper.git
synced 2026-10-01 15:41:36 +00:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fd76c46f39 | ||
|
|
e85e1f45bf | ||
|
|
630cccefe4 |
@@ -1,69 +1,38 @@
|
|||||||
# VBHelper
|
# VBHelper
|
||||||
|
|
||||||
Application to interact with the Vital series, VB, VH, VBC and VBBE.
|
## Developer Setup
|
||||||
|
|
||||||
## Current state of the project
|
1. Clone vb-nfc-reader (https://github.com/cfogrady/lib-vb-nfc)
|
||||||
|
2. Run vb-nfc-reader/publishToMavenLocal gradle task in the lib-vb-nfc project.
|
||||||
Right now the project is still under development, and until further notice, any database updates will result in having to erase application data.
|
3. Clone vb-dim-reader (https://github.com/cfogrady/vb-dim-reader)
|
||||||
|
4. Run publishToMavenLocal gradle task in the vb-dim-reader project.
|
||||||
This document will be updated once the application does not need any more database resets.
|
5. Create res/values/keys.xml within the app module.
|
||||||
|
6. Populate with:
|
||||||
## Features
|
```
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
As of now, the project allows you to read characters, view characters stats, and send them back to your watch.
|
<resources>
|
||||||
|
<string name="password1">beHmacKey1</string>
|
||||||
You can also apply items to the characters read, such as special missions, or change timers, and store characters in the storage section.
|
<string name="password2">beHmacKey2</string>
|
||||||
|
<string name="decryptionKey">aesKey</string>
|
||||||
You also earn new items every time an item such as a special mission (VB only) or a character completes an in-app adventure mission.
|
<integer-array name="substitutionArray">
|
||||||
|
<item>0</item>
|
||||||
App also comes with a dex that will update every time a new character is added, and allows you to see evolution requirements and current adventure stage in the watch.
|
<item>1</item>
|
||||||
|
<item>2</item>
|
||||||
## How to set up
|
<item>3</item>
|
||||||
|
<item>4</item>
|
||||||
1. Download the latest version for VB Arena APK from a trustworthy source. If your download is a standalone APK, continue to step 2. Otherwise, if your download is an XAPK, do the following:
|
<item>5</item>
|
||||||
|
<item>6</item>
|
||||||
1. Using your phone file manager, rename the XAPK file to ZIP, and extract its contents. You can also do this with any other device, such as Windows, macOS and Linux.
|
<item>7</item>
|
||||||
|
<item>8</item>
|
||||||
2. Once the files are extracted, look for an APK called `com.bandai.vitalbraceletarena.apk`. Copy it somewhere else, you will need it.
|
<item>9</item>
|
||||||
|
<item>10</item>
|
||||||
2. Install an APK release for VB Arena. You will find the releases [here](http://github.com/nacabaro/vbhelper/releases). Download the latest release and install its APK.
|
<item>11</item>
|
||||||
|
<item>12</item>
|
||||||
Note, in the current stage of the project, you will have to delete the old application from your device. If the app keeps crashing after installing, clear application data and storage.
|
<item>13</item>
|
||||||
|
<item>14</item>
|
||||||
3. Import secrets in the app. These secrets will allow the app to talk to the watch. On the main screen, click on the gear icon, then `Import secrets`.
|
<item>15</item>
|
||||||
|
</integer-array>
|
||||||
You will be prompted to choose a file. Choose the APK file that was previously obtained.
|
</resources>
|
||||||
|
```
|
||||||
4. Import cards. Due to copyright laws, we cannot offer the characters and sprites themselves in the application. In order to import the cards do the following.
|
7. Replace the values in the keys.xml file with those extracted from the original app.
|
||||||
|
8. Run
|
||||||
1. Using your own DiM/BEm cards, dump the cards to your device. You can get an in-depth tutorial in [here](http://mrblinky.net/digimon/vb/dimcardtool/dimcardtool.html). You can download the dump tool from [here](http://mrblinky.net/digimon/vb/dimcardtool/)
|
|
||||||
|
|
||||||
2. Once installed the tool and drivers, open the tool, connect your DiM/BEm reader hardware to yout computer and click on Read card.
|
|
||||||
|
|
||||||
3. Transfer the resulting file to your mobile device. You can put them anywhere, as long as they are accessible. My recommendation is to put them under a folder called `Cards` in your `Internal storage` or `SD Card`
|
|
||||||
|
|
||||||
4. In the app, click on import card. Next choose the BIN file corresponding to the card you want to import.
|
|
||||||
|
|
||||||
**Note: if you do not import the card, whenever you attempt to read a character from th watch, the character you read will get deleted.**
|
|
||||||
|
|
||||||
5. App will now be ready to be used.
|
|
||||||
|
|
||||||
## Planned features
|
|
||||||
|
|
||||||
- Online battles, undegoing development by `lightheel`.
|
|
||||||
|
|
||||||
- VitalWear compatibility, undergoing development by `cfogrady`.
|
|
||||||
|
|
||||||
- Support for multiple languages, not yet started.
|
|
||||||
|
|
||||||
- Database backup/restore.
|
|
||||||
|
|
||||||
## Credits
|
|
||||||
|
|
||||||
- `cyanic` for helping us understand more about the VB connection protocol.
|
|
||||||
|
|
||||||
- `cfogrady` for making both [`VB-DIM-Reader`](https://github.com/cfogrady/VB-DIM-Reader) and [`lib-vb-nfc`](https://github.com/cfogrady/lib-vb-nfc)
|
|
||||||
|
|
||||||
- `lightheel` for working on the online component in the application, both server and battle client.
|
|
||||||
|
|
||||||
- `shvstrz` for the app icon.
|
|
||||||
@@ -91,5 +91,4 @@ dependencies {
|
|||||||
implementation("com.google.android.material:material:1.2.0")
|
implementation("com.google.android.material:material:1.2.0")
|
||||||
implementation(libs.protobuf.javalite)
|
implementation(libs.protobuf.javalite)
|
||||||
implementation("androidx.compose.material:material")
|
implementation("androidx.compose.material:material")
|
||||||
implementation("androidx.datastore:datastore-preferences:1.1.7")
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.github.nacabaro.vbhelper.daos
|
||||||
|
|
||||||
|
import androidx.room.Dao
|
||||||
|
import androidx.room.Insert
|
||||||
|
import androidx.room.Query
|
||||||
|
import com.github.nacabaro.vbhelper.domain.card.CardBackground
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
interface CardBackgroundDao {
|
||||||
|
@Insert
|
||||||
|
suspend fun insertCardBackground(vararg cardBackground: CardBackground)
|
||||||
|
|
||||||
|
@Query("""
|
||||||
|
SELECT * FROM CardBackground
|
||||||
|
WHERE cardId = :cardId
|
||||||
|
""")
|
||||||
|
suspend fun getCardBackground(cardId: Long): CardBackground
|
||||||
|
|
||||||
|
@Query("""
|
||||||
|
SELECT * FROM CardBackground
|
||||||
|
""")
|
||||||
|
suspend fun getBackgrounds(): List<CardBackground>
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import androidx.room.Insert
|
|||||||
import androidx.room.OnConflictStrategy
|
import androidx.room.OnConflictStrategy
|
||||||
import androidx.room.Query
|
import androidx.room.Query
|
||||||
import com.github.nacabaro.vbhelper.domain.card.Card
|
import com.github.nacabaro.vbhelper.domain.card.Card
|
||||||
|
import com.github.nacabaro.vbhelper.domain.card.CardSprites
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface CardDao {
|
interface CardDao {
|
||||||
@@ -33,4 +34,11 @@ interface CardDao {
|
|||||||
|
|
||||||
@Query("DELETE FROM Card WHERE id = :id")
|
@Query("DELETE FROM Card WHERE id = :id")
|
||||||
suspend fun deleteCard(id: Long)
|
suspend fun deleteCard(id: Long)
|
||||||
|
|
||||||
|
@Insert
|
||||||
|
suspend fun insertSprites(vararg sprites: CardSprites)
|
||||||
|
|
||||||
|
@Query("SELECT * FROM CardSprites")
|
||||||
|
suspend fun getSprites(): List<CardSprites>
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -5,28 +5,30 @@ import androidx.room.Query
|
|||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface CardFusionsDao {
|
interface CardFusionsDao {
|
||||||
@Query("""
|
@Query(
|
||||||
|
"""
|
||||||
INSERT INTO
|
INSERT INTO
|
||||||
CardFusions (
|
CardFusions (
|
||||||
fromCharaId,
|
fromCharaId,
|
||||||
attribute1Fusion,
|
toVirusFusion,
|
||||||
attribute2Fusion,
|
toDataFusion,
|
||||||
attribute3Fusion,
|
toVaccineFusion,
|
||||||
attribute4Fusion
|
toFreeFusion
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
(SELECT id FROM CardCharacter WHERE cardId = :cardId AND charaIndex = :fromCharaId),
|
(SELECT id FROM CardCharacter WHERE cardId = :cardId AND charaIndex = :fromCharaId),
|
||||||
(SELECT id FROM CardCharacter WHERE cardId = :cardId AND charaIndex = :toCharaIdAttr1),
|
(SELECT id FROM CardCharacter WHERE cardId = :cardId AND charaIndex = :toCharaIdVirus),
|
||||||
(SELECT id FROM CardCharacter WHERE cardId = :cardId AND charaIndex = :toCharaIdAttr2),
|
(SELECT id FROM CardCharacter WHERE cardId = :cardId AND charaIndex = :toCharaIdData),
|
||||||
(SELECT id FROM CardCharacter WHERE cardId = :cardId AND charaIndex = :toCharaIdAttr3),
|
(SELECT id FROM CardCharacter WHERE cardId = :cardId AND charaIndex = :toCharaIdVaccine),
|
||||||
(SELECT id FROM CardCharacter WHERE cardId = :cardId AND charaIndex = :toCharaIdAttr4)
|
(SELECT id FROM CardCharacter WHERE cardId = :cardId AND charaIndex = :toCharaIdFree)
|
||||||
""")
|
"""
|
||||||
|
)
|
||||||
suspend fun insertNewFusion(
|
suspend fun insertNewFusion(
|
||||||
cardId: Long,
|
cardId: Long,
|
||||||
fromCharaId: Int,
|
fromCharaId: Int,
|
||||||
toCharaIdAttr1: Int,
|
toCharaIdVirus: Int,
|
||||||
toCharaIdAttr2: Int,
|
toCharaIdData: Int,
|
||||||
toCharaIdAttr3: Int,
|
toCharaIdVaccine: Int,
|
||||||
toCharaIdAttr4: Int
|
toCharaIdFree: Int
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -1,28 +1,17 @@
|
|||||||
package com.github.nacabaro.vbhelper.daos
|
package com.github.nacabaro.vbhelper.daos
|
||||||
|
|
||||||
import androidx.room.Dao
|
import androidx.room.Dao
|
||||||
import androidx.room.Insert
|
|
||||||
import androidx.room.Query
|
import androidx.room.Query
|
||||||
|
import androidx.room.Upsert
|
||||||
import com.github.nacabaro.vbhelper.domain.card.CardProgress
|
import com.github.nacabaro.vbhelper.domain.card.CardProgress
|
||||||
import com.github.nacabaro.vbhelper.dtos.CharacterDtos
|
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface CardProgressDao {
|
interface CardProgressDao {
|
||||||
@Query("""
|
@Upsert
|
||||||
UPDATE CardProgress
|
fun updateDimProgress(vararg cardProgresses: CardProgress)
|
||||||
SET
|
|
||||||
currentStage = :currentStage,
|
|
||||||
unlocked = :unlocked
|
|
||||||
WHERE cardId = :cardId AND
|
|
||||||
currentStage < :currentStage
|
|
||||||
""")
|
|
||||||
fun updateCardProgress(currentStage: Int, cardId: Long, unlocked: Boolean)
|
|
||||||
|
|
||||||
@Query(
|
@Query(
|
||||||
"SELECT currentStage FROM CardProgress WHERE cardId = :cardId"
|
"SELECT currentStage FROM CardProgress WHERE cardId = :cardId"
|
||||||
)
|
)
|
||||||
fun getCardProgress(cardId: Long): Int
|
fun getCardProgress(cardId: Long): Int
|
||||||
|
|
||||||
@Insert
|
|
||||||
fun insertCardProgress(cardProgress: CardProgress)
|
|
||||||
}
|
}
|
||||||
@@ -24,12 +24,10 @@ interface CharacterDao {
|
|||||||
d.cardId as cardId,
|
d.cardId as cardId,
|
||||||
c.charaIndex as charId,
|
c.charaIndex as charId,
|
||||||
c.stage as stage,
|
c.stage as stage,
|
||||||
c.attribute as attribute,
|
c.attribute as attribute
|
||||||
cp.currentStage as currentStage
|
|
||||||
FROM CardCharacter c
|
FROM CardCharacter c
|
||||||
JOIN UserCharacter uc ON c.id = uc.charId
|
JOIN UserCharacter uc ON c.id = uc.charId
|
||||||
JOIN Card d ON c.cardId = d.id
|
JOIN Card d ON c.cardId = d.id
|
||||||
JOIN CardProgress cp ON d.id = cp.cardId
|
|
||||||
WHERE c.id = :charId
|
WHERE c.id = :charId
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
@@ -37,7 +35,7 @@ interface CharacterDao {
|
|||||||
|
|
||||||
@Query(
|
@Query(
|
||||||
"""
|
"""
|
||||||
INSERT INTO PossibleTransformations (charaId, requiredVitals, requiredTrophies, requiredBattles, requiredWinRate, changeTimerHours, requiredAdventureLevelCompleted, toCharaId)
|
INSERT INTO CardTransformations (charaId, requiredVitals, requiredTrophies, requiredBattles, requiredWinRate, changeTimerHours, requiredAdventureLevelCompleted, toCharaId)
|
||||||
SELECT
|
SELECT
|
||||||
(SELECT id FROM CardCharacter WHERE charaIndex = :fromChraraIndex AND cardId = :cardId),
|
(SELECT id FROM CardCharacter WHERE charaIndex = :fromChraraIndex AND cardId = :cardId),
|
||||||
:requiredVitals,
|
:requiredVitals,
|
||||||
@@ -77,7 +75,7 @@ interface CharacterDao {
|
|||||||
pt.changeTimerHours as changeTimerHours,
|
pt.changeTimerHours as changeTimerHours,
|
||||||
pt.requiredAdventureLevelCompleted as requiredAdventureLevelCompleted
|
pt.requiredAdventureLevelCompleted as requiredAdventureLevelCompleted
|
||||||
FROM
|
FROM
|
||||||
PossibleTransformations pt
|
CardTransformations pt
|
||||||
JOIN CardCharacter c on pt.toCharaId = c.id
|
JOIN CardCharacter c on pt.toCharaId = c.id
|
||||||
JOIN Sprite s ON s.id = c.spriteId
|
JOIN Sprite s ON s.id = c.spriteId
|
||||||
LEFT JOIN Dex d ON d.id = pt.toCharaId
|
LEFT JOIN Dex d ON d.id = pt.toCharaId
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package com.github.nacabaro.vbhelper.daos
|
|||||||
import androidx.room.Dao
|
import androidx.room.Dao
|
||||||
import androidx.room.Query
|
import androidx.room.Query
|
||||||
import com.github.nacabaro.vbhelper.dtos.ItemDtos
|
import com.github.nacabaro.vbhelper.dtos.ItemDtos
|
||||||
import kotlinx.coroutines.flow.Flow
|
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface ItemDao {
|
interface ItemDao {
|
||||||
@@ -14,7 +13,7 @@ interface ItemDao {
|
|||||||
ORDER BY Items.itemIcon ASC
|
ORDER BY Items.itemIcon ASC
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
fun getAllItems(): Flow<List<ItemDtos.ItemsWithQuantities>>
|
suspend fun getAllItems(): List<ItemDtos.ItemsWithQuantities>
|
||||||
|
|
||||||
@Query(
|
@Query(
|
||||||
"""
|
"""
|
||||||
@@ -23,7 +22,7 @@ interface ItemDao {
|
|||||||
WHERE quantity > 0
|
WHERE quantity > 0
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
fun getAllUserItems(): Flow<List<ItemDtos.ItemsWithQuantities>>
|
suspend fun getAllUserItems(): List<ItemDtos.ItemsWithQuantities>
|
||||||
|
|
||||||
@Query(
|
@Query(
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import androidx.room.Database
|
|||||||
import androidx.room.RoomDatabase
|
import androidx.room.RoomDatabase
|
||||||
import com.github.nacabaro.vbhelper.daos.AdventureDao
|
import com.github.nacabaro.vbhelper.daos.AdventureDao
|
||||||
import com.github.nacabaro.vbhelper.daos.CardAdventureDao
|
import com.github.nacabaro.vbhelper.daos.CardAdventureDao
|
||||||
|
import com.github.nacabaro.vbhelper.daos.CardBackgroundDao
|
||||||
import com.github.nacabaro.vbhelper.daos.CharacterDao
|
import com.github.nacabaro.vbhelper.daos.CharacterDao
|
||||||
import com.github.nacabaro.vbhelper.daos.DexDao
|
import com.github.nacabaro.vbhelper.daos.DexDao
|
||||||
import com.github.nacabaro.vbhelper.daos.CardDao
|
import com.github.nacabaro.vbhelper.daos.CardDao
|
||||||
@@ -13,13 +14,14 @@ import com.github.nacabaro.vbhelper.daos.ItemDao
|
|||||||
import com.github.nacabaro.vbhelper.daos.SpecialMissionDao
|
import com.github.nacabaro.vbhelper.daos.SpecialMissionDao
|
||||||
import com.github.nacabaro.vbhelper.daos.SpriteDao
|
import com.github.nacabaro.vbhelper.daos.SpriteDao
|
||||||
import com.github.nacabaro.vbhelper.daos.UserCharacterDao
|
import com.github.nacabaro.vbhelper.daos.UserCharacterDao
|
||||||
import com.github.nacabaro.vbhelper.domain.card.Background
|
import com.github.nacabaro.vbhelper.domain.card.CardBackground
|
||||||
import com.github.nacabaro.vbhelper.domain.card.CardCharacter
|
import com.github.nacabaro.vbhelper.domain.card.CardCharacter
|
||||||
import com.github.nacabaro.vbhelper.domain.card.Card
|
import com.github.nacabaro.vbhelper.domain.card.Card
|
||||||
import com.github.nacabaro.vbhelper.domain.card.CardAdventure
|
import com.github.nacabaro.vbhelper.domain.card.CardAdventure
|
||||||
import com.github.nacabaro.vbhelper.domain.card.CardFusions
|
import com.github.nacabaro.vbhelper.domain.card.CardFusions
|
||||||
import com.github.nacabaro.vbhelper.domain.card.CardProgress
|
import com.github.nacabaro.vbhelper.domain.card.CardProgress
|
||||||
import com.github.nacabaro.vbhelper.domain.card.PossibleTransformations
|
import com.github.nacabaro.vbhelper.domain.card.CardSprites
|
||||||
|
import com.github.nacabaro.vbhelper.domain.card.CardTransformations
|
||||||
import com.github.nacabaro.vbhelper.domain.characters.Sprite
|
import com.github.nacabaro.vbhelper.domain.characters.Sprite
|
||||||
import com.github.nacabaro.vbhelper.domain.characters.Adventure
|
import com.github.nacabaro.vbhelper.domain.characters.Adventure
|
||||||
import com.github.nacabaro.vbhelper.domain.characters.Dex
|
import com.github.nacabaro.vbhelper.domain.characters.Dex
|
||||||
@@ -39,6 +41,7 @@ import com.github.nacabaro.vbhelper.domain.items.Items
|
|||||||
CardCharacter::class,
|
CardCharacter::class,
|
||||||
CardAdventure::class,
|
CardAdventure::class,
|
||||||
CardFusions::class,
|
CardFusions::class,
|
||||||
|
CardSprites::class,
|
||||||
Sprite::class,
|
Sprite::class,
|
||||||
UserCharacter::class,
|
UserCharacter::class,
|
||||||
BECharacterData::class,
|
BECharacterData::class,
|
||||||
@@ -49,8 +52,8 @@ import com.github.nacabaro.vbhelper.domain.items.Items
|
|||||||
Dex::class,
|
Dex::class,
|
||||||
Items::class,
|
Items::class,
|
||||||
Adventure::class,
|
Adventure::class,
|
||||||
Background::class,
|
CardBackground::class,
|
||||||
PossibleTransformations::class
|
CardTransformations::class
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
abstract class AppDatabase : RoomDatabase() {
|
abstract class AppDatabase : RoomDatabase() {
|
||||||
@@ -65,4 +68,5 @@ abstract class AppDatabase : RoomDatabase() {
|
|||||||
abstract fun specialMissionDao(): SpecialMissionDao
|
abstract fun specialMissionDao(): SpecialMissionDao
|
||||||
abstract fun cardAdventureDao(): CardAdventureDao
|
abstract fun cardAdventureDao(): CardAdventureDao
|
||||||
abstract fun cardFusionsDao(): CardFusionsDao
|
abstract fun cardFusionsDao(): CardFusionsDao
|
||||||
|
abstract fun cardBackgroundDao(): CardBackgroundDao
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,9 @@
|
|||||||
package com.github.nacabaro.vbhelper.di
|
package com.github.nacabaro.vbhelper.di
|
||||||
|
|
||||||
import com.github.nacabaro.vbhelper.database.AppDatabase
|
import com.github.nacabaro.vbhelper.database.AppDatabase
|
||||||
import com.github.nacabaro.vbhelper.source.CurrencyRepository
|
|
||||||
import com.github.nacabaro.vbhelper.source.DataStoreSecretsRepository
|
import com.github.nacabaro.vbhelper.source.DataStoreSecretsRepository
|
||||||
|
|
||||||
interface AppContainer {
|
interface AppContainer {
|
||||||
val db: AppDatabase
|
val db: AppDatabase
|
||||||
val dataStoreSecretsRepository: DataStoreSecretsRepository
|
val dataStoreSecretsRepository: DataStoreSecretsRepository
|
||||||
val currencyRepository: CurrencyRepository
|
|
||||||
}
|
}
|
||||||
@@ -1,27 +1,20 @@
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.datastore.core.DataStore
|
import androidx.datastore.core.DataStore
|
||||||
import androidx.datastore.dataStore
|
import androidx.datastore.dataStore
|
||||||
import androidx.datastore.preferences.core.Preferences
|
|
||||||
import androidx.datastore.preferences.preferencesDataStore
|
|
||||||
import androidx.room.Room
|
import androidx.room.Room
|
||||||
import com.github.nacabaro.vbhelper.database.AppDatabase
|
import com.github.nacabaro.vbhelper.database.AppDatabase
|
||||||
import com.github.nacabaro.vbhelper.di.AppContainer
|
import com.github.nacabaro.vbhelper.di.AppContainer
|
||||||
import com.github.nacabaro.vbhelper.source.CurrencyRepository
|
|
||||||
import com.github.nacabaro.vbhelper.source.DataStoreSecretsRepository
|
import com.github.nacabaro.vbhelper.source.DataStoreSecretsRepository
|
||||||
import com.github.nacabaro.vbhelper.source.SecretsSerializer
|
import com.github.nacabaro.vbhelper.source.SecretsSerializer
|
||||||
import com.github.nacabaro.vbhelper.source.proto.Secrets
|
import com.github.nacabaro.vbhelper.source.proto.Secrets
|
||||||
|
|
||||||
private const val SECRETS_DATA_STORE_NAME = "secrets.pb"
|
private const val SECRETS_DATA_STORE_NAME = "secrets.pb"
|
||||||
private const val USER_PREFERENCES_NAME = "user_preferences"
|
|
||||||
val Context.secretsStore: DataStore<Secrets> by dataStore(
|
val Context.secretsStore: DataStore<Secrets> by dataStore(
|
||||||
fileName = SECRETS_DATA_STORE_NAME,
|
fileName = SECRETS_DATA_STORE_NAME,
|
||||||
serializer = SecretsSerializer
|
serializer = SecretsSerializer
|
||||||
)
|
)
|
||||||
|
|
||||||
val Context.currencyStore: DataStore<Preferences> by preferencesDataStore(
|
|
||||||
name = USER_PREFERENCES_NAME
|
|
||||||
)
|
|
||||||
|
|
||||||
class DefaultAppContainer(private val context: Context) : AppContainer {
|
class DefaultAppContainer(private val context: Context) : AppContainer {
|
||||||
|
|
||||||
override val db: AppDatabase by lazy {
|
override val db: AppDatabase by lazy {
|
||||||
@@ -36,6 +29,5 @@ class DefaultAppContainer(private val context: Context) : AppContainer {
|
|||||||
|
|
||||||
override val dataStoreSecretsRepository = DataStoreSecretsRepository(context.secretsStore)
|
override val dataStoreSecretsRepository = DataStoreSecretsRepository(context.secretsStore)
|
||||||
|
|
||||||
override val currencyRepository = CurrencyRepository(context.currencyStore)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
package com.github.nacabaro.vbhelper.domain
|
|
||||||
|
|
||||||
import androidx.room.Entity
|
|
||||||
import androidx.room.ForeignKey
|
|
||||||
import androidx.room.PrimaryKey
|
|
||||||
|
|
||||||
@Entity(
|
|
||||||
foreignKeys = [
|
|
||||||
ForeignKey(
|
|
||||||
entity = Character::class,
|
|
||||||
parentColumns = ["id"],
|
|
||||||
childColumns = ["monId"],
|
|
||||||
onDelete = ForeignKey.CASCADE
|
|
||||||
),
|
|
||||||
ForeignKey(
|
|
||||||
entity = Character::class,
|
|
||||||
parentColumns = ["id"],
|
|
||||||
childColumns = ["nextMon"],
|
|
||||||
onDelete = ForeignKey.CASCADE
|
|
||||||
)
|
|
||||||
]
|
|
||||||
)
|
|
||||||
data class Evolutions(
|
|
||||||
@PrimaryKey val monId: Int,
|
|
||||||
@PrimaryKey val nextMon: Int,
|
|
||||||
val trophies: Int,
|
|
||||||
val vitals: Int,
|
|
||||||
val totalBattles: Int,
|
|
||||||
val winRate: Int // Does not need to be a floating point
|
|
||||||
)
|
|
||||||
+2
-2
@@ -14,8 +14,8 @@ import androidx.room.PrimaryKey
|
|||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
data class Background (
|
data class CardBackground (
|
||||||
@PrimaryKey(autoGenerate = true) val id: Long,
|
@PrimaryKey(autoGenerate = true) val id: Long = 0,
|
||||||
val cardId: Long,
|
val cardId: Long,
|
||||||
val background: ByteArray,
|
val background: ByteArray,
|
||||||
val backgroundWidth: Int,
|
val backgroundWidth: Int,
|
||||||
@@ -15,25 +15,25 @@ import androidx.room.PrimaryKey
|
|||||||
ForeignKey(
|
ForeignKey(
|
||||||
entity = CardCharacter::class,
|
entity = CardCharacter::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["attribute1Fusion"],
|
childColumns = ["toVirusFusion"],
|
||||||
onDelete = ForeignKey.CASCADE
|
onDelete = ForeignKey.CASCADE
|
||||||
),
|
),
|
||||||
ForeignKey(
|
ForeignKey(
|
||||||
entity = CardCharacter::class,
|
entity = CardCharacter::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["attribute2Fusion"],
|
childColumns = ["toDataFusion"],
|
||||||
onDelete = ForeignKey.CASCADE
|
onDelete = ForeignKey.CASCADE
|
||||||
),
|
),
|
||||||
ForeignKey(
|
ForeignKey(
|
||||||
entity = CardCharacter::class,
|
entity = CardCharacter::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["attribute3Fusion"],
|
childColumns = ["toVaccineFusion"],
|
||||||
onDelete = ForeignKey.CASCADE
|
onDelete = ForeignKey.CASCADE
|
||||||
),
|
),
|
||||||
ForeignKey(
|
ForeignKey(
|
||||||
entity = CardCharacter::class,
|
entity = CardCharacter::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["attribute4Fusion"],
|
childColumns = ["toFreeFusion"],
|
||||||
onDelete = ForeignKey.CASCADE
|
onDelete = ForeignKey.CASCADE
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
@@ -41,8 +41,8 @@ import androidx.room.PrimaryKey
|
|||||||
data class CardFusions(
|
data class CardFusions(
|
||||||
@PrimaryKey(autoGenerate = true) val id: Long,
|
@PrimaryKey(autoGenerate = true) val id: Long,
|
||||||
val fromCharaId: Long,
|
val fromCharaId: Long,
|
||||||
val attribute1Fusion: Long?,
|
val toVirusFusion: Long?,
|
||||||
val attribute2Fusion: Long?,
|
val toDataFusion: Long?,
|
||||||
val attribute3Fusion: Long?,
|
val toVaccineFusion: Long?,
|
||||||
val attribute4Fusion: Long?
|
val toFreeFusion: Long?
|
||||||
)
|
)
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.github.nacabaro.vbhelper.domain.card
|
||||||
|
|
||||||
|
import androidx.room.Entity
|
||||||
|
import androidx.room.PrimaryKey
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
data class CardSprites(
|
||||||
|
@PrimaryKey(autoGenerate = true) val id: Long = 0,
|
||||||
|
val sprite: ByteArray,
|
||||||
|
val width: Int,
|
||||||
|
val height: Int
|
||||||
|
)
|
||||||
+1
-1
@@ -20,7 +20,7 @@ import androidx.room.PrimaryKey
|
|||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
data class PossibleTransformations (
|
data class CardTransformations (
|
||||||
@PrimaryKey(autoGenerate = true) val id: Long = 0,
|
@PrimaryKey(autoGenerate = true) val id: Long = 0,
|
||||||
var charaId: Long,
|
var charaId: Long,
|
||||||
val requiredVitals: Int,
|
val requiredVitals: Int,
|
||||||
@@ -38,8 +38,7 @@ object CharacterDtos {
|
|||||||
val cardId: Long,
|
val cardId: Long,
|
||||||
val charId: Int,
|
val charId: Int,
|
||||||
val stage: Int,
|
val stage: Int,
|
||||||
val attribute: NfcCharacter.Attribute,
|
val attribute: NfcCharacter.Attribute
|
||||||
val currentStage: Int
|
|
||||||
)
|
)
|
||||||
|
|
||||||
data class TransformationHistory(
|
data class TransformationHistory(
|
||||||
|
|||||||
-2
@@ -6,7 +6,6 @@ import androidx.lifecycle.lifecycleScope
|
|||||||
import com.github.nacabaro.vbhelper.di.VBHelper
|
import com.github.nacabaro.vbhelper.di.VBHelper
|
||||||
import com.github.nacabaro.vbhelper.dtos.ItemDtos
|
import com.github.nacabaro.vbhelper.dtos.ItemDtos
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.first
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
@@ -78,7 +77,6 @@ class AdventureScreenControllerImpl(
|
|||||||
val randomItem = database
|
val randomItem = database
|
||||||
.itemDao()
|
.itemDao()
|
||||||
.getAllItems()
|
.getAllItems()
|
||||||
.first()
|
|
||||||
.random()
|
.random()
|
||||||
|
|
||||||
val random = ((Random.nextFloat() * character.stage) + 3).roundToInt()
|
val random = ((Random.nextFloat() * character.stage) + 3).roundToInt()
|
||||||
|
|||||||
+2
-5
@@ -7,11 +7,8 @@ import androidx.compose.foundation.verticalScroll
|
|||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
|
||||||
import androidx.compose.runtime.mutableIntStateOf
|
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import com.github.nacabaro.vbhelper.components.TopBanner
|
import com.github.nacabaro.vbhelper.components.TopBanner
|
||||||
@@ -26,7 +23,7 @@ fun CardAdventureScreen(
|
|||||||
cardId: Long
|
cardId: Long
|
||||||
) {
|
) {
|
||||||
val cardAdventureMissions = remember { mutableStateOf(emptyList<CardDtos.CardAdventureWithSprites>()) }
|
val cardAdventureMissions = remember { mutableStateOf(emptyList<CardDtos.CardAdventureWithSprites>()) }
|
||||||
var currentCardAdventure by remember { mutableIntStateOf(0) }
|
var currentCardAdventure = remember { 0 }
|
||||||
|
|
||||||
LaunchedEffect(cardId) {
|
LaunchedEffect(cardId) {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
@@ -58,7 +55,7 @@ fun CardAdventureScreen(
|
|||||||
cardAdventureMissions.value.mapIndexed { index, it ->
|
cardAdventureMissions.value.mapIndexed { index, it ->
|
||||||
CardAdventureEntry(
|
CardAdventureEntry(
|
||||||
cardAdventureEntry = it,
|
cardAdventureEntry = it,
|
||||||
obscure = index > currentCardAdventure - 1
|
obscure = index > currentCardAdventure
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-2
@@ -5,7 +5,6 @@ import androidx.lifecycle.lifecycleScope
|
|||||||
import com.github.cfogrady.vbnfc.vb.SpecialMission
|
import com.github.cfogrady.vbnfc.vb.SpecialMission
|
||||||
import com.github.nacabaro.vbhelper.di.VBHelper
|
import com.github.nacabaro.vbhelper.di.VBHelper
|
||||||
import com.github.nacabaro.vbhelper.dtos.ItemDtos
|
import com.github.nacabaro.vbhelper.dtos.ItemDtos
|
||||||
import kotlinx.coroutines.flow.first
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
@@ -42,7 +41,6 @@ class HomeScreenControllerImpl(
|
|||||||
val randomItem = database
|
val randomItem = database
|
||||||
.itemDao()
|
.itemDao()
|
||||||
.getAllItems()
|
.getAllItems()
|
||||||
.first()
|
|
||||||
.random()
|
.random()
|
||||||
|
|
||||||
val randomItemAmount = (Random.nextFloat() * 5).roundToInt()
|
val randomItemAmount = (Random.nextFloat() * 5).roundToInt()
|
||||||
|
|||||||
@@ -1,164 +0,0 @@
|
|||||||
package com.github.nacabaro.vbhelper.screens.itemsScreen
|
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
|
||||||
import androidx.compose.foundation.layout.Box
|
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.Spacer
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.foundation.layout.size
|
|
||||||
import androidx.compose.material3.Button
|
|
||||||
import androidx.compose.material3.Card
|
|
||||||
import androidx.compose.material3.Icon
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.res.painterResource
|
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import androidx.compose.ui.window.Dialog
|
|
||||||
import androidx.compose.ui.window.DialogProperties
|
|
||||||
import com.github.nacabaro.vbhelper.R
|
|
||||||
import com.github.nacabaro.vbhelper.domain.items.ItemType
|
|
||||||
import com.github.nacabaro.vbhelper.dtos.ItemDtos
|
|
||||||
import com.github.nacabaro.vbhelper.ui.theme.VBHelperTheme
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun ItemDialog(
|
|
||||||
item: ItemDtos.ItemsWithQuantities,
|
|
||||||
onClickCancel: () -> Unit,
|
|
||||||
onClickUse: (() -> Unit)? = null,
|
|
||||||
onClickPurchase: (() -> Unit)? = null,
|
|
||||||
) {
|
|
||||||
Dialog(
|
|
||||||
onDismissRequest = onClickCancel,
|
|
||||||
properties = DialogProperties(
|
|
||||||
dismissOnBackPress = true,
|
|
||||||
dismissOnClickOutside = true
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Card (
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(16.dp)
|
|
||||||
) {
|
|
||||||
Column (
|
|
||||||
modifier = Modifier
|
|
||||||
.padding(16.dp)
|
|
||||||
) {
|
|
||||||
Row {
|
|
||||||
Box(modifier = Modifier) {
|
|
||||||
// Background image (full size)
|
|
||||||
Icon(
|
|
||||||
painter = painterResource(id = getIconResource(item.itemIcon)),
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier
|
|
||||||
.size(96.dp)
|
|
||||||
.align(Alignment.Center)
|
|
||||||
)
|
|
||||||
Icon(
|
|
||||||
painter = painterResource(id = getLengthResource(item.itemLength)),
|
|
||||||
contentDescription = null,
|
|
||||||
tint = MaterialTheme.colorScheme.outline,
|
|
||||||
modifier = Modifier
|
|
||||||
.size(64.dp) // Set the size of the overlay image
|
|
||||||
.align(Alignment.BottomEnd) // Align to the top end (top-right corner)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Column (
|
|
||||||
modifier = Modifier
|
|
||||||
.padding(16.dp)
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
fontSize = MaterialTheme.typography.titleLarge.fontSize,
|
|
||||||
text = item.name,
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Text(
|
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
fontSize = MaterialTheme.typography.bodyMedium.fontSize,
|
|
||||||
fontFamily = MaterialTheme.typography.bodyMedium.fontFamily,
|
|
||||||
text = item.description,
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(4.dp)
|
|
||||||
)
|
|
||||||
if (onClickPurchase != null) {
|
|
||||||
Text(
|
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
fontSize = MaterialTheme.typography.bodySmall.fontSize,
|
|
||||||
fontFamily = MaterialTheme.typography.bodySmall.fontFamily,
|
|
||||||
text = "Costs ${item.price} credits",
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Text(
|
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
fontSize = MaterialTheme.typography.bodySmall.fontSize,
|
|
||||||
fontFamily = MaterialTheme.typography.bodySmall.fontFamily,
|
|
||||||
text = "You have ${item.quantity} of this item",
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
)
|
|
||||||
|
|
||||||
Row (
|
|
||||||
horizontalArrangement = Arrangement.Center,
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
) {
|
|
||||||
if (onClickUse != null) {
|
|
||||||
Button(
|
|
||||||
onClick = onClickUse
|
|
||||||
) {
|
|
||||||
Text("Use item")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (onClickPurchase != null) {
|
|
||||||
Button(
|
|
||||||
onClick = onClickPurchase
|
|
||||||
) {
|
|
||||||
Text("Purchase")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.size(8.dp))
|
|
||||||
Button(
|
|
||||||
onClick = onClickCancel
|
|
||||||
) {
|
|
||||||
Text("Cancel")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
@Preview(showBackground = true)
|
|
||||||
fun PreviewItemDialog() {
|
|
||||||
VBHelperTheme {
|
|
||||||
ItemDialog(
|
|
||||||
item = ItemDtos.ItemsWithQuantities(
|
|
||||||
name = "AP Training x3 (60 min)",
|
|
||||||
description = "Boosts AP during training (for 60 minutes)",
|
|
||||||
itemIcon = R.drawable.baseline_attack_24,
|
|
||||||
itemLength = R.drawable.baseline_60_min_timer,
|
|
||||||
quantity = 19,
|
|
||||||
id = 1,
|
|
||||||
price = 500,
|
|
||||||
itemType = ItemType.BEITEM
|
|
||||||
),
|
|
||||||
onClickUse = { },
|
|
||||||
onClickCancel = { }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +1,36 @@
|
|||||||
package com.github.nacabaro.vbhelper.screens.itemsScreen
|
package com.github.nacabaro.vbhelper.screens.itemsScreen
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.aspectRatio
|
import androidx.compose.foundation.layout.aspectRatio
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.material3.Button
|
||||||
import androidx.compose.material3.Card
|
import androidx.compose.material3.Card
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.github.nacabaro.vbhelper.dtos.ItemDtos
|
import androidx.compose.ui.window.Dialog
|
||||||
|
import androidx.compose.ui.window.DialogProperties
|
||||||
|
import com.github.nacabaro.vbhelper.R
|
||||||
|
import com.github.nacabaro.vbhelper.ui.theme.VBHelperTheme
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ItemElement(
|
fun ItemElement(
|
||||||
item: ItemDtos.ItemsWithQuantities,
|
itemIcon: Int,
|
||||||
|
lengthIcon: Int,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
onClick: (() -> Unit) = { }
|
onClick: (() -> Unit) = { }
|
||||||
) {
|
) {
|
||||||
@@ -28,7 +41,7 @@ fun ItemElement(
|
|||||||
) {
|
) {
|
||||||
Box(modifier = Modifier.fillMaxSize()) {
|
Box(modifier = Modifier.fillMaxSize()) {
|
||||||
Icon(
|
Icon(
|
||||||
painter = painterResource(id = getIconResource(item.itemIcon)),
|
painter = painterResource(id = itemIcon),
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.size(96.dp)
|
.size(96.dp)
|
||||||
@@ -36,14 +49,164 @@ fun ItemElement(
|
|||||||
.padding(16.dp)
|
.padding(16.dp)
|
||||||
)
|
)
|
||||||
Icon(
|
Icon(
|
||||||
painter = painterResource(id = getLengthResource(item.itemLength)),
|
painter = painterResource(id = lengthIcon),
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
tint = MaterialTheme.colorScheme.surfaceTint,
|
tint = MaterialTheme.colorScheme.surfaceTint,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.size(48.dp)
|
.size(48.dp) // Set the size of the overlay image
|
||||||
.align(Alignment.TopStart)
|
.align(Alignment.TopStart) // Align to the top end (top-right corner)
|
||||||
.padding(8.dp)
|
.padding(8.dp)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun ItemDialog(
|
||||||
|
name: String,
|
||||||
|
description: String,
|
||||||
|
itemIcon: Int,
|
||||||
|
lengthIcon: Int,
|
||||||
|
amount: Int,
|
||||||
|
onClickUse: () -> Unit,
|
||||||
|
onClickCancel: () -> Unit
|
||||||
|
) {
|
||||||
|
Dialog(
|
||||||
|
onDismissRequest = onClickCancel,
|
||||||
|
properties = DialogProperties(
|
||||||
|
dismissOnBackPress = true,
|
||||||
|
dismissOnClickOutside = true
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
Card (
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(16.dp)
|
||||||
|
) {
|
||||||
|
Column (
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(16.dp)
|
||||||
|
) {
|
||||||
|
Row {
|
||||||
|
Box(modifier = Modifier) {
|
||||||
|
// Background image (full size)
|
||||||
|
Icon(
|
||||||
|
painter = painterResource(id = itemIcon),
|
||||||
|
contentDescription = null,
|
||||||
|
modifier = Modifier
|
||||||
|
.size(96.dp)
|
||||||
|
.align(Alignment.Center)
|
||||||
|
)
|
||||||
|
Icon(
|
||||||
|
painter = painterResource(id = lengthIcon),
|
||||||
|
contentDescription = null,
|
||||||
|
tint = MaterialTheme.colorScheme.outline,
|
||||||
|
modifier = Modifier
|
||||||
|
.size(64.dp) // Set the size of the overlay image
|
||||||
|
.align(Alignment.BottomEnd) // Align to the top end (top-right corner)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Column (
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(16.dp)
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
fontSize = MaterialTheme.typography.titleLarge.fontSize,
|
||||||
|
text = name,
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Text(
|
||||||
|
textAlign = TextAlign.Center,
|
||||||
|
fontSize = MaterialTheme.typography.bodyMedium.fontSize,
|
||||||
|
fontFamily = MaterialTheme.typography.bodyMedium.fontFamily,
|
||||||
|
text = description,
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(4.dp)
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
textAlign = TextAlign.Center,
|
||||||
|
fontSize = MaterialTheme.typography.bodySmall.fontSize,
|
||||||
|
fontFamily = MaterialTheme.typography.bodySmall.fontFamily,
|
||||||
|
text = "You have $amount of this item",
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(8.dp)
|
||||||
|
)
|
||||||
|
Row (
|
||||||
|
horizontalArrangement = Arrangement.Center,
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
) {
|
||||||
|
Button(
|
||||||
|
onClick = onClickUse
|
||||||
|
) {
|
||||||
|
Text("Use item")
|
||||||
|
}
|
||||||
|
Spacer(modifier = Modifier.size(8.dp))
|
||||||
|
Button(
|
||||||
|
onClick = onClickCancel
|
||||||
|
) {
|
||||||
|
Text("Cancel")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getIconResource(index: Int): Int {
|
||||||
|
return when (index) {
|
||||||
|
ItemsScreenControllerImpl.ItemTypes.PPTraining.id -> R.drawable.baseline_agility_24
|
||||||
|
ItemsScreenControllerImpl.ItemTypes.APTraining.id -> R.drawable.baseline_attack_24
|
||||||
|
ItemsScreenControllerImpl.ItemTypes.HPTraining.id -> R.drawable.baseline_shield_24
|
||||||
|
ItemsScreenControllerImpl.ItemTypes.BPTraining.id -> R.drawable.baseline_trophy_24
|
||||||
|
ItemsScreenControllerImpl.ItemTypes.AllTraining.id -> R.drawable.baseline_arrow_up_24
|
||||||
|
6 -> R.drawable.baseline_timer_24
|
||||||
|
7 -> R.drawable.baseline_rank_24
|
||||||
|
8 -> R.drawable.baseline_vitals_24
|
||||||
|
else -> R.drawable.baseline_question_mark_24
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getLengthResource(index: Int): Int {
|
||||||
|
return when (index) {
|
||||||
|
15 -> R.drawable.baseline_15_min_timer
|
||||||
|
30 -> R.drawable.baseline_30_min_timer
|
||||||
|
60 -> R.drawable.baseline_60_min_timer
|
||||||
|
-60 -> R.drawable.baseline_60_min_timer
|
||||||
|
300 -> R.drawable.baseline_5_hour_timer
|
||||||
|
600 -> R.drawable.baseline_10_hour_timer
|
||||||
|
-720 -> R.drawable.baseline_12_hour_timer
|
||||||
|
-1440 -> R.drawable.baseline_24_hour_timer
|
||||||
|
6000 -> R.drawable.baseline_reset_24
|
||||||
|
1000 -> R.drawable.baseline_single_arrow_up
|
||||||
|
2500 -> R.drawable.baseline_double_arrow_up
|
||||||
|
5000 -> R.drawable.baseline_triple_arrow_up
|
||||||
|
9999 -> R.drawable.baseline_health_24
|
||||||
|
-500 -> R.drawable.baseline_single_arrow_down
|
||||||
|
-1000 -> R.drawable.baseline_double_arrow_down
|
||||||
|
-2500 -> R.drawable.baseline_triple_arrow_down
|
||||||
|
-9999 -> R.drawable.baseline_reset_24
|
||||||
|
else -> R.drawable.baseline_question_mark_24
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
@Preview(showBackground = true)
|
||||||
|
fun PreviewItemDialog() {
|
||||||
|
VBHelperTheme {
|
||||||
|
ItemDialog(
|
||||||
|
name = "AP Training x3 (60 min)",
|
||||||
|
description = "Boosts AP during training (for 60 minutes)",
|
||||||
|
itemIcon = R.drawable.baseline_attack_24,
|
||||||
|
lengthIcon = R.drawable.baseline_60_min_timer,
|
||||||
|
onClickUse = { },
|
||||||
|
onClickCancel = { },
|
||||||
|
amount = 19
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
package com.github.nacabaro.vbhelper.screens.itemsScreen
|
|
||||||
|
|
||||||
import com.github.nacabaro.vbhelper.R
|
|
||||||
|
|
||||||
fun getIconResource(index: Int): Int {
|
|
||||||
return when (index) {
|
|
||||||
ItemsScreenControllerImpl.ItemTypes.PPTraining.id -> R.drawable.baseline_agility_24
|
|
||||||
ItemsScreenControllerImpl.ItemTypes.APTraining.id -> R.drawable.baseline_attack_24
|
|
||||||
ItemsScreenControllerImpl.ItemTypes.HPTraining.id -> R.drawable.baseline_shield_24
|
|
||||||
ItemsScreenControllerImpl.ItemTypes.BPTraining.id -> R.drawable.baseline_trophy_24
|
|
||||||
ItemsScreenControllerImpl.ItemTypes.AllTraining.id -> R.drawable.baseline_arrow_up_24
|
|
||||||
6 -> R.drawable.baseline_timer_24
|
|
||||||
7 -> R.drawable.baseline_rank_24
|
|
||||||
8 -> R.drawable.baseline_vitals_24
|
|
||||||
else -> R.drawable.baseline_question_mark_24
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getLengthResource(index: Int): Int {
|
|
||||||
return when (index) {
|
|
||||||
15 -> R.drawable.baseline_15_min_timer
|
|
||||||
30 -> R.drawable.baseline_30_min_timer
|
|
||||||
60 -> R.drawable.baseline_60_min_timer
|
|
||||||
-60 -> R.drawable.baseline_60_min_timer
|
|
||||||
300 -> R.drawable.baseline_5_hour_timer
|
|
||||||
600 -> R.drawable.baseline_10_hour_timer
|
|
||||||
-720 -> R.drawable.baseline_12_hour_timer
|
|
||||||
-1440 -> R.drawable.baseline_24_hour_timer
|
|
||||||
6000 -> R.drawable.baseline_reset_24
|
|
||||||
1000 -> R.drawable.baseline_single_arrow_up
|
|
||||||
2500 -> R.drawable.baseline_double_arrow_up
|
|
||||||
5000 -> R.drawable.baseline_triple_arrow_up
|
|
||||||
9999 -> R.drawable.baseline_health_24
|
|
||||||
-500 -> R.drawable.baseline_single_arrow_down
|
|
||||||
-1000 -> R.drawable.baseline_double_arrow_down
|
|
||||||
-2500 -> R.drawable.baseline_triple_arrow_down
|
|
||||||
-9999 -> R.drawable.baseline_reset_24
|
|
||||||
else -> R.drawable.baseline_question_mark_24
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +1,25 @@
|
|||||||
package com.github.nacabaro.vbhelper.screens.itemsScreen
|
package com.github.nacabaro.vbhelper.screens.itemsScreen
|
||||||
|
|
||||||
import android.widget.Toast
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.lazy.grid.GridCells
|
import androidx.compose.foundation.lazy.grid.GridCells
|
||||||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||||
import androidx.compose.foundation.lazy.grid.items
|
import androidx.compose.foundation.lazy.grid.items
|
||||||
import androidx.compose.material3.Card
|
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import com.github.nacabaro.vbhelper.database.AppDatabase
|
|
||||||
import com.github.nacabaro.vbhelper.di.VBHelper
|
import com.github.nacabaro.vbhelper.di.VBHelper
|
||||||
import com.github.nacabaro.vbhelper.dtos.ItemDtos
|
import com.github.nacabaro.vbhelper.dtos.ItemDtos
|
||||||
import com.github.nacabaro.vbhelper.source.CurrencyRepository
|
|
||||||
import com.github.nacabaro.vbhelper.source.ItemsRepository
|
import com.github.nacabaro.vbhelper.source.ItemsRepository
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ItemsStore(
|
fun ItemsStore(
|
||||||
@@ -37,98 +27,45 @@ fun ItemsStore(
|
|||||||
) {
|
) {
|
||||||
val application = LocalContext.current.applicationContext as VBHelper
|
val application = LocalContext.current.applicationContext as VBHelper
|
||||||
val itemsRepository = ItemsRepository(application.container.db)
|
val itemsRepository = ItemsRepository(application.container.db)
|
||||||
val myItems by itemsRepository.getAllItems().collectAsState(emptyList())
|
val myItems = remember { mutableStateOf(emptyList<ItemDtos.ItemsWithQuantities>()) }
|
||||||
|
|
||||||
var selectedElementIndex by remember { mutableStateOf<Int?>(null) }
|
var selectedElementIndex by remember { mutableStateOf<Int?>(null) }
|
||||||
|
|
||||||
val currencyRepository = application.container.currencyRepository
|
LaunchedEffect(itemsRepository) {
|
||||||
val currentCurrency = currencyRepository.currencyValue.collectAsState(0)
|
withContext(Dispatchers.IO) {
|
||||||
|
myItems.value = itemsRepository.getAllItems()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val scope = rememberCoroutineScope()
|
if (myItems.value.isEmpty()) {
|
||||||
|
|
||||||
if (myItems.isEmpty()) {
|
|
||||||
Column(
|
|
||||||
verticalArrangement = Arrangement.Center,
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
modifier = Modifier.fillMaxSize()
|
|
||||||
) {
|
|
||||||
Text("No items")
|
Text("No items")
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Column() {
|
|
||||||
Card(
|
|
||||||
modifier = Modifier
|
|
||||||
.padding(8.dp)
|
|
||||||
.fillMaxWidth()
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = "${currentCurrency.value} credits",
|
|
||||||
modifier = Modifier
|
|
||||||
.padding(8.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
LazyVerticalGrid(
|
LazyVerticalGrid(
|
||||||
columns = GridCells.Fixed(3),
|
columns = GridCells.Fixed(3),
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
) {
|
) {
|
||||||
items(myItems) { index ->
|
items(myItems.value) { index ->
|
||||||
ItemElement(
|
ItemElement(
|
||||||
item = index,
|
itemIcon = getIconResource(index.itemIcon),
|
||||||
|
lengthIcon = getLengthResource(index.itemLength),
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(8.dp),
|
.padding(8.dp),
|
||||||
onClick = {
|
onClick = {
|
||||||
selectedElementIndex = myItems.indexOf(index)
|
selectedElementIndex = myItems.value.indexOf(index)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (selectedElementIndex != null) {
|
if (selectedElementIndex != null) {
|
||||||
ItemDialog(
|
ItemDialog(
|
||||||
item = myItems[selectedElementIndex!!],
|
name = myItems.value[selectedElementIndex!!].name,
|
||||||
onClickPurchase = {
|
description = myItems.value[selectedElementIndex!!].description,
|
||||||
scope.launch {
|
itemIcon = getIconResource(myItems.value[selectedElementIndex!!].itemIcon),
|
||||||
Toast.makeText(
|
lengthIcon = getLengthResource(myItems.value[selectedElementIndex!!].itemLength),
|
||||||
application.applicationContext,
|
amount = myItems.value[selectedElementIndex!!].quantity,
|
||||||
purchaseItem(
|
onClickUse = { },
|
||||||
application.container.db,
|
|
||||||
myItems[selectedElementIndex!!],
|
|
||||||
currencyRepository
|
|
||||||
),
|
|
||||||
Toast.LENGTH_SHORT
|
|
||||||
).show(
|
|
||||||
)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onClickCancel = { selectedElementIndex = null }
|
onClickCancel = { selectedElementIndex = null }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun purchaseItem(
|
|
||||||
db: AppDatabase,
|
|
||||||
item: ItemDtos.ItemsWithQuantities,
|
|
||||||
currencyRepository: CurrencyRepository
|
|
||||||
): String {
|
|
||||||
if (currencyRepository.currencyValue.first() < item.price) {
|
|
||||||
return "Not enough credits"
|
|
||||||
} else {
|
|
||||||
db
|
|
||||||
.itemDao()
|
|
||||||
.purchaseItem(
|
|
||||||
item.id,
|
|
||||||
1
|
|
||||||
)
|
|
||||||
|
|
||||||
currencyRepository
|
|
||||||
.setCurrencyValue(
|
|
||||||
currencyRepository.currencyValue.first() - item.price
|
|
||||||
)
|
|
||||||
|
|
||||||
return "Purchase successful!"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,7 @@ import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
|||||||
import androidx.compose.foundation.lazy.grid.items
|
import androidx.compose.foundation.lazy.grid.items
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
@@ -20,8 +20,11 @@ import androidx.compose.ui.platform.LocalContext
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import com.github.nacabaro.vbhelper.di.VBHelper
|
import com.github.nacabaro.vbhelper.di.VBHelper
|
||||||
|
import com.github.nacabaro.vbhelper.dtos.ItemDtos
|
||||||
import com.github.nacabaro.vbhelper.navigation.NavigationItems
|
import com.github.nacabaro.vbhelper.navigation.NavigationItems
|
||||||
import com.github.nacabaro.vbhelper.source.ItemsRepository
|
import com.github.nacabaro.vbhelper.source.ItemsRepository
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun MyItems(
|
fun MyItems(
|
||||||
@@ -29,11 +32,16 @@ fun MyItems(
|
|||||||
) {
|
) {
|
||||||
val application = LocalContext.current.applicationContext as VBHelper
|
val application = LocalContext.current.applicationContext as VBHelper
|
||||||
val itemsRepository = ItemsRepository(application.container.db)
|
val itemsRepository = ItemsRepository(application.container.db)
|
||||||
val myItems by itemsRepository.getUserItems().collectAsState(emptyList())
|
val myItems = remember { mutableStateOf(emptyList<ItemDtos.ItemsWithQuantities>()) }
|
||||||
|
|
||||||
var selectedElementIndex by remember { mutableStateOf<Int?>(null) }
|
var selectedElementIndex by remember { mutableStateOf<Int?>(null) }
|
||||||
|
|
||||||
if (myItems.isEmpty()) {
|
LaunchedEffect(itemsRepository) {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
myItems.value = itemsRepository.getUserItems()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (myItems.value.isEmpty()) {
|
||||||
Column(
|
Column(
|
||||||
verticalArrangement = Arrangement.Center,
|
verticalArrangement = Arrangement.Center,
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
@@ -46,13 +54,14 @@ fun MyItems(
|
|||||||
columns = GridCells.Fixed(3),
|
columns = GridCells.Fixed(3),
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
) {
|
) {
|
||||||
items(myItems) { index ->
|
items(myItems.value) { index ->
|
||||||
ItemElement(
|
ItemElement(
|
||||||
item = index,
|
itemIcon = getIconResource(index.itemIcon),
|
||||||
|
lengthIcon = getLengthResource(index.itemLength),
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(8.dp),
|
.padding(8.dp),
|
||||||
onClick = {
|
onClick = {
|
||||||
selectedElementIndex = myItems.indexOf(index)
|
selectedElementIndex = myItems.value.indexOf(index)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -60,7 +69,11 @@ fun MyItems(
|
|||||||
|
|
||||||
if (selectedElementIndex != null) {
|
if (selectedElementIndex != null) {
|
||||||
ItemDialog(
|
ItemDialog(
|
||||||
item = myItems[selectedElementIndex!!],
|
name = myItems.value[selectedElementIndex!!].name,
|
||||||
|
description = myItems.value[selectedElementIndex!!].description,
|
||||||
|
itemIcon = getIconResource(myItems.value[selectedElementIndex!!].itemIcon),
|
||||||
|
lengthIcon = getLengthResource(myItems.value[selectedElementIndex!!].itemLength),
|
||||||
|
amount = myItems.value[selectedElementIndex!!].quantity,
|
||||||
onClickUse = {
|
onClickUse = {
|
||||||
navController
|
navController
|
||||||
.navigate(
|
.navigate(
|
||||||
@@ -68,7 +81,7 @@ fun MyItems(
|
|||||||
.ApplyItem.route
|
.ApplyItem.route
|
||||||
.replace(
|
.replace(
|
||||||
"{itemId}",
|
"{itemId}",
|
||||||
myItems[selectedElementIndex!!].id.toString()
|
myItems.value[selectedElementIndex!!].id.toString()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
selectedElementIndex = null
|
selectedElementIndex = null
|
||||||
|
|||||||
+7
-5
@@ -152,13 +152,15 @@ class FromNfcConverter (
|
|||||||
nfcCharacter: NfcCharacter,
|
nfcCharacter: NfcCharacter,
|
||||||
cardData: Card
|
cardData: Card
|
||||||
) {
|
) {
|
||||||
|
val currentCardProgress = CardProgress(
|
||||||
|
cardId = cardData.id,
|
||||||
|
currentStage = nfcCharacter.nextAdventureMissionStage.toInt(),
|
||||||
|
unlocked = nfcCharacter.nextAdventureMissionStage.toInt() > cardData.stageCount
|
||||||
|
)
|
||||||
|
|
||||||
database
|
database
|
||||||
.cardProgressDao()
|
.cardProgressDao()
|
||||||
.updateCardProgress(
|
.updateDimProgress(currentCardProgress)
|
||||||
currentStage = nfcCharacter.nextAdventureMissionStage.toInt(),
|
|
||||||
cardId = cardData.id,
|
|
||||||
unlocked = nfcCharacter.nextAdventureMissionStage.toInt() > cardData.stageCount,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+10
-4
@@ -38,10 +38,14 @@ class ToNfcConverter(
|
|||||||
.characterDao()
|
.characterDao()
|
||||||
.getCharacterInfo(userCharacter.charId)
|
.getCharacterInfo(userCharacter.charId)
|
||||||
|
|
||||||
|
val currentCardStage = database
|
||||||
|
.cardProgressDao()
|
||||||
|
.getCardProgress(characterInfo.cardId)
|
||||||
|
|
||||||
return if (userCharacter.characterType == DeviceType.BEDevice)
|
return if (userCharacter.characterType == DeviceType.BEDevice)
|
||||||
nfcToBENfc(characterId, characterInfo, userCharacter)
|
nfcToBENfc(characterId, characterInfo, currentCardStage, userCharacter)
|
||||||
else
|
else
|
||||||
nfcToVBNfc(characterId, characterInfo, userCharacter)
|
nfcToVBNfc(characterId, characterInfo, currentCardStage, userCharacter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -49,6 +53,7 @@ class ToNfcConverter(
|
|||||||
private suspend fun nfcToVBNfc(
|
private suspend fun nfcToVBNfc(
|
||||||
characterId: Long,
|
characterId: Long,
|
||||||
characterInfo: CharacterDtos.CardCharacterInfo,
|
characterInfo: CharacterDtos.CardCharacterInfo,
|
||||||
|
currentCardStage: Int,
|
||||||
userCharacter: UserCharacter
|
userCharacter: UserCharacter
|
||||||
): VBNfcCharacter {
|
): VBNfcCharacter {
|
||||||
val vbData = database
|
val vbData = database
|
||||||
@@ -65,7 +70,7 @@ class ToNfcConverter(
|
|||||||
stage = characterInfo.stage.toByte(),
|
stage = characterInfo.stage.toByte(),
|
||||||
attribute = characterInfo.attribute,
|
attribute = characterInfo.attribute,
|
||||||
ageInDays = userCharacter.ageInDays.toByte(),
|
ageInDays = userCharacter.ageInDays.toByte(),
|
||||||
nextAdventureMissionStage = characterInfo.currentStage.toByte(),
|
nextAdventureMissionStage = currentCardStage.toByte(),
|
||||||
mood = userCharacter.mood.toByte(),
|
mood = userCharacter.mood.toByte(),
|
||||||
vitalPoints = userCharacter.vitalPoints.toUShort(),
|
vitalPoints = userCharacter.vitalPoints.toUShort(),
|
||||||
transformationCountdownInMinutes = userCharacter.transformationCountdown.toUShort(),
|
transformationCountdownInMinutes = userCharacter.transformationCountdown.toUShort(),
|
||||||
@@ -168,6 +173,7 @@ class ToNfcConverter(
|
|||||||
private suspend fun nfcToBENfc(
|
private suspend fun nfcToBENfc(
|
||||||
characterId: Long,
|
characterId: Long,
|
||||||
characterInfo: CharacterDtos.CardCharacterInfo,
|
characterInfo: CharacterDtos.CardCharacterInfo,
|
||||||
|
currentCardStage: Int,
|
||||||
userCharacter: UserCharacter
|
userCharacter: UserCharacter
|
||||||
): BENfcCharacter {
|
): BENfcCharacter {
|
||||||
val beData = database
|
val beData = database
|
||||||
@@ -182,7 +188,7 @@ class ToNfcConverter(
|
|||||||
stage = characterInfo.stage.toByte(),
|
stage = characterInfo.stage.toByte(),
|
||||||
attribute = characterInfo.attribute,
|
attribute = characterInfo.attribute,
|
||||||
ageInDays = userCharacter.ageInDays.toByte(),
|
ageInDays = userCharacter.ageInDays.toByte(),
|
||||||
nextAdventureMissionStage = characterInfo.currentStage.toByte(),
|
nextAdventureMissionStage = currentCardStage.toByte(),
|
||||||
mood = userCharacter.mood.toByte(),
|
mood = userCharacter.mood.toByte(),
|
||||||
vitalPoints = userCharacter.vitalPoints.toUShort(),
|
vitalPoints = userCharacter.vitalPoints.toUShort(),
|
||||||
itemEffectMentalStateValue = beData.itemEffectMentalStateValue.toByte(),
|
itemEffectMentalStateValue = beData.itemEffectMentalStateValue.toByte(),
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import androidx.compose.runtime.Composable
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import com.github.nacabaro.vbhelper.components.TopBanner
|
import com.github.nacabaro.vbhelper.components.TopBanner
|
||||||
|
import com.github.nacabaro.vbhelper.navigation.NavigationItems
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun CreditsScreen(
|
fun CreditsScreen(
|
||||||
@@ -19,6 +20,9 @@ fun CreditsScreen(
|
|||||||
text = "Credits",
|
text = "Credits",
|
||||||
onBackClick = {
|
onBackClick = {
|
||||||
navController.popBackStack()
|
navController.popBackStack()
|
||||||
|
},
|
||||||
|
onGearClick = {
|
||||||
|
navController.navigate(NavigationItems.Viewer.route)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|||||||
+60
-10
@@ -17,8 +17,10 @@ import com.github.nacabaro.vbhelper.database.AppDatabase
|
|||||||
import com.github.nacabaro.vbhelper.di.VBHelper
|
import com.github.nacabaro.vbhelper.di.VBHelper
|
||||||
import com.github.nacabaro.vbhelper.domain.characters.Sprite
|
import com.github.nacabaro.vbhelper.domain.characters.Sprite
|
||||||
import com.github.nacabaro.vbhelper.domain.card.Card
|
import com.github.nacabaro.vbhelper.domain.card.Card
|
||||||
|
import com.github.nacabaro.vbhelper.domain.card.CardBackground
|
||||||
import com.github.nacabaro.vbhelper.domain.card.CardProgress
|
import com.github.nacabaro.vbhelper.domain.card.CardProgress
|
||||||
import com.github.nacabaro.vbhelper.domain.card.CardCharacter
|
import com.github.nacabaro.vbhelper.domain.card.CardCharacter
|
||||||
|
import com.github.nacabaro.vbhelper.domain.card.CardSprites
|
||||||
import com.github.nacabaro.vbhelper.source.ApkSecretsImporter
|
import com.github.nacabaro.vbhelper.source.ApkSecretsImporter
|
||||||
import com.github.nacabaro.vbhelper.source.SecretsImporter
|
import com.github.nacabaro.vbhelper.source.SecretsImporter
|
||||||
import com.github.nacabaro.vbhelper.source.SecretsRepository
|
import com.github.nacabaro.vbhelper.source.SecretsRepository
|
||||||
@@ -215,7 +217,7 @@ class SettingsScreenControllerImpl(
|
|||||||
spriteHappy = card.spriteData.sprites[spriteCounter + 4].pixelData,
|
spriteHappy = card.spriteData.sprites[spriteCounter + 4].pixelData,
|
||||||
spriteSleep = card.spriteData.sprites[spriteCounter + 5].pixelData,
|
spriteSleep = card.spriteData.sprites[spriteCounter + 5].pixelData,
|
||||||
spriteAttack = card.spriteData.sprites[spriteCounter + 2].pixelData,
|
spriteAttack = card.spriteData.sprites[spriteCounter + 2].pixelData,
|
||||||
spriteDodge = card.spriteData.sprites[spriteCounter + 3].pixelData
|
spriteDodge = card.spriteData.sprites[spriteCounter + 3].pixelData,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
domainSprite = Sprite(
|
domainSprite = Sprite(
|
||||||
@@ -324,10 +326,10 @@ class SettingsScreenControllerImpl(
|
|||||||
.insertNewFusion(
|
.insertNewFusion(
|
||||||
cardId = cardId,
|
cardId = cardId,
|
||||||
fromCharaId = it.characterIndex,
|
fromCharaId = it.characterIndex,
|
||||||
toCharaIdAttr1 = it.attribute1Fusion,
|
toCharaIdVirus = it.attribute1Fusion,
|
||||||
toCharaIdAttr2 = it.attribute2Fusion,
|
toCharaIdData = it.attribute2Fusion,
|
||||||
toCharaIdAttr3 = it.attribute3Fusion,
|
toCharaIdVaccine = it.attribute3Fusion,
|
||||||
toCharaIdAttr4 = it.attribute4Fusion
|
toCharaIdFree = it.attribute4Fusion
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -336,15 +338,49 @@ class SettingsScreenControllerImpl(
|
|||||||
private fun updateCardProgress(
|
private fun updateCardProgress(
|
||||||
cardId: Long,
|
cardId: Long,
|
||||||
) {
|
) {
|
||||||
database
|
val cardProgress = CardProgress(
|
||||||
.cardProgressDao()
|
|
||||||
.insertCardProgress(
|
|
||||||
CardProgress(
|
|
||||||
cardId = cardId,
|
cardId = cardId,
|
||||||
currentStage = 1,
|
currentStage = 0,
|
||||||
unlocked = false
|
unlocked = false
|
||||||
)
|
)
|
||||||
|
|
||||||
|
database
|
||||||
|
.cardProgressDao()
|
||||||
|
.updateDimProgress(cardProgress)
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun importBackgrounds(
|
||||||
|
cardId: Long,
|
||||||
|
card: com.github.cfogrady.vb.dim.card.Card<*, *, *, *, *, *>
|
||||||
|
) {
|
||||||
|
val backgrounds = mutableListOf<CardBackground>()
|
||||||
|
|
||||||
|
if (card is DimCard) {
|
||||||
|
backgrounds.add(
|
||||||
|
CardBackground(
|
||||||
|
cardId = cardId,
|
||||||
|
background = card.spriteData.sprites[1].pixelData,
|
||||||
|
backgroundWidth = card.spriteData.sprites[1].width,
|
||||||
|
backgroundHeight = card.spriteData.sprites[1].height
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
} else if (card is BemCard) {
|
||||||
|
val possibleBackgroundsIds = listOf(1, 10, 30, 31, 32, 33)
|
||||||
|
for (id in possibleBackgroundsIds) {
|
||||||
|
backgrounds.add(
|
||||||
|
CardBackground(
|
||||||
|
cardId = cardId,
|
||||||
|
background = card.spriteData.sprites[id].pixelData,
|
||||||
|
backgroundWidth = card.spriteData.sprites[id].width,
|
||||||
|
backgroundHeight = card.spriteData.sprites[id].height
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
database
|
||||||
|
.cardBackgroundDao()
|
||||||
|
.insertCardBackground(*backgrounds.toTypedArray())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun importCard(uri: Uri) {
|
private fun importCard(uri: Uri) {
|
||||||
@@ -379,6 +415,20 @@ class SettingsScreenControllerImpl(
|
|||||||
importAdventureMissions(cardId, card)
|
importAdventureMissions(cardId, card)
|
||||||
|
|
||||||
importCardFusions(cardId, card)
|
importCardFusions(cardId, card)
|
||||||
|
|
||||||
|
importBackgrounds(cardId, card)
|
||||||
|
|
||||||
|
val cardSprites: List<CardSprites> = card.spriteData.sprites.map {
|
||||||
|
CardSprites(
|
||||||
|
sprite = it.pixelData,
|
||||||
|
width = it.width,
|
||||||
|
height = it.height
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
database
|
||||||
|
.cardDao()
|
||||||
|
.insertSprites(*cardSprites.toTypedArray())
|
||||||
}
|
}
|
||||||
|
|
||||||
inputStream?.close()
|
inputStream?.close()
|
||||||
|
|||||||
+3
-3
@@ -1,9 +1,9 @@
|
|||||||
package com.github.nacabaro.vbhelper.screens.spriteViewer
|
package com.github.nacabaro.vbhelper.screens.spriteViewer
|
||||||
|
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import com.github.nacabaro.vbhelper.domain.characters.Sprite
|
import com.github.nacabaro.vbhelper.domain.card.CardBackground
|
||||||
|
|
||||||
interface SpriteViewerController {
|
interface SpriteViewerController {
|
||||||
suspend fun getAllSprites(): List<Sprite>
|
suspend fun getAllSprites(): List<CardBackground>
|
||||||
fun convertToBitmap(sprites: List<Sprite>): List<Bitmap>
|
fun convertToBitmap(sprites: List<CardBackground>): List<Bitmap>
|
||||||
}
|
}
|
||||||
+7
-43
@@ -1,65 +1,29 @@
|
|||||||
package com.github.nacabaro.vbhelper.screens.spriteViewer
|
package com.github.nacabaro.vbhelper.screens.spriteViewer
|
||||||
|
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.util.Log
|
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.ui.graphics.asImageBitmap
|
|
||||||
import com.github.nacabaro.vbhelper.di.VBHelper
|
import com.github.nacabaro.vbhelper.di.VBHelper
|
||||||
import com.github.nacabaro.vbhelper.domain.characters.Sprite
|
|
||||||
import java.nio.ByteBuffer
|
import java.nio.ByteBuffer
|
||||||
|
import androidx.core.graphics.createBitmap
|
||||||
|
import com.github.nacabaro.vbhelper.domain.card.CardBackground
|
||||||
|
|
||||||
class SpriteViewerControllerImpl(
|
class SpriteViewerControllerImpl(
|
||||||
private val context: ComponentActivity
|
private val context: ComponentActivity
|
||||||
) : SpriteViewerController {
|
) : SpriteViewerController {
|
||||||
override suspend fun getAllSprites(): List<Sprite> {
|
override suspend fun getAllSprites(): List<CardBackground> {
|
||||||
val applicationContext = context.applicationContext as VBHelper
|
val applicationContext = context.applicationContext as VBHelper
|
||||||
val db = applicationContext.container.db
|
val db = applicationContext.container.db
|
||||||
val sprites = db.spriteDao().getAllSprites()
|
val sprites = db.cardBackgroundDao().getBackgrounds()
|
||||||
return sprites
|
return sprites
|
||||||
}
|
}
|
||||||
|
|
||||||
// I don't like this, chief
|
// I don't like this, chief
|
||||||
override fun convertToBitmap(sprites: List<Sprite>): List<Bitmap> {
|
override fun convertToBitmap(sprites: List<CardBackground>): List<Bitmap> {
|
||||||
val bitmapList = mutableListOf<Bitmap>()
|
val bitmapList = mutableListOf<Bitmap>()
|
||||||
|
|
||||||
for (sprite in sprites) {
|
for (sprite in sprites) {
|
||||||
Log.d("SpriteViewer", "sprite: $sprite")
|
bitmapList.add(createBitmap(sprite.backgroundWidth, sprite.backgroundHeight, Bitmap.Config.RGB_565).apply {
|
||||||
bitmapList.add(Bitmap.createBitmap(sprite.width, sprite.height, Bitmap.Config.RGB_565).apply {
|
copyPixelsFromBuffer(ByteBuffer.wrap(sprite.background))
|
||||||
copyPixelsFromBuffer(ByteBuffer.wrap(sprite.spriteIdle1))
|
|
||||||
})
|
|
||||||
bitmapList.add(Bitmap.createBitmap(sprite.width, sprite.height, Bitmap.Config.RGB_565).apply {
|
|
||||||
copyPixelsFromBuffer(ByteBuffer.wrap(sprite.spriteIdle2))
|
|
||||||
})
|
|
||||||
bitmapList.add(Bitmap.createBitmap(sprite.width, sprite.height, Bitmap.Config.RGB_565).apply {
|
|
||||||
copyPixelsFromBuffer(ByteBuffer.wrap(sprite.spriteWalk1))
|
|
||||||
})
|
|
||||||
bitmapList.add(Bitmap.createBitmap(sprite.width, sprite.height, Bitmap.Config.RGB_565).apply {
|
|
||||||
copyPixelsFromBuffer(ByteBuffer.wrap(sprite.spriteWalk2))
|
|
||||||
})
|
|
||||||
bitmapList.add(Bitmap.createBitmap(sprite.width, sprite.height, Bitmap.Config.RGB_565).apply {
|
|
||||||
copyPixelsFromBuffer(ByteBuffer.wrap(sprite.spriteRun1))
|
|
||||||
})
|
|
||||||
bitmapList.add(Bitmap.createBitmap(sprite.width, sprite.height, Bitmap.Config.RGB_565).apply {
|
|
||||||
copyPixelsFromBuffer(ByteBuffer.wrap(sprite.spriteRun2))
|
|
||||||
})
|
|
||||||
bitmapList.add(Bitmap.createBitmap(sprite.width, sprite.height, Bitmap.Config.RGB_565).apply {
|
|
||||||
copyPixelsFromBuffer(ByteBuffer.wrap(sprite.spriteTrain1))
|
|
||||||
})
|
|
||||||
bitmapList.add(Bitmap.createBitmap(sprite.width, sprite.height, Bitmap.Config.RGB_565).apply {
|
|
||||||
copyPixelsFromBuffer(ByteBuffer.wrap(sprite.spriteTrain2))
|
|
||||||
})
|
|
||||||
bitmapList.add(Bitmap.createBitmap(sprite.width, sprite.height, Bitmap.Config.RGB_565).apply {
|
|
||||||
copyPixelsFromBuffer(ByteBuffer.wrap(sprite.spriteHappy))
|
|
||||||
})
|
|
||||||
bitmapList.add(Bitmap.createBitmap(sprite.width, sprite.height, Bitmap.Config.RGB_565).apply {
|
|
||||||
copyPixelsFromBuffer(ByteBuffer.wrap(sprite.spriteSleep))
|
|
||||||
})
|
|
||||||
bitmapList.add(Bitmap.createBitmap(sprite.width, sprite.height, Bitmap.Config.RGB_565).apply {
|
|
||||||
copyPixelsFromBuffer(ByteBuffer.wrap(sprite.spriteAttack))
|
|
||||||
})
|
|
||||||
bitmapList.add(Bitmap.createBitmap(sprite.width, sprite.height, Bitmap.Config.RGB_565).apply {
|
|
||||||
copyPixelsFromBuffer(ByteBuffer.wrap(sprite.spriteDodge))
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
package com.github.nacabaro.vbhelper.source
|
|
||||||
|
|
||||||
import androidx.datastore.core.DataStore
|
|
||||||
import androidx.datastore.preferences.core.Preferences
|
|
||||||
import androidx.datastore.preferences.core.edit
|
|
||||||
import androidx.datastore.preferences.core.intPreferencesKey
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
|
||||||
import kotlinx.coroutines.flow.map
|
|
||||||
|
|
||||||
class CurrencyRepository (
|
|
||||||
private val dataStore: DataStore<Preferences>
|
|
||||||
) {
|
|
||||||
|
|
||||||
private companion object {
|
|
||||||
val CURRENCY_VALUE = intPreferencesKey("currency_value")
|
|
||||||
}
|
|
||||||
|
|
||||||
val currencyValue: Flow<Int> = dataStore.data
|
|
||||||
.map { preferences ->
|
|
||||||
preferences[CURRENCY_VALUE] ?: 10000
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun setCurrencyValue(newValue: Int) {
|
|
||||||
dataStore.edit { preferences ->
|
|
||||||
preferences[CURRENCY_VALUE] = newValue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
package com.github.nacabaro.vbhelper.source
|
package com.github.nacabaro.vbhelper.source
|
||||||
|
|
||||||
import com.github.nacabaro.vbhelper.database.AppDatabase
|
import com.github.nacabaro.vbhelper.database.AppDatabase
|
||||||
|
import com.github.nacabaro.vbhelper.domain.items.Items
|
||||||
import com.github.nacabaro.vbhelper.dtos.ItemDtos
|
import com.github.nacabaro.vbhelper.dtos.ItemDtos
|
||||||
import kotlinx.coroutines.flow.Flow
|
|
||||||
|
|
||||||
class ItemsRepository(
|
class ItemsRepository(
|
||||||
private val db: AppDatabase
|
private val db: AppDatabase
|
||||||
) {
|
) {
|
||||||
fun getAllItems(): Flow<List<ItemDtos.ItemsWithQuantities>> {
|
suspend fun getAllItems(): List<ItemDtos.ItemsWithQuantities> {
|
||||||
return db.itemDao().getAllItems()
|
return db.itemDao().getAllItems()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getUserItems(): Flow<List<ItemDtos.ItemsWithQuantities>> {
|
suspend fun getUserItems(): List<ItemDtos.ItemsWithQuantities> {
|
||||||
return db.itemDao().getAllUserItems()
|
return db.itemDao().getAllUserItems()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
[versions]
|
[versions]
|
||||||
agp = "8.13.1"
|
agp = "8.12.3"
|
||||||
datastore = "1.1.2"
|
datastore = "1.1.2"
|
||||||
kotlin = "2.0.0"
|
kotlin = "2.0.0"
|
||||||
coreKtx = "1.15.0"
|
coreKtx = "1.15.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user