Migrates Monster class to be storable in roomdb.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package com.majinnaibu.monstercards.data.converters;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.room.TypeConverter;
|
||||
|
||||
import com.majinnaibu.monstercards.data.enums.ArmorType;
|
||||
@@ -8,7 +7,7 @@ import com.majinnaibu.monstercards.data.enums.ArmorType;
|
||||
public class ArmorTypeConverter {
|
||||
|
||||
@TypeConverter
|
||||
public static String fromArmorType(@NonNull ArmorType armorType) {
|
||||
public static String fromArmorType(ArmorType armorType) {
|
||||
return armorType.stringValue;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.majinnaibu.monstercards.data.converters;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.room.TypeConverter;
|
||||
|
||||
import com.majinnaibu.monstercards.data.enums.ChallengeRating;
|
||||
@@ -8,7 +7,7 @@ import com.majinnaibu.monstercards.data.enums.ChallengeRating;
|
||||
public class ChallengeRatingConverter {
|
||||
|
||||
@TypeConverter
|
||||
public static String fromChallengeRating(@NonNull ChallengeRating challengeRating) {
|
||||
public static String fromChallengeRating(ChallengeRating challengeRating) {
|
||||
return challengeRating.stringValue;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.majinnaibu.monstercards.data.converters;
|
||||
|
||||
|
||||
import androidx.room.TypeConverter;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.majinnaibu.monstercards.models.SavingThrow;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class SetOfSavingThrowConverter {
|
||||
|
||||
@TypeConverter
|
||||
public static String fromSetOfSavingThrow(Set<SavingThrow> savingThrows) {
|
||||
Gson gson = new Gson();
|
||||
SavingThrow[] saves = new SavingThrow[savingThrows.size()];
|
||||
savingThrows.toArray(saves);
|
||||
return gson.toJson(saves);
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
public static Set<SavingThrow> setOfSavingThrowFromString(String string) {
|
||||
Gson gson = new Gson();
|
||||
Type setType = new TypeToken<HashSet<SavingThrow>>() {
|
||||
}.getType();
|
||||
return gson.fromJson(string, setType);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.majinnaibu.monstercards.data.converters;
|
||||
|
||||
import androidx.room.TypeConverter;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.majinnaibu.monstercards.models.Trait;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class SetOfTraitConverter {
|
||||
@TypeConverter
|
||||
public static String fromSetOfTrait(Set<Trait> traits) {
|
||||
Gson gson = new Gson();
|
||||
return gson.toJson(traits);
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
public static Set<Trait> setOfTraitFromString(String string) {
|
||||
Gson gson = new Gson();
|
||||
Type setType = new TypeToken<HashSet<Trait>>() {
|
||||
}.getType();
|
||||
return gson.fromJson(string, setType);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,13 @@
|
||||
package com.majinnaibu.monstercards.data.converters;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.room.TypeConverter;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class UUIDConverter {
|
||||
|
||||
@NonNull
|
||||
@TypeConverter
|
||||
public static String fromUUID(@NonNull UUID uuid) {
|
||||
public static String fromUUID(UUID uuid) {
|
||||
return uuid.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ public enum AbilityScore {
|
||||
STRENGTH("strength", "Strength", "STR"),
|
||||
DEXTERITY("dexterity", "Dexterity", "DEX"),
|
||||
CONSTITUTION("constitution", "Constitution", "CON"),
|
||||
INTELLIGENCE("intelligence", "Intelligence", "INT"),
|
||||
INTELLIGENCE("intellligence", "Intelligence", "INT"),
|
||||
WISDOM("wisdom", "Wisdom", "WIS"),
|
||||
CHARISMA("charisma", "Charisma", "CHA"),
|
||||
;
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.majinnaibu.monstercards.data.enums;
|
||||
public enum ProficiencyType {
|
||||
NONE("none", "None", ""),
|
||||
PROFICIENT("proficient", "Proficient", "P"),
|
||||
EXPERTISE("expertise", "Expertise", "Ex"),
|
||||
EXPERTISE("experties", "Expertise", "Ex"),
|
||||
;
|
||||
|
||||
public final String displayName;
|
||||
|
||||
Reference in New Issue
Block a user