private void GetWorldDataCallback(AsyncResult result)
        {
            LevelMetadata     level = (LevelMetadata)result.Param;
            LevelBrowserState state = (LevelBrowserState)level.BrowserState;

            if (result.Success)
            {
                AsyncResult_GetWorldData data = result as AsyncResult_GetWorldData;
                if (data != null)
                {
                    data.World.Data.WorldId = data.World.Info.WorldId;
                    level.DownloadState     = LevelMetadata.DownloadStates.Complete;
                }
                else
                {
                    level.DownloadState = LevelMetadata.DownloadStates.Failed;
                }

                state.downloadCallback(data.World.Data, data.World.Info.ThumbnailBytes, level);
            }
            else
            {
                level.DownloadState = LevelMetadata.DownloadStates.Failed;
                state.downloadCallback(null, null, level);
            }
        }
        private void GotThumbnail(AsyncResult ar)
        {
            AsyncResult_Thumbnail result = (AsyncResult_Thumbnail)ar;
            LevelMetadata         level  = (LevelMetadata)result.Param;
            LevelBrowserState     state  = (LevelBrowserState)level.BrowserState;

            if (result.Success)
            {
                MemoryStream stream = new MemoryStream(result.ThumbnailBytes);
                level.Thumbnail.Texture = Storage4.TextureLoad(stream);
                level.Thumbnail.Loading = false;
            }
            else
            {
                // TODO: Set thumbnail to use missing icon.
            }

            if (state.thumbnailCallback != null)
            {
                state.thumbnailCallback(level);
            }
            state.thumbnailCallback = null;

            thumbnailLoadOpCount -= 1;
        }
        public bool StartDownloadingWorld(LevelMetadata level, LevelDownloadCompleteEvent callback)
        {
            LevelBrowserState state = (LevelBrowserState)level.BrowserState;

            state.downloadCallback = callback;
            level.DownloadState    = LevelMetadata.DownloadStates.InProgress;
            return(0 != Web.Community.Async_GetWorldData(level.WorldId, GetWorldDataCallback, level));
        }
Beispiel #4
0
        private void LevelRemoved_Synched(LevelMetadata level)
        {
            for (int i = 0; i < queries.Count; ++i)
            {
                LevelSetQuery query = queries[i] as LevelSetQuery;
                query.LevelRemoved(level);
            }

            LevelBrowserState state = (LevelBrowserState)level.BrowserState;

            state.level        = null;
            level.BrowserState = null;
        }
        private void FetchComplete(AsyncResult ar)
        {
            AsyncResult_GetPageOfLevels result = (AsyncResult_GetPageOfLevels)ar;

            if (result.Success)
            {
                int count = 0;
                foreach (LevelMetadata level in result.Page.Listing)
                {
                    if (IndexOf(level.WorldId) == -1)
                    {
                        LevelBrowserState state = new LevelBrowserState();
                        state.level        = level;
                        level.BrowserState = state;

                        level.Browser = this;
                        allLevels.Add(level);
                        LevelAdded(level);
                        count += 1;
                    }
                }

                if (result.Page.First >= result.Page.Total)
                {
                    pagingEndReached = true;
                }

                pagingFirst += count;
            }
            else
            {
                // An error occured, stop trying.
                pagingEndReached = true;
            }

            ILevelSetQuery query = (ILevelSetQuery)ar.Param;

            query.NotifyFetchComplete();

            pagingOpCount -= 1;
        }
        public void StartDownloadingThumbnail(LevelMetadata level, ThumbnailDownloadCompleteEvent callback, bool lowPriority)
        {
            if (level != null && !level.Thumbnail.IsLoaded && !level.Thumbnail.Loading)
            {
                LevelBrowserState state = (LevelBrowserState)level.BrowserState;
                state.thumbnailCallback = callback;

                // If it already exists in the queue, move it to the end.
                queuedThumbnailLoads.Remove(level);
                queuedThumbnailLoads.Add(level);
            }

            // Only keep a max of 20 pending thumbnail loads, that way of we're just scrolling
            // to the end of the list, we can discard many of these requests as they pass out of view.
            while (queuedThumbnailLoads.Count > 20)
            {
                LevelBrowserState state = (LevelBrowserState)queuedThumbnailLoads[0].BrowserState;
                state.thumbnailCallback = null;
                queuedThumbnailLoads.RemoveAt(0);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Reads a directory, building the list of level metadata available for browsing.
        /// </summary>
        /// <param name="dataSource"></param>
        /// <returns></returns>
        private void ReadDataSource(string folder, Genres tag, StorageSource sources)
        {
            string path = Path.Combine(BokuGame.Settings.MediaPath, BokuGame.LevelsPath, folder);

            string[] files = null;

            try
            {
#if NETFX_CORE
                files = Storage4.GetFiles(path, @"*.Xml", sources);
#else
                files = Storage4.GetFiles(path, @"*.Xml", sources, SearchOption.TopDirectoryOnly);
#endif
            }
            catch { }

            if (files != null)
            {
                // Filter out AutoSave.Xml
                List <string> filteredFiles = new List <string>();
                for (int i = 0; i < files.Length; ++i)
                {
                    if (files[i].ToUpper().Contains("AUTOSAVE"))
                    {
                        continue;
                    }
                    filteredFiles.Add(files[i]);
                }
                files = filteredFiles.ToArray();

                // Load level metadata records
                for (int i = 0; running && i < files.Length; i++)
                {
                    try
                    {
                        string       filename = Path.GetFileName(files[i]);
                        string       fullPath = Path.Combine(path, filename);
                        XmlWorldData xml      = XmlWorldData.Load(fullPath, XnaStorageHelper.Instance, (int)sources);
                        if (xml == null)
                        {
                            continue;
                        }

                        LevelMetadata level = new LevelMetadata();
                        level.FromXml(xml);

                        level.Genres |= tag;

                        LevelBrowserState state = new LevelBrowserState();
                        state.level        = level;
                        level.BrowserState = state;

                        // Force the creator name of built-ins to "Microsoft"
                        if ((level.Genres & Genres.BuiltInWorlds) != 0)
                        {
                            level.Creator = "Kodu Team";
                        }

                        AddLevel(level);
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(e.Message);
                    }
                }
            }
        }