Ejemplo n.º 1
0
    public void TestTransformIntoLake()
    {
        // We actually load the tile into the tile instance
        string suburbs_description = "{\"name\": \"Suburbs\", \"triggers\": [], \"color\": \"GREEN\", \"price\": 3, \"number\": \"0\", \"immediate\": {\"resource\": \"POPULATION\", \"value\": 2}, \"letter\": \"BASE\", \"icon\": \"NONE\"}";

        suburbs = new TileInstance(Tile.LoadFromJson(JSON.Parse(suburbs_description) as JSONClass));
        Assert.AreEqual("Suburbs", suburbs.description.name);

        suburbs.SwitchWithLake();
        Assert.AreEqual("Lake", suburbs.description.name);

        suburbs.SwitchWithLake();
        Assert.AreEqual("Suburbs", suburbs.description.name);

        suburbs.TransformIntoLake();
        Assert.AreEqual("Lake", suburbs.description.name);

        suburbs.TransformIntoLake();
        Assert.AreEqual("Lake", suburbs.description.name);

        suburbs.ResetFromLake();
        Assert.AreEqual("Suburbs", suburbs.description.name);

        suburbs.ResetFromLake();
        Assert.AreEqual("Suburbs", suburbs.description.name);
    }
Ejemplo n.º 2
0
    public void Init()
    {
        player       = new Player();
        player_other = new Player();

        // We create the first three base tiles instances for both players
        suburbs       = new TileInstance();
        suburbs.owner = player;
        park          = new TileInstance();
        park.owner    = player;
        factory       = new TileInstance();
        factory.owner = player;

        suburbs.position = new TilePosition(0, 0);
        park.position    = new TilePosition(0, 2);
        factory.position = new TilePosition(0, 4);


        suburbs_other       = new TileInstance();
        suburbs_other.owner = player_other;
        park_other          = new TileInstance();
        park_other.owner    = player_other;
        factory_other       = new TileInstance();
        factory_other.owner = player_other;

        suburbs_other.position = new TilePosition(0, 0);
        park_other.position    = new TilePosition(0, 2);
        factory_other.position = new TilePosition(0, 4);
    }
Ejemplo n.º 3
0
    public void TestAssignOwner()
    {
        TileInstance instance = new TileInstance();
        TilePosition position = new TilePosition(0, 0);
        Player       player   = new Player();

        Assert.AreEqual(0, player.tiles.Count);

        instance.owner    = player;
        instance.position = position;
        Assert.AreEqual(player, instance.owner);
        Assert.AreEqual(1, player.tiles.Count);
        Assert.AreEqual(true, player.tiles.Contains(instance));

        // And now the other way around
        instance          = new TileInstance();
        player            = new Player();
        instance.position = position;

        Assert.AreEqual(0, player.tiles.Count);

        player.AddTileInstance(instance);
        Assert.AreEqual(player, instance.owner);
        Assert.AreEqual(1, player.tiles.Count);
        Assert.AreEqual(true, player.tiles.Contains(instance));
    }
Ejemplo n.º 4
0
 public void HandleClickOnTileFromREM(EventClickOnTileFromREM p_event)
 {
     if(m_current_tile_chosen != null)
         m_current_tile_chosen.ResetFromLake();
     m_current_tile_chosen = p_event.tile;
     m_index_in_REM = p_event.index_in_REM;
 }
Ejemplo n.º 5
0
        public override Component CreateCollider(Vector3 position, TileInstance tile)
        {
            var obj = pool.RequestInstance();

            obj.transform.position = position + config.offset;
            return(obj.GetComponent <MeshCollider>());
        }
Ejemplo n.º 6
0
 public void AddSubscriber(TileInstance p_tile)
 {
     foreach (TriggerInstance trigger in p_tile.triggers)
     {
         AddSubscriber(trigger);
     }
 }
Ejemplo n.º 7
0
 public EventResourceAdjustment(Player p_player, ETileResource p_resource, int p_value, TileInstance p_tile)
 {
     m_player   = p_player;
     m_resource = p_resource;
     m_value    = p_value;
     m_tile     = p_tile;
 }
Ejemplo n.º 8
0
    public void HandleClickOnFreePosition(EventClickOnFreePosition p_event)
    {
        // The tile has been placed, we emit the tile played event.
        if (m_current_tile_chosen != null)
        {
            int tile_price = Suburbia.Market.PriceOverheadForTileNumber(this.m_index_in_REM)
                             + m_current_tile_chosen.description.price;

            if (Suburbia.ActivePlayer.money >= tile_price)
            {
                // We place the new tile on the player ground :
                m_current_tile_chosen.position = p_event.position;
                Suburbia.ActivePlayer.AddTileInstance(m_current_tile_chosen);
                Suburbia.Bus.FireEvent(new EventSendTileToPosition(Suburbia.ActivePlayer, p_event.position, m_index_in_REM));

                // Transmit sub events.
                Suburbia.Bus.FireEvent(new EventRemoveFreePositionOfPlayer(Suburbia.ActivePlayer));
                Suburbia.Bus.FireEvent(new EventTilePlayed(this.m_current_tile_chosen,
                                                           Suburbia.Market.PriceOverheadForTileNumber(this.m_index_in_REM)));
                // We remove the tile in the REM.
                Suburbia.Market.RemoveTile(this.m_index_in_REM);
                m_current_tile_chosen = null;
            }
            // Otherwise we tell him he can't play the tile !
            else
            {
                Debug.LogError("Can't play the tile bro !");
            }
        }
    }
Ejemplo n.º 9
0
    public void TestHandleTilePlayed()
    {
        player.money      = 20;
        player.income     = 0;
        player.reputation = 0;
        manager.AddPlayer(player);
        manager.AddSubscriber(suburbs);
        manager.AddSubscriber(park);
        manager.AddSubscriber(factory);

        player_other.income     = 0;
        player_other.reputation = 0;
        manager.AddPlayer(player_other);
        manager.AddSubscriber(suburbs_other);
        manager.AddSubscriber(park_other);
        manager.AddSubscriber(factory_other);

        // We add a Park on the right between the park and the factory
        TileInstance park_new = new TileInstance(park_);

        park_new.position = new TilePosition(1, 3);
        park_new.owner    = player;

        // We fire the event linked to the new tile being played
        Suburbia.Bus.FireEvent(new EventTilePlayed(park_new, 4));
        Assert.AreEqual(12, player.money);           // The player paid the tile
        Assert.AreEqual(-1, player.income);          // Immediate effect of the new park
        Assert.AreEqual(0, player.reputation);       // The reputation effects of the new park and the factory negate each other
        Assert.AreEqual(0, player_other.income);
        Assert.AreEqual(0, player_other.reputation); // Other player was not affected
    }
Ejemplo n.º 10
0
    private void DrawTile(TileInstance tile, Vector2 pos)
    {
        TileLayer layer = target as TileLayer;

        if (layer == null)
        {
            return;
        }
        if (layer.material == null)
        {
            return;
        }

        if (pos.x < 0 || pos.y < 0 || pos.x >= layer.layerSize.x || pos.y >= layer.layerSize.y)
        {
            return;
        }

        if (layer.tileData == null || layer.tileData.Length != (int)layer.layerSize.x * (int)layer.layerSize.y)
        {
            layer.tileData = new TileInstance[(int)layer.layerSize.x * (int)layer.layerSize.y];

            for (int i = 0; i < layer.tileData.Length; i++)
            {
                layer.tileData[i] = new TileInstance(-1);
            }
        }

        layer.tileData[(int)pos.x + (int)pos.y * (int)layer.layerSize.x] = new TileInstance(tile.id, tile.rotation, tile.flippedHorizontally, tile.flippedVertically);

        int groupX = (int)Mathf.Floor((float)pos.x / (float)layer.groupSize.x);
        int groupY = (int)Mathf.Floor((float)pos.y / (float)layer.groupSize.y);

        TileLayerUtil.RedrawGroup(layer, groupX, groupY);
    }
Ejemplo n.º 11
0
    public void TestWaterfrontRealty()
    {
        // We add a lake on the right of the park and the suburbs
        string       lake_description = "{\"name\": \"Lake\", \"triggers\": [{\"scope\": \"ADJACENT\", \"when\": \"ALWAYS\", \"effect\": {\"resource\": \"MONEY\", \"value\": 2}, \"type\": \"YELLOW\"}, {\"scope\": \"ADJACENT\", \"when\": \"ALWAYS\", \"effect\": {\"resource\": \"MONEY\", \"value\": 2}, \"type\": \"GREY\"}, {\"scope\": \"ADJACENT\", \"when\": \"ALWAYS\", \"effect\": {\"resource\": \"MONEY\", \"value\": 2}, \"type\": \"GREEN\"}, {\"scope\": \"ADJACENT\", \"when\": \"ALWAYS\", \"effect\": {\"resource\": \"MONEY\", \"value\": 2}, \"type\": \"BLUE\"}], \"color\": \"LAKE\", \"price\": 0, \"number\": 0, \"immediate\": \"NONE\", \"letter\": \"BASE\", \"icon\": \"NONE\"}";
        Tile         description      = GetTileFromString(lake_description);
        TileInstance lake             = new TileInstance(description);

        lake.position = new TilePosition(1, 1);
        lake.owner    = player;

        player.money = 20;
        manager.AddPlayer(player);
        manager.AddSubscriber(suburbs);
        manager.AddSubscriber(park);
        manager.AddSubscriber(factory);
        Suburbia.Bus.FireEvent(new EventTilePlayed(lake, 0));
        Assert.AreEqual(24, player.money);  // 20 (starting money) + 4 (2 adjacent tiles to lake)

        // We add a waterfront realty
        string       waterfront_description = "{\"name\": \"Waterfront Realty\", \"triggers\": [{\"scope\": \"ADJACENT_TO_OWN_LAKE\", \"when\": \"ALWAYS\", \"effect\": {\"resource\": \"MONEY\", \"value\": 2}, \"type\": \"YELLOW\"}, {\"scope\": \"ADJACENT_TO_OWN_LAKE\", \"when\": \"ALWAYS\", \"effect\": {\"resource\": \"MONEY\", \"value\": 2}, \"type\": \"GREY\"}, {\"scope\": \"ADJACENT_TO_OWN_LAKE\", \"when\": \"ALWAYS\", \"effect\": {\"resource\": \"MONEY\", \"value\": 2}, \"type\": \"GREEN\"}, {\"scope\": \"ADJACENT_TO_OWN_LAKE\", \"when\": \"ALWAYS\", \"effect\": {\"resource\": \"MONEY\", \"value\": 2}, \"type\": \"BLUE\"}], \"color\": \"BLUE\", \"price\": 6, \"number\": 2, \"immediate\": \"NONE\", \"letter\": \"A\", \"icon\": \"NONE\"}";
        Tile         description_           = GetTileFromString(waterfront_description);
        TileInstance waterfront_realty      = new TileInstance(description_);

        waterfront_realty.position = new TilePosition(0, 6);
        waterfront_realty.owner    = player;

        Suburbia.Bus.FireEvent(new EventTilePlayed(waterfront_realty, 0));
        Assert.AreEqual(22, player.money);  // 20 (starting money) - 6 (cost of tile) + 8 (2 adjacent tiles to lake + waterfront realty)
    }
Ejemplo n.º 12
0
    public void TestHandleRedLinePassed()
    {
        player.income     = 0;
        player.reputation = 0;
        manager.AddPlayer(player);

        // We add a casino to player's burrough
        string       casino_description = "{\"name\": \"Casino\", \"triggers\": [{\"scope\": \"NONE\", \"when\": \"AFTER_RED_LINE\", \"effect\": {\"resource\": \"INCOME\", \"value\": 1}, \"type\": \"NONE\"}], \"color\": \"BLUE\", \"price\": 22, \"number\": 2, \"immediate\": {\"resource\": \"REPUTATION\", \"value\": -3}, \"letter\": \"B\", \"icon\": \"NONE\"}";
        Tile         description        = GetTileFromString(casino_description);
        TileInstance casino             = new TileInstance(description);

        casino.position = new TilePosition(0, 6);
        casino.owner    = player;
        manager.AddSubscriber(casino);

        // player passes 3 red lines backward
        Suburbia.Bus.FireEvent(new EventRedLine(player, -3));
        // And nothing happens
        Assert.AreEqual(0, player.income);
        Assert.AreEqual(0, player.reputation);

        // player passes 3 red lines forward
        Suburbia.Bus.FireEvent(new EventRedLine(player, 3));
        // And it triggers the casino's effect
        Assert.AreEqual(3, player.income);
        Assert.AreEqual(0, player.reputation);

        player.income = 0;

        //And now we don't directly fire the event, we adjust the player's population
        player.population = 22;
        Assert.AreEqual(0, player.income);      // the casino's effect negated the red line
        Assert.AreEqual(-2, player.reputation); // but the reputation did take a hit
    }
Ejemplo n.º 13
0
    public TileInstance PopNextTile()
    {
        if (m_tilesA.Count == 0)
        {
            if (m_tilesB.Count == 0)
            {
                if (m_tilesC.Count == 0)
                {
                    return(null);
                }

                TileInstance tile = m_tilesC.Pop();

                if (tile is TileInstanceOneMoreRound)
                {
                    // Last Turn starting !
                    Suburbia.Bus.FireEvent(new EventLastTurn());
                    // We put the next tile in the Real Estate Market
                    return(PopNextTile());
                }

                return(tile);
            }
            return(m_tilesB.Pop());
        }
        return(m_tilesA.Pop());
    }
Ejemplo n.º 14
0
    public void TestGetAdjacentToOwnLake()
    {
        List <TileInstance> adjacent_to_lake;

        Assert.AreEqual(null, manager.GetAdjacentToOwnLake(player));

        manager.AddPlayer(player);
        adjacent_to_lake = manager.GetAdjacentToOwnLake(player);
        Assert.AreEqual(0, adjacent_to_lake.Count);

        // We put a lake on the right of the park and the factory
        string lake_description = "{\"name\": \"Lake\", \"triggers\": [{\"scope\": \"ADJACENT\", \"when\": \"ALWAYS\", \"effect\": {\"resource\": \"MONEY\", \"value\": 2}, \"type\": \"YELLOW\"}, {\"scope\": \"ADJACENT\", \"when\": \"ALWAYS\", \"effect\": {\"resource\": \"MONEY\", \"value\": 2}, \"type\": \"GREY\"}, {\"scope\": \"ADJACENT\", \"when\": \"ALWAYS\", \"effect\": {\"resource\": \"MONEY\", \"value\": 2}, \"type\": \"GREEN\"}, {\"scope\": \"ADJACENT\", \"when\": \"ALWAYS\", \"effect\": {\"resource\": \"MONEY\", \"value\": 2}, \"type\": \"BLUE\"}], \"color\": \"LAKE\", \"price\": 0, \"number\": 0, \"immediate\": \"NONE\", \"letter\": \"BASE\", \"icon\": \"NONE\"}";

        Tile         description = GetTileFromString(lake_description);
        TileInstance lake        = new TileInstance(description);
        TilePosition pos         = new TilePosition(1, 3);

        lake.position = pos;
        lake.owner    = player;

        adjacent_to_lake = manager.GetAdjacentToOwnLake(player);
        Assert.AreEqual(2, adjacent_to_lake.Count);
        Assert.AreEqual(true, adjacent_to_lake.Contains(park));
        Assert.AreEqual(true, adjacent_to_lake.Contains(factory));
    }
Ejemplo n.º 15
0
    public void HandleTilePlayed(EventTilePlayed p_event)
    {
        TileInstance p_new_tile = p_event.tile_played;

        if (!Manages(p_new_tile.owner))
        {
            return;
        }
        // The player pays the tile
        int full_price = p_new_tile.description.price + p_event.price_overhead;

        if (p_new_tile.owner.money < full_price)
        {
            // This should not happen
            Debug.Log("The player doesn't have enough money to play this tile!");
            return;
        }
        p_new_tile.owner.money -= full_price;

        // Immediate effect of the new tile
        HandleNewTileImmediateEffect(p_new_tile);
        // Conditional effect of the new tile
        HandleNewTileConditionalEffect(p_new_tile);
        // Conditional effect on the other tiles
        EmitNewTileEvent(p_new_tile);
        // We subscribe the new tile for later conditional effects
        AddSubscriber(p_new_tile);

        if (!p_event.setuptile)
        {
            // End of turn.
            Suburbia.Bus.FireEvent(new EventEndOfTurn(p_new_tile.owner));
        }
    }
Ejemplo n.º 16
0
    public static TileREMView InstantiateForRealEstateMarket(TileInstance p_instance, int p_index, Vector3 p_position, float p_scale)
    {
        try {
            // Creation of the new instance.
            GameObject _new_instance = UnityEngine.Object.Instantiate(RESOURCE) as GameObject;

            _new_instance.transform.position      = p_position;
            _new_instance.transform.localScale    = new Vector3(p_scale, p_scale, p_scale);
            _new_instance.transform.localRotation = Quaternion.Euler(0, 180, -30);
            _new_instance.layer = 8;

            // Get the script associated with the new tile.
            TileREMView _this = _new_instance.AddComponent <TileREMView> ();
            _this.m_tile = p_instance;
            _this.index  = p_index;

            // Set the common properties
            SetTileProperties(_new_instance, _this);

            // Set another script to this instance linked
            _new_instance.AddComponent <SmoothTranslationMarket> ().InitWith(new Vector3(0, 0.5f, 0));

            Debug.Log("Tile : " + p_instance.name + " loaded to market place.");

            return(_this);
        } catch (Exception) {
            Debug.LogError("Error while instanciating tile !");
            return(null);
        }
    }
    public bool CanMergeBoxColliderWith(UniTileTile b, int aX, int aY, int bX, int bY, bool aFlippedH, bool aFlippedV, TileInstance.Rotation aRotation, bool bFlippedH, bool bFlippedV, TileInstance.Rotation bRotation, Vector2 tileSize)
    {
        if(b == null) return false;

        Rect aRect = TileLayerUtil.TransformRect(boxDimensions, tileSize / 2f, aFlippedH, aFlippedV, aRotation);
        Rect bRect = TileLayerUtil.TransformRect(b.boxDimensions, tileSize / 2f, bFlippedH, bFlippedV, bRotation);

        return  b != null
                && b.boxCollider
                && boxDepth == b.boxDepth
                && boxLayer == b.boxLayer
                && boxMaterial == b.boxMaterial
                && boxTag == b.boxTag
                && boxPrefab == b.boxPrefab
                && (
                    (
                        !customBoxDimensions
                        && !b.customBoxDimensions
                    ) || (
                        customBoxDimensions && b.customBoxDimensions && aRect == bRect
                        && (
                            (
                                aY == bY &&
                                aRect.x == 0 && aRect.xMax == tileSize.x
                            ) || (
                                aX == bX &&
                                aRect.y == 0 && aRect.yMax == tileSize.y
                            )
                        )
                    )
                );
    }
Ejemplo n.º 18
0
    public void Init()
    {
        player = new Player();
        player_other = new Player();

        // We create the first three base tiles instances for both players
        suburbs = new TileInstance();
        suburbs.owner = player;
        park = new TileInstance();
        park.owner = player;
        factory = new TileInstance();
        factory.owner = player;

        suburbs.position = new TilePosition(0, 0);
        park.position = new TilePosition(0, 2);
        factory.position = new TilePosition(0, 4);

        suburbs_other = new TileInstance();
        suburbs_other.owner = player_other;
        park_other = new TileInstance();
        park_other.owner = player_other;
        factory_other = new TileInstance();
        factory_other.owner = player_other;

        suburbs_other.position = new TilePosition(0, 0);
        park_other.position = new TilePosition(0, 2);
        factory_other.position = new TilePosition(0, 4);
    }
Ejemplo n.º 19
0
 public TileMap(int _width, int _height)
 {
     m_width    = _width;
     m_height   = _height;
     m_tiles    = new TileInstance[m_width, m_height];
     m_rawTiles = new int[m_width, m_height];
 }
Ejemplo n.º 20
0
    public void TestAssignOwner()
    {
        TileInstance instance = new TileInstance();
        TilePosition position = new TilePosition(0, 0);
        Player player = new Player();

        Assert.AreEqual(0, player.tiles.Count);

        instance.owner = player;
        instance.position = position;
        Assert.AreEqual(player, instance.owner);
        Assert.AreEqual(1, player.tiles.Count);
        Assert.AreEqual(true, player.tiles.Contains(instance));

        // And now the other way around
        instance = new TileInstance();
        player = new Player();
        instance.position = position;

        Assert.AreEqual(0, player.tiles.Count);

        player.AddTileInstance(instance);
        Assert.AreEqual(player, instance.owner);
        Assert.AreEqual(1, player.tiles.Count);
        Assert.AreEqual(true, player.tiles.Contains(instance));
    }
Ejemplo n.º 21
0
    public void HandleClickOnFreePosition(EventClickOnFreePosition p_event)
    {
        // The tile has been placed, we emit the tile played event.
        if (m_current_tile_chosen != null) {

            int tile_price = Suburbia.Market.PriceOverheadForTileNumber (this.m_index_in_REM)
                + m_current_tile_chosen.description.price;

            if (Suburbia.ActivePlayer.money >= tile_price) {

                // We place the new tile on the player ground :
                m_current_tile_chosen.position = p_event.position;
                Suburbia.ActivePlayer.AddTileInstance (m_current_tile_chosen);
                Suburbia.Bus.FireEvent (new EventSendTileToPosition (Suburbia.ActivePlayer, p_event.position, m_index_in_REM));

                // Transmit sub events.
                Suburbia.Bus.FireEvent (new EventRemoveFreePositionOfPlayer (Suburbia.ActivePlayer));
                Suburbia.Bus.FireEvent (new EventTilePlayed (this.m_current_tile_chosen,
                                                         Suburbia.Market.PriceOverheadForTileNumber (this.m_index_in_REM)));
                // We remove the tile in the REM.
                Suburbia.Market.RemoveTile (this.m_index_in_REM);
                m_current_tile_chosen = null;
            }
            // Otherwise we tell him he can't play the tile !
            else
            {
                Debug.LogError ("Can't play the tile bro !");
            }
        }
    }
Ejemplo n.º 22
0
    public static TileREMView InstantiateForRealEstateMarket(TileInstance p_instance, int p_index, Vector3 p_position, float p_scale)
    {
        try {
            // Creation of the new instance.
            GameObject _new_instance = UnityEngine.Object.Instantiate (RESOURCE) as GameObject;

            _new_instance.transform.position = p_position;
            _new_instance.transform.localScale = new Vector3 (p_scale, p_scale, p_scale);
            _new_instance.transform.localRotation = Quaternion.Euler (0, 180, -30);
            _new_instance.layer = 8;

            // Get the script associated with the new tile.
            TileREMView _this = _new_instance.AddComponent<TileREMView> ();
            _this.m_tile = p_instance;
            _this.index = p_index;

            // Set the common properties
            SetTileProperties (_new_instance, _this);

            // Set another script to this instance linked
            _new_instance.AddComponent<SmoothTranslationMarket> ().InitWith (new Vector3 (0, 0.5f, 0));

            Debug.Log ("Tile : " + p_instance.name + " loaded to market place.");

            return _this;
        } catch (Exception) {
            Debug.LogError ("Error while instanciating tile !");
            return null;
        }
    }
Ejemplo n.º 23
0
        public override BoardItem CreateInstance(Layer layer, Board board, int x, int y, int z, bool flip)
        {
            TileInstance instance = new TileInstance(this, layer, board, x, y, z, layer.zMDefault);

            ParseOffsets(instance, board, x, y);
            return(instance);
        }
Ejemplo n.º 24
0
        private void AddTilesFor(Layer layer, List <TileObj> tileObjs)
        {
            DrawLayer engineLayer = DrawLayer.Playground;

            if (layer.Props.Has("drawLayer"))
            {
                string drawLayer = layer.Props.GetString("drawLayer");
                engineLayer = (DrawLayer)Enum.Parse(typeof(DrawLayer), drawLayer);
            }

            for (int i = 0; i < layer.Grid.Size(); i++)
            {
                TileInstance inst = layer.Grid.At(i);
                if (inst == null)
                {
                    continue;
                }
                string  texture = inst.Type.ImagePath;
                int     tOffX   = inst.Type.OffX;
                int     tOffY   = inst.Type.OffY;
                int     width   = inst.Type.Width;
                int     height  = inst.Type.Height;
                int     posX    = inst.PosX;
                int     posY    = inst.PosY;
                TileObj obj     = new TileObj(texture, tOffX, tOffY, posX, posY, width, height);
                tileObjs.Add(obj);
                if (inst.Type.Props.Has("collidable") && inst.Type.Props.GetBool("collidable"))
                {
                    obj.RigidBody          = new Rigidbody(obj);
                    obj.RigidBody.Collider = ColliderFactory.CreateBoxFor(obj);
                    obj.RigidBody.Type     = RigidBodyType.TileObj;
                }
            }
        }
Ejemplo n.º 25
0
    public bool CanMove(GameObject currentTile, Enums.direction dir)
    {
        GameObject   currentGrid  = currentTile.transform.parent.gameObject;
        GridInstance gridInstance = currentGrid.GetComponent <GridInstance>();
        TileInstance tileInstance = currentTile.GetComponent <TileInstance>();

        GameObject[,] tileArray = gridInstance._tileArray;
        GameObject tileNext = null;

        switch (dir)
        {
        case Enums.direction.left:
            tileNext = tileArray[tileInstance.x - 1, tileInstance.y];
            break;

        case Enums.direction.right:
            tileNext = tileArray[tileInstance.x + 1, tileInstance.y];
            break;

        case Enums.direction.up:
            tileNext = tileArray[tileInstance.x, tileInstance.y + 1];
            break;

        case Enums.direction.down:
            tileNext = tileArray[tileInstance.x, tileInstance.y - 1];
            break;
        }

        if (tileNext != null && tileNext.tag != "Obstacle" && tileNext.GetComponent <TileInstance>().connectedObject.tag != "Obstacle")
        {
            return(true);
        }

        return(false);
    }
Ejemplo n.º 26
0
 public bool IsAdjacentTo(TileInstance p_other)
 {
     if (this.owner == p_other.owner)
     {
         return(this.position.IsAdjacentTo(p_other.position));
     }
     return(false);
 }
Ejemplo n.º 27
0
    public TileMap(TileBank _bank, PalettizedImage _sourceImage)
    {
        //
        m_tileBank = _bank;

        //
        int w = _sourceImage.m_width;
        int h = _sourceImage.m_height;

        m_width  = 64;       //(_sourceImage.m_width+7) >> 3;
        m_height = 32;       //(_sourceImage.m_height+7) >> 3;
        int sourceWidth  = w >> 3;
        int sourceHeight = h >> 3;

        //
        m_tiles    = new TileInstance[m_width, m_height];
        m_rawTiles = null;

        //
        int x, y;

        for (y = 0; y < sourceHeight; y++)
        {
            string str = y.ToString() + "=(";
            for (x = 0; x < sourceWidth; x++)
            {
                int pixel_x = x * Tile.Width;
                int pixel_y = y * Tile.Height;

                Tile         srcTile      = new Tile(_sourceImage, pixel_x, pixel_y);
                TileInstance tileInstance = m_tileBank.GetTileInstance(srcTile);
                if (tileInstance == null)
                {
                    Debug.LogException(new UnityException("PANIC! Couldn't find tile instance for tile at coordinates " + pixel_x + "," + pixel_y));
                    return;
                }

                //
                m_tiles[x, y] = tileInstance;
                str          += tileInstance.m_tileBankIndex;
                if (tileInstance.m_flipX)
                {
                    str += "x";
                }
                if (tileInstance.m_flipY)
                {
                    str += "y";
                }
                if (x < sourceWidth - 1)
                {
                    str += ",";
                }
            }

            str += ")";
            //Debug.Log( str );
        }
    }
Ejemplo n.º 28
0
    static public TileMap LoadJson(string _fileName)
    {
        string jsonString = System.IO.File.ReadAllText(_fileName);
        Dictionary <string, object> json = (Dictionary <string, object>)MiniJSON.Json.Deserialize(jsonString);

        // Load tile bank
        List <object> tilesetsJson = (List <object>)json["tilesets"];
        Dictionary <string, object> tilesetJson = (Dictionary <string, object>)tilesetsJson[0];
        string imageFileName = (string)tilesetJson["image"];
        string imageFullPath = System.IO.Path.GetDirectoryName(_fileName) + System.IO.Path.DirectorySeparatorChar + imageFileName;
        //LoadBMP( imageFullPath );

        PalettizedImageConfig imageConfig = new PalettizedImageConfig(imageFullPath + ".config");

        PalettizedImage imageData = PalettizedImage.LoadImage(imageFullPath, imageConfig);
        TileBank        tileBank  = null;

        if (imageData != null)
        {
            //
            imageConfig.SetImage(imageData);

            bool optimizeBank = (imageConfig.m_importAsSprite == false);                // Optimize bank when we're not loading the image as a sprite (i.e. optimize when we're loading as a tile bank)
            tileBank = new TileBank(imageData, optimizeBank);
        }

        // Create map texture
        int map_tiles_w  = ((int)(long)json["width"]);
        int map_tiles_h  = ((int)(long)json["height"]);
        int map_pixels_w = map_tiles_w * 8;
        int map_pixels_h = map_tiles_h * 8;

        TileMap ret = new TileMap(map_tiles_w, map_tiles_h);

        // Find each layer
        List <object> layersJson = (List <object>)json["layers"];
        Dictionary <string, object> layerJson = (Dictionary <string, object>)layersJson[0];
        List <object> layerData = (List <object>)layerJson["data"];
        int           tile_x, tile_y;

        for (tile_y = 0; tile_y < map_tiles_h; tile_y++)
        {
            for (tile_x = 0; tile_x < map_tiles_w; tile_x++)
            {
                int i       = tile_y * map_tiles_w + tile_x;
                int tile_id = (int)(long)layerData[i];
                tile_id--;
                TileInstance tileInstance = tileBank.m_allTileInstances[tile_id];

                //
                ret.SetRawTile(tile_x, tile_y, tile_id);
                ret.SetTile(tile_x, tile_y, tileInstance);
            }
        }

        return(ret);
    }
Ejemplo n.º 29
0
 public TileInstanceEditor(TileInstance item)
 {
     InitializeComponent();
     this.item      = item;
     xInput.Value   = item.X;
     yInput.Value   = item.Y;
     zInput.Value   = item.Z;
     pathLabel.Text = HaCreatorStateManager.CreateItemDescription(item, "\r\n");
 }
Ejemplo n.º 30
0
    public TilePosition(int p_x, int p_y)
    {
        if (!IsValidPosition (p_x, p_y))
            Debug.Log ("TilePosition is incorrect!");

        m_x = p_x;
        m_y = p_y;
        m_parent = null;
    }
Ejemplo n.º 31
0
 public void HandleClickOnTileFromREM(EventClickOnTileFromREM p_event)
 {
     if (m_current_tile_chosen != null)
     {
         m_current_tile_chosen.ResetFromLake();
     }
     m_current_tile_chosen = p_event.tile;
     m_index_in_REM        = p_event.index_in_REM;
 }
Ejemplo n.º 32
0
    private void SetTileVisuals(Node <Tile> node, TileInstance tileInstance, SpriteRenderer spriteRenderer, Color colour)
    {
        if (node.Data != startTile && node.Data != goalTile)
        {
            spriteRenderer.color = colour;
        }

        tileInstance.Node = node;
    }
Ejemplo n.º 33
0
        private void ApplyTileInstanceFlips(Tilemap tilemap, TileInstance tileData, Vector3Int coord)
        {
            float      rotX   = tileData.FlipY ? 180 : 0;
            float      rotY   = tileData.FlipX ? 180 : 0;
            Quaternion rot    = Quaternion.Euler(rotX, rotY, 0);
            Matrix4x4  matrix = Matrix4x4.TRS(Vector3.zero, rot, Vector3.one);

            tilemap.SetTransformMatrix(coord, matrix);
        }
Ejemplo n.º 34
0
        private Vector2Int GetConvertedCoord(TileInstance tileData)
        {
            //doing the division like this because the operator is not available in older unity versions
            Vector2Int coord = new Vector2Int(
                tileData.UnityPx.x / (int)Layer.GridSize,
                tileData.UnityPx.y / (int)Layer.GridSize);

            return(ConvertCellCoord(coord));
        }
Ejemplo n.º 35
0
        public BoardItem CreateInstance(Layer layer, Board board, int x, int y, int z, int zM, bool flip, bool parseOffsets)
        {
            TileInstance instance = new TileInstance(this, layer, board, x, y, z, zM);

            if (parseOffsets)
            {
                ParseOffsets(instance, board, x, y);
            }
            return(instance);
        }
Ejemplo n.º 36
0
        public override Component CreateCollider(Vector3 position, TileInstance tile)
        {
            var collider = pool.RequestComponent();

            collider.center         = position;
            collider.size           = config.size3D;
            collider.isTrigger      = config.isTrigger;
            collider.sharedMaterial = config.material3D;
            return(collider);
        }
Ejemplo n.º 37
0
        public override Component CreateCollider(Vector3 position, TileInstance tile)
        {
            var collider = pool.RequestComponent();

            collider.offset         = position;
            collider.radius         = config.radius;
            collider.isTrigger      = config.isTrigger;
            collider.sharedMaterial = config.material2D;
            return(collider);
        }
Ejemplo n.º 38
0
    public void Init()
    {
        manager = new TileManager ();

        player = new Player ();
        player_other = new Player ();

        suburbs_description = "{\"name\": \"Suburbs\", \"triggers\": [], \"color\": \"GREEN\", \"price\": 3, \"number\": \"0\", \"immediate\": {\"resource\": \"POPULATION\", \"value\": 2}, \"letter\": \"BASE\", \"icon\": \"NONE\"}";
        park_description = "{\"name\": \"Community Park\", \"triggers\": [{\"scope\": \"ADJACENT\", \"when\": \"ALWAYS\", \"effect\": {\"resource\": \"REPUTATION\", \"value\": 1}, \"type\": \"YELLOW\"}, {\"scope\": \"ADJACENT\", \"when\": \"ALWAYS\", \"effect\": {\"resource\": \"REPUTATION\", \"value\": 1}, \"type\": \"GREEN\"}, {\"scope\": \"ADJACENT\", \"when\": \"ALWAYS\", \"effect\": {\"resource\": \"REPUTATION\", \"value\": 1}, \"type\": \"BLUE\"}], \"color\": \"GREY\", \"price\": 4, \"number\": \"0\", \"immediate\": {\"resource\": \"INCOME\", \"value\": -1}, \"letter\": \"BASE\", \"icon\": \"NONE\"}";
        factory_description = "{\"name\": \"Heavy Factory\", \"triggers\": [{\"scope\": \"ADJACENT\", \"when\": \"ALWAYS\", \"effect\": {\"resource\": \"REPUTATION\", \"value\": -1}, \"type\": \"GREY\"}, {\"scope\": \"ADJACENT\", \"when\": \"ALWAYS\", \"effect\": {\"resource\": \"REPUTATION\", \"value\": -1}, \"type\": \"GREEN\"}], \"color\": \"YELLOW\", \"price\": 3, \"number\": \"0\", \"immediate\": {\"resource\": \"INCOME\", \"value\": 1}, \"letter\": \"BASE\", \"icon\": \"NONE\"}";
        suburbs_ = GetTileFromString(suburbs_description);
        park_ = GetTileFromString(park_description);
        factory_ = GetTileFromString(factory_description);

        // We create the first three base tiles instances for both players
        suburbs = new TileInstance (suburbs_);
        suburbs.owner = player;
        park = new TileInstance (park_);
        park.owner = player;
        factory = new TileInstance (factory_);
        factory.owner = player;

        suburbs.position = new TilePosition (0, 0);
        park.position = new TilePosition (0, 2);
        factory.position = new TilePosition (0, 4);

        suburbs_other = new TileInstance (suburbs_);
        suburbs_other.owner = player_other;
        park_other = new TileInstance (park_);
        park_other.owner = player_other;
        factory_other = new TileInstance (factory_);
        factory_other.owner = player_other;

        suburbs_other.position = new TilePosition (0, 0);
        park_other.position = new TilePosition (0, 2);
        factory_other.position = new TilePosition (0, 4);
    }
Ejemplo n.º 39
0
    public void HandleNewTileConditionalEffect(TileInstance p_new_tile)
    {
        // Apply all the triggers of the new tile :

        foreach (TriggerInstance trigger in p_new_tile.triggers) {
            if (trigger.trigger.when == ETileWhen.AFTER_RED_LINE || trigger.trigger.when == ETileWhen.AFTER) {
                continue;
            }

            List<TileInstance> tile_instances = null;

            switch (trigger.trigger.scope) {
            case ETileScope.ADJACENT:

                tile_instances = GetAdjacent (p_new_tile);
                break;

            case ETileScope.OWN:

                tile_instances = GetTilesOfPlayer (p_new_tile.owner);
                break;

            case ETileScope.GLOBAL:

                tile_instances = GetAllTiles ();
                break;

            case ETileScope.OTHER:

                tile_instances = GetTilesOfOtherPlayers (p_new_tile.owner);
                break;

            case ETileScope.ADJACENT_TO_OWN_LAKE:

                tile_instances = GetAdjacentToOwnLake (p_new_tile.owner);
                break;

            case ETileScope.NONE:

                Debug.LogError ("Bug found ! No tile here with a when always and a scope equal to none...");
                continue;
            }

            if (tile_instances == null) {
                Debug.LogWarning ("Tile instances empty !");
                continue;
            }

            TileType trigger_on_tile_type = trigger.trigger.type;
            int number_of_tiles = 0;

            foreach (TileInstance other in tile_instances) {
                if (other.IsOfType (trigger_on_tile_type))
                    number_of_tiles += 1;
            }

            trigger.Apply (p_new_tile.owner, number_of_tiles);
        }
    }
Ejemplo n.º 40
0
    // public for test purposes
    public void SetUpTilesForPlayer(Player p_player)
    {
        if (TileManager.m_setup_tiles != null) {
            foreach (var setupTile in m_setup_tiles) {
                TileInstance tileInstance = new TileInstance (setupTile.tile);
                p_player.AddTileInstance (tileInstance);
                tileInstance.position = new TilePosition (setupTile.x, setupTile.y);

                // Quick hack so that the setup tiles don't cost any money
                Suburbia.Bus.FireEvent(new EventTilePlayed(tileInstance, -setupTile.tile.price, true));
            }
        }
    }
Ejemplo n.º 41
0
 public void HandleNewTileImmediateEffect(TileInstance p_new_tile)
 {
     p_new_tile.ApplyImmediateEffect ();
 }
Ejemplo n.º 42
0
 public void Apply(TileInstance p_other)
 {
     m_trigger.Apply (m_tile_owner.owner, m_tile_owner.IsAdjacentTo (p_other));
 }
    private static void DrawGrid(TileLayer layer, TileInstance[] selectedTiles, int selectedTilesWidth)
    {
        Handles.color = new Color (1f,1f,1f,1f);

        if(layer != null) {

            if(layer.tileSpacing == new Vector2(-1, -1)) layer.tileSpacing = layer.tileSize;

            Transform trans = layer.transform;

            Handles.DrawLine(trans.TransformPoint(new Vector3(0,0,0)), trans.TransformPoint(new Vector3(layer.tileSpacing.x * layer.layerSize.x, 0, 0)));
            Handles.DrawLine(trans.TransformPoint(new Vector3(0,0,0)), trans.TransformPoint(new Vector3(0, layer.tileSpacing.y * layer.layerSize.y, 0)));
            Handles.DrawLine(trans.TransformPoint(new Vector3(0, layer.tileSpacing.y * layer.layerSize.y, 0)), trans.TransformPoint(new Vector3(layer.tileSpacing.x * layer.layerSize.x, layer.tileSpacing.y * layer.layerSize.y, 0)));
            Handles.DrawLine(trans.TransformPoint(new Vector3(layer.tileSpacing.x * layer.layerSize.x, layer.tileSpacing.y * layer.layerSize.y,0)), trans.TransformPoint(new Vector3(layer.tileSpacing.x * layer.layerSize.x, 0, 0)));

            if(TileLayerEditor.picking) {
                Handles.color = new Color (1f,1f,0.5f,1f);
                Vector3 start = new Vector3(Mathf.Min(TileLayerEditor.pickStart.x, TileLayerEditor.pickEnd.x) * layer.tileSpacing.x, Mathf.Min(TileLayerEditor.pickStart.y, TileLayerEditor.pickEnd.y) * layer.tileSpacing.y, 0);
                Vector3 end = new Vector3(Mathf.Max(TileLayerEditor.pickStart.x, TileLayerEditor.pickEnd.x) * layer.tileSpacing.x + layer.tileSpacing.x, Mathf.Max(TileLayerEditor.pickStart.y, TileLayerEditor.pickEnd.y) * layer.tileSpacing.y + layer.tileSpacing.y, 0);
                Handles.DrawLine(trans.TransformPoint(new Vector3(start.x, start.y,0)), trans.TransformPoint(new Vector3(start.x, end.y)));
                Handles.DrawLine(trans.TransformPoint(new Vector3(start.x, start.y,0)), trans.TransformPoint(new Vector3(end.x, start.y)));
                Handles.DrawLine(trans.TransformPoint(new Vector3(start.x, end.y,0)), trans.TransformPoint(new Vector3(end.x, end.y)));
                Handles.DrawLine(trans.TransformPoint(new Vector3(end.x, start.y,0)), trans.TransformPoint(new Vector3(end.x, end.y)));
            } else if(selectedTilesWidth > 0) {
                Handles.color = new Color (1f,1f,1f,1f);
                Vector3 start = TileLayerEditor.gridMousePosition + new Vector3(0, layer.tileSpacing.y, 0);
                Vector3 end = start + new Vector3(selectedTilesWidth * layer.tileSpacing.x, -selectedTiles.Length / selectedTilesWidth * layer.tileSpacing.y, 0);
                Handles.DrawLine(trans.TransformPoint(new Vector3(start.x, start.y,0)), trans.TransformPoint(new Vector3(start.x, end.y)));
                Handles.DrawLine(trans.TransformPoint(new Vector3(start.x, start.y,0)), trans.TransformPoint(new Vector3(end.x, start.y)));
                Handles.DrawLine(trans.TransformPoint(new Vector3(start.x, end.y,0)), trans.TransformPoint(new Vector3(end.x, end.y)));
                Handles.DrawLine(trans.TransformPoint(new Vector3(end.x, start.y,0)), trans.TransformPoint(new Vector3(end.x, end.y)));
            }

            Handles.color = new Color (1f,1f,1f,0.05f);
            for(int i=0;i<=layer.layerSize.y;i++) {
                Handles.DrawLine(trans.TransformPoint(new Vector3(0, (float)i * layer.tileSpacing.y, 0)), trans.TransformPoint(new Vector3(layer.tileSpacing.x * layer.layerSize.x, (float)i * layer.tileSpacing.y, 0)));
            }
            for(int i=0;i<=layer.layerSize.x;i++) {
                Handles.DrawLine(trans.TransformPoint(new Vector3((float)i * layer.tileSpacing.x, 0, 0)), trans.TransformPoint(new Vector3((float)i * layer.tileSpacing.x, layer.tileSpacing.y * layer.layerSize.y, 0)));
            }
        }
    }
Ejemplo n.º 44
0
 public void AddSubscriber(TileInstance p_tile)
 {
     foreach (TriggerInstance trigger in p_tile.triggers) {
         AddSubscriber (trigger);
     }
 }
Ejemplo n.º 45
0
    public void TestEquality()
    {
        // Equality works with position and owner
        TileInstance suburbs_idem = new TileInstance();
        suburbs_idem.owner = player;
        suburbs_idem.position = new TilePosition(0, 0);
        Assert.AreEqual(suburbs, suburbs_idem);

        // Different position
        Assert.AreNotEqual(suburbs, park);

        // Different owner
        Assert.AreNotEqual(suburbs, suburbs_other);
    }
 public void Clear()
 {
     selectedTilesWidth = 1;
     selectedTilesList = new TileInstance[1];
     selectedTilesList[0] = new TileInstance(0);
 }
Ejemplo n.º 47
0
    public bool GetUnoptimizedIndexFromInstance( TileInstance _instance, out int _index )
    {
        foreach( var kvp in m_allTileInstances )
        {
            if( kvp.Value.Equals( _instance ))
            {
                _index = kvp.Key;
                return true;
            }
        }

        _index = -1;
        return false;
    }
Ejemplo n.º 48
0
 void SetTile( int _x, int _y, TileInstance _tile )
 {
     m_tiles[ _x, _y ] = _tile;
 }
Ejemplo n.º 49
0
    public void Export( string _outfilename )
    {
        Debug.Log ("Exporting tile map to " + _outfilename );

        int headersize = 2;

        // Export size = width * height * 2 (each tile in the map is 2 bytes)
        int outsize = m_width*m_height*2;
        byte[] outBytes = new byte[ headersize+outsize ];

        outBytes[ 0 ] = (byte)m_width;
        outBytes[ 1 ] = (byte)m_height;

        int x, y;
        for( y=0; y<m_height; y++ )
        {
            for( x=0; x<m_width; x++ )
            {
                TileInstance tile = m_tiles[ x, y ];

                if( tile == null )
                    tile = new TileInstance( null, null, 0, false, false );	// Create a clear tile instance for where there are none

                int prio = 0;						// 1 bit. Can be 0 or 1
                int paletteIndex = 0;				// 2 bits. 0-3
                int vf = (tile.m_flipY==true)?1:0;	// 1 bit. Flip X?
                int hf = (tile.m_flipX==true)?1:0;	// 1 bit. Flip Y?
                int index = tile.m_tileBankIndex;	// 11 bits. 0-2047

                int value = ((prio&1)<<15) + ((paletteIndex&3)<<13) + ((vf&1)<<12) + ((hf&1)<<11) + (index&0x7ff);

                int wrOfs = headersize + (((y*m_width)+x) * 2);
                outBytes[ wrOfs+0 ] = (byte)((value>>8)&0xff);
                outBytes[ wrOfs+1 ] = (byte)(value&0xff);
            }
        }

        System.IO.File.WriteAllBytes( _outfilename, outBytes );
    }
Ejemplo n.º 50
0
    public static TileView InstantiateWithParent(TileInstance p_instance, Transform p_parent)
    {
        try {
            // Creation of the new instance.
            GameObject _new_instance = UnityEngine.Object.Instantiate (RESOURCE) as GameObject;
            _new_instance.transform.parent = p_parent;

            // Get the script associated with the new tile.
            TileView _this = _new_instance.AddComponent<TileView> ();
            _this.m_tile = p_instance;

            // Set the common properties
            SetTileProperties (_new_instance, _this);

            return _this;

        } catch (Exception) {
            Debug.LogError ("Error while instantiating !");
            return null;
        }
    }
Ejemplo n.º 51
0
    public void TestTransformIntoLake()
    {
        // We actually load the tile into the tile instance
        string suburbs_description = "{\"name\": \"Suburbs\", \"triggers\": [], \"color\": \"GREEN\", \"price\": 3, \"number\": \"0\", \"immediate\": {\"resource\": \"POPULATION\", \"value\": 2}, \"letter\": \"BASE\", \"icon\": \"NONE\"}";
        suburbs = new TileInstance (Tile.LoadFromJson (JSON.Parse (suburbs_description) as JSONClass));
        Assert.AreEqual("Suburbs", suburbs.description.name);

        suburbs.SwitchWithLake();
        Assert.AreEqual("Lake", suburbs.description.name);

        suburbs.SwitchWithLake();
        Assert.AreEqual("Suburbs", suburbs.description.name);

        suburbs.TransformIntoLake();
        Assert.AreEqual("Lake", suburbs.description.name);

        suburbs.TransformIntoLake();
        Assert.AreEqual("Lake", suburbs.description.name);

        suburbs.ResetFromLake();
        Assert.AreEqual("Suburbs", suburbs.description.name);

        suburbs.ResetFromLake();
        Assert.AreEqual("Suburbs", suburbs.description.name);
    }
Ejemplo n.º 52
0
    public void TestAssignPosition()
    {
        TileInstance instance = new TileInstance();
        TilePosition position = new TilePosition(12, 12);
        instance.position = position;

        Assert.AreEqual(position, instance.position);
        Assert.AreEqual(instance, position.parent);
    }
Ejemplo n.º 53
0
 public List<TileInstance> GetAdjacent(TileInstance p_tile)
 {
     return p_tile.GetAdjacentInstances ();
 }
    public void OnSceneGUI(TileLayer layer, UniTileTemplate selection, TileLayerEditor editor)
    {
        DrawGrid(layer, selection.selectedTilesList, selection.selectedTilesWidth);

        MouseInfo(selection);

        GUI.Box(new Rect (10, 10, 170, 60), "");
        GUILayout.BeginArea(new Rect (20, 20, 150, 40));
        LayerSelect(layer);
        GUILayout.EndArea();

        if(justSwitchedLayers)
            return;

        Handles.BeginGUI();

        GUI.Box(new Rect (Screen.width - 160, Screen.height - 90, 160, 70), "");
        GUILayout.BeginArea(new Rect (Screen.width - 150, Screen.height - 80, 140, 50));
        CreateObjectButton(layer);
        TemplatePopup(layer,editor);
        GUILayout.EndArea();

        if(Event.current.keyCode == KeyCode.H && Event.current.type == EventType.KeyUp) {
            for(int i = 0; i < selection.selectedTilesList.Length; i++) {
                if(selection.selectedTilesList[i] != null) {
                    selection.selectedTilesList[i].flippedHorizontally = !selection.selectedTilesList[i].flippedHorizontally;
                }
            }
            TileInstance [] temp = new TileInstance[selection.selectedTilesList.Length];
            for(int i = 0; i < selection.selectedTilesWidth; i++) {
                for(int j = 0; j < selection.selectedTilesHeight; j++) {
                    int x1 = i;
                    int x2 = selection.selectedTilesWidth - x1 - 1;
                    int index1 = x1 + j * selection.selectedTilesWidth;
                    int index2 = x2 + j * selection.selectedTilesWidth;
                    temp[index2] = selection.selectedTilesList[index1];
                }
            }
            selection.selectedTilesList = temp;

            UniTileMarker.Instance.Init(selection);
            editor.selectedTemplate = -1;
        }

        if(Event.current.keyCode == KeyCode.V && Event.current.type == EventType.KeyUp) {
            for(int i = 0; i < selection.selectedTilesList.Length; i++) {
                if(selection.selectedTilesList[i] != null) {
                    selection.selectedTilesList[i].flippedVertically = !selection.selectedTilesList[i].flippedVertically;
                }
            }

            TileInstance [] temp = new TileInstance[selection.selectedTilesList.Length];
            for(int i = 0; i < selection.selectedTilesWidth; i++) {
                for(int j = 0; j < selection.selectedTilesHeight; j++) {
                    int y1 = j;
                    int y2 = selection.selectedTilesHeight - y1 - 1;
                    int index1 = i + y1 * selection.selectedTilesWidth;
                    int index2 = i + y2 * selection.selectedTilesWidth;
                    temp[index2] = selection.selectedTilesList[index1];
                }
            }
            selection.selectedTilesList = temp;

            UniTileMarker.Instance.Init(selection);
            editor.selectedTemplate = -1;
        }

        if(Event.current.keyCode == KeyCode.T && Event.current.type == EventType.KeyUp) {
            for(int i = 0; i < selection.selectedTilesList.Length; i++) {
                if(selection.selectedTilesList[i] != null) {
                    selection.selectedTilesList[i].rotation++;
                    if((uint)selection.selectedTilesList[i].rotation > 3) selection.selectedTilesList[i].rotation = TileInstance.Rotation.r0;
                }
            }

            TileInstance [] temp = new TileInstance[selection.selectedTilesList.Length];
            int newWidth = selection.selectedTilesHeight;

            for(int i = 0; i < selection.selectedTilesWidth; i++) {
                for(int j = 0; j < selection.selectedTilesHeight; j++) {
                    int x1 = i;
                    int y1 = j;
                    int index1 = x1 + y1 * selection.selectedTilesWidth;

                    int x2 = selection.selectedTilesHeight - y1 - 1;
                    int y2 = x1;
                    int index2 = x2 + y2 * newWidth;

                    temp[index2] = selection.selectedTilesList[index1];
                }
            }

            selection.selectedTilesList = temp;
            selection.selectedTilesWidth = newWidth;

            UniTileMarker.Instance.Init(selection);
            editor.selectedTemplate = -1;
        }

        Handles.EndGUI();
    }
Ejemplo n.º 55
0
    public void EmitNewTileEvent(TileInstance p_new_tile)
    {
        foreach (TileType type in p_new_tile.types) {
            List<TriggerInstance> subscribed_triggers = new List<TriggerInstance>();

            m_subscribers.TryGetValue (type, out subscribed_triggers);
            if (subscribed_triggers == null)
                continue;

            subscribed_triggers = TileManager.SortSubscribedTriggers(subscribed_triggers, p_new_tile);

            foreach (TriggerInstance trigger in subscribed_triggers) {
                trigger.Apply (p_new_tile);
            }
        }
    }
Ejemplo n.º 56
0
 public TriggerInstance(Trigger p_trigger, TileInstance p_tile_owner)
 {
     m_trigger = p_trigger;
             m_tile_owner = p_tile_owner;
 }
Ejemplo n.º 57
0
 public void AddTileInstance(TileInstance p_tileinstance)
 {
     this.m_tileinstances.Add(p_tileinstance);
     p_tileinstance.SetOwner(this);
 }
    public void Setup(TileLayerEditor editor, TileInstance[] selectedTiles)
    {
        if(selectedTiles.Length == 0)
        {
            Debug.LogError("No tiles selected! Only use TileEditorWindow if tiles have been selected");
            this.Close();
            return;
        }
        int selectedTile = selectedTiles[0].id;

        this.editor = editor;
        this.selectedTiles = selectedTiles;
        this.layer = editor.target as TileLayer;
        this.boxDepth = 64;
        this.boxTag = "Untagged";

        if(layer.tileset!=null) {
            this.ResizeArray();
            UniTileTile tile = layer.tileset.tiles[selectedTile];
            if(tile!=null) {
                this.prefab = tile.prefab;
                this.name = tile.name;
                this.value = tile.value;
                this.boxCollider = tile.boxCollider;
                this.resizable = tile.resizable;
                this.boxLayer = tile.boxLayer;
                this.boxMaterial = tile.boxMaterial;
                this.boxTag = tile.boxTag;
                this.boxDepth = tile.boxDepth;
                this.boxPrefab = tile.boxPrefab;
                this.prefabOffset = tile.prefabOffset;
                if(this.prefab == null) this.prefabOffset = new Vector2(this.layer.tileSpacing.x / 2f, this.layer.tileSpacing.y / 2f);

                this.customBoxDimensions = tile.customBoxDimensions;
                if(!this.customBoxDimensions) this.boxDimensions = new Rect(0, 0, this.layer.tileSpacing.x, this.layer.tileSpacing.y);
                else this.boxDimensions = tile.boxDimensions;
                if(tile.properties!=null) {
                    this.properties = new UniTileProperty[tile.properties.Length];
                    for(int i=0; i<this.properties.Length;i++) {
                        this.properties[i] = new UniTileProperty();
                        this.properties[i].key = tile.properties[i].key;
                        this.properties[i].value = tile.properties[i].value;
                    }
                } else {
                    this.properties = new UniTileProperty[0];
                }
            }
        }
        if(this.properties == null) this.properties = new UniTileProperty[0];
        this.propertiesLength = this.properties.Length;
        if(this.name == null) this.name = "";
    }
Ejemplo n.º 59
0
 public bool IsAdjacentTo(TileInstance p_other)
 {
     if (this.owner == p_other.owner)
         return this.position.IsAdjacentTo (p_other.position);
     return false;
 }
Ejemplo n.º 60
0
        private IEnumerable<TileBase> GetTiles(Rectangle bounds)
        {
            Debug.Assert(Tiling != null, "Tiling != null");

            Tile origTile = Tiling.Tiles[0];
            Debug.Assert(origTile != null, "origTile != null");

            TileInstance tile = new TileInstance(origTile, origTile.Label, origTile.Transform)
            {
                Style = origTile.Style
            };

            return Tiling.GetTiles(bounds, new TileBase[] { tile });
        }