Пример #1
0
        /*
         * Overwrites the tile's state based on the non-ignore values of the given TileData
         */
        internal void overWriteFromTileData(Mapfile.TileData data)
        {
            tileData.overWriteData(data);

            if (data.texture != Mapfile.TileData.IGNORESTRING && data.texture != texture.key)
            {
                texture = world.engine.resourceComponent.get(data.texture);
            }
            if (data.behavior != Mapfile.TileData.IGNORESTRING && (myBehavior == null || data.behavior != myBehavior.scriptKey))
            {
                myBehavior = world.constructTileBehavior(this, world.engine.resourceComponent.get(data.behavior));
            }
            if (data.solidity != Mapfile.TileData.IGNOREBYTE)
            {
                solidity = data.solidity == 1;
            }
            if (data.opacityFlip != Mapfile.TileData.IGNOREBYTE)
            {
                opacityFlip = data.opacityFlip == 1;
            }
            //if (data.leftSlope != MapFile.TileData.IGNOREFLOAT) leftSlope = data.leftSlope;
            //if (data.rightSlope != MapFile.TileData.IGNOREFLOAT) rightSlope = data.rightSlope;
            //if (data.normal != MapFile.TileData.IGNOREBYTE) normal = data.normal;
        }
Пример #2
0
        /**
         * desc here
         *
         * @param paramsdeschere
         *
         * @return returndeschere
         */
        public FillToolAction fill(Tile startTile)
        {
            Mapfile.TileData ignoreTile = new Mapfile.TileData();
            ignoreTile.setToIgnore();
            if (ignoreTile.Equals(fillCriteria))
            {
                return(null);
            }

            LinkedList <TextureData> changed = new LinkedList <TextureData>(); // for undo

            Mapfile.TileData std         = editor.engine.world.file.worldTileData[0, startTile.xIndex, startTile.yIndex];
            Mapfile.TileData tempCrit    = fillCriteria;
            bool             inSelection = false;

            if (!selectionBox.isDown && editor.selectionTool.selection.contains(new Vector2(startTile.xIndex, startTile.yIndex)))
            {
                inSelection = true;
            }

            tempCrit.overWriteData(std);

            //update actions
            Queue <Tile> applyToMe   = new Queue <Tile>();
            List <Tile>  appliedToMe = new List <Tile>();

            applyToMe.Enqueue(startTile);
            changed.AddLast(new TextureData(startTile.xIndex, startTile.yIndex));

            //Update start tile and its tiledata
            editor.engine.world.file.worldTileData[0, startTile.xIndex, startTile.yIndex].overWriteData(editor.currentTile);
            startTile.overWriteFromTileData(editor.currentTile);

            while (applyToMe.Count() > 0)
            {
                Tile mid = applyToMe.Dequeue();
                foreach (Tile tile in mid.adjacent)
                {
                    if (tile != null && !appliedToMe.Contains(tile))
                    {
                        Mapfile.TileData td = editor.engine.world.file.worldTileData[0, tile.xIndex, tile.yIndex];

                        bool apply = false;

                        //Constrain to opted criteria
                        if (opControl.pressed == (int)Operator.AND)
                        {
                            apply = td.Equals(tempCrit);
                        }
                        else if (opControl.pressed == (int)Operator.OR)
                        {
                            if (fillCriteria.texture != Mapfile.TileData.IGNORESTRING && td.texture == tempCrit.texture)
                            {
                                apply = true;
                            }
                            if (fillCriteria.solidity != Mapfile.TileData.IGNOREBYTE && td.solidity == tempCrit.solidity)
                            {
                                apply = true;
                            }
                            if (fillCriteria.opacityFlip != Mapfile.TileData.IGNOREBYTE && td.opacityFlip == tempCrit.opacityFlip)
                            {
                                apply = true;
                            }
                        }

                        //Constrain to selection border if opted
                        if (!selectionBox.isDown)
                        {
                            if (inSelection ^ editor.selectionTool.selection.contains(new Vector2(tile.xIndex, tile.yIndex)))
                            {
                                apply = false;
                            }
                        }

                        if (apply)
                        {
                            //Update actions
                            applyToMe.Enqueue(tile);
                            changed.AddLast(new TextureData(tile.xIndex, tile.yIndex));

                            //Update current tile and tiledata
                            editor.engine.world.file.worldTileData[0, tile.xIndex, tile.yIndex].overWriteData(editor.currentTile);
                            tile.overWriteFromTileData(editor.currentTile);
                        }
                    }
                    appliedToMe.Add(tile);
                }
            }
            return(new FillToolAction(changed, "", startTile, this));
        }