Example #1
0
        public override MapParallax LoadParallax(string fileId)
        {
            MapParallax parallax = null;

            if (FitsExtension(fileId))
            {
                Stream stream = engine.FileResolver.OpenFile(fileId);
                if (stream != null)
                {
                    XDocument xdoc = XDocument.Load(stream);
                    if (xdoc != null)
                    {
                        var root = xdoc.Root;
                        if (root.Name.LocalName.Equals("parallax"))
                        {
                            string tsName = root.Attribute("name").Value;
                            if (!string.IsNullOrEmpty(tsName))
                            {
                                parallax = LoadParallax(root, fileId);
                            }
                        }
                    }
                    stream.Dispose();
                }
            }
            return(parallax);
        }
Example #2
0
        private MapParallax InternalLoadParallax(IniFile ini, string filename)
        {
            MapParallax   parallax = new MapParallax(filename);
            ParallaxLayer layer    = null;

            foreach (var sec in ini.Sections)
            {
                if (sec.Name.Equals("layer"))
                {
                    string  img = sec.ReadString("image");
                    Texture tx  = engine.GetTexture(img);
                    if (tx != null)
                    {
                        layer          = new ParallaxLayer(tx);
                        layer.MapLayer = sec.ReadString("map_layer");
                        layer.Speed    = (float)sec.ReadDouble("speed");
                        string[] sValues = sec.ReadString("fixed_speed").ToStrValues();
                        if (sValues.Length >= 2)
                        {
                            layer.FixedSpeedX = sValues[0].ToFloatValue();
                            layer.FixedSpeedY = sValues[1].ToFloatValue();
                        }
                        parallax.AddLayer(layer);
                    }
                }
            }
            return(parallax);
        }
Example #3
0
        public override MapParallax LoadParallax(string fileId)
        {
            MapParallax parallax = null;

            if (FitsExtension(fileId))
            {
                Stream stream = engine.FileResolver.OpenFile(fileId);
                if (stream != null)
                {
                    IniFile ini = GetIni(stream);
                    parallax = InternalLoadParallax(ini, fileId);
                    stream.Dispose();
                }
            }
            return(parallax);
        }
Example #4
0
        public MapParallax LoadParallax(string parallaxId)
        {
            MapParallax parallax = null;

            foreach (ILoader loader in loaders)
            {
                if (loader.DetectFileTpye(parallaxId) == FileType.Parallax)
                {
                    parallax = loader.LoadParallax(parallaxId);
                    if (parallax != null)
                    {
                        break;
                    }
                }
            }
            return(parallax);
        }
Example #5
0
        public void SaveParallax(MapParallax parallax, string fileId = null)
        {
            if (parallax == null)
            {
                return;
            }
            if (fileId == null)
            {
                fileId = parallax.Name;
            }
            fileId = AdjustFileName(fileId);
            ISaver saver = GetSaver(fileId);

            if (saver != null)
            {
                saver.Save(parallax, fileId);
            }
        }
Example #6
0
 public override void Save(MapParallax parallax, string fileId)
 {
     using (var stream = GetOutputStream(fileId))
     {
         using (TextWriter tw = new StreamWriter(stream))
         {
             foreach (var layer in parallax.Layers)
             {
                 tw.WriteLine("[layer]");
                 tw.WriteLine($"image={layer.Texture.Name}");
                 tw.WriteLine($"speed={layer.Speed}");
                 if (layer.FixedSpeedX != 0 || layer.FixedSpeedY != 0)
                 {
                     tw.WriteLine($"fixed_speed={layer.FixedSpeedX},{layer.FixedSpeedY}");
                 }
                 if (!string.IsNullOrEmpty(layer.MapLayer))
                 {
                     tw.WriteLine($"map_layer={layer.MapLayer}");
                 }
                 tw.WriteLine();
             }
         }
     }
 }
Example #7
0
 public override void Save(MapParallax parallax, string fileId)
 {
 }
Example #8
0
 public abstract void Save(MapParallax parallax, string fileId);
Example #9
0
        private MapParallax LoadParallax(XElement root, string fileId)
        {
            MapParallax parallax = null;

            return(parallax);
        }