Commit d803cbfd authored by Derrick's avatar Derrick
Browse files

Merge ../Advanced_Options_Map_Editor

parents 8959a100 28a4c2ee
......@@ -18,6 +18,7 @@ import H4Widgets.H4LayerPanel;
import H4Widgets.H4ResourceFrame;
import H4Widgets.H4ResourcePanel;
import H4Widgets.H4SoundPanel;
import H4Widgets.H4TablePanel;
import H4Widgets.H4TransitionPanel;
import Interfaces.Bundle;
import Interfaces.H4ActorSequenceParser;
......@@ -32,6 +33,8 @@ import Interfaces.H4MappingBundle;
import Interfaces.H4ResourceFileParser;
import Interfaces.H4SoundParser;
import Interfaces.H4SpriteParser;
import Interfaces.H4StringsParser;
import Interfaces.H4TableParser;
import Interfaces.H4TransitionParser;
import Utility.Util;
import java.awt.Dimension;
......@@ -303,6 +306,14 @@ public class H4ResourceEditor extends AbstractApp
{
openTransition(f);
}
else if (name.contains(H4TableParser.TABLE_FILE_PREFIX))
{
openTable(f);
}
else if (name.contains(H4StringsParser.STRINGS_FILE_PREFIX))
{
openStrings(f);
}
}
}
......@@ -482,6 +493,30 @@ public class H4ResourceEditor extends AbstractApp
}
private static void openTable(File f)
{
ByteBuffer buffer = ByteBuffer.wrap(Util.getBytesFromFile(f));
buffer.order(ByteOrder.LITTLE_ENDIAN);
H4TableParser table = new H4TableParser(buffer, f.getName());
H4TablePanel p = new H4TablePanel();
p.setTable(table);
Dimension d = new Dimension(400, 300);
openResource(p, d, table.getFileName());
}
private static void openStrings(File f)
{
ByteBuffer buffer = ByteBuffer.wrap(Util.getBytesFromFile(f));
buffer.order(ByteOrder.LITTLE_ENDIAN);
H4StringsParser strings = new H4StringsParser(buffer, f.getName());
H4TablePanel p = new H4TablePanel();
p.setStrings(strings);
Dimension d = new Dimension(400, 300);
openResource(p, d, strings.getFileName());
}
private static void openResource(H4ResourcePanel p, Dimension d, String title)
{
H4ResourceFrame resFrame = new H4ResourceFrame(true, true);
......
......@@ -10,6 +10,7 @@ import Interfaces.H4ActorSequenceParser;
import Interfaces.H4AdventureActorParser;
import Interfaces.H4AdventureObjectParser;
import Interfaces.H4CombatActorParser;
import Interfaces.H4CombatObjectParser;
import Interfaces.H4ImageParser;
import Interfaces.H4ResourceFileParser;
import Interfaces.H4ResourceObjectInterface;
......@@ -39,6 +40,8 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
......@@ -181,6 +184,17 @@ public class H4ResourceEditorFrame extends JFrame
});
//mFileMenu.add(item);
item = new JMenuItem("Crawl Combat Objects");
item.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
handleTestForBrokenCombatObjects();
}
});
//mFileMenu.add(item);
item = new JMenuItem("Search for Town");
item.addActionListener(new ActionListener()
{
......@@ -482,7 +496,43 @@ public class H4ResourceEditorFrame extends JFrame
}
public Set<String> handleSearchObjects(String name)
private void handleTestForBrokenCombatObjects()
{
if (mH4rFile != null)
{
String broken = "";
String[] resourceList = mH4rFile.getFullResourceList();
for (String resourceName : resourceList)
{
if (resourceName.toLowerCase().startsWith(H4CombatObjectParser.COMBAT_OBJECT_FILE_PREFIX))
{
try
{
ByteBuffer buffer = ByteBuffer.wrap(mH4rFile.getResource(resourceName));
buffer.order(ByteOrder.LITTLE_ENDIAN);
H4CombatObjectParser combatObj = new H4CombatObjectParser(buffer, resourceName);
}
catch (Exception e)
{
broken += resourceName + Util.NEWLINE;
Util.logInfo(mClassName + "::handleTestForBrokenObjects", "Resource=%s, caught exception %s", resourceName, e);
}
}
}
try
{
PrintWriter out = new PrintWriter(mFilePath + Util.FILE_SEPARATOR + "broken-" + H4CombatObjectParser.COMBAT_OBJECT_FILE_PREFIX + ".txt");
out.print(broken);
out.close();
}
catch (IOException e)
{ }
}
}
private Set<String> handleSearchObjects(String name)
{
Set<String> foundList = new TreeSet<String>();
String[] resourceList = mH4rFile.getFullResourceList();
......@@ -668,7 +718,8 @@ public class H4ResourceEditorFrame extends JFrame
private void readActorSequences(File f, H4ResourceFileParser h4r)
{
Util.logInfo(mClassName + "::readActorSequences", "DERRICK: READING ACTOR SEQUENCES! %s", f.getName());
for (File actorSequence : f.listFiles())
List<File> actorList = Util.searchForFilePrefix(f.getAbsolutePath(), H4ActorSequenceParser.ACTOR_SEQUENCE_FILE_PREFIX);
for (File actorSequence : actorList)
{
Util.logInfo(mClassName + "::readActorSequences", "DERRICK: actorSequence=%s", actorSequence.getName());
if (actorSequence.getName().contains(H4ActorSequenceParser.ACTOR_SEQUENCE_FILE_PREFIX))
......@@ -750,6 +801,10 @@ public class H4ResourceEditorFrame extends JFrame
Util.saveBytesToFile(tmpSound, soundParser.getBytes());
h4r.addFile(tmpSound);
}
else if (sound.getName().startsWith(H4SoundParser.SOUND_OBJECT_FILE_PREFIX))
{
h4r.addFile(sound);
}
}
}
......
......@@ -12,12 +12,14 @@ import H4Widgets.H4BattlefieldPresetMapPanel;
import H4Widgets.H4BitmapRawPanel;
import H4Widgets.H4CastleObjectPanel;
import H4Widgets.H4CombatActorPanel;
import H4Widgets.H4CombatCastleLayoutPanel;
import H4Widgets.H4CombatObjectPanel;
import H4Widgets.H4LayerLayoutPanel;
import H4Widgets.H4LayerPanel;
import H4Widgets.H4ResourceFrame;
import H4Widgets.H4ResourcePanel;
import H4Widgets.H4SoundPanel;
import H4Widgets.H4TablePanel;
import H4Widgets.H4TransitionPanel;
import Interfaces.H4ActorSequenceParser;
import Interfaces.H4AdventureActorParser;
......@@ -31,6 +33,8 @@ import Interfaces.H4ResourceFileParser;
import Interfaces.H4ResourceTableEntry;
import Interfaces.H4SoundParser;
import Interfaces.H4SpriteParser;
import Interfaces.H4StringsParser;
import Interfaces.H4TableParser;
import Interfaces.H4TransitionParser;
import Utility.H4Util;
import Utility.MyThread;
......@@ -500,7 +504,32 @@ public class H4ResourceEditorPanel extends JPanel
ByteBuffer buffer = ByteBuffer.wrap(resource);
buffer.order(ByteOrder.LITTLE_ENDIAN);
H4CastleObjectParser castle = new H4CastleObjectParser(buffer, resourceName);
openCastleObject(castle);
String[] split = resourceName.split("\\.");
String faction = split[1];
List<H4CombatObjectParser> combatObjects = new ArrayList<H4CombatObjectParser>();
for (String rName : mResourceParser.getResourceList())
{
if (rName.startsWith(H4CombatObjectParser.COMBAT_OBJECT_FILE_PREFIX + ".castle." + faction))
{
byte[] r_bytes = mResourceParser.getResource(rName);
if (r_bytes != null)
{
ByteBuffer buff = ByteBuffer.wrap(r_bytes);
buff.order(ByteOrder.LITTLE_ENDIAN);
H4CombatObjectParser combatObj = new H4CombatObjectParser(buff, rName);
combatObjects.add(combatObj);
}
}
}
if (combatObjects.isEmpty())
{
openCastleObject(castle);
}
else
{
// TODO: Grab the castle files for citadel and fort
openCastleLayout(castle, combatObjects);
}
}
else if (resourceName.contains(H4TransitionParser.TRANSITION_FILE_PREFIX))
{
......@@ -509,6 +538,20 @@ public class H4ResourceEditorPanel extends JPanel
H4TransitionParser transition = new H4TransitionParser(buffer, resourceName);
openTransition(transition);
}
else if (resourceName.contains(H4TableParser.TABLE_FILE_PREFIX))
{
ByteBuffer buffer = ByteBuffer.wrap(resource);
buffer.order(ByteOrder.LITTLE_ENDIAN);
H4TableParser table = new H4TableParser(buffer, resourceName);
openTable(table);
}
else if (resourceName.contains(H4StringsParser.STRINGS_FILE_PREFIX))
{
ByteBuffer buffer = ByteBuffer.wrap(resource);
buffer.order(ByteOrder.LITTLE_ENDIAN);
H4StringsParser strings = new H4StringsParser(buffer, resourceName);
openStrings(strings);
}
}
else
{
......@@ -734,6 +777,16 @@ public class H4ResourceEditorPanel extends JPanel
}
public void openCastleLayout(H4CastleObjectParser castle, List<H4CombatObjectParser> combatObjects)
{
H4CombatCastleLayoutPanel p = new H4CombatCastleLayoutPanel();
p.setCastle(castle);
p.setCastleCombatObjects(combatObjects);
Dimension d = new Dimension(1000, 800);
openResourceFrame(p, d, castle.getFileName());
}
public void openTransition(H4TransitionParser transition)
{
H4TransitionPanel p = new H4TransitionPanel();
......@@ -743,6 +796,24 @@ public class H4ResourceEditorPanel extends JPanel
}
public void openTable(H4TableParser table)
{
H4TablePanel p = new H4TablePanel();
p.setTable(table);
Dimension d = new Dimension(400, 300);
openResourceFrame(p, d, table.getFileName());
}
public void openStrings(H4StringsParser strings)
{
H4TablePanel p = new H4TablePanel();
p.setStrings(strings);
Dimension d = new Dimension(400, 300);
openResourceFrame(p, d, strings.getFileName());
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Interfaces;
import Utility.Util;
import java.io.File;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Derrick
*/
public class H4StringsParser implements H4ResourceObjectInterface
{
public static final String STRINGS_FILE_PREFIX = "strings";
private final String mClassName = this.getClass().getName();
private String mFileName = null;
private H4TableParser mTable = null;
private int mNumRowIndices = 0;
private final List<Integer> mRowIndices = new ArrayList<Integer>();
public H4StringsParser(File f, String filename)
{
mFileName = filename;
ByteBuffer buffer = ByteBuffer.wrap(Util.getBytesFromFile(f));
buffer.order(ByteOrder.LITTLE_ENDIAN);
parseBuffer(buffer);
}
public H4StringsParser(ByteBuffer buffer, String filename)
{
mFileName = filename;
parseBuffer(buffer);
}
private void parseBuffer(ByteBuffer buffer)
{
mTable = new H4TableParser(buffer, mFileName);
mNumRowIndices = buffer.getInt();
for (int i = 0; i < mNumRowIndices; ++i)
{
mRowIndices.add(buffer.getInt());
}
}
public int getNumRowIndices()
{
return mNumRowIndices;
}
public List<Integer> getRowIndices()
{
return mRowIndices;
}
public void insertRowIndex(int row, int value)
{
mRowIndices.add(row, value);
++mNumRowIndices;
}
public void removeRowIndex(int row)
{
if (row > -1 && row < mRowIndices.size())
{
mRowIndices.remove(row);
--mNumRowIndices;
}
}
public H4TableParser getTable()
{
return mTable;
}
@Override
public String getFileName()
{
return mFileName;
}
@Override
public byte[] getBytes()
{
mNumRowIndices = mRowIndices.size();
int buffLen = Integer.BYTES * (mNumRowIndices + 1);
byte[] table_bytes = mTable.getBytes();
buffLen += table_bytes.length;
ByteBuffer buffer = ByteBuffer.allocate(buffLen);
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.put(table_bytes);
buffer.putInt(mNumRowIndices);
for (Integer index : mRowIndices)
{
buffer.putInt(index);
}
return buffer.array();
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Interfaces;
import Utility.Util;
import java.io.File;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Derrick
*/
public class H4TableParser implements H4ResourceObjectInterface
{
public static final String TABLE_FILE_PREFIX = "table";
private final String mClassName = this.getClass().getName();
private String mFileName = "";
private int mNumRows = 0;
private final List<H4TableRowParser> mTableRows = new ArrayList<H4TableRowParser>();
public H4TableParser(File f, String filename)
{
mFileName = filename;
ByteBuffer buffer = ByteBuffer.wrap(Util.getBytesFromFile(f));
buffer.order(ByteOrder.LITTLE_ENDIAN);
parseBuffer(buffer);
}
public H4TableParser(ByteBuffer buffer, String filename)
{
mFileName = filename;
parseBuffer(buffer);
}
private void parseBuffer(ByteBuffer buffer)
{
mNumRows = buffer.getInt();
for (int i = 0; i < mNumRows; ++i)
{
mTableRows.add(new H4TableRowParser(buffer));
}
}
public int getNumRows()
{
return mNumRows;
}
public List<H4TableRowParser> getRows()
{
return mTableRows;
}
public H4TableRowParser getRow(int index)
{
H4TableRowParser row = null;
if (index > -1 && index < mTableRows.size())
{
row = mTableRows.get(index);
}
return row;
}
public void addRow(ArrayList<String> row)
{
// TODO: May need to verify the list being passed in has the same number of strings as the other rows currently in the list. Insert empty Strings if not.
mTableRows.add(new H4TableRowParser(row));
}
public void insertRow(int index, ArrayList<String> row)
{
// TODO: May need to verify the list being passed in has the same number of strings as the other rows currently in the list. Insert empty Strings if not.
if (index > -1)
{
if (index < mTableRows.size())
{
mTableRows.add(new H4TableRowParser(row));
}
else
{
mTableRows.add(index, new H4TableRowParser(row));
}
}
}
public H4TableRowParser deleteRow(int index)
{
H4TableRowParser removed = null;
if (index > -1 && index < mTableRows.size())
{
removed = mTableRows.remove(index);
}
return removed;
}
public String getCsvString()
{
String csv = "";
for (H4TableRowParser row : mTableRows)
{
csv += "\"" + row.getStrings().get(0) + "\"";
for (int i = 1; i < row.getStrings().size(); ++i)
{
csv += "," + "\"" + row.getStrings().get(i) + "\"";
}
csv += Util.NEWLINE;
}
return csv;
}
@Override
public String getFileName()
{
return mFileName;
}
@Override
public byte[] getBytes()
{
mNumRows = mTableRows.size();
int buffLen = Integer.BYTES;
List<byte[]> row_bytes = new ArrayList<byte[]>();
for (H4TableRowParser row : mTableRows)
{
byte[] b = row.getBytes();
buffLen += b.length;
row_bytes.add(b);
}
ByteBuffer buffer = ByteBuffer.allocate(buffLen);
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.putInt(mNumRows);
for (byte[] b : row_bytes)
{
buffer.put(b);
}
return buffer.array();
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Interfaces;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Derrick
*/
public class H4TableRowParser
{
private final String mClassName = this.getClass().getName();
private short mNumStrings = 0;
private List<String> mStringList = new ArrayList<String>();
public H4TableRowParser(ArrayList<String> stringList)
{
mNumStrings = (short)stringList.size();
mStringList = (ArrayList<String>)stringList.clone();
}