|
1 | 1 | "use strict" |
2 | 2 | // ZEPHYR.js directly builds on top of PixiJS for ease of use |
3 | | -PIXI.zephyr = "ZephyrJS version 22.7.14"; |
| 3 | +PIXI.zephyr = "ZephyrJS version 22.7.26"; |
4 | 4 |
|
5 | 5 | PIXI.input = { |
6 | 6 | keyMap: new Map(), |
7 | 7 | // getKeyFired returns true the first time it is called for a key while the key is down |
8 | 8 | getKeyFired: (keyStr) => { |
9 | | - let r = PIXI.input.keyMap.get(keyStr); |
10 | | - PIXI.input.keyMap.set(keyStr, false); |
11 | | - return r; |
| 9 | + if (PIXI.input.keyMap.size > 0 && PIXI.input.keyMap.get(keyStr)) { |
| 10 | + PIXI.input.keyMap.set(keyStr, false); |
| 11 | + return true; |
| 12 | + } |
| 13 | + return false; |
12 | 14 | }, |
13 | 15 | // getKeyDown returns true always if the key is down |
14 | 16 | getKeyDown: (keyStr) => { |
15 | | - return PIXI.input.keyMap.has(keyStr); |
| 17 | + if (PIXI.input.keyMap.size > 0 && PIXI.input.keyMap.has(keyStr)) { |
| 18 | + PIXI.input.keyMap.set(keyStr, false); |
| 19 | + return true; |
| 20 | + } |
| 21 | + return false; |
16 | 22 | }, |
17 | 23 |
|
18 | 24 | mouseContainer: document.getElementsByTagName("html")[0], |
19 | 25 | mouseMap: new Map(), |
20 | 26 | getMouseFired: (btn) => { |
21 | | - let r = PIXI.input.mouseMap.get(btn); |
22 | | - PIXI.input.keyMap.set(btn, false); |
23 | | - return r; |
| 27 | + if (PIXI.input.mouseMap.size > 0 && PIXI.input.mouseMap.get(btn)) { |
| 28 | + PIXI.input.mouseMap.set(btn, false); |
| 29 | + return true; |
| 30 | + } |
| 31 | + return false; |
24 | 32 | }, |
25 | 33 | getMouseDown: (btn) => { |
26 | | - return PIXI.input.mouseMap.has(btn); |
| 34 | + if (PIXI.input.mouseMap.size > 0 && PIXI.input.mouseMap.has(btn)) { |
| 35 | + PIXI.input.mouseMap.set(btn, false); |
| 36 | + return true; |
| 37 | + } |
| 38 | + return false; |
27 | 39 | }, |
28 | 40 | getMouseX: () => { |
29 | 41 | return PIXI.input.mouseMap.get('x'); |
@@ -59,47 +71,11 @@ PIXI.utils.openFullScreen = (view) => { |
59 | 71 | view.msRequestFullscreen(); // IE11 |
60 | 72 | } |
61 | 73 |
|
62 | | -PIXI.utils.saveObjectToFile = (name, state) => { |
63 | | - let blobState = new Blob([JSON.stringify(state)], {type: 'text/plain'}); |
64 | | - let a = document.createElement('a'); |
65 | | - a.download = name + ".json"; |
66 | | - a.href = window.URL.createObjectURL(blobState); |
67 | | - a.click(); |
68 | | -}; |
69 | | - |
70 | | -PIXI.utils.readObjectFromFile = () => { |
71 | | - return new Promise(resolve => { |
72 | | - let input = document.createElement('input'); |
73 | | - input.type = 'file'; |
74 | | - input.accept = '.json'; |
75 | | - |
76 | | - document.body.onfocus = () => { |
77 | | - if (input) { |
78 | | - let res = null; |
79 | | - if(input.target) { |
80 | | - console.log("Files picked"); |
81 | | - let file = input.target.files[0]; |
82 | | - let reader = new FileReader(); |
83 | | - reader.readAsText(file,'UTF-8'); |
84 | | - reader.onload = readerEvent => { |
85 | | - res = JSON.parse(readerEvent.target.result); |
86 | | - } |
87 | | - } else { |
88 | | - console.log("No files picked"); |
89 | | - } |
90 | | - input = null; |
91 | | - resolve(res); |
92 | | - } |
93 | | - } |
94 | | - |
95 | | - input.click(); |
96 | | - }); |
97 | | -}; |
98 | | - |
99 | 74 | // Keyboard |
100 | 75 | window.addEventListener('keydown', (e) => { |
101 | 76 | PIXI.input.keyMap.set(e.key.toLowerCase(), true); |
102 | 77 | }); |
| 78 | + |
103 | 79 | window.addEventListener('keyup', (e) => { |
104 | 80 | PIXI.input.keyMap.delete(e.key.toLowerCase()); |
105 | 81 | }); |
|
0 commit comments