diff --git a/src/main/java/lemon/hxdd/builder/AssetExtractor.java b/src/main/java/lemon/hxdd/builder/AssetExtractor.java index 5b5c98f..0b7a241 100644 --- a/src/main/java/lemon/hxdd/builder/AssetExtractor.java +++ b/src/main/java/lemon/hxdd/builder/AssetExtractor.java @@ -56,15 +56,6 @@ public void ExtractFromWad() { ExportData(data, pal); } - public void ExtractFromPK3() { - // Extract from ZIP - //ZipAssets pk3 = new ZipAssets(this.mf.sourcePK3 + ".pk3"); - this.za.SetFile(new File(this.mf.sourcePK3)); - byte[] data = this.za.ExtractFileAsData(this.mf.inputName); - Palette pal = GetPlaypal(); - ExportData(data, pal); - } - private void ExportData(byte[] data, Palette pal) { if (mf.decodeType == "lumps") { LumpExport(data); @@ -132,7 +123,7 @@ private void TextLumpExport(byte[] data) { //System.out.println("Exported " + path); } catch (IOException e) { - System.out.println("Failed to export lump " + path + " from " + mf.source); + System.out.println("Failed to export lump " + path); } } @@ -160,7 +151,7 @@ private void GraphicsExport(byte[] data, Palette pal) { //System.out.println("Exported " + imagePath); } catch (IOException e) { - System.out.println("Failed to export graphics " + imagePath + " from " + mf.source); + System.out.println("Failed to export graphics " + imagePath); //e.printStackTrace(); } } @@ -185,7 +176,7 @@ private void FlatExport(byte[] data, Palette pal) { File newFile = new File(imagePath); ImageIO.write(image, "PNG", newFile); } catch (IOException e) { - System.out.println("Failed to export flat " + imagePath + " from " + mf.source); + System.out.println("Failed to export flat " + imagePath); } } @@ -228,7 +219,7 @@ private void SoundExport() { //System.out.println("Exported " + filePath + ".lmp"); } } catch (IOException | UnsupportedAudioFileException e) { - System.out.println("Failed to export flat " + filePath + " from " + mf.source); + System.out.println("Failed to export flat " + filePath); e.printStackTrace(); } } @@ -259,7 +250,7 @@ private void MusicExport(boolean lowerVolume) { music.writeBytes(new FileOutputStream(target, false)); //System.out.println("Exported " + filePath + ".mus"); } catch (IOException e) { - System.out.println("Failed to export " + filePath + ".mus" + " from " + mf.source); + System.out.println("Failed to export " + filePath + ".mus"); //e.printStackTrace(); } } diff --git a/src/main/java/lemon/hxdd/builder/MetaFile.java b/src/main/java/lemon/hxdd/builder/MetaFile.java index 3101010..971d29a 100644 --- a/src/main/java/lemon/hxdd/builder/MetaFile.java +++ b/src/main/java/lemon/hxdd/builder/MetaFile.java @@ -1,7 +1,6 @@ package lemon.hxdd.builder; import net.mtrop.doom.Wad; -import net.mtrop.doom.WadFile; import net.mtrop.doom.graphics.Flat; import net.mtrop.doom.graphics.PNGPicture; import net.mtrop.doom.graphics.Palette; @@ -23,8 +22,7 @@ import java.util.Objects; public class MetaFile { - String source; - String sourcePK3; + //String source; String inputName; String outputName; String type; @@ -43,9 +41,8 @@ public class MetaFile { MetaFile() { } - public void Define(String name, String decodeType, String folder, String sourceName) { - this.source = sourceName; // check if pk3 from filename - this.sourcePK3 = null; // PK3 file, overrides wad extract + public void Define(String name, String decodeType, String folder, Wad sourceWad) { + this.wad = sourceWad; this.inputName = name; // input filename this.outputName = name; // output filename this.folder = folder; // export folder @@ -61,18 +58,18 @@ public void ExtractFile(String path) { this.pathTemp = path; // Get data from WAD or PK3 ZIP. try { - if (this.sourcePK3 != null) { - this.ExtractFromPK3(); - } else { + //if (this.sourcePK3 != null) { + // this.ExtractFromPK3(); + //} else { this.ExtractFromWad(); - } + //} } catch (IOException e) { // log error } } public void ExtractFromWad() throws IOException { - this.wad = new WadFile(this.source); + //this.wad = new WadFile(this.source); byte[] data = this.wad.getData(this.inputName); if (this.pal == null) { @@ -80,16 +77,7 @@ public void ExtractFromWad() throws IOException { } ExportData(data); - this.wad.close(); - } - - public void ExtractFromPK3() { - // Extract from ZIP - //ZipAssets pk3 = new ZipAssets(this.mf.sourcePK3 + ".pk3"); - this.za.SetFile(new File(this.sourcePK3)); - byte[] data = this.za.ExtractFileAsData(this.inputName); - Palette pal = GetPlaypal(); - ExportData(data, pal); + //this.wad.close(); } public void SetWad(Wad wf) { @@ -167,7 +155,7 @@ private void TextLumpExport(byte[] data) { //System.out.println("Exported " + path); } catch (IOException e) { - System.out.println("Failed to export lump " + path + " from " + this.source); + System.out.println("Failed to export lump " + path); } } @@ -195,7 +183,7 @@ private void GraphicsExport(byte[] data, Palette pal) { //System.out.println("Exported " + imagePath); } catch (IOException e) { - System.out.println("Failed to export graphics " + imagePath + " from " + this.source); + System.out.println("Failed to export graphics " + imagePath); //e.printStackTrace(); } } @@ -220,7 +208,7 @@ private void FlatExport(byte[] data, Palette pal) { File newFile = new File(imagePath); ImageIO.write(image, "PNG", newFile); } catch (IOException e) { - System.out.println("Failed to export flat " + imagePath + " from " + this.source); + System.out.println("Failed to export flat " + imagePath); } } @@ -263,7 +251,7 @@ private void SoundExport() { //System.out.println("Exported " + filePath + ".lmp"); } } catch (IOException | UnsupportedAudioFileException e) { - System.out.println("Failed to export flat " + filePath + " from " + this.source); + System.out.println("Failed to export flat " + filePath); e.printStackTrace(); } } @@ -294,7 +282,7 @@ private void MusicExport(boolean lowerVolume) { music.writeBytes(new FileOutputStream(target, false)); //System.out.println("Exported " + filePath + ".mus"); } catch (IOException e) { - System.out.println("Failed to export " + filePath + ".mus" + " from " + this.source); + System.out.println("Failed to export " + filePath + ".mus"); //e.printStackTrace(); } } diff --git a/src/main/java/lemon/hxdd/builder/PackageBuilder.java b/src/main/java/lemon/hxdd/builder/PackageBuilder.java index 4e40867..2d561ec 100644 --- a/src/main/java/lemon/hxdd/builder/PackageBuilder.java +++ b/src/main/java/lemon/hxdd/builder/PackageBuilder.java @@ -146,7 +146,7 @@ public void Start() { try { p.getValue().close(); } catch (IOException e) { - // + e.printStackTrace(); } }); @@ -746,10 +746,12 @@ private void ExportRealm667() { String pathMarineStuff = path + "MarineStuff.wad"; try { + Wad wadMarineStuff = new WadFile(pathMarineStuff); + MetaFile f = new MetaFile(); f.SetPalette(GraphicUtils.DOOM); f.SetWad(new WadFile(pathMarineStuff)); - f.Define("AHLMA0", "sprite", "sprites", pathMarineStuff); + f.Define("AHLMA0", "sprite", "sprites", wadMarineStuff); f.folder = "sprites/realm667"; f.ExtractFile(pathTemp); f.inputName = "BOOTA0"; @@ -759,12 +761,14 @@ private void ExportRealm667() { f.outputName = "UNIFA0"; f.ExtractFile(pathTemp); - f.Define("CREDITS", "textlump","", pathMarineStuff); + f.Define("CREDITS", "textlump","", wadMarineStuff); f.outputName = "realm667/marinestuff/CREDITS.txt"; f.ExtractFile(pathTemp); - f.Define("INFO", "textlump","", pathMarineStuff); + f.Define("INFO", "textlump","", wadMarineStuff); f.outputName = "realm667/marinestuff/INFO.txt"; f.ExtractFile(pathTemp); + + wadMarineStuff.close(); } catch (IOException e) { e.printStackTrace(); } diff --git a/src/main/java/lemon/hxdd/builder/WadFileOrganizer.java b/src/main/java/lemon/hxdd/builder/WadFileOrganizer.java index 5e5f783..370f476 100644 --- a/src/main/java/lemon/hxdd/builder/WadFileOrganizer.java +++ b/src/main/java/lemon/hxdd/builder/WadFileOrganizer.java @@ -72,16 +72,16 @@ public void Parse(String path) throws IOException { MetaFile mf = new MetaFile(); mf.SetWad(this.wad); if (Arrays.asList(EngineLumps).contains(entryName)) { - mf.Define(entryName, "lump","lumps", source); + mf.Define(entryName, "lump","lumps", this.wad); mf.SetWad(this.wad); this.entryMaps.get("lumps").put(entryName, mf); } else if (Arrays.asList(GameLumps).contains(entryName.toLowerCase())) { // Will let files be unique and not fight over a single entry. - mf.Define(entryName, "lump","lumps", source); + mf.Define(entryName, "lump","lumps", this.wad); this.entryMaps.get("lumps").put(entryName, mf); } else if (Arrays.asList(TextLumps).contains(entryName.toLowerCase())) { // TextLumps should be renamed per game as to prevent conflicts - mf.Define(entryName, "textlump","lumps", source); + mf.Define(entryName, "textlump","lumps", this.wad); mf.outputName = entryName; this.entryMaps.get("lumps").put(entryName, mf); } else if (!Arrays.asList(EntryIgnoreList).contains(entryName)) { @@ -102,19 +102,19 @@ public void Parse(String path) throws IOException { folder = ""; } } else if (entryName.startsWith("FONT")) { - mf.Define(entryName, "graphic","graphics", source); + mf.Define(entryName, "graphic","graphics", this.wad); this.entryMaps.get("graphics").put(entryName, mf); } else if (entryName.equals("ADVISOR")) { // Heretic / Hexen only advisory - mf.Define(entryName, "sprite", "graphics", source); + mf.Define(entryName, "sprite", "graphics", this.wad); this.entryMaps.get("graphics").put(entryName, mf); } else if (Arrays.asList(GraphicLumps).contains(entryName) || folder.equals("graphics")) { decodeType = "graphic"; folder = "graphics"; - mf.Define(entryName, decodeType, folder, source); + mf.Define(entryName, decodeType, folder, this.wad); this.entryMaps.get(folder).put(entryName, mf); } else if (folder.equals("sprites") || folder.equals("patches") || folder.equals("flats")) { - mf.Define(entryName, decodeType, folder, source); + mf.Define(entryName, decodeType, folder, this.wad); this.entryMaps.get(folder).put(entryName, mf); } else { try { @@ -122,10 +122,10 @@ public void Parse(String path) throws IOException { if (data.length > 4) { // startswith is hacky, but it works if ((data[0] + "" + data[1] + "" + data[2] + "" + data[3]).startsWith("778583")) { - mf.Define(entryName, "music","music", source); + mf.Define(entryName, "music","music", this.wad); this.entryMaps.get("music").put(entryName, mf); } else if ((data[0] + "" + data[1] + "" + data[2] + "" + data[3]).startsWith("301743")) { - mf.Define(entryName, "sound","sounds", source); + mf.Define(entryName, "sound","sounds", this.wad); this.entryMaps.get("sounds").put(entryName, mf); } } @@ -167,9 +167,9 @@ public MetaFile CopyFile(String folder, String source, String target) { MetaFile mfFrom = this.entryMaps.get(folder).get(source); if (mfFrom != null) { MetaFile mfCopy = new MetaFile(); - mfCopy.Define(target, mfFrom.decodeType, folder, mfFrom.source); + mfCopy.Define(target, mfFrom.decodeType, folder, mfFrom.wad); mfCopy.SetWad(mfFrom.wad); - mfCopy.sourcePK3 = mfFrom.sourcePK3; + //mfCopy.sourcePK3 = mfFrom.sourcePK3; mfCopy.inputName = mfFrom.inputName; mfCopy.folder = mfFrom.folder; mfCopy.decodeType = mfFrom.decodeType;