public override bool redoTool() { if (removed) { adventureData.addButton(action, type, ""); } bool done = base.redoTool(); if (!done) { return(false); } else { for (int i = 0; i < adventureData.getButtons().Count; i++) { if (adventureData.getButtons()[i].getType().Equals(type) && adventureData.getButtons()[i].getAction().Equals(action)) { adventureData.getButtons()[i].setPath(resources.getAssetPath(action + "#" + type)); } } controller.updatePanel(); return(true); } }
private void checkContextualButtons(string action, string type) { string useGrabPath = adventureData.getButtonPathFromEditor(DescriptorData.USE_GRAB_BUTTON, type); var hasUseGrabPath = !string.IsNullOrEmpty(useGrabPath); var hasCustomButtonForUseGrabPath = hasUseGrabPath && string.IsNullOrEmpty(adventureData.getButtonPathFromEditor(action, type)); if (hasUseGrabPath && hasCustomButtonForUseGrabPath) { adventureData.addButton(action, type, useGrabPath); } }
private void checkContextualButtons(string action, string type) { string useGrabPath = adventureData.getButtonPathFromEditor(DescriptorData.USE_GRAB_BUTTON, type); if (useGrabPath != null && !useGrabPath.Equals("")) { if (adventureData.getButtonPathFromEditor(action, type) == null || adventureData.getButtonPathFromEditor(action, type).Equals("")) { adventureData.addButton(action, type, useGrabPath); } } }
public void Parse(string path) { XmlDocument xmld = new XmlDocument(); string xml = ""; switch (ResourceManager.Instance.getLoadingType()) { case ResourceManager.LoadingType.RESOURCES_LOAD: directory = path.Split('/') [0] + "/"; if (path.Contains(".xml")) { path = path.Replace(".xml", ""); } TextAsset ta = Resources.Load(path) as TextAsset; if (ta == null) { Debug.Log("Can't load Descriptor file: " + path); return; } else { xml = ta.text; } break; case ResourceManager.LoadingType.SYSTEM_IO: xml = System.IO.File.ReadAllText(path); directory = ""; string[] parts = path.Split('/'); for (int i = 0; i < parts.Length - 1; i++) { directory += parts[i] + "/"; } break; } xmld.LoadXml(xml); XmlElement element = xmld.DocumentElement , descriptor = (XmlElement)element.SelectSingleNode("/game-descriptor") , title = (XmlElement)descriptor.SelectSingleNode("title") , description = (XmlElement)descriptor.SelectSingleNode("description") , configuration = (XmlElement)descriptor.SelectSingleNode("configuration") , contents = (XmlElement)descriptor.SelectSingleNode("contents"); if (descriptor != null) { tmpString = descriptor.GetAttribute("versionNumber"); if (!string.IsNullOrEmpty(tmpString)) { adventureData.setVersionNumber(tmpString); } } if (title != null) { tmpString = title.InnerText; if (!string.IsNullOrEmpty(tmpString)) { adventureData.setTitle(tmpString); } } if (description != null) { tmpString = description.InnerText; if (!string.IsNullOrEmpty(tmpString)) { adventureData.setDescription(tmpString); } } if (configuration != null) { tmpString = configuration.GetAttribute("keepShowing"); if (!string.IsNullOrEmpty(tmpString)) { adventureData.setKeepShowing(tmpString.Equals("yes")); } tmpString = configuration.GetAttribute("keyboard-navigation"); if (!string.IsNullOrEmpty(tmpString)) { adventureData.setKeyboardNavigation(tmpString.Equals("enabled")); } tmpString = configuration.GetAttribute("defaultClickAction"); if (!string.IsNullOrEmpty(tmpString)) { if (tmpString.Equals("showDetails")) { adventureData.setDeafultClickAction(DescriptorData.DefaultClickAction.SHOW_DETAILS); } else if (tmpString.Equals("showDetails")) { adventureData.setDeafultClickAction(DescriptorData.DefaultClickAction.SHOW_ACTIONS); } } tmpString = configuration.GetAttribute("perspective"); if (!string.IsNullOrEmpty(tmpString)) { if (tmpString.Equals("regular")) { adventureData.setPerspective(DescriptorData.Perspective.REGULAR); } else if (tmpString.Equals("isometric")) { adventureData.setPerspective(DescriptorData.Perspective.ISOMETRIC); } } tmpString = configuration.GetAttribute("dragBehaviour"); if (!string.IsNullOrEmpty(tmpString)) { if (tmpString.Equals("considerNonTargets")) { adventureData.setDragBehaviour(DescriptorData.DragBehaviour.CONSIDER_NON_TARGETS); } else if (tmpString.Equals("ignoreNonTargets")) { adventureData.setDragBehaviour(DescriptorData.DragBehaviour.IGNORE_NON_TARGETS); } } XmlElement gui = (XmlElement)configuration.SelectSingleNode("gui"); if (gui != null) { tmpString = gui.GetAttribute("type"); if (!string.IsNullOrEmpty(tmpString)) { if (tmpString.Equals("traditional")) { adventureData.setGUIType(DescriptorData.GUI_TRADITIONAL); } else if (tmpString.Equals("contextual")) { adventureData.setGUIType(DescriptorData.GUI_CONTEXTUAL); } } tmpString = gui.GetAttribute("customized"); if (!string.IsNullOrEmpty(tmpString)) { adventureData.setGUI(adventureData.getGUIType(), tmpString.Equals("yes")); } tmpString = gui.GetAttribute("inventoryPosition"); if (!string.IsNullOrEmpty(tmpString)) { switch (tmpString) { case "none": adventureData.setInventoryPosition(DescriptorData.INVENTORY_NONE); break; case "top_bottom": adventureData.setInventoryPosition(DescriptorData.INVENTORY_TOP_BOTTOM); break; case "top": adventureData.setInventoryPosition(DescriptorData.INVENTORY_TOP); break; case "bottom": adventureData.setInventoryPosition(DescriptorData.INVENTORY_BOTTOM); break; case "fixed_top": adventureData.setInventoryPosition(DescriptorData.INVENTORY_FIXED_TOP); break; case "fixed_bottom": adventureData.setInventoryPosition(DescriptorData.INVENTORY_FIXED_BOTTOM); break; } } XmlNodeList cursors = gui.SelectNodes("cursors/cursor"); foreach (XmlElement cursor in cursors) { string type = ""; string uri = ""; tmpString = cursor.GetAttribute("type"); if (!string.IsNullOrEmpty(tmpString)) { type = tmpString; } tmpString = cursor.GetAttribute("uri"); if (!string.IsNullOrEmpty(tmpString)) { uri = tmpString; } adventureData.addCursor(type, uri); } XmlNodeList buttons = gui.SelectNodes("buttons/button"); foreach (XmlElement button in buttons) { string type = ""; string uri = ""; string action = ""; tmpString = button.GetAttribute("type"); if (!string.IsNullOrEmpty(tmpString)) { type = tmpString; } tmpString = button.GetAttribute("uri"); if (!string.IsNullOrEmpty(tmpString)) { uri = tmpString; } tmpString = button.GetAttribute("action"); if (!string.IsNullOrEmpty(tmpString)) { action = tmpString; } adventureData.addButton(action, type, uri); } XmlNodeList arrows = gui.SelectNodes("cursors/cursor"); foreach (XmlElement arrow in arrows) { string type = ""; string uri = ""; tmpString = arrow.GetAttribute("type"); if (!string.IsNullOrEmpty(tmpString)) { type = tmpString; } tmpString = arrow.GetAttribute("uri"); if (!string.IsNullOrEmpty(tmpString)) { uri = tmpString; } adventureData.addArrow(type, uri); } } XmlElement mode = (XmlElement)configuration.SelectSingleNode("mode"); if (mode != null) { tmpString = mode.GetAttribute("playerTransparent"); if (!string.IsNullOrEmpty(tmpString)) { adventureData.setPlayerMode(tmpString.Equals("yes") ? DescriptorData.MODE_PLAYER_1STPERSON : DescriptorData.MODE_PLAYER_3RDPERSON); } } XmlElement graphics = (XmlElement)configuration.SelectSingleNode("graphics"); if (graphics != null) { tmpString = graphics.GetAttribute("playerTransparent"); if (!string.IsNullOrEmpty(tmpString)) { switch (tmpString) { case "windowed": adventureData.setGraphicConfig(DescriptorData.GRAPHICS_WINDOWED); break; case "fullscreen": adventureData.setGraphicConfig(DescriptorData.GRAPHICS_FULLSCREEN); break; case "blackbkg": adventureData.setGraphicConfig(DescriptorData.GRAPHICS_BLACKBKG); break; } } } } if (contents != null) { Chapter currentChapter; XmlNodeList chapters = contents.SelectNodes("chapter"); foreach (XmlElement chapter in chapters) { currentChapter = new Chapter(); string chapterPath = ""; tmpString = chapter.GetAttribute("path"); if (!string.IsNullOrEmpty(tmpString)) { chapterPath = tmpString; } currentChapter.setChapterPath(directory + chapterPath); ChapterHandler_ chapterParser = new ChapterHandler_(currentChapter); chapterParser.Parse(directory + chapterPath); title = (XmlElement)chapter.SelectSingleNode("title"); if (title != null) { tmpString = title.InnerText; if (!string.IsNullOrEmpty(tmpString)) { currentChapter.setTitle(tmpString); } } description = (XmlElement)chapter.SelectSingleNode("description"); if (description != null) { tmpString = title.InnerText; if (!string.IsNullOrEmpty(tmpString)) { currentChapter.setDescription(tmpString); } } XmlElement adaptation = (XmlElement)chapter.SelectSingleNode("adaptation-configuration"); if (adaptation != null) { tmpString = adaptation.GetAttribute("path"); if (!string.IsNullOrEmpty(tmpString)) { string adaptationName = tmpString; // delete the path's characteristics adaptationName = adaptationName.Substring(adaptationName.IndexOf("/") + 1); adaptationName = adaptationName.Substring(0, adaptationName.IndexOf(".")); currentChapter.setAdaptationName(adaptationName); } } XmlElement assestment = (XmlElement)chapter.SelectSingleNode("assessment-configuration"); if (adaptation != null) { tmpString = adaptation.GetAttribute("path"); if (!string.IsNullOrEmpty(tmpString)) { string assessmentName = tmpString; // delete the path's characteristics assessmentName = assessmentName.Substring(assessmentName.IndexOf("/") + 1); assessmentName = assessmentName.Substring(0, assessmentName.IndexOf(".")); currentChapter.setAssessmentName(assessmentName); } } adventureData.addChapter(currentChapter); } } /*if (qName.EndsWith("automatic-commentaries")) * { * adventureData.setCommentaries(true); * }*/ }
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)); } } } } } }