Commit ddc3cf5f authored by Matyáš Latner's avatar Matyáš Latner

New Game model fields synchronization with Tablexia-Server

parent b692248f
......@@ -26,6 +26,9 @@ final assetsGameGlobalDirectory = "_global"
final assetsGameCommonDifficultyDirectory = "common"
final assetsGameExcludedDirectory = "excluded"
final String TABLEXIA_GIT_PATH = './'
final String MODEL_GIT_PATH = 'core/external/'
System.setProperty("javax.net.ssl.trustStore", new File("${project(":android").projectDir.absolutePath}/assets/keystore/tablexiaTrustKeystore").getAbsolutePath());
System.setProperty("javax.net.ssl.trustStorePassword", "tablexia");
......@@ -45,8 +48,10 @@ allprojects {
masterBranch = 'master'
applicationBaseId = 'cz.nic.tablexia'
tablexiaAppName = getTablexiaAppName()
tablexiaVersionName = getVersionNameFromGit()
tablexiaVersionCode = getVersionCodeFromGit()
tablexiaVersionName = getVersionNameFromGit(TABLEXIA_GIT_PATH)
tablexiaVersionCode = getVersionCodeFromGit(TABLEXIA_GIT_PATH)
tablexiaModelVersionName = getVersionNameFromGit(MODEL_GIT_PATH)
tablexiaModelVersionCode = getVersionCodeFromGit(MODEL_GIT_PATH)
applicationIdBranch = getTablexiaAppId()
applicationIdRelease = applicationBaseId + applicationIdBranch
applicationIdDebugSuffix = '.debug'
......@@ -72,7 +77,7 @@ allprojects {
ravenVersion = '7.5.0'
}
version = getVersionNameFromGit()
version = getVersionNameFromGit(TABLEXIA_GIT_PATH)
repositories {
maven { url "http://repo1.maven.org/maven2" }
......@@ -270,12 +275,13 @@ def getTablexiaAppId() {
}
}
def getVersionNameFromGit() {
def getVersionNameFromGit(String relativePath) {
def stdout = new ByteArrayOutputStream()
String branchName = getBranchNameFromGit()
// get last tag in current branch
exec {
workingDir relativePath
commandLine 'git', 'describe', '--abbrev=0', '--tags'
standardOutput = stdout
}
......@@ -285,6 +291,7 @@ def getVersionNameFromGit() {
if (!project.masterBranch.equals(branchName)) {
stdout = new ByteArrayOutputStream()
exec {
workingDir relativePath
commandLine 'git', 'rev-list', "${result}..HEAD", '--count'
standardOutput = stdout
}
......@@ -298,9 +305,10 @@ def getVersionNameFromGit() {
return result
}
def getVersionCodeFromGit() {
def getVersionCodeFromGit(String relativePath) {
def stdout = new ByteArrayOutputStream()
exec {
workingDir relativePath
commandLine 'git', 'log', '-1', '--format=%at'
standardOutput = stdout
}
......
......@@ -37,6 +37,8 @@ task writeTablexiaBuildConfig {
" public final static String APP_NAME = \"${tablexiaAppName}\";\n" +
" public final static String APPLICATION_VERSION_NAME = \"${tablexiaVersionName}\";\n" +
" public final static Integer APPLICATION_VERSION_CODE = ${tablexiaVersionCode};\n" +
" public final static String MODEL_VERSION_NAME = \"${tablexiaModelVersionName}\";\n" +
" public final static Integer MODEL_VERSION_CODE = ${tablexiaModelVersionCode};\n" +
" public final static String ASSETS_CHECKSUM = \"${getMapConvertedToString(rootProject.ext.assetsChecksum)}\";\n" +
" public final static String TABLEXIA_ASSETS_URL = ${project.hasProperty('TABLEXIA_ASSETS_DOWNLOAD_URL') ? "\"$TABLEXIA_ASSETS_DOWNLOAD_URL\"" : "null"};\n" +
" public final static String TABLEXIA_SERVER_PROTOCOL = ${project.hasProperty('TABLEXIA_SERVER_PROTOCOL') ? "\"$TABLEXIA_SERVER_PROTOCOL\"" : "null"};\n" +
......
......@@ -56,9 +56,12 @@ public class TablexiaSettings {
private static final String APP_NAME = TablexiaBuildConfig.APP_NAME;
private final String APPLICATION_VERSION_NAME = TablexiaBuildConfig.APPLICATION_VERSION_NAME;
private final int APPLICATION_VERSION_CODE = TablexiaBuildConfig.APPLICATION_VERSION_CODE;
private final String MODEL_VERSION_NAME = TablexiaBuildConfig.MODEL_VERSION_NAME;
private final int MODEL_VERSION_CODE = TablexiaBuildConfig.MODEL_VERSION_CODE;
private Platform PLATFORM;
private final BuildType BUILD_TYPE;
private final boolean HAS_SOFT_BACK_BUTTON;
private static String hwSerial;
private static String HW_SERIAL_NUMBER;
private Preferences preferences;
private LocaleDefinition systemLocale;
......@@ -69,15 +72,47 @@ public class TablexiaSettings {
private boolean soundMuted = false;
public enum Platform {
UNKNOWN (-1, null),
DESKTOP (1, Application.ApplicationType.Desktop),
ANDROID (2, Application.ApplicationType.Android),
iOS (3, Application.ApplicationType.iOS);
private static Platform FALLBACK_PLATFORM = UNKNOWN;
private final int id;
private final Application.ApplicationType applicationType;
Platform(int id, Application.ApplicationType applicationType) {
this.id = id;
this.applicationType = applicationType;
}
public int getId() {
return id;
}
public static Platform getPlatformForApplicationType(Application.ApplicationType applicationType) {
for (Platform platform : values()) {
if (platform.applicationType != null && platform.applicationType.equals(applicationType)) {
return platform;
}
}
return FALLBACK_PLATFORM;
}
}
public enum BuildType {
// boxes aInfo sInfo dMenu btName bReport debugBtn
RELEASE ("release", false, false, false, false, false, true, false, Log.TablexiaLogLevel.ERROR),
DEBUG ("debug", false, true, true, true, true, true, true, Log.TablexiaLogLevel.DEBUG),
DEVEL ("devel", true, true, true, true, true, false, true, Log.TablexiaLogLevel.DEBUG);
RELEASE (1, "release", false, false, false, false, false, true, false, Log.TablexiaLogLevel.ERROR),
DEBUG (2, "debug", false, true, true, true, true, true, true, Log.TablexiaLogLevel.DEBUG),
DEVEL (3, "devel", true, true, true, true, true, false, true, Log.TablexiaLogLevel.DEBUG);
private final static BuildType FALLBACK_VARIANT = BuildType.DEVEL;
private int id;
private final String key;
private boolean boundingBoxes;
private boolean applicationInfo;
......@@ -88,7 +123,8 @@ public class TablexiaSettings {
private boolean showDebugButtons;
private final Log.TablexiaLogLevel logLevel;
BuildType(String key, boolean boundingBoxes, boolean applicationInfo, boolean screenInfo, boolean debugMenu, boolean showBuildTypeInName, boolean bugReport, boolean showDebugButtons, Log.TablexiaLogLevel logLevel) {
BuildType(int id, String key, boolean boundingBoxes, boolean applicationInfo, boolean screenInfo, boolean debugMenu, boolean showBuildTypeInName, boolean bugReport, boolean showDebugButtons, Log.TablexiaLogLevel logLevel) {
this.id = id;
this.key = key;
this.boundingBoxes = boundingBoxes;
this.applicationInfo = applicationInfo;
......@@ -100,6 +136,10 @@ public class TablexiaSettings {
this.logLevel = logLevel;
}
public int getId() {
return id;
}
public String getKey() {
return key;
}
......@@ -170,7 +210,7 @@ public class TablexiaSettings {
TablexiaSettings.init(BuildType.getBuildTypeForKey(buildTypeKey), systemLocale, hasSoftBackButton, hwSerial);
}
static void init(BuildType buildType, Locale systemLocale, boolean hasSoftBackButton, String hwSerial) {
static void init(BuildType buildType, Locale systemLocale, boolean hasSoftBackButton, String hwSerialNumber) {
if (instance != null) {
String exceptionMessage = "Tablexia settings already initialized!";
Log.err(TablexiaSettings.class, exceptionMessage);
......@@ -178,7 +218,7 @@ public class TablexiaSettings {
}
instance = new TablexiaSettings(buildType, systemLocale, hasSoftBackButton);
TablexiaSettings.hwSerial = hwSerial;
TablexiaSettings.HW_SERIAL_NUMBER = hwSerialNumber;
}
void dispose() {
......@@ -202,27 +242,42 @@ public class TablexiaSettings {
//////////////////////////// SETTINGS ACCESS
public String getFullName() {
return getAppName() + " " + getVersionName();
return getAppName() + " " + getApplicationVersionName();
}
public String getAppName() {
return getBuildType().getAppName();
}
public String getVersionName() {
public String getApplicationVersionName() {
return APPLICATION_VERSION_NAME;
}
public int getVersionCode() {
public int getApplicationVersionCode() {
return APPLICATION_VERSION_CODE;
}
public String getModelVersionName() {
return MODEL_VERSION_NAME;
}
public int getModelVersionCode() {
return MODEL_VERSION_CODE;
}
public Platform getPlatform() {
if (PLATFORM == null) {
PLATFORM = Platform.getPlatformForApplicationType(Gdx.app.getType());
}
return PLATFORM;
}
public boolean hasSoftBackButton() {
return HAS_SOFT_BACK_BUTTON;
}
public String getHwSerial() {
return hwSerial;
public String getHwSerialNumber() {
return HW_SERIAL_NUMBER;
}
public boolean isWinterMode() { return winterMode; }
......
......@@ -430,7 +430,7 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
random = TablexiaSettings.GAMES_RANDOM_SEED == null ? new TablexiaRandom() : new TablexiaRandom(TablexiaSettings.GAMES_RANDOM_SEED);
GameDefinition gameDefinition = GameDefinition.getGameDefinitionForClass(AbstractTablexiaGame.this.getClass());
GameDifficulty gameDifficulty = gameDefinition.hasTutorial() && UserDAO.isTutorialForGameDefinition(gameDefinition, getSelectedUser()) ? GameDifficulty.TUTORIAL : getGameDifficulty();
game = GameDAO.createGame(getSelectedUser(), gameDifficulty, gameDefinition, random, TablexiaSettings.getInstance().getHwSerial(), TablexiaSettings.getInstance().getVersionName(), TablexiaSettings.getInstance().getVersionCode());
game = GameDAO.createGame(getSelectedUser(), gameDifficulty, gameDefinition, random);
Log.info(getClass(), "[DB] Created new GAME object: " + game);
} else {
Log.info(getClass(), "[DB] Restored last GAME object: " + game);
......
......@@ -42,7 +42,8 @@ import cz.nic.tablexia.util.ui.TablexiaNoBlendingImage;
* @author Matyáš Latner
*/
public abstract class AbstractMenu extends Stack implements Disposable {
private static final String VERSION_LINE_SEPARATOR = "\r\n";
private static final String TABLEXIA_VERSION_LABEL = "%s\r\n%s";
protected enum MenuControlType {
......@@ -314,7 +315,7 @@ public abstract class AbstractMenu extends Stack implements Disposable {
//App name and version
TablexiaLabel appName = new TablexiaLabel(
TablexiaSettings.getInstance().getAppName() + VERSION_LINE_SEPARATOR + TablexiaSettings.getInstance().getVersionName(),
String.format(TABLEXIA_VERSION_LABEL, TablexiaSettings.getInstance().getAppName(), TablexiaSettings.getInstance().getApplicationVersionName()),
new TablexiaLabel.TablexiaLabelStyle(APP_NAME_TEXT_FONT, Color.BLACK));
appName.setAlignment(APP_NAME_TEXT_ALIGN);
appName.setWrap(true);
......
......@@ -32,9 +32,13 @@ public class DatabaseManager {
private enum VersionScript {
VERSION_01( 1, "ALTER TABLE game ADD locale INTEGER NOT NULL DEFAULT " + Game.DEFAULT_GAME_LOCALE),
VERSION_02( 2, "ALTER TABLE game ADD version_name TEXT NOT NULL DEFAULT '" + Game.DEFAULT_GAME_VERSION_NAME + "'"),
VERSION_03( 3, "ALTER TABLE game ADD version_code INTEGER NOT NULL DEFAULT " + Game.DEFAULT_GAME_VERSION_CODE),
VERSION_04( 4, "ALTER TABLE game ADD hw_serial_number TEXT");
VERSION_02( 2, "ALTER TABLE game ADD application_version_name TEXT NOT NULL DEFAULT '" + Game.DEFAULT_APPLICATION_VERSION_NAME + "'"),
VERSION_03( 3, "ALTER TABLE game ADD application_version_code INTEGER NOT NULL DEFAULT " + Game.DEFAULT_APPLICATION_VERSION_CODE),
VERSION_04( 4, "ALTER TABLE game ADD model_version_name TEXT NOT NULL DEFAULT '" + Game.DEFAULT_MODEL_VERSION_NAME + "'"),
VERSION_05( 5, "ALTER TABLE game ADD model_version_code INTEGER NOT NULL DEFAULT " + Game.DEFAULT_MODE_VERSION_CODE),
VERSION_06( 6, "ALTER TABLE game ADD build_type INTEGER NOT NULL DEFAULT " + Game.DEFAULT_BUILD_TYPE),
VERSION_07( 7, "ALTER TABLE game ADD platform INTEGER NOT NULL DEFAULT " + Game.DEFAULT_PLATFORM),
VERSION_08( 7, "ALTER TABLE game ADD hw_serial_number TEXT");
private int version;
private String sqlStatement;
......
......@@ -240,7 +240,7 @@ public class UserDAO {
continue;
}
Long gameId = GameDAO.importGame(dbUser, game.getGameDifficulty(), game.getGameNumber(), game.getGameLocale(), game.getGameVersionName(), game.getRandomSeed(), game.getStartTime(), game.getEndTime());
Long gameId = GameDAO.importGame(dbUser, game);
if (gameId == null) {
continue;
......
......@@ -10,7 +10,6 @@ import cz.nic.tablexia.TablexiaStorage;
import cz.nic.tablexia.game.AbstractTablexiaGame;
import cz.nic.tablexia.game.difficulty.GameDifficulty;
import cz.nic.tablexia.game.trophy.GameTrophyDefinition;
import cz.nic.tablexia.model.UserDAO;
import cz.nic.tablexia.shared.model.User;
import cz.nic.tablexia.shared.model.Game;
import cz.nic.tablexia.util.Log;
......@@ -55,7 +54,7 @@ public class GameTrophy {
public static class ThreeStarsReceived implements GameTrophyResolver {
public static final String GAME_SELECT_FOR_GAME_AND_DIFFICULTY = "SELECT id, user_id, difficulty_number, game_number, random_seed, start_time, end_time, hw_serial_number, application_version_name, application_version_code FROM game WHERE game_number = ? AND difficulty_number = ? AND user_id = ? AND end_time IS NOT NULL";
public static final String GAME_SELECT_FOR_GAME_AND_DIFFICULTY = "SELECT " + GameDAO.GAME_SELECT_COLUMNS + " FROM game WHERE game_number = ? AND difficulty_number = ? AND user_id = ? AND end_time IS NOT NULL";
private static List<Game> getGamesForGameAndDifficulty(User user, GameTrophyDefinition trophyDef) {
List<Game> games = new ArrayList<Game>();
......@@ -67,21 +66,7 @@ public class GameTrophy {
try {
ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
String startTimeStr = resultSet.getString(6);
String endTimeStr = resultSet.getString(7);
Game game = new Game(resultSet.getLong(1),
UserDAO.selectUser(resultSet.getLong(2)),
resultSet.getInt(3),
resultSet.getInt(4),
resultSet.getLong(5),
startTimeStr != null ? Long.valueOf(startTimeStr) : null,
endTimeStr != null ? Long.valueOf(endTimeStr) : null,
resultSet.getString(8),
resultSet.getString(9),
resultSet.getInt(10));
game.setGamePauses(GamePauseDAO.selectGamePausesForGame(game));
game.getGameScoreMap().addAll(GameScoreDAO.selectGameScores(game.getId()));
games.add(game);
games.add(GameDAO.prepareGameObject(resultSet));
}
resultSet.close();
} catch (SQLException e) {
......
......@@ -20,9 +20,8 @@ import cz.nic.tablexia.game.AbstractTablexiaGame;
import cz.nic.tablexia.game.GameDefinition;
import cz.nic.tablexia.game.difficulty.GameDifficulty;
import cz.nic.tablexia.game.trophy.UserTrophyDefinition;
import cz.nic.tablexia.model.UserDAO;
import cz.nic.tablexia.shared.model.User;
import cz.nic.tablexia.shared.model.Game;
import cz.nic.tablexia.shared.model.User;
import cz.nic.tablexia.util.Log;
/**
......@@ -155,8 +154,8 @@ public class UserTrophy {
public static class AllStarsGame implements UserTrophyResolver {
public static final String GAME_SELECT_FOR_USER_AND_DIFFICULTY = "SELECT id, user_id, difficulty_number, game_number, random_seed, start_time, end_time, hw_serial_number, application_version_name, application_version_code FROM game WHERE difficulty_number = ? AND user_id = ? AND end_time IS NOT NULL";
public static final String GAME_SELECT_FOR_USER = "SELECT id, user_id, difficulty_number, game_number, random_seed, start_time, end_time, hw_serial_number, application_version_name, application_version_code FROM game WHERE user_id = ? AND difficulty_number != ? AND start_time IS NOT NULL AND start_time != 0 AND end_time IS NOT NULL AND end_time != 0";
public static final String GAME_SELECT_FOR_USER_AND_DIFFICULTY = "SELECT " + GameDAO.GAME_SELECT_COLUMNS + " FROM game WHERE difficulty_number = ? AND user_id = ? AND end_time IS NOT NULL";
public static final String GAME_SELECT_FOR_USER = "SELECT " + GameDAO.GAME_SELECT_COLUMNS + " FROM game WHERE user_id = ? AND difficulty_number != ? AND start_time IS NOT NULL AND start_time != 0 AND end_time IS NOT NULL AND end_time != 0";
private static List<Game> getGamesForUserAndDifficulty(User user, UserTrophyDefinition trophyDef) throws SQLException {
PreparedStatement statement = TablexiaStorage.getInstance().prepareStatement(GAME_SELECT_FOR_USER_AND_DIFFICULTY);
......@@ -180,22 +179,7 @@ public class UserTrophy {
try {
ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
String startTimeStr = resultSet.getString(6);
String endTimeStr = resultSet.getString(7);
Game game = new Game(resultSet.getLong(1),
UserDAO.selectUser(resultSet.getLong(2)),
resultSet.getInt(3),
resultSet.getInt(4),
resultSet.getLong(5),
startTimeStr != null ? Long.valueOf(startTimeStr) : null,
endTimeStr != null ? Long.valueOf(endTimeStr) : null,
resultSet.getString(8),
resultSet.getString(9),
resultSet.getInt(10));
game.setGamePauses(GamePauseDAO.selectGamePausesForGame(game));
game.getGameScoreMap().addAll(GameScoreDAO.selectGameScores(game.getId()));
games.add(game);
games.add(GameDAO.prepareGameObject(resultSet));
}
resultSet.close();
} catch (SQLException e) {
......
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