Skip to content

Commit

Permalink
Better support of Sprite for embed: textures
Browse files Browse the repository at this point in the history
Rely on the user to load the model, assume that it is always loaded.
  • Loading branch information
alexguirre committed Jun 26, 2021
1 parent 49eb828 commit 63d3fce
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions Source/Elements/Sprite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public bool IsTextureDictLoaded

public bool IsTextureDictionaryLoaded
{
get { return N.HasStreamedTextureDictLoaded(_textureDict); }
get { return HasTextureDictionaryLoaded(_textureDict); }
}

[Obsolete("Use Sprite.LoadTextureDictionary() instead.")]
Expand All @@ -62,7 +62,7 @@ public void LoadTextureDict()

public void LoadTextureDictionary()
{
N.RequestStreamedTextureDict(_textureDict);
RequestTextureDictionary(_textureDict);
}

/// <summary>
Expand Down Expand Up @@ -108,12 +108,37 @@ public void Draw()
Draw(_textureDict, TextureName, Position, Size, Heading, Color, false);
}

private static void RequestTextureDictionary(string textureDictionary)
{
if (textureDictionary.StartsWith("embed:"))
{
// nothing, the user is in charge of loading the model
}
else
{
N.RequestStreamedTextureDict(textureDictionary);
}
}

private static bool HasTextureDictionaryLoaded(string textureDictionary)
{
if (textureDictionary.StartsWith("embed:"))
{
// nothing, the user is in charge of loading the model, assume it is loaded
return true;
}
else
{
return N.HasStreamedTextureDictLoaded(textureDictionary);
}
}

public static void Draw(string textureDictionary, string textureName, Point position, Size size, float heading, Color color, bool loadTexture = true)
{
if (loadTexture)
{
N.RequestStreamedTextureDict(textureDictionary);
if (!N.HasStreamedTextureDictLoaded(textureDictionary))
RequestTextureDictionary(textureDictionary);
if (!HasTextureDictionaryLoaded(textureDictionary))
{
return;
}
Expand Down

0 comments on commit 63d3fce

Please sign in to comment.