Exemplo n.º 1
0
 /**
  * Writes the given CLUE game data to an XML string.
  *
  * @param gameData CLUE game data to convert to XML
  * @return the XML representation of the given CLUE game data
  */
 public static String writeToString(ClueGameData gameData) {
   try {
     XMLTag rootTag = convertToXML(gameData);
     return XMLWriter.writeXMLToString(rootTag);
   } catch (XMLException ex) {
     Messenger.error(ex, "Unable to parse generated XML to string.", "Game XML Conversion Error");
     return null;
   }
 }
Exemplo n.º 2
0
 /**
  * Parses XML from the given text and generates CLUE game data.
  *
  * @param ccgXML XML text to parse
  * @return the generated CLUE game data
  */
 public static ClueGameData readFromString(String ccgXML) {
   try {
     XMLTag rootTag = XMLReader.parseXML(ccgXML);
     return readFromXMLRootTag(rootTag);
   } catch (XMLException ex) {
     Messenger.error(ex, "Invalid XML: " + ccgXML, "CCG String Read Error");
     return null;
   }
 }
Exemplo n.º 3
0
  /**
   * Parses XML from a given file and generates CLUE game data.
   *
   * @param gameFile XML file to parse
   * @return the generated CLUE game data
   */
  public static ClueGameData readFromFile(File gameFile) {
    if (gameFile == null) return null;

    try {
      XMLTag rootTag = XMLReader.parseXMLFile(gameFile);
      return readFromXMLRootTag(rootTag);
    } catch (XMLException ex) {
      Messenger.error(
          ex, "Corrupted or invalid XML Custom Clue Game file: " + gameFile, "CCG File Read Error");
      return null;
    }
  }
Exemplo n.º 4
0
  /**
   * Writes the CLUE game data as XML to a file.
   *
   * @param defaultGameFile default file to offer as file choice for saving.
   * @param gameData CLUE game data to save
   * @return the chosen file were the game was saved or null if canceled or unable to save
   */
  public static File writeToFile(File defaultGameFile, ClueGameData gameData) {
    JFileChooser chooser = new JFileChooser("ccgs/");
    FileNameExtensionFilter filter = new FileNameExtensionFilter("Custom Clue Game (*.ccg)", "ccg");
    chooser.setFileFilter(filter);
    chooser.setSelectedFile(defaultGameFile);
    int returnVal = chooser.showSaveDialog(null);
    if (returnVal != JFileChooser.APPROVE_OPTION) return null;
    File selectedFile = chooser.getSelectedFile();
    if (!selectedFile.getName().endsWith(".ccg"))
      selectedFile = new File(selectedFile.getAbsolutePath() + ".ccg");

    XMLTag rootTag = convertToXML(gameData);

    try {
      XMLWriter.writeXMLToFile(rootTag, selectedFile);
      return selectedFile;
    } catch (XMLException ex) {
      Messenger.error(
          ex,
          "Unable to write to save file: " + selectedFile.getAbsolutePath(),
          "Game Creation Save Error");
      return null;
    }
  }