示例#1
0
        /// <summary>
        /// Finds sector by location in the named milieu (using default/fallbacks if null)
        /// </summary>
        /// <param name="x">Sector x coordinate</param>
        /// <param name="y">Sector y coordinate</param>
        /// <param name="milieu">Milieu name, null for default</param>
        /// <returns>Sector if found, or null</returns>
        private Sector FromLocation(Point pt, string milieu, bool useMilieuFallbacks = false)
        {
            Sector sector = SelectMilieux(milieu)
                            .Select(map => map.FromLocation(pt))
                            .Where(sec => sec != null && (useMilieuFallbacks || !(sec is Dotmap)))
                            .FirstOrDefault();

            if (sector != null || milieu == null || !useMilieuFallbacks)
            {
                return(sector);
            }

            // Fall back to default milieu and produce a dotmap
            sector = FromLocation(pt, null);
            if (sector == null)
            {
                return(null);
            }
            sector = new Dotmap(sector);

            // Remember it, if milieu is known.
            if (milieux.ContainsKey(milieu))
            {
                milieux[milieu].TryAdd(sector);
            }

            return(sector);
        }
示例#2
0
        /// <summary>
        /// Finds sector by location in the named milieu (using default/fallbacks if null)
        /// </summary>
        /// <param name="x">Sector x coordinate</param>
        /// <param name="y">Sector y coordinate</param>
        /// <param name="milieu">Milieu name, null for default</param>
        /// <returns>Sector if found, or null</returns>
        private Sector FromLocation(Point pt, string milieu, bool useMilieuFallbacks = false)
        {
            if (sectors == null)
            {
                throw new MapNotInitializedException();
            }
            Sector sector = SelectMilieux(milieu)
                            .Select(m => m.FromLocation(pt))
                            .Where(s => s != null && (useMilieuFallbacks || !(s is Dotmap)))
                            .FirstOrDefault();

            if (sector != null || milieu == null || !useMilieuFallbacks)
            {
                return(sector);
            }
            sector = FromLocation(pt, null);
            if (sector == null)
            {
                return(null);
            }
            sector = new Dotmap(sector);
            if (milieux.ContainsKey(milieu))
            {
                milieux[milieu].Add(sector);
            }
            return(sector);
        }