forked from soywiz-archive/korge-next
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Partial support for gradle cache configuration on the korge plugin (s…
- Loading branch information
1 parent
bbe496a
commit 33f9f33
Showing
7 changed files
with
206 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 30 additions & 18 deletions
48
korge-gradle-plugin/src/main/kotlin/com/soywiz/korge/gradle/targets/Icons.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,47 @@ | ||
package com.soywiz.korge.gradle.targets | ||
|
||
import com.soywiz.korge.gradle.KorgeExtension | ||
import com.soywiz.korge.gradle.KorgeGradlePlugin | ||
import com.soywiz.korge.gradle.* | ||
import com.soywiz.korge.gradle.util.encodePNG | ||
import com.soywiz.korge.gradle.util.getScaledInstance | ||
import com.soywiz.korge.gradle.util.toBufferedImage | ||
import org.gradle.api.* | ||
import java.io.* | ||
import javax.imageio.ImageIO | ||
|
||
val ICON_SIZES = listOf(20, 29, 40, 44, 48, 50, 55, 57, 58, 60, 72, 76, 80, 87, 88, 100, 114, 120, 144, 152, 167, 172, 180, 196, 1024) | ||
|
||
fun tryGetResourceBytes(path: String): ByteArray? { | ||
return KorgeGradlePlugin::class.java.getResource("/" + path.trim('/'))?.readBytes() | ||
} | ||
fun tryGetResourceBytes(path: String): ByteArray? = | ||
KorgeGradlePlugin::class.java.getResource("/" + path.trim('/'))?.readBytes() | ||
|
||
fun getResourceBytes(path: String): ByteArray = tryGetResourceBytes(path) ?: error("Can't find resource '$path'") | ||
fun getResourceString(path: String): String = getResourceBytes(path).toString(Charsets.UTF_8) | ||
|
||
fun KorgeExtension.iconExists() = icon != null && icon!!.exists() | ||
fun KorgeExtension.bannerExists() = banner != null && banner!!.exists() | ||
fun KorgeExtension.getIconBytes(): ByteArray = KorgeIconProvider(this).getIconBytes() | ||
fun KorgeExtension.getBannerBytes(): ByteArray = KorgeIconProvider(this).getBannerBytes() | ||
|
||
fun KorgeExtension.getIconBytes(): ByteArray = when { | ||
iconExists() -> icon!!.readBytes() | ||
else -> getResourceBytes("/icons/korge.png") | ||
} | ||
fun KorgeExtension.getIconBytes(width: Int, height: Int = width): ByteArray = ImageIO.read(getIconBytes().inputStream()).getScaledInstance(width, height).toBufferedImage().encodePNG() | ||
fun KorgeExtension.getBannerBytes(width: Int, height: Int = width): ByteArray = ImageIO.read(getBannerBytes().inputStream()).getScaledInstance(width, height).toBufferedImage().encodePNG() | ||
|
||
fun KorgeExtension.getBannerBytes(): ByteArray = when { | ||
bannerExists() -> banner!!.readBytes() | ||
iconExists() -> icon!!.readBytes() | ||
else -> getResourceBytes("/banners/korge.png") | ||
} | ||
class KorgeIconProvider(val icon: File? = null, val banner: File? = null) { | ||
constructor(korge: KorgeExtension) : this(korge.icon, korge.banner) | ||
constructor(project: Project) : this(project.korge) | ||
|
||
fun iconExists() = icon != null && icon!!.exists() | ||
fun bannerExists() = banner != null && banner!!.exists() | ||
|
||
fun getIconBytes(): ByteArray = when { | ||
iconExists() -> icon!!.readBytes() | ||
else -> getResourceBytes("/icons/korge.png") | ||
} | ||
|
||
fun KorgeExtension.getIconBytes(width: Int, height: Int = width): ByteArray = ImageIO.read(getIconBytes().inputStream()).getScaledInstance(width, height).toBufferedImage().encodePNG() | ||
fun KorgeExtension.getBannerBytes(width: Int, height: Int = width): ByteArray = ImageIO.read(getBannerBytes().inputStream()).getScaledInstance(width, height).toBufferedImage().encodePNG() | ||
fun getBannerBytes(): ByteArray = when { | ||
bannerExists() -> banner!!.readBytes() | ||
iconExists() -> icon!!.readBytes() | ||
else -> getResourceBytes("/banners/korge.png") | ||
} | ||
|
||
|
||
fun getIconBytes(width: Int, height: Int = width): ByteArray = ImageIO.read(getIconBytes().inputStream()).getScaledInstance(width, height).toBufferedImage().encodePNG() | ||
fun getBannerBytes(width: Int, height: Int = width): ByteArray = ImageIO.read(getBannerBytes().inputStream()).getScaledInstance(width, height).toBufferedImage().encodePNG() | ||
|
||
} |
14 changes: 7 additions & 7 deletions
14
korge-gradle-plugin/src/main/kotlin/com/soywiz/korge/gradle/targets/TaskGroups.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
package com.soywiz.korge.gradle.targets | ||
|
||
val GROUP_KORGE = "korge" | ||
val GROUP_KORGE_RESOURCES = "korge-resources" | ||
val GROUP_KORGE_RUN = "run" | ||
val GROUP_KORGE_ADB = "adb" | ||
val GROUP_KORGE_LIST = "list" | ||
val GROUP_KORGE_PACKAGE = "package" | ||
val GROUP_KORGE_INSTALL = "install" | ||
const val GROUP_KORGE: String = "korge" | ||
const val GROUP_KORGE_RESOURCES: String = "korge-resources" | ||
const val GROUP_KORGE_RUN: String = "run" | ||
const val GROUP_KORGE_ADB: String = "adb" | ||
const val GROUP_KORGE_LIST: String = "list" | ||
const val GROUP_KORGE_PACKAGE: String = "package" | ||
const val GROUP_KORGE_INSTALL: String = "install" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.