forked from BrythonServer/ggame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sysdeps.py
97 lines (81 loc) · 3.37 KB
/
sysdeps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
def module_exists(module_name):
try:
__import__(module_name)
except ImportError:
return False
else:
return True
if module_exists('browser') and module_exists('javascript'):
from browser import window, document
from javascript import JSObject, JSConstructor
major = window.__BRYTHON__.implementation[0]
minor = window.__BRYTHON__.implementation[1]
if major == 3 and minor >= 3 or major > 3:
GFX = window.PIXI
GFX_Rectangle = GFX.Rectangle.new
GFX_Texture = GFX.Texture.new
GFX_Texture_fromImage = GFX.Texture.fromImage.new
GFX_Sprite = GFX.Sprite.new
GFX_Graphics = GFX.Graphics.new()
GFX_Text = GFX.Text.new
GFX_NewStage = GFX.Container.new
SND = window.buzz
SND_Sound = SND.sound.new
else:
GFX = JSObject(window.PIXI)
GFX_Rectangle = JSConstructor(GFX.Rectangle)
GFX_Texture = JSConstructor(GFX.Texture)
GFX_Texture_fromImage = JSConstructor(GFX.Texture.fromImage)
GFX_Sprite = JSConstructor(GFX.Sprite)
GFX_Graphics = JSConstructor(GFX.Graphics)()
GFX_Text = JSConstructor(GFX.Text)
GFX_NewStage = JSConstructor(GFX.Container)
SND = JSObject(window.buzz)
SND_Sound = JSConstructor(SND.sound)
GFX_DetectRenderer = GFX.autoDetectRenderer
class GFX_Window(object):
def __init__(self, width, height, onclose):
canvas = window.document.getElementById('ggame-canvas')
if canvas:
self._w = window
window.bsUI.graphicsmode()
options = {'transparent':True, 'antialias':True, 'view':canvas}
attachpoint = window.document.getElementById('graphics-column')
w, h = attachpoint.clientWidth, attachpoint.clientHeight
else:
self._w = window.open("", "")
w, h = self._w.innerWidth * 0.9, self._w.innerHeight * 0.9
options = {'transparent':True, 'antialias':True}
attachpoint = self._w.document.body
GFX.utils._saidHello = True; # ugly hack to block pixi banner
self._stage = GFX_NewStage()
self.width = width if width != 0 else int(w)
self.height = height if height != 0 else int(h)
self._renderer = GFX.autoDetectRenderer(self.width, self.height, options)
attachpoint.appendChild(self._renderer.view)
self._w.onunload = onclose
def bind(self, evtspec, callback):
self._w.document.body.unbind(evtspec) # in case already bound
self._w.document.body.bind(evtspec, callback)
def unbind(self, evtspec):
self._w.document.body.unbind(evtspec)
def add(self, obj):
self._stage.addChild(obj)
def remove(self, obj):
self._stage.removeChild(obj)
def animate(self, stepcallback):
self._renderer.render(self._stage)
self._w.requestAnimationFrame(stepcallback)
def destroy(self):
SND.all().stop()
self._stage.destroy()
elif module_exists('pygame'):
try:
from ggame.pygamedeps import *
except:
from pygamedeps import *
else:
try:
from ggame.headlessdeps import *
except:
from headlessdeps import *