Skip to content

Commit 40efcf2

Browse files
committed
Stable 22.12.06
1 parent e650a32 commit 40efcf2

File tree

3 files changed

+202
-10
lines changed

3 files changed

+202
-10
lines changed

stable/pixi.js

Lines changed: 8 additions & 8 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: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

stable/zephyr.js

Lines changed: 193 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,193 @@
1-
"use strict";PIXI.Keys={},PIXI.Mouse={},PIXI.Audio={},PIXI.File={},PIXI.Zephyr={color:{PRIMARY:"#ef6f6c",WARNING:"#f0cf6b",SUCCESS:"#6bf097",MESSAGE:"#6c6fef",ADVANCE:"#a36cef",PIXIJS:"#ea1e63"},version:"ZephyrJS 22.11.02",compatible:"PixiJS v7.0.2",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=>{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 s=new XMLHttpRequest;return s.open("GET",e,!0),s.responseType="arraybuffer",s.onload=()=>{PIXI.Audio.ctx.decodeAudioData(s.response,function(s){PIXI.Audio.buffers.set(e,s)})},s.send(),{src:e,play:PIXI.Audio.player}}},useFile(){PIXI.File.write=async(e,s)=>{let t=new Blob([JSON.stringify(e)],{type:JSON});var o=document.createElement("a"),i=URL.createObjectURL(t);o.href=i,o.download=s+".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()))},spriteFix(e){let s=e.anchor?e.anchor:{x:0,y:0};return{x:-e.width*s.x+e.x,y:-e.height*s.y+e.y,width:e.width,height:e.height}}},PIXI.collision={aabb(e,s){let t=PIXI.Zephyr.spriteFix(e),o=PIXI.Zephyr.spriteFix(s);return!(t.x+e.width<o.x||t.y+e.height<o.y||t.x>o.x+s.width||t.y>o.y+s.height)},radius(e,s){let t=PIXI.Zephyr.spriteFix(e),o=PIXI.Zephyr.spriteFix(s);return Math.sqrt(Math.pow(t.x-o.x,2)+Math.pow(t.y-o.y,2))<=e.r+s.r}},PIXI.clamp=(e,s,t)=>Math.min(Math.max(e,s),t),PIXI.mix=(e,s,t)=>e*(1-t)+s*t,PIXI.rand=(e,s)=>Math.random()*(s-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:"+PIXI.Zephyr.color.PRIMARY),console.log("%cCompatible with "+PIXI.Zephyr.compatible,"color:"+PIXI.Zephyr.color.PIXIJS);
1+
"use strict"
2+
PIXI.Keys = {};
3+
PIXI.Mouse = {};
4+
PIXI.Audio = {};
5+
PIXI.File = {};
6+
7+
PIXI.Zephyr = {
8+
color: {
9+
PRIMARY: "#ef6f6c",
10+
WARNING: "#f0cf6b",
11+
SUCCESS: "#6bf097",
12+
MESSAGE: "#6c6fef",
13+
ADVANCE: "#a36cef",
14+
PIXIJS: "#ea1e63",
15+
},
16+
version: "ZephyrJS 22.12.06",
17+
compatible: "PixiJS v7.0.4",
18+
useKeys: () => {
19+
PIXI.Keys.map = new Map();
20+
PIXI.Keys.down = (key) => {
21+
if (PIXI.Keys.map.size > 0 && PIXI.Keys.map.has(key)) {
22+
PIXI.Keys.map.set(key, false);
23+
return true;
24+
}
25+
return false;
26+
};
27+
PIXI.Keys.fired = (key) => {
28+
if (PIXI.Keys.map.size > 0 && PIXI.Keys.map.get(key)) {
29+
PIXI.Keys.map.set(key, false);
30+
return true;
31+
}
32+
return false;
33+
};
34+
35+
window.addEventListener('keydown', (e) => {
36+
e.preventDefault();
37+
PIXI.Keys.map.set(e.code, true);
38+
});
39+
window.addEventListener('keyup', (e) => {
40+
PIXI.Keys.map.delete(e.code);
41+
});
42+
},
43+
useMouse: () => {
44+
PIXI.Mouse.bounds = document.getElementsByTagName("html")[0].getBoundingClientRect();
45+
PIXI.Mouse.container = document.getElementsByTagName("html")[0];
46+
PIXI.Mouse.x = 0;
47+
PIXI.Mouse.y = 0;
48+
PIXI.Mouse.setContainer = (view) => {
49+
PIXI.Mouse.container = view;
50+
PIXI.Mouse.bounds = PIXI.Mouse.container.getBoundingClientRect();
51+
}
52+
window.onresize = () => {
53+
PIXI.Mouse.bounds = PIXI.Mouse.container.getBoundingClientRect();
54+
}
55+
56+
PIXI.Mouse.alias = ["Primary", "Middle", "Secondary"];
57+
58+
PIXI.Mouse.map = new Map();
59+
PIXI.Mouse.down = (btn) => {
60+
if (PIXI.Mouse.map.size > 0 && PIXI.Mouse.map.has(btn)) {
61+
PIXI.Mouse.map.set(btn, false);
62+
return true;
63+
}
64+
return false;
65+
}
66+
67+
PIXI.Mouse.fired = (btn) => {
68+
if (PIXI.Mouse.map.size > 0 && PIXI.Mouse.map.get(btn)) {
69+
PIXI.Mouse.map.set(btn, false);
70+
return true;
71+
}
72+
return false;
73+
}
74+
75+
window.addEventListener('mouseup', (e) => {
76+
PIXI.Mouse.map.delete(PIXI.Mouse.alias[e.button]);
77+
});
78+
window.addEventListener('mousedown', (e) => {
79+
PIXI.Mouse.map.set(PIXI.Mouse.alias[e.button], true);
80+
});
81+
window.addEventListener('mousemove', (e) => {
82+
PIXI.Mouse.x = (e.x - PIXI.Mouse.bounds.left) / PIXI.Mouse.bounds.width * PIXI.Mouse.container.width;
83+
PIXI.Mouse.y = (e.y - PIXI.Mouse.bounds.top) / PIXI.Mouse.bounds.height * PIXI.Mouse.container.height;
84+
});
85+
},
86+
useAudio: () => {
87+
PIXI.Audio.ctx = new AudioContext();
88+
PIXI.Audio.buffers = new Map();
89+
PIXI.Audio.player = function () {
90+
if (PIXI.Audio.buffers.has(this.src)) {
91+
let aud = PIXI.Audio.ctx.createBufferSource();
92+
aud.buffer = PIXI.Audio.buffers.get(this.src);
93+
aud.connect(PIXI.Audio.ctx.destination);
94+
aud.start(0);
95+
}
96+
}
97+
PIXI.Audio.from = (src) => {
98+
let r = new XMLHttpRequest();
99+
r.open('GET', src, true);
100+
r.responseType = 'arraybuffer';
101+
102+
// Decode asynchronously
103+
r.onload = () => {
104+
PIXI.Audio.ctx.decodeAudioData(r.response, function (buffer) {
105+
PIXI.Audio.buffers.set(src, buffer);
106+
});
107+
}
108+
r.send();
109+
return {
110+
src: src,
111+
play: PIXI.Audio.player
112+
}
113+
}
114+
},
115+
useFile: () => {
116+
PIXI.File.write = async (object, fName) => {
117+
let file = new Blob([JSON.stringify(object)], { type: JSON });
118+
var a = document.createElement("a"),
119+
url = URL.createObjectURL(file);
120+
a.href = url;
121+
a.download = fName + ".json";
122+
document.body.appendChild(a);
123+
a.click();
124+
setTimeout(() => {
125+
document.body.removeChild(a);
126+
window.URL.revokeObjectURL(url);
127+
}, 0);
128+
};
129+
PIXI.File.open = async () => {
130+
[fileHandle] = await window.showOpenFilePicker();
131+
let file = await fileHandle.getFile();
132+
let contents = await file.text();
133+
return JSON.parse(contents);
134+
};
135+
},
136+
spriteFix: (s) => { // "Fixes" the provided sprite/object for use with the collision functions, adjusting for anchor positions
137+
let anchor = (s.anchor ? s.anchor : { x: 0, y: 0 });
138+
return {
139+
x: -s.width * anchor.x + s.x,
140+
y: -s.height * anchor.y + s.y,
141+
width: s.width,
142+
height: s.height
143+
}
144+
}
145+
}
146+
// Collision testing methods
147+
PIXI.collision = {
148+
aabb: (a, b) => { // Axis-Aligned Bounding Box method
149+
let aFix = PIXI.Zephyr.spriteFix(a);
150+
let bFix = PIXI.Zephyr.spriteFix(b);
151+
return !(
152+
aFix.x + a.width < bFix.x ||
153+
aFix.y + a.height < bFix.y ||
154+
aFix.x > bFix.x + b.width ||
155+
aFix.y > bFix.y + b.height
156+
);
157+
},
158+
radius: (a, b) => { // Circle collision, for objects a and b, provided they ha
159+
let aFix = PIXI.Zephyr.spriteFix(a);
160+
let bFix = PIXI.Zephyr.spriteFix(b);
161+
return (
162+
Math.sqrt(Math.pow(aFix.x - bFix.x, 2) + Math.pow(aFix.y - bFix.y, 2)) <= a.r + b.r
163+
);
164+
}
165+
}
166+
// Returns the value of x if it is between the bounds of min and max, or the closest bound if x is outside
167+
PIXI.clamp = (x, min, max) => {
168+
return Math.min(Math.max(x, min), max);
169+
};
170+
// Linearly interpolate between values a and b
171+
PIXI.mix = (a, b, m) => {
172+
return a * (1 - m) + b * (m);
173+
}
174+
// Generates a random integer between min and max, inclusive
175+
PIXI.rand = (min, max) => {
176+
return (Math.random() * (max - min + 1)) ^ 0 + min;
177+
};
178+
// Requests fullscreen for the provided element (view)
179+
PIXI.utils.requestFullScreen = (view) => {
180+
if (view.requestFullscreen)
181+
view.requestFullscreen();
182+
else if (view.webkitRequestFullscreen)
183+
view.webkitRequestFullscreen();
184+
else if (view.msRequestFullscreen)
185+
view.msRequestFullscreen();
186+
}
187+
// Stop rClick
188+
window.addEventListener('contextmenu', (e) => {
189+
e.preventDefault();
190+
})
191+
192+
console.log("%cUsing " + PIXI.Zephyr.version + "! https://github.com/OttCS/ZephyrJS", "color:" + PIXI.Zephyr.color.PRIMARY);
193+
console.log("%cCompatible with " + PIXI.Zephyr.compatible, "color:" + PIXI.Zephyr.color.PIXIJS)

0 commit comments

Comments
 (0)