Skip to content

Commit b0c519e

Browse files
committed
stable 23.2
1 parent 8a292fe commit b0c519e

File tree

4 files changed

+484
-236
lines changed

4 files changed

+484
-236
lines changed

stable/pixi.js

Lines changed: 234 additions & 234 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

stable/pixi.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

stable/pixi.min.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

stable/zephyr.js

Lines changed: 249 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,249 @@
1-
"use strict";PIXI.Keys={},PIXI.Mouse={},PIXI.Audio={},PIXI.File={},PIXI.Zephyr={version:"ZephyrJS 23.1",compatible:"PixiJS v7.0.5",useKeys(){PIXI.Keys.map=new Map,PIXI.Keys.down=e=>!!(PIXI.Keys.map.size>0&&PIXI.Keys.map.has(e))&&(PIXI.Keys.map.set(e,!1),!0),PIXI.Keys.fired=e=>!!(PIXI.Keys.map.size>0&&PIXI.Keys.map.get(e))&&(PIXI.Keys.map.set(e,!1),!0),window.addEventListener("keydown",e=>{e.preventDefault(),PIXI.Keys.map.set(e.code,!0)}),window.addEventListener("keyup",e=>{PIXI.Keys.map.delete(e.code)})},useMouse(){PIXI.Mouse.bounds=document.getElementsByTagName("html")[0].getBoundingClientRect(),PIXI.Mouse.container=document.getElementsByTagName("html")[0],PIXI.Mouse.x=0,PIXI.Mouse.y=0,PIXI.Mouse.setContainer=e=>{let t=e.getBoundingClientRect();t.width*t.height==0?console.error("Cannot use PIXI.Mouse.setContainer() with an invalid element."):(PIXI.Mouse.container=e,PIXI.Mouse.bounds=PIXI.Mouse.container.getBoundingClientRect())},window.onresize=()=>{PIXI.Mouse.bounds=PIXI.Mouse.container.getBoundingClientRect()},PIXI.Mouse.alias=["Primary","Middle","Secondary"],PIXI.Mouse.map=new Map,PIXI.Mouse.down=e=>!!(PIXI.Mouse.map.size>0&&PIXI.Mouse.map.has(e))&&(PIXI.Mouse.map.set(e,!1),!0),PIXI.Mouse.fired=e=>!!(PIXI.Mouse.map.size>0&&PIXI.Mouse.map.get(e))&&(PIXI.Mouse.map.set(e,!1),!0),window.addEventListener("mouseup",e=>{PIXI.Mouse.map.delete(PIXI.Mouse.alias[e.button])}),window.addEventListener("mousedown",e=>{PIXI.Mouse.map.set(PIXI.Mouse.alias[e.button],!0)}),window.addEventListener("mousemove",e=>{PIXI.Mouse.x=(e.x-PIXI.Mouse.bounds.left)/PIXI.Mouse.bounds.width*PIXI.Mouse.container.width,PIXI.Mouse.y=(e.y-PIXI.Mouse.bounds.top)/PIXI.Mouse.bounds.height*PIXI.Mouse.container.height})},useAudio(){PIXI.Audio.ctx=new AudioContext,PIXI.Audio.buffers=new Map,PIXI.Audio.player=function(){if(PIXI.Audio.buffers.has(this.src)){let e=PIXI.Audio.ctx.createBufferSource();e.buffer=PIXI.Audio.buffers.get(this.src),e.connect(PIXI.Audio.ctx.destination),e.start(0)}},PIXI.Audio.from=e=>{let t=new XMLHttpRequest;return t.open("GET",e,!0),t.responseType="arraybuffer",t.onload=()=>{PIXI.Audio.ctx.decodeAudioData(t.response,function(t){PIXI.Audio.buffers.set(e,t)})},t.send(),{src:e,play:PIXI.Audio.player}}},useFile(){PIXI.File.write=async(e,t)=>{let s=new Blob([JSON.stringify(e)],{type:JSON});var o=document.createElement("a"),i=URL.createObjectURL(s);o.href=i,o.download=t+".json",document.body.appendChild(o),o.click(),setTimeout(()=>{document.body.removeChild(o),window.URL.revokeObjectURL(i)},0)},PIXI.File.open=async()=>([fileHandle]=await window.showOpenFilePicker(),JSON.parse(await (await fileHandle.getFile()).text()))},fetch(e){filePromise=new Promise(function(e,t){}),e.forEach(e=>{})},spriteFix(e){let t=e.anchor?e.anchor:{x:0,y:0};return{x:-e.width*t.x+e.x,y:-e.height*t.y+e.y,width:e.width,height:e.height}}},PIXI.collision={aabb(e,t){let s=PIXI.Zephyr.spriteFix(e),o=PIXI.Zephyr.spriteFix(t);return!(s.x+e.width<o.x||s.y+e.height<o.y||s.x>o.x+t.width||s.y>o.y+t.height)},radius(e,t){let s=PIXI.Zephyr.spriteFix(e),o=PIXI.Zephyr.spriteFix(t);return Math.sqrt(Math.pow(s.x-o.x,2)+Math.pow(s.y-o.y,2))<=e.r+t.r}},PIXI.clamp=(e,t,s)=>Math.min(Math.max(e,t),s),PIXI.mix=(e,t,s)=>e*(1-s)+t*s,PIXI.rand=(e,t)=>Math.random()*(t-e+1)^0+e,PIXI.utils.requestFullScreen=e=>{e.requestFullscreen?e.requestFullscreen():e.webkitRequestFullscreen?e.webkitRequestFullscreen():e.msRequestFullscreen&&e.msRequestFullscreen()},window.addEventListener("contextmenu",e=>{e.preventDefault()}),console.log("%cUsing "+PIXI.Zephyr.version+"! https://github.com/OttCS/ZephyrJS","color:#ef6f6c"),console.log("%cCompatible with "+PIXI.Zephyr.compatible,"color:#ea1e63");
1+
"use strict"
2+
3+
PIXI.Audio = {};
4+
PIXI.File = {};
5+
PIXI.Particles = {};
6+
7+
// ZEPHYR FUNCTIONALITY //
8+
9+
PIXI.Zephyr = {
10+
version: "ZephyrJS 23.2",
11+
compatible: "PixiJS v7.1.2",
12+
_spriteFix: (s) => { // Returns the actual x/y width/height of a scaled and anchored Sprite
13+
let w = s.width * (s.scale ? s.scale.x : 1);
14+
let h = s.height * (s.scale ? s.scale.y : 1);
15+
return {
16+
x: s.x - (s.anchor ? s.anchor.x * w : 0) + Math.min(0, w),
17+
y: s.y - (s.anchor ? s.anchor.y * h : 0) + Math.min(0, h),
18+
width: Math.abs(w),
19+
height: Math.abs(h)
20+
}
21+
},
22+
useKeys: () => {
23+
PIXI.Keys = {
24+
map: new Map(),
25+
down: (key) => {
26+
if (PIXI.Keys.map.size > 0 && PIXI.Keys.map.has(key)) {
27+
PIXI.Keys.map.set(key, false);
28+
return true;
29+
}
30+
return false;
31+
},
32+
fired: (key) => {
33+
if (PIXI.Keys.map.size > 0 && PIXI.Keys.map.get(key)) {
34+
PIXI.Keys.map.set(key, false);
35+
return true;
36+
}
37+
return false;
38+
},
39+
};
40+
// EVENTS //
41+
window.addEventListener('keydown', (e) => {
42+
PIXI.Keys.map.set(e.code, true);
43+
});
44+
window.addEventListener('keyup', (e) => {
45+
PIXI.Keys.map.delete(e.code);
46+
});
47+
},
48+
useMouse: () => {
49+
PIXI.Mouse = {
50+
// COORDS //
51+
bounds: document.getElementsByTagName("html")[0].getBoundingClientRect(),
52+
container: document.getElementsByTagName("html")[0],
53+
x: 0,
54+
y: 0,
55+
setContainer: (view) => {
56+
let b = view.getBoundingClientRect();
57+
if (b.width * b.height == 0) {
58+
console.error("Cannot use PIXI.Mouse.setContainer() with an invalid element.");
59+
} else {
60+
PIXI.Mouse.container = view;
61+
PIXI.Mouse.bounds = PIXI.Mouse.container.getBoundingClientRect();
62+
}
63+
},
64+
// BUTTONS //
65+
ALIAS: ["Primary", "Middle", "Secondary"],
66+
map: new Map(),
67+
down: (btn) => {
68+
if (PIXI.Mouse.map.size > 0 && PIXI.Mouse.map.has(btn)) {
69+
PIXI.Mouse.map.set(btn, false);
70+
return true;
71+
}
72+
return false;
73+
},
74+
fired: (btn) => {
75+
if (PIXI.Mouse.map.size > 0 && PIXI.Mouse.map.get(btn)) {
76+
PIXI.Mouse.map.set(btn, false);
77+
return true;
78+
}
79+
return false;
80+
}
81+
}
82+
// EVENTS //
83+
window.onresize = () => {
84+
PIXI.Mouse.bounds = PIXI.Mouse.container.getBoundingClientRect();
85+
}
86+
window.addEventListener('mouseup', (e) => {
87+
PIXI.Mouse.map.delete(PIXI.Mouse.ALIAS[e.button]);
88+
});
89+
window.addEventListener('mousedown', (e) => {
90+
PIXI.Mouse.map.set(PIXI.Mouse.ALIAS[e.button], true);
91+
});
92+
window.addEventListener('mousemove', (e) => {
93+
PIXI.Mouse.x = (e.x - PIXI.Mouse.bounds.left + window.pageXOffset) / PIXI.Mouse.bounds.width * PIXI.Mouse.container.width;
94+
PIXI.Mouse.y = (e.y - PIXI.Mouse.bounds.top + window.pageYOffset) / PIXI.Mouse.bounds.height * PIXI.Mouse.container.height;
95+
});
96+
},
97+
useAudio: () => {
98+
PIXI.Audio = {
99+
ctx: new AudioContext(),
100+
buffers: new Map(), // Stores all audio buffers
101+
_player: function () { // Shared function for all Audio objects
102+
if (PIXI.Audio.buffers.has(this.src)) {
103+
let aud = PIXI.Audio.ctx.createBufferSource();
104+
aud.buffer = PIXI.Audio.buffers.get(this.src);
105+
aud.connect(PIXI.Audio.ctx.destination);
106+
aud.start(0);
107+
}
108+
},
109+
from: (src) => {
110+
let r = new XMLHttpRequest();
111+
r.open('GET', src, true);
112+
r.responseType = 'arraybuffer';
113+
114+
r.onload = () => { // Decode asynchronously
115+
PIXI.Audio.ctx.decodeAudioData(r.response, function (buffer) {
116+
PIXI.Audio.buffers.set(src, buffer); // Store audio buffer once
117+
})
118+
}
119+
r.send();
120+
return { src: src, play: PIXI.Audio._player };
121+
}
122+
}
123+
},
124+
useFile: () => {
125+
PIXI.File = {
126+
write: async (object, fName) => {
127+
let file = new Blob([JSON.stringify(object)], { type: JSON });
128+
var a = document.createElement("a"),
129+
url = URL.createObjectURL(file);
130+
a.href = url;
131+
a.download = fName + ".json";
132+
document.body.appendChild(a);
133+
a.click();
134+
setTimeout(() => {
135+
document.body.removeChild(a);
136+
window.URL.revokeObjectURL(url);
137+
}, 0);
138+
},
139+
open: async () => {
140+
[fileHandle] = await window.showOpenFilePicker();
141+
let file = await fileHandle.getFile();
142+
let contents = await file.text();
143+
return JSON.parse(contents);
144+
}
145+
}
146+
},
147+
useParticles: () => {
148+
PIXI.Particles = {
149+
_step: function (deltaTime) {
150+
const init = (p) => {
151+
let r = (Math.random() - 0.5) * this.spread + this.direction;
152+
p.move = { x: this.speed * Math.cos(r), y: this.speed * Math.sin(r) };
153+
p.x = p.y = 0;
154+
p.life = this.life;
155+
}
156+
if (this.children.length < this.size) {
157+
this._spawnTimer -= deltaTime;
158+
if (this._spawnTimer <= 0) {
159+
this._spawnTimer = this.life / this.size;
160+
let p = new PIXI.Sprite(this.baseTexture);
161+
p.anchor = { x: 0.5, y: 0.5 }
162+
init(p);
163+
this.addChild(p);
164+
}
165+
}
166+
this.children.forEach(p => {
167+
p.x += p.move.x * deltaTime;
168+
p.y += p.move.y * deltaTime;
169+
if ((p.life -= deltaTime * this.speed) <= 0)
170+
init(p);
171+
});
172+
},
173+
from: (src, size, options) => {
174+
if (!options) options = {};
175+
let res = new PIXI.ParticleContainer(size);
176+
res._spawnTimer = 0;
177+
res.size = size;
178+
res.baseTexture = PIXI.Texture.from(src);
179+
res.life = (options.life ? options.life : 128);
180+
res.speed = (options.speed ? options.speed : 1);
181+
res.direction = (options.direction ? options.direction : 0);
182+
res.spread = (options.spread ? options.spread : 6.2831853072);
183+
res.step = PIXI.Particles._step;
184+
return res;
185+
}
186+
}
187+
}
188+
}
189+
190+
// Collision testing methods
191+
PIXI.collision = {
192+
aabb: (a, b) => { // Axis-Aligned Bounding Box method
193+
let aFix = PIXI.Zephyr._spriteFix(a);
194+
let bFix = PIXI.Zephyr._spriteFix(b);
195+
return !(
196+
aFix.x + a.width < bFix.x ||
197+
aFix.y + a.height < bFix.y ||
198+
aFix.x > bFix.x + b.width ||
199+
aFix.y > bFix.y + b.height
200+
);
201+
},
202+
radius: (a, b) => { // Circle collision, for objects a and b, provided they ha
203+
let aFix = PIXI.Zephyr._spriteFix(a);
204+
let bFix = PIXI.Zephyr._spriteFix(b);
205+
return (
206+
Math.sqrt(Math.pow(aFix.x - bFix.x, 2) + Math.pow(aFix.y - bFix.y, 2)) <= a.r + b.r
207+
);
208+
}
209+
}
210+
// Returns the value of x if it is between the bounds of min and max, or the closest bound if x is outside
211+
PIXI.clamp = (x, min, max) => {
212+
return Math.min(Math.max(x, min), max);
213+
};
214+
// Linearly interpolate between values a and b
215+
PIXI.mix = (a, b, m) => {
216+
return a * (1 - m) + b * (m);
217+
}
218+
// Generates a random integer between min and max, inclusive
219+
PIXI.rand = (min, max) => {
220+
return (Math.random() * (max - min + 1)) ^ 0 + min;
221+
};
222+
// Requests fullscreen for the provided element (view)
223+
PIXI.toggleFullScreen = (view) => {
224+
if (!view.fullscreenElement &&
225+
!view.mozFullScreenElement && !view.webkitFullscreenElement) { // current working methods
226+
if (view.requestFullscreen) {
227+
view.requestFullscreen();
228+
} else if (view.mozRequestFullScreen) {
229+
view.mozRequestFullScreen();
230+
} else if (view.webkitRequestFullscreen) {
231+
view.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
232+
}
233+
} else {
234+
if (view.cancelFullScreen) {
235+
view.cancelFullScreen();
236+
} else if (view.mozCancelFullScreen) {
237+
view.mozCancelFullScreen();
238+
} else if (view.webkitCancelFullScreen) {
239+
view.webkitCancelFullScreen();
240+
}
241+
}
242+
}
243+
// Stop rClick
244+
window.addEventListener('contextmenu', (e) => {
245+
e.preventDefault();
246+
})
247+
248+
console.log("%cUsing " + PIXI.Zephyr.version + "! https://github.com/OttCS/ZephyrJS", "color:#ef6f6c");
249+
console.log("%cCompatible with " + PIXI.Zephyr.compatible, "color:#ea1e63")

0 commit comments

Comments
 (0)