Example #1
0
        public void LoadSpriteX(SpriteXLoader loader, string overrideForm)
        {
            frameData  = new FrameData();
            animations = new Dictionary <FrameType, Dictionary <Enums.Direction, Surface> >();

            loader.Load(this, frameData, overrideForm);

            this.sizeInBytes = 5 * 1000;
        }
Example #2
0
        public static Mugshot GetMugshot(int num, int form, int shiny, int gender)
        {
            string formString = SpriteXLoader.GetSpriteFormString(form, shiny, gender);

            Mugshot sheet = null;

            lock (mugshotCache)
            {
                sheet = mugshotCache.Get(num + formString);
            }
            if (sheet != null)
            {
                return(sheet);
            }
            // If we are still here, that means the sprite wasn't in the cache
            if (System.IO.File.Exists(IO.Paths.GfxPath + "Mugshots/Portrait" + num + ".zip"))
            {
                sheet = new Mugshot(num, formString);
                string changedFormString = formString;

                SpriteXLoader spriteXLoader = new SpriteXLoader(IO.Paths.GfxPath + "Mugshots/Portrait" + num + ".zip", false);
                List <string> forms         = spriteXLoader.LoadForms();

                using (FileStream fileStream = File.OpenRead(IO.Paths.GfxPath + "Mugshots/Portrait" + num + ".zip"))
                {
                    while (true)
                    {
                        if (mugshotCache.ContainsKey(num + changedFormString))
                        {//this point will be hit if the first fallback data to be found is already in the cache
                         //the cache needs to be updated for aliases, but that's it.  No need to load any new data.

                            sheet = mugshotCache.Get(num + changedFormString);
                            break;
                        }
                        else if (forms.Contains(changedFormString) || changedFormString == "r")
                        {//we've found a spritesheet in the file, so load it.
                            spriteXLoader.LoadMugshot(sheet, changedFormString);

                            mugshotCache.Add(num + changedFormString, sheet);

                            break;
                        }

                        // If the form specified wasn't found, continually revert to the backup until only "r" is reached
                        changedFormString = changedFormString.Substring(0, changedFormString.LastIndexOf('-'));
                    }
                }

                //continually add aliases
                string aliasString = formString;
                while (aliasString != changedFormString)
                {
                    //add aliases here
                    mugshotCache.AddAlias(num + aliasString, num + changedFormString);
                    // If the form specified wasn't found, continually revert to the backup until only "r" is reached
                    aliasString = aliasString.Substring(0, aliasString.LastIndexOf('-'));
                }

                return(sheet);
            }
            else
            {
                return(null);
            }
        }
Example #3
0
        public static SpriteSheet GetSpriteSheet(int num, int form, int shiny, int gender)
        {
            //System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            //watch.Start();
            //System.Diagnostics.Debug.WriteLine("PkMn #"+num+"("+form+"/"+shiny+"/"+gender+") requested");
            string formString = SpriteXLoader.GetSpriteFormString(form, shiny, gender);

            SpriteSheet sheet = null;

            lock (spriteCache)
            {
                sheet = spriteCache.Get(num + formString);
            }
            if (sheet != null)
            {
                //watch.Stop();
                //System.Diagnostics.Debug.WriteLine("PkMn #"+num+"("+form+"/"+shiny+"/"+gender+") retrieved in cache in "+watch.ElapsedMilliseconds);
                return(sheet);
            }
            // If we are still here, that means the sprite wasn't in the cache
            if (System.IO.File.Exists(IO.Paths.GfxPath + "Sprites/Sprite" + num + ".zip"))
            {
                sheet = new SpriteSheet(num, formString);
                string changedFormString = formString;

                SpriteXLoader spriteXLoader = new SpriteXLoader(IO.Paths.GfxPath + "Sprites/Sprite" + num + ".zip", true);

                List <string> forms = spriteXLoader.LoadForms();

                while (true)
                {
                    if (spriteCache.ContainsKey(num + changedFormString))
                    {//this point will be hit if the first fallback data to be found is already in the cache
                     //the cache needs to be updated for aliases, but that's it.  No need to load any new data.

                        sheet = spriteCache.Get(num + changedFormString);
                        break;
                    }
                    else if (forms.Contains(changedFormString) || changedFormString == "r")
                    {//we've found a spritesheet in the file, so load it.
                        sheet.LoadSpriteX(spriteXLoader, changedFormString);

                        spriteCache.Add(num + changedFormString, sheet);

                        break;
                    }

                    // If the form specified wasn't found, continually revert to the backup until only "r" is reached
                    changedFormString = changedFormString.Substring(0, changedFormString.LastIndexOf('-'));
                }

                //continually add aliases
                string aliasString = formString;
                while (aliasString != changedFormString)
                {
                    //add aliases here
                    spriteCache.AddAlias(num + aliasString, num + changedFormString);
                    // If the form specified wasn't found, continually revert to the backup until only "r" is reached
                    aliasString = aliasString.Substring(0, aliasString.LastIndexOf('-'));
                }

                //string rootForm = spriteCache.GetOriginalKeyFromAlias(num + formString);
                //if (rootForm != num + formString)
                //{
                //    Logs.Logger.LogDebug("Could not load " + num + formString + ", loaded " + num + rootForm +" instead.");
                //}

                return(sheet);
            }
            else
            {
                //watch.Stop();
                //System.Diagnostics.Debug.WriteLine("PkMn #"+num+"("+form+"/"+shiny+"/"+gender+") failed retrieval in "+watch.ElapsedMilliseconds);
                return(null);
            }
        }
Example #4
0
        public static SpriteSheet GetSpriteSheet(int num, int form, int shiny, int gender)
        {
            //System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            //watch.Start();
            //System.Diagnostics.Debug.WriteLine("PkMn #"+num+"("+form+"/"+shiny+"/"+gender+") requested");
            string formString = SpriteXLoader.GetSpriteFormString(form, shiny, gender);

            SpriteSheet sheet = null;
            lock (spriteCache)
            {
                sheet = spriteCache.Get(num + formString);
            }
            if (sheet != null)
            {
                //watch.Stop();
                //System.Diagnostics.Debug.WriteLine("PkMn #"+num+"("+form+"/"+shiny+"/"+gender+") retrieved in cache in "+watch.ElapsedMilliseconds);
                return sheet;
            }
            // If we are still here, that means the sprite wasn't in the cache
            if (System.IO.File.Exists(IO.Paths.GfxPath + "Sprites/Sprite" + num + ".zip"))
            {

                sheet = new SpriteSheet(num, formString);
                string changedFormString = formString;

                SpriteXLoader spriteXLoader = new SpriteXLoader(IO.Paths.GfxPath + "Sprites/Sprite" + num + ".zip", true);

                List<string> forms = spriteXLoader.LoadForms();

                while (true)
                {
                    if (spriteCache.ContainsKey(num + changedFormString))
                    {//this point will be hit if the first fallback data to be found is already in the cache
                        //the cache needs to be updated for aliases, but that's it.  No need to load any new data.

                        sheet = spriteCache.Get(num + changedFormString);
                        break;
                    }
                    else if (forms.Contains(changedFormString) || changedFormString == "r")
                    {//we've found a spritesheet in the file, so load it.
                        sheet.LoadSpriteX(spriteXLoader, changedFormString);

                        spriteCache.Add(num + changedFormString, sheet);

                        break;
                    }

                    // If the form specified wasn't found, continually revert to the backup until only "r" is reached
                    changedFormString = changedFormString.Substring(0, changedFormString.LastIndexOf('-'));
                }

                //continually add aliases
                string aliasString = formString;
                while (aliasString != changedFormString)
                {
                    //add aliases here
                    spriteCache.AddAlias(num + aliasString, num + changedFormString);
                    // If the form specified wasn't found, continually revert to the backup until only "r" is reached
                    aliasString = aliasString.Substring(0, aliasString.LastIndexOf('-'));
                }

                //string rootForm = spriteCache.GetOriginalKeyFromAlias(num + formString);
                //if (rootForm != num + formString)
                //{
                //    Logs.Logger.LogDebug("Could not load " + num + formString + ", loaded " + num + rootForm +" instead.");
                //}

                return sheet;
            }
            else
            {
                //watch.Stop();
                //System.Diagnostics.Debug.WriteLine("PkMn #"+num+"("+form+"/"+shiny+"/"+gender+") failed retrieval in "+watch.ElapsedMilliseconds);
                return null;
            }
        }
Example #5
0
        public static Mugshot GetMugshot(int num, int form, int shiny, int gender)
        {
            string formString = SpriteXLoader.GetSpriteFormString(form, shiny, gender);

            Mugshot sheet = null;
            lock (mugshotCache)
            {
                sheet = mugshotCache.Get(num + formString);
            }
            if (sheet != null)
            {
                return sheet;
            }
            // If we are still here, that means the sprite wasn't in the cache
            if (System.IO.File.Exists(IO.Paths.GfxPath + "Mugshots/Portrait" + num + ".zip"))
            {

                sheet = new Mugshot(num, formString);
                string changedFormString = formString;

                SpriteXLoader spriteXLoader = new SpriteXLoader(IO.Paths.GfxPath + "Mugshots/Portrait" + num + ".zip", false);
                List<string> forms = spriteXLoader.LoadForms();

                using (FileStream fileStream = File.OpenRead(IO.Paths.GfxPath + "Mugshots/Portrait" + num + ".zip"))
                {
                    while (true)
                    {
                        if (mugshotCache.ContainsKey(num + changedFormString))
                        {//this point will be hit if the first fallback data to be found is already in the cache
                            //the cache needs to be updated for aliases, but that's it.  No need to load any new data.

                            sheet = mugshotCache.Get(num + changedFormString);
                            break;
                        }
                        else if (forms.Contains(changedFormString) || changedFormString == "r")
                        {//we've found a spritesheet in the file, so load it.
                            spriteXLoader.LoadMugshot(sheet, changedFormString);

                            mugshotCache.Add(num + changedFormString, sheet);

                            break;
                        }

                        // If the form specified wasn't found, continually revert to the backup until only "r" is reached
                        changedFormString = changedFormString.Substring(0, changedFormString.LastIndexOf('-'));
                    }
                }

                //continually add aliases
                string aliasString = formString;
                while (aliasString != changedFormString)
                {
                    //add aliases here
                    mugshotCache.AddAlias(num + aliasString, num + changedFormString);
                    // If the form specified wasn't found, continually revert to the backup until only "r" is reached
                    aliasString = aliasString.Substring(0, aliasString.LastIndexOf('-'));
                }

                return sheet;
            }
            else
            {
                return null;
            }
        }
Example #6
0
        public void LoadSpriteX(SpriteXLoader loader, string overrideForm)
        {
            frameData = new FrameData();
            animations = new Dictionary<FrameType, Dictionary<Enums.Direction, Surface>>();

            loader.Load(this, frameData, overrideForm);

            this.sizeInBytes = 5 * 1000;
        }