From 215baf9361032d7ca1e36314d4f30c5d60c4ca0b Mon Sep 17 00:00:00 2001 From: Caadiq Date: Fri, 26 Dec 2025 19:16:29 +0900 Subject: [PATCH] =?UTF-8?q?feat(IconExporter):=20=ED=8F=B4=EB=8D=94=20?= =?UTF-8?q?=EA=B5=AC=EB=B6=84=20=EC=A0=9C=EA=B1=B0=20-=20=EB=8B=A8?= =?UTF-8?q?=EC=9D=BC=20=ED=8F=B4=EB=8D=94=EB=A1=9C=20=ED=86=B5=ED=95=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - blocks/items 폴더 구분 제거 - 모든 아이콘을 icons/.png로 저장 - ZIP 구조 단순화 (metadata.json + 파일명.png) - 압축 후 PNG 파일만 삭제 --- .../iconexporter/export/IconExportManager.kt | 99 ++++++------------- 1 file changed, 28 insertions(+), 71 deletions(-) diff --git a/IconExporter/src/main/kotlin/com/beemer/iconexporter/export/IconExportManager.kt b/IconExporter/src/main/kotlin/com/beemer/iconexporter/export/IconExportManager.kt index 09e745c..6f618b2 100644 --- a/IconExporter/src/main/kotlin/com/beemer/iconexporter/export/IconExportManager.kt +++ b/IconExporter/src/main/kotlin/com/beemer/iconexporter/export/IconExportManager.kt @@ -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///.png 예: - * icons/create/blocks/brass_casing.png - */ - private fun getOutputPath(namespace: String, type: String, path: String): Path { + /** 아이템 ID로 출력 경로 생성 형식: icons/.png 예: icons/brass_casing.png */ + private fun getOutputPath(namespace: String, path: String): Path { val mc = Minecraft.getInstance() val gameDir = mc.gameDirectory.toPath() - // icons///.png - return gameDir.resolve("icons").resolve(namespace).resolve(type).resolve("$path.png") + // icons/.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,38 +289,17 @@ 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/.png 또는 items/.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 { - // 전체 압축 - Files.walk(iconsDir).use { paths -> - paths.filter { Files.isRegularFile(it) && it.name.endsWith(".png") }.forEach { - file -> - try { - val relativePath = - iconsDir.relativize(file).pathString.replace("\\", "/") - zos.putNextEntry(ZipEntry(relativePath)) - Files.copy(file, zos) - zos.closeEntry() - } catch (e: Exception) { - IconExporter.LOGGER.error("ZIP에 파일 추가 실패: {} - {}", file, e.message) - } + // PNG 파일 추가 (모든 파일을 단순히 파일명만으로 압축) + Files.walk(iconsDir).use { paths -> + paths.filter { Files.isRegularFile(it) && it.name.endsWith(".png") }.forEach { file + -> + try { + // ZIP 내 경로: 파일명만 사용 (예: brass_casing.png) + zos.putNextEntry(ZipEntry(file.name)) + Files.copy(file, zos) + zos.closeEntry() + } catch (e: Exception) { + IconExporter.LOGGER.error("ZIP에 파일 추가 실패: {} - {}", file, e.message) } } } @@ -350,21 +307,21 @@ 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) } + 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("파일 삭제 실패: {} - {}", file, e.message) + } } - IconExporter.LOGGER.info("모든 원본 폴더 삭제됨") } + IconExporter.LOGGER.info("원본 PNG 파일 삭제됨") } catch (e: Exception) { - IconExporter.LOGGER.error("원본 폴더 삭제 실패: {}", e.message) + IconExporter.LOGGER.error("원본 파일 삭제 실패: {}", e.message) } return zipPath