Skip to content

Commit

Permalink
Version management implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Spikatrix committed May 23, 2020
1 parent b7d4d06 commit 54364bb
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 6 deletions.
9 changes: 6 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ android {
minSdkVersion 14
targetSdkVersion 29
versionCode 1
versionName "0.0.1-beta" // Remember to update the GAME_VERSION in Constants.java too !!
versionName "0.0.1-beta"
// Remember to update the GAME_VERSION in Constants.java
// And project.setVersion in Desktop's build.gradle
// Or for Linux users, use the versionUpdate.sh script
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
minifyEnabled false // Don't set this to true because it'll result in a lot of classes missing causing Runtime crashes
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
Expand Down
1 change: 0 additions & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ sourceCompatibility = 1.7

sourceSets.main.java.srcDirs = [ "src/" ]


eclipse.project {
name = appName + "-core"
}
3 changes: 3 additions & 0 deletions core/src/com/cg/zoned/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

public final class Constants {
public static final String GAME_VERSION = "0.0.1-beta";
// Remember to update the versionName in Android's build.gradle
// And project.setVersion in Desktop's build.gradle
// Or for Linux users, use the versionUpdate.sh script

public static final float WORLD_SIZE = 480.0f;

Expand Down
2 changes: 2 additions & 0 deletions core/src/com/cg/zoned/Zoned.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public void dispose() {
} catch (GdxRuntimeException ignored) {
// "Pixmap already disposed!" error
// idk why this happens but ok ¯\_(ツ)_/¯
} catch (NullPointerException ignored) {
// Application was closed before the skin was loaded
}
}
}
9 changes: 8 additions & 1 deletion desktop/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ sourceSets.main.java.srcDirs = [ "src/" ]

project.ext.mainClassName = "com.cg.zoned.desktop.DesktopLauncher"
project.ext.assetsDir = new File("../android/assets")
project.setVersion("0.0.1-beta")
// Remember to update the GAME_VERSION in Constants.java
// And versionName in Android's build.gradle
// Or for Linux users, use the versionUpdate.sh script

task run(dependsOn: classes, type: JavaExec) {
main = project.mainClassName
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = project.assetsDir
ignoreExitValue = true
args project.getVersion()
}

task debug(dependsOn: classes, type: JavaExec) {
Expand All @@ -21,6 +26,7 @@ task debug(dependsOn: classes, type: JavaExec) {
workingDir = project.assetsDir
ignoreExitValue = true
debug = true
args project.getVersion()
}

task dist(type: Jar) {
Expand All @@ -30,9 +36,10 @@ task dist(type: Jar) {
from {configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) }}
from {configurations.compile.collect {zipTree(it)}}
from files(project.assetsDir)

manifest {
attributes 'Main-Class': project.mainClassName
attributes 'Game-Version': project.getVersion()
}
}

Expand Down
9 changes: 8 additions & 1 deletion desktop/src/com/cg/zoned/desktop/DesktopLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
import com.badlogic.gdx.Files;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.cg.zoned.Constants;
import com.cg.zoned.Zoned;

public class DesktopLauncher {
public static void main(String[] arg) {
public static void main(String[] args) {
if (args.length > 0 && !args[0].equals(Constants.GAME_VERSION)) {
// Used as a precaution
System.err.println("GAME VERSION MISMATCH (" + args[0] + " and " + Constants.GAME_VERSION + ")");
return;
}

LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.title = "Zoned";
config.vSyncEnabled = true;
Expand Down
24 changes: 24 additions & 0 deletions versionUpdate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

read -p "Old version name: " oldVersionName
read -p "New version name: " newVersionName
read -p "Are you sure you wanna do this? (Y/N) " proceed

if [ "$proceed" == "Y" ]; then
grep -l "$oldVersionName" android/build.gradle | while read filename
do
sed -i -e "s/$oldVersionName/$newVersionName/g" "$filename"
done

grep -l "$oldVersionName" desktop/build.gradle | while read filename
do
sed -i -e "s/$oldVersionName/$newVersionName/g" "$filename"
done

grep -l "$oldVersionName" core/src/com/cg/zoned/Constants.java | while read filename
do
sed -i -e "s/$oldVersionName/$newVersionName/g" "$filename"
done
else
echo "Alright, aborted"
fi

0 comments on commit 54364bb

Please sign in to comment.