protected override void FillNode(XmlNode node, object target, params IDOMWriterParam[] options)
        {
            var character = target as NPC;

            XmlElement characterElement = node as XmlElement;

            // Create the necessary elements to create the DOM
            XmlDocument doc = Writer.GetDoc();

            // Add root node attributes
            characterElement.SetAttribute("id", character.getId());

            // Append the documentation (if avalaible)
            if (character.getDocumentation() != null)
            {
                XmlNode characterDocumentationNode = doc.CreateElement("documentation");
                characterDocumentationNode.AppendChild(doc.CreateTextNode(character.getDocumentation()));
                characterElement.AppendChild(characterDocumentationNode);
            }

            // Append the resources
            foreach (ResourcesUni resources in character.getResources())
            {
                XmlNode resourcesNode = ResourcesDOMWriter.buildDOM(resources, ResourcesDOMWriter.RESOURCES_CHARACTER);
                doc.ImportNode(resourcesNode, true);
                characterElement.AppendChild(resourcesNode);
            }

            // Create the textcolor
            XmlElement textColorNode = doc.CreateElement("textcolor");

            textColorNode.SetAttribute("showsSpeechBubble", (character.getShowsSpeechBubbles() ? "yes" : "no"));
            textColorNode.SetAttribute("bubbleBkgColor", ColorConverter.ColorToHex(character.getBubbleBkgColor()));
            textColorNode.SetAttribute("bubbleBorderColor", ColorConverter.ColorToHex(character.getBubbleBorderColor()));

            // Create and append the frontcolor
            XmlElement frontColorElement = doc.CreateElement("frontcolor");

            frontColorElement.SetAttribute("color", ColorConverter.ColorToHex(character.getTextFrontColor()));
            textColorNode.AppendChild(frontColorElement);

            // Create and append the bordercolor
            XmlElement borderColoElement = doc.CreateElement("bordercolor");

            borderColoElement.SetAttribute("color", ColorConverter.ColorToHex(character.getTextBorderColor()));
            textColorNode.AppendChild(borderColoElement);

            // Append the textcolor
            characterElement.AppendChild(textColorNode);

            //v1.4
            if (character.getBehaviour() == Item.BehaviourType.NORMAL)
            {
                characterElement.SetAttribute("behaviour", "normal");
            }
            if (character.getBehaviour() == Item.BehaviourType.ATREZZO)
            {
                characterElement.SetAttribute("behaviour", "atrezzo");
            }
            if (character.getBehaviour() == Item.BehaviourType.FIRST_ACTION)
            {
                characterElement.SetAttribute("behaviour", "first-action");
            }
            //v1.4


            foreach (Description description in character.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 and its soundPaths
                XmlElement nameNode = doc.CreateElement("name");
                if (description.getNameSoundPath() != null && !description.getNameSoundPath().Equals(""))
                {
                    nameNode.SetAttribute("soundPath", description.getNameSoundPath());
                }
                nameNode.AppendChild(doc.CreateTextNode(description.getName()));
                descriptionNode.AppendChild(nameNode);

                XmlElement briefNode = doc.CreateElement("brief");
                if (description.getDescriptionSoundPath() != null && !description.getDescriptionSoundPath().Equals(""))
                {
                    briefNode.SetAttribute("soundPath", description.getDescriptionSoundPath());
                }
                briefNode.AppendChild(doc.CreateTextNode(description.getDescription()));
                descriptionNode.AppendChild(briefNode);

                XmlElement detailedNode = doc.CreateElement("detailed");
                if (description.getDetailedDescriptionSoundPath() != null &&
                    !description.getDetailedDescriptionSoundPath().Equals(""))
                {
                    detailedNode.SetAttribute("soundPath", description.getDetailedDescriptionSoundPath());
                }
                detailedNode.AppendChild(doc.CreateTextNode(description.getDetailedDescription()));
                descriptionNode.AppendChild(detailedNode);

                // Append the description
                characterElement.AppendChild(descriptionNode);
            }

            // Create the voice tag
            XmlElement voiceNode = doc.CreateElement("voice");

            // Create and append the voice name and if is alwaysSynthesizer
            voiceNode.SetAttribute("name", character.getVoice());
            if (character.isAlwaysSynthesizer())
            {
                voiceNode.SetAttribute("synthesizeAlways", "yes");
            }
            else
            {
                voiceNode.SetAttribute("synthesizeAlways", "no");
            }

            // Append the voice tag

            characterElement.AppendChild(voiceNode);
            if (character.getActionsCount() > 0)
            {
                DOMWriterUtility.DOMWrite(characterElement, character.getActions());
            }
        }
        public static XmlNode buildDOM(ResourcesUni resources, int resourcesType)
        {
            XmlElement resourcesNode = null;

            // Create the necessary elements to create the DOM
            XmlDocument doc = Writer.GetDoc();

            // Create the root node
            resourcesNode = doc.CreateElement("resources");
            resourcesNode.SetAttribute("name", resources.getName());

            // Append the conditions block (if there is one)
            if (!resources.getConditions().IsEmpty())
            {
                DOMWriterUtility.DOMWrite(resourcesNode, resources.getConditions());
            }

            // Take the array of types and values of the assets
            string[] assetTypes  = resources.getAssetTypes();
            string[] assetValues = resources.getAssetValues();
            for (int i = 0; i < resources.getAssetCount(); i++)
            {
                XmlElement assetElement = doc.CreateElement("asset");
                assetElement.SetAttribute("type", assetTypes[i]);
                assetElement.SetAttribute("uri", assetValues[i]);
                resourcesNode.AppendChild(assetElement);
            }

            // If the owner is an item
            if (resourcesType == RESOURCES_ITEM)
            {
                // If the item has no image, add the default one
                if (resources.getAssetPath("image") == null)
                {
                    XmlElement assetElement = doc.CreateElement("asset");
                    assetElement.SetAttribute("type", "image");
                    assetElement.SetAttribute("uri", SpecialAssetPaths.ASSET_EMPTY_IMAGE);
                    resourcesNode.AppendChild(assetElement);
                }

                // If the item has no icon, add the default one
                if (resources.getAssetPath("icon") == null)
                {
                    XmlElement assetElement = doc.CreateElement("asset");
                    assetElement.SetAttribute("type", "icon");
                    assetElement.SetAttribute("uri", SpecialAssetPaths.ASSET_EMPTY_ICON);
                    resourcesNode.AppendChild(assetElement);
                }
            }

            // If the owner is a scene
            if (resourcesType == RESOURCES_SCENE)
            {
                // If the item has no image, add the default one
                if (resources.getAssetPath("background") == null)
                {
                    XmlElement assetElement = doc.CreateElement("asset");
                    assetElement.SetAttribute("type", "background");
                    assetElement.SetAttribute("uri", SpecialAssetPaths.ASSET_EMPTY_BACKGROUND);
                    resourcesNode.AppendChild(assetElement);
                }
            }

            // If the owner is a scene
            if (resourcesType == RESOURCES_CUTSCENE)
            {
                // If the item has no image, add the default one
                if (resources.getAssetPath("slides") == null)
                {
                    XmlElement assetElement = doc.CreateElement("asset");
                    assetElement.SetAttribute("type", "slides");
                    assetElement.SetAttribute("uri", SpecialAssetPaths.ASSET_EMPTY_ANIMATION);
                    resourcesNode.AppendChild(assetElement);
                }
            }

            // If the owner is a character
            else if (resourcesType == RESOURCES_CHARACTER)
            {
                // For each asset, if it has not been declared attach the empty animation
                string[] assets = new string[]
                {
                    "standup", "standdown", "standright", "standleft", "speakup", "speakdown", "speakright", "speakleft",
                    "useright", "useleft", "walkup", "walkdown", "walkright", "walkleft"
                };
                foreach (string asset in assets)
                {
                    if (resources.getAssetPath(asset) == null)
                    {
                        XmlElement assetElement = doc.CreateElement("asset");
                        assetElement.SetAttribute("type", asset);
                        assetElement.SetAttribute("uri", SpecialAssetPaths.ASSET_EMPTY_ANIMATION);
                        resourcesNode.AppendChild(assetElement);
                    }
                }
            }

            // If the owner is a character
            else if (resourcesType == RESOURCES_CUSTOM_ACTION)
            {
                // For each asset, if it has not been declared attach the empty animation
                string[] assets = new string[] { "buttonNormal", "buttonOver", "buttonPressed" };
                foreach (string asset in assets)
                {
                    if (resources.getAssetPath(asset) == null)
                    {
                        XmlElement assetElement = doc.CreateElement("asset");
                        assetElement.SetAttribute("type", asset);
                        assetElement.SetAttribute("uri", SpecialAssetPaths.ASSET_EMPTY_ICON);
                        resourcesNode.AppendChild(assetElement);
                    }
                }
            }

            // if the owner is a book
            else if (resourcesType == RESOURCES_BOOK)
            {
                // For each asset, if it has not been declared attach the empty animation
                string[] assets = new string[]
                { "background" /*, "arrowLeftNormal", "arrowRightNormal", "arrowLeftOver", "arrowRightOver" */ };
                foreach (string asset in assets)
                {
                    if (resources.getAssetPath(asset) == null)
                    {
                        XmlElement assetElement = doc.CreateElement("asset");
                        assetElement.SetAttribute("type", asset);
                        assetElement.SetAttribute("uri", SpecialAssetPaths.ASSET_EMPTY_BACKGROUND);
                        resourcesNode.AppendChild(assetElement);
                    }
                }
            }

            return(resourcesNode);
        }
Exemplo n.º 3
0
        private void FillNode(XmlNode toFill, GraphConversation graphConversation, params IDOMWriterParam[] options)
        {
            XmlElement conversationElement = toFill as XmlElement;

            // Get the complete node list
            List <ConversationNode> nodes = graphConversation.getAllNodes();

            // Create the necessary elements to create the DOM
            XmlDocument doc = Writer.GetDoc();

            // Create the root node
            conversationElement.SetAttribute("id", graphConversation.getId());

            // For each node
            for (int i = 0; i < nodes.Count; i++)
            {
                ConversationNode node = nodes[i];

                XmlElement nodeElement    = null;
                XmlNode    conditionsNode = null;

                // If the node is a dialogue node
                if (node is DialogueConversationNode)
                {
                    // Create the node element and set the nodeindex
                    nodeElement = doc.CreateElement("dialogue-node");
                    nodeElement.SetAttribute("nodeindex", i.ToString());
                    // Adds a random attribute if "keepShowing" is activate in conversation node data
                    if (((DialogueConversationNode)node).isKeepShowing())
                    {
                        nodeElement.SetAttribute("keepShowing", "yes");
                    }
                    if (node.getEditorX() != -1)
                    {
                        nodeElement.SetAttribute("editor-x", node.getEditorX().ToString());
                    }
                    if (node.getEditorY() != -1)
                    {
                        nodeElement.SetAttribute("editor-y", node.getEditorY().ToString());
                    }
                    // For each line of the node
                    for (int j = 0; j < node.getLineCount(); j++)
                    {
                        // Create a phrase element, and extract the actual text line
                        XmlElement       phrase;
                        ConversationLine line = node.getLine(j);

                        // If the line belongs to the player, create a "speak-player" element. Otherwise, if it belongs
                        // to a NPC,
                        // create a "speak-char" element, which will have an attribute "idTarget" with the name of the
                        // non-playable character,
                        // if there is no name the attribute won't be written
                        if (line.isPlayerLine())
                        {
                            phrase = doc.CreateElement("speak-player");
                        }
                        else
                        {
                            phrase = doc.CreateElement("speak-char");
                            if (!line.getName().Equals("NPC"))
                            {
                                phrase.SetAttribute("idTarget", line.getName());
                            }
                        }

                        //If there is audio track, store it as attribute
                        if (line.isValidAudio())
                        {
                            phrase.SetAttribute("uri", line.getAudioPath());
                        }
                        //If there is a synthesizer valid voice, store it as attribute
                        if (line.getSynthesizerVoice())
                        {
                            phrase.SetAttribute("synthesize", "yes");
                        }

                        // Add the line text into the element
                        phrase.InnerText = (line.getText());

                        // Add the element to the node
                        nodeElement.AppendChild(phrase);

                        // Create conditions for current effect
                        DOMWriterUtility.DOMWrite(nodeElement, line.getConditions());
                    }

                    // Check if the node is terminal
                    if (node.isTerminal())
                    {
                        // If it is terminal add a "end-conversation" element
                        XmlElement endConversation = doc.CreateElement("end-conversation");

                        // If the terminal node has an effect, include it into the DOM
                        if (node.hasEffects())
                        {
                            DOMWriterUtility.DOMWrite(endConversation, node.getEffects());
                        }

                        // Add the "end-conversation" tag into the node
                        nodeElement.AppendChild(endConversation);
                    }
                    else
                    {
                        // Otherwise, if the node has a child, add the element
                        XmlElement childElement = doc.CreateElement("child");

                        // Add the number of the child node (index of the node in the structure)
                        childElement.SetAttribute("nodeindex", nodes.IndexOf(node.getChild(0)).ToString());

                        // Insert the tag into the node
                        nodeElement.AppendChild(childElement);

                        // TODO MODIFIED
                        // If the terminal node has an effect, include it into the DOM
                        if (node.hasEffects())
                        {
                            DOMWriterUtility.DOMWrite(nodeElement, node.getEffects());
                        }
                    }
                }

                // If the node is a option node
                if (node is OptionConversationNode)
                {
                    // Create the node element and set the nodeindex
                    nodeElement = doc.CreateElement("option-node");
                    nodeElement.SetAttribute("nodeindex", i.ToString());
                    // Adds a random attribute if "random" is activate in conversation node data
                    if (((OptionConversationNode)node).isRandom())
                    {
                        nodeElement.SetAttribute("random", "yes");
                    }
                    // Adds a random attribute if "keepShowing" is activate in conversation node data
                    if (((OptionConversationNode)node).isKeepShowing())
                    {
                        nodeElement.SetAttribute("keepShowing", "yes");
                    }
                    // Adds a random attribute if "showUserOption" is activate in conversation node data
                    if (((OptionConversationNode)node).isShowUserOption())
                    {
                        nodeElement.SetAttribute("showUserOption", "yes");
                    }
                    // Adds a random attribute if "preListening" is activate in conversation node data
                    if (((OptionConversationNode)node).isPreListening())
                    {
                        nodeElement.SetAttribute("preListening", "yes");
                    }
                    if (node.getEditorX() != -1)
                    {
                        nodeElement.SetAttribute("editor-x", node.getEditorX().ToString());
                    }
                    if (node.getEditorY() != -1)
                    {
                        nodeElement.SetAttribute("editor-y", node.getEditorY().ToString());
                    }
                    // Adds the x position of the options conversations node
                    nodeElement.SetAttribute("x", ((OptionConversationNode)node).getX().ToString());
                    // Adds a random attribute if "preListening" is activate in conversation node data
                    nodeElement.SetAttribute("y", ((OptionConversationNode)node).getY().ToString());

                    // For each line of the node
                    for (int j = 0; j < node.getLineCount(); j++)
                    {
                        // Take the current conversation line
                        ConversationLine line = node.getLine(j);

                        // Create the actual option (a "speak-player" element) and add its respective text
                        XmlElement lineElement = doc.CreateElement("speak-player");
                        lineElement.InnerText = (node.getLine(j).getText());

                        //If there is audio track, store it as attribute
                        if (line.isValidAudio())
                        {
                            lineElement.SetAttribute("uri", line.getAudioPath());
                        }
                        //If there is a synthesizer valid voice, store it as attribute
                        if (line.getSynthesizerVoice())
                        {
                            lineElement.SetAttribute("synthesize", "yes");
                        }

                        // Create a child tag, and set it the index of the child
                        XmlElement childElement = doc.CreateElement("child");
                        childElement.SetAttribute("nodeindex", nodes.IndexOf(node.getChild(j)).ToString());

                        // Insert the text line in the option node
                        nodeElement.AppendChild(lineElement);
                        // Add conditions associated to that effect
                        DOMWriterUtility.DOMWrite(nodeElement, line.getConditions());
                        // Insert child tag
                        nodeElement.AppendChild(childElement);
                    }
                    // If node has an effect, include it into the DOM
                    if (node.hasEffects())
                    {
                        DOMWriterUtility.DOMWrite(nodeElement, node.getEffects());
                    }
                }

                // Add the node to the conversation
                conversationElement.AppendChild(nodeElement);
            }
        }
Exemplo n.º 4
0
        /**
         * Recursive function responsible for transforming a node (and its children)
         * into a DOM structure
         *
         * @param currentNode
         *            Node to be transformed
         * @param rootDOMNode
         *            DOM node in which the elements must be attached
         */

        private static void writeNodeInDOM(ConversationNode currentNode, XmlNode rootDOMNode)
        {
            // Extract the document
            XmlDocument document = rootDOMNode.OwnerDocument;

            // If the node is a DialogueNode write the lines one after another, and then the child (or the mark if it is no
            // child)
            if (currentNode.getType() == ConversationNodeViewEnum.DIALOGUE)
            {
                // For each line of the node
                for (int i = 0; i < currentNode.getLineCount(); i++)
                {
                    // Create a phrase element, and extract the actual text line
                    XmlElement       phrase;
                    XmlNode          conditionsNode = null;
                    ConversationLine line           = currentNode.getLine(i);

                    // If the line belongs to the player, create a "speak-player" element. Otherwise, if it belongs to a
                    // NPC,
                    // create a "speak-char" element, which will have an attribute "idTarget" with the name of the
                    // non-playable character,
                    // if there is no name the attribute won't be written
                    if (line.isPlayerLine())
                    {
                        phrase = document.CreateElement("speak-player");
                    }
                    else
                    {
                        phrase = document.CreateElement("speak-char");
                        if (!line.getName().Equals("NPC"))
                        {
                            phrase.SetAttribute("idTarget", line.getName());
                        }
                    }

                    // Add the line text into the element
                    phrase.InnerText = (line.getText());

                    //If there is audio track, store it as attribute
                    if (line.isValidAudio())
                    {
                        phrase.SetAttribute("uri", line.getAudioPath());
                    }
                    //If there is a synthesizer valid voice, store it as attribute
                    if (line.getSynthesizerVoice())
                    {
                        phrase.SetAttribute("synthesize", "yes");
                    }

                    // Add the element to the DOM root
                    rootDOMNode.AppendChild(phrase);

                    // Create conditions for current effect
                    DOMWriterUtility.DOMWrite(rootDOMNode, line.getConditions());
                }

                // Check if the node is terminal
                if (currentNode.isTerminal())
                {
                    // If it is terminal add a "end-conversation" element
                    XmlElement endConversation = document.CreateElement("end-conversation");

                    // Add the "end-conversation" tag into the root
                    rootDOMNode.AppendChild(endConversation);

                    // If the terminal node has an effect, include it into the DOM
                    if (currentNode.hasEffects())
                    {
                        DOMWriterUtility.DOMWrite(endConversation, currentNode.getEffects());
                    }
                }
                else
                {
                    // If the node isn't terminal, check if it performing a "go-back" (going back to the inmediatly upper
                    // OptionNode)
                    if (TreeConversation.thereIsGoBackTag(currentNode))
                    {
                        // If it is the case, add a "go-back" element
                        rootDOMNode.AppendChild(document.CreateElement("go-back"));
                    }
                    else
                    {
                        // Otherwise, if the node has a child, call the recursive function with the child node, and the same
                        // DOM root node
                        writeNodeInDOM(currentNode.getChild(0), rootDOMNode);
                    }
                }
            }

            // If the node is a OptionNode write a "response" element, and inside it a "option" element with its content
            else if (currentNode.getType() == ConversationNodeViewEnum.OPTION)
            {
                // Create the "response" element
                XmlElement response = document.CreateElement("response");
                // Adds a random attribute if "random" is activate in conversation node data
                if (((OptionConversationNode)currentNode).isRandom())
                {
                    response.SetAttribute("random", "yes");
                }
                // For each line of the node (we suppose the number of line equals the number of links, or children nodes)
                for (int i = 0; i < currentNode.getLineCount(); i++)
                {
                    // Create the "option" element
                    XmlElement       optionElement = document.CreateElement("option");
                    ConversationLine line          = currentNode.getLine(i);
                    // Create the actual option (a "speak-player" element) and add its respective text
                    XmlElement lineElement = document.CreateElement("speak-player");
                    lineElement.InnerText = currentNode.getLine(i).getText();

                    //If there is audio track, store it as attribute
                    if (line.isValidAudio())
                    {
                        lineElement.SetAttribute("uri", line.getAudioPath());
                    }
                    //If there is a synthesizer valid voice, store it as attribute
                    if (line.getSynthesizerVoice())
                    {
                        lineElement.SetAttribute("synthesize", "yes");
                    }

                    // Insert the text line in the option node
                    optionElement.AppendChild(lineElement);

                    // Call the recursive function, to write in the "option" node the appropiate elements
                    // Note that the root DOM node is the "option" element
                    writeNodeInDOM(currentNode.getChild(i), optionElement);

                    // Add the "option" element
                    response.AppendChild(optionElement);
                }
                // If the terminal node has an effect, include it into the DOM
                if (currentNode.hasEffects())
                {
                    DOMWriterUtility.DOMWrite(response, currentNode.getEffects());
                }

                // Add the element
                rootDOMNode.AppendChild(response);
            }
        }
Exemplo n.º 5
0
        protected override void FillNode(XmlNode node, object target, params IDOMWriterParam[] options)
        {
            var player = target as Player;

            XmlNode playerNode = node;

            // Create the necessary elements to create the DOM
            XmlDocument doc = Writer.GetDoc();


            // Append the documentation (if avalaible)
            if (player.getDocumentation() != null)
            {
                XmlNode playerDocumentationNode = doc.CreateElement("documentation");
                playerDocumentationNode.AppendChild(doc.CreateTextNode(player.getDocumentation()));
                playerNode.AppendChild(playerDocumentationNode);
            }

            // Append the resources
            foreach (ResourcesUni resources in player.getResources())
            {
                XmlNode resourcesNode = ResourcesDOMWriter.buildDOM(resources, ResourcesDOMWriter.RESOURCES_CHARACTER);
                doc.ImportNode(resourcesNode, true);
                playerNode.AppendChild(resourcesNode);
            }

            // Create the textcolor
            XmlElement textColorNode = doc.CreateElement("textcolor");

            textColorNode.SetAttribute("showsSpeechBubble", (player.getShowsSpeechBubbles() ? "yes" : "no"));
            textColorNode.SetAttribute("bubbleBkgColor", ColorConverter.ColorToHex(player.getBubbleBkgColor()));
            textColorNode.SetAttribute("bubbleBorderColor", ColorConverter.ColorToHex(player.getBubbleBorderColor()));

            // Create and append the frontcolor
            XmlElement frontColorElement = doc.CreateElement("frontcolor");

            frontColorElement.SetAttribute("color", ColorConverter.ColorToHex(player.getTextFrontColor()));
            textColorNode.AppendChild(frontColorElement);

            // Create and append the bordercolor
            XmlElement borderColoElement = doc.CreateElement("bordercolor");

            borderColoElement.SetAttribute("color", ColorConverter.ColorToHex(player.getTextBorderColor()));
            textColorNode.AppendChild(borderColoElement);

            // Append the textcolor
            playerNode.AppendChild(textColorNode);

            foreach (Description description in player.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 nameNode = doc.CreateElement("name");
                if (description.getNameSoundPath() != null && !description.getNameSoundPath().Equals(""))
                {
                    nameNode.SetAttribute("soundPath", description.getNameSoundPath());
                }
                nameNode.AppendChild(doc.CreateTextNode(description.getName()));
                descriptionNode.AppendChild(nameNode);

                XmlElement briefNode = doc.CreateElement("brief");
                if (description.getDescriptionSoundPath() != null && !description.getDescriptionSoundPath().Equals(""))
                {
                    briefNode.SetAttribute("soundPath", description.getDescriptionSoundPath());
                }
                briefNode.AppendChild(doc.CreateTextNode(description.getDescription()));
                descriptionNode.AppendChild(briefNode);

                XmlElement detailedNode = doc.CreateElement("detailed");
                if (description.getDetailedDescriptionSoundPath() != null &&
                    !description.getDetailedDescriptionSoundPath().Equals(""))
                {
                    detailedNode.SetAttribute("soundPath", description.getDetailedDescriptionSoundPath());
                }
                detailedNode.AppendChild(doc.CreateTextNode(description.getDetailedDescription()));
                descriptionNode.AppendChild(detailedNode);

                // Append the description
                playerNode.AppendChild(descriptionNode);
            }

            // Create the voice tag
            XmlElement voiceNode = doc.CreateElement("voice");

            // Create and append the voice name and if is alwaysSynthesizer
            voiceNode.SetAttribute("name", player.getVoice());
            if (player.isAlwaysSynthesizer())
            {
                voiceNode.SetAttribute("synthesizeAlways", "yes");
            }
            else
            {
                voiceNode.SetAttribute("synthesizeAlways", "no");
            }

            // Append the voice tag

            playerNode.AppendChild(voiceNode);
        }
        /**
         * Returns the DOM element for the chapter
         *
         * @param chapter
         *            Chapter data to be written
         * @return DOM element with the chapter data
         */

        public static XmlElement buildDOM(AssessmentProfile profile, XmlDocument doc)
        {
            List <AssessmentRule> rules = profile.getRules();

            XmlElement assessmentNode = null;

            // Create the root node
            assessmentNode = doc.CreateElement("assessment");
            if (profile.isShowReportAtEnd())
            {
                assessmentNode.SetAttribute("show-report-at-end", "yes");
            }
            else
            {
                assessmentNode.SetAttribute("show-report-at-end", "no");
            }
            if (!profile.isShowReportAtEnd() || !profile.isSendByEmail())
            {
                assessmentNode.SetAttribute("send-to-email", "");
            }
            else
            {
                if (profile.getEmail() == null || !profile.getEmail().Contains("@"))
                {
                    assessmentNode.SetAttribute("send-to-email", "");
                }
                else
                {
                    assessmentNode.SetAttribute("send-to-email", profile.getEmail());
                }
            }
            // add scorm attributes
            if (profile.isScorm12())
            {
                assessmentNode.SetAttribute("scorm12", "yes");
            }
            else
            {
                assessmentNode.SetAttribute("scorm12", "no");
            }
            if (profile.isScorm2004())
            {
                assessmentNode.SetAttribute("scorm2004", "yes");
            }
            else
            {
                assessmentNode.SetAttribute("scorm2004", "no");
            }
            //add the profile's name
            assessmentNode.SetAttribute("name", profile.getName());

            XmlElement smtpConfigNode = doc.CreateElement("smtp-config");

            smtpConfigNode.SetAttribute("smtp-ssl", (profile.isSmtpSSL() ? "yes" : "no"));
            smtpConfigNode.SetAttribute("smtp-server", profile.getSmtpServer());
            smtpConfigNode.SetAttribute("smtp-port", profile.getSmtpPort());
            smtpConfigNode.SetAttribute("smtp-user", profile.getSmtpUser());
            smtpConfigNode.SetAttribute("smtp-pwd", profile.getSmtpPwd());

            assessmentNode.AppendChild(smtpConfigNode);

            // Append the assessment rules
            foreach (AssessmentRule rule in rules)
            {
                if (rule is TimedAssessmentRule)
                {
                    TimedAssessmentRule tRule = (TimedAssessmentRule)rule;
                    //Create the rule node and set attributes
                    XmlElement ruleNode = doc.CreateElement("timed-assessment-rule");
                    ruleNode.SetAttribute("id", tRule.getId());
                    ruleNode.SetAttribute("importance", AssessmentRule.IMPORTANCE_VALUES[tRule.getImportance()]);
                    ruleNode.SetAttribute("usesEndConditions", (tRule.isUsesEndConditions() ? "yes" : "no"));
                    ruleNode.SetAttribute("repeatRule", (tRule.isRepeatRule() ? "yes" : "no"));

                    //Append concept
                    if (tRule.getConcept() != null && !tRule.getConcept().Equals(""))
                    {
                        XmlNode conceptNode = doc.CreateElement("concept");
                        conceptNode.AppendChild(doc.CreateTextNode(tRule.getConcept()));
                        ruleNode.AppendChild(conceptNode);
                    }

                    //Append conditions (always required at least one)
                    if (!tRule.getInitConditions().IsEmpty())
                    {
                        DOMWriterUtility.DOMWrite(ruleNode, tRule.getInitConditions(), DOMWriterUtility.Name(ConditionsDOMWriter.INIT_CONDITIONS));
                    }

                    //Append conditions (always required at least one)
                    if (!tRule.getEndConditions().IsEmpty())
                    {
                        DOMWriterUtility.DOMWrite(ruleNode, tRule.getEndConditions(), DOMWriterUtility.Name(ConditionsDOMWriter.END_CONDITIONS));
                    }

                    // Create effects
                    for (int i = 0; i < tRule.getEffectsCount(); i++)
                    {
                        //Create effect element and append it
                        XmlElement effectNode = doc.CreateElement("assessEffect");

                        // Append time attributes
                        effectNode.SetAttribute("time-min", tRule.getMinTime(i).ToString());
                        effectNode.SetAttribute("time-max", tRule.getMaxTime(i).ToString());

                        //Append set-text when appropriate
                        TimedAssessmentEffect currentEffect = tRule.getEffects()[i];
                        if (currentEffect.getText() != null && !currentEffect.getText().Equals(""))
                        {
                            XmlNode textNode = doc.CreateElement("set-text");
                            textNode.AppendChild(doc.CreateTextNode(currentEffect.getText()));
                            effectNode.AppendChild(textNode);
                        }
                        //Append properties
                        foreach (AssessmentProperty property in currentEffect.getAssessmentProperties())
                        {
                            XmlElement propertyElement = doc.CreateElement("set-property");
                            propertyElement.SetAttribute("id", property.getId());
                            propertyElement.SetAttribute("value", property.getValue().ToString());
                            effectNode.AppendChild(propertyElement);
                        }
                        //Append the effect
                        ruleNode.AppendChild(effectNode);
                    }

                    //Append the rule
                    assessmentNode.AppendChild(ruleNode);
                }
                else
                {
                    //Create the rule node and set attributes
                    XmlElement ruleNode = doc.CreateElement("assessment-rule");
                    ruleNode.SetAttribute("id", rule.getId());
                    ruleNode.SetAttribute("importance", AssessmentRule.IMPORTANCE_VALUES[rule.getImportance()]);
                    ruleNode.SetAttribute("repeatRule", (rule.isRepeatRule() ? "yes" : "no"));

                    //Append concept
                    if (rule.getConcept() != null && !rule.getConcept().Equals(""))
                    {
                        XmlNode conceptNode = doc.CreateElement("concept");
                        conceptNode.AppendChild(doc.CreateTextNode(rule.getConcept()));
                        ruleNode.AppendChild(conceptNode);
                    }

                    //Append conditions (always required at least one)
                    if (!rule.getConditions().IsEmpty())
                    {
                        DOMWriterUtility.DOMWrite(ruleNode, rule.getConditions());
                    }

                    //Create effect element and append it
                    XmlNode effectNode = doc.CreateElement("assessEffect");
                    //Append set-text when appropriate
                    if (rule.getText() != null && !rule.getText().Equals(""))
                    {
                        XmlNode textNode = doc.CreateElement("set-text");
                        textNode.AppendChild(doc.CreateTextNode(rule.getText()));
                        effectNode.AppendChild(textNode);
                    }
                    //Append properties
                    foreach (AssessmentProperty property in rule.getAssessmentProperties())
                    {
                        XmlElement propertyElement = doc.CreateElement("set-property");
                        propertyElement.SetAttribute("id", property.getId());
                        propertyElement.SetAttribute("value", property.getValue());
                        if (property.getVarName() != null)
                        {
                            propertyElement.SetAttribute("varName", property.getVarName());
                        }
                        effectNode.AppendChild(propertyElement);
                    }
                    //Append the effect
                    ruleNode.AppendChild(effectNode);

                    //Append the rule
                    assessmentNode.AppendChild(ruleNode);
                }
            }

            return(assessmentNode);
        }
Exemplo n.º 7
0
        protected override void FillNode(XmlNode node, object target, params IDOMWriterParam[] options)
        {
            var item = target as Item;

            XmlElement itemElement = node as XmlElement;


            // Create the necessary elements to create the DOM
            XmlDocument doc = Writer.GetDoc();

            // Create the root node
            itemElement.SetAttribute("id", item.getId());
            itemElement.SetAttribute("returnsWhenDragged", (item.isReturnsWhenDragged() ? "yes" : "no"));

            //v1.4
            if (item.getBehaviour() == Item.BehaviourType.NORMAL)
            {
                itemElement.SetAttribute("behaviour", "normal");
            }
            if (item.getBehaviour() == Item.BehaviourType.ATREZZO)
            {
                itemElement.SetAttribute("behaviour", "atrezzo");
            }
            if (item.getBehaviour() == Item.BehaviourType.FIRST_ACTION)
            {
                itemElement.SetAttribute("behaviour", "first-action");
            }
            itemElement.SetAttribute("resources-transition-time", item.getResourcesTransitionTime().ToString());
            //v1.4

            // Append the documentation (if avalaible)
            if (item.getDocumentation() != null)
            {
                XmlNode itemDocumentationNode = doc.CreateElement("documentation");
                itemDocumentationNode.AppendChild(doc.CreateTextNode(item.getDocumentation()));
                itemElement.AppendChild(itemDocumentationNode);
            }

            // Append the resources
            foreach (ResourcesUni resources in item.getResources())
            {
                XmlNode resourcesNode = ResourcesDOMWriter.buildDOM(resources, ResourcesDOMWriter.RESOURCES_ITEM);
                doc.ImportNode(resourcesNode, true);
                itemElement.AppendChild(resourcesNode);
            }

            foreach (Description description in item.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 and its soundPaths
                XmlElement nameNode = doc.CreateElement("name");

                if (description.getNameSoundPath() != null && !description.getNameSoundPath().Equals(""))
                {
                    nameNode.SetAttribute("soundPath", description.getNameSoundPath());
                }
                nameNode.AppendChild(doc.CreateTextNode(description.getName()));
                descriptionNode.AppendChild(nameNode);

                XmlElement briefNode = doc.CreateElement("brief");
                if (description.getDescriptionSoundPath() != null && !description.getDescriptionSoundPath().Equals(""))
                {
                    briefNode.SetAttribute("soundPath", description.getDescriptionSoundPath());
                }
                briefNode.AppendChild(doc.CreateTextNode(description.getDescription()));
                descriptionNode.AppendChild(briefNode);

                XmlElement detailedNode = doc.CreateElement("detailed");
                if (description.getDetailedDescriptionSoundPath() != null &&
                    !description.getDetailedDescriptionSoundPath().Equals(""))
                {
                    detailedNode.SetAttribute("soundPath", description.getDetailedDescriptionSoundPath());
                }
                detailedNode.AppendChild(doc.CreateTextNode(description.getDetailedDescription()));
                descriptionNode.AppendChild(detailedNode);

                // Append the description
                itemElement.AppendChild(descriptionNode);
            }

            // Append the actions (if there is at least one)
            if (item.getActions().Count > 0)
            {
                // Create the actions node
                DOMWriterUtility.DOMWrite(itemElement, item.getActions());
            }
        }
Exemplo n.º 8
0
        /**
         * Returns the DOM element for the chapter
         *
         * @param chapter
         *            Chapter data to be written
         * @return DOM element with the chapter data
         */

        protected override void FillNode(XmlNode node, object target, params IDOMWriterParam[] options)
        {
            var        chapter     = target as Chapter;
            var        doc         = Writer.GetDoc();
            XmlElement chapterNode = node as XmlElement;

            //try {
            // Create the necessary elements to create the DOM

            /*DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance( );
             * DocumentBuilder db = dbf.newDocumentBuilder( );
             * Document doc = db.newDocument( );
             */

            // Add the adaptation and assessment active profiles
            if (!chapter.getAdaptationName().Equals(""))
            {
                chapterNode.SetAttribute("adaptProfile", chapter.getAdaptationName());
            }

            // Create and append the assessment configuration
            if (!chapter.getAssessmentName().Equals(""))
            {
                chapterNode.SetAttribute("assessProfile", chapter.getAssessmentName());
            }

            var targetParam = ChapterTargetID(chapter.getTargetId());

            /*
             * // Append the scene elements
             * foreach (Scene scene in chapter.getScenes())
             * {
             *  DOMWriterUtility.DOMWrite(chapterNode, scene, targetParam);
             * }
             *
             * // Append the cutscene elements
             * foreach (Cutscene cutscene in chapter.getCutscenes())
             * {
             *  DOMWriterUtility.DOMWrite(chapterNode, cutscene, targetParam);
             * }
             *
             * // Append the book elements
             * foreach (Book book in chapter.getBooks())
             * {
             *  DOMWriterUtility.DOMWrite(chapterNode, book, targetParam);
             * }
             *
             * // Append the item elements
             * foreach (Item item in chapter.getItems())
             * {
             *  DOMWriterUtility.DOMWrite(chapterNode, item, targetParam);
             * }
             *
             *
             * // Append the character element
             * foreach (NPC character in chapter.getCharacters())
             * {
             *  DOMWriterUtility.DOMWrite(chapterNode, character, targetParam);
             * }
             *
             * // Append the conversation element
             * foreach (Conversation conversation in chapter.getConversations())
             * {
             *  DOMWriterUtility.DOMWrite(chapterNode, conversation, targetParam);
             * }
             *
             * // Append the timers
             * foreach (Timer timer in chapter.getTimers())
             * {
             *  DOMWriterUtility.DOMWrite(chapterNode, timer, targetParam);
             * }
             *
             * // Append global states
             * foreach (GlobalState globalState in chapter.getGlobalStates())
             * {
             *  DOMWriterUtility.DOMWrite(chapterNode, globalState, targetParam);
             * }
             *
             * // Append macros
             * foreach (Macro macro in chapter.getMacros())
             * {
             *  DOMWriterUtility.DOMWrite(chapterNode, macro, targetParam);
             * }
             *
             * // Append the atrezzo item elements
             * foreach (Atrezzo atrezzo in chapter.getAtrezzo())
             * {
             *  DOMWriterUtility.DOMWrite(chapterNode, atrezzo, targetParam);
             * }
             *
             * // Append the completables
             * foreach (Completable completable in chapter.getCompletabes())
             * {
             *  DOMWriterUtility.DOMWrite(chapterNode, completable, targetParam);
             * }
             */
            /*} catch( ParserConfigurationException e ) {
             *  ReportDialog.GenerateErrorReport(e, true, "UNKNOWERROR");
             * }*/

            // Append the player element
            DOMWriterUtility.DOMWrite(chapterNode, chapter.getPlayer(), targetParam);

            foreach (var type in chapter.getObjectTypes())
            {
                foreach (var tosave in chapter.getObjects(type))
                {
                    DOMWriterUtility.DOMWrite(chapterNode, tosave, targetParam);
                }
            }


            // TODO FIX THIS and use normal domwriter

            /** ******* START WRITING THE ADAPTATION DATA ***** */
            foreach (AdaptationProfile profile in chapter.getAdaptationProfiles())
            {
                chapterNode.AppendChild(Writer.writeAdaptationData(profile, true, doc));
            }
            /** ******* END WRITING THE ADAPTATION DATA ***** */

            /** ******* START WRITING THE ASSESSMENT DATA ***** */
            foreach (AssessmentProfile profile in chapter.getAssessmentProfiles())
            {
                chapterNode.AppendChild(Writer.writeAssessmentData(profile, true, doc));
            }
            /** ******* END WRITING THE ASSESSMENT DATA ***** */
        }
Exemplo n.º 9
0
        /**
         * Writes the daventure data into the given file.
         *
         * @param folderName
         *            Folder where to write the data
         * @param adventureData
         *            Adventure data to write in the file
         * @param valid
         *            True if the adventure is valid (can be executed in the
         *            engine), false otherwise
         * @return True if the operation was succesfully completed, false otherwise
         */

        public static bool writeData(string folderName, AdventureDataControl adventureData, bool valid)
        {
            bool dataSaved = false;

            // Create the necessary elements for building the DOM
            doc = new XmlDocument();

            // Delete the previous XML files in the root of the project dir
            //DirectoryInfo projectFolder = new DirectoryInfo(folderName);
            //if (projectFolder.Exists)
            //{
            //    foreach (FileInfo file in projectFolder.GetFiles())
            //    {
            //        file.Delete();
            //    }
            //    foreach (DirectoryInfo dir in projectFolder.GetDirectories())
            //    {
            //        dir.Delete(true);
            //    }
            //}

            // Add the special asset files
            // TODO AssetsController.addSpecialAssets();

            /** ******* START WRITING THE DESCRIPTOR ********* */
            // Pick the main node for the descriptor
            XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", "no");

            //XmlDocumentType typeDescriptor = doc.CreateDocumentType("game-descriptor", "SYSTEM", "descriptor.dtd", null);
            doc.AppendChild(declaration);
            //doc.AppendChild(typeDescriptor);

            if (!valid)
            {
                DOMWriterUtility.DOMWrite(doc, adventureData, new DescriptorDOMWriter.InvalidAdventureDataControlParam());
            }
            else
            {
                DOMWriterUtility.DOMWrite(doc, adventureData);
            }

            doc.Save(folderName + "/descriptor.xml");
            /** ******** END WRITING THE DESCRIPTOR ********** */

            /** ******* START WRITING THE CHAPTERS ********* */
            // Write every chapter
            //XmlDocumentType typeChapter;

            int chapterIndex = 1;

            foreach (Chapter chapter in adventureData.getChapters())
            {
                doc         = new XmlDocument();
                declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", "no");
                //typeChapter = doc.CreateDocumentType("eAdventure", "SYSTEM", "eadventure.dtd", null);
                doc.AppendChild(declaration);
                //doc.AppendChild(typeChapter);

                DOMWriterUtility.DOMWrite(doc, chapter);

                doc.Save(folderName + "/chapter" + chapterIndex++ + ".xml");
            }
            /** ******** END WRITING THE CHAPTERS ********** */

            /** ******* START WRITING THE METADATA ********* */

            // Pick the main node for the descriptor
            var metadata = adventureData.getImsCPMetadata();

            if (metadata != null)
            {
                var xmlMetadata = SerializeToXmlElement(new XmlDocument(), metadata);
                doc         = new XmlDocument();
                xmlMetadata = MetadataUtility.CleanXMLGarbage(doc, xmlMetadata);
                doc.AppendChild(xmlMetadata);
                doc.Save(folderName + "/imscpmetadata.xml");
            }
            /** ******** END WRITING THE CHAPTERS ********** */
            dataSaved = true;
            return(dataSaved);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Fills the descriptor node with the addventure data control data
        /// </summary>
        /// <param name="node"></param>
        /// <param name="target"></param>
        /// <param name="options">InvalidAdventureDataControlParam is accepted</param>
        protected override void FillNode(XmlNode node, object target, params IDOMWriterParam[] options)
        {
            var adventureData = target as AdventureDataControl;

            // Create the necessary elements to create the DOM
            XmlDocument doc = Writer.GetDoc();

            // Create the root node
            ((XmlElement)node).SetAttribute("versionNumber", adventureData.getAdventureData().getVersionNumber());

            // Create and append the title
            XmlNode adventureTitleNode = doc.CreateElement("title");

            adventureTitleNode.AppendChild(doc.CreateTextNode(adventureData.getTitle()));
            node.AppendChild(adventureTitleNode);

            // Create and append the description
            XmlNode adventureDescriptionNode = doc.CreateElement("description");

            adventureDescriptionNode.AppendChild(doc.CreateTextNode(adventureData.getDescription()));
            node.AppendChild(adventureDescriptionNode);

            // Create and append the "invalid" tag (if necessary)
            var invalid = options.Any(option => option is InvalidAdventureDataControlParam);

            if (invalid)
            {
                node.AppendChild(doc.CreateElement("invalid"));
            }

            // Automatic commentaries
            if (adventureData.isCommentaries())
            {
                node.AppendChild(doc.CreateElement("automatic-commentaries"));
            }

            // Create and append the configuration
            XmlElement configurationNode = doc.CreateElement("configuration");

            // Keep Showing
            var keepShowingValue = adventureData.isKeepShowing() ? "yes" : "no";

            configurationNode.SetAttribute("keepShowing", keepShowingValue);

            // Keyboard Navigation
            var keyboardNavigationValue = adventureData.isKeepShowing() ? "enabled" : "disabled";

            configurationNode.SetAttribute("keyboard-navigation", keyboardNavigationValue);

            // Default click action
            switch (adventureData.getDefaultClickAction())
            {
            case DescriptorData.DefaultClickAction.SHOW_DETAILS:
                configurationNode.SetAttribute("defaultClickAction", "showDetails");
                break;

            case DescriptorData.DefaultClickAction.SHOW_ACTIONS:
                configurationNode.SetAttribute("defaultClickAction", "showActions");
                break;
            }

            // Perspective
            switch (adventureData.getPerspective())
            {
            case DescriptorData.Perspective.REGULAR:
                configurationNode.SetAttribute("perspective", "regular");
                break;

            case DescriptorData.Perspective.ISOMETRIC:
                configurationNode.SetAttribute("perspective", "isometric");
                break;
            }

            // Drag Behaviour
            switch (adventureData.getDragBehaviour())
            {
            case DescriptorData.DragBehaviour.IGNORE_NON_TARGETS:
                configurationNode.SetAttribute("dragBehaviour", "ignoreNonTargets");
                break;

            default:     // CONSIDER_NON_TARGETS
                configurationNode.SetAttribute("dragBehaviour", "considerNonTargets");
                break;
            }

            // GUI Element
            XmlElement guiElement = doc.CreateElement("gui");

            switch (adventureData.getGUIType())
            {
            case DescriptorData.GUI_TRADITIONAL:
                guiElement.SetAttribute("type", "ignoreNonTargets");
                break;

            default:     // GUI CONTEXTUAL
                guiElement.SetAttribute("type", "contextual");
                break;
            }

            // Inventory Position
            switch (adventureData.getInventoryPosition())
            {
            case DescriptorData.INVENTORY_NONE:
                guiElement.SetAttribute("inventoryPosition", "none");
                break;

            case DescriptorData.INVENTORY_TOP_BOTTOM:
                guiElement.SetAttribute("inventoryPosition", "top_bottom");
                break;

            case DescriptorData.INVENTORY_TOP:
                guiElement.SetAttribute("inventoryPosition", "top");
                break;

            case DescriptorData.INVENTORY_BOTTOM:
                guiElement.SetAttribute("inventoryPosition", "bottom");
                break;

            case DescriptorData.INVENTORY_FIXED_TOP:
                guiElement.SetAttribute("inventoryPosition", "fixed_top");
                break;

            case DescriptorData.INVENTORY_FIXED_BOTTOM:
                guiElement.SetAttribute("inventoryPosition", "fixed_bottom");
                break;
            }

            // Cursors
            if (adventureData.getCursors().Count > 0)
            {
                XmlNode cursorsNode = doc.CreateElement("cursors");
                foreach (CustomCursor cursor in adventureData.getCursors())
                {
                    XmlElement currentCursor = doc.CreateElement("cursor");
                    currentCursor.SetAttribute("type", cursor.getType());
                    currentCursor.SetAttribute("uri", cursor.getPath());
                    cursorsNode.AppendChild(currentCursor);
                }
                guiElement.AppendChild(cursorsNode);
            }

            // Buttons
            if (adventureData.getButtons().Count > 0)
            {
                XmlNode buttonsNode = doc.CreateElement("buttons");

                foreach (CustomButton button in adventureData.getButtons())
                {
                    XmlElement currentButton = doc.CreateElement("button");
                    currentButton.SetAttribute("action", button.getAction());
                    currentButton.SetAttribute("type", button.getType());
                    currentButton.SetAttribute("uri", button.getPath());
                    buttonsNode.AppendChild(currentButton);
                }
                guiElement.AppendChild(buttonsNode);
            }

            // Arrows
            if (adventureData.getArrows().Count > 0)
            {
                XmlNode arrowNode = doc.CreateElement("arrows");

                foreach (CustomArrow arrow in adventureData.getArrows())
                {
                    XmlElement currentArrow = doc.CreateElement("arrow");
                    currentArrow.SetAttribute("type", arrow.getType());
                    currentArrow.SetAttribute("uri", arrow.getPath());
                    arrowNode.AppendChild(currentArrow);
                }
                guiElement.AppendChild(arrowNode);
            }

            configurationNode.AppendChild(guiElement);

            //Player mode element
            XmlElement playerModeElement   = doc.CreateElement("mode");
            var        isPlayerTransparent = adventureData.getPlayerMode() == DescriptorData.MODE_PLAYER_1STPERSON;

            playerModeElement.SetAttribute("playerTransparent", isPlayerTransparent ? "yes" : "no");
            configurationNode.AppendChild(playerModeElement);

            //Graphic config element
            XmlElement graphicConfigElement = doc.CreateElement("graphics");
            var        graphicsMode         = "fullscreen"; // GRAPHICS_FULLSCREEN

            switch (adventureData.getGraphicConfig())
            {
            case DescriptorData.GRAPHICS_WINDOWED: graphicsMode = "windowed"; break;

            case DescriptorData.GRAPHICS_BLACKBKG: graphicsMode = "blackbkg"; break;
            }
            graphicConfigElement.SetAttribute("mode", graphicsMode);

            configurationNode.AppendChild(graphicConfigElement);


            // Keep Showing
            var autoSave = adventureData.isAutoSave() ? "yes" : "no";

            configurationNode.SetAttribute("autosave", autoSave);

            // Keep Showing
            var saveOnSuspend = adventureData.isSaveOnSuspend() ? "yes" : "no";

            configurationNode.SetAttribute("save-on-suspend", saveOnSuspend);

            //Append configurationNode
            node.AppendChild(configurationNode);

            // Create and add the contents with the chapters
            XmlNode contentsNode = doc.CreateElement("contents");
            int     chapterIndex = 1;

            foreach (Chapter chapter in adventureData.getChapters())
            {
                // Create the chapter and add the path to it
                XmlElement chapterElement = doc.CreateElement("chapter");
                chapterElement.SetAttribute("path", "chapter" + chapterIndex++ + ".xml");

                // Create and append the title
                XmlNode chapterTitleNode = doc.CreateElement("title");
                chapterTitleNode.AppendChild(doc.CreateTextNode(chapter.getTitle()));
                chapterElement.AppendChild(chapterTitleNode);

                // Create and append the description
                XmlNode chapterDescriptionNode = doc.CreateElement("description");
                chapterDescriptionNode.AppendChild(doc.CreateTextNode(chapter.getDescription()));
                chapterElement.AppendChild(chapterDescriptionNode);

                // Store the node
                contentsNode.AppendChild(chapterElement);
            }


            // Extension Objects
            XmlNode extensionObjects = doc.CreateElement("extension-objects");

            foreach (var type in adventureData.getAdventureData().getObjectTypes())
            {
                foreach (var tosave in adventureData.getAdventureData().getObjects(type))
                {
                    DOMWriterUtility.DOMWrite(extensionObjects, tosave, options);
                }
            }
            node.AppendChild(extensionObjects);

            // Store the chapters in the descriptor
            node.AppendChild(contentsNode);
        }
Exemplo n.º 11
0
        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");
            sceneElement.SetAttribute("allowsSavingGame", scene.allowsSavingGame() ? "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());
            }
        }
Exemplo n.º 12
0
        /**
         * Writes the daventure data into the given file.
         *
         * @param folderName
         *            Folder where to write the data
         * @param adventureData
         *            Adventure data to write in the file
         * @param valid
         *            True if the adventure is valid (can be executed in the
         *            engine), false otherwise
         * @return True if the operation was succesfully completed, false otherwise
         */

        public static bool writeData(string folderName, AdventureDataControl adventureData, bool valid)
        {
            bool dataSaved = false;

            // Create the necessary elements for building the DOM
            doc = new XmlDocument();

            // Delete the previous XML files in the root of the project dir
            //DirectoryInfo projectFolder = new DirectoryInfo(folderName);
            //if (projectFolder.Exists)
            //{
            //    foreach (FileInfo file in projectFolder.GetFiles())
            //    {
            //        file.Delete();
            //    }
            //    foreach (DirectoryInfo dir in projectFolder.GetDirectories())
            //    {
            //        dir.Delete(true);
            //    }
            //}

            // Add the special asset files
            // TODO AssetsController.addSpecialAssets();

            /** ******* START WRITING THE DESCRIPTOR ********* */
            // Pick the main node for the descriptor
            XmlDeclaration  declaration    = doc.CreateXmlDeclaration("1.0", "UTF-8", "no");
            XmlDocumentType typeDescriptor = doc.CreateDocumentType("game-descriptor", "SYSTEM", "descriptor.dtd", null);

            doc.AppendChild(declaration);
            doc.AppendChild(typeDescriptor);

            if (!valid)
            {
                DOMWriterUtility.DOMWrite(doc, adventureData, new DescriptorDOMWriter.InvalidAdventureDataControlParam());
            }
            else
            {
                DOMWriterUtility.DOMWrite(doc, adventureData);
            }

            // TODO re-add indentation
            //indentDOM(mainNode, 0);

            // Create the necessary elements for export the DOM into a XML file
            //transformer = tFactory.newTransformer();
            //transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "descriptor.dtd");

            // Create the output buffer, write the DOM and close it
            //fout = new FileOutputStream(folderName + "/descriptor.xml");
            //writeFile = new OutputStreamWriter(fout, "UTF-8");
            //transformer.transform(new DOMSource(doc), new StreamResult(writeFile));
            //writeFile.close();
            //fout.close();
            doc.Save(folderName + "/descriptor.xml");
            /** ******** END WRITING THE DESCRIPTOR ********** */

            /** ******* START WRITING THE CHAPTERS ********* */
            // Write every chapter
            XmlDocumentType typeChapter;

            int chapterIndex = 1;

            foreach (Chapter chapter in adventureData.getChapters())
            {
                doc         = new XmlDocument();
                declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", "no");
                typeChapter = doc.CreateDocumentType("eAdventure", "SYSTEM", "eadventure.dtd", null);
                doc.AppendChild(declaration);
                doc.AppendChild(typeChapter);
                // Pick the main node of the chapter

                // TODO FIX THIS and use normal domwriter

                var chapterwriter = new ChapterDOMWriter();

                DOMWriterUtility.DOMWrite(doc, chapter);

                // TODO re-add indentation
                //indentDOM(mainNode, 0);

                //TODO: testing
                //doc = new XmlDocument();

                // Create the necessary elements for export the DOM into a XML file
                //transformer = tFactory.newTransformer();
                //transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "eadventure.dtd");

                // Create the output buffer, write the DOM and close it
                //fout = new FileOutputStream(folderName + "/chapter" + chapterIndex++ + ".xml");
                //writeFile = new OutputStreamWriter(fout, "UTF-8");
                //transformer.transform(new DOMSource(doc), new StreamResult(writeFile));
                //writeFile.close();
                //fout.close();

                doc.Save(folderName + "/chapter" + chapterIndex++ + ".xml");
            }
            /** ******** END WRITING THE CHAPTERS ********** */

            // Update the zip files
            //File.umount( );
            dataSaved = true;
            return(dataSaved);
        }
Exemplo n.º 13
0
        protected override void FillNode(XmlNode node, object target, params IDOMWriterParam[] options)
        {
            var cutscene        = target as Cutscene;
            var cutsceneElement = node as XmlElement;

            // Create the necessary elements to create the DOM
            XmlDocument doc = Writer.GetDoc();

            // Create the root node
            if (cutscene.getType() == GeneralScene.GeneralSceneSceneType.VIDEOSCENE)
            {
                if (((Videoscene)cutscene).isCanSkip())
                {
                    cutsceneElement.SetAttribute("canSkip", "yes");
                }
                else
                {
                    cutsceneElement.SetAttribute("canSkip", "no");
                }
            }

            // Set the attributes
            cutsceneElement.SetAttribute("id", cutscene.getId());


            if (options.Any(o => o is CIP && (o as CIP).TargetId.Equals(cutscene.getId())))
            {
                cutsceneElement.SetAttribute("start", "yes");
            }
            else
            {
                cutsceneElement.SetAttribute("start", "no");
            }

            if (cutscene.getNext() == Cutscene.NEWSCENE)
            {
                cutsceneElement.SetAttribute("idTarget", cutscene.getTargetId());

                cutsceneElement.SetAttribute("destinyX", cutscene.getPositionX().ToString());
                cutsceneElement.SetAttribute("destinyY", cutscene.getPositionY().ToString());

                cutsceneElement.SetAttribute("transitionTime", cutscene.getTransitionTime().ToString());
                cutsceneElement.SetAttribute("transitionType", ((int)cutscene.getTransitionType()).ToString());
            }

            if (cutscene.getNext() == Cutscene.GOBACK)
            {
                cutsceneElement.SetAttribute("next", "go-back");
            }
            else if (cutscene.getNext() == Cutscene.ENDCHAPTER)
            {
                cutsceneElement.SetAttribute("next", "end-chapter");
            }
            else if (cutscene.getNext() == Cutscene.NEWSCENE)
            {
                cutsceneElement.SetAttribute("next", "new-scene");
            }

            cutsceneElement.SetAttribute("class", cutscene.getXApiClass());
            cutsceneElement.SetAttribute("type", cutscene.getXApiType());

            // Append the documentation (if avalaible)
            if (cutscene.getDocumentation() != null)
            {
                XmlNode cutsceneDocumentationNode = doc.CreateElement("documentation");
                cutsceneDocumentationNode.AppendChild(doc.CreateTextNode(cutscene.getDocumentation()));
                cutsceneElement.AppendChild(cutsceneDocumentationNode);
            }

            if (!cutscene.getEffects().isEmpty())
            {
                DOMWriterUtility.DOMWrite(cutsceneElement, cutscene.getEffects());
            }

            // Append the resources
            foreach (ResourcesUni resources in cutscene.getResources())
            {
                XmlNode resourcesNode = ResourcesDOMWriter.buildDOM(resources, ResourcesDOMWriter.RESOURCES_CUTSCENE);
                doc.ImportNode(resourcesNode, true);
                cutsceneElement.AppendChild(resourcesNode);
            }

            // Append the name
            XmlNode nameNode = doc.CreateElement("name");

            nameNode.AppendChild(doc.CreateTextNode(cutscene.getName()));
            cutsceneElement.AppendChild(nameNode);
        }
Exemplo n.º 14
0
        /**
         * Recursive function responsible for transforming a node (and its children)
         * into a DOM structure
         *
         * @param currentNode
         *            Node to be transformed
         * @param rootDOMNode
         *            DOM node in which the elements must be attached
         */

        private static void WriteNodeInDom(ConversationNode currentNode, XmlNode rootDOMNode, params IDOMWriterParam[] options)
        {
            // Extract the document
            XmlDocument document = rootDOMNode.OwnerDocument;

            // If the node is a DialogueNode write the lines one after another, and then the child (or the mark if it is no
            // child)
            if (currentNode is DialogueConversationNode)
            {
                // For each line of the node
                for (int i = 0; i < currentNode.getLineCount(); i++)
                {
                    // Create a phrase element, and extract the actual text line
                    XmlElement       phrase;
                    ConversationLine line = currentNode.getLine(i);

                    // If the line belongs to the player, create a "speak-player" element. Otherwise, if it belongs to a
                    // NPC,
                    // create a "speak-char" element, which will have an attribute "idTarget" with the name of the
                    // non-playable character,
                    // if there is no name the attribute won't be written
                    if (line.isPlayerLine())
                    {
                        phrase = document.CreateElement("speak-player");
                    }
                    else
                    {
                        phrase = document.CreateElement("speak-char");
                        if (!line.getName().Equals("NPC"))
                        {
                            phrase.SetAttribute("idTarget", line.getName());
                        }
                    }

                    // Add the line text into the element
                    var text = document.CreateElement("text");
                    text.InnerText = line.getText();
                    phrase.AppendChild(text);

                    // Append the resources
                    foreach (ResourcesUni resources in line.getResources())
                    {
                        XmlNode resourcesNode = ResourcesDOMWriter.buildDOM(resources, ResourcesDOMWriter.RESOURCES_CONVERSATION_LINE);
                        document.ImportNode(resourcesNode, true);
                        phrase.AppendChild(resourcesNode);
                    }

                    // Add the element to the DOM root
                    rootDOMNode.AppendChild(phrase);

                    // Create conditions for current effect
                    DOMWriterUtility.DOMWrite(rootDOMNode, line.getConditions(), options);
                }

                // Check if the node is terminal
                if (currentNode.isTerminal())
                {
                    // If it is terminal add a "end-conversation" element
                    XmlElement endConversation = document.CreateElement("end-conversation");

                    // Add the "end-conversation" tag into the root
                    rootDOMNode.AppendChild(endConversation);

                    // If the terminal node has an effect, include it into the DOM
                    if (currentNode.hasEffects())
                    {
                        DOMWriterUtility.DOMWrite(endConversation, currentNode.getEffects(), options);
                    }
                }
                else
                {
                    // If the node isn't terminal, check if it performing a "go-back" (going back to the inmediatly upper
                    // OptionNode)
                    if (TreeConversation.thereIsGoBackTag(currentNode))
                    {
                        // If it is the case, add a "go-back" element
                        rootDOMNode.AppendChild(document.CreateElement("go-back"));
                    }
                    else
                    {
                        // Otherwise, if the node has a child, call the recursive function with the child node, and the same
                        // DOM root node
                        WriteNodeInDom(currentNode.getChild(0), rootDOMNode);
                    }
                }
            }

            // If the node is a OptionNode write a "response" element, and inside it a "option" element with its content
            else if (currentNode is OptionConversationNode)
            {
                // Create the "response" element
                XmlElement response = document.CreateElement("response");
                // Adds a random attribute if "random" is activate in conversation node data
                if (((OptionConversationNode)currentNode).isRandom())
                {
                    response.SetAttribute("random", "yes");
                }
                // For each line of the node (we suppose the number of line equals the number of links, or children nodes)
                for (int i = 0; i < currentNode.getLineCount(); i++)
                {
                    // Create the "option" element
                    XmlElement       optionElement = document.CreateElement("option");
                    ConversationLine line          = currentNode.getLine(i);
                    // Create the actual option (a "speak-player" element) and add its respective text
                    XmlElement lineElement = document.CreateElement("speak-player");

                    var text = document.CreateElement("text");
                    text.InnerText = currentNode.getLine(i).getText();
                    lineElement.AppendChild(text);

                    // Append the resources
                    foreach (ResourcesUni resources in line.getResources())
                    {
                        XmlNode resourcesNode = ResourcesDOMWriter.buildDOM(resources, ResourcesDOMWriter.RESOURCES_CONVERSATION_LINE);
                        document.ImportNode(resourcesNode, true);
                        lineElement.AppendChild(resourcesNode);
                    }

                    // Insert the text line in the option node
                    optionElement.AppendChild(lineElement);

                    // Call the recursive function, to write in the "option" node the appropiate elements
                    // Note that the root DOM node is the "option" element
                    WriteNodeInDom(currentNode.getChild(i), optionElement);

                    // Add the "option" element
                    response.AppendChild(optionElement);
                }
                // If the terminal node has an effect, include it into the DOM
                if (currentNode.hasEffects())
                {
                    DOMWriterUtility.DOMWrite(response, currentNode.getEffects(), options);
                }

                // Add the element
                rootDOMNode.AppendChild(response);
            }
        }
Exemplo n.º 15
0
        private void FillNode(XmlNode toFill, GraphConversation graphConversation, params IDOMWriterParam[] options)
        {
            XmlElement conversationElement = toFill as XmlElement;

            // Get the complete node list
            List <ConversationNode> nodes = graphConversation.getAllNodes();

            // Create the necessary elements to create the DOM
            XmlDocument doc = Writer.GetDoc();

            // Create the root node
            conversationElement.SetAttribute("id", graphConversation.getId());

            // For each node
            for (int i = 0; i < nodes.Count; i++)
            {
                ConversationNode node = nodes[i];

                XmlElement nodeElement            = null;
                var        dialogConversationNode = node as DialogueConversationNode;

                // If the node is a dialogue node
                if (dialogConversationNode != null)
                {
                    // Create the node element and set the nodeindex
                    nodeElement = doc.CreateElement("dialogue-node");
                    nodeElement.SetAttribute("nodeindex", i.ToString());
                    // Adds a random attribute if "keepShowing" is activate in conversation node data
                    if (dialogConversationNode.isKeepShowing())
                    {
                        nodeElement.SetAttribute("keepShowing", "yes");
                    }
                    if (node.getEditorX() != -1)
                    {
                        nodeElement.SetAttribute("editor-x", node.getEditorX().ToString());
                    }
                    if (node.getEditorY() != -1)
                    {
                        nodeElement.SetAttribute("editor-y", node.getEditorY().ToString());
                    }
                    if (node.getEditorCollapsed())
                    {
                        nodeElement.SetAttribute("editor-collapsed", "yes");
                    }
                    // For each line of the node
                    for (int j = 0; j < node.getLineCount(); j++)
                    {
                        // Create a phrase element, and extract the actual text line
                        XmlElement       phrase;
                        ConversationLine line = node.getLine(j);

                        // If the line belongs to the player, create a "speak-player" element. Otherwise, if it belongs
                        // to a NPC,
                        // create a "speak-char" element, which will have an attribute "idTarget" with the name of the
                        // non-playable character,
                        // if there is no name the attribute won't be written
                        if (line.isPlayerLine())
                        {
                            phrase = doc.CreateElement("speak-player");
                        }
                        else
                        {
                            phrase = doc.CreateElement("speak-char");
                            if (!line.getName().Equals("NPC"))
                            {
                                phrase.SetAttribute("idTarget", line.getName());
                            }
                        }

                        // Append the resources
                        foreach (ResourcesUni resources in line.getResources())
                        {
                            XmlNode resourcesNode = ResourcesDOMWriter.buildDOM(resources, ResourcesDOMWriter.RESOURCES_CONVERSATION_LINE);
                            doc.ImportNode(resourcesNode, true);
                            phrase.AppendChild(resourcesNode);
                        }

                        // Add the line text into the element

                        var text = doc.CreateElement("text");
                        text.InnerText = line.getText();
                        phrase.AppendChild(text);

                        // Add the element to the node
                        nodeElement.AppendChild(phrase);

                        // Create conditions for current effect
                        DOMWriterUtility.DOMWrite(nodeElement, line.getConditions(), options);
                    }

                    // Check if the node is terminal
                    if (node.isTerminal())
                    {
                        // If it is terminal add a "end-conversation" element
                        XmlElement endConversation = doc.CreateElement("end-conversation");

                        // If the terminal node has an effect, include it into the DOM
                        if (node.hasEffects())
                        {
                            DOMWriterUtility.DOMWrite(endConversation, node.getEffects(), options);
                        }

                        // Add the "end-conversation" tag into the node
                        nodeElement.AppendChild(endConversation);
                    }
                    else
                    {
                        // Otherwise, if the node has a child, add the element
                        XmlElement childElement = doc.CreateElement("child");

                        // Add the number of the child node (index of the node in the structure)
                        childElement.SetAttribute("nodeindex", nodes.IndexOf(node.getChild(0)).ToString());

                        // Insert the tag into the node
                        nodeElement.AppendChild(childElement);

                        // If the terminal node has an effect, include it into the DOM
                        if (node.hasEffects())
                        {
                            DOMWriterUtility.DOMWrite(nodeElement, node.getEffects(), options);
                        }
                    }
                }

                var optionConversationNode = node as OptionConversationNode;
                // If the node is a option node
                if (optionConversationNode != null)
                {
                    // Create the node element and set the nodeindex
                    nodeElement = doc.CreateElement("option-node");
                    nodeElement.SetAttribute("nodeindex", i.ToString());

                    if (!string.IsNullOrEmpty(optionConversationNode.getXApiQuestion()))
                    {
                        nodeElement.SetAttribute("question", optionConversationNode.getXApiQuestion());
                    }

                    // Adds a random attribute if "random" is activate in conversation node data
                    if (optionConversationNode.isRandom())
                    {
                        nodeElement.SetAttribute("random", "yes");
                    }
                    // Adds a random attribute if "keepShowing" is activate in conversation node data
                    if (optionConversationNode.isKeepShowing())
                    {
                        nodeElement.SetAttribute("keepShowing", "yes");
                    }
                    // Adds a random attribute if "showUserOption" is activate in conversation node data
                    if (optionConversationNode.isShowUserOption())
                    {
                        nodeElement.SetAttribute("showUserOption", "yes");
                    }
                    // Adds a random attribute if "preListening" is activate in conversation node data
                    if (optionConversationNode.isPreListening())
                    {
                        nodeElement.SetAttribute("preListening", "yes");
                    }
                    if (optionConversationNode.MaxElemsPerRow != -1)
                    {
                        nodeElement.SetAttribute("max-elements-per-row", optionConversationNode.MaxElemsPerRow.ToString());
                    }
                    if (optionConversationNode.Alignment != TextAnchor.UpperCenter)
                    {
                        nodeElement.SetAttribute("alignment", optionConversationNode.Alignment.ToString());
                    }
                    if (optionConversationNode.Horizontal)
                    {
                        nodeElement.SetAttribute("horizontal", "yes");
                    }
                    if (node.getEditorX() != -1)
                    {
                        nodeElement.SetAttribute("editor-x", node.getEditorX().ToString());
                    }
                    if (node.getEditorY() != -1)
                    {
                        nodeElement.SetAttribute("editor-y", node.getEditorY().ToString());
                    }
                    if (node.getEditorCollapsed())
                    {
                        nodeElement.SetAttribute("editor-collapsed", "yes");
                    }
                    // Adds the x position of the options conversations node
                    nodeElement.SetAttribute("x", optionConversationNode.getEditorX().ToString());
                    // Adds a random attribute if "preListening" is activate in conversation node data
                    nodeElement.SetAttribute("y", optionConversationNode.getEditorY().ToString());

                    // For each line of the node
                    for (int j = 0; j < node.getLineCount(); j++)
                    {
                        // Take the current conversation line
                        ConversationLine line = node.getLine(j);

                        // Create the actual option (a "speak-player" element) and add its respective text
                        XmlElement lineElement = doc.CreateElement("speak-player");

                        var text = doc.CreateElement("text");
                        text.InnerText = node.getLine(j).getText();
                        lineElement.AppendChild(text);

                        // Append the resources
                        foreach (ResourcesUni resources in line.getResources())
                        {
                            XmlNode resourcesNode = ResourcesDOMWriter.buildDOM(resources, ResourcesDOMWriter.RESOURCES_CONVERSATION_LINE);
                            doc.ImportNode(resourcesNode, true);
                            lineElement.AppendChild(resourcesNode);
                        }

                        if (line.getXApiCorrect())
                        {
                            lineElement.SetAttribute("correct", line.getXApiCorrect().ToString().ToLower());
                        }

                        // Create a child tag, and set it the index of the child
                        XmlElement childElement = doc.CreateElement("child");
                        childElement.SetAttribute("nodeindex", nodes.IndexOf(node.getChild(j)).ToString());


                        // Insert the text line in the option node
                        nodeElement.AppendChild(lineElement);
                        // Add conditions associated to that effect
                        DOMWriterUtility.DOMWrite(nodeElement, line.getConditions(), options);
                        // Insert child tag
                        nodeElement.AppendChild(childElement);
                    }

                    if (optionConversationNode.Timeout >= 0)
                    {
                        // Timeout
                        XmlElement timeoutElement = doc.CreateElement("timeout");
                        timeoutElement.InnerText = optionConversationNode.Timeout.ToString(CultureInfo.InvariantCulture);
                        nodeElement.AppendChild(timeoutElement);
                        // Timeout conditions
                        DOMWriterUtility.DOMWrite(nodeElement, optionConversationNode.TimeoutConditions);

                        // Create a child tag, and set it the index of the child
                        XmlElement timeoutchildElement = doc.CreateElement("child");
                        timeoutchildElement.SetAttribute("nodeindex", nodes.IndexOf(node.getChild(node.getChildCount() - 1)).ToString());
                        nodeElement.AppendChild(timeoutchildElement);
                    }

                    // If node has an effect, include it into the DOM
                    if (node.hasEffects())
                    {
                        DOMWriterUtility.DOMWrite(nodeElement, node.getEffects(), options);
                    }
                }

                // Add the node to the conversation
                conversationElement.AppendChild(nodeElement);
            }
        }