adding support 1.13 new Material class with new Minecraft Items render for Menu Preview
No files matched your search
@@ -0,0 +1,94 @@
|
|||||||
|
@file:DependsOn("io.ktor:ktor-client-core:1.4.0")
|
||||||
|
@file:DependsOn("io.ktor:ktor-client-core-jvm:1.4.0")
|
||||||
|
@file:DependsOn("io.ktor:ktor-client-apache:1.4.0")
|
||||||
|
@file:DependsOn("io.ktor:ktor-client-json-jvm:1.4.0")
|
||||||
|
@file:DependsOn("io.ktor:ktor-client-gson:1.4.0")
|
||||||
|
|
||||||
|
@file:DependsOn("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9")
|
||||||
|
|
||||||
|
// HTML
|
||||||
|
@file:DependsOn("it.skrape:skrapeit-core:1.0.0-alpha6")
|
||||||
|
@file:DependsOn("io.github.rybalkinsd:kohttp:0.12.0")
|
||||||
|
@file:DependsOn("org.jsoup:jsoup:1.13.1")
|
||||||
|
|
||||||
|
// IMAGE RESIZE
|
||||||
|
@file:DependsOn("com.sksamuel.scrimage:scrimage-core:4.0.6")
|
||||||
|
@file:DependsOn("com.sksamuel.scrimage:scrimage-formats-extra:4.0.6")
|
||||||
|
@file:DependsOn("ar.com.hjg:pngj:2.1.0")
|
||||||
|
@file:DependsOn("com.github.zh79325:open-gif:1.0.4")
|
||||||
|
|
||||||
|
import com.sksamuel.scrimage.ImmutableImage
|
||||||
|
import com.sksamuel.scrimage.nio.PngReader
|
||||||
|
import com.sksamuel.scrimage.nio.PngWriter
|
||||||
|
import io.ktor.client.*
|
||||||
|
import io.ktor.client.engine.apache.*
|
||||||
|
import io.ktor.client.request.*
|
||||||
|
import it.skrape.core.htmlDocument
|
||||||
|
import it.skrape.extract
|
||||||
|
import it.skrape.skrape
|
||||||
|
import kotlinx.coroutines.flow.asFlow
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import java.io.File
|
||||||
|
import kotlinx.coroutines.flow.*
|
||||||
|
|
||||||
|
data class Item(
|
||||||
|
val id: String,
|
||||||
|
val image: String
|
||||||
|
)
|
||||||
|
|
||||||
|
val items = skrape {
|
||||||
|
url = "https://www.deadmap.com/idlist"
|
||||||
|
|
||||||
|
extract {
|
||||||
|
htmlDocument {
|
||||||
|
findFirst("#idlist").findAll("tr") {
|
||||||
|
PngReader()
|
||||||
|
|
||||||
|
map {
|
||||||
|
val img = it.findFirst("img")
|
||||||
|
.attribute("src")
|
||||||
|
.replace(" ", "%20")
|
||||||
|
|
||||||
|
val id = it.findFirst("i").text
|
||||||
|
|
||||||
|
Item(id, "https://www.deadmap.com/$img")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println(items.joinToString("\n"))
|
||||||
|
|
||||||
|
runBlocking {
|
||||||
|
val client = HttpClient(Apache)
|
||||||
|
|
||||||
|
val iconsFolder = File("../src/main/resources/assets/items-13").canonicalFile
|
||||||
|
iconsFolder.mkdirs()
|
||||||
|
|
||||||
|
items.withIndex()
|
||||||
|
.asFlow()
|
||||||
|
.onEach { (index, item) ->
|
||||||
|
val (id, imageUrl) = item
|
||||||
|
println("Downloading item: $id ($index/${items.size - 1})")
|
||||||
|
val name = id.removePrefix("minecraft:")
|
||||||
|
|
||||||
|
val imageBytes = client.get<ByteArray>(imageUrl)
|
||||||
|
|
||||||
|
val image = ImmutableImage.loader()
|
||||||
|
.fromBytes(imageBytes)
|
||||||
|
.run {
|
||||||
|
val tags = metadata.tags()
|
||||||
|
val width = tags.first { it.name.contains("Width") }.rawValue.toInt()
|
||||||
|
val height = tags.first { it.name.contains("Height") }.rawValue.toInt()
|
||||||
|
|
||||||
|
if(width > 32 || height > 32)
|
||||||
|
scaleTo(32, 32)
|
||||||
|
else this
|
||||||
|
}
|
||||||
|
|
||||||
|
image.output(PngWriter.NoCompression, File(iconsFolder, "$name.png"))
|
||||||
|
println("Complete download and resize: $id ($index/${items.size - 1})")
|
||||||
|
}
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
@@ -9,6 +9,6 @@ data class MenuDeclaration(
|
|||||||
data class MenuSlotDeclaration(
|
data class MenuSlotDeclaration(
|
||||||
val line: Int,
|
val line: Int,
|
||||||
val slot: Int,
|
val slot: Int,
|
||||||
val itemId: Int?,
|
val item: String,
|
||||||
val isSelected: Boolean = false
|
val isSelected: Boolean = false
|
||||||
)
|
)
|
||||||
@@ -17,6 +17,7 @@ class InventoryComponent(
|
|||||||
private val minecraftFontResource = "/assets/fonts/Minecraftia-Regular.ttf"
|
private val minecraftFontResource = "/assets/fonts/Minecraftia-Regular.ttf"
|
||||||
private val spritesFolder = "/assets/sprites"
|
private val spritesFolder = "/assets/sprites"
|
||||||
private val itemsSpriteFolder = "/assets/items"
|
private val itemsSpriteFolder = "/assets/items"
|
||||||
|
private val items13SpriteFolder = "/assets/items-13"
|
||||||
|
|
||||||
// the selected-border is 36x36 and not 32x32
|
// the selected-border is 36x36 and not 32x32
|
||||||
private val selectedBorderSizeDiff = 2
|
private val selectedBorderSizeDiff = 2
|
||||||
@@ -34,8 +35,14 @@ class InventoryComponent(
|
|||||||
private val itemsImage = declaration.slots.filter {
|
private val itemsImage = declaration.slots.filter {
|
||||||
it.line in 1..declaration.lines && it.slot in 1..9
|
it.line in 1..declaration.lines && it.slot in 1..9
|
||||||
}.keysToMap {
|
}.keysToMap {
|
||||||
ImageLoader.loadFromResource("$itemsSpriteFolder/${it.itemId}-0.png")
|
val item = runCatching { MinecraftItem.valueOf(it.item) }.getOrNull()
|
||||||
//?.getScaledInstance(16, 16, Image.SCALE_FAST)
|
|
||||||
|
if(item != null) {
|
||||||
|
// TODO: Support data
|
||||||
|
ImageLoader.loadFromResource("$itemsSpriteFolder/${item.id}-0.png")
|
||||||
|
} else {
|
||||||
|
ImageLoader.loadFromResource("$items13SpriteFolder/${it.item.toLowerCase()}.png")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
private val selectionImage = if(declaration.slots.any { it.isSelected })
|
private val selectionImage = if(declaration.slots.any { it.isSelected })
|
||||||
ImageLoader.loadFromResource("$spritesFolder/selected-border.png")
|
ImageLoader.loadFromResource("$spritesFolder/selected-border.png")
|
||||||
|
|||||||
@@ -68,14 +68,12 @@ fun findMenuDeclaration(
|
|||||||
val typeExpression = materialExpression.selectorExpression as? KtNameReferenceExpression ?: return@mapNotNull null
|
val typeExpression = materialExpression.selectorExpression as? KtNameReferenceExpression ?: return@mapNotNull null
|
||||||
val materialName = typeExpression.text ?: return@mapNotNull null
|
val materialName = typeExpression.text ?: return@mapNotNull null
|
||||||
|
|
||||||
val item = runCatching { MinecraftItem.valueOf(materialName) }.getOrNull()
|
|
||||||
|
|
||||||
val isSelected = it.getLineNumber() == currentSelectedLine
|
val isSelected = it.getLineNumber() == currentSelectedLine
|
||||||
|
|
||||||
MenuSlotDeclaration(
|
MenuSlotDeclaration(
|
||||||
line,
|
line,
|
||||||
slot,
|
slot,
|
||||||
item?.id,
|
materialName,
|
||||||
isSelected
|
isSelected
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 329 B |
|
After Width: | Height: | Size: 455 B |
|
After Width: | Height: | Size: 210 B |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 81 B |
|
After Width: | Height: | Size: 246 B |
|
After Width: | Height: | Size: 2.4 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 270 B |
|
After Width: | Height: | Size: 315 B |
|
After Width: | Height: | Size: 240 B |
|
After Width: | Height: | Size: 249 B |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 274 B |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 593 B |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 2.4 KiB |
|
After Width: | Height: | Size: 287 B |
|
After Width: | Height: | Size: 191 B |
|
After Width: | Height: | Size: 225 B |
|
After Width: | Height: | Size: 971 B |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 325 B |
|
After Width: | Height: | Size: 462 B |
|
After Width: | Height: | Size: 219 B |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 309 B |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 539 B |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 308 B |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 262 B |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 493 B |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 261 B |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 308 B |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 264 B |
|
After Width: | Height: | Size: 1.3 KiB |