diff --git a/pygame/__init__.js b/pygame/__init__.js index bdc91e3..3652c65 100644 --- a/pygame/__init__.js +++ b/pygame/__init__.js @@ -3,19 +3,19 @@ Sk.insertEvent = function (eventName) { var e = []; switch (eventName) { case "left": - e = [PygameLib.constants.KEYDOWN, {key: PygameLib.constants.K_LEFT}]; + e = [PygameLib.constants.KEYDOWN, { key: PygameLib.constants.K_LEFT }]; break; case "right": - e = [PygameLib.constants.KEYDOWN, {key: PygameLib.constants.K_RIGHT}]; + e = [PygameLib.constants.KEYDOWN, { key: PygameLib.constants.K_RIGHT }]; break; case "up": - e = [PygameLib.constants.KEYDOWN, {key: PygameLib.constants.K_UP}]; + e = [PygameLib.constants.KEYDOWN, { key: PygameLib.constants.K_UP }]; break; case "down": - e = [PygameLib.constants.KEYDOWN, {key: PygameLib.constants.K_DOWN}]; + e = [PygameLib.constants.KEYDOWN, { key: PygameLib.constants.K_DOWN }]; break; case "quit": - e = [PygameLib.constants.QUIT, {key: PygameLib.constants.K_ESCAPE}]; + e = [PygameLib.constants.QUIT, { key: PygameLib.constants.K_ESCAPE }]; break; } PygameLib.eventQueue.unshift(e); @@ -61,26 +61,25 @@ var createKeyboardEvent = function (event) { } else if (event.type === "keydown") { keyPGConstant = PygameLib.constants.KEYDOWN; } + var keyId = event.which; + switch (event.which) { case 27: - e = [PygameLib.constants.QUIT, {key: PygameLib.constants.K_ESCAPE}]; - break; + return [PygameLib.constants.QUIT, { key: PygameLib.constants.K_ESCAPE }]; case 37: - e = [keyPGConstant, {key: PygameLib.constants.K_LEFT}]; - break; + return [keyPGConstant, { key: PygameLib.constants.K_LEFT }]; case 38: - e = [keyPGConstant, {key: PygameLib.constants.K_UP}]; - break; + return [keyPGConstant, { key: PygameLib.constants.K_UP }]; case 39: - e = [keyPGConstant, {key: PygameLib.constants.K_RIGHT}]; - break; + return [keyPGConstant, { key: PygameLib.constants.K_RIGHT }]; case 40: - e = [keyPGConstant, {key: PygameLib.constants.K_DOWN}]; - break; + return [keyPGConstant, { key: PygameLib.constants.K_DOWN }]; default: - e = [keyPGConstant, {key: event.which}]; + var difference = 0; + if ((event.which <= 90) || (event.which >= 65)) + difference = 32; + return [keyPGConstant, { key: (event.which + difference)}]; } - return e; }; function keyEventListener(event) { @@ -1090,11 +1089,13 @@ function pygame_init() { pygame_m.$d['event'] = display_m.$d['event']; pygame_m.$d['draw'] = display_m.$d['draw']; pygame_m.$d['image'] = display_m.$d['image']; + delete PygameLib.eventQueue; + delete PygameLib.eventTimer; PygameLib.eventQueue = []; PygameLib.eventTimer = {}; PygameLib.running = true; PygameLib.repeatKeys = false; - PygameLib.mouseData = {"button": [0, 0, 0], "pos": [0, 0], "rel": [0, 0]}; + PygameLib.mouseData = { "button": [0, 0, 0], "pos": [0, 0], "rel": [0, 0] }; } var mouseEventListener = function (event) { @@ -1116,19 +1117,19 @@ var mouseEventListener = function (event) { var button = event.button + 1; if (event.type === "mousedown") { var e = [PygameLib.constants.MOUSEBUTTONDOWN, - { - key: PygameLib.constants.MOUSEBUTTONDOWN, - pos: [canvasX, canvasY], - button: button - }]; + { + key: PygameLib.constants.MOUSEBUTTONDOWN, + pos: [canvasX, canvasY], + button: button + }]; PygameLib.mouseData["button"][button] = 1; } else if (event.type === "mouseup") { var e = [PygameLib.constants.MOUSEBUTTONUP, - { - key: PygameLib.constants.MOUSEBUTTONUP, - pos: [canvasX, canvasY], - button: button - }]; + { + key: PygameLib.constants.MOUSEBUTTONUP, + pos: [canvasX, canvasY], + button: button + }]; PygameLib.mouseData["button"][button] = 0; } else if (event.type === "mousemove") { var leftButton = 0; @@ -1144,12 +1145,12 @@ var mouseEventListener = function (event) { middleButton = 1; } var e = [PygameLib.constants.MOUSEMOTION, - { - key: PygameLib.constants.MOUSEMOTION, - pos: [canvasX, canvasY], - rel: [event.movementX, event.movementY], - buttons: [leftButton, middleButton, rightButton] - }]; + { + key: PygameLib.constants.MOUSEMOTION, + pos: [canvasX, canvasY], + rel: [event.movementX, event.movementY], + buttons: [leftButton, middleButton, rightButton] + }]; PygameLib.mouseData["pos"] = [canvasX, canvasY]; PygameLib.mouseData["rel"] = [event.movementX, event.movementY]; } @@ -1157,7 +1158,7 @@ var mouseEventListener = function (event) { }; // Surface((width, height)) -var init$1 = function $__init__123$(self, size, fullscreen = false, main = false) { +var init$1 = function $__init__123$(self, size, fullscreen = false, main = true) { Sk.builtin.pyCheckArgs('__init__', arguments, 2, 5, false, false); var tuple_js = Sk.ffi.remapToJs(size); self.width = Math.round(tuple_js[0]); @@ -1172,7 +1173,7 @@ var init$1 = function $__init__123$(self, size, fullscreen = false, main = false window.addEventListener("keydown", keyEventListener); window.addEventListener("keyup", keyEventListener); - if (fullscreen) { + /*if (fullscreen) { self.width = window.innerWidth; self.height = window.innerHeight; self.main_canvas.style["z-index"] = "100"; @@ -1190,7 +1191,7 @@ var init$1 = function $__init__123$(self, size, fullscreen = false, main = false self.offscreen_canvas.height = self.height; self.context2d.drawImage(self.main_canvas, 0, 0); }; - } + } */ } self.main_canvas.width = self.width; self.main_canvas.height = self.height; @@ -1203,14 +1204,16 @@ var init$1 = function $__init__123$(self, size, fullscreen = false, main = false self.offscreen_canvas.height = self.height; self.main_canvas.setAttribute('width', self.width); self.main_canvas.setAttribute('height', self.height); + self.main_canvas.setAttribute('style', "border: 1px solid darkgray;"); fillBlack(self.main_context, self.main_canvas.width, self.main_canvas.height); fillBlack(self.context2d, self.width, self.height); return Sk.builtin.none.none$; + }; function fillBlack(ctx, w, h) { ctx.beginPath(); - ctx.rect(0, 0, w-1, h-1); + ctx.rect(0, 0, w - 1, h - 1); ctx.fillStyle = "rgba(0, 0, 0, 0.0)"; ctx.fill(); } @@ -1351,7 +1354,7 @@ function color_type_f($gbl, $loc) { $loc.__init__ = new Sk.builtin.func(function (self, r, g, b, a) { Sk.builtin.pyCheckArgs('__init__', arguments, 2, 5, false, false); var r_js = Sk.ffi.remapToJs(r); - if (typeof(r_js) == 'string') { + if (typeof (r_js) == 'string') { var color_name = r_js; r = Sk.ffi.remapToPy(PygameLib.Colors[color_name][0]); g = Sk.ffi.remapToPy(PygameLib.Colors[color_name][1]); diff --git a/pygame/draw.js b/pygame/draw.js index 119a18c..d032845 100644 --- a/pygame/draw.js +++ b/pygame/draw.js @@ -200,4 +200,4 @@ var draw_aaline = function (surface, color, startpos, endpos, blend = 1) { //aalines(Surface, color, closed, pointlist, blend=1) -> Rect var draw_aalines = function (surface, color, closed, pointlist, blend = 1) { return draw_lines(surface, color, closed, pointlist); -}; \ No newline at end of file +}; diff --git a/pygame/event.js b/pygame/event.js index c5bad25..7013744 100644 --- a/pygame/event.js +++ b/pygame/event.js @@ -87,4 +87,4 @@ function event_EventType_f($gbl, $loc) { $loc.__repr__.co_name = new Sk.builtins['str']('__repr__'); $loc.__repr__.co_varnames = ['self']; -} \ No newline at end of file +} diff --git a/pygame/font.js b/pygame/font.js index 2827b94..cd546c7 100644 --- a/pygame/font.js +++ b/pygame/font.js @@ -155,4 +155,4 @@ function renderFont(self, text, antialias, color, background) { return s; } -var fonts_osx = ['applecoloremojiui', 'cochin', 'raanana', 'franklingothicmedium', 'signpainter', 'iowanoldstyle', 'corbel', 'avenir', 'birchstd', 'bitstreamverasansmono', 'sfcompacttext', 'albayan', 'applesdgothicneo', 'damascus', 'malayalammn', 'kohinoortelugu', 'minionpro', 'estrangelomidyat', 'lucidagrandeui', 'hiraginokakugothicpro', 'diwankufi', 'calibri', 'arialnarrow', 'applesdgothicneoi', 'gillsans', 'stixsizefoursym', 'adobehebrew', 'farisi', 'ptsanscaption', 'hiraginomarugothicpron', 'avenirnextcondensed', 'couriernew', 'myriadhebrew', 'hiraginominchopron', 'laomn', 'estrangeloantioch', 'damascuspua', 'hiraginosans', 'avenirnext', 'gohatibebzemen', 'altarikhpua', 'arial', 'itfdevanagari', 'hiraginokakugothicstd', 'adobegaramondpro', 'oratorstd', 'kozukagothicpro', 'skia', 'chaparralpro', 'sfnsdisplaycondensed', 'geezapro', 'lithospro', 'heitisc', 'gujaratimt', 'corsivahebrew', 'hoeflertext', 'athelas', 'lucidagrande', 'timesnewroman', 'decotypenaskhpua', 'webdings', 'inaimathi', 'myriadarabic', 'lettergothicstd', 'kozukagothicpr6n', 'lucidasansunicode', 'geezaprointerface', 'kozukaminchopr6n', 'luminari', 'helveticaneue', 'kailasa', 'helvetica', 'systemfont', 'shreedevanagari714', 'gillsansmt', 'applebraille', 'adobedevanagari', 'krungthep', 'stixgeneral', 'verdana', 'sfcompactdisplay', 'baskerville', 'sertomalankara', 'rockwell', 'newpeninimmt', 'malayalamsangammn', 'palatinolinotype', 'mspmincho', 'euphemiaucas', 'gurmukhisangammn', 'ptsansnarrow', 'trattatello', 'consolas', 'mishafigold', 'arialhebrewscholar', 'pingfangtc', 'symbol', 'ptserif', 'ayuthaya', 'notonastaliqurduui', 'stixintegralsd', 'kohinoordevanagari', 'sertomardin', 'notonastaliqurdu', 'stixnonunicode', 'adobekaitistd', 'pingfangsc', 'pingfanghk', 'stencilstd', 'trebuchetms', 'heititc', 'times', 'kohinoorbangla', 'marlett', 'seravek', 'tamilmn', 'andalemono', 'kufistandardgkpua', 'estrangelotalada', 'meiryo', 'banglasangammn', 'adobeheitistd', 'alnilepua', 'cambria', 'sukhumvitset', 'msmincho', 'marion', 'cooperstd', 'brushscriptmt', 'charter', 'comicsansms', 'sinhalasangammn', 'mingliuhkscs', 'palatino', 'arialroundedmtbold', 'estrangeloquenneshrin', 'ptsans', 'kefa', 'chalkboard', 'arabicuidisplay', 'laosangammn', 'impact', 'luxisans', 'menlo', 'bigcaslon', 'simhei', 'helveticaneuedeskinterface', 'myriadpro', 'snellroundhand', 'stixintegralsup', 'bitstreamverasans', 'arialhebrewdeskinterface', 'adobesongstd', 'stixsizeonesym', 'adobefanheitistd', 'superclarendon', 'sfcompactrounded', 'chalkboardse', 'muna', 'perpetua', 'hiraginokakugothicinterface', 'dinalternate', 'adobenaskh', 'stixintegralssm', 'tahoma', 'luxiserif', 'sertojerusalemoutline', 'telugusangammn', 'arabicuitext', 'sfnstextcondensed', 'adobemingstd', 'twcenmt', 'ptserifcaption', 'kannadasangammn', 'candara', 'americantypewriter', 'msreferencesansserif', 'papyrus', 'hiraginokakugothicpron', 'mishafi', 'futura', 'estrangeloedessa', 'sinhalamn', 'kozukaminchopro', 'albayanpua', 'adobecaslonpro', 'gujaratisangammn', 'trajanpro', 'constantia', 'myanmarsangammn', 'copperplate', 'teamviewer12', 'lucidaconsole', 'chalkduster', 'microsoftyibaiti', 'khmersangammn', 'songtitc', 'microsofttaile', 'bodoni72smallcaps', 'itfdevanagarimarathi', 'hiraginokakugothicstdn', 'oriyamn', 'georgia', 'pmingliuextb', 'nadeempua', 'tektonpro', 'applesymbols', 'markerfelt', 'nuevastd', 'songtisc', 'herculanum', 'optima', 'kufistandardgk', 'ptmono', 'bodoni72', 'adobearabic', 'giddyupstd', 'luximono', 'applechancery', 'khmermn', 'arialunicodems', 'bitstreamveraserif', 'eastsyriacadiabene', 'mspgothic', 'mingliu', 'bodoni72oldstyle', 'devanagarimt', 'sertobatnan', 'aquakana', 'hiraginosansgbinterface', 'mshtakan', 'msgothic', 'blackoakstd', 'bradleyhand', 'estrangelonisibin', 'prestigeelitestd', 'wingdings3', 'wingdings2', 'myanmarmn', 'sertokharput', 'stixsizefivesym', 'gurmukhimn', 'kannadamn', 'munapua', 'devanagarisangammn', 'wingdings', 'dincondensed', 'nadeem', 'sanapua', 'thonburi', 'applemyungjo', 'arialhebrew', 'beirutpua', 'baghdadpua', 'gurmukhimt', 'savoyeletcc', 'geezapropua', 'zapfino', 'telugumn', 'banglamn', 'waseem', 'arialblack', 'sertourhoy', 'charlemagnestd', 'microsoftsansserif', 'gulim', 'savoyelet', 'decotypenaskh', 'batang', 'stsong', 'ocrastd', 'franklingothicbook', 'didot', 'applegothic', 'altarikh', 'adobefangsongstd', 'stixvariants', 'zapfdingbats', 'hiraginosansgb', 'farah', 'baghdad', 'gb18030bitmap', 'kokonor', 'sertojerusalem', 'silom', 'estrangeloturabdin', 'bookshelfsymbol7', 'noteworthy', 'stixsizetwosym', 'oriyasangammn', 'tamilsangammn', 'alnile', 'phosphate', 'cambriamath', 'sana', 'stixintegralsupd', 'simsun', 'sathu', 'estrangelonisibinoutline', 'mingliuextb', 'simsunextb', 'beirut', 'farahpua', 'brushscriptstd', 'eastsyriacctesiphon', 'diwankufipua', 'rosewoodstd', 'mongolianbaiti', 'diwanthuluth', 'stixintegralsupsm', 'gabriola', 'mingliuhkscsextb', 'adobemyungjostd', 'msreferencespecialty', 'keyboard', 'microsofthimalaya', 'mesquitestd', 'poplarstd', 'hiraginomarugothicpro', 'hiraginominchopro', 'hobostd', 'stixsizethreesym', 'bodoniornaments', 'lastresort', 'pmingliu', 'applecoloremoji', 'plantagenetcherokee', 'adobegothicstd']; \ No newline at end of file +var fonts_osx = ['applecoloremojiui', 'cochin', 'raanana', 'franklingothicmedium', 'signpainter', 'iowanoldstyle', 'corbel', 'avenir', 'birchstd', 'bitstreamverasansmono', 'sfcompacttext', 'albayan', 'applesdgothicneo', 'damascus', 'malayalammn', 'kohinoortelugu', 'minionpro', 'estrangelomidyat', 'lucidagrandeui', 'hiraginokakugothicpro', 'diwankufi', 'calibri', 'arialnarrow', 'applesdgothicneoi', 'gillsans', 'stixsizefoursym', 'adobehebrew', 'farisi', 'ptsanscaption', 'hiraginomarugothicpron', 'avenirnextcondensed', 'couriernew', 'myriadhebrew', 'hiraginominchopron', 'laomn', 'estrangeloantioch', 'damascuspua', 'hiraginosans', 'avenirnext', 'gohatibebzemen', 'altarikhpua', 'arial', 'itfdevanagari', 'hiraginokakugothicstd', 'adobegaramondpro', 'oratorstd', 'kozukagothicpro', 'skia', 'chaparralpro', 'sfnsdisplaycondensed', 'geezapro', 'lithospro', 'heitisc', 'gujaratimt', 'corsivahebrew', 'hoeflertext', 'athelas', 'lucidagrande', 'timesnewroman', 'decotypenaskhpua', 'webdings', 'inaimathi', 'myriadarabic', 'lettergothicstd', 'kozukagothicpr6n', 'lucidasansunicode', 'geezaprointerface', 'kozukaminchopr6n', 'luminari', 'helveticaneue', 'kailasa', 'helvetica', 'systemfont', 'shreedevanagari714', 'gillsansmt', 'applebraille', 'adobedevanagari', 'krungthep', 'stixgeneral', 'verdana', 'sfcompactdisplay', 'baskerville', 'sertomalankara', 'rockwell', 'newpeninimmt', 'malayalamsangammn', 'palatinolinotype', 'mspmincho', 'euphemiaucas', 'gurmukhisangammn', 'ptsansnarrow', 'trattatello', 'consolas', 'mishafigold', 'arialhebrewscholar', 'pingfangtc', 'symbol', 'ptserif', 'ayuthaya', 'notonastaliqurduui', 'stixintegralsd', 'kohinoordevanagari', 'sertomardin', 'notonastaliqurdu', 'stixnonunicode', 'adobekaitistd', 'pingfangsc', 'pingfanghk', 'stencilstd', 'trebuchetms', 'heititc', 'times', 'kohinoorbangla', 'marlett', 'seravek', 'tamilmn', 'andalemono', 'kufistandardgkpua', 'estrangelotalada', 'meiryo', 'banglasangammn', 'adobeheitistd', 'alnilepua', 'cambria', 'sukhumvitset', 'msmincho', 'marion', 'cooperstd', 'brushscriptmt', 'charter', 'comicsansms', 'sinhalasangammn', 'mingliuhkscs', 'palatino', 'arialroundedmtbold', 'estrangeloquenneshrin', 'ptsans', 'kefa', 'chalkboard', 'arabicuidisplay', 'laosangammn', 'impact', 'luxisans', 'menlo', 'bigcaslon', 'simhei', 'helveticaneuedeskinterface', 'myriadpro', 'snellroundhand', 'stixintegralsup', 'bitstreamverasans', 'arialhebrewdeskinterface', 'adobesongstd', 'stixsizeonesym', 'adobefanheitistd', 'superclarendon', 'sfcompactrounded', 'chalkboardse', 'muna', 'perpetua', 'hiraginokakugothicinterface', 'dinalternate', 'adobenaskh', 'stixintegralssm', 'tahoma', 'luxiserif', 'sertojerusalemoutline', 'telugusangammn', 'arabicuitext', 'sfnstextcondensed', 'adobemingstd', 'twcenmt', 'ptserifcaption', 'kannadasangammn', 'candara', 'americantypewriter', 'msreferencesansserif', 'papyrus', 'hiraginokakugothicpron', 'mishafi', 'futura', 'estrangeloedessa', 'sinhalamn', 'kozukaminchopro', 'albayanpua', 'adobecaslonpro', 'gujaratisangammn', 'trajanpro', 'constantia', 'myanmarsangammn', 'copperplate', 'teamviewer12', 'lucidaconsole', 'chalkduster', 'microsoftyibaiti', 'khmersangammn', 'songtitc', 'microsofttaile', 'bodoni72smallcaps', 'itfdevanagarimarathi', 'hiraginokakugothicstdn', 'oriyamn', 'georgia', 'pmingliuextb', 'nadeempua', 'tektonpro', 'applesymbols', 'markerfelt', 'nuevastd', 'songtisc', 'herculanum', 'optima', 'kufistandardgk', 'ptmono', 'bodoni72', 'adobearabic', 'giddyupstd', 'luximono', 'applechancery', 'khmermn', 'arialunicodems', 'bitstreamveraserif', 'eastsyriacadiabene', 'mspgothic', 'mingliu', 'bodoni72oldstyle', 'devanagarimt', 'sertobatnan', 'aquakana', 'hiraginosansgbinterface', 'mshtakan', 'msgothic', 'blackoakstd', 'bradleyhand', 'estrangelonisibin', 'prestigeelitestd', 'wingdings3', 'wingdings2', 'myanmarmn', 'sertokharput', 'stixsizefivesym', 'gurmukhimn', 'kannadamn', 'munapua', 'devanagarisangammn', 'wingdings', 'dincondensed', 'nadeem', 'sanapua', 'thonburi', 'applemyungjo', 'arialhebrew', 'beirutpua', 'baghdadpua', 'gurmukhimt', 'savoyeletcc', 'geezapropua', 'zapfino', 'telugumn', 'banglamn', 'waseem', 'arialblack', 'sertourhoy', 'charlemagnestd', 'microsoftsansserif', 'gulim', 'savoyelet', 'decotypenaskh', 'batang', 'stsong', 'ocrastd', 'franklingothicbook', 'didot', 'applegothic', 'altarikh', 'adobefangsongstd', 'stixvariants', 'zapfdingbats', 'hiraginosansgb', 'farah', 'baghdad', 'gb18030bitmap', 'kokonor', 'sertojerusalem', 'silom', 'estrangeloturabdin', 'bookshelfsymbol7', 'noteworthy', 'stixsizetwosym', 'oriyasangammn', 'tamilsangammn', 'alnile', 'phosphate', 'cambriamath', 'sana', 'stixintegralsupd', 'simsun', 'sathu', 'estrangelonisibinoutline', 'mingliuextb', 'simsunextb', 'beirut', 'farahpua', 'brushscriptstd', 'eastsyriacctesiphon', 'diwankufipua', 'rosewoodstd', 'mongolianbaiti', 'diwanthuluth', 'stixintegralsupsm', 'gabriola', 'mingliuhkscsextb', 'adobemyungjostd', 'msreferencespecialty', 'keyboard', 'microsofthimalaya', 'mesquitestd', 'poplarstd', 'hiraginomarugothicpro', 'hiraginominchopro', 'hobostd', 'stixsizethreesym', 'bodoniornaments', 'lastresort', 'pmingliu', 'applecoloremoji', 'plantagenetcherokee', 'adobegothicstd']; diff --git a/pygame/key.js b/pygame/key.js index 96b1e10..8afdda6 100644 --- a/pygame/key.js +++ b/pygame/key.js @@ -90,4 +90,5 @@ keyToName = ['unknown key', 'unknown key', 'unknown key', 'unknown key', 'unknow var keyboardModifierKeys = [PygameLib.constants.K_LSHIFT, PygameLib.constants.K_RSHIFT, 0, 0, 0, 0, PygameLib.constants.K_LCTRL, PygameLib.constants.K_RCTRL, PygameLib.constants.K_LALT, PygameLib.constants.K_RALT, PygameLib.constants.K_LMETA, PygameLib.constants.K_RMETA, 0, PygameLib.constants.K_CAPSLOCK, - PygameLib.constants.K_NUMLOCK, PygameLib.constants.K_MODE]; \ No newline at end of file + PygameLib.constants.K_NUMLOCK, PygameLib.constants.K_MODE]; + \ No newline at end of file diff --git a/pygame/mouse.js b/pygame/mouse.js index 44c67c4..3935fa1 100644 --- a/pygame/mouse.js +++ b/pygame/mouse.js @@ -39,4 +39,4 @@ var $builtinmodule = function (name) { throw new Sk.builtin.NotImplementedError("Not yet implemented"); }); return mod; -}; \ No newline at end of file +}; diff --git a/pygame/time.js b/pygame/time.js index 8ae426e..760b0be 100644 --- a/pygame/time.js +++ b/pygame/time.js @@ -143,4 +143,4 @@ function time_Clock($gbl, $loc) { }); } -time_Clock.co_name = new Sk.builtins['str']('Clock'); \ No newline at end of file +time_Clock.co_name = new Sk.builtins['str']('Clock');