/** * Loads the descriptor of the current ZIP adventure loaded * * @return The descriptor data of the game */ public static DescriptorData loadDescriptorData(InputStreamCreator isCreator, List <Incidence> incidences) { DescriptorData descriptorData = null; if (Loader.adventureData != null) { descriptorData = Loader.adventureData; } else { try { // Set the adventure handler DescriptorHandler descriptorParser = new DescriptorHandler(isCreator); //factory.setValidating(false); //SAXParser saxParser = factory.newSAXParser(); // Read and close the inputstrea string descriptorIS = isCreator.buildInputStream("descriptor.xml"); //saxParser.parse(descriptorIS, descriptorParser); //descriptorIS.close(); descriptorParser.Parse(descriptorIS); // Store the adventure data descriptorData = descriptorParser.getGameDescriptor(); } catch (Exception e) { Debug.LogError(e); } //catch (ParserConfigurationException e) //{ // incidences.add(Incidence.createDescriptorIncidence(Language.GetText("Error.LoadDescriptor.SAX"), e)); //} //catch (SAXException e) //{ // incidences.add(Incidence.createDescriptorIncidence(Language.GetText("Error.LoadDescriptor.SAX"), e)); //} //catch (IOException e) //{ // incidences.add(Incidence.createDescriptorIncidence(Language.GetText("Error.LoadDescriptor.IO"), e)); //} //catch (IllegalArgumentException e) //{ // incidences.add(Incidence.createDescriptorIncidence(Language.GetText("Error.LoadDescriptor.NoDescriptor"), e)); //} } return(descriptorData); }
/** * Loads the adventure data from the given ZIP file. * * @param zipFile * Path to the zip file which holds the adventure * @return The adventure data, null if there was an error */ public static AdventureData loadAdventureData(InputStreamCreator isCreator, List <Incidence> incidences) { AdventureData adventureDataTemp = null; try { // Set the adventure handler AdventureHandler adventureParser = new AdventureHandler(isCreator, incidences); //factory.setValidating(false); //SAXParser saxParser = factory.newSAXParser(); // Read and close the input stream string descriptorIS = isCreator.buildInputStream("descriptor.xml"); adventureParser.Parse(descriptorIS); //descriptorIS.close(); // Load the assessment and adaptation profiles. It must be after parse // the adventure data because the profile's load from xml inserts each profile // in each chapter. adventureParser.loadProfiles(); // Store the adventure data adventureDataTemp = adventureParser.getAdventureData(); } catch (Exception e) { Debug.LogError(e); } //catch (ParserConfigurationException e) //{ // incidences.add(Incidence.createDescriptorIncidence(Language.GetText("Error.LoadDescriptor.SAX"), e)); //} //catch (SAXException e) //{ // incidences.add(Incidence.createDescriptorIncidence(Language.GetText("Error.LoadDescriptor.SAX"), e)); //} //catch (IOException e) //{ // incidences.add(Incidence.createDescriptorIncidence(Language.GetText("Error.LoadDescriptor.IO"), e)); //} //catch (IllegalArgumentException e) //{ // incidences.add(Incidence.createDescriptorIncidence(Language.GetText("Error.LoadDescriptor.NoDescriptor"), e)); //} return(adventureDataTemp); }
/** * Loads an animation from a filename * * @param filename * The xml descriptor for the animation * @return the loaded Animation */ public static Animation loadAnimation(InputStreamCreator isCreator, string filename, ImageLoaderFactory imageloader) { AnimationHandler_ animationHandler = new AnimationHandler_(isCreator, imageloader); // Create a new factory //factory.setValidating(false); //SAXParser saxParser; try { //saxParser = factory.newSAXParser(); // Read and close the input stream //File file = new File(filename); string descriptorIS = null; /*try { * System.out.println("FILENAME="+filename); * descriptorIS = ResourceHandler.getInstance( ).buildInputStream(filename); * System.out.println("descriptorIS==null?"+(descriptorIS==null)); * * //descriptorIS = new InputStream(ResourceHandler.getInstance().getResourceAsURLFromZip(filename)); * } catch (Exception e) { Debug.LogError(e); } { * e.printStackTrace(); * } * if (descriptorIS == null) { * descriptorIS = AssetsController.getInputStream(filename); * }*/ descriptorIS = isCreator.buildInputStream("Assets/Resources/CurrentGame/" + filename); if (!descriptorIS.EndsWith(".eaa")) { descriptorIS += ".eaa"; } animationHandler.Parse(descriptorIS); //saxParser.parse(descriptorIS, animationHandler); //descriptorIS.close(); } catch (Exception e) { Debug.LogError(e); } //catch (ParserConfigurationException e) //{ // e.printStackTrace(); // System.err.println(filename); //} //catch (SAXException e) //{ // e.printStackTrace(); // System.err.println(filename); //} //catch (FileNotFoundException e) //{ // e.printStackTrace(); // System.err.println(filename); //} //catch (IOException e) //{ // e.printStackTrace(); // System.err.println(filename); //} if (animationHandler.getAnimation() != null) { return(animationHandler.getAnimation()); } else { return(new Animation("anim" + (new System.Random()).Next(1000), imageloader)); } }
public override void startElement(string namespaceURI, string sName, string qName, Dictionary <string, string> attrs) { if (qName.Equals("game-descriptor")) { foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("versionNumber")) { adventureData.setVersionNumber(entry.Value.ToString()); } } } if (qName.Equals("configuration")) { foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("keepShowing")) { adventureData.setKeepShowing(entry.Value.ToString().Equals("yes")); } if (entry.Key.Equals("keyboard-navigation")) { adventureData.setKeyboardNavigation(entry.Value.ToString().Equals("enabled")); } if (entry.Key.Equals("defaultClickAction")) { if (entry.Value.ToString().Equals("showDetails")) { adventureData.setDeafultClickAction(DescriptorData.DefaultClickAction.SHOW_DETAILS); } if (entry.Value.ToString().Equals("showActions")) { adventureData.setDeafultClickAction(DescriptorData.DefaultClickAction.SHOW_ACTIONS); } } if (entry.Key.Equals("perspective")) { if (entry.Value.ToString().Equals("regular")) { adventureData.setPerspective(DescriptorData.Perspective.REGULAR); } if (entry.Value.ToString().Equals("isometric")) { adventureData.setPerspective(DescriptorData.Perspective.ISOMETRIC); } } if (entry.Key.Equals("dragBehaviour")) { if (entry.Value.ToString().Equals("considerNonTargets")) { adventureData.setDragBehaviour(DescriptorData.DragBehaviour.CONSIDER_NON_TARGETS); } if (entry.Value.ToString().Equals("ignoreNonTargets")) { adventureData.setDragBehaviour(DescriptorData.DragBehaviour.IGNORE_NON_TARGETS); } } } } // If reading a title, empty the current string if (qName.Equals("title") || qName.Equals("description")) { currentstring = string.Empty; } if (qName.EndsWith("automatic-commentaries")) { adventureData.setCommentaries(true); } // If reading the GUI tag, store the settings if (qName.Equals("gui")) { foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("type")) { if (entry.Value.ToString().Equals("traditional")) { adventureData.setGUIType(DescriptorData.GUI_TRADITIONAL); } else if (attrs["type"].Equals("contextual")) { adventureData.setGUIType(DescriptorData.GUI_CONTEXTUAL); } } if (entry.Key.Equals("customized")) { if (entry.Value.ToString().Equals("yes")) { adventureData.setGUI(adventureData.getGUIType(), true); } else { adventureData.setGUI(adventureData.getGUIType(), false); } } if (entry.Key.Equals("inventoryPosition")) { if (entry.Value.ToString().Equals("none")) { adventureData.setInventoryPosition(DescriptorData.INVENTORY_NONE); } else if (entry.Value.ToString().Equals("top_bottom")) { adventureData.setInventoryPosition(DescriptorData.INVENTORY_TOP_BOTTOM); } else if (entry.Value.ToString().Equals("top")) { adventureData.setInventoryPosition(DescriptorData.INVENTORY_TOP); } else if (entry.Value.ToString().Equals("bottom")) { adventureData.setInventoryPosition(DescriptorData.INVENTORY_BOTTOM); } else if (entry.Value.ToString().Equals("fixed_top")) { adventureData.setInventoryPosition(DescriptorData.INVENTORY_FIXED_TOP); } else if (entry.Value.ToString().Equals("fixed_bottom")) { adventureData.setInventoryPosition(DescriptorData.INVENTORY_FIXED_BOTTOM); } } } } //Cursor if (qName.Equals("cursor")) { string type = ""; string uri = ""; foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("type")) { type = entry.Value.ToString(); } else if (entry.Key.Equals("uri")) { uri = entry.Value.ToString(); } } adventureData.addCursor(type, uri); } //Button if (qName.Equals("button")) { string type = ""; string uri = ""; string action = ""; foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("type")) { type = entry.Value.ToString(); } else if (entry.Key.Equals("uri")) { uri = entry.Value.ToString(); } else if (entry.Key.Equals("action")) { action = entry.Value.ToString(); } } adventureData.addButton(action, type, uri); } if (qName.Equals("arrow")) { string type = ""; string uri = ""; foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("type")) { type = entry.Value.ToString(); } else if (entry.Key.Equals("uri")) { uri = entry.Value.ToString(); } } adventureData.addArrow(type, uri); } // If reading the mode tag: if (qName.Equals("mode")) { foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("playerTransparent")) { if (entry.Value.ToString().Equals("yes")) { adventureData.setPlayerMode(DescriptorData.MODE_PLAYER_1STPERSON); } else if (entry.Value.ToString().Equals("no")) { adventureData.setPlayerMode(DescriptorData.MODE_PLAYER_3RDPERSON); } } } } if (qName.Equals("graphics")) { foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("mode")) { if (entry.Value.ToString().Equals("windowed")) { adventureData.setGraphicConfig(DescriptorData.GRAPHICS_WINDOWED); } else if (entry.Value.ToString().Equals("fullscreen")) { adventureData.setGraphicConfig(DescriptorData.GRAPHICS_FULLSCREEN); } else if (entry.Value.ToString().Equals("blackbkg")) { adventureData.setGraphicConfig(DescriptorData.GRAPHICS_BLACKBKG); } } } } // If reading the contents tag, switch to the chapters mode else if (qName.Equals("contents")) { reading = READING_CHAPTER; } // If reading the contents of a chapter, create a new one to store the data else if (qName.Equals("chapter")) { // Create the chapter currentChapter = new Chapter(); // Search and store the path of the file string chapterPath = null; foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("path")) { chapterPath = entry.Value.ToString(); } } if (chapterPath != null) { currentChapter.setChapterPath(chapterPath); } else { currentChapter.setChapterPath(""); } // Open the file and load the data try { // Set the chapter handler // ChapterHandler chapterParser = new ChapterHandler(isCreator, currentChapter); ChapterHandler_ chapterParser = new ChapterHandler_(currentChapter); Debug.Log(currentChapter.getBooks().Count); //// Create a new factory //SAXParserFactory factory = SAXParserFactory.newInstance(); ////factory.setValidating( validate ); //factory.setValidating(false); //SAXParser saxParser = factory.newSAXParser(); //// Set the input stream with the file //InputStream chapterIS = isCreator.buildInputStream(chapterPath); //// Parse the data and close the data //saxParser.parse(chapterIS, chapterParser); //chapterIS.close(); string chapterIS = isCreator.buildInputStream(chapterPath); chapterParser.Parse(chapterIS); } catch (Exception e) { Debug.LogError(e); } //catch (ParserConfigurationException e) //{ // incidences.add(Incidence.createChapterIncidence(Language.GetText("Error.LoadData.SAX"), chapterPath, e)); //} //catch (SAXException e) //{ // incidences.add(Incidence.createChapterIncidence(Language.GetText("Error.LoadData.SAX"), chapterPath, e)); //} //catch (IOException e) //{ // incidences.add(Incidence.createChapterIncidence(Language.GetText("Error.LoadData.IO"), chapterPath, e)); //} } // If reading the adaptation configuration, store it // With last profile modifications, only old games includes that information in its descriptor file. // For that reason, the next "path" info is the name of the profile, and it is necessary to eliminate the path's characteristic // such as / and .xml else if (qName.Equals("adaptation-configuration")) { foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("path")) { string adaptationName = entry.Value.ToString(); // delete the path's characteristics adaptationName = adaptationName.Substring(adaptationName.IndexOf("/") + 1); adaptationName = adaptationName.Substring(0, adaptationName.IndexOf(".")); currentChapter.setAdaptationName(adaptationName); // Search in incidences. If an adaptation incidence was related to this profile, the error is more relevant for (int j = 0; j < incidences.Count; j++) { Incidence current = incidences[j]; if (current.getAffectedArea() == Incidence.ADAPTATION_INCIDENCE && current.getAffectedResource().Equals(adaptationName)) { string message = current.getMessage(); incidences.RemoveAt(j); incidences.Insert(j, Incidence.createAdaptationIncidence(true, message + "Error.LoadAdaptation.Referenced", adaptationName, null)); } } } } } // If reading the assessment configuration, store it // With last profile modifications, only old games includes that information in its descriptor file. // For that reason, the next "path" info is the name of the profile, and it is necessary to eliminate the path's characteristic // such as / and .xml else if (qName.Equals("assessment-configuration")) { foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("path")) { string assessmentName = entry.Value.ToString(); // delete the path's characteristics assessmentName = assessmentName.Substring(assessmentName.IndexOf("/") + 1); assessmentName = assessmentName.Substring(0, assessmentName.IndexOf(".")); currentChapter.setAssessmentName(assessmentName); // Search in incidences. If an adaptation incidence was related to this profile, the error is more relevant for (int j = 0; j < incidences.Count; j++) { Incidence current = incidences[j]; if (current.getAffectedArea() == Incidence.ASSESSMENT_INCIDENCE && current.getAffectedResource().Equals(assessmentName)) { string message = current.getMessage(); incidences.RemoveAt(j); incidences.Insert(j, Incidence.createAssessmentIncidence(true, message + "Error.LoadAssessment.Referenced", assessmentName, null)); } } } } } }
/** * Loads the adaptation profile (set of adaptation rules + initial state) * stored in file with path xmlFile in zipFile * * @param zipFile * @param xmlFile * @param incidences * @return */ public static AdaptationProfile loadAdaptationProfile(InputStreamCreator isCreator, string xmlFile, List<Incidence> incidences) { AdaptationProfile newProfile = null; if (Loader.adventureData != null) { foreach (Chapter chapter in Loader.adventureData.getChapters()) { if (chapter.getAssessmentProfiles().Count != 0) { foreach (AdaptationProfile profile in chapter.getAdaptationProfiles()) if (profile.getName().Equals(xmlFile)) { newProfile = profile; break; } } } } else { // Open the file and load the data try { // Set the chapter handler List<AdaptationRule> rules = new List<AdaptationRule>(); AdaptedState initialState = new AdaptedState(); AdaptationHandler adpParser = new AdaptationHandler(isCreator, rules, initialState); //factory.setValidating(true); //SAXParser saxParser = factory.newSAXParser(); // Parse the data and close the data string adaptationIS = isCreator.buildInputStream(xmlFile); //saxParser.parse(adaptationIS, adpParser); //adaptationIS.close(); adpParser.Parse(adaptationIS); // Finally add the new controller to the list // Create the new profile string name = xmlFile; name = name.Substring(name.IndexOf("/") + 1); name = name.Substring(0, name.IndexOf(".")); newProfile = new AdaptationProfile(adpParser.getAdaptationRules(), adpParser.getInitialState(), name, adpParser.isScorm12(), adpParser.isScorm2004()); newProfile.setFlags(adpParser.getFlags()); newProfile.setVars(adpParser.getVars()); } catch (Exception e) { Debug.LogError(e); } //catch (ParserConfigurationException e) //{ // incidences.add(Incidence.createAdaptationIncidence(false, Language.GetText("Error.LoadAdaptationData.SAX"), xmlFile, e)); //} //catch (SAXException e) //{ // incidences.add(Incidence.createAdaptationIncidence(false, Language.GetText("Error.LoadAdaptationData.SAX"), xmlFile, e)); //} //catch (IOException e) //{ // incidences.add(Incidence.createAdaptationIncidence(false, Language.GetText("Error.LoadAdaptationData.IO"), xmlFile, e)); //} } return newProfile; }
/** * Loads the descriptor of the current ZIP adventure loaded * * @return The descriptor data of the game */ public static DescriptorData loadDescriptorData(InputStreamCreator isCreator, List<Incidence> incidences) { DescriptorData descriptorData = null; if (Loader.adventureData != null) { descriptorData = Loader.adventureData; } else { try { // Set the adventure handler DescriptorHandler descriptorParser = new DescriptorHandler(isCreator); //factory.setValidating(false); //SAXParser saxParser = factory.newSAXParser(); // Read and close the inputstrea string descriptorIS = isCreator.buildInputStream("descriptor.xml"); //saxParser.parse(descriptorIS, descriptorParser); //descriptorIS.close(); descriptorParser.Parse(descriptorIS); // Store the adventure data descriptorData = descriptorParser.getGameDescriptor(); } catch (Exception e) { Debug.LogError(e); } //catch (ParserConfigurationException e) //{ // incidences.add(Incidence.createDescriptorIncidence(Language.GetText("Error.LoadDescriptor.SAX"), e)); //} //catch (SAXException e) //{ // incidences.add(Incidence.createDescriptorIncidence(Language.GetText("Error.LoadDescriptor.SAX"), e)); //} //catch (IOException e) //{ // incidences.add(Incidence.createDescriptorIncidence(Language.GetText("Error.LoadDescriptor.IO"), e)); //} //catch (IllegalArgumentException e) //{ // incidences.add(Incidence.createDescriptorIncidence(Language.GetText("Error.LoadDescriptor.NoDescriptor"), e)); //} } return descriptorData; }
/** * 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 assessment profile (set of assessment rules) stored in file * with path xmlFile in zipFile * * @param zipFile * @param xmlFile * @param incidences * @return */ public static AssessmentProfile loadAssessmentProfile(InputStreamCreator isCreator, string xmlFile, List<Incidence> incidences) { AssessmentProfile newProfile = null; if (Loader.adventureData != null) { foreach (Chapter chapter in Loader.adventureData.getChapters()) { if (chapter.getAssessmentProfiles().Count != 0) { foreach (AssessmentProfile profile in chapter.getAssessmentProfiles()) { if (profile.getName().Equals(xmlFile)) { //try //{ newProfile = (AssessmentProfile)profile; //} //catch (CloneNotSupportedException e) //{ // e.printStackTrace(); //} break; } } } } } else { // Open the file and load the data try { // Set the chapter handler AssessmentProfile profile = new AssessmentProfile(); string name = xmlFile; name = name.Substring(name.IndexOf("/") + 1); if (name.IndexOf(".") != -1) name = name.Substring(0, name.IndexOf(".")); profile.setName(name); AssessmentHandler assParser = new AssessmentHandler(isCreator, profile); //factory.setValidating(true); //SAXParser saxParser = factory.newSAXParser(); //// Parse the data and close the data string assessmentIS = isCreator.buildInputStream(xmlFile); //saxParser.parse(assessmentIS, assParser); //assessmentIS.close(); assParser.Parse(assessmentIS); // Finally add the new controller to the list // Create the new profile // Fill flags & vars newProfile = profile; } catch (Exception e) { Debug.LogError(e); } //catch (ParserConfigurationException e) //{ // incidences.add(Incidence.createAssessmentIncidence(false, Language.GetText("Error.LoadAssessmentData.SAX"), xmlFile, e)); //} //catch (SAXException e) //{ // incidences.add(Incidence.createAssessmentIncidence(false, Language.GetText("Error.LoadAssessmentData.SAX"), xmlFile, e)); //} //catch (IOException e) //{ // incidences.add(Incidence.createAssessmentIncidence(false, Language.GetText("Error.LoadAssessmentData.IO"), xmlFile, e)); //} } return newProfile; }
/** * Loads an animation from a filename * * @param filename * The xml descriptor for the animation * @return the loaded Animation */ public static Animation loadAnimation(InputStreamCreator isCreator, string filename, ImageLoaderFactory imageloader) { AnimationHandler_ animationHandler = new AnimationHandler_(isCreator, imageloader); // Create a new factory //factory.setValidating(false); //SAXParser saxParser; try { //saxParser = factory.newSAXParser(); // Read and close the input stream //File file = new File(filename); string descriptorIS = null; /*try { System.out.println("FILENAME="+filename); descriptorIS = ResourceHandler.getInstance( ).buildInputStream(filename); System.out.println("descriptorIS==null?"+(descriptorIS==null)); //descriptorIS = new InputStream(ResourceHandler.getInstance().getResourceAsURLFromZip(filename)); } catch (Exception e) { Debug.LogError(e); } { e.printStackTrace(); } if (descriptorIS == null) { descriptorIS = AssetsController.getInputStream(filename); }*/ descriptorIS = isCreator.buildInputStream("Assets/Resources/" + filename); if (!descriptorIS.EndsWith(".eaa")) descriptorIS += ".eaa"; animationHandler.Parse(descriptorIS); //saxParser.parse(descriptorIS, animationHandler); //descriptorIS.close(); } catch (Exception e) { Debug.LogError(e); } //catch (ParserConfigurationException e) //{ // e.printStackTrace(); // System.err.println(filename); //} //catch (SAXException e) //{ // e.printStackTrace(); // System.err.println(filename); //} //catch (FileNotFoundException e) //{ // e.printStackTrace(); // System.err.println(filename); //} //catch (IOException e) //{ // e.printStackTrace(); // System.err.println(filename); //} if (animationHandler.getAnimation() != null) return animationHandler.getAnimation(); else return new Animation("anim" + (new System.Random()).Next(1000), imageloader); }
/** * Loads the adventure data from the given ZIP file. * * @param zipFile * Path to the zip file which holds the adventure * @return The adventure data, null if there was an error */ public static AdventureData loadAdventureData(InputStreamCreator isCreator, List<Incidence> incidences) { AdventureData adventureDataTemp = null; try { // Set the adventure handler AdventureHandler adventureParser = new AdventureHandler(isCreator, incidences); //factory.setValidating(false); //SAXParser saxParser = factory.newSAXParser(); // Read and close the input stream string descriptorIS = isCreator.buildInputStream("descriptor.xml"); adventureParser.Parse(descriptorIS); //descriptorIS.close(); // Load the assessment and adaptation profiles. It must be after parse // the adventure data because the profile's load from xml inserts each profile // in each chapter. adventureParser.loadProfiles(); // Store the adventure data adventureDataTemp = adventureParser.getAdventureData(); } catch (Exception e) { Debug.LogError(e); } //catch (ParserConfigurationException e) //{ // incidences.add(Incidence.createDescriptorIncidence(Language.GetText("Error.LoadDescriptor.SAX"), e)); //} //catch (SAXException e) //{ // incidences.add(Incidence.createDescriptorIncidence(Language.GetText("Error.LoadDescriptor.SAX"), e)); //} //catch (IOException e) //{ // incidences.add(Incidence.createDescriptorIncidence(Language.GetText("Error.LoadDescriptor.IO"), e)); //} //catch (IllegalArgumentException e) //{ // incidences.add(Incidence.createDescriptorIncidence(Language.GetText("Error.LoadDescriptor.NoDescriptor"), e)); //} return adventureDataTemp; }
/** * Loads the adaptation profile (set of adaptation rules + initial state) * stored in file with path xmlFile in zipFile * * @param zipFile * @param xmlFile * @param incidences * @return */ public static AdaptationProfile loadAdaptationProfile(InputStreamCreator isCreator, string xmlFile, List <Incidence> incidences) { AdaptationProfile newProfile = null; if (Loader.adventureData != null) { foreach (Chapter chapter in Loader.adventureData.getChapters()) { if (chapter.getAssessmentProfiles().Count != 0) { foreach (AdaptationProfile profile in chapter.getAdaptationProfiles()) { if (profile.getName().Equals(xmlFile)) { newProfile = profile; break; } } } } } else { // Open the file and load the data try { // Set the chapter handler List <AdaptationRule> rules = new List <AdaptationRule>(); AdaptedState initialState = new AdaptedState(); AdaptationHandler adpParser = new AdaptationHandler(isCreator, rules, initialState); //factory.setValidating(true); //SAXParser saxParser = factory.newSAXParser(); // Parse the data and close the data string adaptationIS = isCreator.buildInputStream(xmlFile); //saxParser.parse(adaptationIS, adpParser); //adaptationIS.close(); adpParser.Parse(adaptationIS); // Finally add the new controller to the list // Create the new profile string name = xmlFile; name = name.Substring(name.IndexOf("/") + 1); name = name.Substring(0, name.IndexOf(".")); newProfile = new AdaptationProfile(adpParser.getAdaptationRules(), adpParser.getInitialState(), name, adpParser.isScorm12(), adpParser.isScorm2004()); newProfile.setFlags(adpParser.getFlags()); newProfile.setVars(adpParser.getVars()); } catch (Exception e) { Debug.LogError(e); } //catch (ParserConfigurationException e) //{ // incidences.add(Incidence.createAdaptationIncidence(false, Language.GetText("Error.LoadAdaptationData.SAX"), xmlFile, e)); //} //catch (SAXException e) //{ // incidences.add(Incidence.createAdaptationIncidence(false, Language.GetText("Error.LoadAdaptationData.SAX"), xmlFile, e)); //} //catch (IOException e) //{ // incidences.add(Incidence.createAdaptationIncidence(false, Language.GetText("Error.LoadAdaptationData.IO"), xmlFile, e)); //} } return(newProfile); }
/** * Loads the assessment profile (set of assessment rules) stored in file * with path xmlFile in zipFile * * @param zipFile * @param xmlFile * @param incidences * @return */ public static AssessmentProfile loadAssessmentProfile(InputStreamCreator isCreator, string xmlFile, List <Incidence> incidences) { AssessmentProfile newProfile = null; if (Loader.adventureData != null) { foreach (Chapter chapter in Loader.adventureData.getChapters()) { if (chapter.getAssessmentProfiles().Count != 0) { foreach (AssessmentProfile profile in chapter.getAssessmentProfiles()) { if (profile.getName().Equals(xmlFile)) { //try //{ newProfile = (AssessmentProfile)profile; //} //catch (CloneNotSupportedException e) //{ // e.printStackTrace(); //} break; } } } } } else { // Open the file and load the data try { // Set the chapter handler AssessmentProfile profile = new AssessmentProfile(); string name = xmlFile; name = name.Substring(name.IndexOf("/") + 1); if (name.IndexOf(".") != -1) { name = name.Substring(0, name.IndexOf(".")); } profile.setName(name); AssessmentHandler assParser = new AssessmentHandler(isCreator, profile); //factory.setValidating(true); //SAXParser saxParser = factory.newSAXParser(); //// Parse the data and close the data string assessmentIS = isCreator.buildInputStream(xmlFile); //saxParser.parse(assessmentIS, assParser); //assessmentIS.close(); assParser.Parse(assessmentIS); // Finally add the new controller to the list // Create the new profile // Fill flags & vars newProfile = profile; } catch (Exception e) { Debug.LogError(e); } //catch (ParserConfigurationException e) //{ // incidences.add(Incidence.createAssessmentIncidence(false, Language.GetText("Error.LoadAssessmentData.SAX"), xmlFile, e)); //} //catch (SAXException e) //{ // incidences.add(Incidence.createAssessmentIncidence(false, Language.GetText("Error.LoadAssessmentData.SAX"), xmlFile, e)); //} //catch (IOException e) //{ // incidences.add(Incidence.createAssessmentIncidence(false, Language.GetText("Error.LoadAssessmentData.IO"), xmlFile, e)); //} } return(newProfile); }
/** * 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); }