Commit abfdfa02 authored by Mathieu Féry (Mathius)'s avatar Mathieu Féry (Mathius)
Browse files

Add management of spells in DnDSheet (And rework hashCode and save in DB)

parent b1b4b238
Pipeline #23345 failed with stages
in 2 minutes and 37 seconds
...@@ -53,6 +53,7 @@ public class DnDSheet implements Serializable { ...@@ -53,6 +53,7 @@ public class DnDSheet implements Serializable {
public final List<String> languages; public final List<String> languages;
public final List<String> equipment; public final List<String> equipment;
public final List<String> notes; public final List<String> notes;
public final List<String> spells;
public final DnDSkills skills; public final DnDSkills skills;
protected GIFObject gif; protected GIFObject gif;
public final String searchGIF; public final String searchGIF;
...@@ -69,6 +70,7 @@ public class DnDSheet implements Serializable { ...@@ -69,6 +70,7 @@ public class DnDSheet implements Serializable {
* @param languages : List of all languages known by this character * @param languages : List of all languages known by this character
* @param equipment : List of all equipment of this character * @param equipment : List of all equipment of this character
* @param notes : List of all note concern this character * @param notes : List of all note concern this character
* @param spells : List of all spells of this character
* @param saves : DnDSaves represent resistances of this character * @param saves : DnDSaves represent resistances of this character
* @param attr : DnDAttrs represent attributes of this character * @param attr : DnDAttrs represent attributes of this character
* @param skills : DnDSkills represent all skills of this character * @param skills : DnDSkills represent all skills of this character
...@@ -78,7 +80,8 @@ public class DnDSheet implements Serializable { ...@@ -78,7 +80,8 @@ public class DnDSheet implements Serializable {
@Nullable String appearance, @NonNull DnDClass caracterClass, @Nullable String appearance, @NonNull DnDClass caracterClass,
@Nullable String personality, @NonNull DnDSystem system, @Nullable String personality, @NonNull DnDSystem system,
@NonNull List<String> languages, @NonNull List<String> equipment, @NonNull List<String> languages, @NonNull List<String> equipment,
@NonNull List<String> notes, @NonNull DnDSaves saves, @NonNull DnDAttrs attr, @NonNull List<String> notes, @NonNull List<String> spells,
@NonNull DnDSaves saves, @NonNull DnDAttrs attr,
@NonNull DnDSkills skills, @NonNull GIFObject gifObject) { @NonNull DnDSkills skills, @NonNull GIFObject gifObject) {
this.hp = hp != null && hp != -1 ? hp : null; this.hp = hp != null && hp != -1 ? hp : null;
this.thac9 = thac9 != null && thac9 != -1 ? thac9 : null; this.thac9 = thac9 != null && thac9 != -1 ? thac9 : null;
...@@ -93,6 +96,7 @@ public class DnDSheet implements Serializable { ...@@ -93,6 +96,7 @@ public class DnDSheet implements Serializable {
this.saves = saves; this.saves = saves;
this.attr = attr; this.attr = attr;
this.skills = skills; this.skills = skills;
this.spells = spells;
this.gif = gifObject; this.gif = gifObject;
this.searchGIF = String.format("%s,%s,%s", this.caracterClass, this.appearance, this.searchGIF = String.format("%s,%s,%s", this.caracterClass, this.appearance,
this.system); this.system);
...@@ -110,6 +114,7 @@ public class DnDSheet implements Serializable { ...@@ -110,6 +114,7 @@ public class DnDSheet implements Serializable {
* @param languages : List of all languages known by this character * @param languages : List of all languages known by this character
* @param equipment : List of all equipment of this character * @param equipment : List of all equipment of this character
* @param notes : List of all note concern this character * @param notes : List of all note concern this character
* @param spells : List of all spells of this character
* @param saves : DnDSaves represent resistances of this character * @param saves : DnDSaves represent resistances of this character
* @param attr : DnDAttrs represent attributes of this character * @param attr : DnDAttrs represent attributes of this character
* @param skills : DnDSkills represent all skills of this character * @param skills : DnDSkills represent all skills of this character
...@@ -117,15 +122,16 @@ public class DnDSheet implements Serializable { ...@@ -117,15 +122,16 @@ public class DnDSheet implements Serializable {
* @param tenorArgs : TenorArgs for search media related to this character * @param tenorArgs : TenorArgs for search media related to this character
*/ */
protected DnDSheet(@Nullable Integer hp, @Nullable Integer thac9, @Nullable Integer ac, protected DnDSheet(@Nullable Integer hp, @Nullable Integer thac9, @Nullable Integer ac,
@Nullable String appearance, @NonNull DnDClass caracterClass, @Nullable String appearance, @NonNull DnDClass caracterClass,
@Nullable String personality, @NonNull DnDSystem system, @Nullable String personality, @NonNull DnDSystem system,
@NonNull List<String> languages, @NonNull List<String> equipment, @NonNull List<String> languages, @NonNull List<String> equipment,
@NonNull List<String> notes, @NonNull DnDSaves saves, @NonNull DnDAttrs attr, @NonNull List<String> notes, @NonNull List<String> spells,
@NonNull DnDSkills skills, @NonNull Context ctx, @NonNull DnDSaves saves, @NonNull DnDAttrs attr,
@NonNull TenorArgs tenorArgs) { @NonNull DnDSkills skills, @NonNull Context ctx,
@NonNull TenorArgs tenorArgs) {
this(hp, thac9, ac, appearance, caracterClass, personality, system, languages, equipment, this(hp, thac9, ac, appearance, caracterClass, personality, system, languages, equipment,
notes, saves, attr, skills, GIFObject.getGIFObject(ctx, String.format("%s,%s,%s", notes, spells, saves, attr, skills, GIFObject.getGIFObject(ctx, String.format(
caracterClass, appearance, system), tenorArgs)); "%s,%s,%s", caracterClass, appearance, system), tenorArgs));
} }
/** /**
...@@ -301,6 +307,7 @@ public class DnDSheet implements Serializable { ...@@ -301,6 +307,7 @@ public class DnDSheet implements Serializable {
* languages.hashCode() * languages.hashCode()
* equipment.hashCode() * equipment.hashCode()
* notes.hashCode() * notes.hashCode()
* spells.hashCode()
* saves.hashCode() * saves.hashCode()
* attr.hashCode() * attr.hashCode()
* skills.hashCode(); * skills.hashCode();
...@@ -1346,6 +1353,10 @@ public class DnDSheet implements Serializable { ...@@ -1346,6 +1353,10 @@ public class DnDSheet implements Serializable {
if (json.get("languages") != jsonNull) if (json.get("languages") != jsonNull)
for (JsonElement lang : json.get("languages").getAsJsonArray()) for (JsonElement lang : json.get("languages").getAsJsonArray())
languages.add(lang.getAsString()); languages.add(lang.getAsString());
List<String> spells = new ArrayList<>();
if (json.get("spell") != jsonNull)
for (JsonElement spell : json.get("spell").getAsJsonArray())
spells.add(spell.getAsString());
List<DnDSkill> skills = new ArrayList<>(); List<DnDSkill> skills = new ArrayList<>();
if (json.get("skills") != jsonNull) if (json.get("skills") != jsonNull)
for (JsonElement skillData : json.get("skills").getAsJsonArray()) { for (JsonElement skillData : json.get("skills").getAsJsonArray()) {
...@@ -1366,17 +1377,18 @@ public class DnDSheet implements Serializable { ...@@ -1366,17 +1377,18 @@ public class DnDSheet implements Serializable {
dnDClassProvided ? dnDClass : new DnDClass(json.get("class").getAsString()), dnDClassProvided ? dnDClass : new DnDClass(json.get("class").getAsString()),
json.get("personality") != jsonNull ? json.get("personality") json.get("personality") != jsonNull ? json.get("personality")
.getAsString() : null, .getAsString() : null,
finalSystem, languages, equipment, notes, jsonSaves != null ? new DnDSaves( finalSystem, languages, equipment, notes, spells, jsonSaves != null ? new
jsonSaves.get("wands") != jsonNull ? jsonSaves.get("wands") DnDSaves(
.getAsInt() : null, jsonSaves.get("wands") != jsonNull ? jsonSaves.get("wands")
jsonSaves.get("breath") != jsonNull ? jsonSaves.get("breath") .getAsInt() : null,
.getAsInt() : null, jsonSaves.get("breath") != jsonNull ? jsonSaves.get("breath")
jsonSaves.get("stone") != jsonNull ? jsonSaves.get("stone") .getAsInt() : null,
.getAsInt() : null, jsonSaves.get("stone") != jsonNull ? jsonSaves.get("stone")
jsonSaves.get("magic") != jsonNull ? jsonSaves.get("magic") .getAsInt() : null,
.getAsInt() : null, jsonSaves.get("magic") != jsonNull ? jsonSaves.get("magic")
jsonSaves.get("poison") != jsonNull ? jsonSaves.get("poison") .getAsInt() : null,
.getAsInt() : null jsonSaves.get("poison") != jsonNull ? jsonSaves.get("poison")
.getAsInt() : null
) : null, new DnDAttrs(attr), new DnDSkills(skills), ctx, tenorArgs) ) : null, new DnDAttrs(attr), new DnDSkills(skills), ctx, tenorArgs)
); );
Log.d(TAG, "Result set in OwnFuture"); Log.d(TAG, "Result set in OwnFuture");
......
...@@ -73,6 +73,7 @@ public class DnDSheetDB extends BaseDB { ...@@ -73,6 +73,7 @@ public class DnDSheetDB extends BaseDB {
public static final String LANGUAGES = "languages"; public static final String LANGUAGES = "languages";
public static final String EQUIPMENT = "equipment"; public static final String EQUIPMENT = "equipment";
public static final String NOTES = "notes"; public static final String NOTES = "notes";
public static final String SPELLS = "spells";
public static final String GIF_ID = "gifId"; public static final String GIF_ID = "gifId";
public static final String GIF_ARTEFACT_ID = "gifArtefactId"; public static final String GIF_ARTEFACT_ID = "gifArtefactId";
public static final String SKILLS = "skills"; public static final String SKILLS = "skills";
...@@ -84,7 +85,7 @@ public class DnDSheetDB extends BaseDB { ...@@ -84,7 +85,7 @@ public class DnDSheetDB extends BaseDB {
static { static {
PRIMARY_KEY = Vars._ID; PRIMARY_KEY = Vars._ID;
TABLE_NAME = Vars.TABLE_NAME; TABLE_NAME = Vars.TABLE_NAME;
DATABASE_VERSION = 1; DATABASE_VERSION = 3;
DATABASE_NAME = TABLE_NAME; DATABASE_NAME = TABLE_NAME;
List<String> tempInt = new ArrayList<>(); List<String> tempInt = new ArrayList<>();
tempInt.add(Vars.HP); tempInt.add(Vars.HP);
...@@ -98,6 +99,7 @@ public class DnDSheetDB extends BaseDB { ...@@ -98,6 +99,7 @@ public class DnDSheetDB extends BaseDB {
tempListString.add(Vars.LANGUAGES); tempListString.add(Vars.LANGUAGES);
tempListString.add(Vars.EQUIPMENT); tempListString.add(Vars.EQUIPMENT);
tempListString.add(Vars.NOTES); tempListString.add(Vars.NOTES);
tempListString.add(Vars.SPELLS);
tempListString.add(Vars.SKILLS); tempListString.add(Vars.SKILLS);
tempListString.add(Vars.ATTRS); tempListString.add(Vars.ATTRS);
listStringAttrs = tempListString; listStringAttrs = tempListString;
...@@ -199,6 +201,11 @@ public class DnDSheetDB extends BaseDB { ...@@ -199,6 +201,11 @@ public class DnDSheetDB extends BaseDB {
.split(",")) .split(","))
if (!note.equals("")) if (!note.equals(""))
notes.add(note); notes.add(note);
List<String> spells = new ArrayList<>();
for (String spell : cursor.getString(cursor.getColumnIndex(Vars.SPELLS))
.split(","))
if (!spell.equals(""))
spells.add(spell);
return new DnDSheet( return new DnDSheet(
cursor.getInt(cursor.getColumnIndex(Vars.HP)), cursor.getInt(cursor.getColumnIndex(Vars.HP)),
cursor.getInt(cursor.getColumnIndex(Vars.THAC9)), cursor.getInt(cursor.getColumnIndex(Vars.THAC9)),
...@@ -207,7 +214,7 @@ public class DnDSheetDB extends BaseDB { ...@@ -207,7 +214,7 @@ public class DnDSheetDB extends BaseDB {
new DnDClass(cursor.getString(cursor.getColumnIndex(Vars.CLASS))), new DnDClass(cursor.getString(cursor.getColumnIndex(Vars.CLASS))),
cursor.getString(cursor.getColumnIndex(Vars.PERSONALITY)), cursor.getString(cursor.getColumnIndex(Vars.PERSONALITY)),
DnDSystem.systems.get(cursor.getInt(cursor.getColumnIndex(Vars.SYSTEM_ID))), DnDSystem.systems.get(cursor.getInt(cursor.getColumnIndex(Vars.SYSTEM_ID))),
langs, equips, notes, langs, equips, notes, spells,
new DnDSavesDB(ctx, currentVersion).getDnDSaves(cursor.getInt(cursor.getColumnIndex( new DnDSavesDB(ctx, currentVersion).getDnDSaves(cursor.getInt(cursor.getColumnIndex(
Vars.SAVES_ID))), Vars.SAVES_ID))),
new DnDAttrs(attrs), new DnDSkills(skills), gif new DnDAttrs(attrs), new DnDSkills(skills), gif
...@@ -257,6 +264,11 @@ public class DnDSheetDB extends BaseDB { ...@@ -257,6 +264,11 @@ public class DnDSheetDB extends BaseDB {
for (String note: sheet.notes) for (String note: sheet.notes)
notes = String.format("%s%s,", notes, note); notes = String.format("%s%s,", notes, note);
values.put(Vars.NOTES, notes.length() > 0 ? notes.substring(0, notes.length() - 1) : ""); values.put(Vars.NOTES, notes.length() > 0 ? notes.substring(0, notes.length() - 1) : "");
String spells = "";
for (String spell: sheet.spells)
spells = String.format("%s%s,", spells, spell);
values.put(Vars.SPELLS, spells.length() > 0 ? spells.substring(0, spells.length() - 1) :
"");
String attrs = ""; String attrs = "";
for (DnDAttr attr: sheet.attr.attrs) for (DnDAttr attr: sheet.attr.attrs)
attrs = String.format("%s%s~%s~%d,", attrs, attr.nameAttr, attr.valueUserReadable, attrs = String.format("%s%s~%s~%d,", attrs, attr.nameAttr, attr.valueUserReadable,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment