X-Git-Url: https://git.ucc.asn.au/?p=progcomp2013.git;a=blobdiff_plain;f=qchess%2Ftools%2Fimages.py;h=72848683a6db192d411098609b0811639e775741;hp=a1ec45aa605d80fd643857c0e37ae8ff18a8013b;hb=ef3a2d186de4f86b736dc357948a3ca319ef5423;hpb=444244d5c7698bb7861cdb7c0ec6bfb0e8cebfb7 diff --git a/qchess/tools/images.py b/qchess/tools/images.py deleted file mode 120000 index a1ec45a..0000000 --- a/qchess/tools/images.py +++ /dev/null @@ -1 +0,0 @@ -../src/images.py \ No newline at end of file diff --git a/qchess/tools/images.py b/qchess/tools/images.py new file mode 100644 index 0000000..7284868 --- /dev/null +++ b/qchess/tools/images.py @@ -0,0 +1,54 @@ +try: + import pygame +except: + pass +import os + +# Dictionary that stores the unicode character representations of the different pieces +# Chess was clearly the reason why unicode was invented +# For some reason none of the pygame chess implementations I found used them! +piece_char = {"white" : {"king" : u'\u2654', + "queen" : u'\u2655', + "rook" : u'\u2656', + "bishop" : u'\u2657', + "knight" : u'\u2658', + "pawn" : u'\u2659', + "unknown" : '?'}, + "black" : {"king" : u'\u265A', + "queen" : u'\u265B', + "rook" : u'\u265C', + "bishop" : u'\u265D', + "knight" : u'\u265E', + "pawn" : u'\u265F', + "unknown" : '?'}} + +images = {"white" : {}, "black" : {}} +small_images = {"white" : {}, "black" : {}} + +def create_images(grid_sz, font_name=os.path.join(os.path.curdir, "data", "DejaVuSans.ttf")): + + # Get the font sizes + l_size = 5*(grid_sz[0] / 8) + s_size = 3*(grid_sz[0] / 8) + + for c in piece_char.keys(): + + if c == "black": + for p in piece_char[c].keys(): + images[c].update({p : pygame.font.Font(font_name, l_size).render(piece_char[c][p], True,(0,0,0))}) + small_images[c].update({p : pygame.font.Font(font_name, s_size).render(piece_char[c][p],True,(0,0,0))}) + elif c == "white": + for p in piece_char[c].keys(): + images[c].update({p : pygame.font.Font(font_name, l_size+1).render(piece_char["black"][p], True,(255,255,255))}) + images[c][p].blit(pygame.font.Font(font_name, l_size).render(piece_char[c][p], True,(0,0,0)),(0,0)) + small_images[c].update({p : pygame.font.Font(font_name, s_size+1).render(piece_char["black"][p],True,(255,255,255))}) + small_images[c][p].blit(pygame.font.Font(font_name, s_size).render(piece_char[c][p],True,(0,0,0)),(0,0)) + + +def load_images(image_dir=os.path.join(os.path.curdir, "data", "images")): + if not os.path.exists(image_dir): + raise Exception("Couldn't load images from " + image_dir + " (path doesn't exist)") + for c in piece_char.keys(): + for p in piece_char[c].keys(): + images[c].update({p : pygame.image.load(os.path.join(image_dir, c + "_" + p + ".png"))}) + small_images[c].update({p : pygame.image.load(os.path.join(image_dir, c + "_" + p + "_small.png"))})