feat(IconExporter): 폴더 구분 제거 - 단일 폴더로 통합
- blocks/items 폴더 구분 제거 - 모든 아이콘을 icons/<name>.png로 저장 - ZIP 구조 단순화 (metadata.json + 파일명.png) - 압축 후 PNG 파일만 삭제
This commit is contained in:
parent
4949a7071e
commit
215baf9361
1 changed files with 28 additions and 71 deletions
|
|
@ -11,11 +11,9 @@ import java.util.zip.ZipEntry
|
|||
import java.util.zip.ZipOutputStream
|
||||
import kotlin.io.path.exists
|
||||
import kotlin.io.path.name
|
||||
import kotlin.io.path.pathString
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.core.registries.BuiltInRegistries
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.world.item.BlockItem
|
||||
import net.minecraft.world.item.Item
|
||||
import net.minecraft.world.item.ItemStack
|
||||
|
||||
|
|
@ -134,12 +132,8 @@ object IconExportManager {
|
|||
}
|
||||
|
||||
try {
|
||||
// 아이템이 블록인지 확인 (BlockItem이면 블록, 아니면 아이템)
|
||||
val isBlock = item is BlockItem
|
||||
val type = if (isBlock) "blocks" else "items"
|
||||
|
||||
// 저장 경로 생성
|
||||
val outputPath = getOutputPath(itemId.namespace, type, itemId.path)
|
||||
// 저장 경로 생성 (blocks/items 구분 없이 단일 폴더)
|
||||
val outputPath = getOutputPath(itemId.namespace, itemId.path)
|
||||
|
||||
// 이미 파일이 존재하고 덮어쓰기가 비활성화된 경우 스킵
|
||||
if (outputPath.exists() && !overwrite) {
|
||||
|
|
@ -173,16 +167,13 @@ object IconExportManager {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 아이템 ID로 출력 경로 생성 형식: icons/<namespace>/<type>/<path>.png 예:
|
||||
* icons/create/blocks/brass_casing.png
|
||||
*/
|
||||
private fun getOutputPath(namespace: String, type: String, path: String): Path {
|
||||
/** 아이템 ID로 출력 경로 생성 형식: icons/<path>.png 예: icons/brass_casing.png */
|
||||
private fun getOutputPath(namespace: String, path: String): Path {
|
||||
val mc = Minecraft.getInstance()
|
||||
val gameDir = mc.gameDirectory.toPath()
|
||||
|
||||
// icons/<namespace>/<type>/<path>.png
|
||||
return gameDir.resolve("icons").resolve(namespace).resolve(type).resolve("$path.png")
|
||||
// icons/<path>.png (단일 폴더)
|
||||
return gameDir.resolve("icons").resolve("$path.png")
|
||||
}
|
||||
|
||||
/** 진행률 로그 출력 */
|
||||
|
|
@ -283,19 +274,6 @@ object IconExportManager {
|
|||
|
||||
IconExporter.LOGGER.info("ZIP 압축 생성 중: {}", zipPath)
|
||||
|
||||
// 압축할 모드 폴더 경로 (특정 모드 또는 전체)
|
||||
val targetDir =
|
||||
if (currentModFilter != null) {
|
||||
iconsDir.resolve(currentModFilter!!)
|
||||
} else {
|
||||
iconsDir
|
||||
}
|
||||
|
||||
if (!targetDir.exists()) {
|
||||
IconExporter.LOGGER.error("대상 폴더가 없습니다: {}", targetDir)
|
||||
return null
|
||||
}
|
||||
|
||||
ZipOutputStream(FileOutputStream(zipPath.toFile())).use { zos ->
|
||||
// metadata.json 추가
|
||||
val metadata = buildString {
|
||||
|
|
@ -311,33 +289,13 @@ object IconExportManager {
|
|||
zos.write(metadata.toByteArray(Charsets.UTF_8))
|
||||
zos.closeEntry()
|
||||
|
||||
// PNG 파일 추가
|
||||
if (currentModFilter != null) {
|
||||
// 특정 모드만 압축
|
||||
Files.walk(targetDir).use { paths ->
|
||||
paths.filter { Files.isRegularFile(it) && it.name.endsWith(".png") }.forEach {
|
||||
file ->
|
||||
try {
|
||||
// ZIP 내 상대 경로: blocks/<item>.png 또는 items/<item>.png
|
||||
val relativePath =
|
||||
targetDir.relativize(file).pathString.replace("\\", "/")
|
||||
zos.putNextEntry(ZipEntry(relativePath))
|
||||
Files.copy(file, zos)
|
||||
zos.closeEntry()
|
||||
} catch (e: Exception) {
|
||||
IconExporter.LOGGER.error("ZIP에 파일 추가 실패: {} - {}", file, e.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 전체 압축
|
||||
// PNG 파일 추가 (모든 파일을 단순히 파일명만으로 압축)
|
||||
Files.walk(iconsDir).use { paths ->
|
||||
paths.filter { Files.isRegularFile(it) && it.name.endsWith(".png") }.forEach {
|
||||
file ->
|
||||
paths.filter { Files.isRegularFile(it) && it.name.endsWith(".png") }.forEach { file
|
||||
->
|
||||
try {
|
||||
val relativePath =
|
||||
iconsDir.relativize(file).pathString.replace("\\", "/")
|
||||
zos.putNextEntry(ZipEntry(relativePath))
|
||||
// ZIP 내 경로: 파일명만 사용 (예: brass_casing.png)
|
||||
zos.putNextEntry(ZipEntry(file.name))
|
||||
Files.copy(file, zos)
|
||||
zos.closeEntry()
|
||||
} catch (e: Exception) {
|
||||
|
|
@ -346,25 +304,24 @@ object IconExportManager {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IconExporter.LOGGER.info("ZIP 압축 완료: {}", zipPath)
|
||||
|
||||
// 압축 완료 후 원본 폴더 삭제
|
||||
// 압축 완료 후 원본 PNG 파일 삭제 (ZIP 파일 제외)
|
||||
try {
|
||||
if (currentModFilter != null) {
|
||||
// 특정 모드 폴더만 삭제
|
||||
deleteDirectory(targetDir)
|
||||
IconExporter.LOGGER.info("원본 폴더 삭제됨: {}", targetDir)
|
||||
} else {
|
||||
// 전체 모드인 경우 각 모드 폴더 삭제 (ZIP 파일 제외)
|
||||
Files.list(iconsDir).use { dirs ->
|
||||
dirs.filter { Files.isDirectory(it) }.forEach { dir -> deleteDirectory(dir) }
|
||||
}
|
||||
IconExporter.LOGGER.info("모든 원본 폴더 삭제됨")
|
||||
}
|
||||
Files.list(iconsDir).use { files ->
|
||||
files.filter { Files.isRegularFile(it) && it.name.endsWith(".png") }.forEach { file
|
||||
->
|
||||
try {
|
||||
Files.delete(file)
|
||||
} catch (e: Exception) {
|
||||
IconExporter.LOGGER.error("원본 폴더 삭제 실패: {}", e.message)
|
||||
IconExporter.LOGGER.error("파일 삭제 실패: {} - {}", file, e.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
IconExporter.LOGGER.info("원본 PNG 파일 삭제됨")
|
||||
} catch (e: Exception) {
|
||||
IconExporter.LOGGER.error("원본 파일 삭제 실패: {}", e.message)
|
||||
}
|
||||
|
||||
return zipPath
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue