public object DOMParse(XmlElement element, params object[] parameters) { XmlNodeList points = element.SelectNodes("point"), descriptions = element.SelectNodes("description"); XmlElement conditions = element.SelectSingleNode("condition") as XmlElement, actions = element.SelectSingleNode("actions") as XmlElement, documentation = element.SelectSingleNode("documentation") as XmlElement; string id = ExString.Default(element.GetAttribute("id"), null); bool rectangular = ExString.EqualsDefault(element.GetAttribute("rectangular"), "yes", true); int x = ExParsers.ParseDefault(element.GetAttribute("x"), 0), y = ExParsers.ParseDefault(element.GetAttribute("y"), 0), width = ExParsers.ParseDefault(element.GetAttribute("width"), 0), height = ExParsers.ParseDefault(element.GetAttribute("height"), 0); bool hasInfluence = ExString.EqualsDefault(element.GetAttribute("hasInfluenceArea"), "yes", false); int influenceX = ExParsers.ParseDefault(element.GetAttribute("influenceX"), 0), influenceY = ExParsers.ParseDefault(element.GetAttribute("influenceY"), 0), influenceWidth = ExParsers.ParseDefault(element.GetAttribute("influenceWidth"), 0), influenceHeight = ExParsers.ParseDefault(element.GetAttribute("influenceHeight"), 0); var activeArea = new ActiveArea((id ?? generateId()), rectangular, x, y, width, height); switch (element.GetAttribute("behaviour")) { case "atrezzo": activeArea.setBehaviour(Item.BehaviourType.ATREZZO); break; case "first-action": activeArea.setBehaviour(Item.BehaviourType.FIRST_ACTION); break; default: activeArea.setBehaviour(Item.BehaviourType.NORMAL); break; } if (hasInfluence) { var influenceArea = new InfluenceArea(influenceX, influenceY, influenceWidth, influenceHeight); activeArea.setInfluenceArea(influenceArea); } if (documentation != null) { activeArea.setDocumentation(documentation.InnerText); } activeArea.setDescriptions(DOMParserUtility.DOMParse <Description> (descriptions, parameters).ToList()); foreach (XmlElement el in points) { activeArea.addVector2( new Vector2(ExParsers.ParseDefault(el.GetAttribute("x"), 0), ExParsers.ParseDefault(el.GetAttribute("y"), 0))); } if (actions != null) { activeArea.setActions(DOMParserUtility.DOMParse <Action>(actions.ChildNodes, parameters).ToList()); } if (conditions != null) { activeArea.setConditions(DOMParserUtility.DOMParse(conditions, parameters) as Conditions ?? new Conditions()); } return(activeArea); }
public object DOMParse(XmlElement element, params object[] parameters) { var chapter = parameters [0] as Chapter; string sceneId = element.GetAttribute("id"); bool initialScene = ExString.EqualsDefault(element.GetAttribute("start"), "yes", false); bool hideInventory = ExString.EqualsDefault(element.GetAttribute("hideInventory"), "yes", false); bool allowsSavingGame = ExString.EqualsDefault(element.GetAttribute("allowsSavingGame"), "yes", true); int playerLayer = ExParsers.ParseDefault(element.GetAttribute("playerLayer"), -1); float playerScale = ExParsers.ParseDefault(element.GetAttribute("playerScale"), CultureInfo.InvariantCulture, 1.0f); playerScale = Mathf.Max(0, playerScale); scene = new Scene(sceneId) { HideInventory = hideInventory }; scene.setPlayerLayer(playerLayer); scene.setPlayerScale(playerScale); scene.setAllowsSavingGame(allowsSavingGame); if (initialScene) { chapter.setTargetId(sceneId); } var name = element.SelectSingleNode("name"); if (name != null) { scene.setName(name.InnerText); } var documentation = element.SelectSingleNode("documentation"); if (documentation != null) { scene.setDocumentation(documentation.InnerText); } //XAPI ELEMENTS scene.setXApiClass(ExString.Default(element.GetAttribute("class"), "accesible")); scene.setXApiType(ExString.Default(element.GetAttribute("type"), "area")); //END OF XAPI foreach (var res in DOMParserUtility.DOMParse <ResourcesUni> (element.SelectNodes("resources"), parameters)) { scene.addResources(res); } var defaultsinitialsposition = element.SelectSingleNode("default-initial-position") as XmlElement; if (defaultsinitialsposition != null) { int x = ExParsers.ParseDefault(defaultsinitialsposition.GetAttribute("x"), int.MinValue), y = ExParsers.ParseDefault(defaultsinitialsposition.GetAttribute("y"), int.MinValue); scene.setDefaultPosition(x, y); } foreach (XmlElement el in element.SelectNodes("exits/exit")) { int x = ExParsers.ParseDefault(el.GetAttribute("x"), 0), y = ExParsers.ParseDefault(el.GetAttribute("y"), 0), width = ExParsers.ParseDefault(el.GetAttribute("width"), 0), height = ExParsers.ParseDefault(el.GetAttribute("height"), 0); bool rectangular = ExString.EqualsDefault(el.GetAttribute("rectangular"), "yes", true); bool hasInfluence = ExString.EqualsDefault(el.GetAttribute("hasInfluenceArea"), "yes", false); int influenceX = ExParsers.ParseDefault(el.GetAttribute("influenceX"), 0), influenceY = ExParsers.ParseDefault(el.GetAttribute("influenceY"), 0), influenceWidth = ExParsers.ParseDefault(el.GetAttribute("influenceWidth"), 0), influenceHeight = ExParsers.ParseDefault(el.GetAttribute("influenceHeight"), 0); string idTarget = el.GetAttribute("idTarget"); int destinyX = ExParsers.ParseDefault(el.GetAttribute("destinyX"), int.MinValue), destinyY = ExParsers.ParseDefault(el.GetAttribute("destinyY"), int.MinValue); float destinyScale = ExParsers.ParseDefault(el.GetAttribute("destinyScale"), CultureInfo.InvariantCulture, float.MinValue); int transitionType = ExParsers.ParseDefault(el.GetAttribute("transitionType"), 0), transitionTime = ExParsers.ParseDefault(el.GetAttribute("transitionTime"), 0); bool notEffects = ExString.EqualsDefault(el.GetAttribute("not-effects"), "yes", false); currentExit = new Exit(rectangular, x, y, width, height); currentExit.setNextSceneId(idTarget); currentExit.setDestinyX(destinyX); currentExit.setDestinyY(destinyY); currentExit.setDestinyScale(destinyScale); currentExit.setTransitionTime(transitionTime); currentExit.setTransitionType(transitionType); currentExit.setHasNotEffects(notEffects); if (hasInfluence) { InfluenceArea influenceArea = new InfluenceArea(influenceX, influenceY, influenceWidth, influenceHeight); currentExit.setInfluenceArea(influenceArea); } foreach (XmlElement ell in el.SelectNodes("exit-look")) { currentExitLook = new ExitLook(); string text = ell.GetAttribute("text"); string cursorPath = ell.GetAttribute("cursor-path"); string soundPath = ell.GetAttribute("sound-path"); currentExitLook.setCursorPath(cursorPath); currentExitLook.setExitText(text); currentExitLook.setSoundPath(soundPath); currentExit.setDefaultExitLook(currentExitLook); } if (el.SelectSingleNode("documentation") != null) { currentExit.setDocumentation(el.SelectSingleNode("documentation").InnerText); } foreach (XmlElement ell in el.SelectNodes("point")) { currentPoint = new Vector2( ExParsers.ParseDefault(ell.GetAttribute("x"), 0), ExParsers.ParseDefault(ell.GetAttribute("y"), 0)); currentExit.addPoint(currentPoint); } currentExit.setConditions(DOMParserUtility.DOMParse(el.SelectSingleNode("condition"), parameters) as Conditions ?? new Conditions()); currentExit.setEffects(DOMParserUtility.DOMParse(el.SelectSingleNode("effect"), parameters) as Effects ?? new Effects()); currentExit.setNotEffects(DOMParserUtility.DOMParse(el.SelectSingleNode("not-effect"), parameters) as Effects ?? new Effects()); currentExit.setPostEffects(DOMParserUtility.DOMParse(el.SelectSingleNode("post-effect"), parameters) as Effects ?? new Effects()); if (currentExit.getNextScenes().Count > 0) { foreach (NextScene nextScene in currentExit.getNextScenes()) { Exit exit = (Exit)currentExit; exit.setNextScenes(new List <NextScene>()); exit.setDestinyX(nextScene.getPositionX()); exit.setDestinyY(nextScene.getPositionY()); exit.setEffects(nextScene.getEffects()); exit.setPostEffects(nextScene.getPostEffects()); if (exit.getDefaultExitLook() == null) { exit.setDefaultExitLook(nextScene.getExitLook()); } else { if (nextScene.getExitLook() != null) { if (nextScene.getExitLook().getExitText() != null && !nextScene.getExitLook().getExitText().Equals("")) { exit.getDefaultExitLook().setExitText(nextScene.getExitLook().getExitText()); } if (nextScene.getExitLook().getCursorPath() != null && !nextScene.getExitLook().getCursorPath().Equals("")) { exit.getDefaultExitLook().setCursorPath(nextScene.getExitLook().getCursorPath()); } } } exit.setHasNotEffects(false); exit.setConditions(nextScene.getConditions()); exit.setNextSceneId(nextScene.getTargetId()); scene.addExit(exit); } } else { scene.addExit(currentExit); } } foreach (XmlElement el in element.SelectNodes("next-scene")) { string idTarget = el.GetAttribute("idTarget"); int x = ExParsers.ParseDefault(el.GetAttribute("x"), int.MinValue), y = ExParsers.ParseDefault(el.GetAttribute("y"), int.MinValue), transitionType = ExParsers.ParseDefault(el.GetAttribute("transitionType"), 0), transitionTime = ExParsers.ParseDefault(el.GetAttribute("transitionTime"), 0); currentNextScene = new NextScene(idTarget, x, y); currentNextScene.setTransitionType((TransitionType)transitionType); currentNextScene.setTransitionTime(transitionTime); currentNextScene.setExitLook(currentExitLook); currentNextScene.setConditions(DOMParserUtility.DOMParse(el.SelectSingleNode("condition"), parameters) as Conditions ?? new Conditions()); currentNextScene.setEffects(DOMParserUtility.DOMParse(el.SelectSingleNode("effect"), parameters) as Effects ?? new Effects()); currentNextScene.setPostEffects(DOMParserUtility.DOMParse(el.SelectSingleNode("post-effect"), parameters) as Effects ?? new Effects()); } foreach (XmlElement el in element.SelectNodes("objects/object-ref")) { currentElementReference = parseElementReference(el, parameters); scene.addItemReference(currentElementReference); } foreach (XmlElement el in element.SelectNodes("characters/character-ref")) { currentElementReference = parseElementReference(el, parameters); scene.addCharacterReference(currentElementReference); } foreach (XmlElement el in element.SelectNodes("atrezzo/atrezzo-ref")) { currentElementReference = parseElementReference(el, parameters); scene.addAtrezzoReference(currentElementReference); } foreach (var activeArea in DOMParserUtility.DOMParse <ActiveArea>(element.SelectNodes("active-areas/active-area"), parameters).ToList()) { scene.addActiveArea(activeArea); } foreach (var barrier in DOMParserUtility.DOMParse <Barrier>(element.SelectNodes("barriers/barrier"), parameters).ToList()) { scene.addBarrier(barrier); } foreach (var trajectory in DOMParserUtility.DOMParse <Trajectory>(element.SelectNodes("trajectory"), parameters).ToList()) { scene.setTrajectory(trajectory); } if (scene != null) { TrajectoryFixer.fixTrajectory(scene); } return(scene); }
public object DOMParse(XmlElement element, params object[] parameters) { var chapter = parameters [0] as Chapter; var effects = element.Name == "macro" ? new Macro(element.GetAttribute("id")) : new Effects(); var macro = effects as Macro; if (macro != null) { macro.setDocumentation(element.InnerText); } string tmpArgVal; int x = 0; int y = 0; string path = ""; string id = ""; bool animated = false, addeffect = true; IEffect currentEffect = null; foreach (XmlElement effect in element.ChildNodes) { addeffect = true; switch (effect.Name) { case "cancel-action": currentEffect = new CancelActionEffect(); break; case "activate": case "deactivate": tmpArgVal = effect.GetAttribute("flag"); if (!string.IsNullOrEmpty(tmpArgVal)) { chapter.addFlag(tmpArgVal); } if (effect.Name == "activate") { currentEffect = new ActivateEffect(tmpArgVal); } else { currentEffect = new DeactivateEffect(tmpArgVal); } break; case "set-value": case "increment": case "decrement": string var = effect.GetAttribute("var"); int value = ExParsers.ParseDefault(effect.GetAttribute("value"), 0); if (effect.Name == "set-value") { currentEffect = new SetValueEffect(var, value); } else if (effect.Name == "increment") { currentEffect = new IncrementVarEffect(var, value); } else { currentEffect = new DecrementVarEffect(var, value); } chapter.addVar(var); break; case "macro-ref": currentEffect = new MacroReferenceEffect(effect.GetAttribute("id")); break; case "speak-char": // Add the effect and clear the current string currentEffect = new SpeakCharEffect(effect.GetAttribute("idTarget"), effect.InnerText.ToString().Trim()); ((SpeakCharEffect)currentEffect).setAudioPath(effect.GetAttribute("uri")); break; case "trigger-last-scene": currentEffect = new TriggerLastSceneEffect(); break; case "play-sound": // Store the path and background bool background = ExString.EqualsDefault(effect.GetAttribute("background"), "yes", true); path = effect.GetAttribute("uri"); // Add the new play sound effect currentEffect = new PlaySoundEffect(background, path); break; case "consume-object": currentEffect = new ConsumeObjectEffect(effect.GetAttribute("idTarget")); break; case "generate-object": currentEffect = new GenerateObjectEffect(effect.GetAttribute("idTarget")); break; case "trigger-book": currentEffect = new TriggerBookEffect(effect.GetAttribute("idTarget")); break; case "trigger-conversation": currentEffect = new TriggerConversationEffect(effect.GetAttribute("idTarget")); break; case "trigger-cutscene": currentEffect = new TriggerCutsceneEffect(effect.GetAttribute("idTarget")); break; case "trigger-scene": x = ExParsers.ParseDefault(effect.GetAttribute("x"), 0); y = ExParsers.ParseDefault(effect.GetAttribute("y"), 0); string scene = effect.GetAttribute("idTarget"); var triggerSceneEffect = new TriggerSceneEffect(scene, x, y) { DestinyScale = ExParsers.ParseDefault(effect.GetAttribute("scale"), float.MinValue) }; triggerSceneEffect.setTransitionTime(ExParsers.ParseDefault(effect.GetAttribute("transitionTime"), 0)); triggerSceneEffect.setTransitionType((TransitionType)ExParsers.ParseDefault(effect.GetAttribute("transitionType"), 0)); currentEffect = triggerSceneEffect; break; case "play-animation": x = ExParsers.ParseDefault(effect.GetAttribute("x"), 0); y = ExParsers.ParseDefault(effect.GetAttribute("y"), 0); path = effect.GetAttribute("uri"); // Add the new play sound effect currentEffect = new PlayAnimationEffect(path, x, y); break; case "move-player": x = ExParsers.ParseDefault(effect.GetAttribute("x"), 0); y = ExParsers.ParseDefault(effect.GetAttribute("y"), 0); // Add the new move player effect currentEffect = new MovePlayerEffect(x, y); break; case "move-npc": x = ExParsers.ParseDefault(effect.GetAttribute("x"), 0); y = ExParsers.ParseDefault(effect.GetAttribute("y"), 0); string npcTarget = effect.GetAttribute("idTarget"); // Add the new move NPC effect currentEffect = new MoveNPCEffect(npcTarget, x, y); break; case "random-effect": // Add the new random effect var randomEffect = new RandomEffect(ExParsers.ParseDefault(effect.GetAttribute("probability"), 0)); Effects randomEffectList = DOMParserUtility.DOMParse <Effects> (effect, parameters); if (randomEffectList.Count > 0) { randomEffect.setPositiveEffect(randomEffectList.getEffects()[0]); if (randomEffectList.Count > 1) { randomEffect.setNegativeEffect(randomEffectList.getEffects()[1]); } } currentEffect = randomEffect; break; case "wait-time": // Add the new move NPC effect currentEffect = new WaitTimeEffect(ExParsers.ParseDefault(effect.GetAttribute("time"), 0)); break; case "show-text": x = ExParsers.ParseDefault(effect.GetAttribute("x"), 0); y = ExParsers.ParseDefault(effect.GetAttribute("y"), 0); Color frontColor; ColorUtility.TryParseHtmlString(effect.GetAttribute("frontColor"), out frontColor); Color borderColor; ColorUtility.TryParseHtmlString(effect.GetAttribute("borderColor"), out borderColor); // Add the new ShowTextEffect currentEffect = new ShowTextEffect(effect.InnerText.ToString().Trim(), x, y, frontColor, borderColor); ((ShowTextEffect)currentEffect).setAudioPath(effect.GetAttribute("uri")); break; case "highlight-item": id = effect.GetAttribute("idTarget"); animated = ExString.EqualsDefault(effect.GetAttribute("animated"), "yes", false); int type = 0; tmpArgVal = effect.GetAttribute("type"); if (!string.IsNullOrEmpty(tmpArgVal)) { if (tmpArgVal.Equals("none")) { type = HighlightItemEffect.NO_HIGHLIGHT; } if (tmpArgVal.Equals("green")) { type = HighlightItemEffect.HIGHLIGHT_GREEN; } if (tmpArgVal.Equals("red")) { type = HighlightItemEffect.HIGHLIGHT_RED; } if (tmpArgVal.Equals("blue")) { type = HighlightItemEffect.HIGHLIGHT_BLUE; } if (tmpArgVal.Equals("border")) { type = HighlightItemEffect.HIGHLIGHT_BORDER; } } currentEffect = new HighlightItemEffect(id, type, animated); break; case "move-object": x = ExParsers.ParseDefault(effect.GetAttribute("x"), 0); y = ExParsers.ParseDefault(effect.GetAttribute("y"), 0); id = effect.GetAttribute("idTarget"); animated = ExString.EqualsDefault(effect.GetAttribute("animated"), "yes", false); float scale = ExParsers.ParseDefault(effect.GetAttribute("scale"), CultureInfo.InvariantCulture, 1.0f); int translateSpeed = ExParsers.ParseDefault(effect.GetAttribute("translateSpeed"), 20); int scaleSpeed = ExParsers.ParseDefault(effect.GetAttribute("scaleSpeed"), 20); currentEffect = new MoveObjectEffect(id, x, y, scale, animated, translateSpeed, scaleSpeed); break; case "speak-player": // Add the effect and clear the current string currentEffect = new SpeakPlayerEffect(effect.InnerText.ToString().Trim()); ((SpeakPlayerEffect)currentEffect).setAudioPath(effect.GetAttribute("uri")); break; case "condition": addeffect = false; var currentConditions = DOMParserUtility.DOMParse(effect, parameters) as Conditions ?? new Conditions(); var lastEffect = effects[effects.Count - 1] as AbstractEffect; if (lastEffect != null) { lastEffect.setConditions(currentConditions); } break; case "documentation": addeffect = false; break; default: currentEffect = DOMParserUtility.DOMParse(effect, parameters) as IEffect; addeffect = currentEffect != null; if (!addeffect) { Debug.LogWarning("EFFECT NOT SUPPORTED: " + effect.Name); } break; } if (addeffect) { effects.Add(currentEffect); } } return(effects); }
public object DOMParse(XmlElement element, params object[] parameters) { var chapter = parameters [0] as Chapter; Cutscene cutscene; XmlNodeList endsgame = element.SelectNodes("end-game"), nextsscene = element.SelectNodes("next-scene"); string slidesceneId = element.GetAttribute("id"); bool initialScene = ExString.EqualsDefault(element.GetAttribute("start"), "yes", false); if (element.Name.Equals("slidescene")) { cutscene = new Slidescene(slidesceneId); } else { cutscene = new Videoscene(slidesceneId); } if (initialScene) { chapter.setTargetId(slidesceneId); } //XAPI ELEMENTS cutscene.setXApiClass(element.GetAttribute("class")); cutscene.setXApiType(element.GetAttribute("type")); //END OF XAPI cutscene.setTargetId(element.GetAttribute("idTarget")); cutscene.setPositionX(ExParsers.ParseDefault(element.GetAttribute("destinyX"), int.MinValue)); cutscene.setPositionY(ExParsers.ParseDefault(element.GetAttribute("destinyY"), int.MinValue)); cutscene.setTransitionType((TransitionType)ExParsers.ParseDefault(element.GetAttribute("transitionType"), 0)); cutscene.setTransitionTime(ExParsers.ParseDefault(element.GetAttribute("transitionTime"), 0)); if (element.SelectSingleNode("name") != null) { cutscene.setName(element.SelectSingleNode("name").InnerText); } if (element.SelectSingleNode("documentation") != null) { cutscene.setDocumentation(element.SelectSingleNode("documentation").InnerText); } cutscene.setEffects(DOMParserUtility.DOMParse(element.SelectSingleNode("effect"), parameters) as Effects ?? new Effects()); if (cutscene is Videoscene) { ((Videoscene)cutscene).setCanSkip(ExString.EqualsDefault(element.GetAttribute("canSkip"), "yes", true)); } string next = ExString.Default(element.GetAttribute("next"), "go-back"); if (next.Equals("go-back")) { cutscene.setNext(Cutscene.GOBACK); } else if (next.Equals("new-scene")) { cutscene.setNext(Cutscene.NEWSCENE); } else if (next.Equals("end-chapter")) { cutscene.setNext(Cutscene.ENDCHAPTER); } // RESOURCES foreach (var res in DOMParserUtility.DOMParse <ResourcesUni> (element.SelectNodes("resources"), parameters)) { cutscene.addResources(res); } for (int i = 0; i < endsgame.Count; i++) { cutscene.setNext(Cutscene.ENDCHAPTER); } foreach (XmlElement el in nextsscene) { var currentNextScene = new NextScene(el.GetAttribute("idTarget"), ExParsers.ParseDefault(element.GetAttribute("destinyX"), int.MinValue), ExParsers.ParseDefault(element.GetAttribute("destinyY"), int.MinValue)); currentNextScene.setTransitionType((TransitionType)ExParsers.ParseDefault(element.GetAttribute("transitionType"), 0)); currentNextScene.setTransitionTime(ExParsers.ParseDefault(element.GetAttribute("transitionTime"), 0)); currentNextScene.setConditions(DOMParserUtility.DOMParse(el.SelectSingleNode("condition"), parameters) as Conditions ?? new Conditions()); currentNextScene.setEffects(DOMParserUtility.DOMParse(el.SelectSingleNode("effect"), parameters) as Effects ?? new Effects()); currentNextScene.setPostEffects(DOMParserUtility.DOMParse(el.SelectSingleNode("post-effect"), parameters) as Effects ?? new Effects()); cutscene.addNextScene(currentNextScene); } return(cutscene); }
public object DOMParse(XmlElement element, params object[] parameters) { XmlNodeList resourcess = element.SelectNodes("resources"), documentations = element.SelectNodes("documentations"), texts = element.SelectNodes("text"), pagess = element.SelectNodes("pages"), pages, titles, bullets, imgs; string bookId = ""; string xPrevious = "", xNext = "", yPrevious = "", yNext = ""; bookId = element.GetAttribute("id") ?? ""; xPrevious = element.GetAttribute("xPreviousPage") ?? ""; xNext = element.GetAttribute("xNextPage") ?? ""; yPrevious = element.GetAttribute("yPreviousPage") ?? ""; yNext = element.GetAttribute("yNextPage") ?? ""; Book book = new Book(bookId); if (xPrevious != "" && yPrevious != "") { try { int x = int.Parse(xPrevious); int y = int.Parse(yPrevious); book.setPreviousPageVector2(new Vector2(x, y)); } catch { // Number in XML is wrong -> Do nothing } } if (xNext != "" && yNext != "") { try { int x = int.Parse(xNext); int y = int.Parse(yNext); book.setNextPageVector2(new Vector2(x, y)); } catch { // Number in XML is wrong -> Do nothing } } // RESOURCES foreach (var res in DOMParserUtility.DOMParse <ResourcesUni>(resourcess, parameters)) { book.addResources(res); } foreach (XmlElement el in documentations) { string currentstring = el.InnerText; book.setDocumentation(currentstring.ToString().Trim()); } foreach (XmlElement el in texts) { book.setType(Book.TYPE_PARAGRAPHS); string currentstring_ = el.InnerText; // Add the new text paragraph if (currentstring_ != null && currentstring_.ToString().Trim().Replace("\t", "").Replace("\n", "").Length > 0) { book.addParagraph(new BookParagraph(BookParagraph.TEXT, currentstring_.ToString().Trim().Replace("\t", ""))); } titles = el.SelectNodes("title"); foreach (XmlElement ell in titles) { string currentstring = ell.InnerText; if (currentstring != null && currentstring.ToString().Trim().Replace("\t", "").Replace("\n", "").Length > 0) { book.addParagraph(new BookParagraph(BookParagraph.TITLE, currentstring.ToString().Trim().Replace("\t", ""))); } } bullets = el.SelectNodes("bullet"); foreach (XmlElement ell in bullets) { string currentstring = ell.InnerText; if (currentstring != null && currentstring.ToString().Trim().Replace("\t", "").Replace("\n", "").Length > 0) { book.addParagraph(new BookParagraph(BookParagraph.BULLET, currentstring.ToString().Trim().Replace("\t", ""))); } } imgs = el.SelectNodes("img"); foreach (XmlElement ell in imgs) { string currentstring = ell.InnerText; // Add the new text paragraph if (currentstring.ToString().Trim().Replace("\t", "").Replace("\n", "").Length > 0) { book.addParagraph(new BookParagraph(BookParagraph.TEXT, currentstring.ToString().Trim().Replace("\t", ""))); currentstring = string.Empty; } string path = ell.GetAttribute("src") ?? ""; // Add the new image paragraph book.addParagraph(new BookParagraph(BookParagraph.IMAGE, path)); } } foreach (XmlElement el in pagess) { book.setType(Book.TYPE_PAGES); pages = el.SelectNodes("page"); foreach (XmlElement ell in pages) { string uri = ""; int type = BookPage.TYPE_URL; int margin = 0; int marginEnd = 0; int marginTop = 0; int marginBottom = 0; bool scrollable = false; uri = ell.GetAttribute("uri") ?? ""; switch (ell.GetAttribute("type")) { case "resource": type = BookPage.TYPE_RESOURCE; break; case "image": type = BookPage.TYPE_IMAGE; break; } scrollable = "yes".Equals(ell.GetAttribute("scrollable")); margin = ExParsers.ParseDefault(ell.GetAttribute("margin"), 0); marginEnd = ExParsers.ParseDefault(ell.GetAttribute("marginEnd"), 0); marginTop = ExParsers.ParseDefault(ell.GetAttribute("marginTop"), 0); marginBottom = ExParsers.ParseDefault(ell.GetAttribute("marginBottom"), 0); book.addPage(uri, type, margin, marginEnd, marginTop, marginBottom, scrollable); } } return(book); }
public object DOMParse(XmlElement element, params object[] parameters) { XmlNode effects; XmlNode end_conversation; string tmpArgVal; // Store the name conversationName = ""; tmpArgVal = element.GetAttribute("id"); if (!string.IsNullOrEmpty(tmpArgVal)) { conversationName = tmpArgVal; } graphNodes = new List <ConversationNode>(); nodeLinks = new List <List <int> >(); foreach (XmlElement el in element) { //If there is a "editor-x" and "editor-y" attributes editorX = Mathf.Max(-1, ExParsers.ParseDefault(el.GetAttribute("editor-x"), -1)); editorY = Mathf.Max(-1, ExParsers.ParseDefault(el.GetAttribute("editor-y"), -1)); editorCollapsed = ExString.EqualsDefault(el.GetAttribute("editor-collapsed"), "yes", false); //If there is a "waitUserInteraction" attribute, store if the lines will wait until user interacts keepShowingDialogue = ExString.EqualsDefault(el.GetAttribute("waitUserInteraction"), "yes", false); // Node effects end_conversation = el.SelectSingleNode("end-conversation"); if (end_conversation != null) { effects = end_conversation.SelectSingleNode("effect"); } else { effects = el.SelectSingleNode("effect"); } var parsedEffects = DOMParserUtility.DOMParse(effects, parameters) as Effects ?? new Effects(); if (el.Name == "dialogue-node") { currentNode = new DialogueConversationNode(keepShowingDialogue); } else if (el.Name == "option-node") { random = ExString.EqualsDefault(el.GetAttribute("random"), "yes", false); showUserOption = ExString.EqualsDefault(el.GetAttribute("showUserOption"), "yes", false); keepShowing = ExString.EqualsDefault(el.GetAttribute("keepShowing"), "yes", false); preListening = ExString.EqualsDefault(el.GetAttribute("preListening"), "yes", false) || editorX >= 0 || editorY >= 0; var optionConversationNode = new OptionConversationNode(random, keepShowing, showUserOption, preListening); currentNode = optionConversationNode; //XAPI ELEMENTS optionConversationNode.setXApiQuestion(el.GetAttribute("question")); //END OF XAPI } if (currentNode != null) { // Node editor properties currentNode.setEditorX(editorX); currentNode.setEditorY(editorY); currentNode.setEditorCollapsed(editorCollapsed); // Create a new vector for the links of the current node currentLinks = new List <int>(); parseLines(currentNode, el, parameters); currentNode.setEffects(parsedEffects); // Add the current node to the node list, and the set of children references into the node links graphNodes.Add(currentNode); nodeLinks.Add(currentLinks); } } setNodeLinks(); return(new GraphConversation(conversationName, graphNodes[0])); }
private void parseLines(ConversationNode node, XmlElement lines, params object[] parameters) { string tmpArgVal = ""; currentLinks = new List <int>(); bool addline = true; bool timeoutConditions = false; foreach (XmlElement ell in lines.ChildNodes) { addline = true; audioPath = ell.GetAttribute("uri"); // If there is a "synthesize" attribute, store its value synthesizerVoice = ExString.EqualsDefault(ell.GetAttribute("synthesize"), "yes", false); // If there is a "keepShowing" attribute, store its value keepShowingLine = ExString.EqualsDefault(ell.GetAttribute("keepShowing"), "yes", false); if (ell.Name == "speak-player") { // Store the read string into the current node, and then delete the string. The trim is performed so we // don't have to worry with indentations or leading/trailing spaces conversationLine = new ConversationLine(ConversationLine.PLAYER, ell.InnerText); conversationLine.setAudioPath(audioPath); conversationLine.setSynthesizerVoice(synthesizerVoice); conversationLine.setKeepShowing(keepShowingLine); //XAPI ELEMENTS conversationLine.setXApiCorrect("true".Equals(ell.GetAttribute("correct"))); //END OF XAPI } else if (ell.Name == "speak-char") { // If it is a non-player character line, store the character name and audio path (if present) // Set default name to "NPC" characterName = "NPC"; // If there is a "idTarget" attribute, store it characterName = ell.GetAttribute("idTarget"); // Store the read string into the current node, and then delete the string. The trim is performed so we // don't have to worry with indentations or leading/trailing spaces conversationLine = new ConversationLine(characterName, ell.InnerText); conversationLine.setAudioPath(audioPath); conversationLine.setSynthesizerVoice(synthesizerVoice); conversationLine.setKeepShowing(keepShowingLine); } else if (ell.Name == "condition") { addline = false; var currentConditions = DOMParserUtility.DOMParse(ell, parameters) as Conditions ?? new Conditions(); if (timeoutConditions) { ((OptionConversationNode)currentNode).TimeoutConditions = currentConditions; } else { currentNode.getLine(currentNode.getLineCount() - 1).setConditions(currentConditions); } } else if (ell.Name == "child") { addline = false; tmpArgVal = ell.GetAttribute("nodeindex"); if (!string.IsNullOrEmpty(tmpArgVal)) { // Get the child node index, and store it int childIndex = int.Parse(tmpArgVal); currentLinks.Add(childIndex); } } else if (ell.Name == "timeout") { ((OptionConversationNode)currentNode).Timeout = ExParsers.ParseDefault(ell.InnerText, 10f); timeoutConditions = true; addline = false; } else { addline = false; } if (addline) { node.addLine(conversationLine); } } }
public object DOMParse(XmlElement element, params object[] parameters) { Action currentAction = new Action(0); //First we parse the elements every action haves: bool currentNeedsGoTo = ExString.EqualsDefault(element.GetAttribute("needsGoTo"), "yes", false); int currentKeepDistance = ExParsers.ParseDefault(element.GetAttribute("keepDistance"), 0); bool activateNotEffects = ExString.EqualsDefault(element.GetAttribute("not-effects"), "yes", false); bool activateClickEffects = ExString.EqualsDefault(element.GetAttribute("click-effects"), "yes", false); string currentIdTarget = element.GetAttribute("idTarget"); Conditions conditions = DOMParserUtility.DOMParse <Conditions> ((XmlElement)element.SelectSingleNode("condition"), parameters) ?? new Conditions(); Effects effects = DOMParserUtility.DOMParse <Effects> ((XmlElement)element.SelectSingleNode("effect"), parameters) ?? new Effects(); Effects clickeffects = DOMParserUtility.DOMParse <Effects> ((XmlElement)element.SelectSingleNode("click-effect"), parameters) ?? new Effects(); Effects noteffects = DOMParserUtility.DOMParse <Effects> ((XmlElement)element.SelectSingleNode("not-effect"), parameters) ?? new Effects(); // Then we instantiate the correct action by name. // We also parse the elements that are unique of that action. switch (element.Name) { case "examine": currentAction = new Action(Action.EXAMINE, conditions, effects, noteffects); break; case "grab": currentAction = new Action(Action.GRAB, conditions, effects, noteffects); break; case "use": currentAction = new Action(Action.USE, conditions, effects, noteffects); break; case "talk-to": currentAction = new Action(Action.TALK_TO, conditions, effects, noteffects); break; case "use-with": currentAction = new Action(Action.USE_WITH, currentIdTarget, conditions, effects, noteffects, clickeffects); break; case "give-to": currentAction = new Action(Action.GIVE_TO, currentIdTarget, conditions, effects, noteffects, clickeffects); break; case "drag-to": currentAction = new Action(Action.DRAG_TO, currentIdTarget, conditions, effects, noteffects, clickeffects); break; case "custom": case "custom-interact": CustomAction customAction = new CustomAction((element.Name == "custom") ? Action.CUSTOM : Action.CUSTOM_INTERACT); customAction.setName(element.GetAttribute("name")); customAction.addResources( DOMParserUtility.DOMParse <ResourcesUni>((XmlElement)element.SelectSingleNode("resources"), parameters) ?? new ResourcesUni()); currentAction = customAction; break; } // Documentation var documentationNode = element.SelectSingleNode("documentation"); if (documentationNode != null) { currentAction.setDocumentation(documentationNode.InnerText); } // Lastly we set al the attributes to the action currentAction.setConditions(conditions); currentAction.setEffects(effects); currentAction.setNotEffects(noteffects); currentAction.setKeepDistance(currentKeepDistance); currentAction.setNeedsGoTo(currentNeedsGoTo); currentAction.setActivatedNotEffects(activateNotEffects); currentAction.setClickEffects(clickeffects); currentAction.setActivatedClickEffects(activateClickEffects); return(currentAction); }