/** * Loads the script data from the given XML file * * @param filename * Name of the XML file containing the script * @param validate * distinguish between if the load is made in editor or engine * @return The script stored as game data */ public static Chapter loadChapterData(InputStreamCreator isCreator, string fileName, List<Incidence> incidences) { // Create the chapter Chapter currentChapter = new Chapter(); bool chapterFound = false; if (Loader.adventureData != null) { foreach (Chapter chapter in adventureData.getChapters()) { if (chapter != null && chapter.getChapterPath() != null && chapter.getChapterPath().Equals(fileName)) { currentChapter = chapter; chapterFound = true; break; } else if (chapter != null && chapter.getChapterPath() == null) { currentChapter = chapter; chapterFound = true; currentChapter.setChapterPath("chapter1.xml"); break; } } } if (!chapterFound) { string chapterIS = null; //if (zipFile!=null){ chapterIS = isCreator.buildInputStream(fileName); currentChapter.setChapterPath(fileName); //} else{ // Then fileName is an absolutePath //string chapterPath = fileName.substring( Math.max (fileName.lastIndexOf( '\\' ), fileName.lastIndexOf( '/' ) ), fileName.length( )); //currentChapter.setName( chapterPath ); //try { // chapterIS = new FileInputStream( fileName ); //} catch (FileNotFoundException e) { //e.printStackTrace(); // incidences.add( Incidence.createChapterIncidence( TextConstants.getText( "Error.LoadData.IO" ), fileName ) ); //} //} // Open the file and load the data try { if (chapterIS != null) { // Set the chapter handler ChapterHandler chapterParser = new ChapterHandler(isCreator, currentChapter); //factory.setValidating(false); //SAXParser saxParser = factory.newSAXParser(); //// Parse the data and close the data //saxParser.parse(chapterIS, chapterParser); //chapterIS.close(); chapterParser.Parse(chapterIS); } } catch (Exception e) { Debug.LogError(e); } //catch (ParserConfigurationException e) //{ // incidences.add(Incidence.createChapterIncidence(Language.GetText("Error.LoadData.SAX"), fileName, e)); //} //catch (SAXException e) //{ // incidences.add(Incidence.createChapterIncidence(Language.GetText("Error.LoadData.SAX"), fileName, e)); //} //catch (IOException e) //{ // incidences.add(Incidence.createChapterIncidence(Language.GetText("Error.LoadData.IO"), fileName, e)); //} } //Debug.Log(currentChapter); return currentChapter; }
/** * Loads the script data from the given XML file * * @param filename * Name of the XML file containing the script * @param validate * distinguish between if the load is made in editor or engine * @return The script stored as game data */ public static Chapter loadChapterData(InputStreamCreator isCreator, string fileName, List <Incidence> incidences) { // Create the chapter Chapter currentChapter = new Chapter(); bool chapterFound = false; if (Loader.adventureData != null) { foreach (Chapter chapter in adventureData.getChapters()) { if (chapter != null && chapter.getChapterPath() != null && chapter.getChapterPath().Equals(fileName)) { currentChapter = chapter; chapterFound = true; break; } else if (chapter != null && chapter.getChapterPath() == null) { currentChapter = chapter; chapterFound = true; currentChapter.setChapterPath("chapter1.xml"); break; } } } if (!chapterFound) { string chapterIS = null; //if (zipFile!=null){ chapterIS = isCreator.buildInputStream(fileName); currentChapter.setChapterPath(fileName); //} else{ // Then fileName is an absolutePath //string chapterPath = fileName.substring( Math.max (fileName.lastIndexOf( '\\' ), fileName.lastIndexOf( '/' ) ), fileName.length( )); //currentChapter.setName( chapterPath ); //try { // chapterIS = new FileInputStream( fileName ); //} catch (FileNotFoundException e) { //e.printStackTrace(); // incidences.add( Incidence.createChapterIncidence( TextConstants.getText( "Error.LoadData.IO" ), fileName ) ); //} //} // Open the file and load the data try { if (chapterIS != null) { // Set the chapter handler ChapterHandler chapterParser = new ChapterHandler(isCreator, currentChapter); //factory.setValidating(false); //SAXParser saxParser = factory.newSAXParser(); //// Parse the data and close the data //saxParser.parse(chapterIS, chapterParser); //chapterIS.close(); chapterParser.Parse(chapterIS); } } catch (Exception e) { Debug.LogError(e); } //catch (ParserConfigurationException e) //{ // incidences.add(Incidence.createChapterIncidence(Language.GetText("Error.LoadData.SAX"), fileName, e)); //} //catch (SAXException e) //{ // incidences.add(Incidence.createChapterIncidence(Language.GetText("Error.LoadData.SAX"), fileName, e)); //} //catch (IOException e) //{ // incidences.add(Incidence.createChapterIncidence(Language.GetText("Error.LoadData.IO"), fileName, e)); //} } //Debug.Log(currentChapter); return(currentChapter); }