Tried to fix borked permissions
[progcomp2013.git] / qchess / tools / images.py
1 try:
2         import pygame
3 except:
4         pass
5 import os
6
7 # Dictionary that stores the unicode character representations of the different pieces
8 # Chess was clearly the reason why unicode was invented
9 # For some reason none of the pygame chess implementations I found used them!
10 piece_char = {"white" : {"king" : u'\u2654',
11                          "queen" : u'\u2655',
12                          "rook" : u'\u2656',
13                          "bishop" : u'\u2657',
14                          "knight" : u'\u2658',
15                          "pawn" : u'\u2659',
16                          "unknown" : '?'},
17                 "black" : {"king" : u'\u265A',
18                          "queen" : u'\u265B',
19                          "rook" : u'\u265C',
20                          "bishop" : u'\u265D',
21                          "knight" : u'\u265E',
22                          "pawn" : u'\u265F',
23                          "unknown" : '?'}}
24
25 images = {"white" : {}, "black" : {}}
26 small_images = {"white" : {}, "black" : {}}
27
28 def create_images(grid_sz, font_name=os.path.join(os.path.curdir, "data", "DejaVuSans.ttf")):
29
30         # Get the font sizes
31         l_size = 5*(grid_sz[0] / 8)
32         s_size = 3*(grid_sz[0] / 8)
33
34         for c in piece_char.keys():
35                 
36                 if c == "black":
37                         for p in piece_char[c].keys():
38                                 images[c].update({p : pygame.font.Font(font_name, l_size).render(piece_char[c][p], True,(0,0,0))})
39                                 small_images[c].update({p : pygame.font.Font(font_name, s_size).render(piece_char[c][p],True,(0,0,0))})         
40                 elif c == "white":
41                         for p in piece_char[c].keys():
42                                 images[c].update({p : pygame.font.Font(font_name, l_size+1).render(piece_char["black"][p], True,(255,255,255))})
43                                 images[c][p].blit(pygame.font.Font(font_name, l_size).render(piece_char[c][p], True,(0,0,0)),(0,0))
44                                 small_images[c].update({p : pygame.font.Font(font_name, s_size+1).render(piece_char["black"][p],True,(255,255,255))})
45                                 small_images[c][p].blit(pygame.font.Font(font_name, s_size).render(piece_char[c][p],True,(0,0,0)),(0,0))
46         
47
48 def load_images(image_dir=os.path.join(os.path.curdir, "data", "images")):
49         if not os.path.exists(image_dir):
50                 raise Exception("Couldn't load images from " + image_dir + " (path doesn't exist)")
51         for c in piece_char.keys():
52                 for p in piece_char[c].keys():
53                         images[c].update({p : pygame.image.load(os.path.join(image_dir, c + "_" + p + ".png"))})
54                         small_images[c].update({p : pygame.image.load(os.path.join(image_dir, c + "_" + p + "_small.png"))})

UCC git Repository :: git.ucc.asn.au