public static BaseTile[][] MakeChunk(string str, int chunkSize, UnityAction <string> error = null, bool rle = true) { BaseTile[][] chunk = new BaseTile[chunkSize][]; if (rle && str != null) { str = UnRLE(str); } string[] parts = str.Split(','); if (parts.Length != chunkSize * chunkSize) { if (error != null) { error.Invoke("Incorrect number of tiles for chunk: found " + parts.Length + " when " + chunkSize * chunkSize + " were expected."); } return(null); } for (int x = 0; x < chunkSize; x++) { chunk[x] = new BaseTile[chunkSize]; for (int y = 0; y < chunkSize; y++) { int index = x + chunkSize * y; string prefab = parts[index].Trim(); if (prefab == NULL_ERROR.ToString()) { continue; } if (BaseTile.ContainsTile(prefab)) { chunk[x][y] = BaseTile.GetTile(prefab); } else { if (error != null) { error.Invoke("Tile '" + prefab + "' not found @ local position " + x + ", " + y + "."); } } } } return(chunk); }
public void ApplyPendingOperationsToChunk(int index, bool destroyList = false) { // Applies pending tile operations from clients to a loaded chunk on the server. if (AnyPendingOperationsFor(index)) { if (!IsChunkLoaded(index)) { if (!IsChunkLoading(index)) { Debug.LogError("The chunk for index " + index + " is not loaded or loading, cannot apply pending operations."); } } Chunk chunk = GetChunkFromIndex(index); // Set tiles based on the pending tile operations. foreach (NetPendingTile op in PendingOperations[index]) { bool empty = op.PrefabIsNull(); BaseTile tile = null; if (!empty) { if (!BaseTile.ContainsTile(op.Prefab)) { Debug.LogError("Pending operation requested tile '" + op.Prefab + "', but the server could not find it."); continue; } tile = BaseTile.GetTile(op.Prefab); } int globalX = op.X + chunk.X * ChunkSize; int globalY = op.Y + chunk.Y * ChunkSize; // Set the tile, locally on the server, without networking. SetTile_Server(tile, globalX, globalY, false); } // Clear those pending operations, they are no longer pending! if (!destroyList) { PendingOperations[index].Clear(); } else { PendingOperations.Remove(index); } } }