mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-15 10:25:06 -04:00
improve screenshot taking
This commit is contained in:
parent
a78f24c15c
commit
79eb7afa49
@ -35,21 +35,20 @@ class ScreenshotTaker(
|
|||||||
) {
|
) {
|
||||||
fun takeScreenshot() {
|
fun takeScreenshot() {
|
||||||
try {
|
try {
|
||||||
|
val width = renderWindow.window.size.x
|
||||||
|
val height = renderWindow.window.size.y
|
||||||
|
val buffer = renderWindow.renderSystem.readPixels(Vec2i(0, 0), Vec2i(width, height), PixelTypes.RGBA)
|
||||||
|
|
||||||
val basePath = "${RunConfiguration.HOME_DIRECTORY}/screenshots/${renderWindow.connection.address.hostname}/${DATE_FORMATTER.format(System.currentTimeMillis())}"
|
val basePath = "${RunConfiguration.HOME_DIRECTORY}/screenshots/${renderWindow.connection.address.hostname}/${DATE_FORMATTER.format(System.currentTimeMillis())}"
|
||||||
var path = "$basePath.png"
|
var path = "$basePath.png"
|
||||||
var i = 1
|
var i = 1
|
||||||
while (File(path).exists()) {
|
while (File(path).exists()) {
|
||||||
path = "${basePath}_${i++}.png"
|
path = "${basePath}_${i++}.png"
|
||||||
if (i > 10) {
|
if (i > MAX_FILES_CHECK) {
|
||||||
screenshotFail(StackOverflowError())
|
throw StackOverflowError("There are already > $MAX_FILES_CHECK screenshots with this date! Please try again!")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val width = renderWindow.window.size.x
|
|
||||||
val height = renderWindow.window.size.y
|
|
||||||
val buffer = renderWindow.renderSystem.readPixels(Vec2i(0, 0), Vec2i(width, height), PixelTypes.RGBA)
|
|
||||||
|
|
||||||
DefaultThreadPool += {
|
DefaultThreadPool += {
|
||||||
try {
|
try {
|
||||||
val bufferedImage = BufferedImage(width, height, BufferedImage.TYPE_INT_RGB)
|
val bufferedImage = BufferedImage(width, height, BufferedImage.TYPE_INT_RGB)
|
||||||
@ -88,20 +87,21 @@ class ScreenshotTaker(
|
|||||||
// },
|
// },
|
||||||
))
|
))
|
||||||
} catch (exception: Exception) {
|
} catch (exception: Exception) {
|
||||||
screenshotFail(exception)
|
exception.fail()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (exception: Exception) {
|
} catch (exception: Exception) {
|
||||||
screenshotFail(exception)
|
exception.fail()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun screenshotFail(exception: Throwable?) {
|
private fun Throwable?.fail() {
|
||||||
exception?.printStackTrace()
|
this?.printStackTrace()
|
||||||
renderWindow.sendDebugMessage("§cFailed to make a screenshot!")
|
renderWindow.sendDebugMessage("§cFailed to make a screenshot!")
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val DATE_FORMATTER = SimpleDateFormat("yyyy-MM-dd_HH.mm.ss")
|
private val DATE_FORMATTER = SimpleDateFormat("yyyy-MM-dd_HH.mm.ss")
|
||||||
|
private const val MAX_FILES_CHECK = 10
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user