Beispiel #1
0
        // This creates a list from a configuration structure

        /*internal DataLocationList(Configuration cfg, string path)
         * {
         *      IDictionary resinfo, rlinfo;
         *      DataLocation res;
         *
         *      // Go for all items in the map info
         *      resinfo = cfg.ReadSetting(path, new ListDictionary());
         *      foreach(DictionaryEntry rl in resinfo)
         *      {
         *              // Item is a structure?
         *              if(rl.Value is IDictionary)
         *              {
         *                      // Create resource location
         *                      rlinfo = (IDictionary)rl.Value;
         *                      res = new DataLocation();
         *
         *                      // Copy information from Configuration to ResourceLocation
         *                      if(rlinfo.Contains("type") && (rlinfo["type"] is int)) res.type = (int)rlinfo["type"];
         *                      if(rlinfo.Contains("location") && (rlinfo["location"] is string)) res.location = (string)rlinfo["location"];
         *                      if(rlinfo.Contains("option1") && (rlinfo["option1"] is int)) res.option1 = General.Int2Bool((int)rlinfo["option1"]);
         *                      if(rlinfo.Contains("option2") && (rlinfo["option2"] is int)) res.option2 = General.Int2Bool((int)rlinfo["option2"]);
         *                      if(rlinfo.Contains("notfortesting") && (rlinfo["notfortesting"] is int)) res.notfortesting = General.Int2Bool((int)rlinfo["notfortesting"]);
         *
         *                      // Add resource
         *                      Add(res);
         *              }
         *      }
         * }*/

        #endregion

        #region ================== Methods

        // This merges two lists together
        public static DataLocationList Combined(DataLocationList a, DataLocationList b)
        {
            DataLocationList result = new DataLocationList();

            result.AddRange(a);
            result.AddRange(b);
            return(result);
        }
        // This loads all data resources
        internal void Load(DataLocationList locations)
        {
            // Create collections
            containers       = new List <DataReader>();
            images           = new Dictionary <int, ImageData>();
            imageque         = new Queue <ImageData>();
            previews         = new PreviewManager();
            imagesets        = new List <MatchingImageSet>();
            usedimages       = new Dictionary <int, int>();
            spritecategories = General.Map.Config.GetThingCategories();
            spritetypes      = General.Map.Config.GetThingTypes();

            // Load texture sets
            foreach (DefinedImageSet ts in General.Map.ConfigSettings.TextureSets)
            {
                imagesets.Add(new MatchingImageSet(ts));
            }

            // Sort the texture sets
            imagesets.Sort();

            // Special textures sets
            allimages      = new AllImageSet();
            resourceimages = new List <ResourceImageSet>();

            // Go for all locations
            foreach (DataLocation dl in locations)
            {
                DataReader c;
                try
                {
                    // Choose container type
                    switch (dl.type)
                    {
                    // GRP file container
                    case DataLocationType.RESOURCE_GRP:
                        c = new GRPReader(dl);
                        break;

                    case DataLocationType.RESOURCE_ART:
                        c = new ARTReader(dl);
                        break;

                    // Directory container
                    //case DataLocationType.RESOURCE_DIRECTORY:
                    //c = new DirectoryReader(dl);
                    //break;

                    // PK3 file container
                    //case DataLocationType.RESOURCE_PK3:
                    //c = new PK3Reader(dl);
                    //break;

                    default: throw new NotImplementedException("Unknown DataLocationType");
                    }
                }
                catch (Exception e)
                {
                    // Unable to load resource
                    General.ErrorLogger.Add(ErrorType.Error, "Unable to load resources from location \"" + dl.location + "\". Please make sure the location is accessible and not in use by another program. The resources will now be loaded with this location excluded. You may reload the resources to try again.\n" + e.GetType().Name + " when creating data reader: " + e.Message);
                    General.WriteLogLine(e.StackTrace);
                    continue;
                }

                // Add container
                containers.Add(c);
                resourceimages.Add(c.ImageSet);
            }

            // Load stuff
            LoadPalette();
            images = LoadImages();

            // Sort things
            foreach (SpriteCategory tc in spritecategories)
            {
                tc.SortIfNeeded();
            }

            // Update the used textures
            General.Map.Data.UpdateUsedImages();

            // Add texture names to texture sets
            foreach (KeyValuePair <int, ImageData> img in images)
            {
                // Add to all sets where it matches
                foreach (var ms in imagesets)
                {
                    ms.AddImage(img.Value);
                }

                // Add to all
                allimages.AddImage(img.Value);
            }

            // Start background loading
            StartBackgroundLoader();

            // Output info
            General.WriteLogLine("Loaded " + images.Count + " images, " + spritetypes.Count + " sprite types");
        }