Files
assistant-android/scripts/compile2luac.gradle

119 lines
3.5 KiB
Groovy

import groovy.json.JsonSlurper
import org.apache.tools.ant.taskdefs.condition.Os
def assetsDir = new File(projectDir, '../chhota-bheem-res/win32/')
// read cocos studio build-cfg file
def config = null;
File f = file('build-cfg.json')
if (f.exists()) {
config = f.withReader { r ->
new JsonSlurper().parse(r)
}
}
print(f)
print(config)
// get local.properties and set
File propFile = new File('../local.properties');
if (propFile.exists()) {
def Properties props = new Properties()
props.load(new FileInputStream(propFile))
print(props.get("COCOS_FRAMEWORKS"))
print(properties)
properties.put('COCOS_FRAMEWORKS', props.get('COCOS_FRAMEWORKS'))
}
// get and define ndk_module_path
String ndkModulePath = null;
String cocos_framework = properties.getProperty('COCOS_FRAMEWORKS')
def config_ndk_modules = config.ndk_module_path
//COCOS_FRAMEWORKS = cocos_framework
for (String path : config_ndk_modules) {
String module_path = path.replace('${COCOS_FRAMEWORKS}', cocos_framework)
if (ndkModulePath == null) {
ndkModulePath = module_path
} else {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
ndkModulePath += ";" + new File(module_path).absolutePath
} else {
ndkModulePath += ":" + new File(module_path).absolutePath
}
}
}
// copy resources defined by build-cfg.json, ref:${COCOS_FRAMEWORKS}/cocos2dx-3.9/tools/cocos2d-console/plugins/xxx}
task copyResources << {
// copy assets
config.copy_resources.each { res ->
copy {
from new File(projectDir, res.from.toString()).absolutePath
into new File(assetsDir, res.to.toString()).absolutePath
}
// println('from ' + new File(projectDir, res.from.toString()).absolutePath)
// println('to ' + new File(projectDir, assetsDir + File.separator + res.to.toString()).absolutePath)
}
// copy config
config.must_copy_resources.each { cfg ->
copy {
from new File(projectDir, cfg.from.toString()).absolutePath
into new File(assetsDir, cfg.to.toString()).absolutePath
include '*'
exclude ''
}
// println('from ' + new File(projectDir, cfg.from.toString()).absolutePath)
// println('to ' + new File(projectDir, assetsDir + File.separator + cfg.to.toString()).absolutePath)
}
}
task cleanResources << {
config.copy_resources.each { res ->
delete fileTree(new File(assetsDir, res.to.toString())) {
include '**/*'
}
}
config.must_copy_resources.each { cfg ->
delete fileTree(new File(assetsDir, cfg.to.toString())) {
include '**/*'
}
}
}
// delete *.lua
task deleteLuaSource << {
String lua_dir_src = new File(assetsDir, 'src').toString()
delete fileTree(lua_dir_src) {
include '**/*.lua'
exclude '**/*.luac'
}
}
// compile lua src to assets/src
task buildLua(type: Exec, description: 'Compile lua via cocos command line tool') {
// read cocos studio cocos-project file
File jf = new File(rootProject.projectDir, '.cocos-project.json')
def jCfg = jf.withReader { r ->
new JsonSlurper().parse(r)
}
String engineVer = jCfg.engine_version
String cocos_cmd_path = cocos_framework + File.separator + engineVer + File.separator + 'tools' + File.separator \
+ 'cocos2d-console' + File.separator + 'bin' + File.separator + 'cocos'
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
cocos_cmd_path = cocos_cmd_path + '.bat'
}
String lua_dir_src = new File(rootProject.projectDir, 'src').toString()
String lua_dir_dst = new File(assetsDir, 'src').toString()
commandLine "$cocos_cmd_path", 'luacompile', '-s', lua_dir_src, '-d', lua_dir_dst
doFirst {
copyResources.execute()
}
doLast {
deleteLuaSource.execute()
}
}