Commit b744b4e6 authored by Vitaliy Vashchenko's avatar Vitaliy Vashchenko

#884 added tasks for packing hd assets.

parent 48ea5d83
......@@ -54,8 +54,11 @@ System.setProperty("javax.net.ssl.trustStorePassword", "tablexia");
ext {
assetsChecksumPattern = "\"=======ASSETS_CHECKSUM=======\""
assetsChecksum = [:]
assetsHdChecksum = [:]
assetsPackDir = new File("${rootProject.buildDir}/${assetsDirName}/pack/")
assetsHdPackDir = new File("${rootProject.buildDir}/${assetsDirName}/hd/pack/")
}
allprojects {
......@@ -143,6 +146,7 @@ task prepareAssets {
}
}
task prepareSoundAssets(dependsOn: prepareAssets) {
def assetsDir = new File("${buildDir}/${assetsDirName}/")
......@@ -195,6 +199,50 @@ task prepareJsonAssets(dependsOn: prepareAssets) {
}
}
task copyDefaulAssets(){
}
task prepareHdAssets(dependsOn: [prepareAssets, prepareSoundAssets, prepareJsonAssets]) {
def sourceDir = new File("${buildDir}/${assetsDirName}/src/")
def hdSourceDir = new File(project(":desktop").projectDir.absolutePath + "/${assetsDirName}/" + "hd/")
inputs.dir(sourceDir.absolutePath)
outputs.dir("${buildDir}/${assetsDirName}/" + "hd/" + "${assetsSourceDirName}/")
outputs.upToDateWhen { false }
doLast {
if (project.hasProperty('TABLEXIA_HD_ASSETS') && Boolean.valueOf(TABLEXIA_HD_ASSETS).booleanValue()) {
task("copyingDefaultDest", type: Copy) {
from buildDir.absolutePath + "/${assetsDirName}/${assetsDestinationDirName}/"
into buildDir.absolutePath + "/${assetsDirName}/hd/dest/"
}.execute()
sourceDir.eachDir() { dir ->
if (!dir.name.equals('common')) {
String dirName = dir.getName()
String destDir = "${buildDir}/${assetsDirName}/" + "hd/" + "${assetsSourceDirName}/${dirName}"
task("${name}_${dirName}", type: Copy) {
from sourceDir.absolutePath + "/common"
from hdSourceDir.absolutePath + "/common"
from dir.absolutePath
from hdSourceDir.absolutePath + "/" + dirName
into destDir
}.execute()
}
}
} else {
println "HD PACK IS NOT REQUESTED"
}
}
}
task prepareGraphicAssets(dependsOn: prepareAssets) {
def assetsDir = new File("${buildDir}/${assetsDirName}/")
......@@ -276,6 +324,96 @@ task zipAssets(dependsOn: [prepareSoundAssets, prepareGraphicAssets, prepareJson
}
}
task prepareHdGraphicAssets(dependsOn: prepareHdAssets) {
def assetsDir = new File("${buildDir}/${assetsDirName}/" + "hd/")
inputs.dir("${assetsDir.absolutePath}/"+"hd/"+"${assetsSourceDirName}/")
outputs.dir("${assetsDir.absolutePath}/"+"hd/"+"${assetsDestinationDirName}/")
outputs.upToDateWhen { false }
doLast {
if (project.hasProperty('TABLEXIA_HD_ASSETS') && Boolean.valueOf(TABLEXIA_HD_ASSETS).booleanValue()) {
TexturePacker.Settings settings = new TexturePacker.Settings();
settings.pot = false;
settings.maxWidth = 2048;
settings.maxHeight = 2048;
settings.combineSubdirectories = true;
settings.filterMin = Texture.TextureFilter.Linear;
settings.filterMag = Texture.TextureFilter.Linear;
new File("${assetsDir.absolutePath}/${assetsSourceDirName}/").eachDir() { langDir ->
langDir.eachDir() { sectionDir ->
//If section dir has no dirs, copy whole content
if (hasAtlasDir(sectionDir)) {
sectionDir.eachDir() { atlasDir ->
if (assetsGameDirectory.equals(sectionDir.name) && !assetsGameGlobalDirectory.equals(atlasDir.name)) {
atlasDir.eachDir() { difficultyDir ->
if (!assetsGameExcludedDirectory.equals(difficultyDir.name)) {
String packFileName = assetsGameCommonDifficultyDirectory.equals(difficultyDir.name) ? atlasDir.name : difficultyDir.name;
TexturePacker.process(settings,
"${difficultyDir}",
"${assetsDir.absolutePath}/${assetsDestinationDirName}/${langDir.name}/${sectionDir.name}/${atlasDir.name}/",
"${packFileName}")
} else {
task("${name}_" + sectionDir.name + "_" + langDir.name + "_" + atlasDir.name + "_" + difficultyDir.name, type: Copy) {
from difficultyDir
into "${buildDir}/${assetsDirName}/" + "hd/" + "${assetsDestinationDirName}/${langDir.name}/${sectionDir.name}/${atlasDir.name}/${difficultyDir.name}"
include '**/*'
includeEmptyDirs false
outputs.upToDateWhen { false }
}.execute()
}
}
} else {
TexturePacker.process(settings,
"${atlasDir}",
"${assetsDir.absolutePath}/${assetsDestinationDirName}/${langDir.name}/${sectionDir.name}/${atlasDir.name}/",
"${atlasDir.name}")
}
}
} else {
task("${name}_" + sectionDir.name + "_" + langDir.name, type: Copy) {
from sectionDir
into "${buildDir}/${assetsDirName}/" + "hd/" + "${assetsDestinationDirName}/${langDir.name}/${sectionDir.name}"
include '**/*'
includeEmptyDirs false
outputs.upToDateWhen { false }
}.execute()
}
}
}
} else {
println "HD PACK IS NOT REQUESTED"
}
}
}
task zipHdAssets(dependsOn: prepareHdGraphicAssets) {
def assetsDir = new File("${buildDir}/${assetsDirName}/")
inputs.dir("${assetsDir.absolutePath}/"+"hd/"+"${assetsSourceDirName}/")
outputs.dir("${assetsDir.absolutePath}/"+"hd/"+"${assetsDestinationDirName}/")
outputs.upToDateWhen { false }
doLast {
if (project.hasProperty('TABLEXIA_HD_ASSETS') && Boolean.valueOf(TABLEXIA_HD_ASSETS).booleanValue()) {
new File(project(":core").projectDir.absolutePath + "/${assetsDirName}/").eachDir() { dir ->
if (!dir.name.equals('common')) {
task("${name}_${dir.name}", type: Zip) {
archiveName = "hd_" + dir.getName() + "_SNAPSHOT.zip"
destinationDir = rootProject.ext.assetsHdPackDir
from "${buildDir}/${assetsDirName}/" + "hd/" + "${assetsDestinationDirName}/${dir.name}"
}.execute()
}
}
} else {
println "HD PACK IS NOT REQUESTED"
}
}
}
task processAssets(dependsOn: [':util:checksum:runChecksum', ':util:checksum:runAssetsArchivesChecksum']) {
doLast {
if (project.hasProperty('TABLEXIA_ASSETS_UPLOAD_USER') && project.hasProperty('TABLEXIA_ASSETS_UPLOAD_URL') && project.hasProperty('TABLEXIA_ASSETS_UPLOAD') && Boolean.valueOf(TABLEXIA_ASSETS_UPLOAD).booleanValue()) {
......@@ -306,6 +444,37 @@ task processAssets(dependsOn: [':util:checksum:runChecksum', ':util:checksum:run
}
}
task prepareHdPack(dependsOn: [':util:checksum:runHdChecksum', ':util:checksum:runHdAssetsArchivesChecksum']) {
doLast {
//prepare and upload hd packs
if (project.hasProperty('TABLEXIA_HD_ASSETS_UPLOAD_USER') && project.hasProperty('TABLEXIA_ASSETS_UPLOAD_URL') && project.hasProperty('TABLEXIA_ASSETS_UPLOAD') && Boolean.valueOf(TABLEXIA_ASSETS_UPLOAD).booleanValue()) {
def data = new URL(project.assetsDownloadUrl).getText()
rootProject.ext.assetsHdPackDir.eachFile() { file ->
String fileName = file.getName()
String[] fileNameParts = fileName.split("_SNAPSHOT\\.");
String packageName = "${fileNameParts[0]}_${assetsHdChecksum[fileNameParts[0]]}.${fileNameParts[1]}";
if (!data.contains(packageName)) {
String assetsUploadPath = "${project.assetsUploadURL}${packageName}"
println "AssetsUploader: UPLOADING FILE: ${project.assetsDebugURLPart}${packageName}"
task ("${name}_${packageName}", type:Exec) {
workingDir "${rootProject.projectDir}"
commandLine 'scp', file.getAbsolutePath(), assetsUploadPath
standardOutput = new ByteArrayOutputStream()
ext.output = {
return standardOutput.toString()
}
}.execute()
} else {
println "AssetsUploader: FILE: ${project.assetsDebugURLPart}${packageName} EXISTS ON SERVER -> SKIPPING UPLOAD"
}
}
} else {
println "ASSETS UPLOAD NOT CONFIGURED -> SKIPPING UPLOAD"
}
}
}
task unlockIOSKeyChain() << {
if (project.hasProperty('TABLEXIA_KEYCHAIN_USER') && project.hasProperty('TABLEXIA_KEYCHAIN_PATH')) {
exec {
......@@ -453,6 +622,7 @@ project(":core") {
sourceSets.test.java.srcDirs = ["test/"]
tasks.processResources.dependsOn processAssets
tasks.processResources.dependsOn prepareHdPack
dependencies {
compile project(":util:checksum")
......
......@@ -39,7 +39,7 @@ clean {
}
task writeTablexiaBuildConfig {
dependsOn(':util:checksum:runChecksum')
dependsOn([':util:checksum:runChecksum', ':util:checksum:runHdChecksum'])
doLast {
File folder = file(TABLEXIA_PACKAGE_PATH)
if (!folder.exists()) {
......@@ -59,6 +59,7 @@ task writeTablexiaBuildConfig {
" 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 ASSETS_HD_CHECKSUM = \"${getMapConvertedToString(rootProject.ext.assetsHdChecksum)}\";\n" +
" public final static String TABLEXIA_ASSETS_URL = \"${project.assetsDownloadUrl}\";\n" +
" public final static String TABLEXIA_SERVER_PROTOCOL = ${project.hasProperty('TABLEXIA_SERVER_PROTOCOL') ? "\"$TABLEXIA_SERVER_PROTOCOL\"" : "null"};\n" +
" public final static String TABLEXIA_SERVER_HOST = \"${project.serverHost}\";\n" +
......
......@@ -327,7 +327,7 @@ public class Tablexia extends TablexiaApplication {
// async zip extraction
assetsManager = new TablexiaAssetsManager();
assetsManager.load(locale, Utility.createChecksumMapFromString(TablexiaBuildConfig.ASSETS_CHECKSUM));
assetsManager.load(locale, Utility.createChecksumMapFromString(TablexiaBuildConfig.ASSETS_HD_CHECKSUM));
// async external assets loading
ApplicationExternalSoundManager.getInstance().load();
......
......@@ -62,4 +62,47 @@ task runAssetsArchivesChecksum(dependsOn: [classes, rootProject.tasks.zipAssets]
}
}
}
}
task runHdChecksum(dependsOn: [classes, rootProject.tasks.prepareHdGraphicAssets]) {
doLast {
def sourceDir = new File("${rootProject.buildDir}/assets/hd/dest/")
sourceDir.eachDir() { dir ->
String dirName = dir.getName()
task("${name}_${dirName}", type: JavaExec) {
main = MAIN_CLASS
args = [dir]
classpath sourceSets.main.output.classesDir
classpath += sourceSets.main.runtimeClasspath
def stdout = new ByteArrayOutputStream()
standardOutput = stdout
doLast {
rootProject.ext.assetsHdChecksum[dirName] = stdout.toString().trim()
}
}.execute()
}
}
}
task runHdAssetsArchivesChecksum(dependsOn: [classes, rootProject.tasks.zipHdAssets]) {
doLast {
rootProject.ext.assetsHdPackDir.eachFile() { file ->
String fileName = file.getName()
if (fileName.endsWith(".zip")) {
task("${name}_${fileName}", type: JavaExec) {
main = MAIN_CLASS
args = [file]
classpath sourceSets.main.output.classesDir
classpath += sourceSets.main.runtimeClasspath
def stdout = new ByteArrayOutputStream()
standardOutput = stdout
doLast {
(new File("${assetsHdPackDir.getAbsolutePath()}/${fileName.split("\\.")[0]}.checksum")).write(stdout.toString().trim());
}
}.execute()
}
}
}
}
\ No newline at end of file
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