示例#1
0
        public BreezeInstance(ContentManager contentManager, SpriteBatch spriteBatch, Game game)
        {
            ScreenManager = new ScreenManager();
            SpriteBatch   = new SmartSpriteBatch(spriteBatch.GraphicsDevice);
            AssetLibrary  = new AssetLibrary(SpriteBatch);
            GaussianBlur  = new Breeze.Helpers.GaussianBlur(game);
            InputService  = new InputService();



#if WINDOWS_UAP
            StorageFolder folder = Windows.ApplicationModel.Package.Current.InstalledLocation;

            ContentPath         = folder.Path + "\\";
            ContentPathRelative = "\\";
#elif ANDROID
            Solids.ContentPath         = "Content\\";
            Solids.ContentPathRelative = "Content\\";
#else
            Solids.ContentPath         = "\\Ezmuze.Content\\";
            Solids.ContentPathRelative = "\\Ezmuze.Content\\";
#endif

#if WINDOWS_UAP
            //string pakPath = ContentPathRelative.GetFilePath("Content.pak");
            Debug.WriteLine(FileLocation.InstalledLocation);

            if (Storage.FileSystemStorage.FileExists(ContentPath.GetFilePath("Content.pak")))
            {
                string cpath = ContentPathRelative.GetFilePath("Content.pak");
                Debug.WriteLine("content pak path: " + cpath);
                StorageFile packBuffer = Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(cpath).GetAwaiter().GetResult();

                Stream stream       = packBuffer.OpenStreamForReadAsync().Result;
                int    streamLength = (int)stream.Length;
                byte[] tmp          = new byte[streamLength];
                stream.Read(tmp, 0, tmp.Length);

                string tocPath = ContentPathRelative.GetFilePath("Content.toc");

                Debug.WriteLine("Toc path: " + tocPath);
                var tocBuffer = Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(tocPath).GetAwaiter().GetResult();

                string json = FileIO.ReadTextAsync(tocBuffer).GetAwaiter().GetResult();



                Storage.DatfileStorage.TabletOfContents = JsonConvert.DeserializeObject <List <FileEntry> >(json);
                Storage.DatfileStorage.DataStorage      = tmp;
            }

            Debug.WriteLine("test!");
            //Solids.Breeze.Storage.Init(Solids.ContentPathRelative,tmp).ConfigureAwait(false).GetAwaiter().GetResult();
#elif ANDROID
            string pakPath = ("Content.pak");
            string tocPath = ("Content.toc");

            Stream tocBuffer = tocPath.FromAsset();
            var    sr        = new StreamReader(tocBuffer);
            string json      = sr.ReadToEnd();

            Solids.DatfileStorage.TabletOfContents = JsonConvert.DeserializeObject <List <Storage.FileEntry> >(json);

            var pakBuffer = pakPath.ToStream().Result;

            int length = Solids.DatfileStorage.TabletOfContents.Last().Start + Solids.DatfileStorage.TabletOfContents.Last().Length;

            byte[] data = new byte[length];
            pakBuffer.Read(data, 0, (int)length);
            Solids.DatfileStorage.DataStorage = data;
#endif
            Solids.Instance = this;



            //todo - this needs to be hella more dynamic
            Fonts = new Font
            {
                EuroStile  = new FontFamily("EuroStile", "eurostile"),
                Consolas   = new FontFamily("Consolas", "consolas"),
                MDL2       = new FontFamily("MDL2", "mdl"),
                Segoe      = new FontFamily("SegoeUI", "SegoeUI"),
                SegoeLight = new FontFamily("SegoeUILight", "SegoeUILight")
            };

            Fonts.Fonts.Add("EuroStile", Fonts.EuroStile);
            Fonts.Fonts.Add("Consolas", Fonts.Consolas);
            Fonts.Fonts.Add("MDL2", Fonts.MDL2);
            Fonts.Fonts.Add("Segoe", Fonts.Segoe);
            Fonts.Fonts.Add("SegoeLight", Fonts.SegoeLight);
        }