Exemplo n.º 1
0
        public void ProceduralHSVDeserialization()
        {
            String hsv_string = @"{""twidth"":333,""theight"":300,""hues"":[0.9, 0.99],""saturation"":0.55,""luminosity"":0.123,""packname"":""from_hsv_string""}";
            var    hsv        = ProceduralHSVTileSet.DeSerialize(hsv_string);

            Assert.AreEqual(hsv.twidth, 333);
            Assert.AreEqual(hsv.theight, 300);
            Assert.AreEqual(hsv.hues[1], 0.99f);

            Assert.AreEqual(hsv.saturation, 0.55f);
            Assert.AreEqual(hsv.luminosity, 0.123f);
            Assert.AreEqual(hsv.packname, "from_hsv_string");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initialize/Construct a TileSetRepo via de-serialization from json.
        /// </summary>
        /// <returns>A de-serialized instance.</returns>
        /// <param name="serialized">JSon representation of Serialized object.</param>
        public static TileSetRepo DeSerialize(String serialized)
        {
            var tsr = new TileSetRepo();

            JsonConvert.PopulateObject(serialized, tsr);


            foreach (Dictionary <String, String> tset_data in tsr.serialized_tsets)
            {
                String tset_type       = tset_data["tset_type"];
                String tset_serialized = tset_data["tset_serialized"];

                if (tset_type == "ProceduralHSVTileSet")
                {
                    tsr.AddTileSet(ProceduralHSVTileSet.DeSerialize(tset_serialized));
                }

                System.Console.WriteLine(String.Format("type {0}, ser {1}", tset_type, tset_serialized));
            }
            return(tsr);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Loads the tset file.
        /// </summary>
        /// <param name="abspath">Abspath.</param>
        /// <param name="population">Population.</param>
        private static void LoadTsetFile(String abspath, List <ITileSet> population)
        {
            var jsonstr      = System.IO.File.ReadAllText(abspath);
            var tileset_type = TileSetTypes.TileSet.DetermineType(jsonstr);

            switch (tileset_type)
            {
            case "ProceduralHSVTileSet":
                population.Add(ProceduralHSVTileSet.DeSerialize(jsonstr));
                break;

            case "ChoppedBitmapTileSet":
                var tileset = ChoppedBitmapTileSet.DeSerialize(jsonstr);
                var origin  = Path.GetDirectoryName(abspath);
                System.Console.WriteLine("Setting tileset '{0} 'origin to '{1}'", tileset.PackName(), origin);
                tileset.SetOriginPath(origin);
                population.Add(tileset);
                break;

            default: throw new JsonException(String.Format("Could not determine tileset type from file {0}", abspath));
            }
        }