public static IEnumerable <Vector2d> NonCollidingTiles(AreaMeta area, IEnumerable <AreaMeta> allAreas, AreaMeta extraArea, bool useExtraArea)
        {
            // But not everything has to be removed so we get the limits relevant to the old gameplayArea considering
            var possibleCollidingAreas = allAreas;

            // If we use the extra area we add it to the set
            if (useExtraArea)
            {
                possibleCollidingAreas = possibleCollidingAreas.Union(new[] { extraArea });
            }

            // And finally we get the relevant limits (only overlapping limits)
            var limitsToConsiderBeforeRemoving = GetLimitsRelevantTo(possibleCollidingAreas, area).ToArray();

            // And finally we iterate over the limits where the tile is not contained in any limit
            foreach (var tile in TileUtil.Tiles(area.Limits).Where(t => !limitsToConsiderBeforeRemoving.Any(l => l.Contains(t))))
            {
                yield return(tile);
            }
        }
 public static IEnumerable <RectD> GetLimitsRelevantTo(IEnumerable <AreaMeta> areas, AreaMeta area)
 {
     // First we get the tile limits of all the other areas that use the same tiles
     return(areas
            .Where(a => a.Meta == area.Meta)
            .Select(a => a.Limits)
            // And then we optimize the check by only preserving the regions that intersect with new region we want to remove
            .Where(l => l.Intersects(area.Limits)));
 }
Beispiel #3
0
        public void StoreTiles(MapSceneDataControl mapSceneDataControl, bool displayProgressBar, System.Action <bool> callback)
        {
            StartProcess(mapSceneDataControl);

            if (displayProgressBar)
            {
                EditorUtility.DisplayProgressBar("Geo.TileManager.Progress.Title".Traslate(),
                                                 "Geo.TileManager.Calculating".Traslate(), 0);
            }

            var allAreas     = GetAllAreasExcept(mapSceneDataControl);
            var mapScene     = mapSceneDataControl.getContent() as MapScene;
            var previousArea = new AreaMeta(mapScene);
            var newArea      = new AreaMeta(mapSceneDataControl);
            var current      = new StorageProcess();

            storageProcesses[mapSceneDataControl] = current;

            // Get the tile metas to remove or to download if they exist
            current.toRemoveMeta   = TileProvider.Instance.GetTileMeta(mapScene.TileMetaIdentifier);
            current.toDownloadMeta = TileProvider.Instance.GetTileMeta(mapSceneDataControl.GameplayArea.TileMetaIdentifier);

            // We have to remove if there is gameplayArea based on the previous area and we must substract the new area if it's used
            current.toRemoveTiles = GetNonCollidingStorableTiles(mapScene.UsesGameplayArea, allAreas, previousArea,
                                                                 mapSceneDataControl.GameplayArea.UsesGameplayArea, newArea, current.toRemoveMeta);

            // We have to download if there is gameplayArea based on the new area and we must substract the old area if it's used
            current.toDownloadTiles = GetNonCollidingStorableTiles(mapSceneDataControl.GameplayArea.UsesGameplayArea, allAreas,
                                                                   newArea, mapScene.UsesGameplayArea, previousArea, current.toDownloadMeta);

            // In case any of them is null it means that we have no storer to use for any of the tiles
            if (current.toRemoveTiles == null || current.toDownloadTiles == null)
            {
                FinishProcess(mapSceneDataControl);
                callback(false);
                return;
            }

            RemoveAndDownloadTiles(mapSceneDataControl, new ProgressCallback(current.toRemoveTiles.Count + current.toDownloadTiles.Count * 2,
                                                                             (fase, progress, result) =>
            {
                bool cancel = false;
                if (displayProgressBar)
                {
                    if (fase == 0)
                    {
                        EditorUtility.DisplayProgressBar("Geo.TileManager.Progress.Title".Traslate(),
                                                         "Geo.TileManager.Removing".Traslate(), progress.Progress);
                    }
                    else if (fase == 1)
                    {
                        cancel = EditorUtility.DisplayCancelableProgressBar("Geo.TileManager.Progress.Title".Traslate(),
                                                                            "Geo.TileManager.Downloading".Traslate(), progress.Progress);
                    }
                    else if (fase == 2)
                    {
                        cancel = EditorUtility.DisplayCancelableProgressBar("Geo.TileManager.Progress.Title".Traslate(),
                                                                            "Geo.TileManager.Storing".Traslate(), progress.Progress);
                    }
                }

                if ((fase != 0 && !result) || cancel)
                {
                    FinishProcess(mapSceneDataControl);
                    callback(false);
                }

                if (progress.Progress >= 1f)
                {
                    FinishProcess(mapSceneDataControl);
                    callback(true);
                }
            }).Update);
        }
Beispiel #4
0
        private Dictionary <Vector3d, ITileStorer> GetNonCollidingStorableTiles(bool useArea, List <AreaMeta> allAreas, AreaMeta area, bool useExtraArea, AreaMeta extraArea, ITileMeta tileMeta)
        {
            var storableTiles = new Dictionary <Vector3d, ITileStorer>();

            if (!useArea)
            {
                return(storableTiles);
            }

            var nonCollidingTiles = TileUtil.NonCollidingTiles(area, allAreas, extraArea, useExtraArea).ToList();

            foreach (var tile in nonCollidingTiles)
            {
                var tile3d     = new Vector3d(tile.x, tile.y, 19);
                var tileStorer = tileStorers.Find(ts => ts.CanStoreTile(tile3d, tileMeta));
                if (tileStorer == null)
                {
                    Debug.LogError("Cannot find valid storer for tile " + tile3d);
                    return(null);
                }

                storableTiles.Add(tile3d, tileStorer);
            }

            return(storableTiles);
        }