Skip to content

Commit b973bcc

Browse files
authored
fix: client loading asset packs (#2756)
* Normalizes Windows file paths to use forward slashes when loading graphic assets. * Fixes width/height calculation for packed graphics by accounting for the source graphic width/height and if the graphic is rotated in the pack * Triggers loaded event when packed textures are loaded which is needed for UI rendering * Fix a NRE in the UI if textures do not load
1 parent 1f48c1f commit b973bcc

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

Intersect.Client.Core/MonoGame/File Management/MonoContentManager.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,16 @@ public override void LoadTilesets(string[] tilesetnames)
5454
foreach (var t in tilesetnames)
5555
{
5656
var realFilename = tilesetFiles.FirstOrDefault(file => t.Equals(file, StringComparison.InvariantCultureIgnoreCase)) ?? t;
57+
var assetName = Path.Combine(ClientConfiguration.ResourcesDirectory, "tilesets", t.ToLower()).Replace('\\', '/');
5758
if (!string.IsNullOrWhiteSpace(t) &&
5859
(!string.IsNullOrWhiteSpace(realFilename) ||
59-
AtlasReference.TryGet(Path.Combine(ClientConfiguration.ResourcesDirectory, "tilesets", t.ToLower()), out _) != null) &&
60+
AtlasReference.TryGet(assetName, out _)) &&
6061
!mTilesetDict.ContainsKey(t.ToLower()))
6162
{
6263
mTilesetDict.Add(
6364
t.ToLower(),
6465
Core.Graphics.Renderer.LoadTexture(
65-
Path.Combine(ClientConfiguration.ResourcesDirectory, "tilesets", t),
66+
assetName,
6667
Path.Combine(ClientConfiguration.ResourcesDirectory, "tilesets", realFilename)
6768
)
6869
);

Intersect.Client.Core/MonoGame/Graphics/MonoRenderer.Texture.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,13 @@ AtlasReference atlasReference
148148
{
149149
}
150150

151-
public override int Width => PlatformTexture?.Width ?? 0;
151+
public override int Width => AtlasReference?.IsRotated == true
152+
? AtlasReference.Bounds.Height
153+
: AtlasReference?.Bounds.Width ?? PlatformTexture?.Width ?? 0;
152154

153-
public override int Height => PlatformTexture?.Height ?? 0;
155+
public override int Height => AtlasReference?.IsRotated == true
156+
? AtlasReference.Bounds.Width
157+
: AtlasReference?.Bounds.Height ?? PlatformTexture?.Height ?? 0;
154158

155159
protected override Texture2D? CreatePlatformTextureFromStream(Stream stream)
156160
{

Intersect.Client.Framework/Graphics/AtlasReference.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ public static AtlasReference[] GetAllFor(string folderName)
6161

6262
public static bool TryGet(string assetName, [NotNullWhen(true)] out AtlasReference? atlasReference)
6363
{
64-
return _atlasReferences.TryGetValue(assetName, out atlasReference) ||
65-
_atlasReferences.TryGetValue(assetName.ToLowerInvariant(), out atlasReference);
64+
var normalizedAssetName = assetName.Replace('\\', '/');
65+
return _atlasReferences.TryGetValue(normalizedAssetName, out atlasReference) ||
66+
_atlasReferences.TryGetValue(normalizedAssetName.ToLowerInvariant(), out atlasReference);
6667
}
6768
}

Intersect.Client.Framework/Graphics/GameTexture.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,12 @@ private void LoadPlatformTexture(bool force = false)
257257
}
258258

259259
atlasTexture.LoadPlatformTexture(force);
260+
IsMissingOrCorrupt = atlasTexture.IsMissingOrCorrupt;
261+
if (!IsMissingOrCorrupt)
262+
{
263+
UpdateAccessTime();
264+
EmitLoaded();
265+
}
260266
return;
261267
}
262268

Intersect.Client.Framework/Gwen/Skin/Texturing/Bordered.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Intersect.Client.Framework.GenericClasses;
1+
using Intersect.Client.Framework.GenericClasses;
22
using Intersect.Client.Framework.Graphics;
33

44
namespace Intersect.Client.Framework.Gwen.Skin.Texturing;
@@ -185,7 +185,7 @@ public void Draw(Renderer.Base render, Rectangle r, Color col)
185185

186186
public bool Equals(Bordered other)
187187
{
188-
return _texture.Equals(other._texture) && _subRects.Equals(other._subRects) && _margin.Equals(other._margin) && _width.Equals(other._width) && _height.Equals(other._height);
188+
return (_texture?.Equals(other._texture) ?? false) && _subRects.Equals(other._subRects) && _margin.Equals(other._margin) && _width.Equals(other._width) && _height.Equals(other._height);
189189
}
190190

191191
public override bool Equals(object? obj)

0 commit comments

Comments
 (0)