Example #1
0
    public TerrainCell RenderCell(int id)
    {
        if (!Util.ValidCellIndex(id, WorldWidth))
        {
            return(null);
        }

        if (cells.ContainsKey(id))
        {
            return(cells[id]);
        }

        if (!cellsData.ContainsKey(id))
        {
            AdventureDb     db   = new AdventureDb(saveFile);
            TerrainCellData data = db.LoadCell(id);
            cellsData.Add(id, data);
        }

        TerrainCellData cellData = cellsData[id];

        cellsData.Remove(id);

        TerrainCell cell    = new TerrainCell(cellData, CellSize, BaseBlockSize());
        Vector3     cellPos = Util.CellPositionFromCoords(cell.coords, GetCellScale());

        cell.SetCenteredPosition(cellPos);
        cells.Add(cell.id, cell);
        AddChild(cell);

        foreach (ActorData actor in ActorsDataAtCoords(cell.coords))
        {
            RenderActor(actor.id);
        }

        foreach (ItemData item in ItemDataAtCoords(cell.coords))
        {
            GD.Print("Item found at " + cell.coords);
            RenderItem(item.id);
        }

        return(cell);
    }