Skip to content

Commit

Permalink
Merge pull request #46 from gatheringhallstudios/develop
Browse files Browse the repository at this point in the history
Merge version 2.1.1
  • Loading branch information
CarlosFdez authored Sep 27, 2018
2 parents 163c34b + 32cd606 commit 9295066
Show file tree
Hide file tree
Showing 52 changed files with 1,104 additions and 697 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ MHGU Database for Android (formally MHGen Database)

Source code for the Android app _MHGU Database_.

[![Download from Google Play](http://www.android.com/images/brand/android_app_on_play_large.png "Download from Google Play")](https://play.google.com/store/apps/details?id=com.ghstudios.android.mhgendatabase&hl=en)
[<img src="https://f-droid.org/badge/get-it-on.png"
alt="Get it on F-Droid"
height="80">](https://f-droid.org/packages/com.ghstudios.android.mhgendatabase/)
[<img src="https://play.google.com/intl/en_us/badges/images/generic/en-play-badge.png"
alt="Get it on Google Play"
height="80">](https://play.google.com/store/apps/details?id=com.ghstudios.android.mhgendatabase)

List of To-Dos can be found on our [Trello Board](https://trello.com/b/tI4PYsgH/mhgen-database)

Expand Down
6 changes: 4 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ android {
//2.0.0 Version Code: 8 Released 9-8-2018
//2.0.1 Version Code: 9 Released 9-8-2018
//2.0.2 Version Code:10 Released 9-??-2018
versionCode 10
versionName "2.0.2"
//2.1.0 Version Code:11 Released 9-??-2018
//2.1.1 Version Code:12 Released 9-??-2018
versionCode 12
versionName "2.1.1"

compileOptions {
// we'll still be able to target lower java versions because of desugar
Expand Down
Binary file modified app/src/main/assets/databases/mhgu.db.zip
Binary file not shown.
Binary file modified app/src/main/icon-res/drawable/icon_egg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
Expand All @@ -32,6 +33,7 @@ public class IconLabelTextCell extends FrameLayout {
@BindView(R.id.label_text) TextView labelView;
@BindView(R.id.label_alt_text) TextView labelAltView;
@BindView(R.id.value_text) TextView valueView;
@BindView(R.id.key) TextView keyView;

boolean altEnabled = false;

Expand Down Expand Up @@ -124,6 +126,13 @@ public void setValueText(String valueText) {
valueView.setText(valueText);
}

public void setKeyVisibility(boolean show){
if(show)
keyView.setVisibility(View.VISIBLE);
else
keyView.setVisibility(View.GONE);
}

/**
* Runs some logic to see if alt text should be enabled.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ public void setTitleText(String title) {
}
}

public View addItem(ITintedIcon icon, String itemName, int qty) {
public View addItem(ITintedIcon icon, String itemName, int qty, boolean key) {
IconLabelTextCell cell = new IconLabelTextCell(getContext());
cell.setLeftIcon(icon);
cell.setLabelText(itemName);
cell.setValueText(String.valueOf(qty));
cell.setKeyVisibility(key);

itemsView.addView(cell);

Expand Down
142 changes: 142 additions & 0 deletions app/src/main/java/com/ghstudios/android/data/ASBManager.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package com.ghstudios.android.data

import android.content.ContentValues
import android.content.Context
import android.util.Log
import com.ghstudios.android.data.classes.*
import com.ghstudios.android.data.cursors.ASBSessionCursor
import com.ghstudios.android.data.cursors.ASBSetCursor
import com.ghstudios.android.data.database.MonsterHunterDatabaseHelper
import com.ghstudios.android.data.database.S
import com.ghstudios.android.util.firstOrNull

private fun contentValuesFromMap(map: Map<String, Any>): ContentValues {
val result = ContentValues()
for ((key, value) in map.entries) {
when (value) {
is Boolean -> result.put(key, value)
is String -> result.put(key, value)
is Int -> result.put(key, value)
is Long -> result.put(key, value)
is Double -> result.put(key, value)
is Float -> result.put(key, value)
is ByteArray -> result.put(key, value)
else -> {
Log.e("ASBManager", "UNSUPPORTED TYPE for ${value}")
}
}
}
return result
}

class ASBManager internal constructor(
private val mAppContext: Context,
private val mHelper: MonsterHunterDatabaseHelper
) {
fun queryASBSets(): ASBSetCursor {
return mHelper.queryASBSets()
}

fun getASBSet(id: Long): ASBSet? {
return mHelper.queryASBSet(id).firstOrNull { it.asbSet }
}

/** Get a cursor with a list of all armor sets. */
fun queryASBSessions(): ASBSessionCursor {
return mHelper.queryASBSessions()
}

/** Get a specific armor set. */
fun getASBSession(id: Long): ASBSession? {
return mHelper.queryASBSession(id).firstOrNull { it.getASBSession(mAppContext) }
}

/** Adds a new ASB set to the list. */
fun queryAddASBSet(name: String, rank: Int, hunterType: Int) {
mHelper.queryAddASBSet(name, rank, hunterType)
}

// todo: rename, or replace for something else
/** Adds a new set that is a copy of the designated set to the list. */
fun queryAddASBSet(setId: Long) {
val set = getASBSet(setId)
mHelper.queryAddASBSet(set!!.name!!, set.rank, set.hunterType)
}

fun queryDeleteASBSet(setId: Long) {
mHelper.queryDeleteASBSet(setId)
}

fun queryUpdateASBSet(setId: Long, name: String, rank: Int, hunterType: Int) {
mHelper.queryUpdateASBSet(setId, name, rank, hunterType)
}

fun updateASB(set: ASBSession): Long {
val weaponPiece = set.getPiece(ArmorSet.WEAPON)
val headPiece = set.getPiece(ArmorSet.HEAD)
val bodyPiece = set.getPiece(ArmorSet.BODY)
val armsPiece = set.getPiece(ArmorSet.ARMS)
val waistPiece = set.getPiece(ArmorSet.WAIST)
val legsPiece = set.getPiece(ArmorSet.LEGS)
val talismanPiece = set.getPiece(ArmorSet.TALISMAN)

fun getArmorId(piece: ArmorSetPiece?): Long {
return piece?.equipment?.id ?: -1L
}

fun getDeco(piece: ArmorSetPiece?, idx: Int): Long {
return piece?.decorations?.getOrNull(idx)?.id ?: -1L
}

val updatedColumns = mapOf<String, Any>(
S.COLUMN_ASB_SET_NAME to set.name,
S.COLUMN_ASB_SET_HUNTER_TYPE to set.hunterType,
S.COLUMN_ASB_SET_RANK to set.rank,

S.COLUMN_ASB_WEAPON_SLOTS to set.numWeaponSlots,
S.COLUMN_ASB_WEAPON_DECORATION_1_ID to getDeco(weaponPiece, 0),
S.COLUMN_ASB_WEAPON_DECORATION_2_ID to getDeco(weaponPiece, 1),
S.COLUMN_ASB_WEAPON_DECORATION_3_ID to getDeco(weaponPiece, 2),

S.COLUMN_HEAD_ARMOR_ID to getArmorId(headPiece),
S.COLUMN_HEAD_DECORATION_1_ID to getDeco(headPiece, 0),
S.COLUMN_HEAD_DECORATION_2_ID to getDeco(headPiece, 1),
S.COLUMN_HEAD_DECORATION_3_ID to getDeco(headPiece, 2),

S.COLUMN_BODY_ARMOR_ID to getArmorId(bodyPiece),
S.COLUMN_BODY_DECORATION_1_ID to getDeco(bodyPiece, 0),
S.COLUMN_BODY_DECORATION_2_ID to getDeco(bodyPiece, 1),
S.COLUMN_BODY_DECORATION_3_ID to getDeco(bodyPiece, 2),

S.COLUMN_ARMS_ARMOR_ID to getArmorId(armsPiece),
S.COLUMN_ARMS_DECORATION_1_ID to getDeco(armsPiece, 0),
S.COLUMN_ARMS_DECORATION_2_ID to getDeco(armsPiece, 1),
S.COLUMN_ARMS_DECORATION_3_ID to getDeco(armsPiece, 2),

S.COLUMN_WAIST_ARMOR_ID to getArmorId(waistPiece),
S.COLUMN_WAIST_DECORATION_1_ID to getDeco(waistPiece, 0),
S.COLUMN_WAIST_DECORATION_2_ID to getDeco(waistPiece, 1),
S.COLUMN_WAIST_DECORATION_3_ID to getDeco(waistPiece, 2),

S.COLUMN_LEGS_ARMOR_ID to getArmorId(legsPiece),
S.COLUMN_LEGS_DECORATION_1_ID to getDeco(legsPiece, 0),
S.COLUMN_LEGS_DECORATION_2_ID to getDeco(legsPiece, 1),
S.COLUMN_LEGS_DECORATION_3_ID to getDeco(legsPiece, 2),

S.COLUMN_TALISMAN_EXISTS to (talismanPiece != null),
S.COLUMN_TALISMAN_TYPE to (set.talisman?.typeIndex ?: -1),
S.COLUMN_TALISMAN_SLOTS to (set.talisman?.numSlots ?: 0),
S.COLUMN_TALISMAN_SKILL_1_ID to (set.talisman?.firstSkill?.skillTree?.id ?: -1L),
S.COLUMN_TALISMAN_SKILL_1_POINTS to (set.talisman?.firstSkill?.points ?: 0),
S.COLUMN_TALISMAN_SKILL_2_ID to (set.talisman?.secondSkill?.skillTree?.id ?: -1L),
S.COLUMN_TALISMAN_SKILL_2_POINTS to (set.talisman?.secondSkill?.points ?: 0),
S.COLUMN_TALISMAN_DECORATION_1_ID to getDeco(talismanPiece, 0),
S.COLUMN_TALISMAN_DECORATION_2_ID to getDeco(talismanPiece, 1),
S.COLUMN_TALISMAN_DECORATION_3_ID to getDeco(talismanPiece, 2)
)

val filter = S.COLUMN_ASB_SET_ID + " = " + set.id
val values = contentValuesFromMap(updatedColumns)
return mHelper.updateRecord(S.TABLE_ASB_SETS, filter, values).toLong()
}
}
142 changes: 49 additions & 93 deletions app/src/main/java/com/ghstudios/android/data/DataManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class DataManager private constructor(private val mAppContext: Context) {
private val gatheringDao = GatheringDao(mHelper)
private val skillDao = SkillDao(mHelper)

val asbManager = ASBManager(mAppContext, mHelper)


/********************************* ARMOR QUERIES */

Expand Down Expand Up @@ -633,26 +635,39 @@ class DataManager private constructor(private val mAppContext: Context) {
return mHelper.queryWeaponFamily(id)
}

fun queryWeaponOrigins(id: Long):ArrayList<Weapon>{
/**
* Returns the first weapon of each family tree that led up to the family tree of id.
*/
fun queryWeaponOrigins(id: Long): List<Weapon>{
val weapons = ArrayList<Weapon>()
var currentId = (id and 0xFFFF00)+1

// Iteratively does the following:
// - get the first weapon of the tree: (id && S.WEAPON_FAMILY_MASK) + 1
// - get the parent of that weapon
// - get the first weapon of that tree and cycle again

// note: (id && S.WEAPON_FAMILY_MASK) + 1 is the FIRST weapon of the tree.
var currentId = (id and S.WEAPON_FAMILY_MASK) + 1

while(true) {
val cursor = mHelper.queryWeaponTreeParent(currentId)
cursor.moveToFirst()
val weapon = cursor.weapon ?: break
cursor.close()

val wCur = mHelper.queryWeapon(weapon.id)
wCur.moveToFirst()
val w = wCur.weapon
weapons.add(w)
currentId = (w.id and 0xFFFF00) + 1
wCur.close()
// This particular weapon cursor returns incomplete info
// todo: consider making either a WeaponBase superclass, a WeaponBasic class, or return full info from queryWeaponTreeParent
val weaponBase = mHelper.queryWeaponTreeParent(currentId)
.firstOrNull { it.weapon }
?: break

// Query the full weapon data for the weapon cursor
val weapon = mHelper.queryWeapon(weaponBase.id).first { it.weapon }

// add to results, and then get the id of the first weapon of that tree and iterate again
weapons.add(weapon)
currentId = (weapon.id and S.WEAPON_FAMILY_MASK) + 1
}

return weapons
}

fun queryWeaponBranches(id:Long):ArrayList<Weapon>{
fun queryWeaponBranches(id:Long): List<Weapon> {
val wt = mHelper.queryWeaponFamilyBranches(id).toList { it.weapon }
val weapons = ArrayList<Weapon>()
for(w in wt){
Expand All @@ -662,6 +677,26 @@ class DataManager private constructor(private val mAppContext: Context) {
return weapons
}

/**
* Queries all final weapons that can be derived from this one
*/
fun queryWeaponFinal(id: Long): List<Weapon> {
val results = mutableListOf<Weapon>()

// Get the final of this tree
val final = mHelper.queryWeaponTreeFinal(id)
if (final != null) {
results.add(final)
}

// Get the branch weapons, and recursively get their final weapons
val otherBranches = this.queryWeaponBranches(id)
val branchFinals = otherBranches.map { queryWeaponFinal(it.id) }.flatten()
results.addAll(branchFinals)

return results
}

fun queryPalicoWeapons(): PalicoWeaponCursor {
return mHelper.queryPalicoWeapons()
}
Expand Down Expand Up @@ -1031,85 +1066,6 @@ class DataManager private constructor(private val mAppContext: Context) {
}
}

/********************************* ARMOR SET BUILDER QUERIES */

fun queryASBSets(): ASBSetCursor {
return mHelper.queryASBSets()
}

fun getASBSet(id: Long): ASBSet? {
var set: ASBSet? = null
val cursor = mHelper.queryASBSet(id)
cursor.moveToFirst()

if (!cursor.isAfterLast)
set = cursor.asbSet

cursor.close()
return set
}

/** Get a cursor with a list of all armor sets. */
fun queryASBSessions(): ASBSessionCursor {
return mHelper.queryASBSessions()
}

/** Get a specific armor set. */
fun getASBSession(id: Long): ASBSession? {
var session: ASBSession? = null
val cursor = mHelper.queryASBSession(id)
cursor.moveToFirst()

if (!cursor.isAfterLast)
session = cursor.getASBSession(mAppContext)

cursor.close()
return session
}

/** Adds a new ASB set to the list. */
fun queryAddASBSet(name: String, rank: Int, hunterType: Int) {
mHelper.queryAddASBSet(name, rank, hunterType)
}

/** Adds a new set that is a copy of the designated set to the list. */
fun queryAddASBSet(setId: Long) {
val set = getASBSet(setId)
mHelper.queryAddASBSet(set!!.name!!, set.rank, set.hunterType)
}

fun queryDeleteASBSet(setId: Long) {
mHelper.queryDeleteASBSet(setId)
}

fun queryUpdateASBSet(setId: Long, name: String, rank: Int, hunterType: Int) {
mHelper.queryUpdateASBSet(setId, name, rank, hunterType)
}

fun queryPutASBSessionArmor(asbSetId: Long, armorId: Long, pieceIndex: Int) {
mHelper.queryAddASBSessionArmor(asbSetId, armorId, pieceIndex)
}

fun queryRemoveASBSessionArmor(asbSetId: Long, pieceIndex: Int) {
mHelper.queryAddASBSessionArmor(asbSetId, -1, pieceIndex)
}

fun queryPutASBSessionDecoration(asbSetId: Long, decorationId: Long, pieceIndex: Int, decorationIndex: Int) {
mHelper.queryPutASBSessionDecoration(asbSetId, decorationId, pieceIndex, decorationIndex)
}

fun queryRemoveASBSessionDecoration(asbSetId: Long, pieceIndex: Int, decorationIndex: Int) {
mHelper.queryPutASBSessionDecoration(asbSetId, -1, pieceIndex, decorationIndex)
}

fun queryCreateASBSessionTalisman(asbSetId: Long, type: Int, slots: Int, skill1Id: Long, skill1Points: Int, skill2Id: Long, skill2Points: Int) {
mHelper.queryCreateASBSessionTalisman(asbSetId, type, slots, skill1Id, skill1Points, skill2Id, skill2Points)
}

fun queryRemoveASBSessionTalisman(asbSetId: Long) {
mHelper.queryRemoveASBSessionTalisman(asbSetId)
}

/**************************** WYPORIUM TRADE DATA QUERIES */
/* Get a Cursor that has a list of all wyporium trades */
fun queryWyporiumTrades(): WyporiumTradeCursor {
Expand Down
Loading

0 comments on commit 9295066

Please sign in to comment.