Beispiel #1
0
        /// <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;
        }