protected override void FillNode(XmlNode node, object target, params IDOMWriterParam[] options) { var sceneElement = node as XmlElement; var scene = target as Scene; if (scene != null) { TrajectoryFixer.fixTrajectory(scene); } // Create the necessary elements to create the DOM XmlDocument doc = Writer.GetDoc(); // Create the root node sceneElement.SetAttribute("id", scene.getId()); sceneElement.SetAttribute("hideInventory", scene.HideInventory ? "yes" : "no"); if (options.Any(o => o is CIP && (o as CIP).TargetId.Equals(scene.getId()))) { sceneElement.SetAttribute("start", "yes"); } else { sceneElement.SetAttribute("start", "no"); } sceneElement.SetAttribute("playerLayer", scene.getPlayerLayer().ToString()); sceneElement.SetAttribute("playerScale", scene.getPlayerScale().ToString(CultureInfo.InvariantCulture)); sceneElement.SetAttribute("class", scene.getXApiClass()); sceneElement.SetAttribute("type", scene.getXApiType()); // Append the documentation (if avalaible) if (scene.getDocumentation() != null) { XmlNode sceneDocumentationNode = doc.CreateElement("documentation"); sceneDocumentationNode.AppendChild(doc.CreateTextNode(scene.getDocumentation())); sceneElement.AppendChild(sceneDocumentationNode); } // Append the resources foreach (ResourcesUni resources in scene.getResources()) { XmlNode resourcesNode = ResourcesDOMWriter.buildDOM(resources, ResourcesDOMWriter.RESOURCES_SCENE); doc.ImportNode(resourcesNode, true); sceneElement.AppendChild(resourcesNode); } // Append the name XmlNode nameNode = doc.CreateElement("name"); nameNode.AppendChild(doc.CreateTextNode(scene.getName())); sceneElement.AppendChild(nameNode); // Append the default inital position (if avalaible) if (scene.hasDefaultPosition()) { XmlElement initialPositionElement = doc.CreateElement("default-initial-position"); initialPositionElement.SetAttribute("x", scene.getPositionX().ToString()); initialPositionElement.SetAttribute("y", scene.getPositionY().ToString()); sceneElement.AppendChild(initialPositionElement); } // Append the exits (if there is at least one) if (scene.getExits().Count > 0) { XmlNode exitsElement = doc.CreateElement("exits"); // Append every single exit foreach (Exit exit in scene.getExits()) { // Create the exit element XmlElement exitElement = doc.CreateElement("exit"); exitElement.SetAttribute("rectangular", (exit.isRectangular() ? "yes" : "no")); exitElement.SetAttribute("x", exit.getX().ToString()); exitElement.SetAttribute("y", exit.getY().ToString()); exitElement.SetAttribute("width", exit.getWidth().ToString()); exitElement.SetAttribute("height", exit.getHeight().ToString()); exitElement.SetAttribute("hasInfluenceArea", (exit.getInfluenceArea().isExists() ? "yes" : "no")); exitElement.SetAttribute("idTarget", exit.getNextSceneId()); exitElement.SetAttribute("destinyY", exit.getDestinyY().ToString()); exitElement.SetAttribute("destinyX", exit.getDestinyX().ToString()); if (exit.getDestinyScale() >= 0) { exitElement.SetAttribute("destinyScale", exit.getDestinyScale().ToString(CultureInfo.InvariantCulture)); } exitElement.SetAttribute("transitionType", exit.getTransitionType().ToString()); exitElement.SetAttribute("transitionTime", exit.getTransitionTime().ToString()); exitElement.SetAttribute("not-effects", (exit.isHasNotEffects() ? "yes" : "no")); if (exit.getInfluenceArea().isExists()) { exitElement.SetAttribute("influenceX", exit.getInfluenceArea().getX().ToString()); exitElement.SetAttribute("influenceY", exit.getInfluenceArea().getY().ToString()); exitElement.SetAttribute("influenceWidth", exit.getInfluenceArea().getWidth().ToString()); exitElement.SetAttribute("influenceHeight", exit.getInfluenceArea().getHeight().ToString()); } // Append the documentation (if avalaible) if (exit.getDocumentation() != null) { XmlNode exitDocumentationNode = doc.CreateElement("documentation"); exitDocumentationNode.AppendChild(doc.CreateTextNode(exit.getDocumentation())); exitElement.AppendChild(exitDocumentationNode); } //Append the default exit look (if available) ExitLook defaultLook = exit.getDefaultExitLook(); if (defaultLook != null) { XmlElement exitLook = doc.CreateElement("exit-look"); if (defaultLook.getExitText() != null) { exitLook.SetAttribute("text", defaultLook.getExitText()); } if (defaultLook.getCursorPath() != null) { exitLook.SetAttribute("cursor-path", defaultLook.getCursorPath()); } if (defaultLook.getSoundPath() != null) { exitLook.SetAttribute("sound-path", defaultLook.getSoundPath()); } if (defaultLook.getExitText() != null || defaultLook.getCursorPath() != null) { exitElement.AppendChild(exitLook); } } // Append the next-scene structures foreach (NextScene nextScene in exit.getNextScenes()) { // Create the next-scene element XmlElement nextSceneElement = doc.CreateElement("next-scene"); nextSceneElement.SetAttribute("idTarget", nextScene.getTargetId()); // Append the destination position (if avalaible) if (nextScene.hasPlayerPosition()) { nextSceneElement.SetAttribute("x", nextScene.getPositionX().ToString()); nextSceneElement.SetAttribute("y", nextScene.getPositionY().ToString()); } nextSceneElement.SetAttribute("transitionTime", nextScene.getTransitionTime().ToString()); nextSceneElement.SetAttribute("transitionType", nextScene.getTransitionType().ToString()); // Append the conditions (if avalaible) if (!nextScene.getConditions().IsEmpty()) { DOMWriterUtility.DOMWrite(nextSceneElement, nextScene.getConditions()); } //Append the default exit look (if available) ExitLook look = nextScene.getExitLook(); if (look != null) { Debug.Log("SAVE 154: " + look.getExitText()); XmlElement exitLook = doc.CreateElement("exit-look"); if (look.getExitText() != null) { exitLook.SetAttribute("text", look.getExitText()); } if (look.getCursorPath() != null) { exitLook.SetAttribute("cursor-path", look.getCursorPath()); } if (look.getSoundPath() != null) { exitLook.SetAttribute("sound-path", look.getSoundPath()); } if (look.getExitText() != null || look.getCursorPath() != null) { nextSceneElement.AppendChild(exitLook); } } OrderedDictionary nextSceneEffects = new OrderedDictionary(); if (nextScene.getEffects() != null && !nextScene.getEffects().IsEmpty()) { nextSceneEffects.Add(EffectsDOMWriter.EFFECTS, nextScene.getEffects()); } if (nextScene.getPostEffects() != null && !nextScene.getPostEffects().IsEmpty()) { nextSceneEffects.Add(EffectsDOMWriter.POST_EFFECTS, nextScene.getPostEffects()); } // Append the next scene DOMWriterUtility.DOMWrite(nextSceneElement, nextSceneEffects, DOMWriterUtility.DontCreateElement()); exitElement.AppendChild(nextSceneElement); } if (!exit.isRectangular()) { foreach (Vector2 point in exit.getPoints()) { XmlElement pointNode = doc.CreateElement("point"); pointNode.SetAttribute("x", ((int)point.x).ToString()); pointNode.SetAttribute("y", ((int)point.y).ToString()); exitElement.AppendChild(pointNode); } } if (exit.getConditions() != null && !exit.getConditions().IsEmpty()) { DOMWriterUtility.DOMWrite(exitElement, exit.getConditions()); } OrderedDictionary effectsTypes = new OrderedDictionary(); if (exit.getEffects() != null && !exit.getEffects().IsEmpty()) { effectsTypes.Add(EffectsDOMWriter.EFFECTS, exit.getEffects()); } if (exit.getPostEffects() != null && !exit.getPostEffects().IsEmpty()) { effectsTypes.Add(EffectsDOMWriter.POST_EFFECTS, exit.getPostEffects()); } if (exit.getNotEffects() != null && !exit.getNotEffects().IsEmpty()) { effectsTypes.Add(EffectsDOMWriter.NOT_EFFECTS, exit.getNotEffects()); } DOMWriterUtility.DOMWrite(exitElement, effectsTypes, DOMWriterUtility.DontCreateElement()); // Append the exit exitsElement.AppendChild(exitElement); } // Append the list of exits sceneElement.AppendChild(exitsElement); } // Add the item references (if there is at least one) if (scene.getItemReferences().Count > 0) { XmlNode itemsNode = doc.CreateElement("objects"); // Append every single item reference foreach (ElementReference itemReference in scene.getItemReferences()) { // Create the item reference element XmlElement itemReferenceElement = doc.CreateElement("object-ref"); itemReferenceElement.SetAttribute("idTarget", itemReference.getTargetId()); itemReferenceElement.SetAttribute("x", itemReference.getX().ToString()); itemReferenceElement.SetAttribute("y", itemReference.getY().ToString()); itemReferenceElement.SetAttribute("scale", itemReference.Scale.ToString(CultureInfo.InvariantCulture)); if (itemReference.getLayer() != -1) { itemReferenceElement.SetAttribute("layer", itemReference.getLayer().ToString()); } if (itemReference.getInfluenceArea().isExists()) { itemReferenceElement.SetAttribute("hasInfluenceArea", "yes"); InfluenceArea ia = itemReference.getInfluenceArea(); itemReferenceElement.SetAttribute("influenceX", ia.getX().ToString()); itemReferenceElement.SetAttribute("influenceY", ia.getY().ToString()); itemReferenceElement.SetAttribute("influenceWidth", ia.getWidth().ToString()); itemReferenceElement.SetAttribute("influenceHeight", ia.getHeight().ToString()); } else { itemReferenceElement.SetAttribute("hasInfluenceArea", "no"); } // Append the documentation (if avalaible) if (itemReference.getDocumentation() != null) { XmlNode itemDocumentationNode = doc.CreateElement("documentation"); itemDocumentationNode.AppendChild(doc.CreateTextNode(itemReference.getDocumentation())); itemReferenceElement.AppendChild(itemDocumentationNode); } // Append the conditions (if avalaible) if (!itemReference.Conditions.IsEmpty()) { DOMWriterUtility.DOMWrite(itemReferenceElement, itemReference.Conditions); } // Append the exit itemsNode.AppendChild(itemReferenceElement); } // Append the list of exits sceneElement.AppendChild(itemsNode); } // Add the character references (if there is at least one) if (scene.getCharacterReferences().Count > 0) { XmlNode charactersNode = doc.CreateElement("characters"); // Append every single character reference foreach (ElementReference characterReference in scene.getCharacterReferences()) { // Create the character reference element XmlElement npcReferenceElement = doc.CreateElement("character-ref"); npcReferenceElement.SetAttribute("idTarget", characterReference.getTargetId()); npcReferenceElement.SetAttribute("x", characterReference.getX().ToString()); npcReferenceElement.SetAttribute("y", characterReference.getY().ToString()); npcReferenceElement.SetAttribute("scale", characterReference.Scale.ToString(CultureInfo.InvariantCulture)); npcReferenceElement.SetAttribute("orientation", ((int)characterReference.Orientation).ToString()); if (characterReference.getLayer() != -1) { npcReferenceElement.SetAttribute("layer", characterReference.getLayer().ToString()); } if (characterReference.getInfluenceArea().isExists()) { npcReferenceElement.SetAttribute("hasInfluenceArea", "yes"); InfluenceArea ia = characterReference.getInfluenceArea(); npcReferenceElement.SetAttribute("influenceX", ia.getX().ToString()); npcReferenceElement.SetAttribute("influenceY", ia.getY().ToString()); npcReferenceElement.SetAttribute("influenceWidth", ia.getWidth().ToString()); npcReferenceElement.SetAttribute("influenceHeight", ia.getHeight().ToString()); } else { npcReferenceElement.SetAttribute("hasInfluenceArea", "no"); } // Append the documentation (if avalaible) if (characterReference.getDocumentation() != null) { XmlNode itemDocumentationNode = doc.CreateElement("documentation"); itemDocumentationNode.AppendChild(doc.CreateTextNode(characterReference.getDocumentation())); npcReferenceElement.AppendChild(itemDocumentationNode); } // Append the conditions (if avalaible) if (!characterReference.Conditions.IsEmpty()) { DOMWriterUtility.DOMWrite(npcReferenceElement, characterReference.Conditions); } // Append the exit charactersNode.AppendChild(npcReferenceElement); } // Append the list of exits sceneElement.AppendChild(charactersNode); } // Append the exits (if there is at least one) if (scene.getActiveAreas().Count > 0) { XmlNode aasElement = doc.CreateElement("active-areas"); // Append every single exit foreach (ActiveArea activeArea in scene.getActiveAreas()) { // Create the active area element XmlElement aaElement = doc.CreateElement("active-area"); if (activeArea.getId() != null) { aaElement.SetAttribute("id", activeArea.getId()); } aaElement.SetAttribute("rectangular", (activeArea.isRectangular() ? "yes" : "no")); aaElement.SetAttribute("x", activeArea.getX().ToString()); aaElement.SetAttribute("y", activeArea.getY().ToString()); aaElement.SetAttribute("width", activeArea.getWidth().ToString()); aaElement.SetAttribute("height", activeArea.getHeight().ToString()); if (activeArea.getInfluenceArea().isExists()) { aaElement.SetAttribute("hasInfluenceArea", "yes"); InfluenceArea ia = activeArea.getInfluenceArea(); aaElement.SetAttribute("influenceX", ia.getX().ToString()); aaElement.SetAttribute("influenceY", ia.getY().ToString()); aaElement.SetAttribute("influenceWidth", ia.getWidth().ToString()); aaElement.SetAttribute("influenceHeight", ia.getHeight().ToString()); } else { aaElement.SetAttribute("hasInfluenceArea", "no"); } // Behavior if (activeArea.getBehaviour() == Item.BehaviourType.NORMAL) { aaElement.SetAttribute("behaviour", "normal"); } if (activeArea.getBehaviour() == Item.BehaviourType.ATREZZO) { aaElement.SetAttribute("behaviour", "atrezzo"); } if (activeArea.getBehaviour() == Item.BehaviourType.FIRST_ACTION) { aaElement.SetAttribute("behaviour", "first-action"); } // Append the documentation (if avalaible) if (activeArea.getDocumentation() != null) { XmlNode exitDocumentationNode = doc.CreateElement("documentation"); exitDocumentationNode.AppendChild(doc.CreateTextNode(activeArea.getDocumentation())); aaElement.AppendChild(exitDocumentationNode); } // Append the conditions (if avalaible) if (!activeArea.getConditions().IsEmpty()) { DOMWriterUtility.DOMWrite(aaElement, activeArea.getConditions()); } foreach (Description description in activeArea.getDescriptions()) { // Create the description XmlNode descriptionNode = doc.CreateElement("description"); // Append the conditions (if available) if (description.getConditions() != null && !description.getConditions().IsEmpty()) { DOMWriterUtility.DOMWrite(descriptionNode, description.getConditions()); } // Create and append the name, brief description and detailed description XmlElement aaNameNode = doc.CreateElement("name"); if (description.getNameSoundPath() != null && !description.getNameSoundPath().Equals("")) { aaNameNode.SetAttribute("soundPath", description.getNameSoundPath()); } aaNameNode.AppendChild(doc.CreateTextNode(description.getName())); descriptionNode.AppendChild(aaNameNode); XmlElement aaBriefNode = doc.CreateElement("brief"); if (description.getDescriptionSoundPath() != null && !description.getDescriptionSoundPath().Equals("")) { aaBriefNode.SetAttribute("soundPath", description.getDescriptionSoundPath()); } aaBriefNode.AppendChild(doc.CreateTextNode(description.getDescription())); descriptionNode.AppendChild(aaBriefNode); XmlElement aaDetailedNode = doc.CreateElement("detailed"); if (description.getDetailedDescriptionSoundPath() != null && !description.getDetailedDescriptionSoundPath().Equals("")) { aaDetailedNode.SetAttribute("soundPath", description.getDetailedDescriptionSoundPath()); } aaDetailedNode.AppendChild(doc.CreateTextNode(description.getDetailedDescription())); descriptionNode.AppendChild(aaDetailedNode); // Append the description aaElement.AppendChild(descriptionNode); } // Append the actions (if there is at least one) if (activeArea.getActions().Count > 0) { DOMWriterUtility.DOMWrite(aaElement, activeArea.getActions()); } if (!activeArea.isRectangular()) { foreach (Vector2 point in activeArea.getPoints()) { XmlElement pointNode = doc.CreateElement("point"); pointNode.SetAttribute("x", ((int)point.x).ToString()); pointNode.SetAttribute("y", ((int)point.y).ToString()); aaElement.AppendChild(pointNode); } } // Append the exit aasElement.AppendChild(aaElement); } // Append the list of exits sceneElement.AppendChild(aasElement); } // Append the barriers (if there is at least one) if (scene.getBarriers().Count > 0) { XmlNode barriersElement = doc.CreateElement("barriers"); // Append every single barrier foreach (Barrier barrier in scene.getBarriers()) { // Create the active area element XmlElement barrierElement = doc.CreateElement("barrier"); barrierElement.SetAttribute("x", barrier.getX().ToString()); barrierElement.SetAttribute("y", barrier.getY().ToString()); barrierElement.SetAttribute("width", barrier.getWidth().ToString()); barrierElement.SetAttribute("height", barrier.getHeight().ToString()); // Append the documentation (if avalaible) if (barrier.getDocumentation() != null) { XmlNode exitDocumentationNode = doc.CreateElement("documentation"); exitDocumentationNode.AppendChild(doc.CreateTextNode(barrier.getDocumentation())); barrierElement.AppendChild(exitDocumentationNode); } // Append the conditions (if avalaible) if (!barrier.getConditions().IsEmpty()) { DOMWriterUtility.DOMWrite(barrierElement, barrier.getConditions()); } // Append the barrier barriersElement.AppendChild(barrierElement); } // Append the list of exits sceneElement.AppendChild(barriersElement); } // Add the atrezzo item references (if there is at least one) if (scene.getAtrezzoReferences().Count > 0) { XmlNode atrezzoNode = doc.CreateElement("atrezzo"); // Append every single atrezzo reference foreach (ElementReference atrezzoReference in scene.getAtrezzoReferences()) { // Create the atrezzo reference element XmlElement atrezzoReferenceElement = doc.CreateElement("atrezzo-ref"); atrezzoReferenceElement.SetAttribute("idTarget", atrezzoReference.getTargetId()); atrezzoReferenceElement.SetAttribute("x", atrezzoReference.getX().ToString()); atrezzoReferenceElement.SetAttribute("y", atrezzoReference.getY().ToString()); atrezzoReferenceElement.SetAttribute("scale", atrezzoReference.Scale.ToString(CultureInfo.InvariantCulture)); if (atrezzoReference.getLayer() != -1) { atrezzoReferenceElement.SetAttribute("layer", atrezzoReference.getLayer().ToString()); } // Append the documentation (if avalaible) if (atrezzoReference.getDocumentation() != null) { XmlNode itemDocumentationNode = doc.CreateElement("documentation"); itemDocumentationNode.AppendChild(doc.CreateTextNode(atrezzoReference.getDocumentation())); atrezzoReferenceElement.AppendChild(itemDocumentationNode); } // Append the conditions (if avalaible) if (!atrezzoReference.Conditions.IsEmpty()) { DOMWriterUtility.DOMWrite(atrezzoReferenceElement, atrezzoReference.Conditions); } // Append the atrezzo reference atrezzoNode.AppendChild(atrezzoReferenceElement); } // Append the list of atrezzo references sceneElement.AppendChild(atrezzoNode); } if (scene.getTrajectory() != null) { DOMWriterUtility.DOMWrite(sceneElement, scene.getTrajectory()); } }
public static XmlNode buildDOM(Scene scene, bool initialScene) { XmlElement sceneElement = null; if (scene != null) { TrajectoryFixer.fixTrajectory(scene); } // Create the necessary elements to create the DOM XmlDocument doc = Writer.GetDoc(); // Create the root node sceneElement = doc.CreateElement("scene"); sceneElement.SetAttribute("id", scene.getId()); if (initialScene) { sceneElement.SetAttribute("start", "yes"); } else { sceneElement.SetAttribute("start", "no"); } sceneElement.SetAttribute("playerLayer", scene.getPlayerLayer().ToString()); sceneElement.SetAttribute("playerScale", scene.getPlayerScale().ToString()); // Append the documentation (if avalaible) if (scene.getDocumentation() != null) { XmlNode sceneDocumentationNode = doc.CreateElement("documentation"); sceneDocumentationNode.AppendChild(doc.CreateTextNode(scene.getDocumentation())); sceneElement.AppendChild(sceneDocumentationNode); } // Append the resources foreach (ResourcesUni resources in scene.getResources()) { XmlNode resourcesNode = ResourcesDOMWriter.buildDOM(resources, ResourcesDOMWriter.RESOURCES_SCENE); doc.ImportNode(resourcesNode, true); sceneElement.AppendChild(resourcesNode); } // Append the name XmlNode nameNode = doc.CreateElement("name"); nameNode.AppendChild(doc.CreateTextNode(scene.getName())); sceneElement.AppendChild(nameNode); // Append the default inital position (if avalaible) if (scene.hasDefaultPosition()) { XmlElement initialPositionElement = doc.CreateElement("default-initial-position"); initialPositionElement.SetAttribute("x", scene.getPositionX().ToString()); initialPositionElement.SetAttribute("y", scene.getPositionY().ToString()); sceneElement.AppendChild(initialPositionElement); } // Append the exits (if there is at least one) if (scene.getExits().Count > 0) { XmlNode exitsElement = doc.CreateElement("exits"); // Append every single exit foreach (Exit exit in scene.getExits()) { // Create the exit element XmlElement exitElement = doc.CreateElement("exit"); exitElement.SetAttribute("rectangular", (exit.isRectangular() ? "yes" : "no")); exitElement.SetAttribute("x", exit.getX().ToString()); exitElement.SetAttribute("y", exit.getY().ToString()); exitElement.SetAttribute("width", exit.getWidth().ToString()); exitElement.SetAttribute("height", exit.getHeight().ToString()); exitElement.SetAttribute("hasInfluenceArea", (exit.getInfluenceArea().isExists() ? "yes" : "no")); exitElement.SetAttribute("idTarget", exit.getNextSceneId()); exitElement.SetAttribute("destinyY", exit.getDestinyY().ToString()); exitElement.SetAttribute("destinyX", exit.getDestinyX().ToString()); exitElement.SetAttribute("transitionType", exit.getTransitionType().ToString()); exitElement.SetAttribute("transitionTime", exit.getTransitionTime().ToString()); exitElement.SetAttribute("not-effects", (exit.isHasNotEffects() ? "yes" : "no")); if (exit.getInfluenceArea().isExists()) { exitElement.SetAttribute("influenceX", exit.getInfluenceArea().getX().ToString()); exitElement.SetAttribute("influenceY", exit.getInfluenceArea().getY().ToString()); exitElement.SetAttribute("influenceWidth", exit.getInfluenceArea().getWidth().ToString()); exitElement.SetAttribute("influenceHeight", exit.getInfluenceArea().getHeight().ToString()); } // Append the documentation (if avalaible) if (exit.getDocumentation() != null) { XmlNode exitDocumentationNode = doc.CreateElement("documentation"); exitDocumentationNode.AppendChild(doc.CreateTextNode(exit.getDocumentation())); exitElement.AppendChild(exitDocumentationNode); } //Append the default exit look (if available) ExitLook defaultLook = exit.getDefaultExitLook(); if (defaultLook != null) { XmlElement exitLook = doc.CreateElement("exit-look"); if (defaultLook.getExitText() != null) { exitLook.SetAttribute("text", defaultLook.getExitText()); } if (defaultLook.getCursorPath() != null) { exitLook.SetAttribute("cursor-path", defaultLook.getCursorPath()); } if (defaultLook.getSoundPath() != null) { exitLook.SetAttribute("sound-path", defaultLook.getSoundPath()); } if (defaultLook.getExitText() != null || defaultLook.getCursorPath() != null) { exitElement.AppendChild(exitLook); } } // Append the next-scene structures foreach (NextScene nextScene in exit.getNextScenes()) { // Create the next-scene element XmlElement nextSceneElement = doc.CreateElement("next-scene"); nextSceneElement.SetAttribute("idTarget", nextScene.getTargetId()); // Append the destination position (if avalaible) if (nextScene.hasPlayerPosition()) { nextSceneElement.SetAttribute("x", nextScene.getPositionX().ToString()); nextSceneElement.SetAttribute("y", nextScene.getPositionY().ToString()); } nextSceneElement.SetAttribute("transitionTime", nextScene.getTransitionTime().ToString()); nextSceneElement.SetAttribute("transitionType", nextScene.getTransitionType().ToString()); // Append the conditions (if avalaible) if (!nextScene.getConditions().isEmpty()) { XmlNode conditionsNode = ConditionsDOMWriter.buildDOM(nextScene.getConditions()); doc.ImportNode(conditionsNode, true); nextSceneElement.AppendChild(conditionsNode); } //Append the default exit look (if available) ExitLook look = nextScene.getExitLook(); if (look != null) { Debug.Log("SAVE 154: " + look.getExitText()); XmlElement exitLook = doc.CreateElement("exit-look"); if (look.getExitText() != null) { exitLook.SetAttribute("text", look.getExitText()); } if (look.getCursorPath() != null) { exitLook.SetAttribute("cursor-path", look.getCursorPath()); } if (look.getSoundPath() != null) { exitLook.SetAttribute("sound-path", look.getSoundPath()); } if (look.getExitText() != null || look.getCursorPath() != null) { nextSceneElement.AppendChild(exitLook); } } // Append the effects (if avalaible) if (!nextScene.getEffects().isEmpty()) { XmlNode effectsNode = EffectsDOMWriter.buildDOM(EffectsDOMWriter.EFFECTS, nextScene.getEffects()); doc.ImportNode(effectsNode, true); nextSceneElement.AppendChild(effectsNode); } // Append the post-effects (if avalaible) if (!nextScene.getPostEffects().isEmpty()) { XmlNode postEffectsNode = EffectsDOMWriter.buildDOM(EffectsDOMWriter.POST_EFFECTS, nextScene.getPostEffects()); doc.ImportNode(postEffectsNode, true); nextSceneElement.AppendChild(postEffectsNode); } // Append the next scene exitElement.AppendChild(nextSceneElement); } if (!exit.isRectangular()) { foreach (Vector2 point in exit.getPoints()) { XmlElement pointNode = doc.CreateElement("point"); pointNode.SetAttribute("x", ((int)point.x).ToString()); pointNode.SetAttribute("y", ((int)point.y).ToString()); exitElement.AppendChild(pointNode); } } if (exit.getConditions() != null && !exit.getConditions().isEmpty()) { XmlNode conditionsNode = ConditionsDOMWriter.buildDOM(exit.getConditions()); doc.ImportNode(conditionsNode, true); exitElement.AppendChild(conditionsNode); } if (exit.getEffects() != null && !exit.getEffects().isEmpty()) { Debug.Log("SceneDOM Effects: " + exit.getEffects().getEffects().Count); XmlNode effectsNode = EffectsDOMWriter.buildDOM(EffectsDOMWriter.EFFECTS, exit.getEffects()); doc.ImportNode(effectsNode, true); exitElement.AppendChild(effectsNode); } if (exit.getPostEffects() != null && !exit.getPostEffects().isEmpty()) { Debug.Log("SceneDOM PostEffects: " + exit.getPostEffects().getEffects().Count); XmlNode postEffectsNode = EffectsDOMWriter.buildDOM(EffectsDOMWriter.POST_EFFECTS, exit.getPostEffects()); doc.ImportNode(postEffectsNode, true); exitElement.AppendChild(postEffectsNode); } if (exit.getNotEffects() != null && !exit.getNotEffects().isEmpty()) { Debug.Log("SceneDOM NonEffects: " + exit.getNotEffects().getEffects().Count); XmlNode notEffectsNode = EffectsDOMWriter.buildDOM(EffectsDOMWriter.NOT_EFFECTS, exit.getNotEffects()); doc.ImportNode(notEffectsNode, true); exitElement.AppendChild(notEffectsNode); } // Append the exit exitsElement.AppendChild(exitElement); } // Append the list of exits sceneElement.AppendChild(exitsElement); } // Add the item references (if there is at least one) if (scene.getItemReferences().Count > 0) { XmlNode itemsNode = doc.CreateElement("objects"); // Append every single item reference foreach (ElementReference itemReference in scene.getItemReferences()) { // Create the item reference element XmlElement itemReferenceElement = doc.CreateElement("object-ref"); itemReferenceElement.SetAttribute("idTarget", itemReference.getTargetId()); itemReferenceElement.SetAttribute("x", itemReference.getX().ToString()); itemReferenceElement.SetAttribute("y", itemReference.getY().ToString()); itemReferenceElement.SetAttribute("scale", itemReference.getScale().ToString()); if (itemReference.getLayer() != -1) { itemReferenceElement.SetAttribute("layer", itemReference.getLayer().ToString()); } if (itemReference.getInfluenceArea().isExists()) { itemReferenceElement.SetAttribute("hasInfluenceArea", "yes"); InfluenceArea ia = itemReference.getInfluenceArea(); itemReferenceElement.SetAttribute("influenceX", ia.getX().ToString()); itemReferenceElement.SetAttribute("influenceY", ia.getY().ToString()); itemReferenceElement.SetAttribute("influenceWidth", ia.getWidth().ToString()); itemReferenceElement.SetAttribute("influenceHeight", ia.getHeight().ToString()); } else { itemReferenceElement.SetAttribute("hasInfluenceArea", "no"); } // Append the documentation (if avalaible) if (itemReference.getDocumentation() != null) { XmlNode itemDocumentationNode = doc.CreateElement("documentation"); itemDocumentationNode.AppendChild(doc.CreateTextNode(itemReference.getDocumentation())); itemReferenceElement.AppendChild(itemDocumentationNode); } // Append the conditions (if avalaible) if (!itemReference.getConditions().isEmpty()) { XmlNode conditionsNode = ConditionsDOMWriter.buildDOM(itemReference.getConditions()); doc.ImportNode(conditionsNode, true); itemReferenceElement.AppendChild(conditionsNode); } // Append the exit itemsNode.AppendChild(itemReferenceElement); } // Append the list of exits sceneElement.AppendChild(itemsNode); } // Add the character references (if there is at least one) if (scene.getCharacterReferences().Count > 0) { XmlNode charactersNode = doc.CreateElement("characters"); // Append every single character reference foreach (ElementReference characterReference in scene.getCharacterReferences()) { // Create the character reference element XmlElement npcReferenceElement = doc.CreateElement("character-ref"); npcReferenceElement.SetAttribute("idTarget", characterReference.getTargetId()); npcReferenceElement.SetAttribute("x", characterReference.getX().ToString()); npcReferenceElement.SetAttribute("y", characterReference.getY().ToString()); npcReferenceElement.SetAttribute("scale", characterReference.getScale().ToString()); if (characterReference.getLayer() != -1) { npcReferenceElement.SetAttribute("layer", characterReference.getLayer().ToString()); } if (characterReference.getInfluenceArea().isExists()) { npcReferenceElement.SetAttribute("hasInfluenceArea", "yes"); InfluenceArea ia = characterReference.getInfluenceArea(); npcReferenceElement.SetAttribute("influenceX", ia.getX().ToString()); npcReferenceElement.SetAttribute("influenceY", ia.getY().ToString()); npcReferenceElement.SetAttribute("influenceWidth", ia.getWidth().ToString()); npcReferenceElement.SetAttribute("influenceHeight", ia.getHeight().ToString()); } else { npcReferenceElement.SetAttribute("hasInfluenceArea", "no"); } // Append the documentation (if avalaible) if (characterReference.getDocumentation() != null) { XmlNode itemDocumentationNode = doc.CreateElement("documentation"); itemDocumentationNode.AppendChild(doc.CreateTextNode(characterReference.getDocumentation())); npcReferenceElement.AppendChild(itemDocumentationNode); } // Append the conditions (if avalaible) if (!characterReference.getConditions().isEmpty()) { XmlNode conditionsNode = ConditionsDOMWriter.buildDOM(characterReference.getConditions()); doc.ImportNode(conditionsNode, true); npcReferenceElement.AppendChild(conditionsNode); } // Append the exit charactersNode.AppendChild(npcReferenceElement); } // Append the list of exits sceneElement.AppendChild(charactersNode); } // Append the exits (if there is at least one) if (scene.getActiveAreas().Count > 0) { XmlNode aasElement = doc.CreateElement("active-areas"); // Append every single exit foreach (ActiveArea activeArea in scene.getActiveAreas()) { // Create the active area element XmlElement aaElement = doc.CreateElement("active-area"); if (activeArea.getId() != null) { aaElement.SetAttribute("id", activeArea.getId()); } aaElement.SetAttribute("rectangular", (activeArea.isRectangular() ? "yes" : "no")); aaElement.SetAttribute("x", activeArea.getX().ToString()); aaElement.SetAttribute("y", activeArea.getY().ToString()); aaElement.SetAttribute("width", activeArea.getWidth().ToString()); aaElement.SetAttribute("height", activeArea.getHeight().ToString()); if (activeArea.getInfluenceArea().isExists()) { aaElement.SetAttribute("hasInfluenceArea", "yes"); InfluenceArea ia = activeArea.getInfluenceArea(); aaElement.SetAttribute("influenceX", ia.getX().ToString()); aaElement.SetAttribute("influenceY", ia.getY().ToString()); aaElement.SetAttribute("influenceWidth", ia.getWidth().ToString()); aaElement.SetAttribute("influenceHeight", ia.getHeight().ToString()); } else { aaElement.SetAttribute("hasInfluenceArea", "no"); } // Append the documentation (if avalaible) if (activeArea.getDocumentation() != null) { XmlNode exitDocumentationNode = doc.CreateElement("documentation"); exitDocumentationNode.AppendChild(doc.CreateTextNode(activeArea.getDocumentation())); aaElement.AppendChild(exitDocumentationNode); } // Append the conditions (if avalaible) if (!activeArea.getConditions().isEmpty()) { XmlNode conditionsNode = ConditionsDOMWriter.buildDOM(activeArea.getConditions()); doc.ImportNode(conditionsNode, true); aaElement.AppendChild(conditionsNode); } foreach (Description description in activeArea.getDescriptions()) { // Create the description XmlNode descriptionNode = doc.CreateElement("description"); // Append the conditions (if available) if (description.getConditions() != null && !description.getConditions().isEmpty()) { XmlNode conditionsNode = ConditionsDOMWriter.buildDOM(description.getConditions()); doc.ImportNode(conditionsNode, true); descriptionNode.AppendChild(conditionsNode); } // Create and append the name, brief description and detailed description XmlElement aaNameNode = doc.CreateElement("name"); if (description.getNameSoundPath() != null && !description.getNameSoundPath().Equals("")) { aaNameNode.SetAttribute("soundPath", description.getNameSoundPath()); } aaNameNode.AppendChild(doc.CreateTextNode(description.getName())); descriptionNode.AppendChild(aaNameNode); XmlElement aaBriefNode = doc.CreateElement("brief"); if (description.getDescriptionSoundPath() != null && !description.getDescriptionSoundPath().Equals("")) { aaBriefNode.SetAttribute("soundPath", description.getDescriptionSoundPath()); } aaBriefNode.AppendChild(doc.CreateTextNode(description.getDescription())); descriptionNode.AppendChild(aaBriefNode); XmlElement aaDetailedNode = doc.CreateElement("detailed"); if (description.getDetailedDescriptionSoundPath() != null && !description.getDetailedDescriptionSoundPath().Equals("")) { aaDetailedNode.SetAttribute("soundPath", description.getDetailedDescriptionSoundPath()); } aaDetailedNode.AppendChild(doc.CreateTextNode(description.getDetailedDescription())); descriptionNode.AppendChild(aaDetailedNode); // Append the description aaElement.AppendChild(descriptionNode); } // Append the actions (if there is at least one) if (activeArea.getActions().Count > 0) { XmlNode actionsNode = ActionsDOMWriter.buildDOM(activeArea.getActions()); doc.ImportNode(actionsNode, true); // Append the actions node aaElement.AppendChild(actionsNode); } if (!activeArea.isRectangular()) { foreach (Vector2 point in activeArea.getPoints()) { XmlElement pointNode = doc.CreateElement("point"); pointNode.SetAttribute("x", ((int)point.x).ToString()); pointNode.SetAttribute("y", ((int)point.y).ToString()); aaElement.AppendChild(pointNode); } } // Append the exit aasElement.AppendChild(aaElement); } // Append the list of exits sceneElement.AppendChild(aasElement); } // Append the barriers (if there is at least one) if (scene.getBarriers().Count > 0) { XmlNode barriersElement = doc.CreateElement("barriers"); // Append every single barrier foreach (Barrier barrier in scene.getBarriers()) { // Create the active area element XmlElement barrierElement = doc.CreateElement("barrier"); barrierElement.SetAttribute("x", barrier.getX().ToString()); barrierElement.SetAttribute("y", barrier.getY().ToString()); barrierElement.SetAttribute("width", barrier.getWidth().ToString()); barrierElement.SetAttribute("height", barrier.getHeight().ToString()); // Append the documentation (if avalaible) if (barrier.getDocumentation() != null) { XmlNode exitDocumentationNode = doc.CreateElement("documentation"); exitDocumentationNode.AppendChild(doc.CreateTextNode(barrier.getDocumentation())); barrierElement.AppendChild(exitDocumentationNode); } // Append the conditions (if avalaible) if (!barrier.getConditions().isEmpty()) { XmlNode conditionsNode = ConditionsDOMWriter.buildDOM(barrier.getConditions()); doc.ImportNode(conditionsNode, true); barrierElement.AppendChild(conditionsNode); } // Append the barrier barriersElement.AppendChild(barrierElement); } // Append the list of exits sceneElement.AppendChild(barriersElement); } // Add the atrezzo item references (if there is at least one) if (scene.getAtrezzoReferences().Count > 0) { XmlNode atrezzoNode = doc.CreateElement("atrezzo"); // Append every single atrezzo reference foreach (ElementReference atrezzoReference in scene.getAtrezzoReferences()) { // Create the atrezzo reference element XmlElement atrezzoReferenceElement = doc.CreateElement("atrezzo-ref"); atrezzoReferenceElement.SetAttribute("idTarget", atrezzoReference.getTargetId()); atrezzoReferenceElement.SetAttribute("x", atrezzoReference.getX().ToString()); atrezzoReferenceElement.SetAttribute("y", atrezzoReference.getY().ToString()); atrezzoReferenceElement.SetAttribute("scale", atrezzoReference.getScale().ToString()); if (atrezzoReference.getLayer() != -1) { atrezzoReferenceElement.SetAttribute("layer", atrezzoReference.getLayer().ToString()); } // Append the documentation (if avalaible) if (atrezzoReference.getDocumentation() != null) { XmlNode itemDocumentationNode = doc.CreateElement("documentation"); itemDocumentationNode.AppendChild(doc.CreateTextNode(atrezzoReference.getDocumentation())); atrezzoReferenceElement.AppendChild(itemDocumentationNode); } // Append the conditions (if avalaible) if (!atrezzoReference.getConditions().isEmpty()) { XmlNode conditionsNode = ConditionsDOMWriter.buildDOM(atrezzoReference.getConditions()); doc.ImportNode(conditionsNode, true); atrezzoReferenceElement.AppendChild(conditionsNode); } // Append the atrezzo reference atrezzoNode.AppendChild(atrezzoReferenceElement); } // Append the list of atrezzo references sceneElement.AppendChild(atrezzoNode); } if (scene.getTrajectory() != null) { XmlNode trajectoryNode = TrajectoryDOMWriter.buildDOM(scene.getTrajectory()); doc.ImportNode(trajectoryNode, true); sceneElement.AppendChild(trajectoryNode); } return(sceneElement); }
public override void ParseElement(XmlElement element) { XmlNodeList resourcess = element.SelectNodes("resources"), assets, conditions, effects, postseffects, notseffect, defaultsinitialsposition = element.SelectNodes("default-initial-position"), exits = element.SelectNodes("exits/exit"), exitslook, nextsscene = element.SelectNodes("next-scene"), points, objectsrefs = element.SelectNodes("objects/object-ref"), charactersrefs = element.SelectNodes("characters/character-ref"), atrezzosrefs = element.SelectNodes("atrezzo/atrezzo-ref"), activesareas = element.SelectNodes("active-areas/active-area"), barriers = element.SelectNodes("barrier"), trajectorys = element.SelectNodes("trajectory"); string tmpArgVal; string sceneId = ""; bool initialScene = false; int playerLayer = -1; float playerScale = 1.0f; tmpArgVal = element.GetAttribute("id"); if (!string.IsNullOrEmpty(tmpArgVal)) { sceneId = tmpArgVal; } tmpArgVal = element.GetAttribute("start"); if (!string.IsNullOrEmpty(tmpArgVal)) { initialScene = tmpArgVal.Equals("yes"); } tmpArgVal = element.GetAttribute("playerLayer"); if (!string.IsNullOrEmpty(tmpArgVal)) { playerLayer = int.Parse(tmpArgVal); } tmpArgVal = element.GetAttribute("playerScale"); if (!string.IsNullOrEmpty(tmpArgVal)) { playerScale = float.Parse(tmpArgVal, CultureInfo.InvariantCulture); } scene = new Scene(sceneId); scene.setPlayerLayer(playerLayer); scene.setPlayerScale(playerScale); if (initialScene) { chapter.setTargetId(sceneId); } if (element.SelectSingleNode("name") != null) { scene.setName(element.SelectSingleNode("name").InnerText); } if (element.SelectSingleNode("documentation") != null) { scene.setDocumentation(element.SelectSingleNode("documentation").InnerText); } foreach (XmlElement el in resourcess) { currentResources = new ResourcesUni(); tmpArgVal = el.GetAttribute("name"); if (!string.IsNullOrEmpty(tmpArgVal)) { currentResources.setName(el.GetAttribute(tmpArgVal)); } assets = el.SelectNodes("asset"); foreach (XmlElement ell in assets) { string type = ""; string path = ""; tmpArgVal = ell.GetAttribute("type"); if (!string.IsNullOrEmpty(tmpArgVal)) { type = tmpArgVal; } tmpArgVal = ell.GetAttribute("uri"); if (!string.IsNullOrEmpty(tmpArgVal)) { path = tmpArgVal; } currentResources.addAsset(type, path); } conditions = el.SelectNodes("condition"); foreach (XmlElement ell in conditions) { currentConditions = new Conditions(); new ConditionSubParser_(currentConditions, chapter).ParseElement(ell); currentResources.setConditions(currentConditions); } scene.addResources(currentResources); } foreach (XmlElement el in defaultsinitialsposition) { int x = int.MinValue, y = int.MinValue; tmpArgVal = el.GetAttribute("x"); if (!string.IsNullOrEmpty(tmpArgVal)) { x = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("y"); if (!string.IsNullOrEmpty(tmpArgVal)) { y = int.Parse(tmpArgVal); } scene.setDefaultPosition(x, y); } foreach (XmlElement el in exits) { int x = 0, y = 0, width = 0, height = 0; bool rectangular = true; int influenceX = 0, influenceY = 0, influenceWidth = 0, influenceHeight = 0; bool hasInfluence = false; string idTarget = ""; int destinyX = int.MinValue, destinyY = int.MinValue; int transitionType = 0, transitionTime = 0; bool notEffects = false; tmpArgVal = el.GetAttribute("rectangular"); if (!string.IsNullOrEmpty(tmpArgVal)) { rectangular = tmpArgVal.Equals("yes"); } tmpArgVal = el.GetAttribute("x"); if (!string.IsNullOrEmpty(tmpArgVal)) { x = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("y"); if (!string.IsNullOrEmpty(tmpArgVal)) { y = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("width"); if (!string.IsNullOrEmpty(tmpArgVal)) { width = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("height"); if (!string.IsNullOrEmpty(tmpArgVal)) { height = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("hasInfluenceArea"); if (!string.IsNullOrEmpty(tmpArgVal)) { hasInfluence = tmpArgVal.Equals("yes"); } tmpArgVal = el.GetAttribute("influenceX"); if (!string.IsNullOrEmpty(tmpArgVal)) { influenceX = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("influenceY"); if (!string.IsNullOrEmpty(tmpArgVal)) { influenceY = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("influenceWidth"); if (!string.IsNullOrEmpty(tmpArgVal)) { influenceWidth = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("influenceHeight"); if (!string.IsNullOrEmpty(tmpArgVal)) { influenceHeight = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("idTarget"); if (!string.IsNullOrEmpty(tmpArgVal)) { idTarget = tmpArgVal; } tmpArgVal = el.GetAttribute("destinyX"); if (!string.IsNullOrEmpty(tmpArgVal)) { destinyX = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("destinyY"); if (!string.IsNullOrEmpty(tmpArgVal)) { destinyY = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("transitionType"); if (!string.IsNullOrEmpty(tmpArgVal)) { transitionType = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("transitionTime"); if (!string.IsNullOrEmpty(tmpArgVal)) { transitionTime = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("not-effects"); if (!string.IsNullOrEmpty(tmpArgVal)) { notEffects = tmpArgVal.Equals("yes"); } currentExit = new Exit(rectangular, x, y, width, height); currentExit.setNextSceneId(idTarget); currentExit.setDestinyX(destinyX); currentExit.setDestinyY(destinyY); currentExit.setTransitionTime(transitionTime); currentExit.setTransitionType(transitionType); currentExit.setHasNotEffects(notEffects); if (hasInfluence) { InfluenceArea influenceArea = new InfluenceArea(influenceX, influenceY, influenceWidth, influenceHeight); currentExit.setInfluenceArea(influenceArea); } exitslook = el.SelectNodes("exit-look"); foreach (XmlElement ell in exitslook) { currentExitLook = new ExitLook(); string text = null; string cursorPath = null; string soundPath = null; tmpArgVal = ell.GetAttribute("text"); if (!string.IsNullOrEmpty(tmpArgVal)) { text = tmpArgVal; } tmpArgVal = ell.GetAttribute("cursor-path"); if (!string.IsNullOrEmpty(tmpArgVal)) { cursorPath = tmpArgVal; } tmpArgVal = ell.GetAttribute("sound-path"); if (!string.IsNullOrEmpty(tmpArgVal)) { soundPath = tmpArgVal; } currentExitLook.setCursorPath(cursorPath); currentExitLook.setExitText(text); if (soundPath != null) { currentExitLook.setSoundPath(soundPath); } currentExit.setDefaultExitLook(currentExitLook); } if (el.SelectSingleNode("documentation") != null) { currentExit.setDocumentation(el.SelectSingleNode("documentation").InnerText); } points = el.SelectNodes("point"); foreach (XmlElement ell in points) { int x_ = 0; int y_ = 0; tmpArgVal = ell.GetAttribute("x"); if (!string.IsNullOrEmpty(tmpArgVal)) { x_ = int.Parse(tmpArgVal); } tmpArgVal = ell.GetAttribute("y"); if (!string.IsNullOrEmpty(tmpArgVal)) { y_ = int.Parse(tmpArgVal); } currentPoint = new Vector2(x_, y_); currentExit.addPoint(currentPoint); } conditions = el.SelectNodes("condition"); foreach (XmlElement ell in conditions) { currentConditions = new Conditions(); new ConditionSubParser_(currentConditions, chapter).ParseElement(ell); currentExit.setConditions(currentConditions); } effects = el.SelectNodes("effect"); foreach (XmlElement ell in effects) { currentEffects = new Effects(); new EffectSubParser_(currentEffects, chapter).ParseElement(ell); currentExit.setEffects(currentEffects); } notseffect = el.SelectNodes("not-effect"); foreach (XmlElement ell in notseffect) { currentEffects = new Effects(); new EffectSubParser_(currentEffects, chapter).ParseElement(ell); currentExit.setNotEffects(currentEffects); } postseffects = el.SelectNodes("post-effect"); foreach (XmlElement ell in postseffects) { currentEffects = new Effects(); new EffectSubParser_(currentEffects, chapter).ParseElement(ell); currentExit.setPostEffects(currentEffects); } 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 nextsscene) { string idTarget = ""; int x = int.MinValue, y = int.MinValue; int transitionType = 0, transitionTime = 0; tmpArgVal = el.GetAttribute("idTarget"); if (!string.IsNullOrEmpty(tmpArgVal)) { idTarget = tmpArgVal; } tmpArgVal = el.GetAttribute("x"); if (!string.IsNullOrEmpty(tmpArgVal)) { x = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("y"); if (!string.IsNullOrEmpty(tmpArgVal)) { y = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("transitionType"); if (!string.IsNullOrEmpty(tmpArgVal)) { transitionType = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("transitionTime"); if (!string.IsNullOrEmpty(tmpArgVal)) { transitionTime = int.Parse(tmpArgVal); } currentNextScene = new NextScene(idTarget, x, y); currentNextScene.setTransitionType((NextSceneEnumTransitionType)transitionType); currentNextScene.setTransitionTime(transitionTime); currentNextScene.setExitLook(currentExitLook); conditions = el.SelectNodes("condition"); foreach (XmlElement ell in conditions) { currentConditions = new Conditions(); new ConditionSubParser_(currentConditions, chapter).ParseElement(ell); currentNextScene.setConditions(currentConditions); } effects = el.SelectNodes("effect"); foreach (XmlElement ell in effects) { currentEffects = new Effects(); new EffectSubParser_(currentEffects, chapter).ParseElement(ell); currentNextScene.setEffects(currentEffects); } postseffects = el.SelectNodes("post-effect"); foreach (XmlElement ell in effects) { currentEffects = new Effects(); new EffectSubParser_(currentEffects, chapter).ParseElement(ell); currentNextScene.setPostEffects(currentEffects); } } foreach (XmlElement el in objectsrefs) { string idTarget = ""; int x = 0, y = 0; float scale = 0; int layer = 0; int influenceX = 0, influenceY = 0, influenceWidth = 0, influenceHeight = 0; bool hasInfluence = false; tmpArgVal = el.GetAttribute("idTarget"); if (!string.IsNullOrEmpty(tmpArgVal)) { idTarget = tmpArgVal; } tmpArgVal = el.GetAttribute("x"); if (!string.IsNullOrEmpty(tmpArgVal)) { x = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("y"); if (!string.IsNullOrEmpty(tmpArgVal)) { y = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("scale"); if (!string.IsNullOrEmpty(tmpArgVal)) { scale = float.Parse(tmpArgVal, CultureInfo.InvariantCulture); } tmpArgVal = el.GetAttribute("layer"); if (!string.IsNullOrEmpty(tmpArgVal)) { layer = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("hasInfluenceArea"); if (!string.IsNullOrEmpty(tmpArgVal)) { hasInfluence = tmpArgVal.Equals("yes"); } tmpArgVal = el.GetAttribute("layer"); if (!string.IsNullOrEmpty(tmpArgVal)) { layer = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("influenceX"); if (!string.IsNullOrEmpty(tmpArgVal)) { influenceX = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("influenceY"); if (!string.IsNullOrEmpty(tmpArgVal)) { influenceY = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("influenceWidth"); if (!string.IsNullOrEmpty(tmpArgVal)) { influenceWidth = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("influenceHeight"); if (!string.IsNullOrEmpty(tmpArgVal)) { influenceHeight = int.Parse(tmpArgVal); } // This is for maintain the back-compatibility: in previous dtd versions layer has -1 as default value and this is // an erroneous value. This reason, if this value is -1, it will be changed to 0. Now in dtd there are not default value // for layer if (layer == -1) { layer = 0; } currentElementReference = new ElementReference(idTarget, x, y, layer); if (hasInfluence) { InfluenceArea influenceArea = new InfluenceArea(influenceX, influenceY, influenceWidth, influenceHeight); currentElementReference.setInfluenceArea(influenceArea); } if (scale > 0.001 || scale < -0.001) { currentElementReference.setScale(scale); } if (el.SelectSingleNode("documentation") != null) { currentElementReference.setDocumentation(el.SelectSingleNode("documentation").InnerText); } conditions = el.SelectNodes("condition"); foreach (XmlElement ell in conditions) { currentConditions = new Conditions(); new ConditionSubParser_(currentConditions, chapter).ParseElement(ell); currentElementReference.setConditions(currentConditions); } scene.addItemReference(currentElementReference); } foreach (XmlElement el in charactersrefs) { string idTarget = ""; int x = 0, y = 0; float scale = 0; int layer = 0; int influenceX = 0, influenceY = 0, influenceWidth = 0, influenceHeight = 0; bool hasInfluence = false; tmpArgVal = el.GetAttribute("idTarget"); if (!string.IsNullOrEmpty(tmpArgVal)) { idTarget = tmpArgVal; } tmpArgVal = el.GetAttribute("x"); if (!string.IsNullOrEmpty(tmpArgVal)) { x = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("y"); if (!string.IsNullOrEmpty(tmpArgVal)) { y = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("scale"); if (!string.IsNullOrEmpty(tmpArgVal)) { scale = float.Parse(tmpArgVal, CultureInfo.InvariantCulture); } tmpArgVal = el.GetAttribute("layer"); if (!string.IsNullOrEmpty(tmpArgVal)) { layer = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("hasInfluenceArea"); if (!string.IsNullOrEmpty(tmpArgVal)) { hasInfluence = tmpArgVal.Equals("yes"); } tmpArgVal = el.GetAttribute("layer"); if (!string.IsNullOrEmpty(tmpArgVal)) { layer = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("influenceX"); if (!string.IsNullOrEmpty(tmpArgVal)) { influenceX = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("influenceY"); if (!string.IsNullOrEmpty(tmpArgVal)) { influenceY = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("influenceWidth"); if (!string.IsNullOrEmpty(tmpArgVal)) { influenceWidth = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("influenceHeight"); if (!string.IsNullOrEmpty(tmpArgVal)) { influenceHeight = int.Parse(tmpArgVal); } // This is for maintain the back-compatibility: in previous dtd versions layer has -1 as default value and this is // an erroneous value. This reason, if this value is -1, it will be changed to 0. Now in dtd there are not default value // for layer if (layer == -1) { layer = 0; } currentElementReference = new ElementReference(idTarget, x, y, layer); if (hasInfluence) { InfluenceArea influenceArea = new InfluenceArea(influenceX, influenceY, influenceWidth, influenceHeight); currentElementReference.setInfluenceArea(influenceArea); } if (scale > 0.001 || scale < -0.001) { currentElementReference.setScale(scale); } if (el.SelectSingleNode("documentation") != null) { currentElementReference.setDocumentation(el.SelectSingleNode("documentation").InnerText); } conditions = el.SelectNodes("condition"); foreach (XmlElement ell in conditions) { currentConditions = new Conditions(); new ConditionSubParser_(currentConditions, chapter).ParseElement(ell); currentElementReference.setConditions(currentConditions); } scene.addCharacterReference(currentElementReference); } foreach (XmlElement el in atrezzosrefs) { string idTarget = ""; int x = 0, y = 0; float scale = 0; int layer = 0; int influenceX = 0, influenceY = 0, influenceWidth = 0, influenceHeight = 0; bool hasInfluence = false; tmpArgVal = el.GetAttribute("idTarget"); if (!string.IsNullOrEmpty(tmpArgVal)) { idTarget = tmpArgVal; } tmpArgVal = el.GetAttribute("x"); if (!string.IsNullOrEmpty(tmpArgVal)) { x = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("y"); if (!string.IsNullOrEmpty(tmpArgVal)) { y = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("scale"); if (!string.IsNullOrEmpty(tmpArgVal)) { scale = float.Parse(tmpArgVal, CultureInfo.InvariantCulture); } tmpArgVal = el.GetAttribute("layer"); if (!string.IsNullOrEmpty(tmpArgVal)) { layer = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("hasInfluenceArea"); if (!string.IsNullOrEmpty(tmpArgVal)) { hasInfluence = tmpArgVal.Equals("yes"); } tmpArgVal = el.GetAttribute("layer"); if (!string.IsNullOrEmpty(tmpArgVal)) { layer = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("influenceX"); if (!string.IsNullOrEmpty(tmpArgVal)) { influenceX = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("influenceY"); if (!string.IsNullOrEmpty(tmpArgVal)) { influenceY = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("influenceWidth"); if (!string.IsNullOrEmpty(tmpArgVal)) { influenceWidth = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("influenceHeight"); if (!string.IsNullOrEmpty(tmpArgVal)) { influenceHeight = int.Parse(tmpArgVal); } // This is for maintain the back-compatibility: in previous dtd versions layer has -1 as default value and this is // an erroneous value. This reason, if this value is -1, it will be changed to 0. Now in dtd there are not default value // for layer if (layer == -1) { layer = 0; } currentElementReference = new ElementReference(idTarget, x, y, layer); if (hasInfluence) { InfluenceArea influenceArea = new InfluenceArea(influenceX, influenceY, influenceWidth, influenceHeight); currentElementReference.setInfluenceArea(influenceArea); } if (scale > 0.001 || scale < -0.001) { currentElementReference.setScale(scale); } if (el.SelectSingleNode("documentation") != null) { currentElementReference.setDocumentation(el.SelectSingleNode("documentation").InnerText); } conditions = el.SelectNodes("condition"); foreach (XmlElement ell in conditions) { currentConditions = new Conditions(); new ConditionSubParser_(currentConditions, chapter).ParseElement(ell); currentElementReference.setConditions(currentConditions); } scene.addAtrezzoReference(currentElementReference); } foreach (XmlElement el in activesareas) { new ActiveAreaSubParser_(chapter, scene, scene.getActiveAreas().Count).ParseElement(el); } foreach (XmlElement el in barriers) { new BarrierSubParser_(chapter, scene, scene.getBarriers().Count).ParseElement(el); } foreach (XmlElement el in trajectorys) { new TrajectorySubParser_(chapter, scene).ParseElement(el); } if (scene != null) { TrajectoryFixer.fixTrajectory(scene); } chapter.addScene(scene); }
/* * (non-Javadoc) * * @see es.eucm.eadventure.engine.cargador.subparsers.SubParser#endElement(java.lang.string, java.lang.string, * java.lang.string) */ public override void endElement(string namespaceURI, string sName, string qName) { Debug.Log("END: " + sName + " " + qName + " sub:" + subParsing + ", reading: " + reading); // If no element is being subparsed if (subParsing == SUBPARSING_NONE) { // If it is a scene tag, store the scene in the game data if (qName.Equals("scene")) { if (scene != null) { TrajectoryFixer.fixTrajectory(scene); } chapter.addScene(scene); } // If it is a resources tag, add the resources to the scene else if (qName.Equals("resources")) { scene.addResources(currentResources); reading = READING_NONE; } // If it is a name tag, store the name in the scene else if (qName.Equals("name")) { scene.setName(currentstring.ToString().Trim()); } // If it is a documentation tag, hold the documentation in the current element else if (qName.Equals("documentation")) { if (reading == READING_NONE) { scene.setDocumentation(currentstring.ToString().Trim()); } else if (reading == READING_EXIT) { currentExit.setDocumentation(currentstring.ToString().Trim()); } else if (reading == READING_ELEMENT_REFERENCE) { currentElementReference.setDocumentation(currentstring.ToString().Trim()); } } // If it is an exit tag, store the exit in the scene else if (qName.Equals("exit")) { 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); } //scene.addExit( currentExit ); reading = READING_NONE; } // If it is an exit look tag, store the look in the exit else if (qName.Equals("exit-look")) { Debug.Log("559" + currentExitLook.getExitText()); if (reading == READING_NEXT_SCENE) { currentNextScene.setExitLook(currentExitLook); } else if (reading == READING_EXIT) { currentExit.setDefaultExitLook(currentExitLook); } } // If it is a next-scene tag, store the next scene in the current exit else if (qName.Equals("next-scene")) { currentExit.addNextScene(currentNextScene); reading = READING_NONE; } else if (qName.Equals("point")) { currentExit.addPoint(currentPoint); } // If it is a object-ref tag, store the reference in the scene else if (qName.Equals("object-ref")) { Debug.Log("SceneReference End"); scene.addItemReference(currentElementReference); reading = READING_NONE; } // If it is a character-ref tag, store the reference in the scene else if (qName.Equals("character-ref")) { Debug.Log("CharRef End"); scene.addCharacterReference(currentElementReference); reading = READING_NONE; } // If it is a atrezzo-ref tag, store the reference in the scene else if (qName.Equals("atrezzo-ref")) { scene.addAtrezzoReference(currentElementReference); reading = READING_NONE; } // Reset the current string currentstring = string.Empty; } // If a condition is being subparsed else if (subParsing == SUBPARSING_CONDITION) { // Spread the call subParser.endElement(namespaceURI, sName, qName); // If the condition tag is being closed if (qName.Equals("condition")) { // If we are parsing resources, add the condition to the current resources if (reading == READING_RESOURCES) { currentResources.setConditions(currentConditions); } // If we are parsing a next-scene, add the condition to the current next scene if (reading == READING_NEXT_SCENE) { currentNextScene.setConditions(currentConditions); } // If we are parsing an element reference, add the condition to the current element reference if (reading == READING_ELEMENT_REFERENCE) { currentElementReference.setConditions(currentConditions); } if (reading == READING_EXIT) { currentExit.setConditions(currentConditions); } // Switch the state subParsing = SUBPARSING_NONE; } } // If an effect is being subparsed else if (subParsing == SUBPARSING_EFFECT) { // Spread the call subParser.endElement(namespaceURI, sName, qName); // If the effect tag is being closed, add the effects to the current next scene and switch the state if (qName.Equals("effect")) { if (reading == READING_NEXT_SCENE) { currentNextScene.setEffects(currentEffects); } if (reading == READING_EXIT) { currentExit.setEffects(currentEffects); } subParsing = SUBPARSING_NONE; } // If the effect tag is being closed, add the post-effects to the current next scene and switch the state if (qName.Equals("post-effect")) { if (reading == READING_NEXT_SCENE) { currentNextScene.setPostEffects(currentEffects); } if (reading == READING_EXIT) { currentExit.setPostEffects(currentEffects); } subParsing = SUBPARSING_NONE; } if (qName.Equals("not-effect")) { currentExit.setNotEffects(currentEffects); subParsing = SUBPARSING_NONE; } } // If an active area is being subparsed else if (subParsing == SUBPARSING_ACTIVE_AREA) { // Spread the call subParser.endElement(namespaceURI, sName, qName); if (qName.Equals("active-area")) { subParsing = SUBPARSING_NONE; } } // If a barrier is being subparsed else if (subParsing == SUBPARSING_BARRIER) { // Spread the call subParser.endElement(namespaceURI, sName, qName); if (qName.Equals("barrier")) { subParsing = SUBPARSING_NONE; } } else if (subParsing == SUBPARSING_TRAJECTORY) { subParser.endElement(namespaceURI, sName, qName); if (qName.Equals("trajectory")) { subParsing = SUBPARSING_NONE; // next line is moved to TrayectorySubParser //scene.getTrajectory().deleteUnconnectedNodes(); } } }