Example #1
0
        public bool SetTile(TileCoordinates coordinates, Tile tile, FlatDirection direction = FlatDirection.North, bool notifyNeighbours = true)
        {
            var oldTile      = GetTile(coordinates);
            var oldDirection = oldTile.GetDirection(m_level, coordinates);

            if (tile != oldTile || direction != oldDirection)
            {
                int oldSubState = oldTile.GetSubState(m_level, coordinates);
                ExpandToFit(coordinates);
                SetTileInternal(coordinates, tile, direction, 0);
                if (m_latestTimeStamp > 0.0f)
                {
                    var change = new TileChange();
                    change.Type         = TileChangeType.Tile;
                    change.TimeStamp    = m_latestTimeStamp;
                    change.Coordinates  = coordinates;
                    change.OldTile      = oldTile;
                    change.OldDirection = oldDirection;
                    change.OldSubState  = oldSubState;
                    m_history.Push(change);
                }
                if (notifyNeighbours)
                {
                    tile.NotifyNeighboursChanged(m_level, coordinates);
                }
                return(true);
            }
            return(false);
        }
Example #2
0
    public override void HandleTile(TileChange tileChange, Action <TileChange> callback = null)
    {
        switch (tileChange.action)
        {
        case TileAction.Create:
            if (!tiles.ContainsKey(new Vector2Int(tileChange.X, tileChange.Y)))
            {
                Tile newTile = new Tile();
                tiles.Add(new Vector2Int(tileChange.X, tileChange.Y), newTile);

                StartCoroutine(GetAssetFromWebserver(tileChange, callback));
            }
            break;

        case TileAction.Upgrade:
            break;

        case TileAction.Downgrade:
            break;

        case TileAction.Remove:
            tiles.Remove(new Vector2Int(tileChange.X, tileChange.Y));
            callback(tileChange);
            break;

        default:
            callback(tileChange);
            break;
        }
    }
Example #3
0
        private IEnumerator SpawnLineObjects(SewerLines sewerLines, TileChange tileChange, Vector3RD boundingBoxMinimum, Vector3RD boundingBoxMaximum, Tile tile, System.Action <TileChange> callback = null)
        {
            tile.gameObject.SetActive(isEnabled);
            SewerLines.Feature sewerLineFeature;
            for (int i = 0; i < sewerLines.features.Length; i++)
            {
                if ((i % maxSpawnsPerFrame) == 0)
                {
                    yield return(new WaitForEndOfFrame());
                }

                sewerLineFeature = sewerLines.features[i];

                sewerPipeSpawner.CreateSewerLine(
                    sewerLineFeature.geometry.unity_coordinates[0],
                    sewerLineFeature.geometry.unity_coordinates[1],
                    float.Parse(sewerLineFeature.properties.diameter),
                    tile.gameObject
                    );
            }

            //Lines are done spawing. Start loading and spawing the manholes.
            StartCoroutine(GetSewerManholesInBoundingBox(tileChange, boundingBoxMinimum, boundingBoxMaximum, tile, callback));

            yield return(null);
        }
Example #4
0
        private IEnumerator SpawnManHoleObjects(string geoJSONtext, TileChange tileChange, Tile tile, System.Action <TileChange> callback = null)
        {
            tile.gameObject.SetActive(isEnabled);
            GeoJSON customJsonHandler = new GeoJSON(geoJSONtext);

            yield return(null);

            double[] point2D;
            Vector3  point;

            int parseCounter = 0;

            while (customJsonHandler.GotoNextFeature())
            {
                parseCounter++;
                if ((parseCounter % maxParsesPerFrame) == 0)
                {
                    yield return(new WaitForEndOfFrame());
                }
                if (customJsonHandler.PropertyValueStringEquals("objectsoort", "Knikpunt"))
                {
                    point2D = customJsonHandler.getGeometryPoint2DDouble();

                    double putdekselhoogte = customJsonHandler.getPropertyFloatValue("putdekselhoogte");
                    point = ConvertCoordinates.CoordConvert.WGS84toUnity(new Vector3WGS(point2D[0], point2D[1], putdekselhoogte + Config.activeConfiguration.zeroGroundLevelY));
                    sewerManholeSpawner.CreateManhole(point, 1.50f, tile.gameObject);
                }
            }
            StartCoroutine(CombineSewerage(tileChange, tile, callback));
        }
Example #5
0
        public TileChange Draw(Tile tile, List <Ship> ships)
        {
            var tileElement = new TileChange();

            var tileShip = ships.FirstOrDefault(item => item.Position == tile.Position);

            if (tileShip != null)
            {
                tileElement.BackgroundImageSrc = null;
                tileElement.BackgroundColor    = GetTeamColor(tileShip.TeamId);
            }
            else if (tile.Type == TileType.Water && tileElement.BackgroundImageSrc == null)
            {
                tileElement.BackgroundImageSrc = @"/Content/Fields/water.png";
                tileElement.BackgroundColor    = "Gray";
            }

            tileElement.Levels = new LevelChange[tile.Levels.Count];

            for (int i = 0; i < tile.Levels.Count; i++)
            {
                var level = tile.Levels[i];
                tileElement.Levels[i] = DrawPiratesAndCoins(level, i, tile.Levels.Count, tileShip);
            }
            DrawTileBackground(tile, tileShip, ref tileElement);

            return(tileElement);
        }
Example #6
0
        public bool SetSubState(TileCoordinates coordinates, int subState, bool notifyNeighbours)
        {
            var tile        = GetTile(coordinates);
            int oldSubState = tile.GetSubState(m_level, coordinates);

            if (subState != oldSubState)
            {
                ExpandToFit(coordinates);
                SetSubStateInternal(coordinates, subState);
                if (m_latestTimeStamp > 0.0f)
                {
                    var change = new TileChange();
                    change.Type        = TileChangeType.SubState;
                    change.TimeStamp   = m_latestTimeStamp;
                    change.Coordinates = coordinates;
                    change.OldSubState = oldSubState;
                    m_history.Push(change);
                }
                if (notifyNeighbours)
                {
                    tile.NotifyNeighboursChanged(m_level, coordinates);
                }
                return(true);
            }
            return(false);
        }
Example #7
0
        public void Generate(TileChange tileChange, Tile tile, System.Action <TileChange> callback = null)
        {
            napOffset = Config.activeConfiguration.zeroGroundLevelY;
            Vector3RD boundingBoxMinimum = new Vector3RD(tileChange.X, tileChange.Y, napOffset);
            Vector3RD boundingBoxMaximum = new Vector3RD(tileChange.X + tileSize, tileChange.Y + tileSize, napOffset);;

            StartCoroutine(GetSewerLinesInBoundingBox(tileChange, tile, boundingBoxMinimum, boundingBoxMaximum, callback));
        }
Example #8
0
 private void RedoTiles()
 {
     if (_historyService.RedoTiles.Count > 0)
     {
         TileChange redoTiles = _historyService.RedoTiles.Pop();
         _historyService.UndoTiles.Push(ApplyTileChange(redoTiles));
     }
 }
Example #9
0
        IEnumerator GetSewerLinesInBoundingBox(TileChange tileChange, Tile tile, Vector3RD boundingBoxMinimum, Vector3RD boundingBoxMaximum, System.Action <TileChange> callback = null)
        {
            yield return(null);

            yield return(new WaitUntil(() => activeCount < maxSimultaneous));

            activeCount++;
            tile.gameObject.SetActive(true);
            string escapedUrl = sewerPipesWfsUrl;

            escapedUrl += UnityWebRequest.EscapeURL((boundingBoxMinimum.x).ToString(CultureInfo.InvariantCulture) + "," + (boundingBoxMinimum.y).ToString(CultureInfo.InvariantCulture) + "," + (boundingBoxMaximum.x).ToString(CultureInfo.InvariantCulture) + "," + (boundingBoxMaximum.y).ToString(CultureInfo.InvariantCulture));
            var sewerageRequest = UnityWebRequest.Get(escapedUrl);

            yield return(sewerageRequest.SendWebRequest());

            if (!sewerageRequest.isNetworkError && !sewerageRequest.isHttpError)
            {
                GeoJSON customJsonHandler = new GeoJSON(sewerageRequest.downloadHandler.text);
                yield return(null);

                Vector3 startpoint;
                Vector3 endpoint;
                int     parseCounter = 0;
                while (customJsonHandler.GotoNextFeature())
                {
                    parseCounter++;
                    if ((parseCounter % maxParsesPerFrame) == 0)
                    {
                        yield return(null);
                    }
                    double        diameter     = customJsonHandler.getPropertyFloatValue("diameter");
                    double        bobBeginPunt = customJsonHandler.getPropertyFloatValue("bob_beginpunt");
                    List <double> coordinates  = customJsonHandler.getGeometryLineString();
                    endpoint = ConvertCoordinates.CoordConvert.WGS84toUnity(new Vector3WGS(coordinates[0], coordinates[1], bobBeginPunt + Config.activeConfiguration.zeroGroundLevelY));
                    for (int i = 2; i < coordinates.Count; i += 2)
                    {
                        startpoint = endpoint;
                        double bobEindPunt = customJsonHandler.getPropertyFloatValue("bob_eindpunt");
                        endpoint = ConvertCoordinates.CoordConvert.WGS84toUnity(new Vector3WGS(coordinates[i], coordinates[(i + 1)], bobEindPunt + Config.activeConfiguration.zeroGroundLevelY));

                        sewerPipeSpawner.CreateSewerLine(startpoint, endpoint, diameter, tile.gameObject);
                    }
                }
                StartCoroutine(GetSewerManholesInBoundingBox(tileChange, boundingBoxMinimum, boundingBoxMaximum, tile, callback));
            }
            else
            { //callback if weberror
                Debug.Log("sewerlinedata not found");
                activeCount--;
                callback(tileChange);
            }

            yield return(null);
        }
Example #10
0
 private void UndoChange(TileChange change)
 {
     ExpandToFit(change.Coordinates);
     if (change.Type == TileChangeType.Tile)
     {
         SetTileInternal(change.Coordinates, change.OldTile, change.OldDirection, change.OldSubState);
     }
     else
     {
         SetSubStateInternal(change.Coordinates, change.OldSubState);
     }
 }
Example #11
0
 private void setCurrentVars()
 {
     GameObject[] changableTiles = GameObject.FindGameObjectsWithTag("Changable Tiles");
     foreach (GameObject changable in changableTiles)
     {
         TileChange tiles = changable.GetComponent <TileChange>();
         if (tiles)
         {
             tileChanges.Add(tiles);
             numCurrentLevelTiles += tiles.getSizeTilePositions();
         }
     }
 }
Example #12
0
        private void RemoveTile(TileChange tileChange, System.Action <TileChange> callback = null)
        {
            Tile tile = tiles[new Vector2Int(tileChange.X, tileChange.Y)];

            MeshFilter[] meshFilters = tile.gameObject.GetComponents <MeshFilter>();
            foreach (var meshfilter in meshFilters)
            {
                Destroy(meshfilter.sharedMesh);
            }
            Destroy(tile.gameObject);
            tiles.Remove(new Vector2Int(tileChange.X, tileChange.Y));
            callback(tileChange);
        }
Example #13
0
        private Tile CreateNewTile(TileChange tileChange, System.Action <TileChange> callback = null)
        {
            Tile tile = new Tile();

            tile.LOD        = 0;
            tile.tileKey    = new Vector2Int(tileChange.X, tileChange.Y);
            tile.layer      = transform.gameObject.GetComponent <Layer>();
            tile.gameObject = new GameObject("sewerage-" + tileChange.X + "_" + tileChange.Y);
            tile.gameObject.transform.parent = transform.gameObject.transform;
            tile.gameObject.layer            = tile.gameObject.transform.parent.gameObject.layer;
            tile.gameObject.SetActive(false);
            Generate(tileChange, tile, callback);
            return(tile);
        }
    void Update()
    {
        if (Input.GetKey(KeyCode.RightControl) && Input.GetKeyDown(KeyCode.Z))
        {
            if (changes.Count > 0)
            {
                TileChange tc = changes.Pop();
                SetTile(tc.oldType, tc.position, false);
                revertedChanges.Push(tc);
            }
        }
        if (Input.GetKey(KeyCode.RightControl) && Input.GetKeyDown(KeyCode.Y))
        {
            if (revertedChanges.Count > 0)
            {
                TileChange tc = revertedChanges.Pop();
                SetTile(tc.newType, tc.position, false);
                changes.Push(tc);
            }
        }
        if (EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }
        Vector3    mousePosition3   = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        Vector3Int mousePositionInt = new Vector3Int(Mathf.FloorToInt(mousePosition3.x),
                                                     Mathf.Abs(Mathf.FloorToInt(mousePosition3.y)),
                                                     0
                                                     );

        if (mousePositionInt.x < 0 ||
            mousePositionInt.y < 0 ||
            mousePositionInt.x > Tiles.GetLength(0) - 1 ||
            mousePositionInt.y > Tiles.GetLength(1) - 1)
        {
            return;
        }
        if (Input.GetMouseButton(0) || Input.GetKey(KeyCode.Mouse0))
        {
            SetTile(CurrentTileType, mousePositionInt);
        }
        if (Input.GetMouseButton(1) || Input.GetKeyDown(KeyCode.Mouse1))
        {
            SetTile(TileType.Empty, mousePositionInt);
        }
    }
Example #15
0
        IEnumerator GetSewerManholesInBoundingBox(TileChange tileChange, Vector3RD boundingBoxMinimum, Vector3RD boundingBoxMaximum, Tile tile, System.Action <TileChange> callback = null)
        {
            string escapedUrl = sewerManholesWfsUrl;

            escapedUrl += UnityWebRequest.EscapeURL((boundingBoxMinimum.x).ToString(CultureInfo.InvariantCulture) + "," + (boundingBoxMinimum.y).ToString(CultureInfo.InvariantCulture) + "," + (boundingBoxMaximum.x).ToString(CultureInfo.InvariantCulture) + "," + (boundingBoxMaximum.y).ToString(CultureInfo.InvariantCulture));
            var sewerageRequest = UnityWebRequest.Get(escapedUrl);

            yield return(sewerageRequest.SendWebRequest());

            if (!sewerageRequest.isNetworkError && !sewerageRequest.isHttpError)
            {
                StartCoroutine(SpawnManHoleObjects(sewerageRequest.downloadHandler.text, tileChange, tile, callback));
            }
            else
            {
                activeCount--;
                callback(tileChange);
            }
            yield return(null);
        }
Example #16
0
        private void HandleTileRelease(MouseButtonEventArgs e)
        {
            Point mousePoint = Snap(e.GetPosition(WorldRenderSource));

            if (_drawMode == DrawMode.Default && _isDragging)
            {
                _isDragging = false;

                if (_selectionMode == SelectionMode.SetTiles)
                {
                    int columnStart = (int)(Math.Min(originalTilePoint.X, mousePoint.X) / 16);
                    int rowStart    = (int)(Math.Min(originalTilePoint.Y, mousePoint.Y) / 16);
                    int columnEnd   = (int)(Math.Max(originalTilePoint.X, mousePoint.X) / 16);
                    int rowEnd      = (int)(Math.Max(originalTilePoint.Y, mousePoint.Y) / 16);

                    TileChange tileChange = new TileChange(columnStart, rowStart, (columnEnd - columnStart) + 1, (rowEnd - rowStart) + 1);

                    for (int c = columnStart, i = 0; c <= columnEnd; c++, i++)
                    {
                        for (int r = rowStart, j = 0; r <= rowEnd; r++, j++)
                        {
                            tileChange.Data[i, j] = _worldDataAccessor.GetData(c, r);
                            _worldDataAccessor.SetData(c, r, TileSelector.SelectedBlockValue);
                        }
                    }

                    _historyService.UndoTiles.Push(tileChange);
                    _historyService.RedoTiles.Clear();

                    Update(new Rect(columnStart * 16, rowStart * 16, (columnEnd - columnStart + 1) * 16, (rowEnd - rowStart + 1) * 16));
                    SetSelectionRectangle(new Rect(mousePoint.X, mousePoint.Y, 16, 16));
                }
                else if (_selectionMode == SelectionMode.SelectTiles)
                {
                    if (SelectionRectangle.Width == 16 && SelectionRectangle.Height == 16)
                    {
                        _selectionMode = SelectionMode.SetTiles;
                    }
                }
            }
        }
        public override void HandleTile(TileChange tileChange, System.Action <TileChange> callback = null)
        {
            TileAction action  = tileChange.action;
            var        tileKey = new Vector2Int(tileChange.X, tileChange.Y);

            switch (action)
            {
            case TileAction.Create:
                Tile newTile = CreateNewTile(tileChange, callback);
                tiles.Add(tileKey, newTile);
                break;

            case TileAction.Remove:
                InteruptRunningProcesses(tileKey);
                RemoveTile(tileChange, callback);
                return;

            default:
                callback(tileChange);
                break;
            }
        }
Example #18
0
        public override void HandleTile(TileChange tileChange, System.Action <TileChange> callback = null)
        {
            TileAction action = tileChange.action;

            switch (action)
            {
            case TileAction.Create:
                Tile newTile = CreateNewTile(tileChange, callback);
                tiles.Add(new Vector2Int(tileChange.X, tileChange.Y), newTile);
                break;

            case TileAction.Remove:
                RemoveTile(tileChange, callback);
                tiles.Remove(new Vector2Int(tileChange.X, tileChange.Y));
                callback(tileChange);
                return;

            default:
                callback(tileChange);
                break;
            }
        }
Example #19
0
    IEnumerator GetAssetFromWebserver(TileChange tileChange, System.Action <TileChange> callback = null)
    {
        var x = tileChange.X;
        var y = tileChange.Y;

        var name = _replaceString.Replace("{x}", x.ToString()).Replace("{y}", y.ToString());

        if (_tiles.ContainsKey(name) == false)
        {
            Uri baseUri = new Uri(Config.activeConfiguration.webserverRootPath);
            var uri     = new Uri(baseUri, name);
            var tilepos = CoordConvert.RDtoUnity(new Vector3(x, y, 0));
            using (UnityWebRequest uwr = UnityWebRequestAssetBundle.GetAssetBundle(uri.AbsoluteUri))
            {
                yield return(uwr.SendWebRequest());

                if (!uwr.isNetworkError && !uwr.isHttpError)
                {
                    AssetBundle assetBundle = DownloadHandlerAssetBundle.GetContent(uwr);

                    // yield return new WaitUntil(() => pauseLoading == false);

                    var        mesh = assetBundle.LoadAllAssets <Mesh>().First();
                    GameObject gam  = new GameObject();
                    gam.transform.localScale = Vector3.one * _scale;
                    gam.name               = name;
                    gam.transform.parent   = transform;
                    gam.transform.position = tilepos + _offset;
                    gam.AddComponent <MeshFilter>().sharedMesh = mesh;
                    gam.AddComponent <MeshRenderer>().material = _material;

                    callback(tileChange);

                    _tiles.Add(name, gam);
                }
            }
        }
        callback(tileChange);
    }
        IEnumerator GetSewerManholesInBoundingBox(TileChange tileChange, Vector3RD boundingBoxMinimum, Vector3RD boundingBoxMaximum, Tile tile, System.Action <TileChange> callback = null)
        {
            string escapedUrl = Config.activeConfiguration.sewerManholesWfsUrl;

            escapedUrl += UnityWebRequest.EscapeURL($"{boundingBoxMinimum.x.ToInvariant()},{boundingBoxMinimum.y.ToInvariant()},{boundingBoxMaximum.x.ToInvariant()},{boundingBoxMaximum.y.ToInvariant()}");

            var sewerageRequest = UnityWebRequest.Get(escapedUrl);

            tile.runningWebRequest = sewerageRequest;
            yield return(sewerageRequest.SendWebRequest());

            tile.runningWebRequest = null;

            if (!sewerageRequest.isNetworkError && !sewerageRequest.isHttpError)
            {
                yield return(SpawnManHoleObjects(sewerageRequest.downloadHandler.text, tileChange, tile, callback));
            }
            else
            {
                callback(tileChange);
            }
            yield return(null);
        }
        private void RemoveTile(TileChange tileChange, System.Action <TileChange> callback = null)
        {
            var tileKey = new Vector2Int(tileChange.X, tileChange.Y);

            if (tiles.ContainsKey(tileKey))
            {
                Tile tile = tiles[tileKey];
                if (tile.gameObject)
                {
                    MeshFilter[] meshFilters = tile.gameObject.GetComponents <MeshFilter>();

                    foreach (var meshfilter in meshFilters)
                    {
                        Destroy(meshfilter.sharedMesh);
                    }

                    Destroy(tile.gameObject);
                }

                tiles.Remove(tileKey);
            }
            callback(tileChange);
        }
Example #22
0
        private TileChange ApplyTileChange(TileChange tileChange)
        {
            int columnStart = tileChange.X;
            int rowStart    = tileChange.Y;
            int columnEnd   = tileChange.X + tileChange.Width;
            int rowEnd      = tileChange.Y + tileChange.Height;

            TileChange reverseTileChange = new TileChange(columnStart, rowStart, columnEnd - columnStart, rowEnd - rowStart);

            for (int c = columnStart, i = 0; c < columnEnd; c++, i++)
            {
                for (int r = rowStart, j = 0; r < rowEnd; r++, j++)
                {
                    if (tileChange.Data[i, j] > -1)
                    {
                        reverseTileChange.Data[i, j] = _worldDataAccessor.GetData(c, r);
                        _worldDataAccessor.SetData(c, r, tileChange.Data[i, j]);
                    }
                }
            }

            Update(new Rect(columnStart * 16, rowStart * 16, (columnEnd - columnStart) * 16, (rowEnd - rowStart) * 16));
            return(reverseTileChange);
        }
Example #23
0
        private void HandleTileClick(MouseButtonEventArgs e)
        {
            Point clickPoint = Snap(e.GetPosition(WorldRenderSource));

            if (e.LeftButton == MouseButtonState.Pressed)
            {
                int x = (int)(clickPoint.X / 16), y = (int)(clickPoint.Y / 16);
                int tileValue = _worldDataAccessor.GetData(x, y);

                if (Keyboard.Modifiers == ModifierKeys.Shift)
                {
                    TileSelector.SelectedBlockValue = tileValue;
                    return;
                }

                _selectionMode = SelectionMode.SetTiles;

                if (_drawMode == DrawMode.Default)
                {
                    _dragStartPoint   = clickPoint;
                    _isDragging       = true;
                    originalTilePoint = clickPoint;
                }
                else if (_drawMode == DrawMode.Replace)
                {
                    if (tileValue != TileSelector.SelectedBlockValue)
                    {
                        _worldDataAccessor.ReplaceValue(tileValue, TileSelector.SelectedBlockValue);
                        Update();
                    }
                }
                else if (_drawMode == DrawMode.Fill)
                {
                    Stack <Point> stack = new Stack <Point>();
                    stack.Push(new Point(x, y));

                    int checkValue = _worldDataAccessor.GetData(x, y);
                    if (checkValue == TileSelector.SelectedBlockValue)
                    {
                        return;
                    }

                    int lowestX, highestX;
                    int lowestY, highestY;

                    lowestX = highestX = x;
                    lowestY = highestY = y;

                    while (stack.Count > 0)
                    {
                        Point point = stack.Pop();

                        int i = (int)(point.X);
                        int j = (int)(point.Y);

                        if (checkValue == _worldDataAccessor.GetData(i, j))
                        {
                            _worldDataAccessor.SetData(i, j, TileSelector.SelectedBlockValue);

                            if (i < lowestX)
                            {
                                lowestX = i;
                            }
                            if (i > highestX)
                            {
                                highestX = i;
                            }
                            if (j < lowestY)
                            {
                                lowestY = j;
                            }
                            if (j > highestY)
                            {
                                highestY = j;
                            }

                            stack.Push(new Point(i + 1, j));
                            stack.Push(new Point(i - 1, j));
                            stack.Push(new Point(i, j + 1));
                            stack.Push(new Point(i, j - 1));
                        }
                    }

                    TileChange tileChange = new TileChange(lowestX, lowestY, highestX - lowestX + 1, highestY - lowestY + 1);

                    for (int j = 0, row = lowestY; row <= highestY; row++, j++)
                    {
                        for (int i = 0, col = lowestX; col <= highestX; col++, i++)
                        {
                            tileChange.Data[i, j] = _worldDataAccessor.GetData(col, row) == TileSelector.SelectedBlockValue ? checkValue : -1;
                        }
                    }

                    _historyService.UndoTiles.Push(tileChange);

                    Update(new Rect(lowestX * 16, lowestY * 16, (highestX - lowestX + 1) * 16, (highestY - lowestY + 1) * 16));
                }
            }
            else if (e.RightButton == MouseButtonState.Pressed)
            {
                _selectionMode = SelectionMode.SelectTiles;

                int x = (int)(clickPoint.X / 16), y = (int)(clickPoint.Y / 16);

                _dragStartPoint   = clickPoint;
                _isDragging       = true;
                originalTilePoint = clickPoint;

                SetSelectionRectangle(new Rect(x * 16, y * 16, 16, 16));
            }
        }
Example #24
0
        private IEnumerator CombineSewerage(TileChange tileChange, Tile tile, System.Action <TileChange> callback = null)
        {
            int parseCounter = 0;

            //Do not try to combine if our gameobject was already destroyed.
            if (!tile.gameObject)
            {
                activeCount--;
                callback(tileChange);
                tile.gameObject.SetActive(isEnabled);
                yield break;
            }

            //Determine meshes to combine
            MeshFilter[]      meshFilters = tile.gameObject.GetComponentsInChildren <MeshFilter>(true);
            CombineInstance[] combine     = new CombineInstance[meshFilters.Length];
            int i = 0;

            while (i < meshFilters.Length)
            {
                combine[i].mesh      = meshFilters[i].sharedMesh;
                combine[i].transform = meshFilters[i].transform.localToWorldMatrix;
                //meshFilters[i].gameObject.SetActive(false);

                i++;
            }

            //Own combined mesh
            GameObject newCombinedTile = new GameObject();

            newCombinedTile.name = "CombinedTile";
            newCombinedTile.transform.SetParent(tile.gameObject.transform);
            newCombinedTile.AddComponent <MeshRenderer>().material = sharedMaterial;

            Mesh newMesh = new Mesh
            {
                indexFormat = UnityEngine.Rendering.IndexFormat.UInt32
            };

            newMesh.CombineMeshes(combine);
            newCombinedTile.AddComponent <MeshFilter>().sharedMesh = newMesh;

            //Now destroy our large amount of network children.

            GameObject childObject;

            for (int j = tile.gameObject.transform.childCount - 1; j >= 0; j--)
            {
                parseCounter++;
                if ((parseCounter % maxParsesPerFrame) == 0)
                {
                    yield return(new WaitForEndOfFrame());
                }
                childObject = tile.gameObject.transform.GetChild(j).gameObject;

                if (childObject.name[0] == 'S')
                {
                    SewerLineObjectPool.ReturnObject(childObject);
                }
                else if (childObject.name[0] == 'M')
                {
                    manHoleObjectPool.ReturnObject(childObject);
                }
            }

            callback(tileChange);
            activeCount--;
            tile.gameObject.SetActive(isEnabled);
        }
Example #25
0
        private void DrawTileBackground(Tile tile, Ship ship, ref TileChange tileChange)
        {
            TileType type = tile.Type;

            // не зарисовываем корабль водой
            if (ship != null)
            {
                return;
            }

            // после открытия поля - фон не меняется
            //if (type != TileType.Unknown)
            //{
            //  return;
            //}

            int rotateCount = 0;

            string filename;

            switch (type)
            {
            case TileType.Unknown:
                tileChange.IsUnknown = true;
                filename             = @"back";
                break;

            case TileType.Water:
                filename = @"water";
                break;

            case TileType.Grass:
                filename = @"empty1";
                break;

            case TileType.Chest1:
                filename = @"chest1";
                break;

            case TileType.Chest2:
                filename = @"chest2";
                break;

            case TileType.Chest3:
                filename = @"chest3";
                break;

            case TileType.Chest4:
                filename = @"chest4";
                break;

            case TileType.Chest5:
                filename = @"chest5";
                break;

            case TileType.Fort:
                filename = @"fort";
                break;

            case TileType.RespawnFort:
                filename = @"respawn";
                break;

            case TileType.RumBarrel:
                filename = @"rumbar";
                break;

            case TileType.Horse:
                filename = @"horse";
                break;

            case TileType.Cannon:
                filename    = @"cannon";
                rotateCount = tile.CannonDirection;
                break;

            case TileType.Croc:
                filename = @"croc";
                break;

            case TileType.Airplane:
                filename = @"airplane";
                break;

            case TileType.Balloon:
                filename = @"balloon";
                break;

            case TileType.Ice:
                filename = @"ice";
                break;

            case TileType.Trap:
                filename = @"trap";
                break;

            case TileType.Canibal:
                filename = @"canibal";
                break;

            case TileType.Spinning:
                switch (tile.SpinningCount)
                {
                case 2:
                    filename = "forest";
                    break;

                case 3:
                    filename = "desert";
                    break;

                case 4:
                    filename = "swamp";
                    break;

                case 5:
                    filename = "mount";
                    break;

                default:
                    throw new NotSupportedException();
                }
                break;

            case TileType.Arrow:
                var search = ArrowsCodesHelper.Search(tile.ArrowsCode);
                rotateCount = search.RotateCount;
                int fileNumber = (search.ArrowType + 1);
                filename = @"arrow" + fileNumber;
                break;

            default:
                throw new NotSupportedException();
            }

            string relativePath = string.Format(@"/Content/Fields/{0}.png", filename);

            tileChange.BackgroundImageSrc = relativePath;
            tileChange.Rotate             = rotateCount;
        }
Example #26
0
        private void PasteSelection()
        {
            if (_copyBuffer != null)
            {
                int startX       = (int)((Canvas.GetLeft(SelectionRectangle) + 2) / 16);
                int endX         = (int)((SelectionRectangle.Width - 4) / 16) + startX;
                int startY       = (int)((Canvas.GetTop(SelectionRectangle) + 2) / 16);
                int endY         = (int)((SelectionRectangle.Height - 4) / 16) + startY;
                int bufferWidth  = _copyBuffer.GetLength(0);
                int bufferHeight = _copyBuffer.GetLength(1);

                TileChange tileChange;

                if (startX + bufferWidth > Level.BLOCK_WIDTH)
                {
                    bufferWidth = Level.BLOCK_WIDTH - startX;
                }

                if (startY + bufferHeight > Level.BLOCK_HEIGHT)
                {
                    bufferHeight = Level.BLOCK_HEIGHT - startY;
                }

                if (SelectionRectangle.Width == 20 &&
                    SelectionRectangle.Height == 20)
                {
                    tileChange = new TileChange(startX, startY, bufferWidth, bufferHeight);

                    for (int r = startY, y = 0; y < bufferHeight; r++, y++)
                    {
                        for (int c = startX, x = 0; x < bufferWidth; c++, x++)
                        {
                            tileChange.Data[x, y] = _worldDataAccessor.GetData(c, r);
                            _worldDataAccessor.SetData(c, r, _copyBuffer[x % bufferWidth, y % bufferHeight]);
                        }
                    }

                    Update(new Rect(startX * 16, startY * 16, bufferWidth * 16, bufferHeight * 16));
                }
                else
                {
                    tileChange = new TileChange(startX, startY, endX - startX, endY - startY);

                    for (int r = startY, y = 0; r < endY; r++, y++)
                    {
                        for (int c = startX, x = 0; c < endX; c++, x++)
                        {
                            tileChange.Data[x, y] = _worldDataAccessor.GetData(c, r);

                            _worldDataAccessor.SetData(c, r, _copyBuffer[x % bufferWidth, y % bufferHeight]);
                        }
                    }

                    Update(new Rect(Canvas.GetLeft(SelectionRectangle) + 2,
                                    Canvas.GetTop(SelectionRectangle) + 2,
                                    (SelectionRectangle.Width - 4),
                                    (SelectionRectangle.Height - 4)));
                }

                _historyService.UndoTiles.Push(tileChange);

                _selectionMode = SelectionMode.SetTiles;
                SetSelectionRectangle(new Rect(_dragStartPoint.X, _dragStartPoint.Y, 16, 16));
            }
        }
	public void SetTiles(TileChange[] changes)
	{
		foreach(TileChange change in changes)
		{
			SetTileInternal(change.pos.x, change.pos.y, change.newTile);
		}
		TileLayerUtil.RedrawGroupForChanges(this, changes);
	}
        IEnumerator GetSewerLinesInBoundingBox(TileChange tileChange, Tile tile, Vector3RD boundingBoxMinimum, Vector3RD boundingBoxMaximum, System.Action <TileChange> callback = null)
        {
            yield return(new WaitForEndOfFrame());

            var ownCoroutine = tile.runningCoroutine;

            yield return(new WaitUntil(() => CoroutineSlotsAvailable()));

            coroutinesWaiting[ownCoroutine] = false;

            string escapedUrl = Config.activeConfiguration.sewerPipesWfsUrl;

            escapedUrl += UnityWebRequest.EscapeURL($"{boundingBoxMinimum.x.ToInvariant()},{boundingBoxMinimum.y.ToInvariant()},{boundingBoxMaximum.x.ToInvariant()},{boundingBoxMaximum.y.ToInvariant()}");

            var sewerageRequest = UnityWebRequest.Get(escapedUrl);

            tile.runningWebRequest = sewerageRequest;
            yield return(sewerageRequest.SendWebRequest());

            tile.runningWebRequest = null;

            if (!sewerageRequest.isNetworkError && !sewerageRequest.isHttpError)
            {
                GeoJSON customJsonHandler = new GeoJSON(sewerageRequest.downloadHandler.text);

                yield return(null);

                Vector3 startpoint;
                Vector3 endpoint;
                int     parseCounter = 0;

                while (customJsonHandler.GotoNextFeature())
                {
                    parseCounter++;
                    if ((parseCounter % maxParsesPerFrame) == 0)
                    {
                        yield return(null);
                    }
                    double diameter     = customJsonHandler.getPropertyFloatValue(DiameterString);
                    double bobBeginPunt = customJsonHandler.getPropertyFloatValue(BobBeginPuntString);

                    List <double> coordinates = customJsonHandler.getGeometryLineString();
                    endpoint = GetUnityPoint(coordinates[0], coordinates[1], bobBeginPunt + Config.activeConfiguration.zeroGroundLevelY);

                    for (int i = 2; i < coordinates.Count; i += 2)
                    {
                        startpoint = endpoint;
                        double bobEindPunt = customJsonHandler.getPropertyFloatValue(BobEindPuntString);

                        endpoint = GetUnityPoint(coordinates[i], coordinates[(i + 1)], bobEindPunt + Config.activeConfiguration.zeroGroundLevelY);
                        sewerPipeSpawner.CreateSewerLine(startpoint, endpoint, diameter, tile.gameObject);
                    }
                }
                yield return(GetSewerManholesInBoundingBox(tileChange, boundingBoxMinimum, boundingBoxMaximum, tile, callback));
            }
            else
            {             //callback if weberror
                Debug.Log("sewerlinedata not found");
                callback(tileChange);
            }

            if (coroutinesWaiting.ContainsKey(ownCoroutine))
            {
                coroutinesWaiting.Remove(ownCoroutine);
            }

            yield return(null);
        }
	public void SetTile(TileChange change)
	{
		SetTileInternal(change.pos.x, change.pos.y, change.newTile);
		TileLayerUtil.RedrawGroupForChange(this, change);
	}
Example #30
0
    public static void RedrawGroupForChange(TileLayer layer, TileChange change)
    {
        GroupPos group = TileToGroup(layer, change.pos);

        RedrawGroup(layer, group.x, group.y);
    }
Example #31
0
 /// <summary>
 /// Resets this instance.
 /// </summary>
 public void Reset()
 {
     Events.Clear();
     EntityChange.Clear();
     TileChange.Clear();
 }
Example #32
0
 void OnChangeState( TileChange change )
 {
     if ( evolve )
         return;
     switch ( change )
     {
         case TileChange.ADDLIVE:
             foreach ( Tile tile in SelectedTiles.Selection )
             {
                 CurrentState [ tile.X , tile.Y ] = TileType.LIVE;
                 tile.Type = TileType.LIVE;
             }
             break;
         case TileChange.KILL:
             foreach ( Tile tile in SelectedTiles.Selection )
             {
                 CurrentState [ tile.X , tile.Y ] = TileType.DEAD;
                 tile.Type = TileType.DEAD;
             }
             break;
         default:
             break;
     }
 }
 public void SetTile(TileChange change)
 {
     SetTileInternal(change.pos.x, change.pos.y, change.newTile);
     TileLayerUtil.RedrawGroupForChange(this, change);
 }