Skip to content
Snippets Groups Projects
Commit fe9df4a3 authored by v.tarantik's avatar v.tarantik
Browse files

User trophy definition fix

parent 1e126b1e
No related branches found
No related tags found
No related merge requests found
......@@ -95,7 +95,7 @@ public enum GameTrophyDefinition implements TrophyEnum {
}
@Override
public String getDescription() {
public String getTrophyDescription() {
return trophyDescription;
}
......
......@@ -21,6 +21,6 @@ package cz.nic.tablexia.game.trophy;
public interface TrophyEnum {
public String getTrophyName();
public String getDescription();
public String getTrophyDescription();
}
......@@ -22,11 +22,7 @@ package cz.nic.tablexia.game.trophy;
import java.util.ArrayList;
import java.util.List;
import cz.nic.tablexia.R;
import cz.nic.tablexia.game.difficulty.GameDifficulty;
import cz.nic.tablexia.game.manager.GameManager;
import cz.nic.tablexia.menu.usermenu.User;
import cz.nic.tablexia.util.Utility;
/**
* Definitions of user trophies
......@@ -35,31 +31,25 @@ import cz.nic.tablexia.util.Utility;
*/
public enum UserTrophyDefinition implements TrophyEnum {
CONSECUTIVELY_DAYSBACK_3(UserTrophyTypeDefinition.CONSECUTIVELY_DAYSBACK, "consecutively3Days", R.drawable.trophy_user_consecutively3days_small, R.id.screen_halloffame_trophy_user_consecutively3days, R.drawable.trophy_user_consecutively3days, R.string.trophy_user_consecutively3Days_name, R.string.trophy_user_consecutively3Days_description, 3),
CONSECUTIVELY_DAYSBACK_5(UserTrophyTypeDefinition.CONSECUTIVELY_DAYSBACK, "consecutively5Days", R.drawable.trophy_user_consecutively5days_small, R.id.screen_halloffame_trophy_user_consecutively5days, R.drawable.trophy_user_consecutively5days, R.string.trophy_user_consecutively5Days_name, R.string.trophy_user_consecutively5Days_description, 5),
CONSECUTIVELY_DAYSBACK_8(UserTrophyTypeDefinition.CONSECUTIVELY_DAYSBACK, "consecutively8Days", R.drawable.trophy_user_consecutively8days_small, R.id.screen_halloffame_trophy_user_consecutively8days, R.drawable.trophy_user_consecutively8days, R.string.trophy_user_consecutively8Days_name, R.string.trophy_user_consecutively8Days_description, 8),
ONEDAYALLGAMES_0STARS(UserTrophyTypeDefinition.ONEDAYALLGAMES, "consecutivelyAllGames0Stars", R.drawable.trophy_user_consecutivelyallgames0stars_small, R.id.screen_halloffame_trophy_user_consecutivelyallgames0stars, R.drawable.trophy_user_consecutivelyallgames0stars, R.string.trophy_user_consecutivelyAllGames0Stars_name, R.string.trophy_user_consecutivelyAllGames0Stars_description, 0),
CONSECUTIVELYALLGAMES_MEDIUMDIFFICULTY(UserTrophyTypeDefinition.CONSECUTIVELY_ALLGAMES, "consecutivelyAllGames2Stars", R.drawable.trophy_user_consecutivelyallgames2stars_small, R.id.screen_halloffame_trophy_user_consecutivelyallgames2stars, R.drawable.trophy_user_consecutivelyallgames2stars, R.string.trophy_user_consecutivelyAllGames2Stars_name, R.string.trophy_user_consecutivelyAllGames2Stars_description, GameDifficulty.MEDIUM.ordinal()),
CONSECUTIVELYALLGAMES_HARDDIFFICULTY(UserTrophyTypeDefinition.CONSECUTIVELY_ALLGAMES, "consecutivelyAllGames3Stars", R.drawable.trophy_user_consecutivelyallgames3stars_small, R.id.screen_halloffame_trophy_user_consecutivelyallgames3stars, R.drawable.trophy_user_consecutivelyallgames3stars, R.string.trophy_user_consecutivelyAllGames3Stars_name, R.string.trophy_user_consecutivelyAllGames3Stars_description, GameDifficulty.HARD.ordinal());
CONSECUTIVELY_DAYSBACK_3(UserTrophyTypeDefinition.CONSECUTIVELY_DAYSBACK, "consecutively3Days", "trophy_user_consecutively3days", "trophy_user_consecutively3days_description", 3),
CONSECUTIVELY_DAYSBACK_5(UserTrophyTypeDefinition.CONSECUTIVELY_DAYSBACK, "consecutively5Days", "trophy_user_consecutively5days", "trophy_user_consecutively5days_description", 5),
CONSECUTIVELY_DAYSBACK_8(UserTrophyTypeDefinition.CONSECUTIVELY_DAYSBACK, "consecutively8Days", "trophy_user_consecutively8days", "trophy_user_consecutively8days_description", 8),
ONEDAYALLGAMES_0STARS(UserTrophyTypeDefinition.ONEDAYALLGAMES, "consecutivelyAllGames0Stars", "trophy_user_consecutivelyallgames0stars", "trophy_user_consecutivelyallgames0stars_description", 0),
CONSECUTIVELYALLGAMES_MEDIUMDIFFICULTY(UserTrophyTypeDefinition.CONSECUTIVELY_ALLGAMES, "consecutivelyAllGames2Stars", "trophy_user_consecutivelyallgames2stars", "trophy_user_consecutivelyallgames2stars_description", GameDifficulty.MEDIUM.ordinal()),
CONSECUTIVELYALLGAMES_HARDDIFFICULTY(UserTrophyTypeDefinition.CONSECUTIVELY_ALLGAMES, "consecutivelyAllGames3Stars", "trophy_user_consecutivelyallgames3stars", "trophy_user_consecutivelyallgames2stars_description", GameDifficulty.HARD.ordinal());
private UserTrophyTypeDefinition trophyTypeDefinition;
private String dbFieldName;
private int smallImageResourceId;
private int trophyImageId;
private String imageName;
private String imageDescription;
private int limit;
private int nameResourceId;
private int descriptionResourceId;
private int fullImageResourceId;
private UserTrophyDefinition(UserTrophyTypeDefinition trophyTypeDefinition, String dbFieldName, int smallImageResourceId, int trophyImageId, int fullImageResourceId, int nameResourceId, int descriptionResourceId, int limit) {
private UserTrophyDefinition(UserTrophyTypeDefinition trophyTypeDefinition, String dbFieldName, String imageName, String imageDescription, int limit) {
this.trophyTypeDefinition = trophyTypeDefinition;
this.dbFieldName = dbFieldName;
this.smallImageResourceId = smallImageResourceId;
this.fullImageResourceId = fullImageResourceId;
this.nameResourceId = nameResourceId;
this.descriptionResourceId = descriptionResourceId;
this.trophyImageId = trophyImageId;
this.imageName = imageName;
this.imageDescription = imageDescription;
this.limit = limit;
}
......@@ -72,73 +62,59 @@ public enum UserTrophyDefinition implements TrophyEnum {
}
@Override
public int getSmallImageResourceId() {
return smallImageResourceId;
}
public int getFullImageResourceId() {
return fullImageResourceId;
}
@Override
public int getNameResourceId() {
return nameResourceId;
public String getTrophyName() {
return null;
}
@Override
public int getDescriptionResourceId() {
return descriptionResourceId;
}
@Override
public int getTrophyImageId() {
return trophyImageId;
public String getTrophyDescription() {
return null;
}
public int getLimit() {
return limit;
}
public static List<TrophyEnum> processUserTrophies(User user) {
List<TrophyEnum> resultList = new ArrayList<TrophyEnum>();
for (UserTrophyDefinition userTrophyDefinition : UserTrophyDefinition.getTrophyDefinitionByUserTrophyDefinition(UserTrophyTypeDefinition.CONSECUTIVELY_DAYSBACK)) {
if (!Utility.isSetTrophyForName(user, userTrophyDefinition.getDbFieldName())) {
boolean result = true;
for (int i = 0; i < userTrophyDefinition.getLimit(); i++) {
boolean existGame = GameManager.isGameManagerForDayBack(user.getId(), i);
result = result && existGame;
if (!existGame) {
break;
}
}
if (result) {
Utility.setTrophyForName(user, userTrophyDefinition.getDbFieldName());
resultList.add(userTrophyDefinition);
}
}
}
for (UserTrophyDefinition userTrophyDefinition : UserTrophyDefinition.getTrophyDefinitionByUserTrophyDefinition(UserTrophyTypeDefinition.ONEDAYALLGAMES)) {
if (!Utility.isSetTrophyForName(user, userTrophyDefinition.getDbFieldName())) {
if (GameManager.existsGameTypeManagersInOneDayWithStars(user.getId(), userTrophyDefinition.getLimit())) {
Utility.setTrophyForName(user, userTrophyDefinition.getDbFieldName());
resultList.add(userTrophyDefinition);
}
}
}
for (UserTrophyDefinition userTrophyDefinition : UserTrophyDefinition.getTrophyDefinitionByUserTrophyDefinition(UserTrophyTypeDefinition.CONSECUTIVELY_ALLGAMES)) {
if (!Utility.isSetTrophyForName(user, userTrophyDefinition.getDbFieldName())) {
if (GameManager.existsGameTypeManagersConsecutivelyWithStarsNumberAndDifficulty(user.getId(), userTrophyDefinition.getLimit(), 3)) {
Utility.setTrophyForName(user, userTrophyDefinition.getDbFieldName());
resultList.add(userTrophyDefinition);
}
}
}
user.save();
return resultList;
}
// public static List<TrophyEnum> processUserTrophies(User user) {
// List<TrophyEnum> resultList = new ArrayList<TrophyEnum>();
// for (UserTrophyDefinition userTrophyDefinition : UserTrophyDefinition.getTrophyDefinitionByUserTrophyDefinition(UserTrophyTypeDefinition.CONSECUTIVELY_DAYSBACK)) {
// if (!Utility.isSetTrophyForName(user, userTrophyDefinition.getDbFieldName())) {
// boolean result = true;
// for (int i = 0; i < userTrophyDefinition.getLimit(); i++) {
// boolean existGame = GameManager.isGameManagerForDayBack(user.getId(), i);
// result = result && existGame;
// if (!existGame) {
// break;
// }
// }
// if (result) {
// Utility.setTrophyForName(user, userTrophyDefinition.getDbFieldName());
// resultList.add(userTrophyDefinition);
// }
// }
// }
//
// for (UserTrophyDefinition userTrophyDefinition : UserTrophyDefinition.getTrophyDefinitionByUserTrophyDefinition(UserTrophyTypeDefinition.ONEDAYALLGAMES)) {
// if (!Utility.isSetTrophyForName(user, userTrophyDefinition.getDbFieldName())) {
// if (GameManager.existsGameTypeManagersInOneDayWithStars(user.getId(), userTrophyDefinition.getLimit())) {
// Utility.setTrophyForName(user, userTrophyDefinition.getDbFieldName());
// resultList.add(userTrophyDefinition);
// }
// }
// }
//
// for (UserTrophyDefinition userTrophyDefinition : UserTrophyDefinition.getTrophyDefinitionByUserTrophyDefinition(UserTrophyTypeDefinition.CONSECUTIVELY_ALLGAMES)) {
// if (!Utility.isSetTrophyForName(user, userTrophyDefinition.getDbFieldName())) {
// if (GameManager.existsGameTypeManagersConsecutivelyWithStarsNumberAndDifficulty(user.getId(), userTrophyDefinition.getLimit(), 3)) {
// Utility.setTrophyForName(user, userTrophyDefinition.getDbFieldName());
// resultList.add(userTrophyDefinition);
// }
// }
// }
//
// user.save();
// return resultList;
// }
public static List<UserTrophyDefinition> getTrophyDefinitionByUserTrophyDefinition(UserTrophyTypeDefinition trophyTypeDefinition) {
List<UserTrophyDefinition> result = new ArrayList<UserTrophyDefinition>();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment