Esempio n. 1
0
        private void GenerateAnimations()
        {
            char[] alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToLower().ToCharArray();
            var    xmlData  = FileUtil.SolveXmlFile(XmlDirectory, "visualization");

            this.AnimationCount = 0;
            this.Animations     = new SortedDictionary <int, ChromaAnimation>();

            if (xmlData == null)
            {
                return;
            }

            XmlNodeList frames = xmlData.SelectNodes("//visualizationData/visualization[@size='" + (IsSmallFurni ? "32" : "64") + "']/animations/animation/animationLayer/frameSequence/frame");

            if (frames == null)
            {
                frames = xmlData.SelectNodes("//visualizationData/visualization[@size='64']/animations/animation/animationLayer/frameSequence/frame");
            }

            this.HighestAnimationLayer = 0;

            for (int i = 0; i < frames.Count; i++)
            {
                var frame = frames.Item(i);

                var animationLayer = frame.ParentNode.ParentNode;
                int letterPosition = int.Parse(animationLayer.Attributes.GetNamedItem("id").InnerText);

                if (letterPosition < 0 || letterPosition > alphabet.Length)
                {
                    continue;
                }

                var animationLetter = int.Parse(animationLayer.Attributes.GetNamedItem("id").InnerText);//Convert.ToString(alphabet[int.Parse(animationLayer.Attributes.GetNamedItem("id").InnerText)]);

                HighestAnimationLayer = int.Parse(animationLayer.Attributes.GetNamedItem("id").InnerText) + 1;

                var animation   = frame.ParentNode.ParentNode.ParentNode;
                var animationId = int.Parse(animation.Attributes.GetNamedItem("id").InnerText);

                var castAnimationId = animationId + 1;

                if (castAnimationId > this.AnimationCount)
                {
                    this.AnimationCount = castAnimationId;
                }

                if (!this.Animations.ContainsKey(animationLetter))
                {
                    this.Animations.Add(animationLetter, new ChromaAnimation());//new Dictionary<int, List<string>>());
                }

                if (!this.Animations[animationLetter].States.ContainsKey(animationId))
                {
                    var frameClass = new ChromaFrame();
                    this.Animations[animationLetter].States.Add(animationId, frameClass);

                    if (animationLayer.Attributes.GetNamedItem("loopCount") != null)
                    {
                        frameClass.Loop = int.Parse(animationLayer.Attributes.GetNamedItem("loopCount").InnerText);
                    }

                    if (animationLayer.Attributes.GetNamedItem("frameRepeat") != null)
                    {
                        frameClass.FramesPerSecond = int.Parse(animationLayer.Attributes.GetNamedItem("frameRepeat").InnerText);
                    }
                }

                this.Animations[animationLetter].States[animationId].Frames.Add(frame.Attributes.GetNamedItem("id").InnerText);
            }
        }
Esempio n. 2
0
        private void GenerateAssets(bool createFiles = true)
        {
            var xmlData = FileUtil.SolveXmlFile(XmlDirectory, "assets");

            if (xmlData == null)
            {
                return;
            }

            XmlNodeList assets = xmlData.SelectNodes("//assets/asset");

            for (int i = 0; i < assets.Count; i++)
            {
                var asset = assets.Item(i);

                var X = int.Parse(asset.Attributes.GetNamedItem("x").InnerText);
                var Y = int.Parse(asset.Attributes.GetNamedItem("y").InnerText);

                string imageName = asset.Attributes.GetNamedItem("name").InnerText;

                if (imageName.Contains(".props") || imageName.StartsWith("s_" + this.Sprite))
                {
                    continue;
                }

                if (!IsIcon)
                {
                    if (imageName.Contains("_icon_"))
                    {
                        continue;
                    }
                }
                else
                {
                    if (!imageName.Contains("_icon_"))
                    {
                        continue;
                    }
                }

                if (asset.Attributes.GetNamedItem("source") != null)
                {
                    var newChromaAsset = new ChromaAsset(this, X, Y, asset.Attributes.GetNamedItem("source").InnerText, imageName);
                    CreateAsset(newChromaAsset, asset, createFiles);
                }
                else
                {
                    var chromaAsset = new ChromaAsset(this, X, Y, null, imageName);
                    CreateAsset(chromaAsset, asset, createFiles);
                }
            }

            this.MaxStates = 0;

            var visualization = FileUtil.SolveXmlFile(XmlDirectory, "visualization");

            if (visualization == null)
            {
                return;
            }

            XmlNodeList animations = visualization.SelectNodes("//visualizationData/visualization[@size='" + (IsSmallFurni ? "32" : "64") + "']/animations/animation");

            if (animations == null || animations.Count == 0)
            {
                animations = visualization.SelectNodes("//visualizationData/visualization[@size='" + (IsSmallFurni ? "32" : "64") + "']/directions/direction[@id='" + RenderDirection + "']/animations/animation");
            }

            for (int i = 0; i < animations.Count; i++)
            {
                var animation = animations.Item(i);

                if (animation.Name != "animation" && animation.Attributes.GetNamedItem("id") == null)
                {
                    continue;
                }

                int state = int.Parse(animation.Attributes.GetNamedItem("id").InnerText);

                if (state > MaxStates)
                {
                    MaxStates = state;
                }
            }

            this.MaxStates             = MaxStates;
            this.HighestAnimationLayer = this.Assets.Where(x => !x.Shadow).ToList().Max(x => x.Layer) + 1;

            for (int i = 0; i < HighestAnimationLayer; i++)
            {
                //var letter = alphabet[i];
                //string letter = Convert.ToString(alphabet[i]);

                if (!this.Animations.ContainsKey(i))
                {
                    var animation = new ChromaAnimation();
                    this.Animations.Add(i, animation);

                    for (int j = 0; j < this.AnimationCount; j++)
                    {
                        if (!animation.States.ContainsKey(j))
                        {
                            var frame = new ChromaFrame();
                            frame.Frames.Add("0");

                            animation.States.Add(j, frame);
                        }
                    }
                }
            }
        }