/// <summary> /// Asynchronously loads maps from world with the specified <see cref="worldId" />. /// </summary> /// <param name="worldId">World identifier.</param> /// <param name="signFormat"><see cref="MapData" /> reader.</param> /// <param name="positionMapper">The position mapper used to get map rectangle.</param> /// <returns>The loaded maps.</returns> public async Task <List <Map> > LoadMapsAsync(string worldId, ISignFormat signFormat, IPositionMapper positionMapper) { var botBits = new BotBitsClient(); await Login.Of(botBits).AsGuestAsync().CreateJoinRoomAsync(worldId); Console.WriteLine("Connected"); var connectResult = new TaskCompletionSource <bool>(); var cts = new CancellationTokenSource(); // Wait for init or info event // Only one of them is sent depending on visibility of the world WaitForInfoEvent(botBits, connectResult, cts.Token); WaitForInitEvent(botBits, connectResult, cts.Token); await connectResult.Task; cts.Cancel(); var maps = OnLoadMaps(botBits, signFormat, positionMapper); botBits.Dispose(); return(maps); }
public MapSpot(int id, Blocks blocks, int width, int height, ISignFormat signFormat) { Id = id; Width = width; Height = height; var spotWidth = Width + 4; var spotHeight = Height + 4; var mapsInRow = (blocks.Width - 2) / spotWidth; var x = spotWidth * (id % mapsInRow); var y = spotHeight * (id / mapsInRow); SignPoint = new Point(x + 2, y + 2); MapPoint = new Point(x + 3, y + 3); var block = blocks.At(SignPoint).Foreground.Block; if (block.Type != ForegroundType.Sign) { return; } MapData mapData; if (!signFormat.TryGetMapData(block.Text, "", out mapData)) { return; } Map = new Map(blocks, new Rectangle(MapPoint.X, MapPoint.Y, Width, Height), mapData.Name, mapData.Creators); }
private List <Map> OnLoadMaps(BotBitsClient botBits, ISignFormat signFormat, IPositionMapper positionMapper) { var maps = new List <Map>(); var blocks = Blocks.Of(botBits); for (var x = 1; x < blocks.Width - MapWidth; x++) { for (var y = 1; y < blocks.Height - MapHeight; y++) { var block = blocks.At(x, y).Foreground.Block; if (block.Type != ForegroundType.Sign) { continue; } MapData mapData; if (!signFormat.TryGetMapData(block.Text, Room.Of(botBits).Owner, out mapData)) { continue; } maps.Add(new Map(blocks, positionMapper.GetMapRectangle(new Point(x, y), MapWidth, MapHeight), mapData.Name, mapData.Creators)); } } return(maps); }
private List<Map> OnLoadMaps(BotBitsClient botBits, ISignFormat signFormat, IPositionMapper positionMapper) { var maps = new List<Map>(); var blocks = Blocks.Of(botBits); for (var x = 1; x < blocks.Width - MapWidth; x++) { for (var y = 1; y < blocks.Height - MapHeight; y++) { var block = blocks.At(x, y).Foreground.Block; if (block.Type != ForegroundType.Sign) continue; MapData mapData; if (!signFormat.TryGetMapData(block.Text, Room.Of(botBits).Owner, out mapData)) continue; maps.Add(new Map(blocks, positionMapper.GetMapRectangle(new Point(x, y), MapWidth, MapHeight), mapData.Name, mapData.Creators)); } } return maps; }
public MapSpot(int id, Blocks blocks, int width, int height, ISignFormat signFormat) { Id = id; Width = width; Height = height; var spotWidth = Width + 4; var spotHeight = Height + 4; var mapsInRow = (blocks.Width - 2)/spotWidth; var x = spotWidth*(id%mapsInRow); var y = spotHeight*(id/mapsInRow); SignPoint = new Point(x + 2, y + 2); MapPoint = new Point(x + 3, y + 3); var block = blocks.At(SignPoint).Foreground.Block; if (block.Type != ForegroundType.Sign) return; MapData mapData; if (!signFormat.TryGetMapData(block.Text, "", out mapData)) return; Map = new Map(blocks, new Rectangle(MapPoint.X, MapPoint.Y, Width, Height), mapData.Name, mapData.Creators); }
/// <summary> /// Asynchronously loads maps from world with the specified <see cref="worldId" />. /// </summary> /// <param name="worldId">World identifier.</param> /// <param name="signFormat"><see cref="MapData" /> reader.</param> /// <param name="positionMapper">The position mapper used to get map rectangle.</param> /// <returns>The loaded maps.</returns> public async Task<List<Map>> LoadMapsAsync(string worldId, ISignFormat signFormat, IPositionMapper positionMapper) { var botBits = new BotBitsClient(); await Login.Of(botBits).AsGuestAsync().CreateJoinRoomAsync(worldId); Console.WriteLine("Connected"); var connectResult = new TaskCompletionSource<bool>(); var cts = new CancellationTokenSource(); // Wait for init or info event // Only one of them is sent depending on visibility of the world WaitForInfoEvent(botBits, connectResult, cts.Token); WaitForInitEvent(botBits, connectResult, cts.Token); await connectResult.Task; cts.Cancel(); var maps = OnLoadMaps(botBits, signFormat, positionMapper); botBits.Dispose(); return maps; }
public List <Map> LoadMaps(string worldId, ISignFormat signFormat, IPositionMapper positionMapper) { return(LoadMapsAsync(worldId, signFormat, positionMapper).Result); }
public List<Map> LoadMaps(string worldId, ISignFormat signFormat, IPositionMapper positionMapper) { return LoadMapsAsync(worldId, signFormat, positionMapper).Result; }