示例#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 AreaSdo[] ConvertAreasForSaving(Area[,] areas)
    {
        var height = areas.GetLength(0);
        var width  = areas.GetLength(1);

        var convertedAreas = new AreaSdo[height, width];

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

                var tempSdo = ConvertAreaForSaving(currentArea);
                convertedAreas[currentRow, currentColumn] = tempSdo;
            }
        }

        var index  = 0;
        var single = new AreaSdo[height * width];

        for (var row = 0; row < height; row++)
        {
            for (var column = 0; column < width; column++)
            {
                single[index] = convertedAreas[row, column];
                index++;
            }
        }
        return(single);
    }
示例#3
0
    public static AreaSdo ConvertAreaForSaving(Area area)
    {
        AreaSdo tempSdo;

        tempSdo = new AreaSdo();
        tempSdo.PresentEntityIds = new List <Guid>();
        tempSdo.AreaTiles        = area.AreaBuilt()
            ? TileSdo.ConvertAreaTilesForSaving(area.AreaTiles)
            : null;
        tempSdo.BiomeType           = area.BiomeType;
        tempSdo.PresentFactionNames = new List <string>();
        tempSdo.TurnOrderIds        = new Queue <Guid>();
        tempSdo.X                    = area.X;
        tempSdo.Y                    = area.Y;
        tempSdo.ParentCellId         = area.ParentCell.Id;
        tempSdo.SettlementSdo        = area.Settlement?.GetSettlementSdo();
        tempSdo.SettlementSectionSdo =
            area.SettlementSection != null ? new SettlementSectionSdo(area.SettlementSection) : null;

        if (area.PresentEntities != null)
        {
            foreach (var entity in area.PresentEntities)
            {
                tempSdo.PresentEntityIds.Add(entity.Id);
            }
        }

        if (area.TurnOrder != null)
        {
            foreach (var entity in area.TurnOrder)
            {
                tempSdo.TurnOrderIds.Enqueue(entity.Id);
            }
        }

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

        return(tempSdo);
    }
示例#4
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);
    }