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 {
public final List<String> languages;
public final List<String> equipment;
public final List<String> notes;
public final List<String> spells;
public final DnDSkills skills;
protected GIFObject gif;
public final String searchGIF;
......@@ -69,6 +70,7 @@ public class DnDSheet implements Serializable {
* @param languages : List of all languages known by this character
* @param equipment : List of all equipment of 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 attr : DnDAttrs represent attributes of this character
* @param skills : DnDSkills represent all skills of this character
......@@ -78,7 +80,8 @@ public class DnDSheet implements Serializable {
@Nullable String appearance, @NonNull DnDClass caracterClass,
@Nullable String personality, @NonNull DnDSystem system,
@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) {
this.hp = hp != null && hp != -1 ? hp : null;
this.thac9 = thac9 != null && thac9 != -1 ? thac9 : null;
......@@ -93,6 +96,7 @@ public class DnDSheet implements Serializable {
this.saves = saves;
this.attr = attr;
this.skills = skills;
this.spells = spells;
this.gif = gifObject;
this.searchGIF = String.format("%s,%s,%s", this.caracterClass, this.appearance,
this.system);
......@@ -110,6 +114,7 @@ public class DnDSheet implements Serializable {
* @param languages : List of all languages known by this character
* @param equipment : List of all equipment of 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 attr : DnDAttrs represent attributes of this character
* @param skills : DnDSkills represent all skills of this character
......@@ -117,15 +122,16 @@ public class DnDSheet implements Serializable {
* @param tenorArgs : TenorArgs for search media related to this character
*/
protected DnDSheet(@Nullable Integer hp, @Nullable Integer thac9, @Nullable Integer ac,
@Nullable String appearance, @NonNull DnDClass caracterClass,
@Nullable String personality, @NonNull DnDSystem system,
@NonNull List<String> languages, @NonNull List<String> equipment,
@NonNull List<String> notes, @NonNull DnDSaves saves, @NonNull DnDAttrs attr,
@NonNull DnDSkills skills, @NonNull Context ctx,
@NonNull TenorArgs tenorArgs) {
@Nullable String appearance, @NonNull DnDClass caracterClass,
@Nullable String personality, @NonNull DnDSystem system,
@NonNull List<String> languages, @NonNull List<String> equipment,
@NonNull List<String> notes, @NonNull List<String> spells,
@NonNull DnDSaves saves, @NonNull DnDAttrs attr,
@NonNull DnDSkills skills, @NonNull Context ctx,
@NonNull TenorArgs tenorArgs) {
this(hp, thac9, ac, appearance, caracterClass, personality, system, languages, equipment,
notes, saves, attr, skills, GIFObject.getGIFObject(ctx, String.format("%s,%s,%s",
caracterClass, appearance, system), tenorArgs));
notes, spells, saves, attr, skills, GIFObject.getGIFObject(ctx, String.format(
"%s,%s,%s", caracterClass, appearance, system), tenorArgs));
}
/**
......@@ -301,6 +307,7 @@ public class DnDSheet implements Serializable {
* languages.hashCode()
* equipment.hashCode()
* notes.hashCode()
* spells.hashCode()
* saves.hashCode()
* attr.hashCode()
* skills.hashCode();
......@@ -1346,6 +1353,10 @@ public class DnDSheet implements Serializable {
if (json.get("languages") != jsonNull)
for (JsonElement lang : json.get("languages").getAsJsonArray())
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<>();
if (json.get("skills") != jsonNull)
for (JsonElement skillData : json.get("skills").getAsJsonArray()) {
......@@ -1366,17 +1377,18 @@ public class DnDSheet implements Serializable {
dnDClassProvided ? dnDClass : new DnDClass(json.get("class").getAsString()),
json.get("personality") != jsonNull ? json.get("personality")
.getAsString() : null,
finalSystem, languages, equipment, notes, jsonSaves != null ? new DnDSaves(
jsonSaves.get("wands") != jsonNull ? jsonSaves.get("wands")
.getAsInt() : null,
jsonSaves.get("breath") != jsonNull ? jsonSaves.get("breath")
.getAsInt() : null,
jsonSaves.get("stone") != jsonNull ? jsonSaves.get("stone")
.getAsInt() : null,
jsonSaves.get("magic") != jsonNull ? jsonSaves.get("magic")
.getAsInt() : null,
jsonSaves.get("poison") != jsonNull ? jsonSaves.get("poison")
.getAsInt() : null
finalSystem, languages, equipment, notes, spells, jsonSaves != null ? new
DnDSaves(
jsonSaves.get("wands") != jsonNull ? jsonSaves.get("wands")
.getAsInt() : null,
jsonSaves.get("breath") != jsonNull ? jsonSaves.get("breath")
.getAsInt() : null,
jsonSaves.get("stone") != jsonNull ? jsonSaves.get("stone")
.getAsInt() : null,
jsonSaves.get("magic") != jsonNull ? jsonSaves.get("magic")
.getAsInt() : null,
jsonSaves.get("poison") != jsonNull ? jsonSaves.get("poison")
.getAsInt() : null
) : null, new DnDAttrs(attr), new DnDSkills(skills), ctx, tenorArgs)
);
Log.d(TAG, "Result set in OwnFuture");
......
......@@ -73,6 +73,7 @@ public class DnDSheetDB extends BaseDB {
public static final String LANGUAGES = "languages";
public static final String EQUIPMENT = "equipment";
public static final String NOTES = "notes";
public static final String SPELLS = "spells";
public static final String GIF_ID = "gifId";
public static final String GIF_ARTEFACT_ID = "gifArtefactId";
public static final String SKILLS = "skills";
......@@ -84,7 +85,7 @@ public class DnDSheetDB extends BaseDB {
static {
PRIMARY_KEY = Vars._ID;
TABLE_NAME = Vars.TABLE_NAME;
DATABASE_VERSION = 1;
DATABASE_VERSION = 3;
DATABASE_NAME = TABLE_NAME;
List<String> tempInt = new ArrayList<>();
tempInt.add(Vars.HP);
......@@ -98,6 +99,7 @@ public class DnDSheetDB extends BaseDB {
tempListString.add(Vars.LANGUAGES);
tempListString.add(Vars.EQUIPMENT);
tempListString.add(Vars.NOTES);
tempListString.add(Vars.SPELLS);
tempListString.add(Vars.SKILLS);
tempListString.add(Vars.ATTRS);
listStringAttrs = tempListString;
......@@ -199,6 +201,11 @@ public class DnDSheetDB extends BaseDB {
.split(","))
if (!note.equals(""))
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(
cursor.getInt(cursor.getColumnIndex(Vars.HP)),
cursor.getInt(cursor.getColumnIndex(Vars.THAC9)),
......@@ -207,7 +214,7 @@ public class DnDSheetDB extends BaseDB {
new DnDClass(cursor.getString(cursor.getColumnIndex(Vars.CLASS))),
cursor.getString(cursor.getColumnIndex(Vars.PERSONALITY)),
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(
Vars.SAVES_ID))),
new DnDAttrs(attrs), new DnDSkills(skills), gif
......@@ -257,6 +264,11 @@ public class DnDSheetDB extends BaseDB {
for (String note: sheet.notes)
notes = String.format("%s%s,", notes, note);
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 = "";
for (DnDAttr attr: sheet.attr.attrs)
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