Fix missing pieces UI for non-ascii paths

This commit is contained in:
Sebastian Lague 2023-07-24 17:43:57 +02:00
parent 87a2ef31eb
commit eb28f8eb2f

View file

@ -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);