public static bool WriteAnimation(string filename, Animation animation)
        {
            bool        dataSaved = false;
            XmlDocument doc       = new XmlDocument();

            // Declaration, encoding, version, etc
            XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", "no");

            doc.AppendChild(declaration);

            // DTD
            XmlDocumentType typeDescriptor = doc.CreateDocumentType("animation", "SYSTEM", "animation.dtd", null);

            doc.AppendChild(typeDescriptor);

            // Main animation node
            XmlElement mainNode = doc.CreateElement("animation");

            mainNode.SetAttribute("id", animation.getId());
            mainNode.SetAttribute("usetransitions", animation.isUseTransitions() ? "yes" : "no");
            mainNode.SetAttribute("slides", animation.isSlides() ? "yes" : "no");

            // Documentation node
            XmlElement documentation = doc.CreateElement("documentation");

            if (animation.getDocumentation() != null && animation.getDocumentation().Length > 0)
            {
                documentation.InnerText = animation.getDocumentation();
            }

            mainNode.AppendChild(documentation);

            // Resources in this animation
            foreach (ResourcesUni resources in animation.getResources())
            {
                // TODO update to domwriter resource
                XmlNode resourcesNode = ResourcesDOMWriter.buildDOM(resources, ResourcesDOMWriter.RESOURCES_ANIMATION);
                doc.ImportNode(resourcesNode, true);
                mainNode.AppendChild(resourcesNode);
            }

            // Frames and transitions
            // TODO update to DOMWriter
            for (int i = 0; i < animation.getFrames().Count; i++)
            {
                mainNode.AppendChild(createTransitionElement(animation.getTransitions()[i], doc));
                mainNode.AppendChild(createFrameElement(animation.getFrames()[i], doc));
            }
            mainNode.AppendChild(createTransitionElement(animation.getEndTransition(), doc));
            doc.ImportNode(mainNode, true);
            doc.AppendChild(mainNode);

            // File saving
            string name = "Assets/uAdventure/Resources/CurrentGame/" + filename;

            if (!name.EndsWith(".eaa.xml"))
            {
                name += ".eaa.xml";
            }

            try
            {
                // Save
                doc.Save(name);
                dataSaved = true;
            }
            catch (System.Exception ex)
            {
                Debug.Log("Couldn't save Animation file \"" + name + "\": " + ex.Message);
            }

            return(dataSaved);
        }
        public static bool writeAnimation(string filename, Animation animation)
        {
            bool            dataSaved      = false;
            XmlDocument     doc            = doc = new XmlDocument();
            XmlDeclaration  declaration    = doc.CreateXmlDeclaration("1.0", "UTF-8", "no");
            XmlDocumentType typeDescriptor = doc.CreateDocumentType("animation", "SYSTEM", "animation.dtd", null);

            doc.AppendChild(declaration);
            doc.AppendChild(typeDescriptor);
            XmlElement mainNode = doc.CreateElement("animation");

            //mainNode.AppendChild(doc.createAttribute("id").setNodeValue(animation.getId()));
            mainNode.SetAttribute("id", animation.getId());
            mainNode.SetAttribute("usetransitions", animation.isUseTransitions() ? "yes" : "no");
            mainNode.SetAttribute("slides", animation.isSlides() ? "yes" : "no");
            XmlElement documentation = doc.CreateElement("documentation");

            if (animation.getDocumentation() != null && animation.getDocumentation().Length > 0)
            {
                documentation.InnerText = animation.getDocumentation();
            }
            mainNode.AppendChild(documentation);

            foreach (ResourcesUni resources in animation.getResources())
            {
                XmlNode resourcesNode = ResourcesDOMWriter.buildDOM(resources, ResourcesDOMWriter.RESOURCES_ANIMATION);
                doc.ImportNode(resourcesNode, true);
                mainNode.AppendChild(resourcesNode);
            }

            for (int i = 0; i < animation.getFrames().Count; i++)
            {
                mainNode.AppendChild(createTransitionElement(animation.getTransitions()[i], doc));
                mainNode.AppendChild(createFrameElement(animation.getFrames()[i], doc));
            }
            mainNode.AppendChild(createTransitionElement(animation.getEndTransition(), doc));

            doc.ImportNode(mainNode, true);
            doc.AppendChild(mainNode);
            string name = "Assets/Resources/CurrentGame/" + filename;

            if (!name.EndsWith(".eaa"))
            {
                name += ".eaa";
            }
            doc.Save(name);
            System.IO.File.Copy(name, name.Substring(0, name.LastIndexOf(".")) + ".xml", true);
            //TODO: implementation?
            //transformer = tf.newTransformer();
            //transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "animation.dtd");

            //try
            //{
            //    fout = new FileOutputStream(filename);
            //}
            //catch (FileNotFoundException e)
            //{
            //    fout = new FileOutputStream(Controller.getInstance().getProjectFolder() + "/" + filename);
            //}

            //writeFile = new OutputStreamWriter(fout, "UTF-8");
            //transformer.transform(new DOMSource(doc), new StreamResult(writeFile));
            //writeFile.close();
            //fout.close();

            dataSaved = true;

            return(dataSaved);
        }
Example #3
0
        public void Init(DialogReceiverInterface e, string cutsceneFilePath)
        {
            cutscenePath = cutsceneFilePath;
            clearImg     = (Texture2D)Resources.Load("EAdventureData/img/icons/deleteContent", typeof(Texture2D));
            addTexture   = (Texture2D)Resources.Load("EAdventureData/img/icons/addNode", typeof(Texture2D));
            moveLeft     = (Texture2D)Resources.Load("EAdventureData/img/icons/moveNodeLeft", typeof(Texture2D));
            moveRight    = (Texture2D)Resources.Load("EAdventureData/img/icons/moveNodeRight", typeof(Texture2D));
            duplicateImg = (Texture2D)Resources.Load("EAdventureData/img/icons/duplicateNode", typeof(Texture2D));

            animInfoRect        = new Rect(0f, 0.05f * windowHeight, windowWidth, 0.15f * windowHeight);
            timelineRect        = new Rect(0f, 0.25f * windowHeight, windowWidth, 0.3f * windowHeight);
            timelineButtonsRect = new Rect(0f, 0.50f * windowHeight, windowWidth, 0.1f * windowHeight);
            frameInfoRect       = new Rect(0f, 0.65f * windowHeight, windowWidth, 0.25f * windowHeight);
            buttonRect          = new Rect(0f, 0.9f * windowHeight, windowWidth, 0.1f * windowHeight);

            noBackgroundSkin  = (GUISkin)Resources.Load("Editor/EditorNoBackgroundSkin", typeof(GUISkin));
            selectedFrameSkin = (GUISkin)Resources.Load("Editor/EditorLeftMenuItemSkinConcreteOptions", typeof(GUISkin));

            //transitionTypes = new string []{ "None" , "Fade in", "Horizontal", "Vertical"};
            Debug.Log(cutsceneFilePath);

            workingAnimation = Loader.loadAnimation(AssetsController.InputStreamCreatorEditor.getInputStreamCreator(),
                                                    cutsceneFilePath, new EditorImageLoader());

            Debug.Log(workingAnimation.getAboslutePath() + " " + workingAnimation.getFrames().Count + " " + workingAnimation.isSlides() + " " + workingAnimation.getId());
            if (workingAnimation == null)
            {
                workingAnimation = new Animation(cutsceneFilePath, 40, new EditorImageLoader());
            }

            // Initalize
            selectedFrame            = 0;
            documentationTextContent = workingAnimation.getFrames()[selectedFrame].getDocumentation();
            imagePath = workingAnimation.getFrames()[selectedFrame].getUri();
            soundPath = workingAnimation.getFrames()[selectedFrame].getSoundUri();
            animationDurationString          =
                animationDurationStringLast  = workingAnimation.getFrames()[selectedFrame].getTime().ToString();
            transitionDurationString         =
                transitionDurationStringLast = workingAnimation.getTransitions()[selectedFrame + 1].getTime().ToString();
            useTransitonFlag    = useTransitonFlagLast = workingAnimation.isUseTransitions();
            slidesAnimationFlag = slidesAnimationFlagLast = workingAnimation.isSlides();

            base.Init(e);
        }