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

#30 Automatic atlas loading

 * new api for loading texture regions from atlases
 * removed old texture loader
 * gradle tasks for assets preparing
 * gradle UP-TO-DATE task check
 * application new api fix
 * atlases automatic linear filtering
 * sound assets conversion to flat hierarchy
 * automatic global assets loading
 * automatic screen and game local assets loading
parent ad9415ed
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.tools.texturepacker.TexturePacker
buildscript {
......@@ -17,7 +18,8 @@ buildscript {
}
final assetsDirName = "assets"
final atlasesDirName = "atlases"
final assetsSourceDirName = "src"
final assetsDestinationDirName = "dest"
ext {
assetsChecksumPattern = "\"=======ASSETS_CHECKSUM=======\""
......@@ -59,16 +61,95 @@ allprojects {
}
}
task texturePacker << {
TexturePacker.Settings settings = new TexturePacker.Settings();
settings.maxWidth = 2048;
settings.maxHeight = 2048;
task clean << {
delete "${buildDir}"
}
task prepareAssets {
def sourceDir = new File(project(":core").projectDir.absolutePath + "/${assetsDirName}")
inputs.dir(sourceDir.absolutePath)
outputs.dir("${buildDir}/${assetsDirName}/${assetsSourceDirName}/")
doLast {
sourceDir.eachDir() { dir ->
if (!dir.name.equals('common')) {
String dirName = dir.getName()
String destDir = "${buildDir}/${assetsDirName}/${assetsSourceDirName}/${dirName}"
task("${name}_${dirName}", type: Copy) {
from sourceDir.absolutePath + "/common"
from dir.absolutePath
into destDir
}.execute()
}
}
}
}
task prepareSoundAssets(dependsOn: prepareAssets) {
def assetsDir = new File("${buildDir}/${assetsDirName}/")
inputs.dir("${assetsDir.absolutePath}/${assetsSourceDirName}/")
outputs.dir("${assetsDir.absolutePath}/${assetsDestinationDirName}/")
doLast {
new File("${assetsDir}/${assetsSourceDirName}/").eachDir() { langDir ->
langDir.eachDir() { sectionDir ->
sectionDir.eachDir() { atlasDir ->
task("${name}_" + atlasDir.name + "_" + langDir.name, type: Copy) {
from atlasDir
into "${buildDir}/${assetsDirName}/${assetsDestinationDirName}/${langDir.name}/${sectionDir.name}/${atlasDir.name}/"
include '**/*.mp3'
includeEmptyDirs false
eachFile { FileCopyDetails fcd ->
fcd.setPath(fcd.getRelativePath().toString().replace(File.separator, '.'))
}
}.execute()
}
}
}
}
}
task prepareGraphicAssets(dependsOn: prepareAssets) {
def assetsDir = new File("${buildDir}/${assetsDirName}/")
inputs.dir("${assetsDir.absolutePath}/${assetsSourceDirName}/")
outputs.dir("${assetsDir.absolutePath}/${assetsDestinationDirName}/")
doLast {
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 ->
sectionDir.eachDir() { atlasDir ->
TexturePacker.process(settings,
"${atlasDir}",
"${assetsDir.absolutePath}/${assetsDestinationDirName}/${langDir.name}/${sectionDir.name}/${atlasDir.name}/",
"${atlasDir.name}")
}
}
}
}
}
task zipAssets(dependsOn: [prepareSoundAssets, prepareGraphicAssets]) {
doLast {
new File(project(":core").projectDir.absolutePath + "/${assetsDirName}").eachDir() { dir ->
def assetsDir = new File(project(":core").projectDir.absolutePath + "/${assetsDirName}")
assetsDir.eachDir() { langDir ->
langDir.eachDir() { sectionDir ->
sectionDir.eachDir() { atlasdir ->
TexturePacker.process(settings, "${atlasdir}", "${buildDir}/${atlasesDirName}/${langDir.name}/${sectionDir.name}/${atlasdir.name}/", "${atlasdir.name}")
if (!dir.name.equals('common')) {
task("${name}_${dir.name}", type: Zip) {
archiveName = dir.getName() + ".zip"
destinationDir = new File(project(":android").projectDir.absolutePath + "/${assetsDirName}")
from "${buildDir}/${assetsDirName}/${assetsDestinationDirName}/${dir.name}"
}.execute()
}
}
}
......@@ -101,20 +182,6 @@ def getMapConvertedToString(Map map) {
return result;
}
task zipAssets(type:Zip) {
outputs.upToDateWhen { false }
new File(project(":core").projectDir.absolutePath + "/assets").eachDir() { dir ->
task(dir.getName(), type: Zip) {
archiveName = dir.getName() + ".zip"
ext.destDir = new File(project(":android").projectDir.absolutePath + "/assets/")
ext.destFile = new File(destDir, archiveName)
destinationDir = new File("android/assets/")
from dir.getPath()
}.execute()
}
}
project(":desktop") {
apply plugin: "java"
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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