コード例 #1
0
    public static Cell ConvertToCell(CellSdo cellSdo)
    {
        if (cellSdo == null)
        {
            return(null);
        }

        var cell = WorldData.Instance.MapDictionary[cellSdo.Id];

        cell.biomeType  = cellSdo.BiomeType;
        cell.Rivers     = RiverSdo.ConvertToRivers(cellSdo.RiverSdos);
        cell.Settlement = new Settlement(cellSdo.SettlementSdo);
        cell.LoadCellSprite(cellSdo.WorldMapSpriteData);

        cell.PresentFactions = new List <Faction>();

        foreach (var factionName in cellSdo.PresentFactionNames)
        {
            cell.PresentFactions.Add(WorldData.Instance.Factions[factionName]);
        }

        cell.Areas = AreaSdo.ConvertAreasForPlaying(cellSdo.AreaSdos);

        return(cell);
    }
コード例 #2
0
    public static CellSdo ConvertToCellSdo(Cell cell)
    {
        if (cell == null)
        {
            return(null);
        }

        var sdo = new CellSdo
        {
            BiomeType           = cell.BiomeType,
            X                   = cell.X,
            Y                   = cell.Y,
            Id                  = cell.Id,
            RiverSdos           = RiverSdo.ConvertToRiverSdos(cell.Rivers),
            WorldMapSpriteData  = cell.WorldMapSprite.LayerPrefabIndexes,
            PresentFactionNames = new List <string>()
        };

        if (cell.PresentFactions != null)
        {
            foreach (var faction in cell.PresentFactions)
            {
                sdo.PresentFactionNames.Add(faction.Name);
            }
        }

        sdo.AreaSdos      = AreaSdo.ConvertAreasForSaving(cell.Areas);
        sdo.SettlementSdo = cell.Settlement?.GetSettlementSdo();

        if (sdo.SettlementSdo != null)
        {
            foreach (var areaSdo in sdo.AreaSdos)
            {
                if (cell.Areas[areaSdo.X, areaSdo.Y].SettlementSection != null)
                {
                    areaSdo.SettlementSdo = sdo.SettlementSdo;
                }
            }
        }

        return(sdo);
    }
コード例 #3
0
    private static SaveData.SerializableMapDictionary ConvertMapForSaving(Cell[,] map)
    {
        var height = map.GetLength(0);
        var width  = map.GetLength(1);

        var convertedCells = new SaveData.SerializableMapDictionary();

        for (var currentRow = 0; currentRow < height; currentRow++)
        {
            for (var currentColumn = 0; currentColumn < width; currentColumn++)
            {
                var currentCell = map[currentRow, currentColumn];

                var tempSdo = CellSdo.ConvertToCellSdo(currentCell);

                convertedCells.Add(currentCell.Id, tempSdo);
            }
        }

        return(convertedCells);
    }
コード例 #4
0
    private static Cell[,] ConvertMapForPlaying(SaveData.SerializableMapDictionary savedMap)
    {
        var tempMap = WorldData.Instance.Map;

        foreach (var cellSdo in savedMap)
        {
            var x = cellSdo.Value.X;
            var y = cellSdo.Value.Y;

            tempMap[x, y] = CellSdo.ConvertToCell(cellSdo.Value);

            if (WorldData.Instance.MapDictionary.ContainsKey(cellSdo.Key))
            {
                WorldData.Instance.MapDictionary[cellSdo.Key] = tempMap[x, y];
            }
            else
            {
                WorldData.Instance.MapDictionary.Add(cellSdo.Key, tempMap[x, y]);
            }
        }

        return(tempMap);
    }
コード例 #5
0
 public CellSdo ConvertToCellSdo()
 {
     return(CellSdo.ConvertToCellSdo(this));
 }