public void RedrawDynamicTargets(DynamicTextureSource source, string variant, Dictionary <TextureCategory, bool> options) { HSBOperation op = source.OperationMap[variant]; DynamicTextureTarget target = DynamicMapping[source]; RedrawDynamicTargets(target.DefaultTileTargets, op); foreach (TextureCategory category in target.OptionalTileTargets.Keys) { if (options.ContainsKey(category) && options[category]) { RedrawDynamicTargets(target.OptionalTileTargets[category], op); } } }
public static TextureLevelMapping Get(TR2Level level, string mappingFilePrefix, TextureDatabase database, Dictionary <StaticTextureSource, List <StaticTextureTarget> > predefinedMapping = null, List <TR2Entities> entitiesToIgnore = null) { string mapFile = Path.Combine(@"Resources\Textures\Mapping\", mappingFilePrefix + "-Textures.json"); if (!File.Exists(mapFile)) { return(null); } Dictionary <DynamicTextureSource, DynamicTextureTarget> dynamicMapping = new Dictionary <DynamicTextureSource, DynamicTextureTarget>(); Dictionary <StaticTextureSource, List <StaticTextureTarget> > staticMapping = new Dictionary <StaticTextureSource, List <StaticTextureTarget> >(); Dictionary <StaticTextureSource, Dictionary <int, List <LandmarkTextureTarget> > > landmarkMapping = new Dictionary <StaticTextureSource, Dictionary <int, List <LandmarkTextureTarget> > >(); Color skyBoxColour = _defaultSkyBox; Dictionary <string, object> rootMapping = JsonConvert.DeserializeObject <Dictionary <string, object> >(File.ReadAllText(mapFile)); // Read the dynamic mapping - this holds object and sprite texture indices for the level to which we will apply an HSB operation if (rootMapping.ContainsKey("Dynamic")) { SortedDictionary <string, Dictionary <string, object> > mapping = JsonConvert.DeserializeObject <SortedDictionary <string, Dictionary <string, object> > >(rootMapping["Dynamic"].ToString()); foreach (string sourceName in mapping.Keys) { DynamicTextureSource source = database.GetDynamicSource(sourceName); DynamicTextureTarget target = new DynamicTextureTarget { DefaultTileTargets = JsonConvert.DeserializeObject <Dictionary <int, List <Rectangle> > >(mapping[sourceName]["Default"].ToString()) }; if (mapping[sourceName].ContainsKey("Optional")) { target.OptionalTileTargets = JsonConvert.DeserializeObject <Dictionary <TextureCategory, Dictionary <int, List <Rectangle> > > >(mapping[sourceName]["Optional"].ToString()); } dynamicMapping[source] = target; } } // The static mapping contains basic texture segment source to tile target locations if (rootMapping.ContainsKey("Static")) { SortedDictionary <string, object> mapping = JsonConvert.DeserializeObject <SortedDictionary <string, object> >(rootMapping["Static"].ToString()); foreach (string sourceName in mapping.Keys) { staticMapping[database.GetStaticSource(sourceName)] = JsonConvert.DeserializeObject <List <StaticTextureTarget> >(mapping[sourceName].ToString()); } } // Landmark mapping links static sources to room number -> rectangle/triangle indices if (rootMapping.ContainsKey("Landmarks")) { Dictionary <string, Dictionary <int, List <LandmarkTextureTarget> > > mapping = JsonConvert.DeserializeObject <Dictionary <string, Dictionary <int, List <LandmarkTextureTarget> > > >(rootMapping["Landmarks"].ToString()); foreach (string sourceName in mapping.Keys) { landmarkMapping[database.GetStaticSource(sourceName)] = mapping[sourceName]; } } // If a level has had textures removed externally, but the JSON file has static // imports ready for it, we need to make sure they are ignored. if (entitiesToIgnore != null) { List <StaticTextureSource> sources = new List <StaticTextureSource>(staticMapping.Keys); for (int i = 0; i < sources.Count; i++) { StaticTextureSource source = sources[i]; if (source.TextureEntities != null) { foreach (TR2Entities entity in source.TextureEntities) { if (entitiesToIgnore.Contains(entity)) { staticMapping.Remove(source); break; } } } } } // Allows for dynamic mapping to be targeted at levels e.g. when importing non-native // models that are otherwise undefined in the default level JSON data. // This should be done after removing ignored entity textures, for the likes of when // Lara is being replaced. if (predefinedMapping != null) { foreach (StaticTextureSource source in predefinedMapping.Keys) { staticMapping[source] = predefinedMapping[source]; } } // Add global sources, unless they are already defined. These tend to be sprite sequences // so they will be mapped per GenerateSpriteSequenceTargets, but there is also scope to // define global targets if relevant. foreach (StaticTextureSource source in database.GlobalGrouping.Sources.Keys) { if (!staticMapping.ContainsKey(source)) { staticMapping[source] = new List <StaticTextureTarget>(database.GlobalGrouping.Sources[source]); } } // Apply grouping to what has been selected as source elements List <TextureGrouping> staticGrouping = database.GlobalGrouping.GetGrouping(staticMapping.Keys); return(new TextureLevelMapping(level) { DynamicMapping = dynamicMapping, StaticMapping = staticMapping, StaticGrouping = staticGrouping, LandmarkMapping = landmarkMapping, DefaultSkyBox = skyBoxColour }); }
private void OnMediaOpened() { _textureSource = new DynamicTextureSource(Width, Height, TextureRender, this); RaiseMediaOpened(); }