public static IDirectionalTextureProvider GetPrototypeIcon(EntityPrototype prototype, IResourceCache resourceCache) { if (!prototype.Components.TryGetValue("Icon", out var mapping)) { return(resourceCache.GetFallback <TextureResource>().Texture); } return(TextureForConfig(YamlObjectSerializer.NewReader(mapping), resourceCache)); }
private static IRsiStateLike TextureForConfig(ObjectSerializer serializer, IResourceCache resourceCache) { DebugTools.Assert(serializer.Reading); if (serializer.TryGetCacheData <IRsiStateLike>(SerializationCache, out var dirTex)) { return(dirTex); } var tex = serializer.ReadDataField <string?>("texture", null); if (!string.IsNullOrWhiteSpace(tex)) { dirTex = resourceCache.GetResource <TextureResource>(SpriteComponent.TextureRoot / tex).Texture; serializer.SetCacheData(SerializationCache, dirTex); return(dirTex); } RSI rsi; var rsiPath = serializer.ReadDataField <string?>("sprite", null); if (string.IsNullOrWhiteSpace(rsiPath)) { dirTex = resourceCache.GetFallback <TextureResource>().Texture; serializer.SetCacheData(SerializationCache, dirTex); return(dirTex); } var path = SpriteComponent.TextureRoot / rsiPath; try { rsi = resourceCache.GetResource <RSIResource>(path).RSI; } catch { dirTex = resourceCache.GetFallback <TextureResource>().Texture; serializer.SetCacheData(SerializationCache, dirTex); return(dirTex); } var stateId = serializer.ReadDataField <string?>("state", null); if (string.IsNullOrWhiteSpace(stateId)) { Logger.ErrorS(LogCategory, "No state specified."); dirTex = resourceCache.GetFallback <TextureResource>().Texture; serializer.SetCacheData(SerializationCache, dirTex); return(dirTex); } if (rsi.TryGetState(stateId, out var state)) { serializer.SetCacheData(SerializationCache, state); return(state); } else { Logger.ErrorS(LogCategory, "State '{0}' does not exist on RSI.", stateId); return(resourceCache.GetFallback <TextureResource>().Texture); } }
private static IRsiStateLike TextureForConfig(IconComponent compData, IResourceCache resourceCache) { return(compData.Icon?.Default ?? resourceCache.GetFallback <TextureResource>().Texture); }