Camtech075

FEditor Script Converter - Source

Sep 19th, 2011
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.50 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileNotFoundException;
  3. import java.io.PrintStream;
  4. import java.io.FileInputStream;
  5. import java.io.IOException;
  6. import javax.swing.JFrame;
  7. import javax.swing.JLabel;
  8. import java.awt.Container;
  9. import javax.swing.JTextField;
  10. import javax.swing.JButton;
  11. import java.awt.FlowLayout;
  12. import java.awt.event.ActionListener;
  13. import java.awt.event.ActionEvent;
  14. import javax.swing.JCheckBox;
  15. import javax.swing.AbstractButton;
  16.  
  17. public class FEditor_Script_Reader {
  18.  
  19. public static void main(String[] args) {
  20.  
  21. JFrame frame;
  22. JTextField textfield;
  23. Container contentPane;
  24. String go;
  25. JLabel whatmode;
  26. JButton button;
  27. FlowLayout layout;
  28. String fileName;
  29. JCheckBox regAttack, crit, ranged, rngcrit, dodge, stand;
  30.  
  31. frame = new JFrame();
  32. frame.setTitle("Script Converter");
  33.  
  34. contentPane = frame.getContentPane();
  35. textfield = new JTextField("dumped.dmp", 15);
  36. whatmode = new JLabel("Check the modes you wish to convert (see readme)");
  37.  
  38. go = "Create Script!";
  39.  
  40. regAttack = new JCheckBox("1/2/12", true);
  41. regAttack.addActionListener(new MyActionListener(regAttack));
  42. crit = new JCheckBox("3/4", true);
  43. crit.addActionListener(new MyActionListener(crit));
  44. ranged = new JCheckBox("5", true);
  45. ranged.addActionListener(new MyActionListener(ranged));
  46. rngcrit = new JCheckBox("6", true);
  47. rngcrit.addActionListener(new MyActionListener(rngcrit));
  48. dodge = new JCheckBox("7/8/9", true);
  49. dodge.addActionListener(new MyActionListener(dodge));
  50. stand = new JCheckBox("10/11", true);
  51. stand.addActionListener(new MyActionListener(stand));
  52.  
  53. button = new JButton(go);
  54. button.addActionListener(new MyActionListener(textfield));
  55.  
  56. contentPane.add(textfield);
  57. contentPane.add(whatmode);
  58. contentPane.add(regAttack);
  59. contentPane.add(crit);
  60. contentPane.add(ranged);
  61. contentPane.add(rngcrit);
  62. contentPane.add(dodge);
  63. contentPane.add(stand);
  64. contentPane.add(button);
  65. layout = new FlowLayout();
  66. contentPane.setLayout(layout);
  67.  
  68. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  69. frame.pack();
  70. frame.setSize(800,110);
  71. frame.setVisible(true);
  72.  
  73. //Scanner dmpReader = new Scanner(new File("literal.txt"));
  74.  
  75. }
  76.  
  77. }
  78.  
  79. class MyActionListener implements ActionListener {
  80.  
  81. public static JLabel label;
  82. public static JTextField textfield;
  83. public static JCheckBox cbox;
  84. public static String errorMessage, finished;
  85. static JFrame finalframe;
  86. static Container contentPane;
  87.  
  88. public static final int FRAME_COMMAND = 0x86;
  89. public static final int TERMINATOR = 0x80;
  90. public static final int CALL_COMMAND = 0x85;
  91.  
  92. static boolean attackIsChecked = true;
  93. static boolean critIsChecked = true;
  94. static boolean rangeIsChecked = true;
  95. static boolean rngcritIsChecked = true;
  96. static boolean dodgeIsChecked = true;
  97. static boolean standIsChecked = true;
  98.  
  99. public static String toHex(long a) {
  100.  
  101. //Laziness, it's easier to write
  102. //toHex(asdf) than "asdf.whatever"
  103.  
  104. String result = Long.toString(a, 16);
  105.  
  106. return result.toUpperCase();
  107.  
  108. }
  109.  
  110. MyActionListener(JTextField textfield) {
  111.  
  112. this.textfield = textfield;
  113.  
  114. }
  115.  
  116. MyActionListener(JCheckBox cbox) {
  117.  
  118. this.cbox = cbox;
  119.  
  120. }
  121.  
  122. public void actionPerformed(ActionEvent e) {
  123.  
  124. String go = "Create Script!";
  125. String attackString = "1/2/12";
  126. String critString = "3/4";
  127. String rangeString = "5";
  128. String rngcritString = "6";
  129. String dodgeString = "7/8/9";
  130. String standString = "10/11";
  131.  
  132. //The following bit (everything up to go) is really ugly, and I have no idea
  133. //how to make it better (I dunno how to make a switch work with booleans).
  134.  
  135. boolean attackIsChanged = e.getActionCommand().equals(attackString);
  136. boolean critIsChanged = e.getActionCommand().equals(critString);
  137. boolean rangeIsChanged = e.getActionCommand().equals(rangeString);
  138. boolean rngcritIsChanged = e.getActionCommand().equals(rngcritString);
  139. boolean dodgeIsChanged = e.getActionCommand().equals(dodgeString);
  140. boolean standIsChanged = e.getActionCommand().equals(standString);
  141.  
  142. if(attackIsChanged)
  143. {
  144. attackIsChecked = !attackIsChecked;
  145. }
  146.  
  147. if(critIsChanged)
  148. {
  149. critIsChecked = !critIsChecked;
  150. }
  151.  
  152. if(rangeIsChanged)
  153. {
  154. rangeIsChecked = !rangeIsChecked;
  155. }
  156.  
  157. if(rngcritIsChanged)
  158. {
  159. rngcritIsChecked = !rngcritIsChecked;
  160. }
  161.  
  162. if(dodgeIsChanged)
  163. {
  164. dodgeIsChecked = !dodgeIsChecked;
  165. }
  166.  
  167. if(standIsChanged)
  168. {
  169. standIsChecked = !standIsChecked;
  170. }
  171.  
  172. if(e.getActionCommand().equals(go))
  173. {
  174.  
  175. finished = "Finished.";
  176. errorMessage = "Error with your file.";
  177. String fileName = textfield.getText();
  178. System.out.println(attackIsChecked);
  179.  
  180. try
  181. {
  182.  
  183. FileInputStream dmpReader = new FileInputStream(new File(fileName));
  184. PrintStream txtWriter = new PrintStream("dumpscript.txt");
  185.  
  186. int countvar = 0;
  187. int modenum = 1;
  188. int framenum = 1;
  189.  
  190. //FileNotFoundException("Error: File not Found");
  191.  
  192. txtWriter.println("//begin Mode 1");
  193.  
  194. while (dmpReader.available()!=0)
  195. {
  196. long byte1 = dmpReader.read();
  197. long byte2 = dmpReader.read();
  198. long byte3 = dmpReader.read();
  199. long cmdbyte = dmpReader.read();
  200.  
  201. long threebytes = byte1 + byte2 + byte3;
  202.  
  203. //if (cmdbyte == 0x80 && threebytes == 0x00)
  204. switch ((int)cmdbyte)
  205. {
  206. case TERMINATOR:
  207. txtWriter.println("~~~");
  208. modenum++;
  209.  
  210. if (modenum < 13)
  211. {
  212. txtWriter.println("//begin Mode " + modenum);
  213. }
  214. else
  215. {
  216. txtWriter.print("//End of animation script");
  217. }
  218. break;
  219.  
  220. //framenum = 1;
  221. case CALL_COMMAND:
  222. //int cbyte = cmdbyte.parseInt(16);
  223. if (byte1 < 0x10)
  224. {
  225. txtWriter.print("C0");
  226. txtWriter.println(toHex(byte1));
  227. }
  228. else
  229. {
  230. txtWriter.print("C");
  231. txtWriter.println(toHex(byte1));
  232. }
  233. break;
  234.  
  235. case FRAME_COMMAND:
  236.  
  237. switch(modenum)
  238. {
  239.  
  240. case 1:
  241. case 2:
  242. case 12:
  243. if (attackIsChecked)
  244. {
  245. txtWriter.print(byte1 + " p- ");
  246. txtWriter.println("att-" + byte3 + ".png");
  247. ++framenum;
  248. }
  249. break;
  250. case 3:
  251. case 4:
  252. if (critIsChecked)
  253. {
  254. txtWriter.print(byte1 + " p- ");
  255. txtWriter.println("crt-" + byte3 + ".png");
  256. ++framenum;
  257. }
  258. break;
  259. case 5:
  260. if (rangeIsChecked)
  261. {
  262. txtWriter.print(byte1 + " p- ");
  263. txtWriter.println("rng-" + byte3 + ".png");
  264. ++framenum;
  265. }
  266. break;
  267. case 6:
  268. if (rngcritIsChecked)
  269. {
  270. txtWriter.print(byte1 + " p- ");
  271. txtWriter.println("rngcrit-" + byte3 + ".png");
  272. ++framenum;
  273. }
  274. break;
  275. case 7:
  276. case 8:
  277. if (dodgeIsChecked)
  278. {
  279. txtWriter.print(byte1 + " p- ");
  280. txtWriter.println("dodge-" + byte3 + ".png");
  281. ++framenum;
  282. }
  283. break;
  284. case 9:
  285. case 10:
  286. case 11:
  287. if (standIsChecked)
  288. {
  289. txtWriter.print(byte1 + " p- ");
  290. txtWriter.println("stand-" + byte3 + ".png");
  291. ++framenum;
  292. }
  293. break;
  294.  
  295. }
  296. break;
  297.  
  298. case 0x00:
  299. break;
  300.  
  301. default:
  302. txtWriter.println(byte1 + " " + byte2 + " " + " " + byte3 + " " + cmdbyte);
  303. System.out.println("//Found unknown command: " + cmdbyte);
  304. break;
  305.  
  306. }
  307. }
  308.  
  309. finalframe = new JFrame();
  310.  
  311. label = new JLabel(finished);
  312. contentPane = finalframe.getContentPane();
  313. contentPane.add(label);
  314.  
  315. finalframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  316. finalframe.pack();
  317. finalframe.setVisible(true);
  318.  
  319. }
  320. catch (IOException exception)
  321. {
  322. finalframe = new JFrame();
  323.  
  324. label = new JLabel(errorMessage);
  325.  
  326. contentPane = finalframe.getContentPane();
  327. contentPane.add(label);
  328.  
  329. finalframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  330. finalframe.pack();
  331. finalframe.setVisible(true);
  332. }
  333. }
  334. }
  335.  
  336. }
Advertisement
Add Comment
Please, Sign In to add comment