Exemplo n.º 1
0
 public CellLayer(MapGridT gridT, Size size)
 {
     Size    = size;
     bounds  = new Rectangle(0, 0, Size.Width, Size.Height);
     GridT   = gridT;
     entries = new T[size.Width * size.Height];
 }
Exemplo n.º 2
0
        public CellRegion(MapGridT gridT, CPos topLeft, CPos bottomRight)
        {
            this.gridT = gridT;

            this.TopLeft     = topLeft;
            this.BottomRight = bottomRight;

            mapTopLeft     = TopLeft.ToMPos(gridT);
            mapBottomRight = BottomRight.ToMPos(gridT);
        }
Exemplo n.º 3
0
        public MPos ToMPos(MapGridT gridT)
        {
            if (gridT == MapGridT.Rectangular)
            {
                return(new MPos(X, Y));
            }

            //Convert from RectangularIsometric cell (x,y) position to rectangular map position (u,v)
            var u = (X - Y) / 2;
            var v = X + Y;

            return(new MPos(u, v));
        }
Exemplo n.º 4
0
        public CPos ToCPos(MapGridT gridT)
        {
            //TODO
            if (gridT == MapGridT.Rectangular)
            {
                return(new CPos(U, V));
            }

            var offset = (V & 1) == 1 ? 1 : 0;//1 是奇数 0 是偶数
            var y      = (V - offset) / 2 - U;
            var x      = V - y;

            return(new CPos(x, y));
        }
Exemplo n.º 5
0
        public Int2 ConvertToPreview(CPos cell, MapGridT gridType)
        {
            var preview   = Preview();
            var point     = cell.ToMPos(gridType);
            var cellWidth = gridType == MapGridT.RectangularIsometric ? 2 : 1;
            var dx        = (int)(previewScale * cellWidth * (point.U - preview.Bounds.Left));
            var dy        = (int)(previewScale * (point.V - preview.Bounds.Top));

            // Odd rows are shifted right by 1px
            if ((point.V & 1) == 1)
            {
                dx += 1;
            }

            return(new Int2(mapRect.X + dx, mapRect.Y + dy));
        }
Exemplo n.º 6
0
        public MapPreview(ModData modData, string uid, MapGridT gridT, MapCache cache)
        {
            this.cache   = cache;
            this.modData = modData;

            Uid = uid;

            innerData = new InnerData
            {
                Title       = "Unknown Map",
                Categories  = new[] { "Unknown" },
                Author      = "Unknown Author",
                TileSet     = "Unknown",
                Players     = null,
                PlayerCount = 0,
                SpawnPoints = NoSpawns,
                GridT       = gridT,
                Bounds      = Rectangle.Empty,
                Preview     = null,
                Status      = MapStatus.Unavailable,
                Visibility  = MapVisibility.Lobby,
            };
        }
Exemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="initialCellValueFactory"></param>
        /// <param name="size"></param>
        /// <param name="mapGridT"></param>
        /// <returns></returns>
        public static CellLayer <T> CreateInstance(Func <MPos, T> initialCellValueFactory, Size size, MapGridT mapGridT)
        {
            var cellLayer = new CellLayer <T>(mapGridT, size);

            for (var v = 0; v < size.Height; v++)
            {
                for (var u = 0; u < size.Width; u++)
                {
                    var mpos = new MPos(u, v);
                    cellLayer[mpos] = initialCellValueFactory(mpos);
                }
            }
            return(cellLayer);
        }
Exemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="p"></param>
        /// <param name="parent"></param>
        /// <param name="classification"></param>
        /// <param name="mapCompatibility"></param>
        /// <param name="gridT"></param>
        public void UpdateFromMap(IReadOnlyPackage p, IReadOnlyPackage parent, MapClassification classification, string[] mapCompatibility, MapGridT gridT)
        {
            Dictionary <string, MiniYaml> yaml;

            using (var yamlStream = p.GetStream("map.yaml"))
            {
                if (yamlStream == null)
                {
                    throw new FileNotFoundException("Required file map.yaml not present in this map");
                }

                yaml = new MiniYaml(null, MiniYaml.FromStream(yamlStream, "map.yaml")).ToDictionary();
            }

            Package       = p;
            parentPackage = parent;


            var newData = innerData.Clone();

            newData.GridT = gridT;
            newData.Class = classification;

            MiniYaml temp;

            if (yaml.TryGetValue("MapFormat", out temp))
            {
                var format = FieldLoader.GetValue <int>("MapFormat", temp.Value);
                if (format != Map.SupportedMapFormat)
                {
                    throw new InvalidOperationException("Map format {0} is not supported.".F(format));
                }
            }
            if (yaml.TryGetValue("Title", out temp))
            {
                newData.Title = temp.Value;
            }
            if (yaml.TryGetValue("Categories", out temp))
            {
                newData.Categories = FieldLoader.GetValue <string[]>("Categories", temp.Value);
            }
            if (yaml.TryGetValue("Tileset", out temp))
            {
                newData.TileSet = temp.Value;
            }

            if (yaml.TryGetValue("Author", out temp))
            {
                newData.Author = temp.Value;
            }
            if (yaml.TryGetValue("Bounds", out temp))
            {
                newData.Bounds = FieldLoader.GetValue <Rectangle>("Bounds", temp.Value);
            }

            if (yaml.TryGetValue("Visibility", out temp))
            {
                newData.Visibility = FieldLoader.GetValue <MapVisibility>("Visibility", temp.Value);
            }

            string requiresMod = string.Empty;

            if (yaml.TryGetValue("RequiresMod", out temp))
            {
                requiresMod = temp.Value;
            }

            newData.Status = mapCompatibility == null || mapCompatibility.Contains(requiresMod) ? MapStatus.Available : MapStatus.Unavailable;

            try
            {
                MiniYaml actorDefinitions;
                if (yaml.TryGetValue("Actors", out actorDefinitions))
                {
                    var spawns = new List <CPos>();
                    foreach (var kv in actorDefinitions.Nodes.Where(d => d.Value.Value == "mpspawn"))
                    {
                        var s = new ActorReference(kv.Value.Value, kv.Value.ToDictionary());
                        spawns.Add(s.InitDict.Get <LocationInit>().Value(null));
                    }
                    newData.SpawnPoints = spawns.ToArray();
                }
                else
                {
                    newData.SpawnPoints = new CPos[0];
                }
            }
            catch (Exception)
            {
                newData.SpawnPoints = new CPos[0];
                newData.Status      = MapStatus.Unavailable;
            }


            try
            {
                //Player definitions may change if the map format changes
                MiniYaml playerDefinitions;
                if (yaml.TryGetValue("Players", out playerDefinitions))
                {
                    newData.Players     = new MapPlayers(playerDefinitions.Nodes);
                    newData.PlayerCount = newData.Players.Players.Count(x => x.Value.Playable);
                }
            }
            catch (Exception)
            {
                newData.Status = MapStatus.Unavailable;
            }

            newData.SetRulesetGenerator(modData, () => {
                var ruleDefinitions          = LoadRuleSection(yaml, "Rules");
                var weaponDefinitions        = LoadRuleSection(yaml, "Weapons");
                var voiceDefinitions         = LoadRuleSection(yaml, "Voices");
                var musicDefinitions         = LoadRuleSection(yaml, "Music");
                var notificationDefinitions  = LoadRuleSection(yaml, "Notifications");
                var sequenceDefinitions      = LoadRuleSection(yaml, "Sequences");
                var modelSequenceDefinitions = LoadRuleSection(yaml, "ModelSequences");

                var rules = Ruleset.Load(modData, this, TileSet, ruleDefinitions, weaponDefinitions, voiceDefinitions, notificationDefinitions, musicDefinitions, sequenceDefinitions, modelSequenceDefinitions);

                var flagged = Ruleset.DefinesUnsafeCustomRules(modData, this, ruleDefinitions, weaponDefinitions, voiceDefinitions, notificationDefinitions, sequenceDefinitions);
                return(Pair.New(rules, flagged));
            });

            if (Package.Contains("map.png"))
            {
                using (var dataStream = p.GetStream("map.png"))
                    newData.Preview = BitmapFactory.DecodeStream(dataStream, null,
                                                                 new BitmapFactory.Options
                    {
                        InScaled           = false,
                        InDither           = false,
                        InJustDecodeBounds = false,
                        InPurgeable        = true,
                        InInputShareable   = true,
                    });
            }

            innerData = newData;
        }