1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 from Font import Font
24 from Texture import Texture
25 from Svg import SvgDrawing, SvgContext
26 from Texture import Texture
27 from Audio import Sound
28 from Language import _
29 import random
30 import Language
31 import Config
32
33
34 STAR1 = unicode('\x10')
35 STAR2 = unicode('\x11')
36 LEFT = unicode('\x12')
37 RIGHT = unicode('\x13')
38 BALL1 = unicode('\x14')
39 BALL2 = unicode('\x15')
40
42 """A collection of globally used data resources such as fonts and sound effects."""
44 self.resource = resource
45 self.svg = svg
46
47
48 self.loadSvgDrawing(self, "star1", "star1.svg", textureSize = (128, 128))
49 self.loadSvgDrawing(self, "star2", "star2.svg", textureSize = (128, 128))
50 self.loadSvgDrawing(self, "left", "left.svg", textureSize = (128, 128))
51 self.loadSvgDrawing(self, "right", "right.svg", textureSize = (128, 128))
52 self.loadSvgDrawing(self, "ball1", "ball1.svg", textureSize = (128, 128))
53 self.loadSvgDrawing(self, "ball2", "ball2.svg", textureSize = (128, 128))
54
55
56 self.loadSvgDrawing(self, "loadingImage", "loading.svg", textureSize = (256, 256))
57
58
59 asciiOnly = not bool(Language.language)
60 reversed = _("__lefttoright__") == "__righttoleft__" and True or False
61 scale = Config.get("video", "fontscale")
62 fontSize = [22, 108]
63
64 if asciiOnly:
65 font = resource.fileName("default.ttf")
66 bigFont = resource.fileName("title.ttf")
67 else:
68 font = \
69 bigFont = resource.fileName("international.ttf")
70
71
72 font1 = lambda: Font(font, fontSize[0], scale = scale, reversed = reversed, systemFont = not asciiOnly)
73 font2 = lambda: Font(bigFont, fontSize[1], scale = scale, reversed = reversed, systemFont = not asciiOnly)
74 resource.load(self, "font", font1, onLoad = self.customizeFont)
75 resource.load(self, "bigFont", font2, onLoad = self.customizeFont)
76
77
78 resource.load(self, "screwUpSounds", self.loadScrewUpSounds)
79 self.loadSoundEffect(self, "acceptSound", "in.ogg")
80 self.loadSoundEffect(self, "cancelSound", "out.ogg")
81 self.loadSoundEffect(self, "selectSound1", "crunch1.ogg")
82 self.loadSoundEffect(self, "selectSound2", "crunch2.ogg")
83 self.loadSoundEffect(self, "selectSound3", "crunch3.ogg")
84 self.loadSoundEffect(self, "startSound", "start.ogg")
85
90
92 return [Sound(self.resource.fileName("fiba%d.ogg" % i)) for i in range(1, 7)]
93
95 """
96 Load an SVG drawing synchronously.
97
98 @param target: An object that will own the drawing
99 @param name: The name of the attribute the drawing will be assigned to
100 @param fileName: The name of the file in the data directory
101 @param textureSize Either None or (x, y), in which case the file will
102 be rendered to an x by y texture
103 @return: L{SvgDrawing} instance
104 """
105 fileName = self.resource.fileName(fileName)
106 drawing = self.resource.load(target, name, lambda: SvgDrawing(self.svg, fileName), synch = True)
107 if textureSize:
108 drawing.convertToTexture(textureSize[0], textureSize[1])
109 return drawing
110
111
120
122 """@return: A randomly chosen selection sound."""
123 return random.choice([self.selectSound1, self.selectSound2, self.selectSound3])
124
125 selectSound = property(getSelectSound)
126
128 """@return: A randomly chosen screw-up sound."""
129 return random.choice(self.screwUpSounds)
130
131 screwUpSound = property(getScrewUpSound)
132
134 """return: True if essential resources such as the font have been loaded."""
135 return bool(self.font and self.bigFont)
136
138 """return: True if all the resources have been loaded."""
139 return not None in self.__dict__.values()
140