Пример #1
0
        public string Load(string file, string assign = "")
        {
            try {
                var tag = assign;
                var at  = 0;
                if (tag == "")
                {
                    do
                    {
                        at++; tag = $"IMAGE:{at}";
                    } while (Images.ContainsKey(tag));
                }
                if (qstr.Suffixed(file.ToLower(), ".jpbf"))
                {
                    Images[tag] = TQMG.GetBundle(file);
                }
                else
                {
                    Images[tag] = TQMG.GetImage(file);
                }
                if (Images[tag] == null)
                {
                    throw new Exception($"Filed loading {file} at {tag}\n{UseJCR6.JCR6.JERROR}");
                }
                return(tag);
            } catch (Exception Catastrophe) {
#if DEBUG
                SBubble.MyError($"Bubble.Graphics.Images.Load(\"{file}\",\"{assign}\")", Catastrophe.Message, $"{SBubble.TraceLua(vm)}\n\n.NET Traceback:\n{Catastrophe.StackTrace}");
#else
                SBubble.MyError($"Bubble.Graphics.Images.Load(\"{file}\",\"{assign}\")", Catastrophe.Message, $"{SBubble.TraceLua(vm)}");
#endif
                return("Il ya une catastrophe");
            }
        }
Пример #2
0
        TQMGImage GetTex(KthuraObject obj)
        {
            var file  = obj.Texture;
            var kind  = obj.kind;
            var lay   = obj.Parent;
            var map   = lay.Parent;
            var mfile = qstr.StripExt(file);

            if (qstr.ExtractExt(file.ToUpper()) == "PNG" && map.TextureJCR.Exists($"{mfile}.frames") && map.TextureJCR.DirExists($"{mfile}.jpbf"))
            {
                var rfile = $"{mfile}.jpbf";
                switch (AutoBundle)
                {
                case TAutoBundle.Off: break;

                case TAutoBundle.AutomaticallyFixObject:
                    obj.Texture = rfile;
                    // Fallthrough... Otherwise not supported in C#, so this is the only way to do it (bad bad Microsoft)
                    goto case TAutoBundle.ReplaceInLoadOnly;

                case TAutoBundle.ReplaceInLoadOnly:
                    file = rfile;
                    break;
                }
            }
            if (map != LastUsedMap)
            {
                Textures.Clear();                     // Only store texture per map. Will take too much RAM otherwise!
            }
            LastUsedMap = map;
            var tag = $"{kind}::{file}";

            if (!Textures.ContainsKey(tag))
            {
                if (qstr.ExtractExt(file.ToUpper()) == "JPBF")
                {
                    Textures[tag] = TQMG.GetBundle(map.TextureJCR, $"{file}/");
                    //Bubble.BubConsole.WriteLine($"KTHURA DRAW DEBUG: Loading Bundle {file}", 255, 255, 0); // debug! (must be on comment when not in use)
                }
                else
                {
                    if (map.TextureJCR == null)
                    {
                        Debug.WriteLine("TextureJCR is null???");
                    }
                    var bt = map.TextureJCR.ReadFile(file);
                    if (bt == null)
                    {
                        if (NoTexture != null)
                        {
                            Textures[tag] = NoTexture; //TQMG.GetImage(NoTexture.GetTex(0));
                            System.Console.Beep();
                            Debug.WriteLine($"Texture {file} for {tag} could not be loaded , so set to alternet picture in stead ({UseJCR6.JCR6.JERROR})");
                            //return NoTexture;
                        }
                        else
                        {
                            CrashOnNoTex?.Invoke($"Couldn't open texture file {file} for {tag}");
                            Debug.WriteLine($"Couldn't open texture file {file} for {tag}");
                            return(null);
                        }
                    }
                    else
                    {
                        Textures[tag] = TQMG.GetImage(bt);
                        if (Textures[tag] == null)
                        {
                            if (NoTexture != null)
                            {
                                Textures[tag] = NoTexture;
                                System.Console.Beep();
                                Debug.WriteLine($"Texture {tag} could not be loaded, so set to alternet picture in stead");
                            }
                            else
                            {
                                CrashOnNoTex?.Invoke($"Texture `{file}` didn't load at all on tag {tag}.\n{UseJCR6.JCR6.JERROR}");
                            }
                        }
                    }
                }
                if (Textures[tag].Frames == 0)
                {
                    CrashOnNoTex?.Invoke($"Texture `{file}` for tag `{tag}` has no frames");
                }
                if (obj.kind == "Obstacle" || obj.kind == "Actor")
                {
                    Textures[tag].HotBottomCenter();
                }
            }
            return(Textures[tag]);
        }