public ChunkBuilder GetBuilderAtPosition(IntVector2 worldPosition) { if (!_chunkBuildersByWorldPosition.TryGetValue(worldPosition, out var builder)) { if (GameSaves.HasGameData(worldPosition.ToString() + "B")) { builder = LoadBuilder(worldPosition); } else if (!GameSaves.HasGameData(worldPosition.ToString())) { builder = AddBuilder(worldPosition); } } return(builder); }
private void CreateChunk(IntVector2 worldPosition) { if (GetNearestChunkPosition(worldPosition) != worldPosition) { throw new InvalidOperationException($"Chunk cannot be spawned at {worldPosition}."); } if (_chunksByWorldPosition.ContainsKey(worldPosition)) { return; } else { Chunk chunk; if (GameSaves.HasGameData(worldPosition.ToString())) { _log.Info($"Loading Chunk at {worldPosition}."); chunk = LoadChunk(worldPosition); } else { _log.Info($"Building Chunk at {worldPosition}."); chunk = BuildChunk(worldPosition); } Register(chunk); if (_chunkConstructionCoroutine == null) { _chunkConstructionCoroutine = StartCoroutine(ChunkConstructionCoroutine()); } foreach (var direction in Directions.Cardinals) { if (_chunkBuildersByWorldPosition.TryGetValue(worldPosition + direction, out var neighborBuilder)) { _spaceArchitect.CheckForSpaces(neighborBuilder); } } } }