Example #1
0
        public static RawMap New()
        {
            RawMap file = new RawMap();

            file.Name = "New Map";

            return(file);
        }
Example #2
0
        public static void Save(RawMap file, string path)
        {
            path = Path.Combine(Resources.Main_Path, "Maps\\" + path + "\\_Map.ragox");

            using (BinaryWriter stream = new BinaryWriter(File.Open(path, FileMode.Create), Encoding.UTF8)){
                stream.Write(version);
                //----------
                stream.Write((byte)Parts.Info);
                stream.Write(file.Type);
                stream.Write(file.Name);
                stream.Write(file.Author);
                stream.Write(file.Description);
                stream.Write(file.Max_Players);
                //----------
                stream.Write((byte)Parts.Environement);
                stream.Write(file.Ambient);
                stream.Write(file.Ambient_Color.X);
                stream.Write(file.Ambient_Color.Y);
                stream.Write(file.Ambient_Color.Z);

                stream.Write(file.Sun_Rotation);
                stream.Write(file.Sun_Height);
                stream.Write(file.Sun_Color.X);
                stream.Write(file.Sun_Color.Y);
                stream.Write(file.Sun_Color.Z);

                stream.Write(file.Water_Level);
                stream.Write(file.Water_Density);
                stream.Write(file.Water_Color.X);
                stream.Write(file.Water_Color.Y);
                stream.Write(file.Water_Color.Z);

                //----------
                stream.Write((byte)Parts.Terrain);
                stream.Write(file.Width);
                stream.Write(file.Height);

                stream.Write(file.Textures.Length);
                for (int i = 0; i < file.Textures.Length; i++)
                {
                    stream.Write(file.Textures[i]);
                }

                stream.Write(file.Data.Length);
                for (int i = 0; i < file.Data.Length; i++)
                {
                    stream.Write(file.Data[i]);
                }

                //----------
                stream.Write((byte)Parts.Pathfinding);

                stream.Write(file.Accessibilty_Array.Length);
                stream.Write(file.Accessibilty_Array);

                //----------
                stream.Write((byte)Parts.Objects);

                stream.Write(file.Models.Count);
                for (int i = 0; i < file.Models.Count; i++)
                {
                    MapModel model = file.Models[i];
                    stream.Write(model.file);

                    stream.Write(model.Position.X);
                    stream.Write(model.Position.Y);
                    stream.Write(model.Position.Z);

                    stream.Write(model.Orientation.X);
                    stream.Write(model.Orientation.Y);
                    stream.Write(model.Orientation.Z);
                    stream.Write(model.Orientation.W);

                    stream.Write(model.Scale.X);
                    stream.Write(model.Scale.Y);
                    stream.Write(model.Scale.Z);

                    stream.Write(model.instanced);
                }

                /*stream.Write(0); // Always 0 decals
                 * stream.Write(file.Decals.Length);
                 * for (int i = 0; i < file.Decals.Length; i++){
                 *  MapDecal model = file.Models[i];
                 *  stream.Write(model.file);
                 *
                 *  stream.Write(model.Position.X);
                 *  stream.Write(model.Position.Y);
                 *  stream.Write(model.Position.Z);
                 *
                 *  stream.Write(model.Orientation.X);
                 *  stream.Write(model.Orientation.Y);
                 *  stream.Write(model.Orientation.Z);
                 *  stream.Write(model.Orientation.W);
                 *
                 *  stream.Write(model.Scale.X);
                 *  stream.Write(model.Scale.Y);
                 *  stream.Write(model.Scale.Z);
                 *
                 *  stream.Write(model.foliage);
                 * }*/

                /*stream.Write(file.Nodes.Count);
                 * for (int i = 0; i < file.Nodes.Count; i++) {
                 *  MapNode node = file.Nodes[i];
                 *  stream.Write(node.type);
                 *  stream.Write(node.value);
                 *  stream.Write(node.Position.X);
                 *  stream.Write(node.Position.Y);
                 *  stream.Write(node.Scale.X);
                 *  stream.Write(node.Scale.Y);
                 * }*/
            }
        }
Example #3
0
        public static RawMap Load(string path)
        {
            string combinedpath = Path.Combine(Resources.Main_Path, "Maps\\" + path + "\\_Map.ragox");

            RawMap file = new RawMap();

            file.MainPath = path;
            using (BinaryReader stream = new BinaryReader(File.Open(combinedpath, FileMode.Open), Encoding.UTF8)) {
                if (stream.ReadByte() != 1)
                {
                    throw new Exception("This file format is not version 1");
                }
                //----------
                Contract.Equals(stream.ReadByte(), (byte)Parts.Info);
                file.Type        = ""; stream.ReadString();
                file.Name        = stream.ReadString();
                file.Author      = stream.ReadString();
                file.Description = stream.ReadString();
                file.Max_Players = stream.ReadByte();

                //----------
                Contract.Equals(stream.ReadByte(), (byte)Parts.Environement);
                file.Ambient       = stream.ReadSingle();
                file.Ambient_Color = new Vector3(stream.ReadSingle(), stream.ReadSingle(), stream.ReadSingle());

                file.Sun_Rotation = stream.ReadSingle();
                file.Sun_Height   = stream.ReadSingle();
                file.Sun_Color    = new Vector3(stream.ReadSingle(), stream.ReadSingle(), stream.ReadSingle());

                file.Water_Level   = stream.ReadSingle();
                file.Water_Density = stream.ReadSingle();
                file.Water_Color   = new Vector3(stream.ReadSingle(), stream.ReadSingle(), stream.ReadSingle());

                //----------
                Contract.Equals(stream.ReadByte(), (byte)Parts.Terrain);

                file.Width  = stream.ReadUInt16();
                file.Height = stream.ReadUInt16();

                file.Textures = new string[stream.ReadInt32()];
                for (int i = 0; i < file.Textures.Length; i++)
                {
                    file.Textures[i] = stream.ReadString();
                }

                file.Data = new float[stream.ReadInt32()];
                for (int i = 0; i < file.Data.Length; i++)
                {
                    file.Data[i] = stream.ReadSingle();
                }

                //----------
                Contract.Equals(stream.ReadByte(), (byte)Parts.Pathfinding);

                int acclength = stream.ReadInt32();
                file.Accessibilty_Array = stream.ReadBytes(acclength);

                //----------
                Contract.Equals(stream.ReadByte(), (byte)Parts.Objects);

                file.Models = new List <MapModel>(stream.ReadInt32());
                for (int i = 0; i < file.Models.Capacity; i++)
                {
                    MapModel model = new MapModel();
                    model.file        = stream.ReadString();
                    model.Position    = new Vector3(stream.ReadSingle(), stream.ReadSingle(), stream.ReadSingle());
                    model.Orientation = new Quaternion(stream.ReadSingle(), stream.ReadSingle(), stream.ReadSingle(), stream.ReadSingle());
                    model.Scale       = new Vector3(stream.ReadSingle(), stream.ReadSingle(), stream.ReadSingle());
                    model.instanced   = stream.ReadBoolean();
                    file.Models.Add(model);
                }
            }


            return(file);
        }