private List <StaticTextureSource> GetSourcesToMonitor(List <TR2Entities> entities)
        {
            List <TR2Entities> expandedEntities = new List <TR2Entities>(entities);

            // This needs improving - it shouldn't be defined here but we need to capture
            // things like flames being imported into Boat, Opera, Skidoo and the fact that
            // the red Skidoo is available when importing MercSnomobDriver.
            foreach (TR2Entities entity in _expandedMonitorMap.Keys)
            {
                if (expandedEntities.Contains(entity) && !expandedEntities.Contains(_expandedMonitorMap[entity]))
                {
                    expandedEntities.Add(_expandedMonitorMap[entity]);
                }
            }

            List <StaticTextureSource> sources = new List <StaticTextureSource>();

            foreach (TR2Entities entity in expandedEntities)
            {
                foreach (StaticTextureSource source in _textureDatabase.GetStaticSource(entity))
                {
                    // Does the source have any defined object texture indices we are interested in monitoring?
                    if (source.EntityTextureMap != null && !sources.Contains(source))
                    {
                        sources.Add(source);
                    }
                }
            }

            return(sources);
        }
Beispiel #2
0
        public GlobalGrouping(TextureDatabase database)
        {
            Sources  = new Dictionary <StaticTextureSource, List <StaticTextureTarget> >();
            Grouping = new List <TextureGrouping>();

            Dictionary <string, object> globalData = JsonConvert.DeserializeObject <Dictionary <string, object> >(File.ReadAllText(@"Resources\Textures\Source\Static\global_grouping.json"));

            // These sources will be added to all levels automatically without having to explicitly map them. The targets
            // can be empty for such things as dynamic sprite sequence mapping, or filled with shared values in all levels
            // (not currently used).
            if (globalData.ContainsKey("GlobalSources"))
            {
                Dictionary <string, List <StaticTextureTarget> > sources = JsonConvert.DeserializeObject <Dictionary <string, List <StaticTextureTarget> > >(globalData["GlobalSources"].ToString());
                foreach (string sourceName in sources.Keys)
                {
                    Sources.Add(database.GetStaticSource(sourceName), sources[sourceName]);
                }
            }

            if (globalData.ContainsKey("GlobalGrouping"))
            {
                List <Dictionary <string, object> > groupListData = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(globalData["GlobalGrouping"].ToString());
                foreach (IDictionary <string, object> groupData in groupListData)
                {
                    TextureGrouping grouping = new TextureGrouping
                    {
                        Leader = database.GetStaticSource(groupData["Leader"].ToString())
                    };

                    if (groupData.ContainsKey("Masters"))
                    {
                        // Masters can be defined and if they are present in a source list, the leader will be ignored
                        SortedSet <string> masters = JsonConvert.DeserializeObject <SortedSet <string> >(groupData["Masters"].ToString());
                        foreach (string sourceName in masters)
                        {
                            grouping.Masters.Add(database.GetStaticSource(sourceName));
                        }
                    }

                    SortedSet <string> followers = JsonConvert.DeserializeObject <SortedSet <string> >(groupData["Followers"].ToString());
                    foreach (string sourceName in followers)
                    {
                        grouping.Followers.Add(database.GetStaticSource(sourceName));
                    }

                    if (groupData.ContainsKey("ThemeAlternatives"))
                    {
                        Dictionary <string, Dictionary <string, string> > alternatives = JsonConvert.DeserializeObject <Dictionary <string, Dictionary <string, string> > >(groupData["ThemeAlternatives"].ToString());
                        foreach (string theme in alternatives.Keys)
                        {
                            Dictionary <StaticTextureSource, string> map = new Dictionary <StaticTextureSource, string>();
                            foreach (string sourceName in alternatives[theme].Keys)
                            {
                                map.Add(database.GetStaticSource(sourceName), alternatives[theme][sourceName]);
                            }
                            grouping.ThemeAlternatives.Add(theme, map);
                        }
                    }

                    Grouping.Add(grouping);
                }
            }
        }