📄 mapxmlparser.java
字号:
package xmlRead;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.io.FileOutputStream;
import org.xmlpull.v1.XmlPullParser;
//import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
public class MAPXMLParser extends WindowAdapter implements ActionListener{
String xmlURL = null;
Frame fram;
Panel pane1;
Panel pane2;
TextField txf1;
Button but;
public MAPXMLParser(){
fram= new Frame("动作编辑器XML解析");
pane1 = new Panel();
pane2 = new Panel();
fram.setBackground(new Color(0x999999));
pane1.setBackground(new Color(0x999999));
pane2.setBackground(new Color(0x999999));
fram.setLayout(new FlowLayout());
fram.add(pane1);
fram.add(pane2);
pane1.setLayout(new GridLayout(5,2));
txf1 = new TextField(10);
but = new Button("GO");
pane1.add(new Label("文件名: "));
pane1.add(txf1);
pane2.add(but);
but.addActionListener(this);
fram.setSize(180,120);
fram.setVisible(true);
fram.addWindowListener(this);
}
public static void main(String[] args)
{
//MAPXMLParser mxp =
new MAPXMLParser();
}
public void windowClosing(WindowEvent e){
fram.dispose();
}
public void actionPerformed(ActionEvent e1){
//得到文件名
xmlURL = txf1.getText();
String x=null,y=null,w= null,h= null;
String index = null,xlink = null,ylink = null;
String imageData = null;
byte peopleNum = 0;
byte kickNum = 0;
int tempKickData[][][] = new int[10][60][4];
byte everyPeopleKickNum[] = new byte[10];
byte actionNum = 0;
byte frameNum = 0;
byte piceNum = 0;
int tempActionFrameData[][][][][] = new int[10][20][60][100][3];
byte everyPeopleActionNum[] = new byte[10];
byte everyPeopleActionFrameNum[][] = new byte[10][20];
byte everyPeopleActionFramepiceNum[][][] = new byte[10][20][60];
boolean inPart = false;
int actionnum = 0;
int flage = -1;//0:x,1:y,2:w,3:h
try
{
BufferedReader reader = new BufferedReader(new FileReader(xmlURL+".xml"));
PrintStream ps = new PrintStream(new FileOutputStream(xmlURL+".txt"));
DataOutputStream out = new DataOutputStream(new FileOutputStream(xmlURL+".pro"));
if( reader != null )
{
XmlPullParserFactory factory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();
xpp.setInput (reader);
int eventType = xpp.getEventType();
//boolean in = false;
do
{
if(eventType == XmlPullParser.START_TAG)
{
if(xpp.getName().equals("Parts") )
{
ps.println("{//碎片矩阵");
}/*else if(xpp.getName().equals("FaceData") )
{
inPart = true;
flage = 7;
}*/
else if(xpp.getName().equals("PartX") )
{
inPart = true;
flage = 0;
}
else if(xpp.getName().equals("PartY") )
{
inPart = true;
flage = 1;
}
else if(xpp.getName().equals("PartW") )
{
inPart = true;
flage = 2;
}
else if(xpp.getName().equals("PartH") )
{
inPart = true;
flage = 3;
}
else if(xpp.getName().equals("Action"))
{
ps.println("{//动作"+actionnum);
actionnum ++;
}
else if(xpp.getName().equals("Frame"))
{
ps.print(" {");
// ps.print(" ");
}
else if(xpp.getName().equals("Index"))
{
inPart = true;
flage = 4;
}
else if(xpp.getName().equals("LinkX"))
{
inPart = true;
flage = 5;
}
else if(xpp.getName().equals("LinkY"))
{
inPart = true;
flage = 6;
}
else
inPart = false;
}
if(eventType == XmlPullParser.TEXT && inPart)
{
switch(flage )
{
case 0:
x = xpp.getText();
break;
case 1:
y = xpp.getText();
break;
case 2:
w = xpp.getText();
break;
case 3:
h = xpp.getText();
break;
case 4:
index = xpp.getText();
break;
case 5:
xlink = xpp.getText();
break;
case 6:
ylink = xpp.getText();
break;
/*case 7:
imageData = xpp.getText();
break;*/
}
inPart = false;
// System.out.println(xpp.getText());
}
if(eventType == XmlPullParser.END_TAG)
{
if( xpp.getName().equals("Part") )
{
tempKickData[peopleNum][kickNum][0] = Integer.parseInt(x);
tempKickData[peopleNum][kickNum][1] = Integer.parseInt(y);
tempKickData[peopleNum][kickNum][2] = Integer.parseInt(w);
tempKickData[peopleNum][kickNum][3] = Integer.parseInt(h);
kickNum ++;
inPart = false;
flage = -1;
ps.println(" {"+x+","+y+","+w+","+h+"},");
//System.out.println("stop" +xpp.getName());
}
if( xpp.getName().equals("Parts") )
{
everyPeopleKickNum[peopleNum] = kickNum;
peopleNum ++;
kickNum = 0;
ps.println("},");
//System.out.println("stop" +xpp.getName());
}
/*if( xpp.getName().equals("FaceData") )
{
inPart = false;
flage = -1;
ps.println(" {"+imageData+"},");
//System.out.println("stop" +xpp.getName());
}*/
if( xpp.getName().equals("FramePart") )
{
tempActionFrameData[peopleNum-1][actionNum][frameNum][piceNum][0] = Integer.parseInt(index);
tempActionFrameData[peopleNum-1][actionNum][frameNum][piceNum][1] = Integer.parseInt(xlink);
tempActionFrameData[peopleNum-1][actionNum][frameNum][piceNum][2] = Integer.parseInt(ylink);
//System.out.println("index "+tempActionFrameData[peopleNum-1][actionNum][frameNum][piceNum][0]);
//System.out.println("index "+tempActionFrameData[peopleNum-1][actionNum][frameNum][piceNum][1]);
//System.out.println("index "+tempActionFrameData[peopleNum-1][actionNum][frameNum][piceNum][2]);
piceNum ++;
inPart = false;
flage = -1;
ps.print("{"+index+","+xlink+","+ylink+"},");
//System.out.println("stop" +xpp.getName());
}
if( xpp.getName().equals("Frame") )
{
everyPeopleActionFramepiceNum[peopleNum-1][actionNum][frameNum] = piceNum;
frameNum++;
piceNum = 0;
ps.println(" },");
//System.out.println("stop" +xpp.getName());
}
if( xpp.getName().equals("Action") )
{
everyPeopleActionFrameNum[peopleNum-1][actionNum] = frameNum;
actionNum ++;
frameNum = 0;
ps.println("},");
//System.out.println("stop" +xpp.getName());
}
if( xpp.getName().equals("Player") )
{
everyPeopleActionNum[peopleNum-1] = actionNum;
actionNum = 0;
}
}
eventType = xpp.next();
}while (eventType != XmlPullParser.END_DOCUMENT);
}
ps.close();
reader.close();
//build pro file
out.writeByte(peopleNum);
for(int a=0;a<peopleNum;a++){
out.writeByte(everyPeopleKickNum[a]);
for(int b=0;b<everyPeopleKickNum[a];b++){
for(int c=0;c<4;c++){
out.writeShort((short)tempKickData[a][b][c]);
}
}
out.writeByte(everyPeopleActionNum[a]);
for(int b=0;b<everyPeopleActionNum[a];b++){
out.writeByte(everyPeopleActionFrameNum[a][b]);
for(int c=0;c<everyPeopleActionFrameNum[a][b];c++){
out.writeByte(everyPeopleActionFramepiceNum[a][b][c]);
for(int d=0;d<everyPeopleActionFramepiceNum[a][b][c];d++){
for(int e=0;e<3;e++){
out.writeShort((short)tempActionFrameData[a][b][c][d][e]);
}
}
}
}
}
out.close();
out = null;
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -