Get() public static method

public static Get ( ) : Content
return Content
Ejemplo n.º 1
0
        /// <summary>
        /// Gets a resource.
        /// </summary>
        /// <param name="filename">The filename of the resource to get.</param>
        /// <returns>A GameGlobal instance containing the resource.</returns>
        public GameGlobal Get(string filename)
        {
            filename = filename.ToLowerInvariant();
            lock (Cache)
            {
                if (Cache.ContainsKey(filename))
                {
                    return(Cache[filename]);
                }

                //if we can't load this let it throw an exception...
                //probably sanity check this when we add user objects.
                var     iff = new IffFile(Path.Combine(Content.Get().BasePath, "objectdata/globals/" + filename + ".iff"));
                OTFFile otf = null;
                try
                {
                    otf = new OTFFile(Path.Combine(Content.Get().BasePath, "objectdata/globals/" + filename + ".otf"));
                }
                catch (IOException)
                {
                    //if we can't load an otf, it probably doesn't exist.
                }
                var resource = new GameGlobalResource(iff, otf);

                var item = new GameGlobal
                {
                    Resource = resource
                };

                Cache.Add(filename, item);

                return(item);
            }
        }
Ejemplo n.º 2
0
 public void Execute()
 {
     if (Chunk != null)
     {
         lock (Chunk)
         {
             try
             {
                 if (CausesChange)
                 {
                     Content.Get().Changes.ChunkChanged(Chunk);
                 }
                 Action();
             }
             catch (Exception)
             {}
         }
     }
     else
     {
         try
         { Action(); }
         catch (Exception)
         { }
     }
     if (Signal != null)
     {
         Signal.Set();
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets a resource.
        /// </summary>
        /// <param name="filename">The filename of the resource to get.</param>
        /// <returns>A GameGlobal instance containing the resource.</returns>
        public GameGlobal Get(string filename)
        {
            filename = filename.ToLowerInvariant();
            lock (Cache)
            {
                if (Cache.ContainsKey(filename))
                {
                    return(Cache[filename]);
                }

                //if we can't load this let it throw an exception...
                //probably sanity check this when we add user objects.

                GameGlobalResource resource = null;

                if (TS1Provider != null)
                {
                    var data = TS1Provider.GetEntry(
                        TS1Provider.GetAllEntries().FirstOrDefault(x => x.Key.ToLowerInvariant() == (filename + ".iff").ToLowerInvariant()));

                    if (data != null)
                    {
                        using (var stream = new MemoryStream(data))
                        {
                            var iff = new IffFile();
                            iff.Read(stream);
                            resource = new GameGlobalResource(iff, null);
                        }
                    }
                }
                else
                {
                    var     iff = new IffFile(Path.Combine(Content.Get().BasePath, "objectdata/globals/" + filename + ".iff"));
                    OTFFile otf = null;
                    try
                    {
                        var rewrite = PIFFRegistry.GetOTFRewrite(filename + ".otf");
                        otf = new OTFFile(rewrite ?? Path.Combine(Content.Get().BasePath, ("objectdata/globals/" + filename + ".otf")));
                    }
                    catch (IOException)
                    {
                        //if we can't load an otf, it probably doesn't exist.
                    }
                    resource = new GameGlobalResource(iff, otf);
                }

                var item = new GameGlobal
                {
                    Resource = resource
                };

                Cache.Add(filename, item);

                return(item);
            }
        }
Ejemplo n.º 4
0
        public void RegisterObjects(Files.Formats.IFF.IffFile file)
        {
            var objRegistry = Content.Get().WorldObjects;
            var defs        = file.List <OBJD>();

            if (defs != null)
            {
                foreach (var def in defs)
                {
                    objRegistry.AddObject(file, def);
                }
            }
        }
Ejemplo n.º 5
0
        public void UnregisterObjects(IffFile file)
        {
            var objRegistry = Content.Get().WorldObjects;
            var defs        = file.List <OBJD>();

            if (defs != null)
            {
                foreach (var def in defs)
                {
                    objRegistry.RemoveObject(def.GUID);
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets a resource.
        /// </summary>
        /// <param name="filename">The filename of the resource to get.</param>
        /// <returns>A GameGlobal instance containing the resource.</returns>
        public GameGlobal Get(string filename, bool ts1)
        {
            string filepath;

            Files.Formats.IFF.IffFile iff = null;

            filename = filename.ToLowerInvariant();
            lock (Cache)
            {
                if (Cache.ContainsKey(filename))
                {
                    return(Cache[filename]);
                }

                if (!ts1)
                {
                    filepath = Path.Combine(Content.Get().BasePath, "objectdata/globals/" + filename + ".iff");

                    //if we can't load this let it throw an exception...
                    //probably sanity check this when we add user objects.
                    if (File.Exists(filepath))
                    {
                        iff = new Files.Formats.IFF.IffFile(filepath);
                    }
                }


                if (GlobalFar != null && iff == null)
                {
                    var Giff = new IffFile();

                    var bytes = GlobalFar.GetEntry(GlobalFar.GetAllEntries().FirstOrDefault(x => x.Key.ToLowerInvariant() == (filename + ".iff").ToLowerInvariant()));
                    using (var stream = new MemoryStream(bytes))
                    {
                        Giff.Read(stream);
                    }

                    if (Giff != null)
                    {
                        iff = Giff;
                    }
                }


                OTFFile otf = null;
                try
                {
                    otf = new OTFFile(Path.Combine(Content.Get().BasePath, "objectdata/globals/" + filename + ".otf"));
                }
                catch (IOException)
                {
                    //if we can't load an otf, it probably doesn't exist.
                }
                var resource = new GameGlobalResource(iff, otf);

                var item = new GameGlobal
                {
                    Resource = resource
                };

                Cache.Add(filename, item);

                return(item);
            }
        }