From eb28f8eb2f3d20dde85ac89f71ae39e2c875d998 Mon Sep 17 00:00:00 2001 From: Sebastian Lague Date: Mon, 24 Jul 2023 17:43:57 +0200 Subject: [PATCH] Fix missing pieces UI for non-ascii paths --- .../src/Framework/Application/UI/BoardUI.cs | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/Chess-Challenge/src/Framework/Application/UI/BoardUI.cs b/Chess-Challenge/src/Framework/Application/UI/BoardUI.cs index c68bd5f..9ad27dc 100644 --- a/Chess-Challenge/src/Framework/Application/UI/BoardUI.cs +++ b/Chess-Challenge/src/Framework/Application/UI/BoardUI.cs @@ -3,6 +3,7 @@ using Raylib_cs; using System; using System.Collections.Generic; using System.Numerics; +using System.IO; using static ChessChallenge.Application.UIHelper; namespace ChessChallenge.Application @@ -53,10 +54,8 @@ namespace ChessChallenge.Application public BoardUI() { theme = new BoardTheme(); - piecesTexture = Raylib.LoadTexture(UIHelper.GetResourcePath("Pieces.png")); - Raylib.GenTextureMipmaps(ref piecesTexture); - Raylib.SetTextureWrap(piecesTexture, TextureWrap.TEXTURE_WRAP_CLAMP); - Raylib.SetTextureFilter(piecesTexture, TextureFilter.TEXTURE_FILTER_BILINEAR); + + LoadPieceTexture(); board = new Board(); board.LoadStartPosition(); @@ -339,7 +338,7 @@ namespace ChessChallenge.Application } } - Vector2 GetSquarePos(int file, int rank, bool whitePerspective) + static Vector2 GetSquarePos(int file, int rank, bool whitePerspective) { const int boardStartX = -squareSize * 4; const int boardStartY = -squareSize * 4; @@ -384,6 +383,19 @@ namespace ChessChallenge.Application } } + void LoadPieceTexture() + { + // Workaround for Raylib.LoadTexture() not working when path contains non-ascii chars + byte[] pieceImgBytes = File.ReadAllBytes(GetResourcePath("Pieces.png")); + Image pieceImg = Raylib.LoadImageFromMemory(".png", pieceImgBytes); + piecesTexture = Raylib.LoadTextureFromImage(pieceImg); + Raylib.UnloadImage(pieceImg); + + Raylib.GenTextureMipmaps(ref piecesTexture); + Raylib.SetTextureWrap(piecesTexture, TextureWrap.TEXTURE_WRAP_CLAMP); + Raylib.SetTextureFilter(piecesTexture, TextureFilter.TEXTURE_FILTER_BILINEAR); + } + public void Release() { Raylib.UnloadTexture(piecesTexture);