Esempio n. 1
0
        public IEnumerable <ActorTransform> GetTransforms(Map map)
        {
            var offset = int2.Zero;

            if (mirrorOffsets.ContainsKey(Actor.Type))
            {
                offset = mirrorOffsets[Actor.Type];
            }

            var horizontalTransform = new ActorTransform()
            {
                Position = new CPos(map.MapSize.X - Position.X - offset.X - 1, Position.Y),
                Actor    = Actor
            };

            var verticalTransform = new ActorTransform()
            {
                Position = new CPos(Position.X, map.MapSize.Y - Position.Y - offset.Y - 1),
                Actor    = Actor
            };

            var horizontalAndVerticalTransform = new ActorTransform()
            {
                Position = new CPos(map.MapSize.X - Position.X - offset.X - 1, map.MapSize.Y - Position.Y - offset.Y - 1),
                Actor    = Actor
            };

            switch (MirrorType)
            {
            case MirrorType.Horizontal:
                yield return(horizontalTransform);

                break;

            case MirrorType.Vertical:
                yield return(verticalTransform);

                break;

            case MirrorType.HorizontalAndVertical:
                yield return(horizontalTransform);

                yield return(verticalTransform);

                yield return(horizontalAndVerticalTransform);

                break;
            }
        }
Esempio n. 2
0
        protected void Run(Utility utility, string[] args)
        {
            // HACK: The engine code assumes that Game.modData is set.
            Game.ModData = ModData = utility.ModData;

            var filename = args[1];
            var flag     = args[2];

            if (string.IsNullOrWhiteSpace(flag))
            {
                flag = "VH";
            }

            bool flipHorizontal = flag.Contains("H");
            bool flipVertical   = flag.Contains("V");

            MirrorType mirrorType = MirrorType.Horizontal;

            if (flipVertical)
            {
                mirrorType = MirrorType.Vertical;
            }
            if (flipHorizontal && flipVertical)
            {
                mirrorType = MirrorType.HorizontalAndVertical;
            }

            var targetPath = "..\\mods\\dr\\maps";

            var package = new Folder(targetPath).OpenPackage(filename, ModData.ModFiles);

            if (package == null)
            {
                Console.WriteLine("Couldn't find map file: " + filename);
                return;
            }

            Map = new Map(ModData, package);
            var size = Map.MapSize;

            switch (mirrorType)
            {
            case MirrorType.Horizontal:
                size = size.WithX(size.X / 2);
                break;

            case MirrorType.Vertical:
                size = size.WithY(size.Y / 2);
                break;

            case MirrorType.HorizontalAndVertical:
                size = size / 2;
                break;
            }

            // Tiles
            for (int x = 0; x < size.X; x++)
            {
                for (int y = 0; y < size.Y; y++)
                {
                    var pos           = new CPos(x, y);
                    var transformTile = new TileTransform()
                    {
                        Tile       = Map.Tiles[pos],
                        MirrorType = mirrorType,
                        Position   = pos
                    };

                    foreach (var tt in transformTile.GetTransforms(Map))
                    {
                        var newPos = tt.Position;
                        Map.Tiles[newPos] = tt.Tile;
                    }
                }
            }

            // Actors
            actorIndex = GetHighestActorIndex();
            int multiCount = 0;

            var actorDefs    = new List <ActorReference>();
            var removeActors = new List <MiniYamlNode>();

            foreach (var a in Map.ActorDefinitions)
            {
                var existing = new ActorReference(a.Value.Value, a.Value.ToDictionary());
                var pos      = existing.GetOrDefault <LocationInit>().Value;
                var owner    = existing.Get <OwnerInit>();

                if (pos.X < 0 || pos.X >= size.X ||
                    pos.Y < 0 || pos.Y >= size.Y)
                {
                    removeActors.Add(a);
                    continue;
                }

                var actor = new ActorTransform()
                {
                    Actor      = existing,
                    Position   = pos,
                    MirrorType = mirrorType,
                };

                if (actor.Actor.Type == "mpspawn")
                {
                    multiCount++;
                }

                foreach (var at in actor.GetTransforms(Map))
                {
                    var ar = new ActorReference(actor.Actor.Type)
                    {
                        new LocationInit(at.Position),
                        owner
                    };

                    actorDefs.Add(ar);

                    if (at.Actor.Type == "mpspawn")
                    {
                        multiCount++;
                    }
                }
            }

            foreach (var a in actorDefs)
            {
                Map.ActorDefinitions.Add(new MiniYamlNode("Actor" + ++actorIndex, a.Save()));
            }

            foreach (var a in removeActors)
            {
                Map.ActorDefinitions.Remove(a);
            }

            if (multiCount > 0)
            {
                var mapPlayers = new MapPlayers(Map.Rules, multiCount);
                Map.PlayerDefinitions = mapPlayers.ToMiniYaml();
            }

            // Resources
            for (int x = 0; x < size.X; x++)
            {
                for (int y = 0; y < size.Y; y++)
                {
                    var pos      = new CPos(x, y);
                    var resource = new ResourceTransform()
                    {
                        Tile       = Map.Resources[pos],
                        MirrorType = mirrorType,
                        Position   = pos
                    };

                    foreach (var rt in resource.GetTransforms(Map))
                    {
                        var newPos = rt.Position;
                        Map.Resources[newPos] = rt.Tile;
                    }
                }
            }

            var dest = Path.Combine(targetPath, Path.GetFileNameWithoutExtension(filename) + ".oramap");

            Map.Save(ZipFileLoader.Create(dest));
            Console.WriteLine(dest + " saved.");
        }