예제 #1
0
파일: World.cs 프로젝트: jpiolho/sledge
 public override MapObject Copy(IDGenerator generator)
 {
     var e = new World(generator.GetNextObjectID())
     {
         EntityData = EntityData.Clone(),
     };
     e.Paths.AddRange(Paths.Select(x => x.Clone()));
     CopyBase(e, generator);
     return e;
 }
예제 #2
0
파일: World.cs 프로젝트: jpiolho/sledge
 public override MapObject Clone()
 {
     var e = new World(ID)
     {
         EntityData = EntityData.Clone(),
     };
     e.Paths.AddRange(Paths.Select(x => x.Clone()));
     CopyBase(e, null, true);
     return e;
 }
예제 #3
0
파일: Map.cs 프로젝트: jpiolho/sledge
        public Map()
        {
            Version = 1;
            Visgroups = new List<Visgroup>();
            Cameras = new List<Camera>();
            ActiveCamera = null;
            IDGenerator = new IDGenerator();
            WorldSpawn = new World(IDGenerator.GetNextObjectID());

            Show2DGrid = SnapToGrid = true;
            TextureLock = true;
            HideDisplacementSolids = true;
            CordonBounds = new Box(Coordinate.One * -1024, Coordinate.One * 1024);
        }
예제 #4
0
 private static void WriteMapWorld(BinaryWriter bw, World w)
 {
     bw.WriteCString("CMapWorld");
     WriteMapBase(bw, w);
     WriteEntityData(bw, w.EntityData);
     bw.Write(w.Paths.Count);
     foreach (var path in w.Paths)
     {
         WritePath(bw, path);
     }
 }
예제 #5
0
 private static MapObject ReadMapWorld(BinaryReader br, List<Visgroup> visgroups, IDGenerator generator)
 {
     var wld = new World(generator.GetNextObjectID());
     ReadMapBase(br, wld, visgroups, generator);
     wld.EntityData = ReadEntityData(br);
     var numPaths = br.ReadInt32();
     for (var i = 0; i < numPaths; i++)
     {
         wld.Paths.Add(ReadPath(br));
     }
     return wld;
 }
예제 #6
0
        private void WriteWorld(StreamWriter sw, World world)
        {
            var solids = new List<Solid>();
            var entities = new List<Entity>();
            CollectSolids(solids, world);
            CollectEntities(entities, world);

            sw.WriteLine("{");

            WriteProperty(sw, "classname", world.EntityData.Name);
            WriteProperty(sw, "spawnflags", world.EntityData.Flags.ToString(CultureInfo.InvariantCulture));
            WriteProperty(sw, "mapversion", "220");
            foreach (var prop in world.EntityData.Properties)
            {
                if (prop.Key == "classname" || prop.Key == "spawnflags" || prop.Key == "mapversion") continue;
                WriteProperty(sw, prop.Key, prop.Value);
            }
            solids.ForEach(x => WriteSolid(sw, x));

            sw.WriteLine("}");

            entities.ForEach(x => WriteEntity(sw, x));
        }
예제 #7
0
        private static World ReadWorld(GenericStructure world, IDGenerator generator)
        {
            var ret = new World(GetObjectID(world, generator))
                          {
                              ClassName = "worldspawn",
                              EntityData = ReadEntityData(world)
                          };

            // Load groups
            var groups = new Dictionary<Group, long>();
            foreach (var group in world.GetChildren("group"))
            {
                var g = ReadGroup(group, generator);
                var editor = group.GetChildren("editor").FirstOrDefault() ?? new GenericStructure("editor");
                var gid = editor.PropertyLong("groupid");
                groups.Add(g, gid);
            }

            // Build group tree
            var assignedGroups = groups.Where(x => x.Value == 0).Select(x => x.Key).ToList();
            foreach (var ag in assignedGroups)
            {
                // Add the groups with no parent
                ag.SetParent(ret);
                groups.Remove(ag);
            }
            while (groups.Any())
            {
                var canAssign = groups.Where(x => assignedGroups.Any(y => y.ID == x.Value)).ToList();
                if (!canAssign.Any())
                {
                    break;
                }
                foreach (var kv in canAssign)
                {
                    // Add the group to the tree and the assigned list, remove it from the groups list
                    var parent = assignedGroups.First(y => y.ID == kv.Value);
                    kv.Key.SetParent(parent);
                    assignedGroups.Add(kv.Key);
                    groups.Remove(kv.Key);
                }
            }

            // Load visible solids
            foreach (var solid in world.GetChildren("solid"))
            {
                var s = ReadSolid(solid, generator);
                if (s == null) continue;

                var editor = solid.GetChildren("editor").FirstOrDefault() ?? new GenericStructure("editor");
                var gid = editor.PropertyLong("groupid");
                var parent = gid > 0 ? assignedGroups.FirstOrDefault(x => x.ID == gid) ?? (MapObject) ret : ret;
                s.SetParent(parent);
                parent.UpdateBoundingBox();
            }

            // Load hidden solids
            foreach (var hidden in world.GetChildren("hidden"))
            {
                foreach (var solid in hidden.GetChildren("solid"))
                {
                    var s = ReadSolid(solid, generator);
                    if (s == null) continue;

                    s.IsVisgroupHidden = true;

                    var editor = solid.GetChildren("editor").FirstOrDefault() ?? new GenericStructure("editor");
                    var gid = editor.PropertyLong("groupid");
                    var parent = gid > 0 ? assignedGroups.FirstOrDefault(x => x.ID == gid) ?? (MapObject)ret : ret;
                    s.SetParent(parent);
                    parent.UpdateBoundingBox();
                }
            }

            assignedGroups.ForEach(x => x.UpdateBoundingBox(false));

            return ret;
        }
예제 #8
0
 private void SetEntityData(World world, EntityData data)
 {
     world.EntityData = data;
 }