Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
48161f5c24 | ||
|
|
70233b7508 | ||
|
|
ad0d32b7aa | ||
|
|
505e808318 | ||
|
|
07298c8fcd | ||
|
|
f664a4971b | ||
|
|
7c6e6df91a | ||
|
|
fd0a071cb3 | ||
|
|
62d77e7038 | ||
|
|
0a42269479 | ||
|
|
ecc91fb4e0 | ||
|
|
f812b92b8a | ||
|
|
a1450680a4 | ||
|
|
9f687b4f8a | ||
|
|
79dc3566f4 | ||
|
|
336de314a1 | ||
|
|
92e86494e3 | ||
|
|
d211cf669c | ||
|
|
dbaf7269e9 | ||
|
|
3d22d0e169 | ||
|
|
89b00db103 | ||
|
|
95374339b9 | ||
|
|
fba731e740 | ||
|
|
f260108433 | ||
|
|
87858d6bbf | ||
|
|
e79dd5856d | ||
|
|
48ed27dfcc | ||
|
|
f885f7b023 | ||
|
|
e2eddc8b24 | ||
|
|
e41e35fd09 | ||
|
|
a486bf6b4a | ||
|
|
5da0e42be4 | ||
|
|
15fe5ed6c8 | ||
|
|
609ea7ec8f | ||
|
|
4f950ae801 | ||
|
|
5d3fe891cd | ||
|
|
2ba6b4ff67 | ||
|
|
60f0e8967f | ||
|
|
30fc4099c6 | ||
|
|
ee007cd28e | ||
|
|
c904475ae6 | ||
|
|
13d6ab512b | ||
|
|
9b6c819e0e | ||
|
|
50624c1552 | ||
|
|
ebda1f99e3 | ||
|
|
abe344b408 | ||
|
|
90b1946c25 | ||
|
|
78598ae54a | ||
|
|
fe6664eac7 | ||
|
|
bb5d8ca170 | ||
|
|
eb7af3d2a2 | ||
|
|
822a2df289 | ||
|
|
0c97e8e151 | ||
|
|
b2fa345c9d | ||
|
|
c552d86639 | ||
|
|
4d4f7d3d56 | ||
|
|
aa0d8ff238 | ||
|
|
87d52bd85e | ||
|
|
912d6e46aa | ||
|
|
55cf10a085 | ||
|
|
ca0d1eb8af | ||
|
|
f4dab1847e | ||
|
|
10bc22b717 | ||
|
|
128bdccd79 | ||
|
|
d44261b191 | ||
|
|
b2263c16c6 | ||
|
|
3f3b6bfd35 | ||
|
|
2a353a0327 | ||
|
|
0f438d5221 | ||
|
|
a27f6d6562 | ||
|
|
2fe8a3a0a7 | ||
|
|
bdc1c2ceb9 | ||
|
|
923c2504ba | ||
|
|
8a90a87492 | ||
|
|
5acb4e9f1b | ||
|
|
e28cdbeb6a | ||
|
|
66e86e7d82 | ||
|
|
c18de53bab | ||
|
|
ed13283f0f | ||
|
|
7c597999d4 | ||
|
|
6235f25184 | ||
|
|
d31777972c | ||
|
|
7bdcbf5c2a | ||
|
|
71b4cc532f | ||
|
|
d54a92310d | ||
|
|
fef28c6a6a | ||
|
|
6ef89826df | ||
|
|
12e5d2aceb | ||
|
|
801c2af9d4 | ||
|
|
188d6239a3 | ||
|
|
b742439db8 | ||
|
|
99e0934244 | ||
|
|
5d4da0ce66 | ||
|
|
22847f6ade | ||
|
|
70ee753859 | ||
|
|
f9aa7f7339 | ||
|
|
54d98944e4 | ||
|
|
e77f5da2cd | ||
|
|
936118bd91 | ||
|
|
a81a8effb4 | ||
|
|
1e59bc69fb | ||
|
|
559d75eba1 | ||
|
|
4c1dacfa02 | ||
|
|
5b036557c0 | ||
|
|
6bf7bab917 | ||
|
|
19483bafed | ||
|
|
16749edf20 | ||
|
|
3d4783980e | ||
|
|
4bbcc380c5 | ||
|
|
3c8cd20b70 | ||
|
|
b8d3a61c97 | ||
|
|
d323404676 | ||
|
|
8a09469798 | ||
|
|
9289f690eb | ||
|
|
89fe2855e4 | ||
|
|
0f58945212 | ||
|
|
09def364c3 | ||
|
|
0e55e644a9 | ||
|
|
8a85155c08 | ||
|
|
ecf61fc80c | ||
|
|
c2745bec35 | ||
|
|
c884bab7ec | ||
|
|
f76ba6840f | ||
|
|
619b8415ed | ||
|
|
91dc7a4acf | ||
|
|
e74114f384 | ||
|
|
142348f70b | ||
|
|
7aa82a1cb0 | ||
|
|
c2d7fb7fab | ||
|
|
aff7d99a8a | ||
|
|
0b1bcaf270 | ||
|
|
f9776f30fc | ||
|
|
8b2f1cca51 | ||
|
|
e002827a20 | ||
|
|
c2f0128797 | ||
|
|
2d49a31ecd | ||
|
|
9bf7d070f5 | ||
|
|
1248a6c06e | ||
|
|
df32190db8 | ||
|
|
73745e5720 | ||
|
|
48f6d850c8 | ||
|
|
ab7e55ef27 | ||
|
|
5768336150 | ||
|
|
04dcb29c88 | ||
|
|
a174bbc6b3 | ||
|
|
bc77c3f84e | ||
|
|
d7205992a5 | ||
|
|
77cc3858d9 | ||
|
|
a7873a3b74 | ||
|
|
11954812c6 | ||
|
|
d1da4cbdef | ||
|
|
84ef32e62a | ||
|
|
f3dcd3e831 | ||
|
|
982faeedb8 | ||
|
|
4c9c50584e | ||
|
|
955909979d | ||
|
|
ce27acd3ca | ||
|
|
4f2c26df77 | ||
|
|
3038f6fcf8 | ||
|
|
d4781a19d9 | ||
|
|
7cae283a4c | ||
|
|
04106b1388 | ||
|
|
d80467a08a | ||
|
|
c8d6fe6c01 | ||
|
|
a5343b4bc0 | ||
|
|
3c123293ba | ||
|
|
9827e7522f | ||
|
|
727a06cd9b | ||
|
|
9f30f656bc | ||
|
|
a2c756e37f | ||
|
|
72eb22128f | ||
|
|
d0e886259d | ||
|
|
d620fc7796 | ||
|
|
b3fff37faf | ||
|
|
08fb303801 | ||
|
|
945c9c1a0d | ||
|
|
6d21d39b19 | ||
|
|
dcce99ec60 | ||
|
|
b0d3f6e192 | ||
|
|
c81cf0c882 | ||
|
|
4695f62d1d | ||
|
|
c647792c12 | ||
|
|
d19ad4976d | ||
|
|
0591c7f2bd | ||
|
|
6648cb3812 | ||
|
|
ec845155eb | ||
|
|
829a1b00e4 | ||
|
|
80f5c0a67d | ||
|
|
0a7513240a | ||
|
|
533a4c2e30 | ||
|
|
dd8962d4b5 | ||
|
|
114d1d2fbf | ||
|
|
232c96cc54 | ||
|
|
461f7ee54d | ||
|
|
d848fa089d | ||
|
|
1bcbf91398 | ||
|
|
7b6beddc0c | ||
|
|
038cb213e8 | ||
|
|
7dac2b6506 | ||
|
|
2389c6c231 | ||
|
|
c2533d1146 | ||
|
|
c5f6817c4c | ||
|
|
1f8c809f53 | ||
|
|
3b9386727e | ||
|
|
a30762ed8c | ||
|
|
730594835a | ||
|
|
2f03f5fc43 | ||
|
|
d42f396ba0 | ||
|
|
82d4ba4538 | ||
|
|
1c37cd1a96 | ||
|
|
2de70d07a5 | ||
|
|
b951b02de8 | ||
|
|
2270da2479 | ||
|
|
f9f17ad353 | ||
|
|
49fe5ee65f | ||
|
|
59f7a59312 | ||
|
|
5b532ab2e4 | ||
|
|
b20a6ff85a | ||
|
|
31c4d8cb14 | ||
|
|
d510b785b1 | ||
|
|
fe372af453 | ||
|
|
23ec3816db | ||
|
|
39e7b84cd9 | ||
|
|
3e53c0671d | ||
|
|
498725c078 | ||
|
|
ce1523585f | ||
|
|
f2054f8a2a | ||
|
|
0fad46e04b | ||
|
|
c1eafe865a | ||
|
|
f3c9049e76 | ||
|
|
7b4374cabf | ||
|
|
b1d836dfaf | ||
|
|
2a26257caa | ||
|
|
09f57fa346 | ||
|
|
3c0c349089 | ||
|
|
03b7467018 | ||
|
|
4cef0d1d35 | ||
|
|
204ec46b2b | ||
|
|
4ef0750c07 | ||
|
|
67bf221073 | ||
|
|
94add2ea6e | ||
|
|
c7485301ca | ||
|
|
c5ace72180 | ||
|
|
bd54460e80 | ||
|
|
e2141c91a6 | ||
|
|
0b2d818ba8 | ||
|
|
05cc32fbc9 | ||
|
|
53aa43566e | ||
|
|
55568592b5 | ||
|
|
a6e8436e6d | ||
|
|
3cdd2baff0 | ||
|
|
ce7bfd1fc2 | ||
|
|
8fc31ed83b | ||
|
|
1c311a73df | ||
|
|
0adbf1d92f | ||
|
|
aaaaf7ede3 | ||
|
|
77582fb1ed | ||
|
|
2a8447f64e | ||
|
|
deb37e9a90 | ||
|
|
ca932038fb | ||
|
|
00ef200914 | ||
|
|
e88c48641d | ||
|
|
1052df6660 | ||
|
|
4be5a10e44 | ||
|
|
5cf8b846f8 | ||
|
|
9da64e6baf | ||
|
|
98693cb418 | ||
|
|
b1a33cc593 | ||
|
|
b5b5a99dce | ||
|
|
be982b4322 | ||
|
|
493380a51e | ||
|
|
0a08e1ae0e | ||
|
|
e39073d07b | ||
|
|
54a5e6477c | ||
|
|
2a5b6ef12a | ||
|
|
e62b300a25 | ||
|
|
7d98a1bb9d | ||
|
|
c5cccf3283 |
@@ -1 +1,6 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
|
.idea
|
||||||
|
Phaser OSX.sublime-project
|
||||||
|
Phaser OSX.sublime-workspace
|
||||||
|
Phaser.sublime-project
|
||||||
|
Phaser.sublime-workspace
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
YUI.add("yuidoc-meta", function(Y) {
|
||||||
|
Y.YUIDoc = { meta: {
|
||||||
|
"classes": [
|
||||||
|
"TimeManager"
|
||||||
|
],
|
||||||
|
"modules": [
|
||||||
|
"Phaser"
|
||||||
|
],
|
||||||
|
"allModules": [
|
||||||
|
{
|
||||||
|
"displayName": "Phaser",
|
||||||
|
"name": "Phaser"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
} };
|
||||||
|
});
|
||||||
|
After Width: | Height: | Size: 491 B |
|
After Width: | Height: | Size: 6.2 KiB |
@@ -0,0 +1,783 @@
|
|||||||
|
/*
|
||||||
|
Font sizes for all selectors other than the body are given in percentages,
|
||||||
|
with 100% equal to 13px. To calculate a font size percentage, multiply the
|
||||||
|
desired size in pixels by 7.6923076923.
|
||||||
|
|
||||||
|
Here's a quick lookup table:
|
||||||
|
|
||||||
|
10px - 76.923%
|
||||||
|
11px - 84.615%
|
||||||
|
12px - 92.308%
|
||||||
|
13px - 100%
|
||||||
|
14px - 107.692%
|
||||||
|
15px - 115.385%
|
||||||
|
16px - 123.077%
|
||||||
|
17px - 130.769%
|
||||||
|
18px - 138.462%
|
||||||
|
19px - 146.154%
|
||||||
|
20px - 153.846%
|
||||||
|
*/
|
||||||
|
|
||||||
|
html {
|
||||||
|
background: #fff;
|
||||||
|
color: #333;
|
||||||
|
overflow-y: scroll;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
/*font: 13px/1.4 'Lucida Grande', 'Lucida Sans Unicode', 'DejaVu Sans', 'Bitstream Vera Sans', 'Helvetica', 'Arial', sans-serif;*/
|
||||||
|
font: 13px/1.4 'Helvetica', 'Arial', sans-serif;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -- Links ----------------------------------------------------------------- */
|
||||||
|
a {
|
||||||
|
color: #356de4;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hidden {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
a:hover { text-decoration: underline; }
|
||||||
|
|
||||||
|
/* "Jump to Table of Contents" link is shown to assistive tools, but hidden from
|
||||||
|
sight until it's focused. */
|
||||||
|
.jump {
|
||||||
|
position: absolute;
|
||||||
|
padding: 3px 6px;
|
||||||
|
left: -99999px;
|
||||||
|
top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.jump:focus { left: 40%; }
|
||||||
|
|
||||||
|
/* -- Paragraphs ------------------------------------------------------------ */
|
||||||
|
p { margin: 1.3em 0; }
|
||||||
|
dd p, td p { margin-bottom: 0; }
|
||||||
|
dd p:first-child, td p:first-child { margin-top: 0; }
|
||||||
|
|
||||||
|
/* -- Headings -------------------------------------------------------------- */
|
||||||
|
h1, h2, h3, h4, h5, h6 {
|
||||||
|
color: #D98527;/*was #f80*/
|
||||||
|
font-family: 'Trebuchet MS', sans-serif;
|
||||||
|
font-weight: bold;
|
||||||
|
line-height: 1.1;
|
||||||
|
margin: 1.1em 0 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 184.6%;
|
||||||
|
color: #30418C;
|
||||||
|
margin: 0.75em 0 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
font-size: 153.846%;
|
||||||
|
color: #E48A2B;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 { font-size: 138.462%; }
|
||||||
|
|
||||||
|
h4 {
|
||||||
|
border-bottom: 1px solid #DBDFEA;
|
||||||
|
color: #E48A2B;
|
||||||
|
font-size: 115.385%;
|
||||||
|
font-weight: normal;
|
||||||
|
padding-bottom: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h5, h6 { font-size: 107.692%; }
|
||||||
|
|
||||||
|
/* -- Code and examples ----------------------------------------------------- */
|
||||||
|
code, kbd, pre, samp {
|
||||||
|
font-family: Menlo, Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace;
|
||||||
|
font-size: 92.308%;
|
||||||
|
line-height: 1.35;
|
||||||
|
}
|
||||||
|
|
||||||
|
p code, p kbd, p samp {
|
||||||
|
background: #FCFBFA;
|
||||||
|
border: 1px solid #EFEEED;
|
||||||
|
padding: 0 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
a code, a kbd, a samp,
|
||||||
|
pre code, pre kbd, pre samp,
|
||||||
|
table code, table kbd, table samp,
|
||||||
|
.intro code, .intro kbd, .intro samp,
|
||||||
|
.toc code, .toc kbd, .toc samp {
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre.code, pre.terminal, pre.cmd {
|
||||||
|
overflow-x: auto;
|
||||||
|
*overflow-x: scroll;
|
||||||
|
padding: 0.3em 0.6em;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre.code {
|
||||||
|
background: #FCFBFA;
|
||||||
|
border: 1px solid #EFEEED;
|
||||||
|
border-left-width: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre.terminal, pre.cmd {
|
||||||
|
background: #F0EFFC;
|
||||||
|
border: 1px solid #D0CBFB;
|
||||||
|
border-left: 5px solid #D0CBFB;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Don't reduce the font size of <code>/<kbd>/<samp> elements inside <pre>
|
||||||
|
blocks. */
|
||||||
|
pre code, pre kbd, pre samp { font-size: 100%; }
|
||||||
|
|
||||||
|
/* Used to denote text that shouldn't be selectable, such as line numbers or
|
||||||
|
shell prompts. Guess which browser this doesn't work in. */
|
||||||
|
.noselect {
|
||||||
|
-moz-user-select: -moz-none;
|
||||||
|
-khtml-user-select: none;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
-o-user-select: none;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -- Lists ----------------------------------------------------------------- */
|
||||||
|
dd { margin: 0.2em 0 0.7em 1em; }
|
||||||
|
dl { margin: 1em 0; }
|
||||||
|
dt { font-weight: bold; }
|
||||||
|
|
||||||
|
/* -- Tables ---------------------------------------------------------------- */
|
||||||
|
caption, th { text-align: left; }
|
||||||
|
|
||||||
|
table {
|
||||||
|
border-collapse: collapse;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
td, th {
|
||||||
|
border: 1px solid #fff;
|
||||||
|
padding: 5px 12px;
|
||||||
|
vertical-align: top;
|
||||||
|
}
|
||||||
|
|
||||||
|
td { background: #E6E9F5; }
|
||||||
|
td dl { margin: 0; }
|
||||||
|
td dl dl { margin: 1em 0; }
|
||||||
|
td pre:first-child { margin-top: 0; }
|
||||||
|
|
||||||
|
th {
|
||||||
|
background: #D2D7E6;/*#97A0BF*/
|
||||||
|
border-bottom: none;
|
||||||
|
border-top: none;
|
||||||
|
color: #000;/*#FFF1D5*/
|
||||||
|
font-family: 'Trebuchet MS', sans-serif;
|
||||||
|
font-weight: bold;
|
||||||
|
line-height: 1.3;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* -- Layout and Content ---------------------------------------------------- */
|
||||||
|
#doc {
|
||||||
|
margin: auto;
|
||||||
|
min-width: 1024px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content { padding: 0 20px 0 25px; }
|
||||||
|
|
||||||
|
.sidebar {
|
||||||
|
padding: 0 15px 0 10px;
|
||||||
|
}
|
||||||
|
#bd {
|
||||||
|
padding: 7px 0 130px;
|
||||||
|
position: relative;
|
||||||
|
width: 99%;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -- Table of Contents ----------------------------------------------------- */
|
||||||
|
|
||||||
|
/* The #toc id refers to the single global table of contents, while the .toc
|
||||||
|
class refers to generic TOC lists that could be used throughout the page. */
|
||||||
|
|
||||||
|
.toc code, .toc kbd, .toc samp { font-size: 100%; }
|
||||||
|
.toc li { font-weight: bold; }
|
||||||
|
.toc li li { font-weight: normal; }
|
||||||
|
|
||||||
|
/* -- Intro and Example Boxes ----------------------------------------------- */
|
||||||
|
/*
|
||||||
|
.intro, .example { margin-bottom: 2em; }
|
||||||
|
.example {
|
||||||
|
-moz-border-radius: 4px;
|
||||||
|
-webkit-border-radius: 4px;
|
||||||
|
border-radius: 4px;
|
||||||
|
-moz-box-shadow: 0 0 5px #bfbfbf;
|
||||||
|
-webkit-box-shadow: 0 0 5px #bfbfbf;
|
||||||
|
box-shadow: 0 0 5px #bfbfbf;
|
||||||
|
padding: 1em;
|
||||||
|
}
|
||||||
|
.intro {
|
||||||
|
background: none repeat scroll 0 0 #F0F1F8; border: 1px solid #D4D8EB; padding: 0 1em;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* -- Other Styles ---------------------------------------------------------- */
|
||||||
|
|
||||||
|
/* These are probably YUI-specific, and should be moved out of Selleck's default
|
||||||
|
theme. */
|
||||||
|
|
||||||
|
.button {
|
||||||
|
border: 1px solid #dadada;
|
||||||
|
-moz-border-radius: 3px;
|
||||||
|
-webkit-border-radius: 3px;
|
||||||
|
border-radius: 3px;
|
||||||
|
color: #444;
|
||||||
|
display: inline-block;
|
||||||
|
font-family: Helvetica, Arial, sans-serif;
|
||||||
|
font-size: 92.308%;
|
||||||
|
font-weight: bold;
|
||||||
|
padding: 4px 13px 3px;
|
||||||
|
-moz-text-shadow: 1px 1px 0 #fff;
|
||||||
|
-webkit-text-shadow: 1px 1px 0 #fff;
|
||||||
|
text-shadow: 1px 1px 0 #fff;
|
||||||
|
white-space: nowrap;
|
||||||
|
|
||||||
|
background: #EFEFEF; /* old browsers */
|
||||||
|
background: -moz-linear-gradient(top, #f5f5f5 0%, #efefef 50%, #e5e5e5 51%, #dfdfdf 100%); /* firefox */
|
||||||
|
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f5f5f5), color-stop(50%,#efefef), color-stop(51%,#e5e5e5), color-stop(100%,#dfdfdf)); /* webkit */
|
||||||
|
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f5f5f5', endColorstr='#dfdfdf',GradientType=0 ); /* ie */
|
||||||
|
}
|
||||||
|
|
||||||
|
.button:hover {
|
||||||
|
border-color: #466899;
|
||||||
|
color: #fff;
|
||||||
|
text-decoration: none;
|
||||||
|
-moz-text-shadow: 1px 1px 0 #222;
|
||||||
|
-webkit-text-shadow: 1px 1px 0 #222;
|
||||||
|
text-shadow: 1px 1px 0 #222;
|
||||||
|
|
||||||
|
background: #6396D8; /* old browsers */
|
||||||
|
background: -moz-linear-gradient(top, #6396D8 0%, #5A83BC 50%, #547AB7 51%, #466899 100%); /* firefox */
|
||||||
|
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#6396D8), color-stop(50%,#5A83BC), color-stop(51%,#547AB7), color-stop(100%,#466899)); /* webkit */
|
||||||
|
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#6396D8', endColorstr='#466899',GradientType=0 ); /* ie */
|
||||||
|
}
|
||||||
|
|
||||||
|
.newwindow { text-align: center; }
|
||||||
|
|
||||||
|
.header .version em {
|
||||||
|
display: block;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#classdocs .item {
|
||||||
|
border-bottom: 1px solid #466899;
|
||||||
|
margin: 1em 0;
|
||||||
|
padding: 1.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
#classdocs .item .params p,
|
||||||
|
#classdocs .item .returns p,{
|
||||||
|
display: inline;
|
||||||
|
}
|
||||||
|
|
||||||
|
#classdocs .item em code, #classdocs .item em.comment {
|
||||||
|
color: green;
|
||||||
|
}
|
||||||
|
|
||||||
|
#classdocs .item em.comment a {
|
||||||
|
color: green;
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
#classdocs .foundat {
|
||||||
|
font-size: 11px;
|
||||||
|
font-style: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.attrs .emits {
|
||||||
|
margin-left: 2em;
|
||||||
|
padding: .5em;
|
||||||
|
border-left: 1px dashed #ccc;
|
||||||
|
}
|
||||||
|
|
||||||
|
abbr {
|
||||||
|
border-bottom: 1px dashed #ccc;
|
||||||
|
font-size: 80%;
|
||||||
|
cursor: help;
|
||||||
|
}
|
||||||
|
|
||||||
|
.prettyprint li.L0,
|
||||||
|
.prettyprint li.L1,
|
||||||
|
.prettyprint li.L2,
|
||||||
|
.prettyprint li.L3,
|
||||||
|
.prettyprint li.L5,
|
||||||
|
.prettyprint li.L6,
|
||||||
|
.prettyprint li.L7,
|
||||||
|
.prettyprint li.L8 {
|
||||||
|
list-style: decimal;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul li p {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.method .name {
|
||||||
|
font-size: 110%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.apidocs .methods .extends .method,
|
||||||
|
.apidocs .properties .extends .property,
|
||||||
|
.apidocs .attrs .extends .attr,
|
||||||
|
.apidocs .events .extends .event {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.apidocs .methods .extends .inherited,
|
||||||
|
.apidocs .properties .extends .inherited,
|
||||||
|
.apidocs .attrs .extends .inherited,
|
||||||
|
.apidocs .events .extends .inherited {
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
#hd {
|
||||||
|
background: whiteSmoke;
|
||||||
|
background: -moz-linear-gradient(top,#DCDBD9 0,#F6F5F3 100%);
|
||||||
|
background: -webkit-gradient(linear,left top,left bottom,color-stop(0%,#DCDBD9),color-stop(100%,#F6F5F3));
|
||||||
|
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#dcdbd9',endColorstr='#F6F5F3',GradientType=0);
|
||||||
|
border-bottom: 1px solid #DFDFDF;
|
||||||
|
padding: 0 15px 1px 20px;
|
||||||
|
margin-bottom: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#hd img {
|
||||||
|
margin-right: 10px;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* -- API Docs CSS ---------------------------------------------------------- */
|
||||||
|
|
||||||
|
/*
|
||||||
|
This file is organized so that more generic styles are nearer the top, and more
|
||||||
|
specific styles are nearer the bottom of the file. This allows us to take full
|
||||||
|
advantage of the cascade to avoid redundant style rules. Please respect this
|
||||||
|
convention when making changes.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* -- Generic TabView styles ------------------------------------------------ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
These styles apply to all API doc tabviews. To change styles only for a
|
||||||
|
specific tabview, see the other sections below.
|
||||||
|
*/
|
||||||
|
|
||||||
|
.yui3-js-enabled .apidocs .tabview {
|
||||||
|
visibility: hidden; /* Hide until the TabView finishes rendering. */
|
||||||
|
_visibility: visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
.apidocs .tabview.yui3-tabview-content { visibility: visible; }
|
||||||
|
.apidocs .tabview .yui3-tabview-panel { background: #fff; }
|
||||||
|
|
||||||
|
/* -- Generic Content Styles ------------------------------------------------ */
|
||||||
|
|
||||||
|
/* Headings */
|
||||||
|
h2, h3, h4, h5, h6 {
|
||||||
|
border: none;
|
||||||
|
color: #30418C;
|
||||||
|
font-weight: bold;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.link-docs {
|
||||||
|
float: right;
|
||||||
|
font-size: 15px;
|
||||||
|
margin: 4px 4px 6px;
|
||||||
|
padding: 6px 30px 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.apidocs { zoom: 1; }
|
||||||
|
|
||||||
|
/* Generic box styles. */
|
||||||
|
.apidocs .box {
|
||||||
|
border: 1px solid;
|
||||||
|
border-radius: 3px;
|
||||||
|
margin: 1em 0;
|
||||||
|
padding: 0 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* A flag is a compact, capsule-like indicator of some kind. It's used to
|
||||||
|
indicate private and protected items, item return types, etc. in an
|
||||||
|
attractive and unobtrusive way. */
|
||||||
|
.apidocs .flag {
|
||||||
|
background: #bababa;
|
||||||
|
border-radius: 3px;
|
||||||
|
color: #fff;
|
||||||
|
font-size: 11px;
|
||||||
|
margin: 0 0.5em;
|
||||||
|
padding: 2px 4px 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Class/module metadata such as "Uses", "Extends", "Defined in", etc. */
|
||||||
|
.apidocs .meta {
|
||||||
|
background: #f9f9f9;
|
||||||
|
border-color: #efefef;
|
||||||
|
color: #555;
|
||||||
|
font-size: 11px;
|
||||||
|
padding: 3px 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.apidocs .meta p { margin: 0; }
|
||||||
|
|
||||||
|
/* Deprecation warning. */
|
||||||
|
.apidocs .box.deprecated,
|
||||||
|
.apidocs .flag.deprecated {
|
||||||
|
background: #fdac9f;
|
||||||
|
border: 1px solid #fd7775;
|
||||||
|
}
|
||||||
|
|
||||||
|
.apidocs .box.deprecated p { margin: 0.5em 0; }
|
||||||
|
.apidocs .flag.deprecated { color: #333; }
|
||||||
|
|
||||||
|
/* Module/Class intro description. */
|
||||||
|
.apidocs .intro {
|
||||||
|
background: #f0f1f8;
|
||||||
|
border-color: #d4d8eb;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Loading spinners. */
|
||||||
|
#bd.loading .apidocs,
|
||||||
|
#api-list.loading .yui3-tabview-panel {
|
||||||
|
background: #fff url(../img/spinner.gif) no-repeat center 70px;
|
||||||
|
min-height: 150px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#bd.loading .apidocs .content,
|
||||||
|
#api-list.loading .yui3-tabview-panel .apis {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.apidocs .no-visible-items { color: #666; }
|
||||||
|
|
||||||
|
/* Generic inline list. */
|
||||||
|
.apidocs ul.inline {
|
||||||
|
display: inline;
|
||||||
|
list-style: none;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.apidocs ul.inline li { display: inline; }
|
||||||
|
|
||||||
|
/* Comma-separated list. */
|
||||||
|
.apidocs ul.commas li:after { content: ','; }
|
||||||
|
.apidocs ul.commas li:last-child:after { content: ''; }
|
||||||
|
|
||||||
|
/* Keyboard shortcuts. */
|
||||||
|
kbd .cmd { font-family: Monaco, Helvetica; }
|
||||||
|
|
||||||
|
/* -- Generic Access Level styles ------------------------------------------- */
|
||||||
|
.apidocs .item.protected,
|
||||||
|
.apidocs .item.private,
|
||||||
|
.apidocs .index-item.protected,
|
||||||
|
.apidocs .index-item.deprecated,
|
||||||
|
.apidocs .index-item.private {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.show-deprecated .item.deprecated,
|
||||||
|
.show-deprecated .index-item.deprecated,
|
||||||
|
.show-protected .item.protected,
|
||||||
|
.show-protected .index-item.protected,
|
||||||
|
.show-private .item.private,
|
||||||
|
.show-private .index-item.private {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hide-inherited .item.inherited,
|
||||||
|
.hide-inherited .index-item.inherited {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -- Generic Item Index styles --------------------------------------------- */
|
||||||
|
.apidocs .index { margin: 1.5em 0 3em; }
|
||||||
|
|
||||||
|
.apidocs .index h3 {
|
||||||
|
border-bottom: 1px solid #efefef;
|
||||||
|
color: #333;
|
||||||
|
font-size: 13px;
|
||||||
|
margin: 2em 0 0.6em;
|
||||||
|
padding-bottom: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.apidocs .index .no-visible-items { margin-top: 2em; }
|
||||||
|
|
||||||
|
.apidocs .index-list {
|
||||||
|
border-color: #efefef;
|
||||||
|
font-size: 12px;
|
||||||
|
list-style: none;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
-moz-column-count: 4;
|
||||||
|
-moz-column-gap: 10px;
|
||||||
|
-moz-column-width: 170px;
|
||||||
|
-ms-column-count: 4;
|
||||||
|
-ms-column-gap: 10px;
|
||||||
|
-ms-column-width: 170px;
|
||||||
|
-o-column-count: 4;
|
||||||
|
-o-column-gap: 10px;
|
||||||
|
-o-column-width: 170px;
|
||||||
|
-webkit-column-count: 4;
|
||||||
|
-webkit-column-gap: 10px;
|
||||||
|
-webkit-column-width: 170px;
|
||||||
|
column-count: 4;
|
||||||
|
column-gap: 10px;
|
||||||
|
column-width: 170px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.apidocs .no-columns .index-list {
|
||||||
|
-moz-column-count: 1;
|
||||||
|
-ms-column-count: 1;
|
||||||
|
-o-column-count: 1;
|
||||||
|
-webkit-column-count: 1;
|
||||||
|
column-count: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.apidocs .index-item { white-space: nowrap; }
|
||||||
|
|
||||||
|
.apidocs .index-item .flag {
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
color: #afafaf;
|
||||||
|
display: inline;
|
||||||
|
margin: 0 0 0 0.2em;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -- Generic API item styles ----------------------------------------------- */
|
||||||
|
.apidocs .args {
|
||||||
|
display: inline;
|
||||||
|
margin: 0 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.apidocs .flag.chainable { background: #46ca3b; }
|
||||||
|
.apidocs .flag.protected { background: #9b86fc; }
|
||||||
|
.apidocs .flag.private { background: #fd6b1b; }
|
||||||
|
.apidocs .flag.async { background: #356de4; }
|
||||||
|
.apidocs .flag.required { background: #e60923; }
|
||||||
|
|
||||||
|
.apidocs .item {
|
||||||
|
border-bottom: 1px solid #efefef;
|
||||||
|
margin: 1.5em 0 2em;
|
||||||
|
padding-bottom: 2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.apidocs .item h4,
|
||||||
|
.apidocs .item h5,
|
||||||
|
.apidocs .item h6 {
|
||||||
|
color: #333;
|
||||||
|
font-family: inherit;
|
||||||
|
font-size: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.apidocs .item .description p,
|
||||||
|
.apidocs .item pre.code {
|
||||||
|
margin: 1em 0 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.apidocs .item .meta {
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.apidocs .item .name {
|
||||||
|
display: inline;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.apidocs .item .type,
|
||||||
|
.apidocs .item .type a,
|
||||||
|
.apidocs .returns-inline {
|
||||||
|
color: #555;
|
||||||
|
}
|
||||||
|
|
||||||
|
.apidocs .item .type,
|
||||||
|
.apidocs .returns-inline {
|
||||||
|
font-size: 11px;
|
||||||
|
margin: 0 0 0 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.apidocs .item .type a { border-bottom: 1px dotted #afafaf; }
|
||||||
|
.apidocs .item .type a:hover { border: none; }
|
||||||
|
|
||||||
|
/* -- Item Parameter List --------------------------------------------------- */
|
||||||
|
.apidocs .params-list {
|
||||||
|
list-style: square;
|
||||||
|
margin: 1em 0 0 2em;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.apidocs .param { margin-bottom: 1em; }
|
||||||
|
|
||||||
|
.apidocs .param .type,
|
||||||
|
.apidocs .param .type a {
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
|
.apidocs .param .type {
|
||||||
|
margin: 0 0 0 0.5em;
|
||||||
|
*margin-left: 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.apidocs .param-name { font-weight: bold; }
|
||||||
|
|
||||||
|
/* -- Item "Emits" block ---------------------------------------------------- */
|
||||||
|
.apidocs .item .emits {
|
||||||
|
background: #f9f9f9;
|
||||||
|
border-color: #eaeaea;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -- Item "Returns" block -------------------------------------------------- */
|
||||||
|
.apidocs .item .returns .type,
|
||||||
|
.apidocs .item .returns .type a {
|
||||||
|
font-size: 100%;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -- Class Constructor block ----------------------------------------------- */
|
||||||
|
.apidocs .constructor .item {
|
||||||
|
border: none;
|
||||||
|
padding-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -- File Source View ------------------------------------------------------ */
|
||||||
|
.apidocs .file pre.code,
|
||||||
|
#doc .apidocs .file pre.prettyprint {
|
||||||
|
background: inherit;
|
||||||
|
border: none;
|
||||||
|
overflow: visible;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.apidocs .L0,
|
||||||
|
.apidocs .L1,
|
||||||
|
.apidocs .L2,
|
||||||
|
.apidocs .L3,
|
||||||
|
.apidocs .L4,
|
||||||
|
.apidocs .L5,
|
||||||
|
.apidocs .L6,
|
||||||
|
.apidocs .L7,
|
||||||
|
.apidocs .L8,
|
||||||
|
.apidocs .L9 {
|
||||||
|
background: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -- Submodule List -------------------------------------------------------- */
|
||||||
|
.apidocs .module-submodule-description {
|
||||||
|
font-size: 12px;
|
||||||
|
margin: 0.3em 0 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.apidocs .module-submodule-description p:first-child { margin-top: 0; }
|
||||||
|
|
||||||
|
/* -- Sidebar TabView ------------------------------------------------------- */
|
||||||
|
#api-tabview { margin-top: 0.6em; }
|
||||||
|
|
||||||
|
#api-tabview-filter,
|
||||||
|
#api-tabview-panel {
|
||||||
|
border: 1px solid #dfdfdf;
|
||||||
|
}
|
||||||
|
|
||||||
|
#api-tabview-filter {
|
||||||
|
border-bottom: none;
|
||||||
|
border-top: none;
|
||||||
|
padding: 0.6em 10px 0 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#api-tabview-panel { border-top: none; }
|
||||||
|
#api-filter { width: 97%; }
|
||||||
|
|
||||||
|
/* -- Content TabView ------------------------------------------------------- */
|
||||||
|
#classdocs .yui3-tabview-panel { border: none; }
|
||||||
|
|
||||||
|
/* -- Source File Contents -------------------------------------------------- */
|
||||||
|
.prettyprint li.L0,
|
||||||
|
.prettyprint li.L1,
|
||||||
|
.prettyprint li.L2,
|
||||||
|
.prettyprint li.L3,
|
||||||
|
.prettyprint li.L5,
|
||||||
|
.prettyprint li.L6,
|
||||||
|
.prettyprint li.L7,
|
||||||
|
.prettyprint li.L8 {
|
||||||
|
list-style: decimal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -- API options ----------------------------------------------------------- */
|
||||||
|
#api-options {
|
||||||
|
font-size: 11px;
|
||||||
|
margin-top: 2.2em;
|
||||||
|
position: absolute;
|
||||||
|
right: 1.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*#api-options label { margin-right: 0.6em; }*/
|
||||||
|
|
||||||
|
/* -- API list -------------------------------------------------------------- */
|
||||||
|
#api-list {
|
||||||
|
margin-top: 1.5em;
|
||||||
|
*zoom: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.apis {
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.4;
|
||||||
|
list-style: none;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0.5em 0 0.5em 0.4em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.apis a {
|
||||||
|
border: 1px solid transparent;
|
||||||
|
display: block;
|
||||||
|
margin: 0 0 0 -4px;
|
||||||
|
padding: 1px 4px 0;
|
||||||
|
text-decoration: none;
|
||||||
|
_border: none;
|
||||||
|
_display: inline;
|
||||||
|
}
|
||||||
|
|
||||||
|
.apis a:hover,
|
||||||
|
.apis a:focus {
|
||||||
|
background: #E8EDFC;
|
||||||
|
background: -moz-linear-gradient(top, #e8edfc 0%, #becef7 100%);
|
||||||
|
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#E8EDFC), color-stop(100%,#BECEF7));
|
||||||
|
border-color: #AAC0FA;
|
||||||
|
border-radius: 3px;
|
||||||
|
color: #333;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.api-list-item a:hover,
|
||||||
|
.api-list-item a:focus {
|
||||||
|
font-weight: bold;
|
||||||
|
text-shadow: 1px 1px 1px #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.apis .message { color: #888; }
|
||||||
|
.apis .result a { padding: 3px 5px 2px; }
|
||||||
|
|
||||||
|
.apis .result .type {
|
||||||
|
right: 4px;
|
||||||
|
top: 7px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.api-list-item .yui3-highlight {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
After Width: | Height: | Size: 740 B |
|
After Width: | Height: | Size: 2.6 KiB |
@@ -0,0 +1,10 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Redirector</title>
|
||||||
|
<meta http-equiv="refresh" content="0;url=../">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<a href="../">Click here to redirect</a>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
YUI.add('api-filter', function (Y) {
|
||||||
|
|
||||||
|
Y.APIFilter = Y.Base.create('apiFilter', Y.Base, [Y.AutoCompleteBase], {
|
||||||
|
// -- Initializer ----------------------------------------------------------
|
||||||
|
initializer: function () {
|
||||||
|
this._bindUIACBase();
|
||||||
|
this._syncUIACBase();
|
||||||
|
},
|
||||||
|
getDisplayName: function(name) {
|
||||||
|
|
||||||
|
Y.each(Y.YUIDoc.meta.allModules, function(i) {
|
||||||
|
if (i.name === name && i.displayName) {
|
||||||
|
name = i.displayName;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
}, {
|
||||||
|
// -- Attributes -----------------------------------------------------------
|
||||||
|
ATTRS: {
|
||||||
|
resultHighlighter: {
|
||||||
|
value: 'phraseMatch'
|
||||||
|
},
|
||||||
|
|
||||||
|
// May be set to "classes" or "modules".
|
||||||
|
queryType: {
|
||||||
|
value: 'classes'
|
||||||
|
},
|
||||||
|
|
||||||
|
source: {
|
||||||
|
valueFn: function() {
|
||||||
|
var self = this;
|
||||||
|
return function(q) {
|
||||||
|
var data = Y.YUIDoc.meta[self.get('queryType')],
|
||||||
|
out = [];
|
||||||
|
Y.each(data, function(v) {
|
||||||
|
if (v.toLowerCase().indexOf(q.toLowerCase()) > -1) {
|
||||||
|
out.push(v);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return out;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}, '3.4.0', {requires: [
|
||||||
|
'autocomplete-base', 'autocomplete-highlighters', 'autocomplete-sources'
|
||||||
|
]});
|
||||||
@@ -0,0 +1,251 @@
|
|||||||
|
YUI.add('api-list', function (Y) {
|
||||||
|
|
||||||
|
var Lang = Y.Lang,
|
||||||
|
YArray = Y.Array,
|
||||||
|
|
||||||
|
APIList = Y.namespace('APIList'),
|
||||||
|
|
||||||
|
classesNode = Y.one('#api-classes'),
|
||||||
|
inputNode = Y.one('#api-filter'),
|
||||||
|
modulesNode = Y.one('#api-modules'),
|
||||||
|
tabviewNode = Y.one('#api-tabview'),
|
||||||
|
|
||||||
|
tabs = APIList.tabs = {},
|
||||||
|
|
||||||
|
filter = APIList.filter = new Y.APIFilter({
|
||||||
|
inputNode : inputNode,
|
||||||
|
maxResults: 1000,
|
||||||
|
|
||||||
|
on: {
|
||||||
|
results: onFilterResults
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
search = APIList.search = new Y.APISearch({
|
||||||
|
inputNode : inputNode,
|
||||||
|
maxResults: 100,
|
||||||
|
|
||||||
|
on: {
|
||||||
|
clear : onSearchClear,
|
||||||
|
results: onSearchResults
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
tabview = APIList.tabview = new Y.TabView({
|
||||||
|
srcNode : tabviewNode,
|
||||||
|
panelNode: '#api-tabview-panel',
|
||||||
|
render : true,
|
||||||
|
|
||||||
|
on: {
|
||||||
|
selectionChange: onTabSelectionChange
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
focusManager = APIList.focusManager = tabviewNode.plug(Y.Plugin.NodeFocusManager, {
|
||||||
|
circular : true,
|
||||||
|
descendants: '#api-filter, .yui3-tab-panel-selected .api-list-item a, .yui3-tab-panel-selected .result a',
|
||||||
|
keys : {next: 'down:40', previous: 'down:38'}
|
||||||
|
}).focusManager,
|
||||||
|
|
||||||
|
LIST_ITEM_TEMPLATE =
|
||||||
|
'<li class="api-list-item {typeSingular}">' +
|
||||||
|
'<a href="{rootPath}{typePlural}/{name}.html">{displayName}</a>' +
|
||||||
|
'</li>';
|
||||||
|
|
||||||
|
// -- Init ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Duckpunch FocusManager's key event handling to prevent it from handling key
|
||||||
|
// events when a modifier is pressed.
|
||||||
|
Y.before(function (e, activeDescendant) {
|
||||||
|
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) {
|
||||||
|
return new Y.Do.Prevent();
|
||||||
|
}
|
||||||
|
}, focusManager, '_focusPrevious', focusManager);
|
||||||
|
|
||||||
|
Y.before(function (e, activeDescendant) {
|
||||||
|
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) {
|
||||||
|
return new Y.Do.Prevent();
|
||||||
|
}
|
||||||
|
}, focusManager, '_focusNext', focusManager);
|
||||||
|
|
||||||
|
// Create a mapping of tabs in the tabview so we can refer to them easily later.
|
||||||
|
tabview.each(function (tab, index) {
|
||||||
|
var name = tab.get('label').toLowerCase();
|
||||||
|
|
||||||
|
tabs[name] = {
|
||||||
|
index: index,
|
||||||
|
name : name,
|
||||||
|
tab : tab
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// Switch tabs on Ctrl/Cmd-Left/Right arrows.
|
||||||
|
tabviewNode.on('key', onTabSwitchKey, 'down:37,39');
|
||||||
|
|
||||||
|
// Focus the filter input when the `/` key is pressed.
|
||||||
|
Y.one(Y.config.doc).on('key', onSearchKey, 'down:83');
|
||||||
|
|
||||||
|
// Keep the Focus Manager up to date.
|
||||||
|
inputNode.on('focus', function () {
|
||||||
|
focusManager.set('activeDescendant', inputNode);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Update all tabview links to resolved URLs.
|
||||||
|
tabview.get('panelNode').all('a').each(function (link) {
|
||||||
|
link.setAttribute('href', link.get('href'));
|
||||||
|
});
|
||||||
|
|
||||||
|
// -- Private Functions --------------------------------------------------------
|
||||||
|
function getFilterResultNode() {
|
||||||
|
return filter.get('queryType') === 'classes' ? classesNode : modulesNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -- Event Handlers -----------------------------------------------------------
|
||||||
|
function onFilterResults(e) {
|
||||||
|
var frag = Y.one(Y.config.doc.createDocumentFragment()),
|
||||||
|
resultNode = getFilterResultNode(),
|
||||||
|
typePlural = filter.get('queryType'),
|
||||||
|
typeSingular = typePlural === 'classes' ? 'class' : 'module';
|
||||||
|
|
||||||
|
if (e.results.length) {
|
||||||
|
YArray.each(e.results, function (result) {
|
||||||
|
frag.append(Lang.sub(LIST_ITEM_TEMPLATE, {
|
||||||
|
rootPath : APIList.rootPath,
|
||||||
|
displayName : filter.getDisplayName(result.highlighted),
|
||||||
|
name : result.text,
|
||||||
|
typePlural : typePlural,
|
||||||
|
typeSingular: typeSingular
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
frag.append(
|
||||||
|
'<li class="message">' +
|
||||||
|
'No ' + typePlural + ' found.' +
|
||||||
|
'</li>'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
resultNode.empty(true);
|
||||||
|
resultNode.append(frag);
|
||||||
|
|
||||||
|
focusManager.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
function onSearchClear(e) {
|
||||||
|
|
||||||
|
focusManager.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
function onSearchKey(e) {
|
||||||
|
var target = e.target;
|
||||||
|
|
||||||
|
if (target.test('input,select,textarea')
|
||||||
|
|| target.get('isContentEditable')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
inputNode.focus();
|
||||||
|
focusManager.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
function onSearchResults(e) {
|
||||||
|
var frag = Y.one(Y.config.doc.createDocumentFragment());
|
||||||
|
|
||||||
|
if (e.results.length) {
|
||||||
|
YArray.each(e.results, function (result) {
|
||||||
|
frag.append(result.display);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
frag.append(
|
||||||
|
'<li class="message">' +
|
||||||
|
'No results found. Maybe you\'ll have better luck with a ' +
|
||||||
|
'different query?' +
|
||||||
|
'</li>'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
focusManager.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
function onTabSelectionChange(e) {
|
||||||
|
var tab = e.newVal,
|
||||||
|
name = tab.get('label').toLowerCase();
|
||||||
|
|
||||||
|
tabs.selected = {
|
||||||
|
index: tab.get('index'),
|
||||||
|
name : name,
|
||||||
|
tab : tab
|
||||||
|
};
|
||||||
|
|
||||||
|
switch (name) {
|
||||||
|
case 'classes': // fallthru
|
||||||
|
case 'modules':
|
||||||
|
filter.setAttrs({
|
||||||
|
minQueryLength: 0,
|
||||||
|
queryType : name
|
||||||
|
});
|
||||||
|
|
||||||
|
search.set('minQueryLength', -1);
|
||||||
|
|
||||||
|
// Only send a request if this isn't the initially-selected tab.
|
||||||
|
if (e.prevVal) {
|
||||||
|
filter.sendRequest(filter.get('value'));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'everything':
|
||||||
|
filter.set('minQueryLength', -1);
|
||||||
|
search.set('minQueryLength', 1);
|
||||||
|
|
||||||
|
if (search.get('value')) {
|
||||||
|
search.sendRequest(search.get('value'));
|
||||||
|
} else {
|
||||||
|
inputNode.focus();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// WTF? We shouldn't be here!
|
||||||
|
filter.set('minQueryLength', -1);
|
||||||
|
search.set('minQueryLength', -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (focusManager) {
|
||||||
|
setTimeout(function () {
|
||||||
|
focusManager.refresh();
|
||||||
|
}, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onTabSwitchKey(e) {
|
||||||
|
var currentTabIndex = tabs.selected.index;
|
||||||
|
|
||||||
|
if (!(e.ctrlKey || e.metaKey)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
switch (e.keyCode) {
|
||||||
|
case 37: // left arrow
|
||||||
|
if (currentTabIndex > 0) {
|
||||||
|
tabview.selectChild(currentTabIndex - 1);
|
||||||
|
inputNode.focus();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 39: // right arrow
|
||||||
|
if (currentTabIndex < (Y.Object.size(tabs) - 2)) {
|
||||||
|
tabview.selectChild(currentTabIndex + 1);
|
||||||
|
inputNode.focus();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}, '3.4.0', {requires: [
|
||||||
|
'api-filter', 'api-search', 'event-key', 'node-focusmanager', 'tabview'
|
||||||
|
]});
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
YUI.add('api-search', function (Y) {
|
||||||
|
|
||||||
|
var Lang = Y.Lang,
|
||||||
|
Node = Y.Node,
|
||||||
|
YArray = Y.Array;
|
||||||
|
|
||||||
|
Y.APISearch = Y.Base.create('apiSearch', Y.Base, [Y.AutoCompleteBase], {
|
||||||
|
// -- Public Properties ----------------------------------------------------
|
||||||
|
RESULT_TEMPLATE:
|
||||||
|
'<li class="result {resultType}">' +
|
||||||
|
'<a href="{url}">' +
|
||||||
|
'<h3 class="title">{name}</h3>' +
|
||||||
|
'<span class="type">{resultType}</span>' +
|
||||||
|
'<div class="description">{description}</div>' +
|
||||||
|
'<span class="className">{class}</span>' +
|
||||||
|
'</a>' +
|
||||||
|
'</li>',
|
||||||
|
|
||||||
|
// -- Initializer ----------------------------------------------------------
|
||||||
|
initializer: function () {
|
||||||
|
this._bindUIACBase();
|
||||||
|
this._syncUIACBase();
|
||||||
|
},
|
||||||
|
|
||||||
|
// -- Protected Methods ----------------------------------------------------
|
||||||
|
_apiResultFilter: function (query, results) {
|
||||||
|
// Filter components out of the results.
|
||||||
|
return YArray.filter(results, function (result) {
|
||||||
|
return result.raw.resultType === 'component' ? false : result;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
_apiResultFormatter: function (query, results) {
|
||||||
|
return YArray.map(results, function (result) {
|
||||||
|
var raw = Y.merge(result.raw), // create a copy
|
||||||
|
desc = raw.description || '';
|
||||||
|
|
||||||
|
// Convert description to text and truncate it if necessary.
|
||||||
|
desc = Node.create('<div>' + desc + '</div>').get('text');
|
||||||
|
|
||||||
|
if (desc.length > 65) {
|
||||||
|
desc = Y.Escape.html(desc.substr(0, 65)) + ' …';
|
||||||
|
} else {
|
||||||
|
desc = Y.Escape.html(desc);
|
||||||
|
}
|
||||||
|
|
||||||
|
raw['class'] || (raw['class'] = '');
|
||||||
|
raw.description = desc;
|
||||||
|
|
||||||
|
// Use the highlighted result name.
|
||||||
|
raw.name = result.highlighted;
|
||||||
|
|
||||||
|
return Lang.sub(this.RESULT_TEMPLATE, raw);
|
||||||
|
}, this);
|
||||||
|
},
|
||||||
|
|
||||||
|
_apiTextLocator: function (result) {
|
||||||
|
return result.displayName || result.name;
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
// -- Attributes -----------------------------------------------------------
|
||||||
|
ATTRS: {
|
||||||
|
resultFormatter: {
|
||||||
|
valueFn: function () {
|
||||||
|
return this._apiResultFormatter;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
resultFilters: {
|
||||||
|
valueFn: function () {
|
||||||
|
return this._apiResultFilter;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
resultHighlighter: {
|
||||||
|
value: 'phraseMatch'
|
||||||
|
},
|
||||||
|
|
||||||
|
resultListLocator: {
|
||||||
|
value: 'data.results'
|
||||||
|
},
|
||||||
|
|
||||||
|
resultTextLocator: {
|
||||||
|
valueFn: function () {
|
||||||
|
return this._apiTextLocator;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
source: {
|
||||||
|
value: '/api/v1/search?q={query}&count={maxResults}'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}, '3.4.0', {requires: [
|
||||||
|
'autocomplete-base', 'autocomplete-highlighters', 'autocomplete-sources',
|
||||||
|
'escape'
|
||||||
|
]});
|
||||||
@@ -0,0 +1,370 @@
|
|||||||
|
YUI().use(
|
||||||
|
'yuidoc-meta',
|
||||||
|
'api-list', 'history-hash', 'node-screen', 'node-style', 'pjax',
|
||||||
|
function (Y) {
|
||||||
|
|
||||||
|
var win = Y.config.win,
|
||||||
|
localStorage = win.localStorage,
|
||||||
|
|
||||||
|
bdNode = Y.one('#bd'),
|
||||||
|
|
||||||
|
pjax,
|
||||||
|
defaultRoute,
|
||||||
|
|
||||||
|
classTabView,
|
||||||
|
selectedTab;
|
||||||
|
|
||||||
|
// Kill pjax functionality unless serving over HTTP.
|
||||||
|
if (!Y.getLocation().protocol.match(/^https?\:/)) {
|
||||||
|
Y.Router.html5 = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the default route with middleware which enables syntax highlighting
|
||||||
|
// on the loaded content.
|
||||||
|
defaultRoute = Y.Pjax.defaultRoute.concat(function (req, res, next) {
|
||||||
|
prettyPrint();
|
||||||
|
bdNode.removeClass('loading');
|
||||||
|
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
|
pjax = new Y.Pjax({
|
||||||
|
container : '#docs-main',
|
||||||
|
contentSelector: '#docs-main > .content',
|
||||||
|
linkSelector : '#bd a',
|
||||||
|
titleSelector : '#xhr-title',
|
||||||
|
|
||||||
|
navigateOnHash: true,
|
||||||
|
root : '/',
|
||||||
|
routes : [
|
||||||
|
// -- / ----------------------------------------------------------------
|
||||||
|
{
|
||||||
|
path : '/(index.html)?',
|
||||||
|
callbacks: defaultRoute
|
||||||
|
},
|
||||||
|
|
||||||
|
// -- /classes/* -------------------------------------------------------
|
||||||
|
{
|
||||||
|
path : '/classes/:class.html*',
|
||||||
|
callbacks: [defaultRoute, 'handleClasses']
|
||||||
|
},
|
||||||
|
|
||||||
|
// -- /files/* ---------------------------------------------------------
|
||||||
|
{
|
||||||
|
path : '/files/*file',
|
||||||
|
callbacks: [defaultRoute, 'handleFiles']
|
||||||
|
},
|
||||||
|
|
||||||
|
// -- /modules/* -------------------------------------------------------
|
||||||
|
{
|
||||||
|
path : '/modules/:module.html*',
|
||||||
|
callbacks: defaultRoute
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
// -- Utility Functions --------------------------------------------------------
|
||||||
|
|
||||||
|
pjax.checkVisibility = function (tab) {
|
||||||
|
tab || (tab = selectedTab);
|
||||||
|
|
||||||
|
if (!tab) { return; }
|
||||||
|
|
||||||
|
var panelNode = tab.get('panelNode'),
|
||||||
|
visibleItems;
|
||||||
|
|
||||||
|
// If no items are visible in the tab panel due to the current visibility
|
||||||
|
// settings, display a message to that effect.
|
||||||
|
visibleItems = panelNode.all('.item,.index-item').some(function (itemNode) {
|
||||||
|
if (itemNode.getComputedStyle('display') !== 'none') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
panelNode.all('.no-visible-items').remove();
|
||||||
|
|
||||||
|
if (!visibleItems) {
|
||||||
|
if (Y.one('#index .index-item')) {
|
||||||
|
panelNode.append(
|
||||||
|
'<div class="no-visible-items">' +
|
||||||
|
'<p>' +
|
||||||
|
'Some items are not shown due to the current visibility ' +
|
||||||
|
'settings. Use the checkboxes at the upper right of this ' +
|
||||||
|
'page to change the visibility settings.' +
|
||||||
|
'</p>' +
|
||||||
|
'</div>'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
panelNode.append(
|
||||||
|
'<div class="no-visible-items">' +
|
||||||
|
'<p>' +
|
||||||
|
'This class doesn\'t provide any methods, properties, ' +
|
||||||
|
'attributes, or events.' +
|
||||||
|
'</p>' +
|
||||||
|
'</div>'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hide index sections without any visible items.
|
||||||
|
Y.all('.index-section').each(function (section) {
|
||||||
|
var items = 0,
|
||||||
|
visibleItems = 0;
|
||||||
|
|
||||||
|
section.all('.index-item').each(function (itemNode) {
|
||||||
|
items += 1;
|
||||||
|
|
||||||
|
if (itemNode.getComputedStyle('display') !== 'none') {
|
||||||
|
visibleItems += 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
section.toggleClass('hidden', !visibleItems);
|
||||||
|
section.toggleClass('no-columns', visibleItems < 4);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
pjax.initClassTabView = function () {
|
||||||
|
if (!Y.all('#classdocs .api-class-tab').size()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (classTabView) {
|
||||||
|
classTabView.destroy();
|
||||||
|
selectedTab = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
classTabView = new Y.TabView({
|
||||||
|
srcNode: '#classdocs',
|
||||||
|
|
||||||
|
on: {
|
||||||
|
selectionChange: pjax.onTabSelectionChange
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
pjax.updateTabState();
|
||||||
|
classTabView.render();
|
||||||
|
};
|
||||||
|
|
||||||
|
pjax.initLineNumbers = function () {
|
||||||
|
var hash = win.location.hash.substring(1),
|
||||||
|
container = pjax.get('container'),
|
||||||
|
hasLines, node;
|
||||||
|
|
||||||
|
// Add ids for each line number in the file source view.
|
||||||
|
container.all('.linenums>li').each(function (lineNode, index) {
|
||||||
|
lineNode.set('id', 'l' + (index + 1));
|
||||||
|
lineNode.addClass('file-line');
|
||||||
|
hasLines = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Scroll to the desired line.
|
||||||
|
if (hasLines && /^l\d+$/.test(hash)) {
|
||||||
|
if ((node = container.getById(hash))) {
|
||||||
|
win.scroll(0, node.getY());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
pjax.initRoot = function () {
|
||||||
|
var terminators = /^(?:classes|files|modules)$/,
|
||||||
|
parts = pjax._getPathRoot().split('/'),
|
||||||
|
root = [],
|
||||||
|
i, len, part;
|
||||||
|
|
||||||
|
for (i = 0, len = parts.length; i < len; i += 1) {
|
||||||
|
part = parts[i];
|
||||||
|
|
||||||
|
if (part.match(terminators)) {
|
||||||
|
// Makes sure the path will end with a "/".
|
||||||
|
root.push('');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
root.push(part);
|
||||||
|
}
|
||||||
|
|
||||||
|
pjax.set('root', root.join('/'));
|
||||||
|
};
|
||||||
|
|
||||||
|
pjax.updateTabState = function (src) {
|
||||||
|
var hash = win.location.hash.substring(1),
|
||||||
|
defaultTab, node, tab, tabPanel;
|
||||||
|
|
||||||
|
function scrollToNode() {
|
||||||
|
if (node.hasClass('protected')) {
|
||||||
|
Y.one('#api-show-protected').set('checked', true);
|
||||||
|
pjax.updateVisibility();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.hasClass('private')) {
|
||||||
|
Y.one('#api-show-private').set('checked', true);
|
||||||
|
pjax.updateVisibility();
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
// For some reason, unless we re-get the node instance here,
|
||||||
|
// getY() always returns 0.
|
||||||
|
var node = Y.one('#classdocs').getById(hash);
|
||||||
|
win.scrollTo(0, node.getY() - 70);
|
||||||
|
}, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!classTabView) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (src === 'hashchange' && !hash) {
|
||||||
|
defaultTab = 'index';
|
||||||
|
} else {
|
||||||
|
if (localStorage) {
|
||||||
|
defaultTab = localStorage.getItem('tab_' + pjax.getPath()) ||
|
||||||
|
'index';
|
||||||
|
} else {
|
||||||
|
defaultTab = 'index';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hash && (node = Y.one('#classdocs').getById(hash))) {
|
||||||
|
if ((tabPanel = node.ancestor('.api-class-tabpanel', true))) {
|
||||||
|
if ((tab = Y.one('#classdocs .api-class-tab.' + tabPanel.get('id')))) {
|
||||||
|
if (classTabView.get('rendered')) {
|
||||||
|
Y.Widget.getByNode(tab).set('selected', 1);
|
||||||
|
} else {
|
||||||
|
tab.addClass('yui3-tab-selected');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scroll to the desired element if this is a hash URL.
|
||||||
|
if (node) {
|
||||||
|
if (classTabView.get('rendered')) {
|
||||||
|
scrollToNode();
|
||||||
|
} else {
|
||||||
|
classTabView.once('renderedChange', scrollToNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tab = Y.one('#classdocs .api-class-tab.' + defaultTab);
|
||||||
|
|
||||||
|
// When the `defaultTab` node isn't found, `localStorage` is stale.
|
||||||
|
if (!tab && defaultTab !== 'index') {
|
||||||
|
tab = Y.one('#classdocs .api-class-tab.index');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (classTabView.get('rendered')) {
|
||||||
|
Y.Widget.getByNode(tab).set('selected', 1);
|
||||||
|
} else {
|
||||||
|
tab.addClass('yui3-tab-selected');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
pjax.updateVisibility = function () {
|
||||||
|
var container = pjax.get('container');
|
||||||
|
|
||||||
|
container.toggleClass('hide-inherited',
|
||||||
|
!Y.one('#api-show-inherited').get('checked'));
|
||||||
|
|
||||||
|
container.toggleClass('show-deprecated',
|
||||||
|
Y.one('#api-show-deprecated').get('checked'));
|
||||||
|
|
||||||
|
container.toggleClass('show-protected',
|
||||||
|
Y.one('#api-show-protected').get('checked'));
|
||||||
|
|
||||||
|
container.toggleClass('show-private',
|
||||||
|
Y.one('#api-show-private').get('checked'));
|
||||||
|
|
||||||
|
pjax.checkVisibility();
|
||||||
|
};
|
||||||
|
|
||||||
|
// -- Route Handlers -----------------------------------------------------------
|
||||||
|
|
||||||
|
pjax.handleClasses = function (req, res, next) {
|
||||||
|
var status = res.ioResponse.status;
|
||||||
|
|
||||||
|
// Handles success and local filesystem XHRs.
|
||||||
|
if (!status || (status >= 200 && status < 300)) {
|
||||||
|
pjax.initClassTabView();
|
||||||
|
}
|
||||||
|
|
||||||
|
next();
|
||||||
|
};
|
||||||
|
|
||||||
|
pjax.handleFiles = function (req, res, next) {
|
||||||
|
var status = res.ioResponse.status;
|
||||||
|
|
||||||
|
// Handles success and local filesystem XHRs.
|
||||||
|
if (!status || (status >= 200 && status < 300)) {
|
||||||
|
pjax.initLineNumbers();
|
||||||
|
}
|
||||||
|
|
||||||
|
next();
|
||||||
|
};
|
||||||
|
|
||||||
|
// -- Event Handlers -----------------------------------------------------------
|
||||||
|
|
||||||
|
pjax.onNavigate = function (e) {
|
||||||
|
var hash = e.hash,
|
||||||
|
originTarget = e.originEvent && e.originEvent.target,
|
||||||
|
tab;
|
||||||
|
|
||||||
|
if (hash) {
|
||||||
|
tab = originTarget && originTarget.ancestor('.yui3-tab', true);
|
||||||
|
|
||||||
|
if (hash === win.location.hash) {
|
||||||
|
pjax.updateTabState('hashchange');
|
||||||
|
} else if (!tab) {
|
||||||
|
win.location.hash = hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only scroll to the top of the page when the URL doesn't have a hash.
|
||||||
|
this.set('scrollToTop', !e.url.match(/#.+$/));
|
||||||
|
|
||||||
|
bdNode.addClass('loading');
|
||||||
|
};
|
||||||
|
|
||||||
|
pjax.onOptionClick = function (e) {
|
||||||
|
pjax.updateVisibility();
|
||||||
|
};
|
||||||
|
|
||||||
|
pjax.onTabSelectionChange = function (e) {
|
||||||
|
var tab = e.newVal,
|
||||||
|
tabId = tab.get('contentBox').getAttribute('href').substring(1);
|
||||||
|
|
||||||
|
selectedTab = tab;
|
||||||
|
|
||||||
|
// If switching from a previous tab (i.e., this is not the default tab),
|
||||||
|
// replace the history entry with a hash URL that will cause this tab to
|
||||||
|
// be selected if the user navigates away and then returns using the back
|
||||||
|
// or forward buttons.
|
||||||
|
if (e.prevVal && localStorage) {
|
||||||
|
localStorage.setItem('tab_' + pjax.getPath(), tabId);
|
||||||
|
}
|
||||||
|
|
||||||
|
pjax.checkVisibility(tab);
|
||||||
|
};
|
||||||
|
|
||||||
|
// -- Init ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
pjax.on('navigate', pjax.onNavigate);
|
||||||
|
|
||||||
|
pjax.initRoot();
|
||||||
|
pjax.upgrade();
|
||||||
|
pjax.initClassTabView();
|
||||||
|
pjax.initLineNumbers();
|
||||||
|
pjax.updateVisibility();
|
||||||
|
|
||||||
|
Y.APIList.rootPath = pjax.get('root');
|
||||||
|
|
||||||
|
Y.one('#api-options').delegate('click', pjax.onOptionClick, 'input');
|
||||||
|
|
||||||
|
Y.on('hashchange', function (e) {
|
||||||
|
pjax.updateTabState('hashchange');
|
||||||
|
}, win);
|
||||||
|
|
||||||
|
});
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
YUI().use('node', function(Y) {
|
||||||
|
var code = Y.all('.prettyprint.linenums');
|
||||||
|
if (code.size()) {
|
||||||
|
code.each(function(c) {
|
||||||
|
var lis = c.all('ol li'),
|
||||||
|
l = 1;
|
||||||
|
lis.each(function(n) {
|
||||||
|
n.prepend('<a name="LINENUM_' + l + '"></a>');
|
||||||
|
l++;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
var h = location.hash;
|
||||||
|
location.hash = '';
|
||||||
|
h = h.replace('LINE_', 'LINENUM_');
|
||||||
|
location.hash = h;
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -0,0 +1,130 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||||
|
<title>Change Log</title>
|
||||||
|
</head>
|
||||||
|
<body bgcolor="white">
|
||||||
|
<a style="float:right" href="README.html">README</a>
|
||||||
|
|
||||||
|
<h1>Known Issues</h1>
|
||||||
|
<ul>
|
||||||
|
<li>Perl formatting is really crappy. Partly because the author is lazy and
|
||||||
|
partly because Perl is
|
||||||
|
<a href="http://www.perlmonks.org/?node_id=663393">hard</a> to parse.
|
||||||
|
<li>On some browsers, <code><code></code> elements with newlines in the text
|
||||||
|
which use CSS to specify <code>white-space:pre</code> will have the newlines
|
||||||
|
improperly stripped if the element is not attached to the document at the time
|
||||||
|
the stripping is done. Also, on IE 6, all newlines will be stripped from
|
||||||
|
<code><code></code> elements because of the way IE6 produces
|
||||||
|
<code>innerHTML</code>. Workaround: use <code><pre></code> for code with
|
||||||
|
newlines.
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h1>Change Log</h1>
|
||||||
|
<h2>29 March 2007</h2>
|
||||||
|
<ul>
|
||||||
|
<li>Added <a href="tests/prettify_test.html#PHP">tests</a> for PHP support
|
||||||
|
to address
|
||||||
|
<a href="http://code.google.com/p/google-code-prettify/issues/detail?id=3"
|
||||||
|
>issue 3</a>.
|
||||||
|
<li>Fixed
|
||||||
|
<a href="http://code.google.com/p/google-code-prettify/issues/detail?id=6"
|
||||||
|
>bug</a>: <code>prettyPrintOne</code> was not halting. This was not
|
||||||
|
reachable through the normal entry point.
|
||||||
|
<li>Fixed
|
||||||
|
<a href="http://code.google.com/p/google-code-prettify/issues/detail?id=4"
|
||||||
|
>bug</a>: recursing into a script block or PHP tag that was not properly
|
||||||
|
closed would not silently drop the content.
|
||||||
|
(<a href="tests/prettify_test.html#issue4">test</a>)
|
||||||
|
<li>Fixed
|
||||||
|
<a href="http://code.google.com/p/google-code-prettify/issues/detail?id=8"
|
||||||
|
>bug</a>: was eating tabs
|
||||||
|
(<a href="tests/prettify_test.html#issue8">test</a>)
|
||||||
|
<li>Fixed entity handling so that the caveat
|
||||||
|
<blockquote>
|
||||||
|
<p>Caveats: please properly escape less-thans. <tt>x&lt;y</tt>
|
||||||
|
instead of <tt>x<y</tt>, and use <tt>"</tt> instead of
|
||||||
|
<tt>&quot;</tt> for string delimiters.</p>
|
||||||
|
</blockquote>
|
||||||
|
is no longer applicable.
|
||||||
|
<li>Added noisefree's C#
|
||||||
|
<a href="http://code.google.com/p/google-code-prettify/issues/detail?id=4"
|
||||||
|
>patch</a>
|
||||||
|
<li>Added a <a href="http://google-code-prettify.googlecode.com/files/prettify-small.zip">distribution</a> that has comments and
|
||||||
|
whitespace removed to reduce download size from 45.5kB to 12.8kB.
|
||||||
|
</ul>
|
||||||
|
<h2>4 Jul 2008</h2>
|
||||||
|
<ul>
|
||||||
|
<li>Added <a href="http://code.google.com/p/google-code-prettify/issues/detail?id=17">language specific formatters</a> that are triggered by the presence
|
||||||
|
of a <code>lang-<language-file-extension></code></li>
|
||||||
|
<li>Fixed <a href="http://code.google.com/p/google-code-prettify/issues/detail?id=29">bug</a>: python handling of <code>'''string'''</code>
|
||||||
|
<li>Fixed bug: <code>/</code> in regex <code>[charsets] should not end regex</code>
|
||||||
|
</ul>
|
||||||
|
<h2>5 Jul 2008</h2>
|
||||||
|
<ul>
|
||||||
|
<li>Defined language extensions for Lisp and Lua</code>
|
||||||
|
</ul>
|
||||||
|
<h2>14 Jul 2008</h2>
|
||||||
|
<ul>
|
||||||
|
<li>Language handlers for F#, OCAML, SQL</code>
|
||||||
|
<li>Support for <code>nocode</code> spans to allow embedding of line
|
||||||
|
numbers and code annotations which should not be styled or otherwise
|
||||||
|
affect the tokenization of prettified code.
|
||||||
|
See the issue 22
|
||||||
|
<a href="tests/prettify_test.html#issue22">testcase</a>.</code>
|
||||||
|
</ul>
|
||||||
|
<h2>6 Jan 2009</h2>
|
||||||
|
<ul>
|
||||||
|
<li>Language handlers for Visual Basic, Haskell, CSS, and WikiText</li>
|
||||||
|
<li>Added <tt>.mxml</tt> extension to the markup style handler for
|
||||||
|
Flex <a href="http://en.wikipedia.org/wiki/MXML">MXML files</a>. See
|
||||||
|
<a
|
||||||
|
href="http://code.google.com/p/google-code-prettify/issues/detail?id=37"
|
||||||
|
>issue 37</a>.
|
||||||
|
<li>Added <tt>.m</tt> extension to the C style handler so that Objective
|
||||||
|
C source files properly highlight. See
|
||||||
|
<a
|
||||||
|
href="http://code.google.com/p/google-code-prettify/issues/detail?id=58"
|
||||||
|
>issue 58</a>.
|
||||||
|
<li>Changed HTML lexer to use the same embedded source mechanism as the
|
||||||
|
wiki language handler, and changed to use the registered
|
||||||
|
CSS handler for STYLE element content.
|
||||||
|
</ul>
|
||||||
|
<h2>21 May 2009</h2>
|
||||||
|
<ul>
|
||||||
|
<li>Rewrote to improve performance on large files.
|
||||||
|
See <a href="http://mikesamuel.blogspot.com/2009/05/efficient-parsing-in-javascript.html">benchmarks</a>.</li>
|
||||||
|
<li>Fixed bugs with highlighting of Haskell line comments, Lisp
|
||||||
|
number literals, Lua strings, C preprocessor directives,
|
||||||
|
newlines in Wiki code on Windows, and newlines in IE6.</li>
|
||||||
|
</ul>
|
||||||
|
<h2>14 August 2009</h2>
|
||||||
|
<ul>
|
||||||
|
<li>Fixed prettifying of <code><code></code> blocks with embedded newlines.
|
||||||
|
</ul>
|
||||||
|
<h2>3 October 2009</h2>
|
||||||
|
<ul>
|
||||||
|
<li>Fixed prettifying of XML/HTML tags that contain uppercase letters.
|
||||||
|
</ul>
|
||||||
|
<h2>19 July 2010</h2>
|
||||||
|
<ul>
|
||||||
|
<li>Added support for line numbers. Bug
|
||||||
|
<a href="http://code.google.com/p/google-code-prettify/issues/detail?id=22"
|
||||||
|
>22</a></li>
|
||||||
|
<li>Added YAML support. Bug
|
||||||
|
<a href="http://code.google.com/p/google-code-prettify/issues/detail?id=123"
|
||||||
|
>123</a></li>
|
||||||
|
<li>Added VHDL support courtesy Le Poussin.</li>
|
||||||
|
<li>IE performance improvements. Bug
|
||||||
|
<a href="http://code.google.com/p/google-code-prettify/issues/detail?id=102"
|
||||||
|
>102</a> courtesy jacobly.</li>
|
||||||
|
<li>A variety of markup formatting fixes courtesy smain and thezbyg.</li>
|
||||||
|
<li>Fixed copy and paste in IE[678].
|
||||||
|
<li>Changed output to use <code>&#160;</code> instead of
|
||||||
|
<code>&nbsp;</code> so that the output works when embedded in XML.
|
||||||
|
Bug
|
||||||
|
<a href="http://code.google.com/p/google-code-prettify/issues/detail?id=108"
|
||||||
|
>108</a>.</li>
|
||||||
|
</ul>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,202 @@
|
|||||||
|
|
||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
@@ -0,0 +1,203 @@
|
|||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||||
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||||
|
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Javascript code prettifier</title>
|
||||||
|
|
||||||
|
<link href="src/prettify.css" type="text/css" rel="stylesheet" />
|
||||||
|
|
||||||
|
<script src="src/prettify.js" type="text/javascript"></script>
|
||||||
|
|
||||||
|
<style type="text/css">
|
||||||
|
body { margin-left: .5in }
|
||||||
|
h1, h2, h3, h4, .footer { margin-left: -.4in; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body onload="prettyPrint()" bgcolor="white">
|
||||||
|
<small style="float: right">Languages : <a href="README-zh-Hans.html">CH</a></small>
|
||||||
|
<h1>Javascript code prettifier</h1>
|
||||||
|
|
||||||
|
<h2>Setup</h2>
|
||||||
|
<ol>
|
||||||
|
<li><a href="http://code.google.com/p/google-code-prettify/downloads/list">Download</a> a distribution
|
||||||
|
<li>Include the script and stylesheets in your document
|
||||||
|
(you will need to make sure the css and js file are on your server, and
|
||||||
|
adjust the paths in the <tt>script</tt> and <tt>link</tt> tag)
|
||||||
|
<pre class="prettyprint">
|
||||||
|
<link href="prettify.css" type="text/css" rel="stylesheet" />
|
||||||
|
<script type="text/javascript" src="prettify.js"></script></pre>
|
||||||
|
<li>Add <code class="prettyprint lang-html">onload="prettyPrint()"</code> to your
|
||||||
|
document's body tag.
|
||||||
|
<li>Modify the stylesheet to get the coloring you prefer</li>
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
<h2>Usage</h2>
|
||||||
|
<p>Put code snippets in
|
||||||
|
<tt><pre class="prettyprint">...</pre></tt>
|
||||||
|
or <tt><code class="prettyprint">...</code></tt>
|
||||||
|
and it will automatically be pretty printed.
|
||||||
|
|
||||||
|
<table summary="code examples">
|
||||||
|
<tr>
|
||||||
|
<th>The original
|
||||||
|
<th>Prettier
|
||||||
|
<tr>
|
||||||
|
<td><pre style="border: 1px solid #888;padding: 2px"
|
||||||
|
><a name="voila1"></a>class Voila {
|
||||||
|
public:
|
||||||
|
// Voila
|
||||||
|
static const string VOILA = "Voila";
|
||||||
|
|
||||||
|
// will not interfere with embedded <a href="#voila1">tags</a>.
|
||||||
|
}</pre>
|
||||||
|
|
||||||
|
<td><pre class="prettyprint"><a name="voila2"></a>class Voila {
|
||||||
|
public:
|
||||||
|
// Voila
|
||||||
|
static const string VOILA = "Voila";
|
||||||
|
|
||||||
|
// will not interfere with embedded <a href="#voila2">tags</a>.
|
||||||
|
}</pre>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<h2>FAQ</h2>
|
||||||
|
<h3 id="langs">Which languages does it work for?</h3>
|
||||||
|
<p>The comments in <tt>prettify.js</tt> are authoritative but the lexer
|
||||||
|
should work on a number of languages including C and friends,
|
||||||
|
Java, Python, Bash, SQL, HTML, XML, CSS, Javascript, and Makefiles.
|
||||||
|
It works passably on Ruby, PHP, VB, and Awk and a decent subset of Perl
|
||||||
|
and Ruby, but, because of commenting conventions, doesn't work on
|
||||||
|
Smalltalk, or CAML-like languages.</p>
|
||||||
|
|
||||||
|
<p>LISPy languages are supported via an extension:
|
||||||
|
<a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-lisp.js"
|
||||||
|
><code>lang-lisp.js</code></a>.</p>
|
||||||
|
<p>And similarly for
|
||||||
|
<a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-css.js"
|
||||||
|
><code>CSS</code></a>,
|
||||||
|
<a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-hs.js"
|
||||||
|
><code>Haskell</code></a>,
|
||||||
|
<a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-lua.js"
|
||||||
|
><code>Lua</code></a>,
|
||||||
|
<a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-ml.js"
|
||||||
|
><code>OCAML, SML, F#</code></a>,
|
||||||
|
<a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-vb.js"
|
||||||
|
><code>Visual Basic</code></a>,
|
||||||
|
<a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-sql.js"
|
||||||
|
><code>SQL</code></a>,
|
||||||
|
<a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-proto.js"
|
||||||
|
><code>Protocol Buffers</code></a>, and
|
||||||
|
<a href="http://code.google.com/p/google-code-prettify/source/browse/trunk/src/lang-wiki.js"
|
||||||
|
><code>WikiText</code></a>..
|
||||||
|
|
||||||
|
<p>If you'd like to add an extension for your favorite language, please
|
||||||
|
look at <tt>src/lang-lisp.js</tt> and file an
|
||||||
|
<a href="http://code.google.com/p/google-code-prettify/issues/list"
|
||||||
|
>issue</a> including your language extension, and a testcase.</p>
|
||||||
|
|
||||||
|
<h3>How do I specify which language my code is in?</h3>
|
||||||
|
<p>You don't need to specify the language since <code>prettyprint()</code>
|
||||||
|
will guess. You can specify a language by specifying the language extension
|
||||||
|
along with the <code>prettyprint</code> class like so:</p>
|
||||||
|
<pre class="prettyprint lang-html"
|
||||||
|
><pre class="prettyprint <b>lang-html</b>">
|
||||||
|
The lang-* class specifies the language file extensions.
|
||||||
|
File extensions supported by default include
|
||||||
|
"bsh", "c", "cc", "cpp", "cs", "csh", "cyc", "cv", "htm", "html",
|
||||||
|
"java", "js", "m", "mxml", "perl", "pl", "pm", "py", "rb", "sh",
|
||||||
|
"xhtml", "xml", "xsl".
|
||||||
|
</pre></pre>
|
||||||
|
|
||||||
|
<h3>It doesn't work on <tt><obfuscated code sample></tt>?</h3>
|
||||||
|
<p>Yes. Prettifying obfuscated code is like putting lipstick on a pig
|
||||||
|
— i.e. outside the scope of this tool.</p>
|
||||||
|
|
||||||
|
<h3>Which browsers does it work with?</h3>
|
||||||
|
<p>It's been tested with IE 6, Firefox 1.5 & 2, and Safari 2.0.4.
|
||||||
|
Look at <a href="tests/prettify_test.html">the test page</a> to see if it
|
||||||
|
works in your browser.</p>
|
||||||
|
|
||||||
|
<h3>What's changed?</h3>
|
||||||
|
<p>See the <a href="CHANGES.html">change log</a></p>
|
||||||
|
|
||||||
|
<h3>Why doesn't Prettyprinting of strings work on WordPress?</h3>
|
||||||
|
<p>Apparently wordpress does "smart quoting" which changes close quotes.
|
||||||
|
This causes end quotes to not match up with open quotes.
|
||||||
|
<p>This breaks prettifying as well as copying and pasting of code samples.
|
||||||
|
See
|
||||||
|
<a href="http://wordpress.org/support/topic/125038"
|
||||||
|
>WordPress's help center</a> for info on how to stop smart quoting of code
|
||||||
|
snippets.</p>
|
||||||
|
|
||||||
|
<h3 id="linenums">How do I put line numbers in my code?</h3>
|
||||||
|
<p>You can use the <code>linenums</code> class to turn on line
|
||||||
|
numbering. If your code doesn't start at line number 1, you can
|
||||||
|
add a colon and a line number to the end of that class as in
|
||||||
|
<code>linenums:52</code>.
|
||||||
|
|
||||||
|
<p>For example
|
||||||
|
<pre class="prettyprint"><pre class="prettyprint linenums:<b>4</b>"
|
||||||
|
>// This is line 4.
|
||||||
|
foo();
|
||||||
|
bar();
|
||||||
|
baz();
|
||||||
|
boo();
|
||||||
|
far();
|
||||||
|
faz();
|
||||||
|
<pre></pre>
|
||||||
|
produces
|
||||||
|
<pre class="prettyprint linenums:4"
|
||||||
|
>// This is line 4.
|
||||||
|
foo();
|
||||||
|
bar();
|
||||||
|
baz();
|
||||||
|
boo();
|
||||||
|
far();
|
||||||
|
faz();
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<h3>How do I prevent a portion of markup from being marked as code?</h3>
|
||||||
|
<p>You can use the <code>nocode</code> class to identify a span of markup
|
||||||
|
that is not code.
|
||||||
|
<pre class="prettyprint"><pre class=prettyprint>
|
||||||
|
int x = foo(); /* This is a comment <span class="nocode">This is not code</span>
|
||||||
|
Continuation of comment */
|
||||||
|
int y = bar();
|
||||||
|
</pre></pre>
|
||||||
|
produces
|
||||||
|
<pre class="prettyprint">
|
||||||
|
int x = foo(); /* This is a comment <span class="nocode">This is not code</span>
|
||||||
|
Continuation of comment */
|
||||||
|
int y = bar();
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<p>For a more complete example see the issue22
|
||||||
|
<a href="tests/prettify_test.html#issue22">testcase</a>.</p>
|
||||||
|
|
||||||
|
<h3>I get an error message "a is not a function" or "opt_whenDone is not a function"</h3>
|
||||||
|
<p>If you are calling <code>prettyPrint</code> via an event handler, wrap it in a function.
|
||||||
|
Instead of doing
|
||||||
|
<blockquote>
|
||||||
|
<code class="prettyprint lang-js"
|
||||||
|
>addEventListener('load', prettyPrint, false);</code>
|
||||||
|
</blockquote>
|
||||||
|
wrap it in a closure like
|
||||||
|
<blockquote>
|
||||||
|
<code class="prettyprint lang-js"
|
||||||
|
>addEventListener('load', function (event) { prettyPrint() }, false);</code>
|
||||||
|
</blockquote>
|
||||||
|
so that the browser does not pass an event object to <code>prettyPrint</code> which
|
||||||
|
will confuse it.
|
||||||
|
|
||||||
|
<br><br><br>
|
||||||
|
|
||||||
|
<div class="footer">
|
||||||
|
<!-- Created: Tue Oct 3 17:51:56 PDT 2006 -->
|
||||||
|
<!-- hhmts start -->
|
||||||
|
Last modified: Wed Jul 19 13:56:00 PST 2010
|
||||||
|
<!-- hhmts end -->
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
.pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee}
|
||||||
@@ -0,0 +1,364 @@
|
|||||||
|
{
|
||||||
|
"project": {
|
||||||
|
"name": "Phaser",
|
||||||
|
"description": "HTML5 Game Framework",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"url": "http://www.phaser.io/"
|
||||||
|
},
|
||||||
|
"files": {
|
||||||
|
"..\\Phaser\\time\\TimeManager.ts": {
|
||||||
|
"name": "..\\Phaser\\time\\TimeManager.ts",
|
||||||
|
"modules": {
|
||||||
|
"Phaser": 1
|
||||||
|
},
|
||||||
|
"classes": {
|
||||||
|
"TimeManager": 1
|
||||||
|
},
|
||||||
|
"fors": {},
|
||||||
|
"namespaces": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"modules": {
|
||||||
|
"Phaser": {
|
||||||
|
"name": "Phaser",
|
||||||
|
"submodules": {},
|
||||||
|
"classes": {
|
||||||
|
"TimeManager": 1
|
||||||
|
},
|
||||||
|
"fors": {},
|
||||||
|
"namespaces": {},
|
||||||
|
"tag": "module",
|
||||||
|
"file": "..\\Phaser\\time\\TimeManager.ts",
|
||||||
|
"line": 13,
|
||||||
|
"author": "Richard Davey <rich@photonstorm.com>",
|
||||||
|
"copyright": "2013 Photon Storm Ltd.",
|
||||||
|
"license": "https://github.com/photonstorm/phaser/blob/master/license.txt MIT License"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"classes": {
|
||||||
|
"TimeManager": {
|
||||||
|
"name": "TimeManager",
|
||||||
|
"shortname": "TimeManager",
|
||||||
|
"classitems": [],
|
||||||
|
"plugins": [],
|
||||||
|
"extensions": [],
|
||||||
|
"plugin_for": [],
|
||||||
|
"extension_for": [],
|
||||||
|
"module": "Phaser",
|
||||||
|
"namespace": "",
|
||||||
|
"file": "..\\Phaser\\time\\TimeManager.ts",
|
||||||
|
"line": 13,
|
||||||
|
"description": "This is the core internal game clock. It manages the elapsed time and calculation of delta values,\nused for game object motion and tweens.",
|
||||||
|
"is_constructor": 1,
|
||||||
|
"params": [
|
||||||
|
{
|
||||||
|
"name": "game",
|
||||||
|
"description": "A reference to the currently running game.",
|
||||||
|
"type": "Phaser.Game"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"classitems": [
|
||||||
|
{
|
||||||
|
"file": "..\\Phaser\\time\\TimeManager.ts",
|
||||||
|
"line": 34,
|
||||||
|
"description": "A reference to the currently running Game.",
|
||||||
|
"itemtype": "property",
|
||||||
|
"name": "game",
|
||||||
|
"type": "{Phaser.Game}",
|
||||||
|
"class": "TimeManager",
|
||||||
|
"module": "Phaser"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "..\\Phaser\\time\\TimeManager.ts",
|
||||||
|
"line": 41,
|
||||||
|
"description": "The time at which the Game instance started.",
|
||||||
|
"itemtype": "property",
|
||||||
|
"name": "_started",
|
||||||
|
"access": "private",
|
||||||
|
"tagname": "",
|
||||||
|
"type": "{Number}",
|
||||||
|
"class": "TimeManager",
|
||||||
|
"module": "Phaser"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "..\\Phaser\\time\\TimeManager.ts",
|
||||||
|
"line": 49,
|
||||||
|
"description": "Number of milliseconds elapsed since the last frame update.",
|
||||||
|
"itemtype": "property",
|
||||||
|
"name": "elapsed",
|
||||||
|
"access": "public",
|
||||||
|
"tagname": "",
|
||||||
|
"type": "{Number}",
|
||||||
|
"class": "TimeManager",
|
||||||
|
"module": "Phaser"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "..\\Phaser\\time\\TimeManager.ts",
|
||||||
|
"line": 57,
|
||||||
|
"description": "Game time counter.",
|
||||||
|
"itemtype": "property",
|
||||||
|
"name": "time",
|
||||||
|
"access": "public",
|
||||||
|
"tagname": "",
|
||||||
|
"type": "{Number}",
|
||||||
|
"class": "TimeManager",
|
||||||
|
"module": "Phaser"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "..\\Phaser\\time\\TimeManager.ts",
|
||||||
|
"line": 65,
|
||||||
|
"description": "Records how long the game has been paused for. Is reset each time the game pauses.",
|
||||||
|
"itemtype": "property",
|
||||||
|
"name": "pausedTime",
|
||||||
|
"access": "public",
|
||||||
|
"tagname": "",
|
||||||
|
"type": "{Number}",
|
||||||
|
"class": "TimeManager",
|
||||||
|
"module": "Phaser"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "..\\Phaser\\time\\TimeManager.ts",
|
||||||
|
"line": 73,
|
||||||
|
"description": "The time right now.",
|
||||||
|
"itemtype": "property",
|
||||||
|
"name": "now",
|
||||||
|
"access": "public",
|
||||||
|
"tagname": "",
|
||||||
|
"type": "{Number}",
|
||||||
|
"class": "TimeManager",
|
||||||
|
"module": "Phaser"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "..\\Phaser\\time\\TimeManager.ts",
|
||||||
|
"line": 81,
|
||||||
|
"description": "Elapsed time since the last frame.",
|
||||||
|
"itemtype": "property",
|
||||||
|
"name": "delta",
|
||||||
|
"access": "public",
|
||||||
|
"tagname": "",
|
||||||
|
"type": "{Number}",
|
||||||
|
"class": "TimeManager",
|
||||||
|
"module": "Phaser"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "..\\Phaser\\time\\TimeManager.ts",
|
||||||
|
"line": 89,
|
||||||
|
"description": "The number of seconds that have elapsed since the game was started.",
|
||||||
|
"itemtype": "method",
|
||||||
|
"name": "totalElapsedSeconds",
|
||||||
|
"return": {
|
||||||
|
"description": "",
|
||||||
|
"type": "Number"
|
||||||
|
},
|
||||||
|
"class": "TimeManager",
|
||||||
|
"module": "Phaser"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "..\\Phaser\\time\\TimeManager.ts",
|
||||||
|
"line": 100,
|
||||||
|
"description": "Frames per second.",
|
||||||
|
"itemtype": "property",
|
||||||
|
"name": "fps",
|
||||||
|
"access": "public",
|
||||||
|
"tagname": "",
|
||||||
|
"type": "{Number}",
|
||||||
|
"class": "TimeManager",
|
||||||
|
"module": "Phaser"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "..\\Phaser\\time\\TimeManager.ts",
|
||||||
|
"line": 108,
|
||||||
|
"description": "The lowest rate the fps has dropped to.",
|
||||||
|
"itemtype": "property",
|
||||||
|
"name": "fpsMin",
|
||||||
|
"access": "public",
|
||||||
|
"tagname": "",
|
||||||
|
"type": "{Number}",
|
||||||
|
"class": "TimeManager",
|
||||||
|
"module": "Phaser"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "..\\Phaser\\time\\TimeManager.ts",
|
||||||
|
"line": 116,
|
||||||
|
"description": "The highest rate the fps has reached (usually no higher than 60fps).",
|
||||||
|
"itemtype": "property",
|
||||||
|
"name": "fpsMax",
|
||||||
|
"access": "public",
|
||||||
|
"tagname": "",
|
||||||
|
"type": "{Number}",
|
||||||
|
"class": "TimeManager",
|
||||||
|
"module": "Phaser"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "..\\Phaser\\time\\TimeManager.ts",
|
||||||
|
"line": 124,
|
||||||
|
"description": "The minimum amount of time the game has taken between two frames.",
|
||||||
|
"itemtype": "property",
|
||||||
|
"name": "msMin",
|
||||||
|
"access": "public",
|
||||||
|
"tagname": "",
|
||||||
|
"type": "{Number}",
|
||||||
|
"class": "TimeManager",
|
||||||
|
"module": "Phaser"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "..\\Phaser\\time\\TimeManager.ts",
|
||||||
|
"line": 132,
|
||||||
|
"description": "The maximum amount of time the game has taken between two frames.",
|
||||||
|
"itemtype": "property",
|
||||||
|
"name": "msMax",
|
||||||
|
"access": "public",
|
||||||
|
"tagname": "",
|
||||||
|
"type": "{Number}",
|
||||||
|
"class": "TimeManager",
|
||||||
|
"module": "Phaser"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "..\\Phaser\\time\\TimeManager.ts",
|
||||||
|
"line": 140,
|
||||||
|
"description": "The number of frames record in the last second.",
|
||||||
|
"itemtype": "property",
|
||||||
|
"name": "frames",
|
||||||
|
"access": "public",
|
||||||
|
"tagname": "",
|
||||||
|
"type": "{Number}",
|
||||||
|
"class": "TimeManager",
|
||||||
|
"module": "Phaser"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "..\\Phaser\\time\\TimeManager.ts",
|
||||||
|
"line": 148,
|
||||||
|
"description": "The time (in ms) that the last second counter ticked over.",
|
||||||
|
"itemtype": "property",
|
||||||
|
"name": "_timeLastSecond",
|
||||||
|
"access": "private",
|
||||||
|
"tagname": "",
|
||||||
|
"type": "{Number}",
|
||||||
|
"class": "TimeManager",
|
||||||
|
"module": "Phaser"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "..\\Phaser\\time\\TimeManager.ts",
|
||||||
|
"line": 156,
|
||||||
|
"description": "Update clock and calculate the fps.\nThis is called automatically by Game._raf",
|
||||||
|
"itemtype": "method",
|
||||||
|
"name": "update",
|
||||||
|
"params": [
|
||||||
|
{
|
||||||
|
"name": "raf",
|
||||||
|
"description": "The current timestamp, either performance.now or Date.now",
|
||||||
|
"type": "Number"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"class": "TimeManager",
|
||||||
|
"module": "Phaser"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "..\\Phaser\\time\\TimeManager.ts",
|
||||||
|
"line": 192,
|
||||||
|
"description": "Called when the game enters a paused state.",
|
||||||
|
"itemtype": "method",
|
||||||
|
"name": "gamePaused",
|
||||||
|
"access": "private",
|
||||||
|
"tagname": "",
|
||||||
|
"class": "TimeManager",
|
||||||
|
"module": "Phaser"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "..\\Phaser\\time\\TimeManager.ts",
|
||||||
|
"line": 201,
|
||||||
|
"description": "Called when the game resumes from a paused state.",
|
||||||
|
"itemtype": "method",
|
||||||
|
"name": "gameResumed",
|
||||||
|
"access": "private",
|
||||||
|
"tagname": "",
|
||||||
|
"class": "TimeManager",
|
||||||
|
"module": "Phaser"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "..\\Phaser\\time\\TimeManager.ts",
|
||||||
|
"line": 211,
|
||||||
|
"description": "Records how long the game was paused for in miliseconds.",
|
||||||
|
"itemtype": "property",
|
||||||
|
"name": "pauseDuration",
|
||||||
|
"access": "public",
|
||||||
|
"tagname": "",
|
||||||
|
"type": "{Number}",
|
||||||
|
"class": "TimeManager",
|
||||||
|
"module": "Phaser"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "..\\Phaser\\time\\TimeManager.ts",
|
||||||
|
"line": 219,
|
||||||
|
"description": "The time the game started being paused.",
|
||||||
|
"itemtype": "property",
|
||||||
|
"name": "_pauseStarted",
|
||||||
|
"access": "private",
|
||||||
|
"tagname": "",
|
||||||
|
"type": "{Number}",
|
||||||
|
"class": "TimeManager",
|
||||||
|
"module": "Phaser"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "..\\Phaser\\time\\TimeManager.ts",
|
||||||
|
"line": 227,
|
||||||
|
"description": "How long has passed since the given time.",
|
||||||
|
"itemtype": "method",
|
||||||
|
"name": "elapsedSince",
|
||||||
|
"params": [
|
||||||
|
{
|
||||||
|
"name": "since",
|
||||||
|
"description": "The time you want to measure against.",
|
||||||
|
"type": "Number"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"return": {
|
||||||
|
"description": "The difference between the given time and now.",
|
||||||
|
"type": "Number"
|
||||||
|
},
|
||||||
|
"class": "TimeManager",
|
||||||
|
"module": "Phaser"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "..\\Phaser\\time\\TimeManager.ts",
|
||||||
|
"line": 239,
|
||||||
|
"description": "How long has passed since the given time (in seconds).",
|
||||||
|
"itemtype": "method",
|
||||||
|
"name": "elapsedSecondsSince",
|
||||||
|
"params": [
|
||||||
|
{
|
||||||
|
"name": "since",
|
||||||
|
"description": "The time you want to measure (in seconds).",
|
||||||
|
"type": "Number"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"return": {
|
||||||
|
"description": "Duration between given time and now (in seconds).",
|
||||||
|
"type": "Number"
|
||||||
|
},
|
||||||
|
"class": "TimeManager",
|
||||||
|
"module": "Phaser"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "..\\Phaser\\time\\TimeManager.ts",
|
||||||
|
"line": 251,
|
||||||
|
"description": "Resets the private _started value to now.",
|
||||||
|
"itemtype": "method",
|
||||||
|
"name": "reset",
|
||||||
|
"class": "TimeManager",
|
||||||
|
"module": "Phaser"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"warnings": [
|
||||||
|
{
|
||||||
|
"message": "unknown tag: copyright",
|
||||||
|
"line": " ..\\Phaser\\time\\TimeManager.ts:3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"message": "unknown tag: license",
|
||||||
|
"line": " ..\\Phaser\\time\\TimeManager.ts:3"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,372 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>..\Phaser\time\TimeManager.ts - Phaser</title>
|
||||||
|
<link rel="stylesheet" href="http://yui.yahooapis.com/3.9.1/build/cssgrids/cssgrids-min.css">
|
||||||
|
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
|
||||||
|
<link rel="stylesheet" href="../assets/css/main.css" id="site_styles">
|
||||||
|
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
|
||||||
|
<script src="http://yui.yahooapis.com/combo?3.9.1/build/yui/yui-min.js"></script>
|
||||||
|
</head>
|
||||||
|
<body class="yui3-skin-sam">
|
||||||
|
|
||||||
|
<div id="doc">
|
||||||
|
<div id="hd" class="yui3-g header">
|
||||||
|
<div class="yui3-u-3-4">
|
||||||
|
|
||||||
|
<h1><img src="../assets/css/logo.png" title="Phaser"></h1>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="yui3-u-1-4 version">
|
||||||
|
<em>API Docs for: 1.0.0</em>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div id="bd" class="yui3-g">
|
||||||
|
|
||||||
|
<div class="yui3-u-1-4">
|
||||||
|
<div id="docs-sidebar" class="sidebar apidocs">
|
||||||
|
<div id="api-list">
|
||||||
|
<h2 class="off-left">APIs</h2>
|
||||||
|
<div id="api-tabview" class="tabview">
|
||||||
|
<ul class="tabs">
|
||||||
|
<li><a href="#api-classes">Classes</a></li>
|
||||||
|
<li><a href="#api-modules">Modules</a></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<div id="api-tabview-filter">
|
||||||
|
<input type="search" id="api-filter" placeholder="Type to filter APIs">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="api-tabview-panel">
|
||||||
|
<ul id="api-classes" class="apis classes">
|
||||||
|
|
||||||
|
<li><a href="../classes/TimeManager.html">TimeManager</a></li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<ul id="api-modules" class="apis modules">
|
||||||
|
|
||||||
|
<li><a href="../modules/Phaser.html">Phaser</a></li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="yui3-u-3-4">
|
||||||
|
<div id="api-options">
|
||||||
|
Show:
|
||||||
|
<label for="api-show-inherited">
|
||||||
|
<input type="checkbox" id="api-show-inherited" checked>
|
||||||
|
Inherited
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label for="api-show-protected">
|
||||||
|
<input type="checkbox" id="api-show-protected">
|
||||||
|
Protected
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label for="api-show-private">
|
||||||
|
<input type="checkbox" id="api-show-private">
|
||||||
|
Private
|
||||||
|
</label>
|
||||||
|
<label for="api-show-deprecated">
|
||||||
|
<input type="checkbox" id="api-show-deprecated">
|
||||||
|
Deprecated
|
||||||
|
</label>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="apidocs">
|
||||||
|
<div id="docs-main">
|
||||||
|
<div class="content">
|
||||||
|
<h1 class="file-heading">File: ..\Phaser\time\TimeManager.ts</h1>
|
||||||
|
|
||||||
|
<div class="file">
|
||||||
|
<pre class="code prettyprint linenums">
|
||||||
|
/// <reference path="../_definitions.ts" />
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Richard Davey <rich@photonstorm.com>
|
||||||
|
* @copyright 2013 Photon Storm Ltd.
|
||||||
|
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
|
||||||
|
* @module Phaser
|
||||||
|
*/
|
||||||
|
module Phaser {
|
||||||
|
|
||||||
|
export class TimeManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the core internal game clock. It manages the elapsed time and calculation of delta values,
|
||||||
|
* used for game object motion and tweens.
|
||||||
|
*
|
||||||
|
* @class TimeManager
|
||||||
|
* @constructor
|
||||||
|
* @param {Phaser.Game} game A reference to the currently running game.
|
||||||
|
*/
|
||||||
|
constructor(game: Phaser.Game) {
|
||||||
|
|
||||||
|
this.game = game;
|
||||||
|
|
||||||
|
this._started = 0;
|
||||||
|
this._timeLastSecond = this._started;
|
||||||
|
this.time = this._started;
|
||||||
|
|
||||||
|
this.game.onPause.add(this.gamePaused, this);
|
||||||
|
this.game.onResume.add(this.gameResumed, this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A reference to the currently running Game.
|
||||||
|
* @property game
|
||||||
|
* @type {Phaser.Game}
|
||||||
|
*/
|
||||||
|
public game: Phaser.Game;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The time at which the Game instance started.
|
||||||
|
* @property _started
|
||||||
|
* @private
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
private _started: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number of milliseconds elapsed since the last frame update.
|
||||||
|
* @property elapsed
|
||||||
|
* @public
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
public elapsed: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Game time counter.
|
||||||
|
* @property time
|
||||||
|
* @public
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
public time: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Records how long the game has been paused for. Is reset each time the game pauses.
|
||||||
|
* @property pausedTime
|
||||||
|
* @public
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
public pausedTime: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The time right now.
|
||||||
|
* @property now
|
||||||
|
* @public
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
public now: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Elapsed time since the last frame.
|
||||||
|
* @property delta
|
||||||
|
* @public
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
public delta: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of seconds that have elapsed since the game was started.
|
||||||
|
* @method totalElapsedSeconds
|
||||||
|
* @return {Number}
|
||||||
|
*/
|
||||||
|
public get totalElapsedSeconds(): number {
|
||||||
|
|
||||||
|
return (this.now - this._started) * 0.001;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Frames per second.
|
||||||
|
* @property fps
|
||||||
|
* @public
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
public fps: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The lowest rate the fps has dropped to.
|
||||||
|
* @property fpsMin
|
||||||
|
* @public
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
public fpsMin: number = 1000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The highest rate the fps has reached (usually no higher than 60fps).
|
||||||
|
* @property fpsMax
|
||||||
|
* @public
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
public fpsMax: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The minimum amount of time the game has taken between two frames.
|
||||||
|
* @property msMin
|
||||||
|
* @public
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
public msMin: number = 1000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The maximum amount of time the game has taken between two frames.
|
||||||
|
* @property msMax
|
||||||
|
* @public
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
public msMax: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of frames record in the last second.
|
||||||
|
* @property frames
|
||||||
|
* @public
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
public frames: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The time (in ms) that the last second counter ticked over.
|
||||||
|
* @property _timeLastSecond
|
||||||
|
* @private
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
private _timeLastSecond: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update clock and calculate the fps.
|
||||||
|
* This is called automatically by Game._raf
|
||||||
|
* @method update
|
||||||
|
* @param {Number} raf The current timestamp, either performance.now or Date.now
|
||||||
|
*/
|
||||||
|
public update(raf: number) {
|
||||||
|
|
||||||
|
this.now = raf; // mark
|
||||||
|
this.delta = this.now - this.time; // elapsedMS
|
||||||
|
|
||||||
|
this.msMin = Math.min(this.msMin, this.delta);
|
||||||
|
this.msMax = Math.max(this.msMax, this.delta);
|
||||||
|
|
||||||
|
this.frames++;
|
||||||
|
|
||||||
|
if (this.now > this._timeLastSecond + 1000)
|
||||||
|
{
|
||||||
|
this.fps = Math.round((this.frames * 1000) / (this.now - this._timeLastSecond));
|
||||||
|
this.fpsMin = Math.min(this.fpsMin, this.fps);
|
||||||
|
this.fpsMax = Math.max(this.fpsMax, this.fps);
|
||||||
|
|
||||||
|
this._timeLastSecond = this.now;
|
||||||
|
this.frames = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.time = this.now; // _total
|
||||||
|
|
||||||
|
// Paused?
|
||||||
|
if (this.game.paused)
|
||||||
|
{
|
||||||
|
this.pausedTime = this.now - this._pauseStarted;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the game enters a paused state.
|
||||||
|
* @method gamePaused
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
private gamePaused() {
|
||||||
|
this._pauseStarted = this.now;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the game resumes from a paused state.
|
||||||
|
* @method gameResumed
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
private gameResumed() {
|
||||||
|
// Level out the delta timer to avoid spikes
|
||||||
|
this.pauseDuration = this.pausedTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Records how long the game was paused for in miliseconds.
|
||||||
|
* @property pauseDuration
|
||||||
|
* @public
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
public pauseDuration: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The time the game started being paused.
|
||||||
|
* @property _pauseStarted
|
||||||
|
* @private
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
private _pauseStarted: number = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How long has passed since the given time.
|
||||||
|
* @method elapsedSince
|
||||||
|
* @param {Number} since The time you want to measure against.
|
||||||
|
* @return {Number} The difference between the given time and now.
|
||||||
|
*/
|
||||||
|
public elapsedSince(since: number): number {
|
||||||
|
|
||||||
|
return this.now - since;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How long has passed since the given time (in seconds).
|
||||||
|
* @method elapsedSecondsSince
|
||||||
|
* @param {Number} since The time you want to measure (in seconds).
|
||||||
|
* @return {Number} Duration between given time and now (in seconds).
|
||||||
|
*/
|
||||||
|
public elapsedSecondsSince(since: number): number {
|
||||||
|
|
||||||
|
return (this.now - since) * 0.001;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets the private _started value to now.
|
||||||
|
* @method reset
|
||||||
|
*/
|
||||||
|
public reset() {
|
||||||
|
|
||||||
|
this._started = this.now;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script src="../assets/vendor/prettify/prettify-min.js"></script>
|
||||||
|
<script>prettyPrint();</script>
|
||||||
|
<script src="../assets/js/yui-prettify.js"></script>
|
||||||
|
<script src="../assets/../api.js"></script>
|
||||||
|
<script src="../assets/js/api-filter.js"></script>
|
||||||
|
<script src="../assets/js/api-list.js"></script>
|
||||||
|
<script src="../assets/js/api-search.js"></script>
|
||||||
|
<script src="../assets/js/apidocs.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Phaser</title>
|
||||||
|
<link rel="stylesheet" href="http://yui.yahooapis.com/3.9.1/build/cssgrids/cssgrids-min.css">
|
||||||
|
<link rel="stylesheet" href="./assets/vendor/prettify/prettify-min.css">
|
||||||
|
<link rel="stylesheet" href="./assets/css/main.css" id="site_styles">
|
||||||
|
<link rel="shortcut icon" type="image/png" href="./assets/favicon.png">
|
||||||
|
<script src="http://yui.yahooapis.com/combo?3.9.1/build/yui/yui-min.js"></script>
|
||||||
|
</head>
|
||||||
|
<body class="yui3-skin-sam">
|
||||||
|
|
||||||
|
<div id="doc">
|
||||||
|
<div id="hd" class="yui3-g header">
|
||||||
|
<div class="yui3-u-3-4">
|
||||||
|
|
||||||
|
<h1><img src="./assets/css/logo.png" title="Phaser"></h1>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="yui3-u-1-4 version">
|
||||||
|
<em>API Docs for: 1.0.0</em>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div id="bd" class="yui3-g">
|
||||||
|
|
||||||
|
<div class="yui3-u-1-4">
|
||||||
|
<div id="docs-sidebar" class="sidebar apidocs">
|
||||||
|
<div id="api-list">
|
||||||
|
<h2 class="off-left">APIs</h2>
|
||||||
|
<div id="api-tabview" class="tabview">
|
||||||
|
<ul class="tabs">
|
||||||
|
<li><a href="#api-classes">Classes</a></li>
|
||||||
|
<li><a href="#api-modules">Modules</a></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<div id="api-tabview-filter">
|
||||||
|
<input type="search" id="api-filter" placeholder="Type to filter APIs">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="api-tabview-panel">
|
||||||
|
<ul id="api-classes" class="apis classes">
|
||||||
|
|
||||||
|
<li><a href="./classes/TimeManager.html">TimeManager</a></li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<ul id="api-modules" class="apis modules">
|
||||||
|
|
||||||
|
<li><a href="./modules/Phaser.html">Phaser</a></li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="yui3-u-3-4">
|
||||||
|
<div id="api-options">
|
||||||
|
Show:
|
||||||
|
<label for="api-show-inherited">
|
||||||
|
<input type="checkbox" id="api-show-inherited" checked>
|
||||||
|
Inherited
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label for="api-show-protected">
|
||||||
|
<input type="checkbox" id="api-show-protected">
|
||||||
|
Protected
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label for="api-show-private">
|
||||||
|
<input type="checkbox" id="api-show-private">
|
||||||
|
Private
|
||||||
|
</label>
|
||||||
|
<label for="api-show-deprecated">
|
||||||
|
<input type="checkbox" id="api-show-deprecated">
|
||||||
|
Deprecated
|
||||||
|
</label>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="apidocs">
|
||||||
|
<div id="docs-main">
|
||||||
|
<div class="content">
|
||||||
|
<div class="apidocs">
|
||||||
|
<div id="docs-main" class="content">
|
||||||
|
<p>
|
||||||
|
Browse to a module or class using the sidebar to view its API documentation.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>Keyboard Shortcuts</h2>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><p>Press <kbd>s</kbd> to focus the API search box.</p></li>
|
||||||
|
|
||||||
|
<li><p>Use <kbd>Up</kbd> and <kbd>Down</kbd> to select classes, modules, and search results.</p></li>
|
||||||
|
|
||||||
|
<li class="mac-only"><p>With the API search box or sidebar focused, use <kbd><span class="cmd">⌘</span>-Left</kbd> or <kbd><span class="cmd">⌘</span>-Right</kbd> to switch sidebar tabs.</p></li>
|
||||||
|
|
||||||
|
<li class="pc-only"><p>With the API search box or sidebar focused, use <kbd>Ctrl+Left</kbd> and <kbd>Ctrl+Right</kbd> to switch sidebar tabs.</p></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script src="./assets/vendor/prettify/prettify-min.js"></script>
|
||||||
|
<script>prettyPrint();</script>
|
||||||
|
<script src="./assets/js/yui-prettify.js"></script>
|
||||||
|
<script src="./assets/../api.js"></script>
|
||||||
|
<script src="./assets/js/api-filter.js"></script>
|
||||||
|
<script src="./assets/js/api-list.js"></script>
|
||||||
|
<script src="./assets/js/api-search.js"></script>
|
||||||
|
<script src="./assets/js/apidocs.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,147 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Phaser - Phaser</title>
|
||||||
|
<link rel="stylesheet" href="http://yui.yahooapis.com/3.9.1/build/cssgrids/cssgrids-min.css">
|
||||||
|
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
|
||||||
|
<link rel="stylesheet" href="../assets/css/main.css" id="site_styles">
|
||||||
|
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
|
||||||
|
<script src="http://yui.yahooapis.com/combo?3.9.1/build/yui/yui-min.js"></script>
|
||||||
|
</head>
|
||||||
|
<body class="yui3-skin-sam">
|
||||||
|
|
||||||
|
<div id="doc">
|
||||||
|
<div id="hd" class="yui3-g header">
|
||||||
|
<div class="yui3-u-3-4">
|
||||||
|
|
||||||
|
<h1><img src="../assets/css/logo.png" title="Phaser"></h1>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="yui3-u-1-4 version">
|
||||||
|
<em>API Docs for: 1.0.0</em>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div id="bd" class="yui3-g">
|
||||||
|
|
||||||
|
<div class="yui3-u-1-4">
|
||||||
|
<div id="docs-sidebar" class="sidebar apidocs">
|
||||||
|
<div id="api-list">
|
||||||
|
<h2 class="off-left">APIs</h2>
|
||||||
|
<div id="api-tabview" class="tabview">
|
||||||
|
<ul class="tabs">
|
||||||
|
<li><a href="#api-classes">Classes</a></li>
|
||||||
|
<li><a href="#api-modules">Modules</a></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<div id="api-tabview-filter">
|
||||||
|
<input type="search" id="api-filter" placeholder="Type to filter APIs">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="api-tabview-panel">
|
||||||
|
<ul id="api-classes" class="apis classes">
|
||||||
|
|
||||||
|
<li><a href="../classes/TimeManager.html">TimeManager</a></li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<ul id="api-modules" class="apis modules">
|
||||||
|
|
||||||
|
<li><a href="../modules/Phaser.html">Phaser</a></li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="yui3-u-3-4">
|
||||||
|
<div id="api-options">
|
||||||
|
Show:
|
||||||
|
<label for="api-show-inherited">
|
||||||
|
<input type="checkbox" id="api-show-inherited" checked>
|
||||||
|
Inherited
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label for="api-show-protected">
|
||||||
|
<input type="checkbox" id="api-show-protected">
|
||||||
|
Protected
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label for="api-show-private">
|
||||||
|
<input type="checkbox" id="api-show-private">
|
||||||
|
Private
|
||||||
|
</label>
|
||||||
|
<label for="api-show-deprecated">
|
||||||
|
<input type="checkbox" id="api-show-deprecated">
|
||||||
|
Deprecated
|
||||||
|
</label>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="apidocs">
|
||||||
|
<div id="docs-main">
|
||||||
|
<div class="content">
|
||||||
|
<h1>Phaser Module</h1>
|
||||||
|
<div class="box clearfix meta">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="foundat">
|
||||||
|
Defined in: <a href="../files/.._Phaser_time_TimeManager.ts.html#l13"><code>..\Phaser\time\TimeManager.ts:13</code></a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="box intro">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="yui3-g">
|
||||||
|
<div class="yui3-u-1-2">
|
||||||
|
|
||||||
|
<p>This module provides the following classes:</p>
|
||||||
|
|
||||||
|
<ul class="module-classes">
|
||||||
|
|
||||||
|
<li class="module-class">
|
||||||
|
<a href="../classes/TimeManager.html">
|
||||||
|
TimeManager
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="yui3-u-1-2">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script src="../assets/vendor/prettify/prettify-min.js"></script>
|
||||||
|
<script>prettyPrint();</script>
|
||||||
|
<script src="../assets/js/yui-prettify.js"></script>
|
||||||
|
<script src="../assets/../api.js"></script>
|
||||||
|
<script src="../assets/js/api-filter.js"></script>
|
||||||
|
<script src="../assets/js/api-list.js"></script>
|
||||||
|
<script src="../assets/js/api-search.js"></script>
|
||||||
|
<script src="../assets/js/apidocs.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>phaser - hello world</title>
|
||||||
|
<script src="phaser-min.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
(function () {
|
||||||
|
|
||||||
|
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });
|
||||||
|
|
||||||
|
function preload() {
|
||||||
|
|
||||||
|
game.load.image('logo', 'logo.png');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var logo;
|
||||||
|
|
||||||
|
function create() {
|
||||||
|
|
||||||
|
logo = game.add.sprite(0, 0, 'logo');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function update() {
|
||||||
|
}
|
||||||
|
|
||||||
|
})();
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
After Width: | Height: | Size: 176 KiB |
|
After Width: | Height: | Size: 6.9 MiB |
|
After Width: | Height: | Size: 2.9 MiB |
|
After Width: | Height: | Size: 493 KiB |
|
After Width: | Height: | Size: 176 KiB |
|
After Width: | Height: | Size: 809 B |
|
After Width: | Height: | Size: 4.0 KiB |
|
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 3.6 KiB |
|
After Width: | Height: | Size: 130 KiB |
|
After Width: | Height: | Size: 204 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 2.8 KiB |
|
After Width: | Height: | Size: 9.2 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 4.1 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 612 KiB After Width: | Height: | Size: 612 KiB |
|
Before Width: | Height: | Size: 49 KiB After Width: | Height: | Size: 49 KiB |
|
Before Width: | Height: | Size: 106 KiB After Width: | Height: | Size: 106 KiB |
|
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 62 KiB |
|
After Width: | Height: | Size: 84 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 176 KiB After Width: | Height: | Size: 176 KiB |
|
After Width: | Height: | Size: 86 KiB |
|
After Width: | Height: | Size: 99 KiB |
|
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 66 KiB |
|
Before Width: | Height: | Size: 120 KiB After Width: | Height: | Size: 120 KiB |
|
After Width: | Height: | Size: 243 KiB |
|
After Width: | Height: | Size: 210 KiB |
|
After Width: | Height: | Size: 1021 KiB |
|
After Width: | Height: | Size: 1010 KiB |
|
After Width: | Height: | Size: 1022 KiB |
@@ -0,0 +1 @@
|
|||||||
|
yuidoc -c ../Phaser/yuidoc.json -o API/ -t yuidoc-theme-dana -e .ts ../Phaser/time
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
yuidoc -n -e .ts --server 3000 ../Phaser/time
|
||||||
|
Before Width: | Height: | Size: 531 B |
@@ -0,0 +1,48 @@
|
|||||||
|
/**
|
||||||
|
* @author Richard Davey <rich@photonstorm.com>
|
||||||
|
* @copyright 2013 Photon Storm Ltd.
|
||||||
|
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
|
||||||
|
* @module Phaser
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The class constructor
|
||||||
|
*
|
||||||
|
* @class Name
|
||||||
|
* @constructor
|
||||||
|
* @param {Phaser.Game} game A reference to the currently running game.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A reference to the currently running Game.
|
||||||
|
* @property game
|
||||||
|
* @type {Phaser.Game}
|
||||||
|
*/
|
||||||
|
public game: Phaser.Game;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* My method description. Like other pieces of your comment blocks,
|
||||||
|
* this can span multiple lines.
|
||||||
|
*
|
||||||
|
* @method methodName
|
||||||
|
* @param {String} foo Argument 1
|
||||||
|
* @param {Object} config A config object
|
||||||
|
* @param {String} config.name The name on the config object
|
||||||
|
* @param {Function} config.callback A callback function on the config object
|
||||||
|
* @param {Boolean} [extra=false] Do extra, optional work
|
||||||
|
* @return {Boolean} Returns true on success
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* My property description. Like other pieces of your comment blocks,
|
||||||
|
* this can span multiple lines.
|
||||||
|
*
|
||||||
|
* @property propertyName
|
||||||
|
* @public
|
||||||
|
* @type {Object}
|
||||||
|
* @default "foo"
|
||||||
|
*/
|
||||||
|
|
||||||
|
@param {Type} Name Description
|
||||||
|
Object, Array, String, Boolean, Number, Mixed, MyType
|
||||||
|
|
||||||
@@ -3,6 +3,42 @@ module.exports = function (grunt) {
|
|||||||
grunt.loadNpmTasks('grunt-contrib-watch');
|
grunt.loadNpmTasks('grunt-contrib-watch');
|
||||||
grunt.loadNpmTasks('grunt-contrib-copy');
|
grunt.loadNpmTasks('grunt-contrib-copy');
|
||||||
|
|
||||||
|
var wrapPhaserInUmd = function(content, isAddon) {
|
||||||
|
var replacement = [
|
||||||
|
'(function (root, factory) {',
|
||||||
|
' if (typeof exports === \'object\') {',
|
||||||
|
' module.exports = factory();',
|
||||||
|
' } else if (typeof define === \'function\' && define.amd) {',
|
||||||
|
' define(factory);',
|
||||||
|
' } else {',
|
||||||
|
' root.Phaser = factory();',
|
||||||
|
' }',
|
||||||
|
'}(this, function () {',
|
||||||
|
content,
|
||||||
|
'return Phaser;',
|
||||||
|
'}));'
|
||||||
|
];
|
||||||
|
return replacement.join('\n');
|
||||||
|
};
|
||||||
|
|
||||||
|
var wrapAddonInUmd = function(content) {
|
||||||
|
var replacement = [
|
||||||
|
'(function (root, factory) {',
|
||||||
|
' if (typeof exports === \'object\') {',
|
||||||
|
' module.exports = factory(require(\'phaser\'));',
|
||||||
|
' } else if (typeof define === \'function\' && define.amd) {',
|
||||||
|
' define([\'phaser\'], factory);',
|
||||||
|
' } else {',
|
||||||
|
' factory(root.Phaser);',
|
||||||
|
' }',
|
||||||
|
'}(this, function (Phaser) {',
|
||||||
|
content,
|
||||||
|
'return Phaser;',
|
||||||
|
'}));'
|
||||||
|
];
|
||||||
|
return replacement.join('\n');
|
||||||
|
};
|
||||||
|
|
||||||
grunt.initConfig({
|
grunt.initConfig({
|
||||||
pkg: grunt.file.readJSON('package.json'),
|
pkg: grunt.file.readJSON('package.json'),
|
||||||
typescript: {
|
typescript: {
|
||||||
@@ -10,49 +46,35 @@ module.exports = function (grunt) {
|
|||||||
src: ['Phaser/**/*.ts'],
|
src: ['Phaser/**/*.ts'],
|
||||||
dest: 'build/phaser.js',
|
dest: 'build/phaser.js',
|
||||||
options: {
|
options: {
|
||||||
target: 'ES5'
|
target: 'ES5',
|
||||||
|
declaration: true,
|
||||||
|
comments: true
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
copy: {
|
copy: {
|
||||||
main: {
|
main: {
|
||||||
files: [{
|
files: [{
|
||||||
src: 'build/phaser.js',
|
src: 'build/phaser.js',
|
||||||
dest: 'Tests/phaser.js'
|
dest: 'Tests/phaser.js'
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
amd: {
|
mainAmd: {
|
||||||
files: [{
|
files: [{
|
||||||
src: 'build/phaser.js',
|
src: 'build/phaser.js',
|
||||||
dest: 'build/phaser.amd.js'
|
dest: 'build/phaser.amd.js'
|
||||||
}],
|
}],
|
||||||
options: {
|
options: {
|
||||||
processContent: function(content) {
|
processContent: wrapPhaserInUmd
|
||||||
var replacement = [
|
}
|
||||||
'(function (root, factory) {',
|
},
|
||||||
' if (typeof exports === \'object\') {',
|
},
|
||||||
' module.exports = factory();',
|
watch: {
|
||||||
' } else if (typeof define === \'function\' && define.amd) {',
|
|
||||||
' define(factory);',
|
|
||||||
' } else {',
|
|
||||||
' root.Phaser = factory();',
|
|
||||||
' }',
|
|
||||||
'}(this, function () {',
|
|
||||||
content,
|
|
||||||
'return Phaser;',
|
|
||||||
'}));'
|
|
||||||
];
|
|
||||||
return replacement.join('\n');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
watch: {
|
|
||||||
files: '**/*.ts',
|
files: '**/*.ts',
|
||||||
tasks: ['typescript', 'copy']
|
tasks: ['typescript', 'copy']
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
grunt.registerTask('default', ['watch']);
|
grunt.registerTask('default', ['typescript', 'copy', 'watch']);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,186 +0,0 @@
|
|||||||
/// <reference path="Game.ts" />
|
|
||||||
/// <reference path="gameobjects/Sprite.ts" />
|
|
||||||
/// <reference path="system/animation/Animation.ts" />
|
|
||||||
/// <reference path="system/animation/AnimationLoader.ts" />
|
|
||||||
/// <reference path="system/animation/Frame.ts" />
|
|
||||||
/// <reference path="system/animation/FrameData.ts" />
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Phaser - AnimationManager
|
|
||||||
*
|
|
||||||
* Any Sprite that has animation contains an instance of the AnimationManager, which is used to add, play and update
|
|
||||||
* sprite specific animations.
|
|
||||||
*/
|
|
||||||
|
|
||||||
module Phaser {
|
|
||||||
|
|
||||||
export class AnimationManager {
|
|
||||||
|
|
||||||
constructor(game: Game, parent: Sprite) {
|
|
||||||
|
|
||||||
this._game = game;
|
|
||||||
this._parent = parent;
|
|
||||||
this._anims = {};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private _game: Game;
|
|
||||||
private _parent: Sprite;
|
|
||||||
|
|
||||||
private _anims: {};
|
|
||||||
private _frameIndex: number;
|
|
||||||
private _frameData: FrameData = null;
|
|
||||||
|
|
||||||
public currentAnim: Animation;
|
|
||||||
public currentFrame: Frame = null;
|
|
||||||
|
|
||||||
public loadFrameData(frameData: FrameData) {
|
|
||||||
|
|
||||||
this._frameData = frameData;
|
|
||||||
|
|
||||||
this.frame = 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public add(name: string, frames: any[] = null, frameRate: number = 60, loop: bool = false, useNumericIndex: bool = true) {
|
|
||||||
|
|
||||||
if (this._frameData == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (frames == null)
|
|
||||||
{
|
|
||||||
frames = this._frameData.getFrameIndexes();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (this.validateFrames(frames, useNumericIndex) == false)
|
|
||||||
{
|
|
||||||
throw Error('Invalid frames given to Animation ' + name);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (useNumericIndex == false)
|
|
||||||
{
|
|
||||||
frames = this._frameData.getFrameIndexesByName(frames);
|
|
||||||
}
|
|
||||||
|
|
||||||
this._anims[name] = new Animation(this._game, this._parent, this._frameData, name, frames, frameRate, loop);
|
|
||||||
|
|
||||||
this.currentAnim = this._anims[name];
|
|
||||||
this.currentFrame = this.currentAnim.currentFrame;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private validateFrames(frames: any[], useNumericIndex: bool): bool {
|
|
||||||
|
|
||||||
for (var i = 0; i < frames.length; i++)
|
|
||||||
{
|
|
||||||
if (useNumericIndex == true)
|
|
||||||
{
|
|
||||||
if (frames[i] > this._frameData.total)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (this._frameData.checkFrameName(frames[i]) == false)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public play(name: string, frameRate?: number = null, loop?: bool) {
|
|
||||||
|
|
||||||
if (this._anims[name])
|
|
||||||
{
|
|
||||||
if (this.currentAnim == this._anims[name])
|
|
||||||
{
|
|
||||||
if (this.currentAnim.isPlaying == false)
|
|
||||||
{
|
|
||||||
this.currentAnim.play(frameRate, loop);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.currentAnim = this._anims[name];
|
|
||||||
this.currentAnim.play(frameRate, loop);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public stop(name: string) {
|
|
||||||
|
|
||||||
if (this._anims[name])
|
|
||||||
{
|
|
||||||
this.currentAnim = this._anims[name];
|
|
||||||
this.currentAnim.stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public update() {
|
|
||||||
|
|
||||||
if (this.currentAnim && this.currentAnim.update() == true)
|
|
||||||
{
|
|
||||||
this.currentFrame = this.currentAnim.currentFrame;
|
|
||||||
this._parent.bounds.width = this.currentFrame.width;
|
|
||||||
this._parent.bounds.height = this.currentFrame.height;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public get frameData(): FrameData {
|
|
||||||
return this._frameData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get frameTotal(): number {
|
|
||||||
return this._frameData.total;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get frame(): number {
|
|
||||||
return this._frameIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
public set frame(value: number) {
|
|
||||||
|
|
||||||
if (this._frameData.getFrame(value) !== null)
|
|
||||||
{
|
|
||||||
this.currentFrame = this._frameData.getFrame(value);
|
|
||||||
|
|
||||||
this._parent.bounds.width = this.currentFrame.width;
|
|
||||||
this._parent.bounds.height = this.currentFrame.height;
|
|
||||||
this._frameIndex = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public get frameName(): string {
|
|
||||||
return this.currentFrame.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public set frameName(value: string) {
|
|
||||||
|
|
||||||
if (this._frameData.getFrameByName(value) !== null)
|
|
||||||
{
|
|
||||||
this.currentFrame = this._frameData.getFrameByName(value);
|
|
||||||
|
|
||||||
this._parent.bounds.width = this.currentFrame.width;
|
|
||||||
this._parent.bounds.height = this.currentFrame.height;
|
|
||||||
this._frameIndex = this.currentFrame.index;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,138 +0,0 @@
|
|||||||
/// <reference path="Game.ts" />
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Phaser - Basic
|
|
||||||
*
|
|
||||||
* A useful "generic" object on which all GameObjects and Groups are based.
|
|
||||||
* It has no size, position or graphical data.
|
|
||||||
*/
|
|
||||||
|
|
||||||
module Phaser {
|
|
||||||
|
|
||||||
export class Basic {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiate the basic object.
|
|
||||||
*/
|
|
||||||
constructor(game: Game) {
|
|
||||||
|
|
||||||
this._game = game;
|
|
||||||
this.ID = -1;
|
|
||||||
this.exists = true;
|
|
||||||
this.active = true;
|
|
||||||
this.visible = true;
|
|
||||||
this.alive = true;
|
|
||||||
this.isGroup = false;
|
|
||||||
this.ignoreDrawDebug = false;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The essential reference to the main game object
|
|
||||||
*/
|
|
||||||
public _game: Game;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Allows you to give this object a name. Useful for debugging, but not actually used internally.
|
|
||||||
*/
|
|
||||||
public name: string = '';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* IDs seem like they could be pretty useful, huh?
|
|
||||||
* They're not actually used for anything yet though.
|
|
||||||
*/
|
|
||||||
public ID: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A boolean to store if this object is a Group or not.
|
|
||||||
* Saves us an expensive typeof check inside of core loops.
|
|
||||||
*/
|
|
||||||
public isGroup: bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Controls whether <code>update()</code> and <code>draw()</code> are automatically called by State/Group.
|
|
||||||
*/
|
|
||||||
public exists: bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Controls whether <code>update()</code> is automatically called by State/Group.
|
|
||||||
*/
|
|
||||||
public active: bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Controls whether <code>draw()</code> is automatically called by State/Group.
|
|
||||||
*/
|
|
||||||
public visible: bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Useful state for many game objects - "dead" (!alive) vs alive.
|
|
||||||
* <code>kill()</code> and <code>revive()</code> both flip this switch (along with exists, but you can override that).
|
|
||||||
*/
|
|
||||||
public alive: bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Setting this to true will prevent the object from appearing
|
|
||||||
* when the visual debug mode in the debugger overlay is toggled on.
|
|
||||||
*/
|
|
||||||
public ignoreDrawDebug: bool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Override this to null out iables or manually call
|
|
||||||
* <code>destroy()</code> on class members if necessary.
|
|
||||||
* Don't forget to call <code>super.destroy()</code>!
|
|
||||||
*/
|
|
||||||
public destroy() { }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pre-update is called right before <code>update()</code> on each object in the game loop.
|
|
||||||
*/
|
|
||||||
public preUpdate() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Override this to update your class's position and appearance.
|
|
||||||
* This is where most of your game rules and behavioral code will go.
|
|
||||||
*/
|
|
||||||
public update() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Post-update is called right after <code>update()</code> on each object in the game loop.
|
|
||||||
*/
|
|
||||||
public postUpdate() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handy for "killing" game objects.
|
|
||||||
* Default behavior is to flag them as nonexistent AND dead.
|
|
||||||
* However, if you want the "corpse" to remain in the game,
|
|
||||||
* like to animate an effect or whatever, you should override this,
|
|
||||||
* setting only alive to false, and leaving exists true.
|
|
||||||
*/
|
|
||||||
public kill() {
|
|
||||||
this.alive = false;
|
|
||||||
this.exists = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handy for bringing game objects "back to life". Just sets alive and exists back to true.
|
|
||||||
* In practice, this is most often called by <code>Object.reset()</code>.
|
|
||||||
*/
|
|
||||||
public revive() {
|
|
||||||
this.alive = true;
|
|
||||||
this.exists = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert object to readable string name. Useful for debugging, save games, etc.
|
|
||||||
*/
|
|
||||||
public toString(): string {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,176 +0,0 @@
|
|||||||
/// <reference path="Game.ts" />
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Phaser - Cache
|
|
||||||
*
|
|
||||||
* A game only has one instance of a Cache and it is used to store all externally loaded assets such
|
|
||||||
* as images, sounds and data files as a result of Loader calls. Cache items use string based keys for look-up.
|
|
||||||
*/
|
|
||||||
|
|
||||||
module Phaser {
|
|
||||||
|
|
||||||
export class Cache {
|
|
||||||
|
|
||||||
constructor(game: Game) {
|
|
||||||
|
|
||||||
this._game = game;
|
|
||||||
|
|
||||||
this._canvases = {};
|
|
||||||
this._images = {};
|
|
||||||
this._sounds = {};
|
|
||||||
this._text = {};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private _game: Game;
|
|
||||||
|
|
||||||
private _canvases;
|
|
||||||
private _images;
|
|
||||||
private _sounds;
|
|
||||||
private _text;
|
|
||||||
|
|
||||||
public addCanvas(key: string, canvas: HTMLCanvasElement, context: CanvasRenderingContext2D) {
|
|
||||||
|
|
||||||
this._canvases[key] = { canvas: canvas, context: context };
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public addSpriteSheet(key: string, url: string, data, frameWidth: number, frameHeight: number, frameMax: number) {
|
|
||||||
|
|
||||||
this._images[key] = { url: url, data: data, spriteSheet: true, frameWidth: frameWidth, frameHeight: frameHeight };
|
|
||||||
this._images[key].frameData = AnimationLoader.parseSpriteSheet(this._game, key, frameWidth, frameHeight, frameMax);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public addTextureAtlas(key: string, url: string, data, jsonData) {
|
|
||||||
|
|
||||||
this._images[key] = { url: url, data: data, spriteSheet: true };
|
|
||||||
this._images[key].frameData = AnimationLoader.parseJSONData(this._game, jsonData);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public addImage(key: string, url: string, data) {
|
|
||||||
|
|
||||||
this._images[key] = { url: url, data: data, spriteSheet: false };
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public addSound(key: string, url: string, data) {
|
|
||||||
|
|
||||||
this._sounds[key] = { url: url, data: data, decoded: false };
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public decodedSound(key: string, data) {
|
|
||||||
|
|
||||||
this._sounds[key].data = data;
|
|
||||||
this._sounds[key].decoded = true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public addText(key: string, url: string, data) {
|
|
||||||
|
|
||||||
this._text[key] = { url: url, data: data };
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public getCanvas(key: string) {
|
|
||||||
|
|
||||||
if (this._canvases[key])
|
|
||||||
{
|
|
||||||
return this._canvases[key].canvas;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public getImage(key: string) {
|
|
||||||
|
|
||||||
if (this._images[key])
|
|
||||||
{
|
|
||||||
return this._images[key].data;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public getFrameData(key: string): FrameData {
|
|
||||||
|
|
||||||
if (this._images[key] && this._images[key].spriteSheet == true)
|
|
||||||
{
|
|
||||||
return this._images[key].frameData;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public getSound(key: string) {
|
|
||||||
|
|
||||||
if (this._sounds[key])
|
|
||||||
{
|
|
||||||
return this._sounds[key].data;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public isSoundDecoded(key: string): bool {
|
|
||||||
|
|
||||||
if (this._sounds[key])
|
|
||||||
{
|
|
||||||
return this._sounds[key].decoded;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public isSpriteSheet(key: string): bool {
|
|
||||||
|
|
||||||
if (this._images[key])
|
|
||||||
{
|
|
||||||
return this._images[key].spriteSheet;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public getText(key: string) {
|
|
||||||
|
|
||||||
if (this._text[key])
|
|
||||||
{
|
|
||||||
return this._text[key].data;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public destroy() {
|
|
||||||
|
|
||||||
for (var item in this._canvases)
|
|
||||||
{
|
|
||||||
delete this._canvases[item['key']];
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var item in this._images)
|
|
||||||
{
|
|
||||||
delete this._images[item['key']];
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var item in this._sounds)
|
|
||||||
{
|
|
||||||
delete this._sounds[item['key']];
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var item in this._text)
|
|
||||||
{
|
|
||||||
delete this._text[item['key']];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
/// <reference path="Game.ts" />
|
|
||||||
/// <reference path="system/Camera.ts" />
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Phaser - CameraManager
|
|
||||||
*
|
|
||||||
* Your game only has one CameraManager instance and it's responsible for looking after, creating and destroying
|
|
||||||
* all of the cameras in the world.
|
|
||||||
*
|
|
||||||
* TODO: If the Camera is larger than the Stage size then the rotation offset isn't correct
|
|
||||||
* TODO: Texture Repeat doesn't scroll, because it's part of the camera not the world, need to think about this more
|
|
||||||
*/
|
|
||||||
|
|
||||||
module Phaser {
|
|
||||||
|
|
||||||
export class CameraManager {
|
|
||||||
|
|
||||||
constructor(game: Game, x: number, y: number, width: number, height: number) {
|
|
||||||
|
|
||||||
this._game = game;
|
|
||||||
|
|
||||||
this._cameras = [];
|
|
||||||
|
|
||||||
this.current = this.addCamera(x, y, width, height);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private _game: Game;
|
|
||||||
private _cameras: Camera[];
|
|
||||||
private _cameraInstance: number = 0;
|
|
||||||
|
|
||||||
public current: Camera;
|
|
||||||
|
|
||||||
public getAll(): Camera[] {
|
|
||||||
return this._cameras;
|
|
||||||
}
|
|
||||||
|
|
||||||
public update() {
|
|
||||||
this._cameras.forEach((camera) => camera.update());
|
|
||||||
}
|
|
||||||
|
|
||||||
public render() {
|
|
||||||
this._cameras.forEach((camera) => camera.render());
|
|
||||||
}
|
|
||||||
|
|
||||||
public addCamera(x: number, y: number, width: number, height: number): Camera {
|
|
||||||
|
|
||||||
var newCam: Camera = new Camera(this._game, this._cameraInstance, x, y, width, height);
|
|
||||||
|
|
||||||
this._cameras.push(newCam);
|
|
||||||
|
|
||||||
this._cameraInstance++;
|
|
||||||
|
|
||||||
return newCam;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public removeCamera(id: number): bool {
|
|
||||||
|
|
||||||
for (var c = 0; c < this._cameras.length; c++)
|
|
||||||
{
|
|
||||||
if (this._cameras[c].ID == id)
|
|
||||||
{
|
|
||||||
if (this.current.ID === this._cameras[c].ID)
|
|
||||||
{
|
|
||||||
this.current = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
this._cameras.splice(c, 1);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public destroy() {
|
|
||||||
|
|
||||||
this._cameras.length = 0;
|
|
||||||
|
|
||||||
this.current = this.addCamera(0, 0, this._game.stage.width, this._game.stage.height);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,217 +0,0 @@
|
|||||||
/// <reference path="Game.ts" />
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Phaser - DynamicTexture
|
|
||||||
*
|
|
||||||
* A DynamicTexture can be thought of as a mini canvas into which you can draw anything.
|
|
||||||
* Game Objects can be assigned a DynamicTexture, so when they render in the world they do so
|
|
||||||
* based on the contents of the texture at the time. This allows you to create powerful effects
|
|
||||||
* once and have them replicated across as many game objects as you like.
|
|
||||||
*/
|
|
||||||
|
|
||||||
module Phaser {
|
|
||||||
|
|
||||||
export class DynamicTexture {
|
|
||||||
|
|
||||||
constructor(game: Game, width: number, height: number) {
|
|
||||||
|
|
||||||
this._game = game;
|
|
||||||
|
|
||||||
this.canvas = <HTMLCanvasElement> document.createElement('canvas');
|
|
||||||
this.canvas.width = width;
|
|
||||||
this.canvas.height = height;
|
|
||||||
this.context = this.canvas.getContext('2d');
|
|
||||||
|
|
||||||
this.bounds = new Rectangle(0, 0, width, height);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private _game: Game;
|
|
||||||
|
|
||||||
private _sx: number = 0;
|
|
||||||
private _sy: number = 0;
|
|
||||||
private _sw: number = 0;
|
|
||||||
private _sh: number = 0;
|
|
||||||
private _dx: number = 0;
|
|
||||||
private _dy: number = 0;
|
|
||||||
private _dw: number = 0;
|
|
||||||
private _dh: number = 0;
|
|
||||||
|
|
||||||
// Input / Output nodes?
|
|
||||||
|
|
||||||
public bounds: Rectangle;
|
|
||||||
public canvas: HTMLCanvasElement;
|
|
||||||
public context: CanvasRenderingContext2D;
|
|
||||||
|
|
||||||
public getPixel(x: number, y: number): number {
|
|
||||||
|
|
||||||
//r = imageData.data[0];
|
|
||||||
//g = imageData.data[1];
|
|
||||||
//b = imageData.data[2];
|
|
||||||
//a = imageData.data[3];
|
|
||||||
var imageData = this.context.getImageData(x, y, 1, 1);
|
|
||||||
|
|
||||||
return this.getColor(imageData.data[0], imageData.data[1], imageData.data[2]);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public getPixel32(x: number, y: number) {
|
|
||||||
|
|
||||||
var imageData = this.context.getImageData(x, y, 1, 1);
|
|
||||||
|
|
||||||
return this.getColor32(imageData.data[3], imageData.data[0], imageData.data[1], imageData.data[2]);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns a CanvasPixelArray
|
|
||||||
public getPixels(rect: Rectangle) {
|
|
||||||
|
|
||||||
return this.context.getImageData(rect.x, rect.y, rect.width, rect.height);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public setPixel(x: number, y: number, color: number) {
|
|
||||||
|
|
||||||
this.context.fillStyle = color;
|
|
||||||
this.context.fillRect(x, y, 1, 1);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public setPixel32(x: number, y: number, color: number) {
|
|
||||||
|
|
||||||
this.context.fillStyle = color;
|
|
||||||
this.context.fillRect(x, y, 1, 1);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public setPixels(rect: Rectangle, input) {
|
|
||||||
|
|
||||||
this.context.putImageData(input, rect.x, rect.y);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public fillRect(rect: Rectangle, color: number) {
|
|
||||||
|
|
||||||
this.context.fillStyle = color;
|
|
||||||
this.context.fillRect(rect.x, rect.y, rect.width, rect.height);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public pasteImage(key: string, frame?: number = -1, destX?: number = 0, destY?: number = 0, destWidth?: number = null, destHeight?: number = null) {
|
|
||||||
|
|
||||||
var texture = null;
|
|
||||||
var frameData;
|
|
||||||
|
|
||||||
this._sx = 0;
|
|
||||||
this._sy = 0;
|
|
||||||
this._dx = destX;
|
|
||||||
this._dy = destY;
|
|
||||||
|
|
||||||
// TODO - Load a frame from a sprite sheet, otherwise we'll draw the whole lot
|
|
||||||
if (frame > -1)
|
|
||||||
{
|
|
||||||
//if (this._game.cache.isSpriteSheet(key))
|
|
||||||
//{
|
|
||||||
// texture = this._game.cache.getImage(key);
|
|
||||||
//this.animations.loadFrameData(this._game.cache.getFrameData(key));
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
texture = this._game.cache.getImage(key);
|
|
||||||
this._sw = texture.width;
|
|
||||||
this._sh = texture.height;
|
|
||||||
this._dw = texture.width;
|
|
||||||
this._dh = texture.height;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (destWidth !== null)
|
|
||||||
{
|
|
||||||
this._dw = destWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (destHeight !== null)
|
|
||||||
{
|
|
||||||
this._dh = destHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (texture != null)
|
|
||||||
{
|
|
||||||
this.context.drawImage(
|
|
||||||
texture, // Source Image
|
|
||||||
this._sx, // Source X (location within the source image)
|
|
||||||
this._sy, // Source Y
|
|
||||||
this._sw, // Source Width
|
|
||||||
this._sh, // Source Height
|
|
||||||
this._dx, // Destination X (where on the canvas it'll be drawn)
|
|
||||||
this._dy, // Destination Y
|
|
||||||
this._dw, // Destination Width (always same as Source Width unless scaled)
|
|
||||||
this._dh // Destination Height (always same as Source Height unless scaled)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO - Add in support for: alphaBitmapData: BitmapData = null, alphaPoint: Point = null, mergeAlpha: bool = false
|
|
||||||
public copyPixels(sourceTexture: DynamicTexture, sourceRect: Rectangle, destPoint: Point) {
|
|
||||||
|
|
||||||
// Swap for drawImage if the sourceRect is the same size as the sourceTexture to avoid a costly getImageData call
|
|
||||||
if (sourceRect.equals(this.bounds) == true)
|
|
||||||
{
|
|
||||||
this.context.drawImage(sourceTexture.canvas, destPoint.x, destPoint.y);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.context.putImageData(sourceTexture.getPixels(sourceRect), destPoint.x, destPoint.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public clear() {
|
|
||||||
|
|
||||||
this.context.clearRect(0, 0, this.bounds.width, this.bounds.height);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public get width(): number {
|
|
||||||
return this.bounds.width;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get height(): number {
|
|
||||||
return this.bounds.height;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Given an alpha and 3 color values this will return an integer representation of it
|
|
||||||
*
|
|
||||||
* @param alpha The Alpha value (between 0 and 255)
|
|
||||||
* @param red The Red channel value (between 0 and 255)
|
|
||||||
* @param green The Green channel value (between 0 and 255)
|
|
||||||
* @param blue The Blue channel value (between 0 and 255)
|
|
||||||
*
|
|
||||||
* @return A native color value integer (format: 0xAARRGGBB)
|
|
||||||
*/
|
|
||||||
private getColor32(alpha: number, red: number, green: number, blue: number): number {
|
|
||||||
|
|
||||||
return alpha << 24 | red << 16 | green << 8 | blue;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Given 3 color values this will return an integer representation of it
|
|
||||||
*
|
|
||||||
* @param red The Red channel value (between 0 and 255)
|
|
||||||
* @param green The Green channel value (between 0 and 255)
|
|
||||||
* @param blue The Blue channel value (between 0 and 255)
|
|
||||||
*
|
|
||||||
* @return A native color value integer (format: 0xRRGGBB)
|
|
||||||
*/
|
|
||||||
private getColor(red: number, green: number, blue: number): number {
|
|
||||||
|
|
||||||
return red << 16 | green << 8 | blue;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,429 +0,0 @@
|
|||||||
/// <reference path="AnimationManager.ts" />
|
|
||||||
/// <reference path="Basic.ts" />
|
|
||||||
/// <reference path="Cache.ts" />
|
|
||||||
/// <reference path="CameraManager.ts" />
|
|
||||||
/// <reference path="Collision.ts" />
|
|
||||||
/// <reference path="DynamicTexture.ts" />
|
|
||||||
/// <reference path="GameMath.ts" />
|
|
||||||
/// <reference path="Group.ts" />
|
|
||||||
/// <reference path="Loader.ts" />
|
|
||||||
/// <reference path="Motion.ts" />
|
|
||||||
/// <reference path="Signal.ts" />
|
|
||||||
/// <reference path="SignalBinding.ts" />
|
|
||||||
/// <reference path="SoundManager.ts" />
|
|
||||||
/// <reference path="Stage.ts" />
|
|
||||||
/// <reference path="Time.ts" />
|
|
||||||
/// <reference path="TweenManager.ts" />
|
|
||||||
/// <reference path="World.ts" />
|
|
||||||
/// <reference path="system/Device.ts" />
|
|
||||||
/// <reference path="system/RandomDataGenerator.ts" />
|
|
||||||
/// <reference path="system/RequestAnimationFrame.ts" />
|
|
||||||
/// <reference path="system/input/Input.ts" />
|
|
||||||
/// <reference path="system/input/Keyboard.ts" />
|
|
||||||
/// <reference path="system/input/Mouse.ts" />
|
|
||||||
/// <reference path="system/input/Touch.ts" />
|
|
||||||
/// <reference path="gameobjects/Emitter.ts" />
|
|
||||||
/// <reference path="gameobjects/GameObject.ts" />
|
|
||||||
/// <reference path="gameobjects/GeomSprite.ts" />
|
|
||||||
/// <reference path="gameobjects/Particle.ts" />
|
|
||||||
/// <reference path="gameobjects/Sprite.ts" />
|
|
||||||
/// <reference path="gameobjects/Tilemap.ts" />
|
|
||||||
/// <reference path="gameobjects/ScrollZone.ts" />
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Phaser - Game
|
|
||||||
*
|
|
||||||
* This is where the magic happens. The Game object is the heart of your game,
|
|
||||||
* providing quick access to common functions and handling the boot process.
|
|
||||||
*
|
|
||||||
* "Hell, there are no rules here - we're trying to accomplish something."
|
|
||||||
* Thomas A. Edison
|
|
||||||
*/
|
|
||||||
|
|
||||||
module Phaser {
|
|
||||||
|
|
||||||
export class Game {
|
|
||||||
|
|
||||||
constructor(callbackContext, parent?: string = '', width?: number = 800, height?: number = 600, initCallback = null, createCallback = null, updateCallback = null, renderCallback = null) {
|
|
||||||
|
|
||||||
this.callbackContext = callbackContext;
|
|
||||||
this.onInitCallback = initCallback;
|
|
||||||
this.onCreateCallback = createCallback;
|
|
||||||
this.onUpdateCallback = updateCallback;
|
|
||||||
this.onRenderCallback = renderCallback;
|
|
||||||
|
|
||||||
if (document.readyState === 'complete' || document.readyState === 'interactive')
|
|
||||||
{
|
|
||||||
setTimeout(() => this.boot(parent, width, height));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
document.addEventListener('DOMContentLoaded', () => this.boot(parent, width, height), false);
|
|
||||||
window.addEventListener('load', () => this.boot(parent, width, height), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private _raf: RequestAnimationFrame;
|
|
||||||
private _maxAccumulation: number = 32;
|
|
||||||
private _accumulator: number = 0;
|
|
||||||
private _step: number = 0;
|
|
||||||
private _loadComplete: bool = false;
|
|
||||||
private _paused: bool = false;
|
|
||||||
private _pendingState = null;
|
|
||||||
|
|
||||||
// Event callbacks
|
|
||||||
public callbackContext;
|
|
||||||
public onInitCallback = null;
|
|
||||||
public onCreateCallback = null;
|
|
||||||
public onUpdateCallback = null;
|
|
||||||
public onRenderCallback = null;
|
|
||||||
public onPausedCallback = null;
|
|
||||||
|
|
||||||
public cache: Cache;
|
|
||||||
public collision: Collision;
|
|
||||||
public input: Input;
|
|
||||||
public loader: Loader;
|
|
||||||
public math: GameMath;
|
|
||||||
public motion: Motion;
|
|
||||||
public sound: SoundManager;
|
|
||||||
public stage: Stage;
|
|
||||||
public time: Time;
|
|
||||||
public tweens: TweenManager;
|
|
||||||
public world: World;
|
|
||||||
public rnd: RandomDataGenerator;
|
|
||||||
public device: Device;
|
|
||||||
|
|
||||||
public isBooted: bool = false;
|
|
||||||
|
|
||||||
private boot(parent: string, width: number, height: number) {
|
|
||||||
|
|
||||||
if (this.isBooted == true)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!document.body)
|
|
||||||
{
|
|
||||||
window.setTimeout(() => this.boot(parent, width, height), 13);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.device = new Device();
|
|
||||||
this.motion = new Motion(this);
|
|
||||||
this.math = new GameMath(this);
|
|
||||||
this.stage = new Stage(this, parent, width, height);
|
|
||||||
this.world = new World(this, width, height);
|
|
||||||
this.sound = new SoundManager(this);
|
|
||||||
this.cache = new Cache(this);
|
|
||||||
this.collision = new Collision(this);
|
|
||||||
this.loader = new Loader(this, this.loadComplete);
|
|
||||||
this.time = new Time(this);
|
|
||||||
this.tweens = new TweenManager(this);
|
|
||||||
this.input = new Input(this);
|
|
||||||
this.rnd = new RandomDataGenerator([(Date.now() * Math.random()).toString()]);
|
|
||||||
|
|
||||||
this.framerate = 60;
|
|
||||||
|
|
||||||
// Display the default game screen?
|
|
||||||
if (this.onInitCallback == null && this.onCreateCallback == null && this.onUpdateCallback == null && this.onRenderCallback == null && this._pendingState == null)
|
|
||||||
{
|
|
||||||
this.isBooted = false;
|
|
||||||
this.stage.drawInitScreen();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.isBooted = true;
|
|
||||||
this._loadComplete = false;
|
|
||||||
|
|
||||||
this._raf = new RequestAnimationFrame(this.loop, this);
|
|
||||||
|
|
||||||
if (this._pendingState)
|
|
||||||
{
|
|
||||||
this.switchState(this._pendingState, false, false);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.startState();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private loadComplete() {
|
|
||||||
|
|
||||||
// Called when the loader has finished after init was run
|
|
||||||
this._loadComplete = true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private loop() {
|
|
||||||
|
|
||||||
this.time.update();
|
|
||||||
this.tweens.update();
|
|
||||||
|
|
||||||
if (this._paused == true)
|
|
||||||
{
|
|
||||||
if (this.onPausedCallback !== null)
|
|
||||||
{
|
|
||||||
this.onPausedCallback.call(this.callbackContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
this.input.update();
|
|
||||||
this.stage.update();
|
|
||||||
|
|
||||||
this._accumulator += this.time.delta;
|
|
||||||
|
|
||||||
if (this._accumulator > this._maxAccumulation)
|
|
||||||
{
|
|
||||||
this._accumulator = this._maxAccumulation;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (this._accumulator >= this._step)
|
|
||||||
{
|
|
||||||
this.time.elapsed = this.time.timeScale * (this._step / 1000);
|
|
||||||
this.world.update();
|
|
||||||
this._accumulator = this._accumulator - this._step;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this._loadComplete && this.onUpdateCallback)
|
|
||||||
{
|
|
||||||
this.onUpdateCallback.call(this.callbackContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.world.render();
|
|
||||||
|
|
||||||
if (this._loadComplete && this.onRenderCallback)
|
|
||||||
{
|
|
||||||
this.onRenderCallback.call(this.callbackContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private startState() {
|
|
||||||
|
|
||||||
if (this.onInitCallback !== null)
|
|
||||||
{
|
|
||||||
this.loader.reset();
|
|
||||||
|
|
||||||
this.onInitCallback.call(this.callbackContext);
|
|
||||||
|
|
||||||
// Is the loader empty?
|
|
||||||
if (this.loader.queueSize == 0)
|
|
||||||
{
|
|
||||||
if (this.onCreateCallback !== null)
|
|
||||||
{
|
|
||||||
this.onCreateCallback.call(this.callbackContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
this._loadComplete = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// No init? Then there was nothing to load either
|
|
||||||
if (this.onCreateCallback !== null)
|
|
||||||
{
|
|
||||||
this.onCreateCallback.call(this.callbackContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
this._loadComplete = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public setCallbacks(initCallback = null, createCallback = null, updateCallback = null, renderCallback = null) {
|
|
||||||
|
|
||||||
this.onInitCallback = initCallback;
|
|
||||||
this.onCreateCallback = createCallback;
|
|
||||||
this.onUpdateCallback = updateCallback;
|
|
||||||
this.onRenderCallback = renderCallback;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public switchState(state, clearWorld: bool = true, clearCache: bool = false) {
|
|
||||||
|
|
||||||
if (this.isBooted == false)
|
|
||||||
{
|
|
||||||
this._pendingState = state;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prototype?
|
|
||||||
if (typeof state === 'function')
|
|
||||||
{
|
|
||||||
state = new state(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ok, have we got the right functions?
|
|
||||||
if (state['create'] || state['update'])
|
|
||||||
{
|
|
||||||
this.callbackContext = state;
|
|
||||||
|
|
||||||
this.onInitCallback = null;
|
|
||||||
this.onCreateCallback = null;
|
|
||||||
this.onUpdateCallback = null;
|
|
||||||
this.onRenderCallback = null;
|
|
||||||
this.onPausedCallback = null;
|
|
||||||
|
|
||||||
// Bingo, let's set them up
|
|
||||||
if (state['init'])
|
|
||||||
{
|
|
||||||
this.onInitCallback = state['init'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state['create'])
|
|
||||||
{
|
|
||||||
this.onCreateCallback = state['create'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state['update'])
|
|
||||||
{
|
|
||||||
this.onUpdateCallback = state['update'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state['render'])
|
|
||||||
{
|
|
||||||
this.onRenderCallback = state['render'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state['paused'])
|
|
||||||
{
|
|
||||||
this.onPausedCallback = state['paused'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (clearWorld)
|
|
||||||
{
|
|
||||||
this.world.destroy();
|
|
||||||
|
|
||||||
if (clearCache == true)
|
|
||||||
{
|
|
||||||
this.cache.destroy();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this._loadComplete = false;
|
|
||||||
|
|
||||||
this.startState();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new Error("Invalid State object given. Must contain at least a create or update function.");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Nuke the whole game from orbit
|
|
||||||
public destroy() {
|
|
||||||
|
|
||||||
this.callbackContext = null;
|
|
||||||
this.onInitCallback = null;
|
|
||||||
this.onCreateCallback = null;
|
|
||||||
this.onUpdateCallback = null;
|
|
||||||
this.onRenderCallback = null;
|
|
||||||
this.onPausedCallback = null;
|
|
||||||
this.cache = null;
|
|
||||||
this.input = null;
|
|
||||||
this.loader = null;
|
|
||||||
this.sound = null;
|
|
||||||
this.stage = null;
|
|
||||||
this.time = null;
|
|
||||||
this.world = null;
|
|
||||||
this.isBooted = false;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public get paused(): bool {
|
|
||||||
return this._paused;
|
|
||||||
}
|
|
||||||
|
|
||||||
public set paused(value: bool) {
|
|
||||||
|
|
||||||
if (value == true && this._paused == false)
|
|
||||||
{
|
|
||||||
this._paused = true;
|
|
||||||
}
|
|
||||||
else if (value == false && this._paused == true)
|
|
||||||
{
|
|
||||||
this._paused = false;
|
|
||||||
this.time.time = Date.now();
|
|
||||||
this.input.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public get framerate(): number {
|
|
||||||
return 1000 / this._step;
|
|
||||||
}
|
|
||||||
|
|
||||||
public set framerate(value: number) {
|
|
||||||
|
|
||||||
this._step = 1000 / value;
|
|
||||||
|
|
||||||
if (this._maxAccumulation < this._step)
|
|
||||||
{
|
|
||||||
this._maxAccumulation = this._step;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handy Proxy methods
|
|
||||||
|
|
||||||
public createCamera(x: number, y: number, width: number, height: number): Camera {
|
|
||||||
return this.world.createCamera(x, y, width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
public createGeomSprite(x: number, y: number): GeomSprite {
|
|
||||||
return this.world.createGeomSprite(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
public createSprite(x: number, y: number, key?: string = ''): Sprite {
|
|
||||||
return this.world.createSprite(x, y, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public createDynamicTexture(width: number, height: number): DynamicTexture {
|
|
||||||
return this.world.createDynamicTexture(width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
public createGroup(MaxSize?: number = 0): Group {
|
|
||||||
return this.world.createGroup(MaxSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
public createParticle(): Particle {
|
|
||||||
return this.world.createParticle();
|
|
||||||
}
|
|
||||||
|
|
||||||
public createEmitter(x?: number = 0, y?: number = 0, size?: number = 0): Emitter {
|
|
||||||
return this.world.createEmitter(x, y, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
public createScrollZone(key: string, x?: number = 0, y?: number = 0, width?: number = 0, height?: number = 0): ScrollZone {
|
|
||||||
return this.world.createScrollZone(key, x, y, width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
public createTilemap(key: string, mapData: string, format: number, resizeWorld: bool = true, tileWidth?: number = 0, tileHeight?: number = 0): Tilemap {
|
|
||||||
return this.world.createTilemap(key, mapData, format, resizeWorld, tileWidth, tileHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
public createTween(obj): Tween {
|
|
||||||
return this.tweens.create(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
public collide(objectOrGroup1: Basic = null, objectOrGroup2: Basic = null, notifyCallback = null): bool {
|
|
||||||
return this.collision.overlap(objectOrGroup1, objectOrGroup2, notifyCallback, Collision.separate);
|
|
||||||
}
|
|
||||||
|
|
||||||
public get camera(): Camera {
|
|
||||||
return this.world.cameras.current;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,769 +0,0 @@
|
|||||||
/// <reference path="Basic.ts" />
|
|
||||||
/// <reference path="Game.ts" />
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Phaser - Group
|
|
||||||
*
|
|
||||||
* This class is used for organising, updating and sorting game objects.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
module Phaser {
|
|
||||||
|
|
||||||
export class Group extends Basic {
|
|
||||||
|
|
||||||
constructor(game: Game, MaxSize?: number = 0) {
|
|
||||||
|
|
||||||
super(game);
|
|
||||||
|
|
||||||
this.isGroup = true;
|
|
||||||
this.members = [];
|
|
||||||
this.length = 0;
|
|
||||||
this._maxSize = MaxSize;
|
|
||||||
this._marker = 0;
|
|
||||||
this._sortIndex = null;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Use with <code>sort()</code> to sort in ascending order.
|
|
||||||
*/
|
|
||||||
public static ASCENDING: number = -1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Use with <code>sort()</code> to sort in descending order.
|
|
||||||
*/
|
|
||||||
public static DESCENDING: number = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Array of all the <code>Basic</code>s that exist in this group.
|
|
||||||
*/
|
|
||||||
public members: Basic[];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The number of entries in the members array.
|
|
||||||
* For performance and safety you should check this variable
|
|
||||||
* instead of members.length unless you really know what you're doing!
|
|
||||||
*/
|
|
||||||
public length: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal tracker for the maximum capacity of the group.
|
|
||||||
* Default is 0, or no max capacity.
|
|
||||||
*/
|
|
||||||
private _maxSize: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal helper variable for recycling objects a la <code>Emitter</code>.
|
|
||||||
*/
|
|
||||||
private _marker: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper for sort.
|
|
||||||
*/
|
|
||||||
private _sortIndex: string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper for sort.
|
|
||||||
*/
|
|
||||||
private _sortOrder: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Override this function to handle any deleting or "shutdown" type operations you might need,
|
|
||||||
* such as removing traditional Flash children like Basic objects.
|
|
||||||
*/
|
|
||||||
public destroy() {
|
|
||||||
|
|
||||||
if (this.members != null)
|
|
||||||
{
|
|
||||||
var basic: Basic;
|
|
||||||
var i: number = 0;
|
|
||||||
|
|
||||||
while (i < this.length)
|
|
||||||
{
|
|
||||||
basic = this.members[i++];
|
|
||||||
|
|
||||||
if (basic != null)
|
|
||||||
{
|
|
||||||
basic.destroy();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.members.length = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
this._sortIndex = null;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Automatically goes through and calls update on everything you added.
|
|
||||||
*/
|
|
||||||
public update() {
|
|
||||||
|
|
||||||
var basic: Basic;
|
|
||||||
var i: number = 0;
|
|
||||||
|
|
||||||
while (i < this.length)
|
|
||||||
{
|
|
||||||
basic = this.members[i++];
|
|
||||||
|
|
||||||
if ((basic != null) && basic.exists && basic.active)
|
|
||||||
{
|
|
||||||
basic.preUpdate();
|
|
||||||
basic.update();
|
|
||||||
basic.postUpdate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Automatically goes through and calls render on everything you added.
|
|
||||||
*/
|
|
||||||
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number) {
|
|
||||||
|
|
||||||
var basic: Basic;
|
|
||||||
var i: number = 0;
|
|
||||||
|
|
||||||
while (i < this.length)
|
|
||||||
{
|
|
||||||
basic = this.members[i++];
|
|
||||||
|
|
||||||
if ((basic != null) && basic.exists && basic.visible)
|
|
||||||
{
|
|
||||||
basic.render(camera, cameraOffsetX, cameraOffsetY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The maximum capacity of this group. Default is 0, meaning no max capacity, and the group can just grow.
|
|
||||||
*/
|
|
||||||
public get maxSize(): number {
|
|
||||||
return this._maxSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
public set maxSize(Size: number) {
|
|
||||||
|
|
||||||
this._maxSize = Size;
|
|
||||||
|
|
||||||
if (this._marker >= this._maxSize)
|
|
||||||
{
|
|
||||||
this._marker = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((this._maxSize == 0) || (this.members == null) || (this._maxSize >= this.members.length))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//If the max size has shrunk, we need to get rid of some objects
|
|
||||||
var basic: Basic;
|
|
||||||
var i: number = this._maxSize;
|
|
||||||
var l: number = this.members.length;
|
|
||||||
|
|
||||||
while (i < l)
|
|
||||||
{
|
|
||||||
basic = this.members[i++];
|
|
||||||
|
|
||||||
if (basic != null)
|
|
||||||
{
|
|
||||||
basic.destroy();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.length = this.members.length = this._maxSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a new <code>Basic</code> subclass (Basic, Basic, Enemy, etc) to the group.
|
|
||||||
* Group will try to replace a null member of the array first.
|
|
||||||
* Failing that, Group will add it to the end of the member array,
|
|
||||||
* assuming there is room for it, and doubling the size of the array if necessary.
|
|
||||||
*
|
|
||||||
* <p>WARNING: If the group has a maxSize that has already been met,
|
|
||||||
* the object will NOT be added to the group!</p>
|
|
||||||
*
|
|
||||||
* @param Object The object you want to add to the group.
|
|
||||||
*
|
|
||||||
* @return The same <code>Basic</code> object that was passed in.
|
|
||||||
*/
|
|
||||||
public add(Object: Basic) {
|
|
||||||
|
|
||||||
//Don't bother adding an object twice.
|
|
||||||
if (this.members.indexOf(Object) >= 0)
|
|
||||||
{
|
|
||||||
return Object;
|
|
||||||
}
|
|
||||||
|
|
||||||
//First, look for a null entry where we can add the object.
|
|
||||||
var i: number = 0;
|
|
||||||
var l: number = this.members.length;
|
|
||||||
|
|
||||||
while (i < l)
|
|
||||||
{
|
|
||||||
if (this.members[i] == null)
|
|
||||||
{
|
|
||||||
this.members[i] = Object;
|
|
||||||
|
|
||||||
if (i >= this.length)
|
|
||||||
{
|
|
||||||
this.length = i + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Object;
|
|
||||||
}
|
|
||||||
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Failing that, expand the array (if we can) and add the object.
|
|
||||||
if (this._maxSize > 0)
|
|
||||||
{
|
|
||||||
if (this.members.length >= this._maxSize)
|
|
||||||
{
|
|
||||||
return Object;
|
|
||||||
}
|
|
||||||
else if (this.members.length * 2 <= this._maxSize)
|
|
||||||
{
|
|
||||||
this.members.length *= 2;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.members.length = this._maxSize;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.members.length *= 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
//If we made it this far, then we successfully grew the group,
|
|
||||||
//and we can go ahead and add the object at the first open slot.
|
|
||||||
this.members[i] = Object;
|
|
||||||
this.length = i + 1;
|
|
||||||
|
|
||||||
return Object;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Recycling is designed to help you reuse game objects without always re-allocating or "newing" them.
|
|
||||||
*
|
|
||||||
* <p>If you specified a maximum size for this group (like in Emitter),
|
|
||||||
* then recycle will employ what we're calling "rotating" recycling.
|
|
||||||
* Recycle() will first check to see if the group is at capacity yet.
|
|
||||||
* If group is not yet at capacity, recycle() returns a new object.
|
|
||||||
* If the group IS at capacity, then recycle() just returns the next object in line.</p>
|
|
||||||
*
|
|
||||||
* <p>If you did NOT specify a maximum size for this group,
|
|
||||||
* then recycle() will employ what we're calling "grow-style" recycling.
|
|
||||||
* Recycle() will return either the first object with exists == false,
|
|
||||||
* or, finding none, add a new object to the array,
|
|
||||||
* doubling the size of the array if necessary.</p>
|
|
||||||
*
|
|
||||||
* <p>WARNING: If this function needs to create a new object,
|
|
||||||
* and no object class was provided, it will return null
|
|
||||||
* instead of a valid object!</p>
|
|
||||||
*
|
|
||||||
* @param ObjectClass The class type you want to recycle (e.g. Basic, EvilRobot, etc). Do NOT "new" the class in the parameter!
|
|
||||||
*
|
|
||||||
* @return A reference to the object that was created. Don't forget to cast it back to the Class you want (e.g. myObject = myGroup.recycle(myObjectClass) as myObjectClass;).
|
|
||||||
*/
|
|
||||||
public recycle(ObjectClass = null) {
|
|
||||||
|
|
||||||
var basic;
|
|
||||||
|
|
||||||
if (this._maxSize > 0)
|
|
||||||
{
|
|
||||||
if (this.length < this._maxSize)
|
|
||||||
{
|
|
||||||
if (ObjectClass == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.add(new ObjectClass(this._game));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
basic = this.members[this._marker++];
|
|
||||||
|
|
||||||
if (this._marker >= this._maxSize)
|
|
||||||
{
|
|
||||||
this._marker = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return basic;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
basic = this.getFirstAvailable(ObjectClass);
|
|
||||||
|
|
||||||
if (basic != null)
|
|
||||||
{
|
|
||||||
return basic;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ObjectClass == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.add(new ObjectClass(this._game));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes an object from the group.
|
|
||||||
*
|
|
||||||
* @param Object The <code>Basic</code> you want to remove.
|
|
||||||
* @param Splice Whether the object should be cut from the array entirely or not.
|
|
||||||
*
|
|
||||||
* @return The removed object.
|
|
||||||
*/
|
|
||||||
public remove(Object: Basic, Splice: bool = false): Basic {
|
|
||||||
|
|
||||||
var index: number = this.members.indexOf(Object);
|
|
||||||
|
|
||||||
if ((index < 0) || (index >= this.members.length))
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Splice)
|
|
||||||
{
|
|
||||||
this.members.splice(index, 1);
|
|
||||||
this.length--;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.members[index] = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Object;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replaces an existing <code>Basic</code> with a new one.
|
|
||||||
*
|
|
||||||
* @param OldObject The object you want to replace.
|
|
||||||
* @param NewObject The new object you want to use instead.
|
|
||||||
*
|
|
||||||
* @return The new object.
|
|
||||||
*/
|
|
||||||
public replace(OldObject: Basic, NewObject: Basic): Basic {
|
|
||||||
|
|
||||||
var index: number = this.members.indexOf(OldObject);
|
|
||||||
|
|
||||||
if ((index < 0) || (index >= this.members.length))
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.members[index] = NewObject;
|
|
||||||
|
|
||||||
return NewObject;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Call this function to sort the group according to a particular value and order.
|
|
||||||
* For example, to sort game objects for Zelda-style overlaps you might call
|
|
||||||
* <code>myGroup.sort("y",Group.ASCENDING)</code> at the bottom of your
|
|
||||||
* <code>State.update()</code> override. To sort all existing objects after
|
|
||||||
* a big explosion or bomb attack, you might call <code>myGroup.sort("exists",Group.DESCENDING)</code>.
|
|
||||||
*
|
|
||||||
* @param Index The <code>string</code> name of the member variable you want to sort on. Default value is "y".
|
|
||||||
* @param Order A <code>Group</code> constant that defines the sort order. Possible values are <code>Group.ASCENDING</code> and <code>Group.DESCENDING</code>. Default value is <code>Group.ASCENDING</code>.
|
|
||||||
*/
|
|
||||||
public sort(Index: string = "y", Order: number = Group.ASCENDING) {
|
|
||||||
|
|
||||||
this._sortIndex = Index;
|
|
||||||
this._sortOrder = Order;
|
|
||||||
this.members.sort(this.sortHandler);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Go through and set the specified variable to the specified value on all members of the group.
|
|
||||||
*
|
|
||||||
* @param VariableName The string representation of the variable name you want to modify, for example "visible" or "scrollFactor".
|
|
||||||
* @param Value The value you want to assign to that variable.
|
|
||||||
* @param Recurse Default value is true, meaning if <code>setAll()</code> encounters a member that is a group, it will call <code>setAll()</code> on that group rather than modifying its variable.
|
|
||||||
*/
|
|
||||||
public setAll(VariableName: string, Value: Object, Recurse: bool = true) {
|
|
||||||
|
|
||||||
var basic: Basic;
|
|
||||||
var i: number = 0;
|
|
||||||
|
|
||||||
while (i < length)
|
|
||||||
{
|
|
||||||
basic = this.members[i++];
|
|
||||||
|
|
||||||
if (basic != null)
|
|
||||||
{
|
|
||||||
if (Recurse && (basic.isGroup == true))
|
|
||||||
{
|
|
||||||
<Group> basic['setAll'](VariableName, Value, Recurse);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
basic[VariableName] = Value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Go through and call the specified function on all members of the group.
|
|
||||||
* Currently only works on functions that have no required parameters.
|
|
||||||
*
|
|
||||||
* @param FunctionName The string representation of the function you want to call on each object, for example "kill()" or "init()".
|
|
||||||
* @param Recurse Default value is true, meaning if <code>callAll()</code> encounters a member that is a group, it will call <code>callAll()</code> on that group rather than calling the group's function.
|
|
||||||
*/
|
|
||||||
public callAll(FunctionName: string, Recurse: bool = true) {
|
|
||||||
|
|
||||||
var basic: Basic;
|
|
||||||
var i: number = 0;
|
|
||||||
|
|
||||||
while (i < this.length)
|
|
||||||
{
|
|
||||||
basic = this.members[i++];
|
|
||||||
|
|
||||||
if (basic != null)
|
|
||||||
{
|
|
||||||
if (Recurse && (basic.isGroup == true))
|
|
||||||
{
|
|
||||||
<Group> basic['callAll'](FunctionName, Recurse);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
basic[FunctionName]();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public forEach(callback, recursive: bool = false) {
|
|
||||||
|
|
||||||
var basic;
|
|
||||||
var i: number = 0;
|
|
||||||
|
|
||||||
while (i < this.length)
|
|
||||||
{
|
|
||||||
basic = this.members[i++];
|
|
||||||
|
|
||||||
if (basic != null)
|
|
||||||
{
|
|
||||||
if (recursive && (basic.isGroup == true))
|
|
||||||
{
|
|
||||||
basic.forEach(callback, true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
callback.call(this, basic);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public forEachAlive(context, callback, recursive: bool = false) {
|
|
||||||
|
|
||||||
var basic;
|
|
||||||
var i: number = 0;
|
|
||||||
|
|
||||||
while (i < this.length)
|
|
||||||
{
|
|
||||||
basic = this.members[i++];
|
|
||||||
|
|
||||||
if (basic != null && basic.alive)
|
|
||||||
{
|
|
||||||
if (recursive && (basic.isGroup == true))
|
|
||||||
{
|
|
||||||
basic.forEachAlive(context, callback, true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
callback.call(context, basic);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Call this function to retrieve the first object with exists == false in the group.
|
|
||||||
* This is handy for recycling in general, e.g. respawning enemies.
|
|
||||||
*
|
|
||||||
* @param ObjectClass An optional parameter that lets you narrow the results to instances of this particular class.
|
|
||||||
*
|
|
||||||
* @return A <code>Basic</code> currently flagged as not existing.
|
|
||||||
*/
|
|
||||||
public getFirstAvailable(ObjectClass = null) {
|
|
||||||
|
|
||||||
var basic;
|
|
||||||
var i: number = 0;
|
|
||||||
|
|
||||||
while (i < this.length)
|
|
||||||
{
|
|
||||||
basic = this.members[i++];
|
|
||||||
|
|
||||||
if ((basic != null) && !basic.exists && ((ObjectClass == null) || (typeof basic === ObjectClass)))
|
|
||||||
{
|
|
||||||
return basic;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Call this function to retrieve the first index set to 'null'.
|
|
||||||
* Returns -1 if no index stores a null object.
|
|
||||||
*
|
|
||||||
* @return An <code>int</code> indicating the first null slot in the group.
|
|
||||||
*/
|
|
||||||
public getFirstNull(): number {
|
|
||||||
|
|
||||||
var basic: Basic;
|
|
||||||
var i: number = 0;
|
|
||||||
var l: number = this.members.length;
|
|
||||||
|
|
||||||
while (i < l)
|
|
||||||
{
|
|
||||||
if (this.members[i] == null)
|
|
||||||
{
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Call this function to retrieve the first object with exists == true in the group.
|
|
||||||
* This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
|
|
||||||
*
|
|
||||||
* @return A <code>Basic</code> currently flagged as existing.
|
|
||||||
*/
|
|
||||||
public getFirstExtant(): Basic {
|
|
||||||
|
|
||||||
var basic: Basic;
|
|
||||||
var i: number = 0;
|
|
||||||
|
|
||||||
while (i < length)
|
|
||||||
{
|
|
||||||
basic = this.members[i++];
|
|
||||||
|
|
||||||
if ((basic != null) && basic.exists)
|
|
||||||
{
|
|
||||||
return basic;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Call this function to retrieve the first object with dead == false in the group.
|
|
||||||
* This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
|
|
||||||
*
|
|
||||||
* @return A <code>Basic</code> currently flagged as not dead.
|
|
||||||
*/
|
|
||||||
public getFirstAlive(): Basic {
|
|
||||||
|
|
||||||
var basic: Basic;
|
|
||||||
var i: number = 0;
|
|
||||||
|
|
||||||
while (i < this.length)
|
|
||||||
{
|
|
||||||
basic = this.members[i++];
|
|
||||||
|
|
||||||
if ((basic != null) && basic.exists && basic.alive)
|
|
||||||
{
|
|
||||||
return basic;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Call this function to retrieve the first object with dead == true in the group.
|
|
||||||
* This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
|
|
||||||
*
|
|
||||||
* @return A <code>Basic</code> currently flagged as dead.
|
|
||||||
*/
|
|
||||||
public getFirstDead(): Basic {
|
|
||||||
|
|
||||||
var basic: Basic;
|
|
||||||
var i: number = 0;
|
|
||||||
|
|
||||||
while (i < this.length)
|
|
||||||
{
|
|
||||||
basic = this.members[i++];
|
|
||||||
|
|
||||||
if ((basic != null) && !basic.alive)
|
|
||||||
{
|
|
||||||
return basic;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Call this function to find out how many members of the group are not dead.
|
|
||||||
*
|
|
||||||
* @return The number of <code>Basic</code>s flagged as not dead. Returns -1 if group is empty.
|
|
||||||
*/
|
|
||||||
public countLiving(): number {
|
|
||||||
|
|
||||||
var count: number = -1;
|
|
||||||
var basic: Basic;
|
|
||||||
var i: number = 0;
|
|
||||||
|
|
||||||
while (i < this.length)
|
|
||||||
{
|
|
||||||
basic = this.members[i++];
|
|
||||||
|
|
||||||
if (basic != null)
|
|
||||||
{
|
|
||||||
if (count < 0)
|
|
||||||
{
|
|
||||||
count = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (basic.exists && basic.alive)
|
|
||||||
{
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Call this function to find out how many members of the group are dead.
|
|
||||||
*
|
|
||||||
* @return The number of <code>Basic</code>s flagged as dead. Returns -1 if group is empty.
|
|
||||||
*/
|
|
||||||
public countDead(): number {
|
|
||||||
|
|
||||||
var count: number = -1;
|
|
||||||
var basic: Basic;
|
|
||||||
var i: number = 0;
|
|
||||||
|
|
||||||
while (i < this.length)
|
|
||||||
{
|
|
||||||
basic = this.members[i++];
|
|
||||||
|
|
||||||
if (basic != null)
|
|
||||||
{
|
|
||||||
if (count < 0)
|
|
||||||
{
|
|
||||||
count = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!basic.alive)
|
|
||||||
{
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a member at random from the group.
|
|
||||||
*
|
|
||||||
* @param StartIndex Optional offset off the front of the array. Default value is 0, or the beginning of the array.
|
|
||||||
* @param Length Optional restriction on the number of values you want to randomly select from.
|
|
||||||
*
|
|
||||||
* @return A <code>Basic</code> from the members list.
|
|
||||||
*/
|
|
||||||
public getRandom(StartIndex: number = 0, Length: number = 0): Basic {
|
|
||||||
|
|
||||||
if (Length == 0)
|
|
||||||
{
|
|
||||||
Length = this.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this._game.math.getRandom(this.members, StartIndex, Length);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove all instances of <code>Basic</code> subclass (Basic, Block, etc) from the list.
|
|
||||||
* WARNING: does not destroy() or kill() any of these objects!
|
|
||||||
*/
|
|
||||||
public clear() {
|
|
||||||
this.length = this.members.length = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calls kill on the group's members and then on the group itself.
|
|
||||||
*/
|
|
||||||
public kill() {
|
|
||||||
|
|
||||||
var basic: Basic;
|
|
||||||
var i: number = 0;
|
|
||||||
|
|
||||||
while (i < this.length)
|
|
||||||
{
|
|
||||||
basic = this.members[i++];
|
|
||||||
|
|
||||||
if ((basic != null) && basic.exists)
|
|
||||||
{
|
|
||||||
basic.kill();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper function for the sort process.
|
|
||||||
*
|
|
||||||
* @param Obj1 The first object being sorted.
|
|
||||||
* @param Obj2 The second object being sorted.
|
|
||||||
*
|
|
||||||
* @return An integer value: -1 (Obj1 before Obj2), 0 (same), or 1 (Obj1 after Obj2).
|
|
||||||
*/
|
|
||||||
public sortHandler(Obj1: Basic, Obj2: Basic): number {
|
|
||||||
|
|
||||||
if (Obj1[this._sortIndex] < Obj2[this._sortIndex])
|
|
||||||
{
|
|
||||||
return this._sortOrder;
|
|
||||||
}
|
|
||||||
else if (Obj1[this._sortIndex] > Obj2[this._sortIndex])
|
|
||||||
{
|
|
||||||
return -this._sortOrder;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,347 +0,0 @@
|
|||||||
/// <reference path="Game.ts" />
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Phaser - Loader
|
|
||||||
*
|
|
||||||
* The Loader handles loading all external content such as Images, Sounds, Texture Atlases and data files.
|
|
||||||
* It uses a combination of Image() loading and xhr and provides for progress and completion callbacks.
|
|
||||||
*/
|
|
||||||
|
|
||||||
module Phaser {
|
|
||||||
|
|
||||||
export class Loader {
|
|
||||||
|
|
||||||
constructor(game: Game, callback) {
|
|
||||||
|
|
||||||
this._game = game;
|
|
||||||
this._gameCreateComplete = callback;
|
|
||||||
this._keys = [];
|
|
||||||
this._fileList = {};
|
|
||||||
this._xhr = new XMLHttpRequest();
|
|
||||||
this._queueSize = 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private _game: Game;
|
|
||||||
private _keys: string[];
|
|
||||||
private _fileList;
|
|
||||||
private _gameCreateComplete;
|
|
||||||
private _onComplete;
|
|
||||||
private _onFileLoad;
|
|
||||||
private _progressChunk: number;
|
|
||||||
private _xhr: XMLHttpRequest;
|
|
||||||
private _queueSize: number;
|
|
||||||
|
|
||||||
public hasLoaded: bool;
|
|
||||||
public progress: number;
|
|
||||||
|
|
||||||
public reset() {
|
|
||||||
this._queueSize = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get queueSize(): number {
|
|
||||||
|
|
||||||
return this._queueSize;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public addImageFile(key: string, url: string) {
|
|
||||||
|
|
||||||
if (this.checkKeyExists(key) === false)
|
|
||||||
{
|
|
||||||
this._queueSize++;
|
|
||||||
this._fileList[key] = { type: 'image', key: key, url: url, data: null, error: false, loaded: false };
|
|
||||||
this._keys.push(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public addSpriteSheet(key: string, url: string, frameWidth: number, frameHeight: number, frameMax?: number = -1) {
|
|
||||||
|
|
||||||
if (this.checkKeyExists(key) === false)
|
|
||||||
{
|
|
||||||
this._queueSize++;
|
|
||||||
this._fileList[key] = { type: 'spritesheet', key: key, url: url, data: null, frameWidth: frameWidth, frameHeight: frameHeight, frameMax: frameMax, error: false, loaded: false };
|
|
||||||
this._keys.push(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public addTextureAtlas(key: string, url: string, jsonURL?: string = null, jsonData? = null) {
|
|
||||||
|
|
||||||
if (this.checkKeyExists(key) === false)
|
|
||||||
{
|
|
||||||
if (jsonURL !== null)
|
|
||||||
{
|
|
||||||
// A URL to a json file has been given
|
|
||||||
this._queueSize++;
|
|
||||||
this._fileList[key] = { type: 'textureatlas', key: key, url: url, data: null, jsonURL: jsonURL, jsonData: null, error: false, loaded: false };
|
|
||||||
this._keys.push(key);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// A json string or object has been given
|
|
||||||
if (typeof jsonData === 'string')
|
|
||||||
{
|
|
||||||
var data = JSON.parse(jsonData);
|
|
||||||
// Malformed?
|
|
||||||
if (data['frames'])
|
|
||||||
{
|
|
||||||
this._queueSize++;
|
|
||||||
this._fileList[key] = { type: 'textureatlas', key: key, url: url, data: null, jsonURL: null, jsonData: data['frames'], error: false, loaded: false };
|
|
||||||
this._keys.push(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Malformed?
|
|
||||||
if (jsonData['frames'])
|
|
||||||
{
|
|
||||||
this._queueSize++;
|
|
||||||
this._fileList[key] = { type: 'textureatlas', key: key, url: url, data: null, jsonURL: null, jsonData: jsonData['frames'], error: false, loaded: false };
|
|
||||||
this._keys.push(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public addAudioFile(key: string, url: string) {
|
|
||||||
|
|
||||||
if (this.checkKeyExists(key) === false)
|
|
||||||
{
|
|
||||||
this._queueSize++;
|
|
||||||
this._fileList[key] = { type: 'audio', key: key, url: url, data: null, buffer: null, error: false, loaded: false };
|
|
||||||
this._keys.push(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public addTextFile(key: string, url: string) {
|
|
||||||
|
|
||||||
if (this.checkKeyExists(key) === false)
|
|
||||||
{
|
|
||||||
this._queueSize++;
|
|
||||||
this._fileList[key] = { type: 'text', key: key, url: url, data: null, error: false, loaded: false };
|
|
||||||
this._keys.push(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public removeFile(key: string) {
|
|
||||||
|
|
||||||
delete this._fileList[key];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public removeAll() {
|
|
||||||
|
|
||||||
this._fileList = {};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public load(onFileLoadCallback = null, onCompleteCallback = null) {
|
|
||||||
|
|
||||||
this.progress = 0;
|
|
||||||
this.hasLoaded = false;
|
|
||||||
|
|
||||||
this._onComplete = onCompleteCallback;
|
|
||||||
|
|
||||||
if (onCompleteCallback == null)
|
|
||||||
{
|
|
||||||
this._onComplete = this._game.onCreateCallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
this._onFileLoad = onFileLoadCallback;
|
|
||||||
|
|
||||||
if (this._keys.length > 0)
|
|
||||||
{
|
|
||||||
this._progressChunk = 100 / this._keys.length;
|
|
||||||
this.loadFile();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.progress = 1;
|
|
||||||
this.hasLoaded = true;
|
|
||||||
this._gameCreateComplete.call(this._game);
|
|
||||||
|
|
||||||
if (this._onComplete !== null)
|
|
||||||
{
|
|
||||||
this._onComplete.call(this._game.callbackContext);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private loadFile() {
|
|
||||||
|
|
||||||
var file = this._fileList[this._keys.pop()];
|
|
||||||
|
|
||||||
// Image or Data?
|
|
||||||
|
|
||||||
switch (file.type)
|
|
||||||
{
|
|
||||||
case 'image':
|
|
||||||
case 'spritesheet':
|
|
||||||
case 'textureatlas':
|
|
||||||
file.data = new Image();
|
|
||||||
file.data.name = file.key;
|
|
||||||
file.data.onload = () => this.fileComplete(file.key);
|
|
||||||
file.data.onerror = () => this.fileError(file.key);
|
|
||||||
file.data.src = file.url;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'audio':
|
|
||||||
this._xhr.open("GET", file.url, true);
|
|
||||||
this._xhr.responseType = "arraybuffer";
|
|
||||||
this._xhr.onload = () => this.fileComplete(file.key);
|
|
||||||
this._xhr.onerror = () => this.fileError(file.key);
|
|
||||||
this._xhr.send();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'text':
|
|
||||||
this._xhr.open("GET", file.url, true);
|
|
||||||
this._xhr.responseType = "text";
|
|
||||||
this._xhr.onload = () => this.fileComplete(file.key);
|
|
||||||
this._xhr.onerror = () => this.fileError(file.key);
|
|
||||||
this._xhr.send();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private fileError(key: string) {
|
|
||||||
|
|
||||||
this._fileList[key].loaded = true;
|
|
||||||
this._fileList[key].error = true;
|
|
||||||
|
|
||||||
this.nextFile(key, false);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private fileComplete(key: string) {
|
|
||||||
|
|
||||||
this._fileList[key].loaded = true;
|
|
||||||
|
|
||||||
var file = this._fileList[key];
|
|
||||||
var loadNext: bool = true;
|
|
||||||
|
|
||||||
switch (file.type)
|
|
||||||
{
|
|
||||||
case 'image':
|
|
||||||
this._game.cache.addImage(file.key, file.url, file.data);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'spritesheet':
|
|
||||||
this._game.cache.addSpriteSheet(file.key, file.url, file.data, file.frameWidth, file.frameHeight, file.frameMax);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'textureatlas':
|
|
||||||
if (file.jsonURL == null)
|
|
||||||
{
|
|
||||||
this._game.cache.addTextureAtlas(file.key, file.url, file.data, file.jsonData);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Load the JSON before carrying on with the next file
|
|
||||||
loadNext = false;
|
|
||||||
this._xhr.open("GET", file.jsonURL, true);
|
|
||||||
this._xhr.responseType = "text";
|
|
||||||
this._xhr.onload = () => this.jsonLoadComplete(file.key);
|
|
||||||
this._xhr.onerror = () => this.jsonLoadError(file.key);
|
|
||||||
this._xhr.send();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'audio':
|
|
||||||
file.data = this._xhr.response;
|
|
||||||
this._game.cache.addSound(file.key, file.url, file.data);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'text':
|
|
||||||
file.data = this._xhr.response;
|
|
||||||
this._game.cache.addText(file.key, file.url, file.data);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (loadNext)
|
|
||||||
{
|
|
||||||
this.nextFile(key, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private jsonLoadComplete(key: string) {
|
|
||||||
|
|
||||||
var data = JSON.parse(this._xhr.response);
|
|
||||||
|
|
||||||
// Malformed?
|
|
||||||
if (data['frames'])
|
|
||||||
{
|
|
||||||
var file = this._fileList[key];
|
|
||||||
this._game.cache.addTextureAtlas(file.key, file.url, file.data, data['frames']);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.nextFile(key, true);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private jsonLoadError(key: string) {
|
|
||||||
|
|
||||||
var file = this._fileList[key];
|
|
||||||
file.error = true;
|
|
||||||
this.nextFile(key, true);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private nextFile(previousKey: string, success: bool) {
|
|
||||||
|
|
||||||
this.progress = Math.round(this.progress + this._progressChunk);
|
|
||||||
|
|
||||||
if (this.progress > 1)
|
|
||||||
{
|
|
||||||
this.progress = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this._onFileLoad)
|
|
||||||
{
|
|
||||||
this._onFileLoad.call(this._game.callbackContext, this.progress, previousKey, success);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this._keys.length > 0)
|
|
||||||
{
|
|
||||||
this.loadFile();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.hasLoaded = true;
|
|
||||||
this.removeAll();
|
|
||||||
this._gameCreateComplete.call(this._game);
|
|
||||||
|
|
||||||
if (this._onComplete !== null)
|
|
||||||
{
|
|
||||||
this._onComplete.call(this._game.callbackContext);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private checkKeyExists(key: string): bool {
|
|
||||||
|
|
||||||
if (this._fileList[key])
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,331 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<PropertyGroup>
|
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
|
||||||
<ProjectGuid>{A90BE60F-CAEA-4747-904A-CDB097BA2459}</ProjectGuid>
|
|
||||||
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
|
|
||||||
<OutputType>Library</OutputType>
|
|
||||||
<OutputPath>bin</OutputPath>
|
|
||||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
|
||||||
<DebugType>full</DebugType>
|
|
||||||
<DebugSymbols>true</DebugSymbols>
|
|
||||||
<UseIISExpress>true</UseIISExpress>
|
|
||||||
<IISExpressSSLPort />
|
|
||||||
<IISExpressAnonymousAuthentication />
|
|
||||||
<IISExpressWindowsAuthentication />
|
|
||||||
<IISExpressUseClassicPipelineMode />
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup>
|
|
||||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
|
||||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup>
|
|
||||||
<RootNamespace>Phaser</RootNamespace>
|
|
||||||
</PropertyGroup>
|
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
|
||||||
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
|
|
||||||
<ProjectExtensions>
|
|
||||||
<VisualStudio>
|
|
||||||
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
|
|
||||||
<WebProjectProperties>
|
|
||||||
<UseIIS>True</UseIIS>
|
|
||||||
<AutoAssignPort>True</AutoAssignPort>
|
|
||||||
<DevelopmentServerPort>0</DevelopmentServerPort>
|
|
||||||
<DevelopmentServerVPath>/</DevelopmentServerVPath>
|
|
||||||
<IISUrl>http://localhost:51891/</IISUrl>
|
|
||||||
<NTLMAuthentication>False</NTLMAuthentication>
|
|
||||||
<UseCustomServer>False</UseCustomServer>
|
|
||||||
<CustomServerUrl>
|
|
||||||
</CustomServerUrl>
|
|
||||||
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
|
|
||||||
</WebProjectProperties>
|
|
||||||
</FlavorProperties>
|
|
||||||
</VisualStudio>
|
|
||||||
</ProjectExtensions>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
|
|
||||||
<TypeScriptTarget>ES5</TypeScriptTarget>
|
|
||||||
<TypeScriptIncludeComments>true</TypeScriptIncludeComments>
|
|
||||||
<TypeScriptSourceMap>false</TypeScriptSourceMap>
|
|
||||||
<TypeScriptOutFile>../build/phaser.js</TypeScriptOutFile>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
|
|
||||||
<TypeScriptTarget>ES5</TypeScriptTarget>
|
|
||||||
<TypeScriptIncludeComments>false</TypeScriptIncludeComments>
|
|
||||||
<TypeScriptSourceMap>false</TypeScriptSourceMap>
|
|
||||||
<TypeScriptOutFile>../build/phaser.js</TypeScriptOutFile>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="plugins\" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Content Include="AnimationManager.js">
|
|
||||||
<DependentUpon>AnimationManager.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="Collision.js">
|
|
||||||
<DependentUpon>Collision.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="DynamicTexture.js">
|
|
||||||
<DependentUpon>DynamicTexture.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="Game.js">
|
|
||||||
<DependentUpon>Game.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="GameMath.js">
|
|
||||||
<DependentUpon>GameMath.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="gameobjects\Emitter.js">
|
|
||||||
<DependentUpon>Emitter.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="gameobjects\GameObject.js">
|
|
||||||
<DependentUpon>GameObject.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="gameobjects\GeomSprite.js">
|
|
||||||
<DependentUpon>GeomSprite.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="gameobjects\Particle.js">
|
|
||||||
<DependentUpon>Particle.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<TypeScriptCompile Include="gameobjects\ScrollZone.ts" />
|
|
||||||
<TypeScriptCompile Include="gameobjects\ScrollRegion.ts" />
|
|
||||||
<Content Include="gameobjects\ScrollRegion.js">
|
|
||||||
<DependentUpon>ScrollRegion.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="gameobjects\ScrollZone.js">
|
|
||||||
<DependentUpon>ScrollZone.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="gameobjects\Sprite.js">
|
|
||||||
<DependentUpon>Sprite.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="gameobjects\Tilemap.js">
|
|
||||||
<DependentUpon>Tilemap.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="geom\Circle.js">
|
|
||||||
<DependentUpon>Circle.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="geom\IntersectResult.js">
|
|
||||||
<DependentUpon>IntersectResult.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="geom\Line.js">
|
|
||||||
<DependentUpon>Line.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<TypeScriptCompile Include="geom\MicroPoint.ts" />
|
|
||||||
<Content Include="geom\MicroPoint.js">
|
|
||||||
<DependentUpon>MicroPoint.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="geom\Point.js">
|
|
||||||
<DependentUpon>Point.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<TypeScriptCompile Include="geom\Quad.ts" />
|
|
||||||
<Content Include="geom\Quad.js">
|
|
||||||
<DependentUpon>Quad.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="geom\Rectangle.js">
|
|
||||||
<DependentUpon>Rectangle.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="SoundManager.js">
|
|
||||||
<DependentUpon>SoundManager.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="system\Sound.js">
|
|
||||||
<DependentUpon>Sound.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<TypeScriptCompile Include="system\Sound.ts" />
|
|
||||||
<TypeScriptCompile Include="SoundManager.ts" />
|
|
||||||
<Content Include="system\animation\Animation.js">
|
|
||||||
<DependentUpon>Animation.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="system\animation\AnimationLoader.js">
|
|
||||||
<DependentUpon>AnimationLoader.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="system\animation\Frame.js">
|
|
||||||
<DependentUpon>Frame.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="system\animation\FrameData.js">
|
|
||||||
<DependentUpon>FrameData.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="system\Camera.js">
|
|
||||||
<DependentUpon>Camera.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="system\Device.js">
|
|
||||||
<DependentUpon>Device.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="system\LinkedList.js">
|
|
||||||
<DependentUpon>LinkedList.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="system\QuadTree.js">
|
|
||||||
<DependentUpon>QuadTree.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="system\RandomDataGenerator.js">
|
|
||||||
<DependentUpon>RandomDataGenerator.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="system\RequestAnimationFrame.js">
|
|
||||||
<DependentUpon>RequestAnimationFrame.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="system\StageScaleMode.js">
|
|
||||||
<DependentUpon>StageScaleMode.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="system\Tile.js">
|
|
||||||
<DependentUpon>Tile.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<TypeScriptCompile Include="system\TilemapLayer.ts" />
|
|
||||||
<Content Include="system\TilemapLayer.js">
|
|
||||||
<DependentUpon>TilemapLayer.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="system\Tween.js">
|
|
||||||
<DependentUpon>Tween.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<TypeScriptCompile Include="system\Tween.ts" />
|
|
||||||
<TypeScriptCompile Include="system\Tile.ts" />
|
|
||||||
<TypeScriptCompile Include="system\StageScaleMode.ts" />
|
|
||||||
<TypeScriptCompile Include="system\RequestAnimationFrame.ts" />
|
|
||||||
<TypeScriptCompile Include="system\RandomDataGenerator.ts" />
|
|
||||||
<TypeScriptCompile Include="system\QuadTree.ts" />
|
|
||||||
<TypeScriptCompile Include="system\LinkedList.ts" />
|
|
||||||
<TypeScriptCompile Include="system\Device.ts" />
|
|
||||||
<TypeScriptCompile Include="system\Camera.ts" />
|
|
||||||
<Content Include="system\easing\Back.js">
|
|
||||||
<DependentUpon>Back.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="system\easing\Bounce.js">
|
|
||||||
<DependentUpon>Bounce.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="system\easing\Circular.js">
|
|
||||||
<DependentUpon>Circular.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="system\easing\Cubic.js">
|
|
||||||
<DependentUpon>Cubic.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="system\easing\Elastic.js">
|
|
||||||
<DependentUpon>Elastic.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="system\easing\Exponential.js">
|
|
||||||
<DependentUpon>Exponential.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="system\easing\Linear.js">
|
|
||||||
<DependentUpon>Linear.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="system\easing\Quadratic.js">
|
|
||||||
<DependentUpon>Quadratic.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="system\easing\Quartic.js">
|
|
||||||
<DependentUpon>Quartic.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="system\easing\Quintic.js">
|
|
||||||
<DependentUpon>Quintic.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="system\easing\Sinusoidal.js">
|
|
||||||
<DependentUpon>Sinusoidal.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="system\input\Finger.js">
|
|
||||||
<DependentUpon>Finger.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="system\input\Input.js">
|
|
||||||
<DependentUpon>Input.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="system\input\Keyboard.js">
|
|
||||||
<DependentUpon>Keyboard.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="system\input\Mouse.js">
|
|
||||||
<DependentUpon>Mouse.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="system\input\Touch.js">
|
|
||||||
<DependentUpon>Touch.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<TypeScriptCompile Include="system\input\Touch.ts" />
|
|
||||||
<TypeScriptCompile Include="system\input\Mouse.ts" />
|
|
||||||
<TypeScriptCompile Include="system\input\Keyboard.ts" />
|
|
||||||
<TypeScriptCompile Include="system\input\Input.ts" />
|
|
||||||
<TypeScriptCompile Include="system\input\Finger.ts" />
|
|
||||||
<TypeScriptCompile Include="system\easing\Sinusoidal.ts" />
|
|
||||||
<TypeScriptCompile Include="system\easing\Quintic.ts" />
|
|
||||||
<TypeScriptCompile Include="system\easing\Quartic.ts" />
|
|
||||||
<TypeScriptCompile Include="system\easing\Quadratic.ts" />
|
|
||||||
<TypeScriptCompile Include="system\easing\Linear.ts" />
|
|
||||||
<TypeScriptCompile Include="system\easing\Exponential.ts" />
|
|
||||||
<TypeScriptCompile Include="system\easing\Elastic.ts" />
|
|
||||||
<TypeScriptCompile Include="system\easing\Cubic.ts" />
|
|
||||||
<TypeScriptCompile Include="system\easing\Circular.ts" />
|
|
||||||
<TypeScriptCompile Include="system\easing\Bounce.ts" />
|
|
||||||
<TypeScriptCompile Include="system\easing\Back.ts" />
|
|
||||||
<TypeScriptCompile Include="system\animation\FrameData.ts" />
|
|
||||||
<TypeScriptCompile Include="system\animation\Frame.ts" />
|
|
||||||
<TypeScriptCompile Include="system\animation\AnimationLoader.ts" />
|
|
||||||
<TypeScriptCompile Include="system\animation\Animation.ts" />
|
|
||||||
<TypeScriptCompile Include="geom\Rectangle.ts" />
|
|
||||||
<TypeScriptCompile Include="geom\Point.ts" />
|
|
||||||
<TypeScriptCompile Include="geom\Line.ts" />
|
|
||||||
<TypeScriptCompile Include="geom\IntersectResult.ts" />
|
|
||||||
<TypeScriptCompile Include="geom\Circle.ts" />
|
|
||||||
<TypeScriptCompile Include="gameobjects\Tilemap.ts" />
|
|
||||||
<TypeScriptCompile Include="gameobjects\Sprite.ts" />
|
|
||||||
<TypeScriptCompile Include="gameobjects\Particle.ts" />
|
|
||||||
<TypeScriptCompile Include="gameobjects\GeomSprite.ts" />
|
|
||||||
<TypeScriptCompile Include="gameobjects\GameObject.ts" />
|
|
||||||
<TypeScriptCompile Include="gameobjects\Emitter.ts" />
|
|
||||||
<Content Include="Group.js">
|
|
||||||
<DependentUpon>Group.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="Loader.js">
|
|
||||||
<DependentUpon>Loader.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="Motion.js">
|
|
||||||
<DependentUpon>Motion.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="Phaser.js">
|
|
||||||
<DependentUpon>Phaser.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="Signal.js">
|
|
||||||
<DependentUpon>Signal.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="SignalBinding.js">
|
|
||||||
<DependentUpon>SignalBinding.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="Stage.js">
|
|
||||||
<DependentUpon>Stage.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="State.js">
|
|
||||||
<DependentUpon>State.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="Time.js">
|
|
||||||
<DependentUpon>Time.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="TweenManager.js">
|
|
||||||
<DependentUpon>TweenManager.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="World.js">
|
|
||||||
<DependentUpon>World.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<TypeScriptCompile Include="World.ts" />
|
|
||||||
<TypeScriptCompile Include="TweenManager.ts" />
|
|
||||||
<TypeScriptCompile Include="Time.ts" />
|
|
||||||
<TypeScriptCompile Include="State.ts" />
|
|
||||||
<TypeScriptCompile Include="Stage.ts" />
|
|
||||||
<TypeScriptCompile Include="SignalBinding.ts" />
|
|
||||||
<TypeScriptCompile Include="Signal.ts" />
|
|
||||||
<TypeScriptCompile Include="Phaser.ts" />
|
|
||||||
<TypeScriptCompile Include="Motion.ts" />
|
|
||||||
<TypeScriptCompile Include="Loader.ts" />
|
|
||||||
<TypeScriptCompile Include="Group.ts" />
|
|
||||||
<TypeScriptCompile Include="GameMath.ts" />
|
|
||||||
<TypeScriptCompile Include="Game.ts" />
|
|
||||||
<TypeScriptCompile Include="DynamicTexture.ts" />
|
|
||||||
<TypeScriptCompile Include="Collision.ts" />
|
|
||||||
<TypeScriptCompile Include="AnimationManager.ts" />
|
|
||||||
<Content Include="Basic.js">
|
|
||||||
<DependentUpon>Basic.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="Cache.js">
|
|
||||||
<DependentUpon>Cache.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<Content Include="CameraManager.js">
|
|
||||||
<DependentUpon>CameraManager.ts</DependentUpon>
|
|
||||||
</Content>
|
|
||||||
<TypeScriptCompile Include="CameraManager.ts" />
|
|
||||||
<TypeScriptCompile Include="Cache.ts" />
|
|
||||||
<TypeScriptCompile Include="Basic.ts" />
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(VSToolsPath)\TypeScript\Microsoft.TypeScript.targets" />
|
|
||||||
<PropertyGroup>
|
|
||||||
<PostBuildEvent>cd $(ProjectDir)..\build
|
|
||||||
copy phaser.js ..\Tests\</PostBuildEvent>
|
|
||||||
</PropertyGroup>
|
|
||||||
</Project>
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
/**
|
|
||||||
* Phaser
|
|
||||||
*
|
|
||||||
* v0.9.4 - April 28th 2013
|
|
||||||
*
|
|
||||||
* A small and feature-packed 2D canvas game framework born from the firey pits of Flixel and Kiwi.
|
|
||||||
*
|
|
||||||
* Richard Davey (@photonstorm)
|
|
||||||
*
|
|
||||||
* Many thanks to Adam Saltsman (@ADAMATOMIC) for the original Flixel AS3 code on which Phaser is based.
|
|
||||||
*
|
|
||||||
* "If you want your children to be intelligent, read them fairy tales."
|
|
||||||
* "If you want them to be more intelligent, read them more fairy tales."
|
|
||||||
* -- Albert Einstein
|
|
||||||
*/
|
|
||||||
|
|
||||||
module Phaser {
|
|
||||||
|
|
||||||
export var VERSION: string = 'Phaser version 0.9.4';
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,124 +0,0 @@
|
|||||||
/// <reference path="Game.ts" />
|
|
||||||
/// <reference path="system/Sound.ts" />
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Phaser - SoundManager
|
|
||||||
*
|
|
||||||
* This is an embroyonic web audio sound management class. There is a lot of work still to do here.
|
|
||||||
*/
|
|
||||||
|
|
||||||
module Phaser {
|
|
||||||
|
|
||||||
export class SoundManager {
|
|
||||||
|
|
||||||
constructor(game: Game) {
|
|
||||||
|
|
||||||
this._game = game;
|
|
||||||
|
|
||||||
if (game.device.webaudio == true)
|
|
||||||
{
|
|
||||||
if (!!window['AudioContext'])
|
|
||||||
{
|
|
||||||
this._context = new window['AudioContext']();
|
|
||||||
}
|
|
||||||
else if (!!window['webkitAudioContext'])
|
|
||||||
{
|
|
||||||
this._context = new window['webkitAudioContext']();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this._context !== null)
|
|
||||||
{
|
|
||||||
this._gainNode = this._context.createGainNode();
|
|
||||||
this._gainNode.connect(this._context.destination);
|
|
||||||
this._volume = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private _game: Game;
|
|
||||||
|
|
||||||
private _context = null;
|
|
||||||
private _gainNode;
|
|
||||||
private _volume: number;
|
|
||||||
|
|
||||||
public mute() {
|
|
||||||
|
|
||||||
this._gainNode.gain.value = 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public unmute() {
|
|
||||||
|
|
||||||
this._gainNode.gain.value = this._volume;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public set volume(value: number) {
|
|
||||||
|
|
||||||
this._volume = value;
|
|
||||||
this._gainNode.gain.value = this._volume;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public get volume(): number {
|
|
||||||
return this._volume;
|
|
||||||
}
|
|
||||||
|
|
||||||
public decode(key: string, callback = null, sound?: Sound = null) {
|
|
||||||
|
|
||||||
var soundData = this._game.cache.getSound(key);
|
|
||||||
|
|
||||||
if (soundData)
|
|
||||||
{
|
|
||||||
if (this._game.cache.isSoundDecoded(key) === false)
|
|
||||||
{
|
|
||||||
var that = this;
|
|
||||||
|
|
||||||
this._context.decodeAudioData(soundData, function (buffer) {
|
|
||||||
that._game.cache.decodedSound(key, buffer);
|
|
||||||
|
|
||||||
if (sound)
|
|
||||||
{
|
|
||||||
sound.setDecodedBuffer(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public play(key: string, volume?: number = 1, loop?: bool = false): Sound {
|
|
||||||
|
|
||||||
if (this._context === null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var soundData = this._game.cache.getSound(key);
|
|
||||||
|
|
||||||
if (soundData)
|
|
||||||
{
|
|
||||||
// Does the sound need decoding?
|
|
||||||
if (this._game.cache.isSoundDecoded(key) === true)
|
|
||||||
{
|
|
||||||
return new Sound(this._context, this._gainNode, soundData, volume, loop);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var tempSound: Sound = new Sound(this._context, this._gainNode, null, volume, loop);
|
|
||||||
|
|
||||||
// this is an async process, so we can return the Sound object anyway, it just won't be playing yet
|
|
||||||
this.decode(key, () => this.play(key), tempSound);
|
|
||||||
|
|
||||||
return tempSound;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,247 +0,0 @@
|
|||||||
/// <reference path="Phaser.ts" />
|
|
||||||
/// <reference path="Game.ts" />
|
|
||||||
/// <reference path="system/StageScaleMode.ts" />
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Phaser - Stage
|
|
||||||
*
|
|
||||||
* The Stage is the canvas on which everything is displayed. This class handles display within the web browser, focus handling,
|
|
||||||
* resizing, scaling and pause/boot screens.
|
|
||||||
*/
|
|
||||||
|
|
||||||
module Phaser {
|
|
||||||
|
|
||||||
export class Stage {
|
|
||||||
|
|
||||||
constructor(game: Game, parent: string, width: number, height: number) {
|
|
||||||
|
|
||||||
this._game = game;
|
|
||||||
|
|
||||||
this.canvas = <HTMLCanvasElement> document.createElement('canvas');
|
|
||||||
this.canvas.width = width;
|
|
||||||
this.canvas.height = height;
|
|
||||||
|
|
||||||
if (document.getElementById(parent))
|
|
||||||
{
|
|
||||||
document.getElementById(parent).appendChild(this.canvas);
|
|
||||||
document.getElementById(parent).style.overflow = 'hidden';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
document.body.appendChild(this.canvas);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Consume default actions on the canvas
|
|
||||||
this.canvas.style.msTouchAction = 'none';
|
|
||||||
this.canvas.style['touch-action'] = 'none';
|
|
||||||
|
|
||||||
this.context = this.canvas.getContext('2d');
|
|
||||||
|
|
||||||
this.offset = this.getOffset(this.canvas);
|
|
||||||
this.bounds = new Rectangle(this.offset.x, this.offset.y, width, height);
|
|
||||||
this.aspectRatio = width / height;
|
|
||||||
this.scaleMode = StageScaleMode.NO_SCALE;
|
|
||||||
this.scale = new StageScaleMode(this._game);
|
|
||||||
|
|
||||||
document.addEventListener('visibilitychange', (event) => this.visibilityChange(event), false);
|
|
||||||
document.addEventListener('webkitvisibilitychange', (event) => this.visibilityChange(event), false);
|
|
||||||
window.onblur = (event) => this.visibilityChange(event);
|
|
||||||
window.onfocus = (event) => this.visibilityChange(event);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private _game: Game;
|
|
||||||
private _bgColor: string;
|
|
||||||
|
|
||||||
|
|
||||||
public static ORIENTATION_LANDSCAPE: number = 0;
|
|
||||||
public static ORIENTATION_PORTRAIT: number = 1;
|
|
||||||
|
|
||||||
public bounds: Rectangle;
|
|
||||||
public aspectRatio: number;
|
|
||||||
public clear: bool = true;
|
|
||||||
public canvas: HTMLCanvasElement;
|
|
||||||
public context: CanvasRenderingContext2D;
|
|
||||||
public disablePauseScreen: bool = false;
|
|
||||||
public offset: Point;
|
|
||||||
public scale: StageScaleMode;
|
|
||||||
public scaleMode: number;
|
|
||||||
|
|
||||||
public minScaleX: number = null;
|
|
||||||
public maxScaleX: number = null;
|
|
||||||
public minScaleY: number = null;
|
|
||||||
public maxScaleY: number = null;
|
|
||||||
|
|
||||||
public update() {
|
|
||||||
|
|
||||||
this.scale.update();
|
|
||||||
|
|
||||||
if (this.clear)
|
|
||||||
{
|
|
||||||
// implement dirty rect? could take up more cpu time than it saves. needs benching.
|
|
||||||
this.context.clearRect(0, 0, this.width, this.height);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public renderDebugInfo() {
|
|
||||||
|
|
||||||
this.context.fillStyle = 'rgb(255,255,255)';
|
|
||||||
this.context.fillText(Phaser.VERSION, 10, 20);
|
|
||||||
this.context.fillText('Game Size: ' + this.width + ' x ' + this.height, 10, 40);
|
|
||||||
this.context.fillText('x: ' + this.x + ' y: ' + this.y, 10, 60);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//if (document['hidden'] === true || document['webkitHidden'] === true)
|
|
||||||
private visibilityChange(event) {
|
|
||||||
|
|
||||||
//console.log(event);
|
|
||||||
|
|
||||||
if (this.disablePauseScreen)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.type == 'blur' && this._game.paused == false && this._game.isBooted == true)
|
|
||||||
{
|
|
||||||
this._game.paused = true;
|
|
||||||
this.drawPauseScreen();
|
|
||||||
}
|
|
||||||
else if (event.type == 'focus')
|
|
||||||
{
|
|
||||||
this._game.paused = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public drawInitScreen() {
|
|
||||||
|
|
||||||
this.context.fillStyle = 'rgb(40, 40, 40)';
|
|
||||||
this.context.fillRect(0, 0, this.width, this.height);
|
|
||||||
|
|
||||||
this.context.fillStyle = 'rgb(255,255,255)';
|
|
||||||
this.context.font = 'bold 18px Arial';
|
|
||||||
this.context.textBaseline = 'top';
|
|
||||||
this.context.fillText(Phaser.VERSION, 54, 32);
|
|
||||||
this.context.fillText('Game Size: ' + this.width + ' x ' + this.height, 32, 64);
|
|
||||||
this.context.fillText('www.photonstorm.com', 32, 96);
|
|
||||||
this.context.font = '16px Arial';
|
|
||||||
this.context.fillText('You are seeing this screen because you didn\'t specify any default', 32, 160);
|
|
||||||
this.context.fillText('functions in the Game constructor, or use Game.loadState()', 32, 184);
|
|
||||||
|
|
||||||
var image = new Image();
|
|
||||||
var that = this;
|
|
||||||
|
|
||||||
image.onload = function () {
|
|
||||||
that.context.drawImage(image, 32, 32);
|
|
||||||
};
|
|
||||||
|
|
||||||
image.src = this._logo;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private drawPauseScreen() {
|
|
||||||
|
|
||||||
this.saveCanvasValues();
|
|
||||||
|
|
||||||
this.context.fillStyle = 'rgba(0, 0, 0, 0.4)';
|
|
||||||
this.context.fillRect(0, 0, this.width, this.height);
|
|
||||||
|
|
||||||
// Draw a 'play' arrow
|
|
||||||
var arrowWidth = Math.round(this.width / 2);
|
|
||||||
var arrowHeight = Math.round(this.height / 2);
|
|
||||||
|
|
||||||
var sx = this.centerX - arrowWidth / 2;
|
|
||||||
var sy = this.centerY - arrowHeight / 2;
|
|
||||||
|
|
||||||
this.context.beginPath();
|
|
||||||
this.context.moveTo(sx, sy);
|
|
||||||
this.context.lineTo(sx, sy + arrowHeight);
|
|
||||||
this.context.lineTo(sx + arrowWidth, this.centerY);
|
|
||||||
this.context.fillStyle = 'rgba(255, 255, 255, 0.8)';
|
|
||||||
this.context.fill();
|
|
||||||
this.context.closePath();
|
|
||||||
|
|
||||||
this.restoreCanvasValues();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private getOffset(element): Point {
|
|
||||||
|
|
||||||
var box = element.getBoundingClientRect();
|
|
||||||
|
|
||||||
var clientTop = element.clientTop || document.body.clientTop || 0;
|
|
||||||
var clientLeft = element.clientLeft || document.body.clientLeft || 0;
|
|
||||||
var scrollTop = window.pageYOffset || element.scrollTop || document.body.scrollTop;
|
|
||||||
var scrollLeft = window.pageXOffset || element.scrollLeft || document.body.scrollLeft;
|
|
||||||
|
|
||||||
return new Point(box.left + scrollLeft - clientLeft, box.top + scrollTop - clientTop);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public strokeStyle: string;
|
|
||||||
public lineWidth: number;
|
|
||||||
public fillStyle: string;
|
|
||||||
|
|
||||||
public saveCanvasValues() {
|
|
||||||
|
|
||||||
this.strokeStyle = this.context.strokeStyle;
|
|
||||||
this.lineWidth = this.context.lineWidth;
|
|
||||||
this.fillStyle = this.context.fillStyle;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public restoreCanvasValues() {
|
|
||||||
|
|
||||||
this.context.strokeStyle = this.strokeStyle;
|
|
||||||
this.context.lineWidth = this.lineWidth;
|
|
||||||
this.context.fillStyle = this.fillStyle;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public set backgroundColor(color: string) {
|
|
||||||
this.canvas.style.backgroundColor = color;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get backgroundColor(): string {
|
|
||||||
return this._bgColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get x(): number {
|
|
||||||
return this.bounds.x;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get y(): number {
|
|
||||||
return this.bounds.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get width(): number {
|
|
||||||
return this.bounds.width;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get height(): number {
|
|
||||||
return this.bounds.height;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get centerX(): number {
|
|
||||||
return this.bounds.halfWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get centerY(): number {
|
|
||||||
return this.bounds.halfHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get randomX(): number {
|
|
||||||
return Math.round(Math.random() * this.bounds.width);
|
|
||||||
}
|
|
||||||
|
|
||||||
public get randomY(): number {
|
|
||||||
return Math.round(Math.random() * this.bounds.height);
|
|
||||||
}
|
|
||||||
|
|
||||||
private _logo: string = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAO1JREFUeNpi/P//PwM6YGRkxBQEAqBaRnQxFmwa10d6MAjrMqMofHv5L1we2SBGmAtAktg0ogOQQYHLd8ANYYFpPtTmzUAMAFmwnsEDrAdkCAvMZlIAsiFMMAEYsKvaSrQhIMCELkGsV2AAbIC8gCQYgwKIUABiNYBf9yoYH7n7n6CzN274g2IYEyFbsNmKLIaSkHpP7WSwUfbA0ASzFQRslBlxp0RcAF0TRhggA3zhAJIDpUKU5A9KyshpHDkjFZu5g2nJMFcwXVJSgqIGnBKx5bKenh4w/XzVbgbPtlIUcVgSxuoCUgHIIIAAAwArtXwJBABO6QAAAABJRU5ErkJggg==";
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,103 +0,0 @@
|
|||||||
/// <reference path="Game.ts" />
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Phaser - State
|
|
||||||
*
|
|
||||||
* This is a base State class which can be extended if you are creating your game using TypeScript.
|
|
||||||
*/
|
|
||||||
|
|
||||||
module Phaser {
|
|
||||||
|
|
||||||
export class State {
|
|
||||||
|
|
||||||
constructor(game: Game) {
|
|
||||||
|
|
||||||
this.game = game;
|
|
||||||
|
|
||||||
this.camera = game.camera;
|
|
||||||
this.cache = game.cache;
|
|
||||||
this.collision = game.collision;
|
|
||||||
this.input = game.input;
|
|
||||||
this.loader = game.loader;
|
|
||||||
this.math = game.math;
|
|
||||||
this.motion = game.motion;
|
|
||||||
this.sound = game.sound;
|
|
||||||
this.stage = game.stage;
|
|
||||||
this.time = game.time;
|
|
||||||
this.tweens = game.tweens;
|
|
||||||
this.world = game.world;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public game: Game;
|
|
||||||
|
|
||||||
public camera: Camera;
|
|
||||||
public cache: Cache;
|
|
||||||
public collision: Collision;
|
|
||||||
public input: Input;
|
|
||||||
public loader: Loader;
|
|
||||||
public math: GameMath;
|
|
||||||
public motion: Motion;
|
|
||||||
public sound: SoundManager;
|
|
||||||
public stage: Stage;
|
|
||||||
public time: Time;
|
|
||||||
public tweens: TweenManager;
|
|
||||||
public world: World;
|
|
||||||
|
|
||||||
|
|
||||||
// Overload these in your own States
|
|
||||||
public init() { }
|
|
||||||
public create() { }
|
|
||||||
public update() { }
|
|
||||||
public render() { }
|
|
||||||
public paused() { }
|
|
||||||
|
|
||||||
// Handy Proxy methods
|
|
||||||
|
|
||||||
public createCamera(x: number, y: number, width: number, height: number): Camera {
|
|
||||||
return this.game.world.createCamera(x, y, width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
public createGeomSprite(x: number, y: number): GeomSprite {
|
|
||||||
return this.world.createGeomSprite(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
public createSprite(x: number, y: number, key?: string = ''): Sprite {
|
|
||||||
return this.game.world.createSprite(x, y, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public createDynamicTexture(width: number, height: number): DynamicTexture {
|
|
||||||
return this.game.world.createDynamicTexture(width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
public createGroup(MaxSize?: number = 0): Group {
|
|
||||||
return this.game.world.createGroup(MaxSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
public createParticle(): Particle {
|
|
||||||
return this.game.world.createParticle();
|
|
||||||
}
|
|
||||||
|
|
||||||
public createEmitter(x?: number = 0, y?: number = 0, size?: number = 0): Emitter {
|
|
||||||
return this.game.world.createEmitter(x, y, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
public createScrollZone(key: string, x?: number = 0, y?: number = 0, width?: number = 0, height?: number = 0): ScrollZone {
|
|
||||||
return this.game.world.createScrollZone(key, x, y, width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
public createTilemap(key: string, mapData: string, format: number, resizeWorld: bool = true, tileWidth?: number = 0, tileHeight?: number = 0): Tilemap {
|
|
||||||
return this.game.world.createTilemap(key, mapData, format, resizeWorld, tileWidth, tileHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
public createTween(obj): Tween {
|
|
||||||
return this.game.tweens.create(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
public collide(ObjectOrGroup1: Basic = null, ObjectOrGroup2: Basic = null, NotifyCallback = null): bool {
|
|
||||||
return this.collision.overlap(ObjectOrGroup1, ObjectOrGroup2, NotifyCallback, Collision.separate);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,140 +0,0 @@
|
|||||||
/// <reference path="Game.ts" />
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Phaser - Time
|
|
||||||
*
|
|
||||||
* This is the game clock and it manages elapsed time and calculation of delta values, used for game object motion.
|
|
||||||
*/
|
|
||||||
|
|
||||||
module Phaser {
|
|
||||||
|
|
||||||
export class Time {
|
|
||||||
|
|
||||||
constructor(game: Game) {
|
|
||||||
|
|
||||||
this._started = Date.now();
|
|
||||||
this._timeLastSecond = this._started;
|
|
||||||
this.time = this._started;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private _game: Game;
|
|
||||||
private _started: number;
|
|
||||||
|
|
||||||
|
|
||||||
public timeScale: number = 1.0;
|
|
||||||
public elapsed: number = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @property time
|
|
||||||
* @type Number
|
|
||||||
*/
|
|
||||||
public time: number = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @property now
|
|
||||||
* @type Number
|
|
||||||
*/
|
|
||||||
public now: number = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @property delta
|
|
||||||
* @type Number
|
|
||||||
*/
|
|
||||||
public delta: number = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @method totalElapsedSeconds
|
|
||||||
* @return {Number}
|
|
||||||
*/
|
|
||||||
public get totalElapsedSeconds(): number {
|
|
||||||
|
|
||||||
return (this.now - this._started) * 0.001;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public fps: number = 0;
|
|
||||||
public fpsMin: number = 1000;
|
|
||||||
public fpsMax: number = 0;
|
|
||||||
public msMin: number = 1000;
|
|
||||||
public msMax: number = 0;
|
|
||||||
public frames: number = 0;
|
|
||||||
|
|
||||||
private _timeLastSecond: number = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @method update
|
|
||||||
*/
|
|
||||||
public update() {
|
|
||||||
|
|
||||||
// Can we use performance.now() ?
|
|
||||||
this.now = Date.now(); // mark
|
|
||||||
this.delta = this.now - this.time; // elapsedMS
|
|
||||||
|
|
||||||
this.msMin = Math.min(this.msMin, this.delta);
|
|
||||||
this.msMax = Math.max(this.msMax, this.delta);
|
|
||||||
|
|
||||||
this.frames++;
|
|
||||||
|
|
||||||
if (this.now > this._timeLastSecond + 1000)
|
|
||||||
{
|
|
||||||
this.fps = Math.round((this.frames * 1000) / (this.now - this._timeLastSecond));
|
|
||||||
this.fpsMin = Math.min(this.fpsMin, this.fps);
|
|
||||||
this.fpsMax = Math.max(this.fpsMax, this.fps);
|
|
||||||
|
|
||||||
this._timeLastSecond = this.now;
|
|
||||||
this.frames = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.time = this.now; // _total
|
|
||||||
|
|
||||||
//// Lock the delta at 0.1 to minimise fps tunneling
|
|
||||||
//if (this.delta > 0.1)
|
|
||||||
//{
|
|
||||||
// this.delta = 0.1;
|
|
||||||
//}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @method elapsedSince
|
|
||||||
* @param {Number} since
|
|
||||||
* @return {Number}
|
|
||||||
*/
|
|
||||||
public elapsedSince(since: number): number {
|
|
||||||
|
|
||||||
return this.now - since;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @method elapsedSecondsSince
|
|
||||||
* @param {Number} since
|
|
||||||
* @return {Number}
|
|
||||||
*/
|
|
||||||
public elapsedSecondsSince(since: number): number {
|
|
||||||
|
|
||||||
return (this.now - since) * 0.001;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @method reset
|
|
||||||
*/
|
|
||||||
public reset() {
|
|
||||||
|
|
||||||
this._started = this.now;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
/// <reference path="Game.ts" />
|
|
||||||
/// <reference path="system/Tween.ts" />
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Phaser - TweenManager
|
|
||||||
*
|
|
||||||
* The Game has a single instance of the TweenManager through which all Tween objects are created and updated.
|
|
||||||
* Tweens are hooked into the game clock and pause system, adjusting based on the game state.
|
|
||||||
* TweenManager is based heavily on tween.js by sole (http://soledadpenades.com).
|
|
||||||
* I converted it to TypeScript, swapped the callbacks for signals and patched a few issues with regard
|
|
||||||
* to properties and completion errors. Please see https://github.com/sole/tween.js for a full list of contributors.
|
|
||||||
*/
|
|
||||||
|
|
||||||
module Phaser {
|
|
||||||
|
|
||||||
export class TweenManager {
|
|
||||||
|
|
||||||
constructor(game: Phaser.Game) {
|
|
||||||
|
|
||||||
this._game = game;
|
|
||||||
this._tweens = [];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private _game: Phaser.Game;
|
|
||||||
private _tweens: Phaser.Tween[];
|
|
||||||
|
|
||||||
public getAll() {
|
|
||||||
|
|
||||||
return this._tweens;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public removeAll() {
|
|
||||||
|
|
||||||
this._tweens.length = 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public create(object): Phaser.Tween {
|
|
||||||
|
|
||||||
return new Phaser.Tween(object, this._game);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public add(tween: Phaser.Tween) {
|
|
||||||
|
|
||||||
tween.parent = this._game;
|
|
||||||
|
|
||||||
this._tweens.push(tween);
|
|
||||||
|
|
||||||
return tween;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public remove(tween: Phaser.Tween) {
|
|
||||||
|
|
||||||
var i = this._tweens.indexOf(tween);
|
|
||||||
|
|
||||||
if (i !== -1)
|
|
||||||
{
|
|
||||||
this._tweens.splice(i, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public update() {
|
|
||||||
|
|
||||||
if (this._tweens.length === 0)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var i = 0;
|
|
||||||
var numTweens = this._tweens.length;
|
|
||||||
|
|
||||||
while (i < numTweens)
|
|
||||||
{
|
|
||||||
if (this._tweens[i].update(this._game.time.now))
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this._tweens.splice(i, 1);
|
|
||||||
numTweens--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,159 +0,0 @@
|
|||||||
/// <reference path="Game.ts" />
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Phaser - World
|
|
||||||
*
|
|
||||||
* A game has only one world. The world is an abstract place in which all game objects live. It is not bound
|
|
||||||
* by stage limits and can be any size or dimension. You look into the world via cameras and all game objects
|
|
||||||
* live within the world at world-based coordinates. By default a world is created the same size as your Stage.
|
|
||||||
*/
|
|
||||||
|
|
||||||
module Phaser {
|
|
||||||
|
|
||||||
export class World {
|
|
||||||
|
|
||||||
constructor(game: Game, width: number, height: number) {
|
|
||||||
|
|
||||||
this._game = game;
|
|
||||||
|
|
||||||
this.cameras = new CameraManager(this._game, 0, 0, width, height);
|
|
||||||
|
|
||||||
this._game.camera = this.cameras.current;
|
|
||||||
|
|
||||||
this.group = new Group(this._game, 0);
|
|
||||||
|
|
||||||
this.bounds = new Rectangle(0, 0, width, height);
|
|
||||||
|
|
||||||
this.worldDivisions = 6;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private _game: Game;
|
|
||||||
|
|
||||||
public cameras: CameraManager;
|
|
||||||
public group: Group;
|
|
||||||
public bounds: Rectangle;
|
|
||||||
public worldDivisions: number;
|
|
||||||
|
|
||||||
public update() {
|
|
||||||
|
|
||||||
this.group.preUpdate();
|
|
||||||
this.group.update();
|
|
||||||
this.group.postUpdate();
|
|
||||||
|
|
||||||
this.cameras.update();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public render() {
|
|
||||||
|
|
||||||
// Unlike in flixel our render process is camera driven, not group driven
|
|
||||||
this.cameras.render();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public destroy() {
|
|
||||||
|
|
||||||
this.group.destroy();
|
|
||||||
|
|
||||||
this.cameras.destroy();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// World methods
|
|
||||||
|
|
||||||
public setSize(width: number, height: number, updateCameraBounds: bool = true) {
|
|
||||||
|
|
||||||
this.bounds.width = width;
|
|
||||||
this.bounds.height = height;
|
|
||||||
|
|
||||||
if (updateCameraBounds == true)
|
|
||||||
{
|
|
||||||
this._game.camera.setBounds(0, 0, width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public get width(): number {
|
|
||||||
return this.bounds.width;
|
|
||||||
}
|
|
||||||
|
|
||||||
public set width(value: number) {
|
|
||||||
this.bounds.width = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get height(): number {
|
|
||||||
return this.bounds.height;
|
|
||||||
}
|
|
||||||
|
|
||||||
public set height(value: number) {
|
|
||||||
this.bounds.height = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get centerX(): number {
|
|
||||||
return this.bounds.halfWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get centerY(): number {
|
|
||||||
return this.bounds.halfHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get randomX(): number {
|
|
||||||
return Math.round(Math.random() * this.bounds.width);
|
|
||||||
}
|
|
||||||
|
|
||||||
public get randomY(): number {
|
|
||||||
return Math.round(Math.random() * this.bounds.height);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cameras
|
|
||||||
|
|
||||||
public createCamera(x: number, y: number, width: number, height: number): Camera {
|
|
||||||
return this.cameras.addCamera(x, y, width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
public removeCamera(id: number): bool {
|
|
||||||
return this.cameras.removeCamera(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public getAllCameras(): Camera[] {
|
|
||||||
return this.cameras.getAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Game Objects
|
|
||||||
|
|
||||||
public createSprite(x: number, y: number, key?: string = ''): Sprite {
|
|
||||||
return <Sprite> this.group.add(new Sprite(this._game, x, y, key));
|
|
||||||
}
|
|
||||||
|
|
||||||
public createGeomSprite(x: number, y: number): GeomSprite {
|
|
||||||
return <GeomSprite> this.group.add(new GeomSprite(this._game, x, y));
|
|
||||||
}
|
|
||||||
|
|
||||||
public createDynamicTexture(width: number, height: number): DynamicTexture {
|
|
||||||
return new DynamicTexture(this._game, width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
public createGroup(MaxSize?: number = 0): Group {
|
|
||||||
return <Group> this.group.add(new Group(this._game, MaxSize));
|
|
||||||
}
|
|
||||||
|
|
||||||
public createScrollZone(key: string, x?: number = 0, y?: number = 0, width?: number = 0, height?: number = 0): ScrollZone {
|
|
||||||
return <ScrollZone> this.group.add(new ScrollZone(this._game, key, x, y, width, height));
|
|
||||||
}
|
|
||||||
|
|
||||||
public createTilemap(key: string, mapData: string, format: number, resizeWorld: bool = true, tileWidth?: number = 0, tileHeight?: number = 0): Tilemap {
|
|
||||||
return <Tilemap> this.group.add(new Tilemap(this._game, key, mapData, format, resizeWorld, tileWidth, tileHeight));
|
|
||||||
}
|
|
||||||
|
|
||||||
public createParticle(): Particle {
|
|
||||||
return new Particle(this._game);
|
|
||||||
}
|
|
||||||
|
|
||||||
public createEmitter(x?: number = 0, y?: number = 0, size?: number = 0): Emitter {
|
|
||||||
return <Emitter> this.group.add(new Emitter(this._game, x, y, size));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,600 +0,0 @@
|
|||||||
/// <reference path="../Game.ts" />
|
|
||||||
/// <reference path="../Basic.ts" />
|
|
||||||
/// <reference path="../Signal.ts" />
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Phaser - GameObject
|
|
||||||
*
|
|
||||||
* This is the base GameObject on which all other game objects are derived. It contains all the logic required for position,
|
|
||||||
* motion, size, collision and input.
|
|
||||||
*/
|
|
||||||
|
|
||||||
module Phaser {
|
|
||||||
|
|
||||||
export class GameObject extends Basic {
|
|
||||||
|
|
||||||
constructor(game: Game, x?: number = 0, y?: number = 0, width?: number = 16, height?: number = 16) {
|
|
||||||
|
|
||||||
super(game);
|
|
||||||
|
|
||||||
this.bounds = new Rectangle(x, y, width, height);
|
|
||||||
this.exists = true;
|
|
||||||
this.active = true;
|
|
||||||
this.visible = true;
|
|
||||||
this.alive = true;
|
|
||||||
this.isGroup = false;
|
|
||||||
this.alpha = 1;
|
|
||||||
this.scale = new MicroPoint(1, 1);
|
|
||||||
|
|
||||||
this.last = new MicroPoint(x, y);
|
|
||||||
this.origin = new MicroPoint(this.bounds.halfWidth, this.bounds.halfHeight);
|
|
||||||
this.align = GameObject.ALIGN_TOP_LEFT;
|
|
||||||
this.mass = 1;
|
|
||||||
this.elasticity = 0;
|
|
||||||
this.health = 1;
|
|
||||||
this.immovable = false;
|
|
||||||
this.moves = true;
|
|
||||||
this.worldBounds = null;
|
|
||||||
|
|
||||||
this.touching = Collision.NONE;
|
|
||||||
this.wasTouching = Collision.NONE;
|
|
||||||
this.allowCollisions = Collision.ANY;
|
|
||||||
|
|
||||||
this.velocity = new MicroPoint();
|
|
||||||
this.acceleration = new MicroPoint();
|
|
||||||
this.drag = new MicroPoint();
|
|
||||||
this.maxVelocity = new MicroPoint(10000, 10000);
|
|
||||||
|
|
||||||
this.angle = 0;
|
|
||||||
this.angularVelocity = 0;
|
|
||||||
this.angularAcceleration = 0;
|
|
||||||
this.angularDrag = 0;
|
|
||||||
this.maxAngular = 10000;
|
|
||||||
|
|
||||||
this.cameraBlacklist = [];
|
|
||||||
this.scrollFactor = new MicroPoint(1, 1);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private _angle: number = 0;
|
|
||||||
|
|
||||||
public static ALIGN_TOP_LEFT: number = 0;
|
|
||||||
public static ALIGN_TOP_CENTER: number = 1;
|
|
||||||
public static ALIGN_TOP_RIGHT: number = 2;
|
|
||||||
public static ALIGN_CENTER_LEFT: number = 3;
|
|
||||||
public static ALIGN_CENTER: number = 4;
|
|
||||||
public static ALIGN_CENTER_RIGHT: number = 5;
|
|
||||||
public static ALIGN_BOTTOM_LEFT: number = 6;
|
|
||||||
public static ALIGN_BOTTOM_CENTER: number = 7;
|
|
||||||
public static ALIGN_BOTTOM_RIGHT: number = 8;
|
|
||||||
|
|
||||||
public static OUT_OF_BOUNDS_STOP: number = 0;
|
|
||||||
public static OUT_OF_BOUNDS_KILL: number = 1;
|
|
||||||
|
|
||||||
public _point: MicroPoint;
|
|
||||||
|
|
||||||
public cameraBlacklist: number[];
|
|
||||||
public bounds: Rectangle;
|
|
||||||
public worldBounds: Quad;
|
|
||||||
public outOfBoundsAction: number = 0;
|
|
||||||
public align: number;
|
|
||||||
public facing: number;
|
|
||||||
public alpha: number;
|
|
||||||
public scale: MicroPoint;
|
|
||||||
public origin: MicroPoint;
|
|
||||||
public z: number = 0;
|
|
||||||
|
|
||||||
// This value is added to the angle of the GameObject.
|
|
||||||
// For example if you had a sprite drawn facing straight up then you could set
|
|
||||||
// rotationOffset to 90 and it would correspond correctly with Phasers rotation system
|
|
||||||
public rotationOffset: number = 0;
|
|
||||||
|
|
||||||
public renderRotation: bool = true;
|
|
||||||
|
|
||||||
// Physics properties
|
|
||||||
public immovable: bool;
|
|
||||||
|
|
||||||
// Velocity is given in pixels per second. Therefore a velocity of
|
|
||||||
// 100 will move at a rate of 100 pixels every 1000 ms (1sec). It's not balls-on
|
|
||||||
// accurate due to the way timers work, but it's pretty close. Expect tolerance
|
|
||||||
// of +- 10 px. Also that speed assumes no drag
|
|
||||||
public velocity: MicroPoint;
|
|
||||||
|
|
||||||
public mass: number;
|
|
||||||
public elasticity: number;
|
|
||||||
public acceleration: MicroPoint;
|
|
||||||
public drag: MicroPoint;
|
|
||||||
public maxVelocity: MicroPoint;
|
|
||||||
public angularVelocity: number;
|
|
||||||
public angularAcceleration: number;
|
|
||||||
public angularDrag: number;
|
|
||||||
public maxAngular: number;
|
|
||||||
public scrollFactor: MicroPoint;
|
|
||||||
|
|
||||||
public health: number;
|
|
||||||
public moves: bool = true;
|
|
||||||
public touching: number;
|
|
||||||
public wasTouching: number;
|
|
||||||
public allowCollisions: number;
|
|
||||||
public last: MicroPoint;
|
|
||||||
|
|
||||||
// Input
|
|
||||||
public inputEnabled: bool = false;
|
|
||||||
private _inputOver: bool = false;
|
|
||||||
|
|
||||||
public onInputOver: Phaser.Signal;
|
|
||||||
public onInputOut: Phaser.Signal;
|
|
||||||
public onInputDown: Phaser.Signal;
|
|
||||||
public onInputUp: Phaser.Signal;
|
|
||||||
|
|
||||||
public preUpdate() {
|
|
||||||
|
|
||||||
// flicker time
|
|
||||||
|
|
||||||
this.last.x = this.bounds.x;
|
|
||||||
this.last.y = this.bounds.y;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public update() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public postUpdate() {
|
|
||||||
|
|
||||||
if (this.moves)
|
|
||||||
{
|
|
||||||
this.updateMotion();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.worldBounds != null)
|
|
||||||
{
|
|
||||||
if (this.outOfBoundsAction == GameObject.OUT_OF_BOUNDS_KILL)
|
|
||||||
{
|
|
||||||
if (this.x < this.worldBounds.x || this.x > this.worldBounds.right || this.y < this.worldBounds.y || this.y > this.worldBounds.bottom)
|
|
||||||
{
|
|
||||||
this.kill();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (this.x < this.worldBounds.x)
|
|
||||||
{
|
|
||||||
this.x = this.worldBounds.x;
|
|
||||||
}
|
|
||||||
else if (this.x > this.worldBounds.right)
|
|
||||||
{
|
|
||||||
this.x = this.worldBounds.right;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.y < this.worldBounds.y)
|
|
||||||
{
|
|
||||||
this.y = this.worldBounds.y;
|
|
||||||
}
|
|
||||||
else if (this.y > this.worldBounds.bottom)
|
|
||||||
{
|
|
||||||
this.y = this.worldBounds.bottom;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.inputEnabled)
|
|
||||||
{
|
|
||||||
this.updateInput();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.wasTouching = this.touching;
|
|
||||||
this.touching = Collision.NONE;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private updateInput() {
|
|
||||||
}
|
|
||||||
|
|
||||||
private updateMotion() {
|
|
||||||
|
|
||||||
var delta: number;
|
|
||||||
var velocityDelta: number;
|
|
||||||
|
|
||||||
velocityDelta = (this._game.motion.computeVelocity(this.angularVelocity, this.angularAcceleration, this.angularDrag, this.maxAngular) - this.angularVelocity) / 2;
|
|
||||||
this.angularVelocity += velocityDelta;
|
|
||||||
this._angle += this.angularVelocity * this._game.time.elapsed;
|
|
||||||
this.angularVelocity += velocityDelta;
|
|
||||||
|
|
||||||
velocityDelta = (this._game.motion.computeVelocity(this.velocity.x, this.acceleration.x, this.drag.x, this.maxVelocity.x) - this.velocity.x) / 2;
|
|
||||||
this.velocity.x += velocityDelta;
|
|
||||||
delta = this.velocity.x * this._game.time.elapsed;
|
|
||||||
this.velocity.x += velocityDelta;
|
|
||||||
this.bounds.x += delta;
|
|
||||||
|
|
||||||
velocityDelta = (this._game.motion.computeVelocity(this.velocity.y, this.acceleration.y, this.drag.y, this.maxVelocity.y) - this.velocity.y) / 2;
|
|
||||||
this.velocity.y += velocityDelta;
|
|
||||||
delta = this.velocity.y * this._game.time.elapsed;
|
|
||||||
this.velocity.y += velocityDelta;
|
|
||||||
this.bounds.y += delta;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks to see if some <code>GameObject</code> overlaps this <code>GameObject</code> or <code>Group</code>.
|
|
||||||
* If the group has a LOT of things in it, it might be faster to use <code>Collision.overlaps()</code>.
|
|
||||||
* WARNING: Currently tilemaps do NOT support screen space overlap checks!
|
|
||||||
*
|
|
||||||
* @param ObjectOrGroup The object or group being tested.
|
|
||||||
* @param InScreenSpace Whether to take scroll factors numbero account when checking for overlap. Default is false, or "only compare in world space."
|
|
||||||
* @param Camera Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
|
||||||
*
|
|
||||||
* @return Whether or not the two objects overlap.
|
|
||||||
*/
|
|
||||||
public overlaps(ObjectOrGroup, InScreenSpace: bool = false, Camera: Camera = null): bool {
|
|
||||||
|
|
||||||
if (ObjectOrGroup.isGroup)
|
|
||||||
{
|
|
||||||
var results: bool = false;
|
|
||||||
var i: number = 0;
|
|
||||||
var members = <Group> ObjectOrGroup.members;
|
|
||||||
|
|
||||||
while (i < length)
|
|
||||||
{
|
|
||||||
if (this.overlaps(members[i++], InScreenSpace, Camera))
|
|
||||||
{
|
|
||||||
results = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!InScreenSpace)
|
|
||||||
{
|
|
||||||
return (ObjectOrGroup.x + ObjectOrGroup.width > this.x) && (ObjectOrGroup.x < this.x + this.width) &&
|
|
||||||
(ObjectOrGroup.y + ObjectOrGroup.height > this.y) && (ObjectOrGroup.y < this.y + this.height);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Camera == null)
|
|
||||||
{
|
|
||||||
Camera = this._game.camera;
|
|
||||||
}
|
|
||||||
|
|
||||||
var objectScreenPos: Point = ObjectOrGroup.getScreenXY(null, Camera);
|
|
||||||
|
|
||||||
this.getScreenXY(this._point, Camera);
|
|
||||||
|
|
||||||
return (objectScreenPos.x + ObjectOrGroup.width > this._point.x) && (objectScreenPos.x < this._point.x + this.width) &&
|
|
||||||
(objectScreenPos.y + ObjectOrGroup.height > this._point.y) && (objectScreenPos.y < this._point.y + this.height);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks to see if this <code>GameObject</code> were located at the given position, would it overlap the <code>GameObject</code> or <code>Group</code>?
|
|
||||||
* This is distinct from overlapsPoint(), which just checks that point, rather than taking the object's size numbero account.
|
|
||||||
* WARNING: Currently tilemaps do NOT support screen space overlap checks!
|
|
||||||
*
|
|
||||||
* @param X The X position you want to check. Pretends this object (the caller, not the parameter) is located here.
|
|
||||||
* @param Y The Y position you want to check. Pretends this object (the caller, not the parameter) is located here.
|
|
||||||
* @param ObjectOrGroup The object or group being tested.
|
|
||||||
* @param InScreenSpace Whether to take scroll factors numbero account when checking for overlap. Default is false, or "only compare in world space."
|
|
||||||
* @param Camera Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
|
||||||
*
|
|
||||||
* @return Whether or not the two objects overlap.
|
|
||||||
*/
|
|
||||||
public overlapsAt(X: number, Y: number, ObjectOrGroup, InScreenSpace: bool = false, Camera: Camera = null): bool {
|
|
||||||
|
|
||||||
if (ObjectOrGroup.isGroup)
|
|
||||||
{
|
|
||||||
var results: bool = false;
|
|
||||||
var basic;
|
|
||||||
var i: number = 0;
|
|
||||||
var members = ObjectOrGroup.members;
|
|
||||||
|
|
||||||
while (i < length)
|
|
||||||
{
|
|
||||||
if (this.overlapsAt(X, Y, members[i++], InScreenSpace, Camera))
|
|
||||||
{
|
|
||||||
results = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!InScreenSpace)
|
|
||||||
{
|
|
||||||
return (ObjectOrGroup.x + ObjectOrGroup.width > X) && (ObjectOrGroup.x < X + this.width) &&
|
|
||||||
(ObjectOrGroup.y + ObjectOrGroup.height > Y) && (ObjectOrGroup.y < Y + this.height);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Camera == null)
|
|
||||||
{
|
|
||||||
Camera = this._game.camera;
|
|
||||||
}
|
|
||||||
|
|
||||||
var objectScreenPos: Point = ObjectOrGroup.getScreenXY(null, Camera);
|
|
||||||
|
|
||||||
this._point.x = X - Camera.scroll.x * this.scrollFactor.x; //copied from getScreenXY()
|
|
||||||
this._point.y = Y - Camera.scroll.y * this.scrollFactor.y;
|
|
||||||
this._point.x += (this._point.x > 0) ? 0.0000001 : -0.0000001;
|
|
||||||
this._point.y += (this._point.y > 0) ? 0.0000001 : -0.0000001;
|
|
||||||
|
|
||||||
return (objectScreenPos.x + ObjectOrGroup.width > this._point.x) && (objectScreenPos.x < this._point.x + this.width) &&
|
|
||||||
(objectScreenPos.y + ObjectOrGroup.height > this._point.y) && (objectScreenPos.y < this._point.y + this.height);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks to see if a point in 2D world space overlaps this <code>GameObject</code>.
|
|
||||||
*
|
|
||||||
* @param Point The point in world space you want to check.
|
|
||||||
* @param InScreenSpace Whether to take scroll factors numbero account when checking for overlap.
|
|
||||||
* @param Camera Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
|
||||||
*
|
|
||||||
* @return Whether or not the point overlaps this object.
|
|
||||||
*/
|
|
||||||
public overlapsPoint(point: Point, InScreenSpace: bool = false, Camera: Camera = null): bool {
|
|
||||||
|
|
||||||
if (!InScreenSpace)
|
|
||||||
{
|
|
||||||
return (point.x > this.x) && (point.x < this.x + this.width) && (point.y > this.y) && (point.y < this.y + this.height);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Camera == null)
|
|
||||||
{
|
|
||||||
Camera = this._game.camera;
|
|
||||||
}
|
|
||||||
|
|
||||||
var X: number = point.x - Camera.scroll.x;
|
|
||||||
var Y: number = point.y - Camera.scroll.y;
|
|
||||||
|
|
||||||
this.getScreenXY(this._point, Camera);
|
|
||||||
|
|
||||||
return (X > this._point.x) && (X < this._point.x + this.width) && (Y > this._point.y) && (Y < this._point.y + this.height);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check and see if this object is currently on screen.
|
|
||||||
*
|
|
||||||
* @param Camera Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
|
||||||
*
|
|
||||||
* @return Whether the object is on screen or not.
|
|
||||||
*/
|
|
||||||
public onScreen(Camera: Camera = null): bool {
|
|
||||||
|
|
||||||
if (Camera == null)
|
|
||||||
{
|
|
||||||
Camera = this._game.camera;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.getScreenXY(this._point, Camera);
|
|
||||||
|
|
||||||
return (this._point.x + this.width > 0) && (this._point.x < Camera.width) && (this._point.y + this.height > 0) && (this._point.y < Camera.height);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Call this to figure out the on-screen position of the object.
|
|
||||||
*
|
|
||||||
* @param Camera Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
|
|
||||||
* @param Point Takes a <code>MicroPoint</code> object and assigns the post-scrolled X and Y values of this object to it.
|
|
||||||
*
|
|
||||||
* @return The <code>MicroPoint</code> you passed in, or a new <code>Point</code> if you didn't pass one, containing the screen X and Y position of this object.
|
|
||||||
*/
|
|
||||||
public getScreenXY(point: MicroPoint = null, Camera: Camera = null): MicroPoint {
|
|
||||||
|
|
||||||
if (point == null)
|
|
||||||
{
|
|
||||||
point = new MicroPoint();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Camera == null)
|
|
||||||
{
|
|
||||||
Camera = this._game.camera;
|
|
||||||
}
|
|
||||||
|
|
||||||
point.x = this.x - Camera.scroll.x * this.scrollFactor.x;
|
|
||||||
point.y = this.y - Camera.scroll.y * this.scrollFactor.y;
|
|
||||||
point.x += (point.x > 0) ? 0.0000001 : -0.0000001;
|
|
||||||
point.y += (point.y > 0) ? 0.0000001 : -0.0000001;
|
|
||||||
|
|
||||||
return point;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether the object collides or not. For more control over what directions
|
|
||||||
* the object will collide from, use collision constants (like LEFT, FLOOR, etc)
|
|
||||||
* to set the value of allowCollisions directly.
|
|
||||||
*/
|
|
||||||
public get solid(): bool {
|
|
||||||
return (this.allowCollisions & Collision.ANY) > Collision.NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
public set solid(Solid: bool) {
|
|
||||||
|
|
||||||
if (Solid)
|
|
||||||
{
|
|
||||||
this.allowCollisions = Collision.ANY;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.allowCollisions = Collision.NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve the midpoint of this object in world coordinates.
|
|
||||||
*
|
|
||||||
* @Point Allows you to pass in an existing <code>Point</code> object if you're so inclined. Otherwise a new one is created.
|
|
||||||
*
|
|
||||||
* @return A <code>Point</code> object containing the midpoint of this object in world coordinates.
|
|
||||||
*/
|
|
||||||
public getMidpoint(point: MicroPoint = null): MicroPoint {
|
|
||||||
|
|
||||||
if (point == null)
|
|
||||||
{
|
|
||||||
point = new MicroPoint();
|
|
||||||
}
|
|
||||||
|
|
||||||
point.copyFrom(this.bounds.center);
|
|
||||||
|
|
||||||
return point;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handy for reviving game objects.
|
|
||||||
* Resets their existence flags and position.
|
|
||||||
*
|
|
||||||
* @param X The new X position of this object.
|
|
||||||
* @param Y The new Y position of this object.
|
|
||||||
*/
|
|
||||||
public reset(X: number, Y: number) {
|
|
||||||
|
|
||||||
this.revive();
|
|
||||||
this.touching = Collision.NONE;
|
|
||||||
this.wasTouching = Collision.NONE;
|
|
||||||
this.x = X;
|
|
||||||
this.y = Y;
|
|
||||||
this.last.x = X;
|
|
||||||
this.last.y = Y;
|
|
||||||
this.velocity.x = 0;
|
|
||||||
this.velocity.y = 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handy for checking if this object is touching a particular surface.
|
|
||||||
* For slightly better performance you can just & the value directly numbero <code>touching</code>.
|
|
||||||
* However, this method is good for readability and accessibility.
|
|
||||||
*
|
|
||||||
* @param Direction Any of the collision flags (e.g. LEFT, FLOOR, etc).
|
|
||||||
*
|
|
||||||
* @return Whether the object is touching an object in (any of) the specified direction(s) this frame.
|
|
||||||
*/
|
|
||||||
public isTouching(Direction: number): bool {
|
|
||||||
return (this.touching & Direction) > Collision.NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handy for checking if this object is just landed on a particular surface.
|
|
||||||
*
|
|
||||||
* @param Direction Any of the collision flags (e.g. LEFT, FLOOR, etc).
|
|
||||||
*
|
|
||||||
* @return Whether the object just landed on (any of) the specified surface(s) this frame.
|
|
||||||
*/
|
|
||||||
public justTouched(Direction: number): bool {
|
|
||||||
return ((this.touching & Direction) > Collision.NONE) && ((this.wasTouching & Direction) <= Collision.NONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reduces the "health" variable of this sprite by the amount specified in Damage.
|
|
||||||
* Calls kill() if health drops to or below zero.
|
|
||||||
*
|
|
||||||
* @param Damage How much health to take away (use a negative number to give a health bonus).
|
|
||||||
*/
|
|
||||||
public hurt(Damage: number) {
|
|
||||||
|
|
||||||
this.health = this.health - Damage;
|
|
||||||
|
|
||||||
if (this.health <= 0)
|
|
||||||
{
|
|
||||||
this.kill();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the world bounds that this GameObject can exist within. By default a GameObject can exist anywhere
|
|
||||||
* in the world. But by setting the bounds (which are given in world dimensions, not screen dimensions)
|
|
||||||
* it can be stopped from leaving the world, or a section of it.
|
|
||||||
*/
|
|
||||||
public setBounds(x: number, y: number, width: number, height: number) {
|
|
||||||
|
|
||||||
this.worldBounds = new Quad(x, y, width, height);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If you do not wish this object to be visible to a specific camera, pass the camera here.
|
|
||||||
*/
|
|
||||||
public hideFromCamera(camera: Camera) {
|
|
||||||
|
|
||||||
if (this.cameraBlacklist.indexOf(camera.ID) == -1)
|
|
||||||
{
|
|
||||||
this.cameraBlacklist.push(camera.ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public showToCamera(camera: Camera) {
|
|
||||||
|
|
||||||
if (this.cameraBlacklist.indexOf(camera.ID) !== -1)
|
|
||||||
{
|
|
||||||
this.cameraBlacklist.slice(this.cameraBlacklist.indexOf(camera.ID), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public clearCameraList() {
|
|
||||||
|
|
||||||
this.cameraBlacklist.length = 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public destroy() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public get x(): number {
|
|
||||||
return this.bounds.x;
|
|
||||||
}
|
|
||||||
|
|
||||||
public set x(value: number) {
|
|
||||||
this.bounds.x = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get y(): number {
|
|
||||||
return this.bounds.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public set y(value: number) {
|
|
||||||
this.bounds.y = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get rotation(): number {
|
|
||||||
return this._angle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public set rotation(value: number) {
|
|
||||||
this._angle = this._game.math.wrap(value, 360, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public get angle(): number {
|
|
||||||
return this._angle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public set angle(value: number) {
|
|
||||||
this._angle = this._game.math.wrap(value, 360, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public set width(value:number) {
|
|
||||||
this.bounds.width = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public set height(value:number) {
|
|
||||||
this.bounds.height = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get width(): number {
|
|
||||||
return this.bounds.width;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get height(): number {
|
|
||||||
return this.bounds.height;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,457 +0,0 @@
|
|||||||
/// <reference path="../Game.ts" />
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Phaser - GeomSprite
|
|
||||||
*
|
|
||||||
* A GeomSprite is a special kind of GameObject that contains a base geometry class (Circle, Line, Point, Rectangle).
|
|
||||||
* They can be rendered in the game and used for collision just like any other game object. Display of them is controlled
|
|
||||||
* via the lineWidth / lineColor / fillColor and renderOutline / renderFill properties.
|
|
||||||
*/
|
|
||||||
|
|
||||||
module Phaser {
|
|
||||||
|
|
||||||
export class GeomSprite extends GameObject {
|
|
||||||
|
|
||||||
constructor(game: Game, x?: number = 0, y?: number = 0) {
|
|
||||||
|
|
||||||
super(game, x, y);
|
|
||||||
|
|
||||||
this.type = GeomSprite.UNASSIGNED;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// local rendering related temp vars to help avoid gc spikes
|
|
||||||
private _dx: number = 0;
|
|
||||||
private _dy: number = 0;
|
|
||||||
private _dw: number = 0;
|
|
||||||
private _dh: number = 0;
|
|
||||||
|
|
||||||
public type: number = 0;
|
|
||||||
|
|
||||||
public static UNASSIGNED: number = 0;
|
|
||||||
public static CIRCLE: number = 1;
|
|
||||||
public static LINE: number = 2;
|
|
||||||
public static POINT: number = 3;
|
|
||||||
public static RECTANGLE: number = 4;
|
|
||||||
|
|
||||||
public circle: Circle;
|
|
||||||
public line: Line;
|
|
||||||
public point: Point;
|
|
||||||
public rect: Rectangle;
|
|
||||||
|
|
||||||
public renderOutline: bool = true;
|
|
||||||
public renderFill: bool = true;
|
|
||||||
|
|
||||||
public lineWidth: number = 1;
|
|
||||||
public lineColor: string = 'rgb(0,255,0)';
|
|
||||||
public fillColor: string = 'rgb(0,100,0)';
|
|
||||||
|
|
||||||
loadCircle(circle:Circle): GeomSprite {
|
|
||||||
|
|
||||||
this.refresh();
|
|
||||||
this.circle = circle;
|
|
||||||
this.type = GeomSprite.CIRCLE;
|
|
||||||
return this;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
loadLine(line:Line): GeomSprite {
|
|
||||||
|
|
||||||
this.refresh();
|
|
||||||
this.line = line;
|
|
||||||
this.type = GeomSprite.LINE;
|
|
||||||
return this;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
loadPoint(point:Point): GeomSprite {
|
|
||||||
|
|
||||||
this.refresh();
|
|
||||||
this.point = point;
|
|
||||||
this.type = GeomSprite.POINT;
|
|
||||||
return this;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
loadRectangle(rect:Rectangle): GeomSprite {
|
|
||||||
|
|
||||||
this.refresh();
|
|
||||||
this.rect = rect;
|
|
||||||
this.type = GeomSprite.RECTANGLE;
|
|
||||||
return this;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
createCircle(diameter: number): GeomSprite {
|
|
||||||
|
|
||||||
this.refresh();
|
|
||||||
this.circle = new Circle(this.x, this.y, diameter);
|
|
||||||
this.type = GeomSprite.CIRCLE;
|
|
||||||
this.bounds.setTo(this.circle.x - this.circle.radius, this.circle.y - this.circle.radius, this.circle.diameter, this.circle.diameter);
|
|
||||||
return this;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
createLine(x: number, y: number): GeomSprite {
|
|
||||||
|
|
||||||
this.refresh();
|
|
||||||
this.line = new Line(this.x, this.y, x, y);
|
|
||||||
this.type = GeomSprite.LINE;
|
|
||||||
this.bounds.setTo(this.x, this.y, this.line.width, this.line.height);
|
|
||||||
return this;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
createPoint(): GeomSprite {
|
|
||||||
|
|
||||||
this.refresh();
|
|
||||||
this.point = new Point(this.x, this.y);
|
|
||||||
this.type = GeomSprite.POINT;
|
|
||||||
this.bounds.width = 1;
|
|
||||||
this.bounds.height = 1;
|
|
||||||
return this;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
createRectangle(width: number, height: number): GeomSprite {
|
|
||||||
|
|
||||||
this.refresh();
|
|
||||||
this.rect = new Rectangle(this.x, this.y, width, height);
|
|
||||||
this.type = GeomSprite.RECTANGLE;
|
|
||||||
this.bounds.copyFrom(this.rect);
|
|
||||||
return this;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
refresh() {
|
|
||||||
|
|
||||||
this.circle = null;
|
|
||||||
this.line = null;
|
|
||||||
this.point = null;
|
|
||||||
this.rect = null;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
update() {
|
|
||||||
|
|
||||||
// Update bounds and position?
|
|
||||||
if (this.type == GeomSprite.UNASSIGNED)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (this.type == GeomSprite.CIRCLE)
|
|
||||||
{
|
|
||||||
this.circle.x = this.x;
|
|
||||||
this.circle.y = this.y;
|
|
||||||
this.bounds.width = this.circle.diameter;
|
|
||||||
this.bounds.height = this.circle.diameter;
|
|
||||||
}
|
|
||||||
else if (this.type == GeomSprite.LINE)
|
|
||||||
{
|
|
||||||
this.line.x1 = this.x;
|
|
||||||
this.line.y1 = this.y;
|
|
||||||
this.bounds.setTo(this.x, this.y, this.line.width, this.line.height);
|
|
||||||
}
|
|
||||||
else if (this.type == GeomSprite.POINT)
|
|
||||||
{
|
|
||||||
this.point.x = this.x;
|
|
||||||
this.point.y = this.y;
|
|
||||||
}
|
|
||||||
else if (this.type == GeomSprite.RECTANGLE)
|
|
||||||
{
|
|
||||||
this.rect.x = this.x;
|
|
||||||
this.rect.y = this.y;
|
|
||||||
this.bounds.copyFrom(this.rect);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public inCamera(camera: Rectangle): bool {
|
|
||||||
|
|
||||||
if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0)
|
|
||||||
{
|
|
||||||
this._dx = this.bounds.x - (camera.x * this.scrollFactor.x);
|
|
||||||
this._dy = this.bounds.y - (camera.y * this.scrollFactor.x);
|
|
||||||
this._dw = this.bounds.width * this.scale.x;
|
|
||||||
this._dh = this.bounds.height * this.scale.y;
|
|
||||||
|
|
||||||
return (camera.right > this._dx) && (camera.x < this._dx + this._dw) && (camera.bottom > this._dy) && (camera.y < this._dy + this._dh);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return camera.intersects(this.bounds);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number): bool {
|
|
||||||
|
|
||||||
// Render checks
|
|
||||||
if (this.type == GeomSprite.UNASSIGNED || this.visible === false || this.scale.x == 0 || this.scale.y == 0 || this.alpha < 0.1 || this.cameraBlacklist.indexOf(camera.ID) !== -1 || this.inCamera(camera.worldView) == false)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Alpha
|
|
||||||
if (this.alpha !== 1)
|
|
||||||
{
|
|
||||||
var globalAlpha = this._game.stage.context.globalAlpha;
|
|
||||||
this._game.stage.context.globalAlpha = this.alpha;
|
|
||||||
}
|
|
||||||
|
|
||||||
this._dx = cameraOffsetX + (this.bounds.x - camera.worldView.x);
|
|
||||||
this._dy = cameraOffsetY + (this.bounds.y - camera.worldView.y);
|
|
||||||
this._dw = this.bounds.width * this.scale.x;
|
|
||||||
this._dh = this.bounds.height * this.scale.y;
|
|
||||||
|
|
||||||
// Circles are drawn center based
|
|
||||||
if (this.type == GeomSprite.CIRCLE)
|
|
||||||
{
|
|
||||||
this._dx += this.circle.radius;
|
|
||||||
this._dy += this.circle.radius;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply camera difference
|
|
||||||
if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0)
|
|
||||||
{
|
|
||||||
this._dx -= (camera.worldView.x * this.scrollFactor.x);
|
|
||||||
this._dy -= (camera.worldView.y * this.scrollFactor.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rotation is disabled for now as I don't want it to be misleading re: collision
|
|
||||||
/*
|
|
||||||
if (this.angle !== 0)
|
|
||||||
{
|
|
||||||
this._game.stage.context.save();
|
|
||||||
this._game.stage.context.translate(this._dx + (this._dw / 2) - this.origin.x, this._dy + (this._dh / 2) - this.origin.y);
|
|
||||||
this._game.stage.context.rotate(this.angle * (Math.PI / 180));
|
|
||||||
this._dx = -(this._dw / 2);
|
|
||||||
this._dy = -(this._dh / 2);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
this._dx = Math.round(this._dx);
|
|
||||||
this._dy = Math.round(this._dy);
|
|
||||||
this._dw = Math.round(this._dw);
|
|
||||||
this._dh = Math.round(this._dh);
|
|
||||||
|
|
||||||
this._game.stage.saveCanvasValues();
|
|
||||||
|
|
||||||
// Debug
|
|
||||||
//this._game.stage.context.fillStyle = 'rgba(255,0,0,0.5)';
|
|
||||||
//this._game.stage.context.fillRect(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
|
|
||||||
|
|
||||||
this._game.stage.context.lineWidth = this.lineWidth;
|
|
||||||
this._game.stage.context.strokeStyle = this.lineColor;
|
|
||||||
this._game.stage.context.fillStyle = this.fillColor;
|
|
||||||
|
|
||||||
if (this._game.stage.fillStyle !== this.fillColor)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// Primitive Renderer
|
|
||||||
if (this.type == GeomSprite.CIRCLE)
|
|
||||||
{
|
|
||||||
this._game.stage.context.beginPath();
|
|
||||||
this._game.stage.context.arc(this._dx, this._dy, this.circle.radius, 0, Math.PI * 2);
|
|
||||||
this._game.stage.context.stroke();
|
|
||||||
|
|
||||||
if (this.renderFill)
|
|
||||||
{
|
|
||||||
this._game.stage.context.fill();
|
|
||||||
}
|
|
||||||
|
|
||||||
this._game.stage.context.closePath();
|
|
||||||
}
|
|
||||||
else if (this.type == GeomSprite.LINE)
|
|
||||||
{
|
|
||||||
this._game.stage.context.beginPath();
|
|
||||||
this._game.stage.context.moveTo(this._dx, this._dy);
|
|
||||||
this._game.stage.context.lineTo(this.line.x2, this.line.y2);
|
|
||||||
this._game.stage.context.stroke();
|
|
||||||
this._game.stage.context.closePath();
|
|
||||||
}
|
|
||||||
else if (this.type == GeomSprite.POINT)
|
|
||||||
{
|
|
||||||
this._game.stage.context.fillRect(this._dx, this._dy, 2, 2);
|
|
||||||
}
|
|
||||||
else if (this.type == GeomSprite.RECTANGLE)
|
|
||||||
{
|
|
||||||
// We can use the faster fillRect if we don't need the outline
|
|
||||||
if (this.renderOutline == false)
|
|
||||||
{
|
|
||||||
this._game.stage.context.fillRect(this._dx, this._dy, this.rect.width, this.rect.height);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this._game.stage.context.beginPath();
|
|
||||||
this._game.stage.context.rect(this._dx, this._dy, this.rect.width, this.rect.height);
|
|
||||||
this._game.stage.context.stroke();
|
|
||||||
|
|
||||||
if (this.renderFill)
|
|
||||||
{
|
|
||||||
this._game.stage.context.fill();
|
|
||||||
}
|
|
||||||
|
|
||||||
this._game.stage.context.closePath();
|
|
||||||
}
|
|
||||||
|
|
||||||
// And now the edge points
|
|
||||||
this._game.stage.context.fillStyle = 'rgb(255,255,255)';
|
|
||||||
this.renderPoint(this._dx, this._dy, this.rect.topLeft, 2);
|
|
||||||
this.renderPoint(this._dx, this._dy, this.rect.topCenter, 2);
|
|
||||||
this.renderPoint(this._dx, this._dy, this.rect.topRight, 2);
|
|
||||||
this.renderPoint(this._dx, this._dy, this.rect.leftCenter, 2);
|
|
||||||
this.renderPoint(this._dx, this._dy, this.rect.center, 2);
|
|
||||||
this.renderPoint(this._dx, this._dy, this.rect.rightCenter, 2);
|
|
||||||
this.renderPoint(this._dx, this._dy, this.rect.bottomLeft, 2);
|
|
||||||
this.renderPoint(this._dx, this._dy, this.rect.bottomCenter, 2);
|
|
||||||
this.renderPoint(this._dx, this._dy, this.rect.bottomRight, 2);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
this._game.stage.restoreCanvasValues();
|
|
||||||
|
|
||||||
if (this.rotation !== 0)
|
|
||||||
{
|
|
||||||
this._game.stage.context.translate(0, 0);
|
|
||||||
this._game.stage.context.restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (globalAlpha > -1)
|
|
||||||
{
|
|
||||||
this._game.stage.context.globalAlpha = globalAlpha;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public renderPoint(offsetX, offsetY, point, size) {
|
|
||||||
|
|
||||||
offsetX = 0;
|
|
||||||
offsetY = 0;
|
|
||||||
this._game.stage.context.fillRect(offsetX + point.x, offsetY + point.y, 1, 1);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
|
|
||||||
|
|
||||||
//this._game.stage.context.fillStyle = color;
|
|
||||||
//this._game.stage.context.fillText('Sprite: ' + this.name + ' (' + this.bounds.width + ' x ' + this.bounds.height + ')', x, y);
|
|
||||||
//this._game.stage.context.fillText('x: ' + this.bounds.x.toFixed(1) + ' y: ' + this.bounds.y.toFixed(1) + ' rotation: ' + this.angle.toFixed(1), x, y + 14);
|
|
||||||
//this._game.stage.context.fillText('dx: ' + this._dx.toFixed(1) + ' dy: ' + this._dy.toFixed(1) + ' dw: ' + this._dw.toFixed(1) + ' dh: ' + this._dh.toFixed(1), x, y + 28);
|
|
||||||
//this._game.stage.context.fillText('sx: ' + this._sx.toFixed(1) + ' sy: ' + this._sy.toFixed(1) + ' sw: ' + this._sw.toFixed(1) + ' sh: ' + this._sh.toFixed(1), x, y + 42);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gives a basic boolean response to a geometric collision.
|
|
||||||
// If you need the details of the collision use the Collision functions instead and inspect the IntersectResult object.
|
|
||||||
public collide(source: GeomSprite): bool {
|
|
||||||
|
|
||||||
// Circle vs. Circle
|
|
||||||
if (this.type == GeomSprite.CIRCLE && source.type == GeomSprite.CIRCLE)
|
|
||||||
{
|
|
||||||
return Collision.circleToCircle(this.circle, source.circle).result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Circle vs. Rect
|
|
||||||
if (this.type == GeomSprite.CIRCLE && source.type == GeomSprite.RECTANGLE)
|
|
||||||
{
|
|
||||||
return Collision.circleToRectangle(this.circle, source.rect).result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Circle vs. Point
|
|
||||||
if (this.type == GeomSprite.CIRCLE && source.type == GeomSprite.POINT)
|
|
||||||
{
|
|
||||||
return Collision.circleContainsPoint(this.circle, source.point).result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Circle vs. Line
|
|
||||||
if (this.type == GeomSprite.CIRCLE && source.type == GeomSprite.LINE)
|
|
||||||
{
|
|
||||||
return Collision.lineToCircle(source.line, this.circle).result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rect vs. Rect
|
|
||||||
if (this.type == GeomSprite.RECTANGLE && source.type == GeomSprite.RECTANGLE)
|
|
||||||
{
|
|
||||||
return Collision.rectangleToRectangle(this.rect, source.rect).result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rect vs. Circle
|
|
||||||
if (this.type == GeomSprite.RECTANGLE && source.type == GeomSprite.CIRCLE)
|
|
||||||
{
|
|
||||||
return Collision.circleToRectangle(source.circle, this.rect).result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rect vs. Point
|
|
||||||
if (this.type == GeomSprite.RECTANGLE && source.type == GeomSprite.POINT)
|
|
||||||
{
|
|
||||||
return Collision.pointToRectangle(source.point, this.rect).result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rect vs. Line
|
|
||||||
if (this.type == GeomSprite.RECTANGLE && source.type == GeomSprite.LINE)
|
|
||||||
{
|
|
||||||
return Collision.lineToRectangle(source.line, this.rect).result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Point vs. Point
|
|
||||||
if (this.type == GeomSprite.POINT && source.type == GeomSprite.POINT)
|
|
||||||
{
|
|
||||||
return this.point.equals(source.point);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Point vs. Circle
|
|
||||||
if (this.type == GeomSprite.POINT && source.type == GeomSprite.CIRCLE)
|
|
||||||
{
|
|
||||||
return Collision.circleContainsPoint(source.circle, this.point).result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Point vs. Rect
|
|
||||||
if (this.type == GeomSprite.POINT && source.type == GeomSprite.RECTANGLE)
|
|
||||||
{
|
|
||||||
return Collision.pointToRectangle(this.point, source.rect).result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Point vs. Line
|
|
||||||
if (this.type == GeomSprite.POINT && source.type == GeomSprite.LINE)
|
|
||||||
{
|
|
||||||
return source.line.isPointOnLine(this.point.x, this.point.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Line vs. Line
|
|
||||||
if (this.type == GeomSprite.LINE && source.type == GeomSprite.LINE)
|
|
||||||
{
|
|
||||||
return Collision.lineSegmentToLineSegment(this.line, source.line).result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Line vs. Circle
|
|
||||||
if (this.type == GeomSprite.LINE && source.type == GeomSprite.CIRCLE)
|
|
||||||
{
|
|
||||||
return Collision.lineToCircle(this.line, source.circle).result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Line vs. Rect
|
|
||||||
if (this.type == GeomSprite.LINE && source.type == GeomSprite.RECTANGLE)
|
|
||||||
{
|
|
||||||
return Collision.lineSegmentToRectangle(this.line, source.rect).result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Line vs. Point
|
|
||||||
if (this.type == GeomSprite.LINE && source.type == GeomSprite.POINT)
|
|
||||||
{
|
|
||||||
return this.line.isPointOnLine(source.point.x, source.point.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,108 +0,0 @@
|
|||||||
/// <reference path="../Game.ts" />
|
|
||||||
/// <reference path="Sprite.ts" />
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Phaser - Particle
|
|
||||||
*
|
|
||||||
* This is a simple particle class that extends a Sprite to have a slightly more
|
|
||||||
* specialised behaviour. It is used exclusively by the Emitter class and can be extended as required.
|
|
||||||
*/
|
|
||||||
|
|
||||||
module Phaser {
|
|
||||||
|
|
||||||
export class Particle extends Sprite {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiate a new particle. Like <code>Sprite</code>, all meaningful creation
|
|
||||||
* happens during <code>loadGraphic()</code> or <code>makeGraphic()</code> or whatever.
|
|
||||||
*/
|
|
||||||
constructor(game: Game) {
|
|
||||||
|
|
||||||
super(game);
|
|
||||||
|
|
||||||
this.lifespan = 0;
|
|
||||||
this.friction = 500;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* How long this particle lives before it disappears.
|
|
||||||
* NOTE: this is a maximum, not a minimum; the object
|
|
||||||
* could get recycled before its lifespan is up.
|
|
||||||
*/
|
|
||||||
public lifespan: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines how quickly the particles come to rest on the ground.
|
|
||||||
* Only used if the particle has gravity-like acceleration applied.
|
|
||||||
* @default 500
|
|
||||||
*/
|
|
||||||
public friction: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The particle's main update logic. Basically it checks to see if it should
|
|
||||||
* be dead yet, and then has some special bounce behavior if there is some gravity on it.
|
|
||||||
*/
|
|
||||||
public update() {
|
|
||||||
|
|
||||||
//lifespan behavior
|
|
||||||
if (this.lifespan <= 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.lifespan -= this._game.time.elapsed;
|
|
||||||
|
|
||||||
if (this.lifespan <= 0)
|
|
||||||
{
|
|
||||||
this.kill();
|
|
||||||
}
|
|
||||||
|
|
||||||
//simpler bounce/spin behavior for now
|
|
||||||
if (this.touching)
|
|
||||||
{
|
|
||||||
if (this.angularVelocity != 0)
|
|
||||||
{
|
|
||||||
this.angularVelocity = -this.angularVelocity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.acceleration.y > 0) //special behavior for particles with gravity
|
|
||||||
{
|
|
||||||
if (this.touching & Collision.FLOOR)
|
|
||||||
{
|
|
||||||
this.drag.x = this.friction;
|
|
||||||
|
|
||||||
if (!(this.wasTouching & Collision.FLOOR))
|
|
||||||
{
|
|
||||||
if (this.velocity.y < -this.elasticity * 10)
|
|
||||||
{
|
|
||||||
if (this.angularVelocity != 0)
|
|
||||||
{
|
|
||||||
this.angularVelocity *= -this.elasticity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.velocity.y = 0;
|
|
||||||
this.angularVelocity = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.drag.x = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggered whenever this object is launched by a <code>Emitter</code>.
|
|
||||||
* You can override this to add custom behavior like a sound or AI or something.
|
|
||||||
*/
|
|
||||||
public onEmit() {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,208 +0,0 @@
|
|||||||
/// <reference path="../Game.ts" />
|
|
||||||
/// <reference path="../geom/Quad.ts" />
|
|
||||||
/// <reference path="ScrollRegion.ts" />
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Phaser - ScrollZone
|
|
||||||
*
|
|
||||||
* Creates a scrolling region of the given width and height from an image in the cache.
|
|
||||||
* The ScrollZone can be positioned anywhere in-world like a normal game object, re-act to physics, collision, etc.
|
|
||||||
* The image within it is scrolled via ScrollRegions and their scrollSpeed.x/y properties.
|
|
||||||
* If you create a scroll zone larger than the given source image it will create a DynamicTexture and fill it with a pattern of the source image.
|
|
||||||
*/
|
|
||||||
|
|
||||||
module Phaser {
|
|
||||||
|
|
||||||
export class ScrollZone extends GameObject {
|
|
||||||
|
|
||||||
constructor(game: Game, key:string, x: number = 0, y: number = 0, width?: number = 0, height?: number = 0) {
|
|
||||||
|
|
||||||
super(game, x, y, width, height);
|
|
||||||
|
|
||||||
this.regions = [];
|
|
||||||
|
|
||||||
if (this._game.cache.getImage(key))
|
|
||||||
{
|
|
||||||
this._texture = this._game.cache.getImage(key);
|
|
||||||
this.width = this._texture.width;
|
|
||||||
this.height = this._texture.height;
|
|
||||||
|
|
||||||
if (width > this._texture.width || height > this._texture.height)
|
|
||||||
{
|
|
||||||
// Create our repeating texture (as the source image wasn't large enough for the requested size)
|
|
||||||
this.createRepeatingTexture(width, height);
|
|
||||||
this.width = width;
|
|
||||||
this.height = height;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a default ScrollRegion at the requested size
|
|
||||||
this.addRegion(0, 0, this.width, this.height);
|
|
||||||
|
|
||||||
// If the zone is smaller than the image itself then shrink the bounds
|
|
||||||
if ((width < this._texture.width || height < this._texture.height) && width !== 0 && height !== 0)
|
|
||||||
{
|
|
||||||
this.width = width;
|
|
||||||
this.height = height;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private _texture;
|
|
||||||
private _dynamicTexture: DynamicTexture = null;
|
|
||||||
|
|
||||||
// local rendering related temp vars to help avoid gc spikes
|
|
||||||
private _dx: number = 0;
|
|
||||||
private _dy: number = 0;
|
|
||||||
private _dw: number = 0;
|
|
||||||
private _dh: number = 0;
|
|
||||||
|
|
||||||
public currentRegion: ScrollRegion;
|
|
||||||
public regions: ScrollRegion[];
|
|
||||||
public flipped: bool = false;
|
|
||||||
|
|
||||||
public addRegion(x: number, y: number, width: number, height: number, speedX?:number = 0, speedY?:number = 0):ScrollRegion {
|
|
||||||
|
|
||||||
if (x > this.width || y > this.height || x < 0 || y < 0 || (x + width) > this.width || (y + height) > this.height)
|
|
||||||
{
|
|
||||||
throw Error('Invalid ScrollRegion defined. Cannot be larger than parent ScrollZone');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.currentRegion = new ScrollRegion(x, y, width, height, speedX, speedY);
|
|
||||||
|
|
||||||
this.regions.push(this.currentRegion);
|
|
||||||
|
|
||||||
return this.currentRegion;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public setSpeed(x: number, y: number) {
|
|
||||||
|
|
||||||
if (this.currentRegion)
|
|
||||||
{
|
|
||||||
this.currentRegion.scrollSpeed.setTo(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public update() {
|
|
||||||
|
|
||||||
for (var i = 0; i < this.regions.length; i++)
|
|
||||||
{
|
|
||||||
this.regions[i].update(this._game.time.delta);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public inCamera(camera: Rectangle): bool {
|
|
||||||
|
|
||||||
if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0)
|
|
||||||
{
|
|
||||||
this._dx = this.bounds.x - (camera.x * this.scrollFactor.x);
|
|
||||||
this._dy = this.bounds.y - (camera.y * this.scrollFactor.x);
|
|
||||||
this._dw = this.bounds.width * this.scale.x;
|
|
||||||
this._dh = this.bounds.height * this.scale.y;
|
|
||||||
|
|
||||||
return (camera.right > this._dx) && (camera.x < this._dx + this._dw) && (camera.bottom > this._dy) && (camera.y < this._dy + this._dh);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return camera.intersects(this.bounds, this.bounds.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number) {
|
|
||||||
|
|
||||||
// Render checks
|
|
||||||
if (this.visible == false || this.scale.x == 0 || this.scale.y == 0 || this.alpha < 0.1 || this.cameraBlacklist.indexOf(camera.ID) !== -1 || this.inCamera(camera.worldView) == false)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Alpha
|
|
||||||
if (this.alpha !== 1)
|
|
||||||
{
|
|
||||||
var globalAlpha = this._game.stage.context.globalAlpha;
|
|
||||||
this._game.stage.context.globalAlpha = this.alpha;
|
|
||||||
}
|
|
||||||
|
|
||||||
this._dx = cameraOffsetX + (this.bounds.topLeft.x - camera.worldView.x);
|
|
||||||
this._dy = cameraOffsetY + (this.bounds.topLeft.y - camera.worldView.y);
|
|
||||||
this._dw = this.bounds.width * this.scale.x;
|
|
||||||
this._dh = this.bounds.height * this.scale.y;
|
|
||||||
|
|
||||||
// Apply camera difference
|
|
||||||
if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0)
|
|
||||||
{
|
|
||||||
this._dx -= (camera.worldView.x * this.scrollFactor.x);
|
|
||||||
this._dy -= (camera.worldView.y * this.scrollFactor.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rotation - needs to work from origin point really, but for now from center
|
|
||||||
if (this.angle !== 0 || this.flipped == true)
|
|
||||||
{
|
|
||||||
this._game.stage.context.save();
|
|
||||||
this._game.stage.context.translate(this._dx + (this._dw / 2), this._dy + (this._dh / 2));
|
|
||||||
|
|
||||||
if (this.angle !== 0)
|
|
||||||
{
|
|
||||||
this._game.stage.context.rotate(this.angle * (Math.PI / 180));
|
|
||||||
}
|
|
||||||
|
|
||||||
this._dx = -(this._dw / 2);
|
|
||||||
this._dy = -(this._dh / 2);
|
|
||||||
|
|
||||||
if (this.flipped == true)
|
|
||||||
{
|
|
||||||
this._game.stage.context.scale(-1, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this._dx = Math.round(this._dx);
|
|
||||||
this._dy = Math.round(this._dy);
|
|
||||||
this._dw = Math.round(this._dw);
|
|
||||||
this._dh = Math.round(this._dh);
|
|
||||||
|
|
||||||
for (var i = 0; i < this.regions.length; i++)
|
|
||||||
{
|
|
||||||
if (this._dynamicTexture)
|
|
||||||
{
|
|
||||||
this.regions[i].render(this._game.stage.context, this._dynamicTexture.canvas, this._dx, this._dy, this._dw, this._dh);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.regions[i].render(this._game.stage.context, this._texture, this._dx, this._dy, this._dw, this._dh);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (globalAlpha > -1)
|
|
||||||
{
|
|
||||||
this._game.stage.context.globalAlpha = globalAlpha;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private createRepeatingTexture(regionWidth: number, regionHeight: number) {
|
|
||||||
|
|
||||||
// Work out how many we'll need of the source image to make it tile properly
|
|
||||||
var tileWidth = Math.ceil(this._texture.width / regionWidth) * regionWidth;
|
|
||||||
var tileHeight = Math.ceil(this._texture.height / regionHeight) * regionHeight;
|
|
||||||
|
|
||||||
this._dynamicTexture = new DynamicTexture(this._game, tileWidth, tileHeight);
|
|
||||||
|
|
||||||
this._dynamicTexture.context.rect(0, 0, tileWidth, tileHeight);
|
|
||||||
this._dynamicTexture.context.fillStyle = this._dynamicTexture.context.createPattern(this._texture, "repeat");
|
|
||||||
this._dynamicTexture.context.fill();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,351 +0,0 @@
|
|||||||
/// <reference path="../Game.ts" />
|
|
||||||
/// <reference path="../AnimationManager.ts" />
|
|
||||||
/// <reference path="GameObject.ts" />
|
|
||||||
/// <reference path="../system/Camera.ts" />
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Phaser - Sprite
|
|
||||||
*
|
|
||||||
* The Sprite GameObject is an extension of the core GameObject that includes support for animation and dynamic textures.
|
|
||||||
* It's probably the most used GameObject of all.
|
|
||||||
*/
|
|
||||||
|
|
||||||
module Phaser {
|
|
||||||
|
|
||||||
export class Sprite extends GameObject {
|
|
||||||
|
|
||||||
constructor(game: Game, x?: number = 0, y?: number = 0, key?: string = null) {
|
|
||||||
|
|
||||||
super(game, x, y);
|
|
||||||
|
|
||||||
this._texture = null;
|
|
||||||
|
|
||||||
this.animations = new AnimationManager(this._game, this);
|
|
||||||
|
|
||||||
if (key !== null)
|
|
||||||
{
|
|
||||||
this.loadGraphic(key);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.bounds.width = 16;
|
|
||||||
this.bounds.height = 16;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private _texture;
|
|
||||||
private _dynamicTexture: bool = false;
|
|
||||||
|
|
||||||
// local rendering related temp vars to help avoid gc spikes
|
|
||||||
private _sx: number = 0;
|
|
||||||
private _sy: number = 0;
|
|
||||||
private _sw: number = 0;
|
|
||||||
private _sh: number = 0;
|
|
||||||
private _dx: number = 0;
|
|
||||||
private _dy: number = 0;
|
|
||||||
private _dw: number = 0;
|
|
||||||
private _dh: number = 0;
|
|
||||||
|
|
||||||
public animations: AnimationManager;
|
|
||||||
|
|
||||||
public renderDebug: bool = false;
|
|
||||||
public renderDebugColor: string = 'rgba(0,255,0,0.5)';
|
|
||||||
public renderDebugPointColor: string = 'rgba(255,255,255,1)';
|
|
||||||
public flipped: bool = false;
|
|
||||||
|
|
||||||
public loadGraphic(key: string): Sprite {
|
|
||||||
|
|
||||||
if (this._game.cache.getImage(key) !== null)
|
|
||||||
{
|
|
||||||
if (this._game.cache.isSpriteSheet(key) == false)
|
|
||||||
{
|
|
||||||
this._texture = this._game.cache.getImage(key);
|
|
||||||
this.bounds.width = this._texture.width;
|
|
||||||
this.bounds.height = this._texture.height;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this._texture = this._game.cache.getImage(key);
|
|
||||||
this.animations.loadFrameData(this._game.cache.getFrameData(key));
|
|
||||||
}
|
|
||||||
|
|
||||||
this._dynamicTexture = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public loadDynamicTexture(texture: DynamicTexture): Sprite {
|
|
||||||
|
|
||||||
this._texture = texture;
|
|
||||||
|
|
||||||
this.bounds.width = this._texture.width;
|
|
||||||
this.bounds.height = this._texture.height;
|
|
||||||
|
|
||||||
this._dynamicTexture = true;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public makeGraphic(width: number, height: number, color: number = 0xffffffff): Sprite {
|
|
||||||
|
|
||||||
this._texture = null;
|
|
||||||
this.width = width;
|
|
||||||
this.height = height;
|
|
||||||
|
|
||||||
this._dynamicTexture = false;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public inCamera(camera: Rectangle): bool {
|
|
||||||
|
|
||||||
if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0)
|
|
||||||
{
|
|
||||||
this._dx = this.bounds.x - (camera.x * this.scrollFactor.x);
|
|
||||||
this._dy = this.bounds.y - (camera.y * this.scrollFactor.x);
|
|
||||||
this._dw = this.bounds.width * this.scale.x;
|
|
||||||
this._dh = this.bounds.height * this.scale.y;
|
|
||||||
|
|
||||||
return (camera.right > this._dx) && (camera.x < this._dx + this._dw) && (camera.bottom > this._dy) && (camera.y < this._dy + this._dh);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return camera.intersects(this.bounds, this.bounds.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public postUpdate() {
|
|
||||||
|
|
||||||
this.animations.update();
|
|
||||||
|
|
||||||
super.postUpdate();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public set frame(value: number) {
|
|
||||||
this.animations.frame = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get frame(): number {
|
|
||||||
return this.animations.frame;
|
|
||||||
}
|
|
||||||
|
|
||||||
public set frameName(value: string) {
|
|
||||||
this.animations.frameName = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get frameName(): string {
|
|
||||||
return this.animations.frameName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number): bool {
|
|
||||||
|
|
||||||
// Render checks
|
|
||||||
if (this.visible == false || this.scale.x == 0 || this.scale.y == 0 || this.alpha < 0.1 || this.cameraBlacklist.indexOf(camera.ID) !== -1 || this.inCamera(camera.worldView) == false)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Alpha
|
|
||||||
if (this.alpha !== 1)
|
|
||||||
{
|
|
||||||
var globalAlpha = this._game.stage.context.globalAlpha;
|
|
||||||
this._game.stage.context.globalAlpha = this.alpha;
|
|
||||||
}
|
|
||||||
|
|
||||||
this._sx = 0;
|
|
||||||
this._sy = 0;
|
|
||||||
this._sw = this.bounds.width;
|
|
||||||
this._sh = this.bounds.height;
|
|
||||||
this._dx = cameraOffsetX + (this.bounds.topLeft.x - camera.worldView.x);
|
|
||||||
this._dy = cameraOffsetY + (this.bounds.topLeft.y - camera.worldView.y);
|
|
||||||
this._dw = this.bounds.width * this.scale.x;
|
|
||||||
this._dh = this.bounds.height * this.scale.y;
|
|
||||||
|
|
||||||
if (this.align == GameObject.ALIGN_TOP_CENTER)
|
|
||||||
{
|
|
||||||
this._dx -= this.bounds.halfWidth * this.scale.x;
|
|
||||||
}
|
|
||||||
else if (this.align == GameObject.ALIGN_TOP_RIGHT)
|
|
||||||
{
|
|
||||||
this._dx -= this.bounds.width * this.scale.x;
|
|
||||||
}
|
|
||||||
else if (this.align == GameObject.ALIGN_CENTER_LEFT)
|
|
||||||
{
|
|
||||||
this._dy -= this.bounds.halfHeight * this.scale.y;
|
|
||||||
}
|
|
||||||
else if (this.align == GameObject.ALIGN_CENTER)
|
|
||||||
{
|
|
||||||
this._dx -= this.bounds.halfWidth * this.scale.x;
|
|
||||||
this._dy -= this.bounds.halfHeight * this.scale.y;
|
|
||||||
}
|
|
||||||
else if (this.align == GameObject.ALIGN_CENTER_RIGHT)
|
|
||||||
{
|
|
||||||
this._dx -= this.bounds.width * this.scale.x;
|
|
||||||
this._dy -= this.bounds.halfHeight * this.scale.y;
|
|
||||||
}
|
|
||||||
else if (this.align == GameObject.ALIGN_BOTTOM_LEFT)
|
|
||||||
{
|
|
||||||
this._dy -= this.bounds.height * this.scale.y;
|
|
||||||
}
|
|
||||||
else if (this.align == GameObject.ALIGN_BOTTOM_CENTER)
|
|
||||||
{
|
|
||||||
this._dx -= this.bounds.halfWidth * this.scale.x;
|
|
||||||
this._dy -= this.bounds.height * this.scale.y;
|
|
||||||
}
|
|
||||||
else if (this.align == GameObject.ALIGN_BOTTOM_RIGHT)
|
|
||||||
{
|
|
||||||
this._dx -= this.bounds.width * this.scale.x;
|
|
||||||
this._dy -= this.bounds.height * this.scale.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this._dynamicTexture == false && this.animations.currentFrame !== null)
|
|
||||||
{
|
|
||||||
this._sx = this.animations.currentFrame.x;
|
|
||||||
this._sy = this.animations.currentFrame.y;
|
|
||||||
|
|
||||||
if (this.animations.currentFrame.trimmed)
|
|
||||||
{
|
|
||||||
this._dx += this.animations.currentFrame.spriteSourceSizeX;
|
|
||||||
this._dy += this.animations.currentFrame.spriteSourceSizeY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply camera difference
|
|
||||||
if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0)
|
|
||||||
{
|
|
||||||
this._dx -= (camera.worldView.x * this.scrollFactor.x);
|
|
||||||
this._dy -= (camera.worldView.y * this.scrollFactor.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rotation - needs to work from origin point really, but for now from center
|
|
||||||
if (this.angle !== 0 || this.rotationOffset !== 0 || this.flipped == true)
|
|
||||||
{
|
|
||||||
this._game.stage.context.save();
|
|
||||||
this._game.stage.context.translate(this._dx + (this._dw / 2), this._dy + (this._dh / 2));
|
|
||||||
|
|
||||||
if (this.renderRotation == true && (this.angle !== 0 || this.rotationOffset !== 0))
|
|
||||||
{
|
|
||||||
this._game.stage.context.rotate((this.rotationOffset + this.angle) * (Math.PI / 180));
|
|
||||||
}
|
|
||||||
|
|
||||||
this._dx = -(this._dw / 2);
|
|
||||||
this._dy = -(this._dh / 2);
|
|
||||||
|
|
||||||
if (this.flipped == true)
|
|
||||||
{
|
|
||||||
this._game.stage.context.scale(-1, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this._sx = Math.round(this._sx);
|
|
||||||
this._sy = Math.round(this._sy);
|
|
||||||
this._sw = Math.round(this._sw);
|
|
||||||
this._sh = Math.round(this._sh);
|
|
||||||
this._dx = Math.round(this._dx);
|
|
||||||
this._dy = Math.round(this._dy);
|
|
||||||
this._dw = Math.round(this._dw);
|
|
||||||
this._dh = Math.round(this._dh);
|
|
||||||
|
|
||||||
if (this._texture != null)
|
|
||||||
{
|
|
||||||
if (this._dynamicTexture)
|
|
||||||
{
|
|
||||||
this._game.stage.context.drawImage(
|
|
||||||
this._texture.canvas, // Source Image
|
|
||||||
this._sx, // Source X (location within the source image)
|
|
||||||
this._sy, // Source Y
|
|
||||||
this._sw, // Source Width
|
|
||||||
this._sh, // Source Height
|
|
||||||
this._dx, // Destination X (where on the canvas it'll be drawn)
|
|
||||||
this._dy, // Destination Y
|
|
||||||
this._dw, // Destination Width (always same as Source Width unless scaled)
|
|
||||||
this._dh // Destination Height (always same as Source Height unless scaled)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this._game.stage.context.drawImage(
|
|
||||||
this._texture, // Source Image
|
|
||||||
this._sx, // Source X (location within the source image)
|
|
||||||
this._sy, // Source Y
|
|
||||||
this._sw, // Source Width
|
|
||||||
this._sh, // Source Height
|
|
||||||
this._dx, // Destination X (where on the canvas it'll be drawn)
|
|
||||||
this._dy, // Destination Y
|
|
||||||
this._dw, // Destination Width (always same as Source Width unless scaled)
|
|
||||||
this._dh // Destination Height (always same as Source Height unless scaled)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this._game.stage.context.fillStyle = 'rgb(255,255,255)';
|
|
||||||
this._game.stage.context.fillRect(this._dx, this._dy, this._dw, this._dh);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.flipped === true || this.rotation !== 0 || this.rotationOffset !== 0)
|
|
||||||
{
|
|
||||||
//this._game.stage.context.translate(0, 0);
|
|
||||||
this._game.stage.context.restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.renderDebug)
|
|
||||||
{
|
|
||||||
this.renderBounds(camera, cameraOffsetX, cameraOffsetY);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (globalAlpha > -1)
|
|
||||||
{
|
|
||||||
this._game.stage.context.globalAlpha = globalAlpha;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Renders the bounding box around this Sprite and the contact points. Useful for visually debugging.
|
|
||||||
private renderBounds(camera:Camera, cameraOffsetX:number, cameraOffsetY:number) {
|
|
||||||
|
|
||||||
this._dx = cameraOffsetX + (this.bounds.topLeft.x - camera.worldView.x);
|
|
||||||
this._dy = cameraOffsetY + (this.bounds.topLeft.y - camera.worldView.y);
|
|
||||||
|
|
||||||
this._game.stage.context.fillStyle = this.renderDebugColor;
|
|
||||||
this._game.stage.context.fillRect(this._dx, this._dy, this._dw, this._dh);
|
|
||||||
this._game.stage.context.fillStyle = this.renderDebugPointColor;
|
|
||||||
|
|
||||||
var hw = this.bounds.halfWidth * this.scale.x;
|
|
||||||
var hh = this.bounds.halfHeight * this.scale.y;
|
|
||||||
var sw = (this.bounds.width * this.scale.x) - 1;
|
|
||||||
var sh = (this.bounds.height * this.scale.y) - 1;
|
|
||||||
|
|
||||||
this._game.stage.context.fillRect(this._dx, this._dy, 1, 1); // top left
|
|
||||||
this._game.stage.context.fillRect(this._dx + hw, this._dy, 1, 1); // top center
|
|
||||||
this._game.stage.context.fillRect(this._dx + sw, this._dy, 1, 1); // top right
|
|
||||||
this._game.stage.context.fillRect(this._dx, this._dy + hh, 1, 1); // left center
|
|
||||||
this._game.stage.context.fillRect(this._dx + hw, this._dy + hh, 1, 1); // center
|
|
||||||
this._game.stage.context.fillRect(this._dx + sw, this._dy + hh, 1, 1); // right center
|
|
||||||
this._game.stage.context.fillRect(this._dx, this._dy + sh, 1, 1); // bottom left
|
|
||||||
this._game.stage.context.fillRect(this._dx + hw, this._dy + sh, 1, 1); // bottom center
|
|
||||||
this._game.stage.context.fillRect(this._dx + sw, this._dy + sh, 1, 1); // bottom right
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
|
|
||||||
|
|
||||||
this._game.stage.context.fillStyle = color;
|
|
||||||
this._game.stage.context.fillText('Sprite: ' + this.name + ' (' + this.bounds.width + ' x ' + this.bounds.height + ')', x, y);
|
|
||||||
this._game.stage.context.fillText('x: ' + this.bounds.x.toFixed(1) + ' y: ' + this.bounds.y.toFixed(1) + ' rotation: ' + this.angle.toFixed(1), x, y + 14);
|
|
||||||
this._game.stage.context.fillText('dx: ' + this._dx.toFixed(1) + ' dy: ' + this._dy.toFixed(1) + ' dw: ' + this._dw.toFixed(1) + ' dh: ' + this._dh.toFixed(1), x, y + 28);
|
|
||||||
this._game.stage.context.fillText('sx: ' + this._sx.toFixed(1) + ' sy: ' + this._sy.toFixed(1) + ' sw: ' + this._sw.toFixed(1) + ' sh: ' + this._sh.toFixed(1), x, y + 42);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,265 +0,0 @@
|
|||||||
/// <reference path="../Game.ts" />
|
|
||||||
/// <reference path="GameObject.ts" />
|
|
||||||
/// <reference path="../system/TilemapLayer.ts" />
|
|
||||||
/// <reference path="../system/Tile.ts" />
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Phaser - Tilemap
|
|
||||||
*
|
|
||||||
* This GameObject allows for the display of a tilemap within the game world. Tile maps consist of an image, tile data and a size.
|
|
||||||
* Internally it creates a TilemapLayer for each layer in the tilemap.
|
|
||||||
*/
|
|
||||||
|
|
||||||
module Phaser {
|
|
||||||
|
|
||||||
export class Tilemap extends GameObject {
|
|
||||||
|
|
||||||
constructor(game: Game, key: string, mapData: string, format: number, resizeWorld: bool = true, tileWidth?: number = 0, tileHeight?: number = 0) {
|
|
||||||
|
|
||||||
super(game);
|
|
||||||
|
|
||||||
this.isGroup = false;
|
|
||||||
|
|
||||||
this.tiles = [];
|
|
||||||
this.layers = [];
|
|
||||||
|
|
||||||
this.mapFormat = format;
|
|
||||||
|
|
||||||
switch (format)
|
|
||||||
{
|
|
||||||
case Tilemap.FORMAT_CSV:
|
|
||||||
this.parseCSV(game.cache.getText(mapData), key, tileWidth, tileHeight);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Tilemap.FORMAT_TILED_JSON:
|
|
||||||
this.parseTiledJSON(game.cache.getText(mapData), key);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.currentLayer && resizeWorld)
|
|
||||||
{
|
|
||||||
this._game.world.setSize(this.currentLayer.widthInPixels, this.currentLayer.heightInPixels, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static FORMAT_CSV: number = 0;
|
|
||||||
public static FORMAT_TILED_JSON: number = 1;
|
|
||||||
|
|
||||||
public tiles : Tile[];
|
|
||||||
public layers : TilemapLayer[];
|
|
||||||
public currentLayer: TilemapLayer;
|
|
||||||
public collisionLayer: TilemapLayer;
|
|
||||||
public mapFormat: number;
|
|
||||||
|
|
||||||
public update() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number) {
|
|
||||||
|
|
||||||
if (this.cameraBlacklist.indexOf(camera.ID) == -1)
|
|
||||||
{
|
|
||||||
// Loop through the layers
|
|
||||||
for (var i = 0; i < this.layers.length; i++)
|
|
||||||
{
|
|
||||||
this.layers[i].render(camera, cameraOffsetX, cameraOffsetY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private parseCSV(data: string, key: string, tileWidth: number, tileHeight: number) {
|
|
||||||
|
|
||||||
var layer: TilemapLayer = new TilemapLayer(this._game, this, key, Tilemap.FORMAT_CSV, 'TileLayerCSV' + this.layers.length.toString(), tileWidth, tileHeight);
|
|
||||||
|
|
||||||
// Trim any rogue whitespace from the data
|
|
||||||
data = data.trim();
|
|
||||||
|
|
||||||
var rows = data.split("\n");
|
|
||||||
|
|
||||||
for (var i = 0; i < rows.length; i++)
|
|
||||||
{
|
|
||||||
var column = rows[i].split(",");
|
|
||||||
|
|
||||||
if (column.length > 0)
|
|
||||||
{
|
|
||||||
layer.addColumn(column);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
layer.updateBounds();
|
|
||||||
var tileQuantity = layer.parseTileOffsets();
|
|
||||||
|
|
||||||
this.currentLayer = layer;
|
|
||||||
this.collisionLayer = layer;
|
|
||||||
|
|
||||||
this.layers.push(layer);
|
|
||||||
|
|
||||||
this.generateTiles(tileQuantity);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private parseTiledJSON(data: string, key: string) {
|
|
||||||
|
|
||||||
// Trim any rogue whitespace from the data
|
|
||||||
data = data.trim();
|
|
||||||
|
|
||||||
var json = JSON.parse(data);
|
|
||||||
|
|
||||||
for (var i = 0; i < json.layers.length; i++)
|
|
||||||
{
|
|
||||||
var layer: TilemapLayer = new TilemapLayer(this._game, this, key, Tilemap.FORMAT_TILED_JSON, json.layers[i].name, json.tilewidth, json.tileheight);
|
|
||||||
|
|
||||||
layer.alpha = json.layers[i].opacity;
|
|
||||||
layer.visible = json.layers[i].visible;
|
|
||||||
layer.tileMargin = json.tilesets[0].margin;
|
|
||||||
layer.tileSpacing = json.tilesets[0].spacing;
|
|
||||||
|
|
||||||
var c = 0;
|
|
||||||
var row;
|
|
||||||
|
|
||||||
for (var t = 0; t < json.layers[i].data.length; t++)
|
|
||||||
{
|
|
||||||
if (c == 0)
|
|
||||||
{
|
|
||||||
row = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
row.push(json.layers[i].data[t]);
|
|
||||||
|
|
||||||
c++;
|
|
||||||
|
|
||||||
if (c == json.layers[i].width)
|
|
||||||
{
|
|
||||||
layer.addColumn(row);
|
|
||||||
c = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
layer.updateBounds();
|
|
||||||
|
|
||||||
var tileQuantity = layer.parseTileOffsets();
|
|
||||||
|
|
||||||
this.currentLayer = layer;
|
|
||||||
this.collisionLayer = layer;
|
|
||||||
|
|
||||||
this.layers.push(layer);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
this.generateTiles(tileQuantity);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private generateTiles(qty:number) {
|
|
||||||
|
|
||||||
for (var i = 0; i < qty; i++)
|
|
||||||
{
|
|
||||||
this.tiles.push(new Tile(this._game, this, i, this.currentLayer.tileWidth, this.currentLayer.tileHeight));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public get widthInPixels(): number {
|
|
||||||
return this.currentLayer.widthInPixels;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get heightInPixels(): number {
|
|
||||||
return this.currentLayer.heightInPixels;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tile Collision
|
|
||||||
|
|
||||||
public setCollisionRange(start: number, end: number, collision?:number = Collision.ANY, resetCollisions: bool = false) {
|
|
||||||
|
|
||||||
for (var i = start; i < end; i++)
|
|
||||||
{
|
|
||||||
this.tiles[i].setCollision(collision, resetCollisions);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public setCollisionByIndex(values:number[], collision?:number = Collision.ANY, resetCollisions: bool = false) {
|
|
||||||
|
|
||||||
for (var i = 0; i < values.length; i++)
|
|
||||||
{
|
|
||||||
this.tiles[values[i]].setCollision(collision, resetCollisions);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tile Management
|
|
||||||
|
|
||||||
public getTile(x: number, y: number, layer?: number = 0):Tile {
|
|
||||||
|
|
||||||
return this.tiles[this.layers[layer].getTileIndex(x, y)];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public getTileFromWorldXY(x: number, y: number, layer?: number = 0):Tile {
|
|
||||||
|
|
||||||
return this.tiles[this.layers[layer].getTileFromWorldXY(x, y)];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public getTileFromInputXY(layer?: number = 0):Tile {
|
|
||||||
|
|
||||||
return this.tiles[this.layers[layer].getTileFromWorldXY(this._game.input.worldX, this._game.input.worldY)];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public getTileOverlaps(object: GameObject) {
|
|
||||||
|
|
||||||
return this.currentLayer.getTileOverlaps(object);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// COLLIDE
|
|
||||||
public collide(objectOrGroup = null, callback = null): bool {
|
|
||||||
|
|
||||||
if (objectOrGroup == null)
|
|
||||||
{
|
|
||||||
objectOrGroup = this._game.world.group;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Group?
|
|
||||||
if (objectOrGroup.isGroup == false)
|
|
||||||
{
|
|
||||||
return this.collideGameObject(objectOrGroup);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
objectOrGroup.forEachAlive(this, this.collideGameObject, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public collideGameObject(object: GameObject): bool {
|
|
||||||
|
|
||||||
if (object == this) { return false; }
|
|
||||||
|
|
||||||
if (object.immovable == false && object.exists == true && object.allowCollisions != Collision.NONE)
|
|
||||||
{
|
|
||||||
return this.collisionLayer.getTileOverlaps(object);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Set current layer
|
|
||||||
// Set layer order?
|
|
||||||
// Get block of tiles
|
|
||||||
// Swap tiles around
|
|
||||||
// Delete tiles of certain type
|
|
||||||
// Erase tiles
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
/// <reference path="../Game.ts" />
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Phaser - IntersectResult
|
|
||||||
*
|
|
||||||
* A light-weight result object to hold the results of an intersection. For when you need more than just true/false.
|
|
||||||
*/
|
|
||||||
|
|
||||||
module Phaser {
|
|
||||||
|
|
||||||
export class IntersectResult {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Did they intersect or not?
|
|
||||||
* @property result
|
|
||||||
* @type Boolean
|
|
||||||
*/
|
|
||||||
result: bool = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @property x
|
|
||||||
* @type Number
|
|
||||||
*/
|
|
||||||
x: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @property y
|
|
||||||
* @type Number
|
|
||||||
*/
|
|
||||||
y: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @property x1
|
|
||||||
* @type Number
|
|
||||||
*/
|
|
||||||
x1: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @property y1
|
|
||||||
* @type Number
|
|
||||||
*/
|
|
||||||
y1: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @property x2
|
|
||||||
* @type Number
|
|
||||||
*/
|
|
||||||
x2: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @property y2
|
|
||||||
* @type Number
|
|
||||||
*/
|
|
||||||
y2: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @property width
|
|
||||||
* @type Number
|
|
||||||
*/
|
|
||||||
width: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @property height
|
|
||||||
* @type Number
|
|
||||||
*/
|
|
||||||
height: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @method setTo
|
|
||||||
* @param {Number} x1
|
|
||||||
* @param {Number} y1
|
|
||||||
* @param {Number} [x2]
|
|
||||||
* @param {Number} [y2]
|
|
||||||
* @param {Number} [width]
|
|
||||||
* @param {Number} [height]
|
|
||||||
*/
|
|
||||||
setTo(x1: number, y1: number, x2?: number = 0, y2?: number = 0, width?: number = 0, height?: number = 0) {
|
|
||||||
|
|
||||||
this.x = x1;
|
|
||||||
this.y = y1;
|
|
||||||
|
|
||||||
this.x1 = x1;
|
|
||||||
this.y1 = y1;
|
|
||||||
|
|
||||||
this.x2 = x2;
|
|
||||||
this.y2 = y2;
|
|
||||||
|
|
||||||
this.width = width;
|
|
||||||
this.height = height;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,170 +0,0 @@
|
|||||||
/// <reference path="../Game.ts" />
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Phaser - MicroPoint
|
|
||||||
*
|
|
||||||
* The MicroPoint object represents a location in a two-dimensional coordinate system,
|
|
||||||
* where x represents the horizontal axis and y represents the vertical axis.
|
|
||||||
* It is different to the Point class in that it doesn't contain any of the help methods like add/substract/distanceTo, etc.
|
|
||||||
* Use a MicroPoint when all you literally need is a solid container for x and y (such as in the Rectangle class).
|
|
||||||
*/
|
|
||||||
|
|
||||||
module Phaser {
|
|
||||||
|
|
||||||
export class MicroPoint {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new point. If you pass no parameters to this method, a point is created at (0,0).
|
|
||||||
* @class MicroPoint
|
|
||||||
* @constructor
|
|
||||||
* @param {Number} x The horizontal position of this point (default 0)
|
|
||||||
* @param {Number} y The vertical position of this point (default 0)
|
|
||||||
**/
|
|
||||||
constructor(x: number = 0, y: number = 0, parent?:any = null) {
|
|
||||||
|
|
||||||
this._x = x;
|
|
||||||
this._y = y;
|
|
||||||
this.parent = parent;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private _x: number;
|
|
||||||
private _y: number;
|
|
||||||
|
|
||||||
public parent: any;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The x coordinate of the top-left corner of the rectangle
|
|
||||||
* @property x
|
|
||||||
* @type Number
|
|
||||||
**/
|
|
||||||
public get x(): number {
|
|
||||||
|
|
||||||
return this._x;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The y coordinate of the top-left corner of the rectangle
|
|
||||||
* @property y
|
|
||||||
* @type Number
|
|
||||||
**/
|
|
||||||
public get y(): number {
|
|
||||||
|
|
||||||
return this._y;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The x coordinate of the top-left corner of the rectangle
|
|
||||||
* @property x
|
|
||||||
* @type Number
|
|
||||||
**/
|
|
||||||
public set x(value: number) {
|
|
||||||
|
|
||||||
this._x = value;
|
|
||||||
|
|
||||||
if (this.parent)
|
|
||||||
{
|
|
||||||
this.parent.updateBounds();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The y coordinate of the top-left corner of the rectangle
|
|
||||||
* @property y
|
|
||||||
* @type Number
|
|
||||||
**/
|
|
||||||
public set y(value:number) {
|
|
||||||
|
|
||||||
this._y = value;
|
|
||||||
|
|
||||||
if (this.parent)
|
|
||||||
{
|
|
||||||
this.parent.updateBounds();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copies the x and y values from any given object to this MicroPoint.
|
|
||||||
* @method copyFrom
|
|
||||||
* @param {any} source - The object to copy from.
|
|
||||||
* @return {MicroPoint} This MicroPoint object. Useful for chaining method calls.
|
|
||||||
**/
|
|
||||||
public copyFrom(source: any): MicroPoint {
|
|
||||||
|
|
||||||
return this.setTo(source.x, source.y);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copies the x and y values from this MicroPoint to any given object.
|
|
||||||
* @method copyTo
|
|
||||||
* @param {any} target - The object to copy to.
|
|
||||||
* @return {any} The target object.
|
|
||||||
**/
|
|
||||||
public copyTo(target: any): MicroPoint {
|
|
||||||
|
|
||||||
target.x = this._x;
|
|
||||||
target.y = this._y;
|
|
||||||
|
|
||||||
return target;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the x and y values of this MicroPoint object to the given coordinates.
|
|
||||||
* @method setTo
|
|
||||||
* @param {Number} x - The horizontal position of this point.
|
|
||||||
* @param {Number} y - The vertical position of this point.
|
|
||||||
* @return {MicroPoint} This MicroPoint object. Useful for chaining method calls.
|
|
||||||
**/
|
|
||||||
public setTo(x: number, y: number, callParent?:bool = true): MicroPoint {
|
|
||||||
|
|
||||||
this._x = x;
|
|
||||||
this._y = y;
|
|
||||||
|
|
||||||
if (this.parent != null && callParent == true)
|
|
||||||
{
|
|
||||||
this.parent.updateBounds();
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines whether this MicroPoint object and the given object are equal. They are equal if they have the same x and y values.
|
|
||||||
* @method equals
|
|
||||||
* @param {any} point - The object to compare against. Must have x and y properties.
|
|
||||||
* @return {Boolean} A value of true if the object is equal to this MicroPoin object; false if it is not equal.
|
|
||||||
**/
|
|
||||||
public equals(toCompare): bool {
|
|
||||||
|
|
||||||
if (this._x === toCompare.x && this._y === toCompare.y)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a string representation of this object.
|
|
||||||
* @method toString
|
|
||||||
* @return {string} a string representation of the instance.
|
|
||||||
**/
|
|
||||||
public toString(): string {
|
|
||||||
|
|
||||||
return '[{MicroPoint (x=' + this._x + ' y=' + this._y + ')}]';
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,341 +0,0 @@
|
|||||||
/// <reference path="../Game.ts" />
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Phaser - Point
|
|
||||||
*
|
|
||||||
* The Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis.
|
|
||||||
*/
|
|
||||||
|
|
||||||
module Phaser {
|
|
||||||
|
|
||||||
export class Point {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new point. If you pass no parameters to this method, a point is created at (0,0).
|
|
||||||
* @class Point
|
|
||||||
* @constructor
|
|
||||||
* @param {Number} x The horizontal position of this point (default 0)
|
|
||||||
* @param {Number} y The vertical position of this point (default 0)
|
|
||||||
**/
|
|
||||||
constructor(x: number = 0, y: number = 0) {
|
|
||||||
|
|
||||||
this.setTo(x, y);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The horizontal position of this point (default 0)
|
|
||||||
* @property x
|
|
||||||
* @type Number
|
|
||||||
**/
|
|
||||||
public x: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The vertical position of this point (default 0)
|
|
||||||
* @property y
|
|
||||||
* @type Number
|
|
||||||
**/
|
|
||||||
public y: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds the coordinates of another point to the coordinates of this point to create a new point.
|
|
||||||
* @method add
|
|
||||||
* @param {Point} point - The point to be added.
|
|
||||||
* @return {Point} The new Point object.
|
|
||||||
**/
|
|
||||||
public add(toAdd: Point, output?: Point = new Point): Point {
|
|
||||||
|
|
||||||
return output.setTo(this.x + toAdd.x, this.y + toAdd.y);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds the given values to the coordinates of this point and returns it
|
|
||||||
* @method addTo
|
|
||||||
* @param {Number} x - The amount to add to the x value of the point
|
|
||||||
* @param {Number} y - The amount to add to the x value of the point
|
|
||||||
* @return {Point} This Point object.
|
|
||||||
**/
|
|
||||||
public addTo(x?: number = 0, y?: number = 0): Point {
|
|
||||||
|
|
||||||
return this.setTo(this.x + x, this.y + y);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds the given values to the coordinates of this point and returns it
|
|
||||||
* @method addTo
|
|
||||||
* @param {Number} x - The amount to add to the x value of the point
|
|
||||||
* @param {Number} y - The amount to add to the x value of the point
|
|
||||||
* @return {Point} This Point object.
|
|
||||||
**/
|
|
||||||
public subtractFrom(x?: number = 0, y?: number = 0): Point {
|
|
||||||
|
|
||||||
return this.setTo(this.x - x, this.y - y);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Inverts the x and y values of this point
|
|
||||||
* @method invert
|
|
||||||
* @return {Point} This Point object.
|
|
||||||
**/
|
|
||||||
public invert(): Point {
|
|
||||||
|
|
||||||
return this.setTo(this.y, this.x);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clamps this Point object to be between the given min and max
|
|
||||||
* @method clamp
|
|
||||||
* @param {number} The minimum value to clamp this Point to
|
|
||||||
* @param {number} The maximum value to clamp this Point to
|
|
||||||
* @return {Point} This Point object.
|
|
||||||
**/
|
|
||||||
public clamp(min: number, max: number): Point {
|
|
||||||
|
|
||||||
this.clampX(min, max);
|
|
||||||
this.clampY(min, max);
|
|
||||||
return this;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clamps the x value of this Point object to be between the given min and max
|
|
||||||
* @method clampX
|
|
||||||
* @param {number} The minimum value to clamp this Point to
|
|
||||||
* @param {number} The maximum value to clamp this Point to
|
|
||||||
* @return {Point} This Point object.
|
|
||||||
**/
|
|
||||||
public clampX(min: number, max: number): Point {
|
|
||||||
|
|
||||||
this.x = Math.max(Math.min(this.x, max), min);
|
|
||||||
|
|
||||||
return this;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clamps the y value of this Point object to be between the given min and max
|
|
||||||
* @method clampY
|
|
||||||
* @param {number} The minimum value to clamp this Point to
|
|
||||||
* @param {number} The maximum value to clamp this Point to
|
|
||||||
* @return {Point} This Point object.
|
|
||||||
**/
|
|
||||||
public clampY(min: number, max: number): Point {
|
|
||||||
|
|
||||||
this.x = Math.max(Math.min(this.x, max), min);
|
|
||||||
this.y = Math.max(Math.min(this.y, max), min);
|
|
||||||
|
|
||||||
return this;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a copy of this Point.
|
|
||||||
* @method clone
|
|
||||||
* @param {Point} output Optional Point object. If given the values will be set into this object, otherwise a brand new Point object will be created and returned.
|
|
||||||
* @return {Point} The new Point object.
|
|
||||||
**/
|
|
||||||
public clone(output?: Point = new Point): Point {
|
|
||||||
|
|
||||||
return output.setTo(this.x, this.y);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copies the point data from the source Point object into this Point object.
|
|
||||||
* @method copyFrom
|
|
||||||
* @param {Point} source - The point to copy from.
|
|
||||||
* @return {Point} This Point object. Useful for chaining method calls.
|
|
||||||
**/
|
|
||||||
public copyFrom(source: Point): Point {
|
|
||||||
|
|
||||||
return this.setTo(source.x, source.y);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copies the point data from this Point object to the given target Point object.
|
|
||||||
* @method copyTo
|
|
||||||
* @param {Point} target - The point to copy to.
|
|
||||||
* @return {Point} The target Point object.
|
|
||||||
**/
|
|
||||||
public copyTo(target: Point): Point {
|
|
||||||
|
|
||||||
return target.setTo(this.x, this.y);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the distance from this Point object to the given Point object.
|
|
||||||
* @method distanceFrom
|
|
||||||
* @param {Point} target - The destination Point object.
|
|
||||||
* @param {Boolean} round - Round the distance to the nearest integer (default false)
|
|
||||||
* @return {Number} The distance between this Point object and the destination Point object.
|
|
||||||
**/
|
|
||||||
public distanceTo(target: Point, round?: bool = false): number {
|
|
||||||
|
|
||||||
var dx = this.x - target.x;
|
|
||||||
var dy = this.y - target.y;
|
|
||||||
|
|
||||||
if (round === true)
|
|
||||||
{
|
|
||||||
return Math.round(Math.sqrt(dx * dx + dy * dy));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return Math.sqrt(dx * dx + dy * dy);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the distance between the two Point objects.
|
|
||||||
* @method distanceBetween
|
|
||||||
* @param {Point} pointA - The first Point object.
|
|
||||||
* @param {Point} pointB - The second Point object.
|
|
||||||
* @param {Boolean} round - Round the distance to the nearest integer (default false)
|
|
||||||
* @return {Number} The distance between the two Point objects.
|
|
||||||
**/
|
|
||||||
public static distanceBetween(pointA: Point, pointB: Point, round?: bool = false): number {
|
|
||||||
|
|
||||||
var dx: number = pointA.x - pointB.x;
|
|
||||||
var dy: number = pointA.y - pointB.y;
|
|
||||||
|
|
||||||
if (round === true)
|
|
||||||
{
|
|
||||||
return Math.round(Math.sqrt(dx * dx + dy * dy));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return Math.sqrt(dx * dx + dy * dy);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the distance between this point and a target point is greater than or equal a specified distance.
|
|
||||||
* This avoids using a costly square root operation
|
|
||||||
* @method distanceCompare
|
|
||||||
* @param {Point} target - The Point object to use for comparison.
|
|
||||||
* @param {Number} distance - The distance to use for comparison.
|
|
||||||
* @return {Boolena} True if distance is >= specified distance.
|
|
||||||
**/
|
|
||||||
public distanceCompare(target: Point, distance: number): bool {
|
|
||||||
|
|
||||||
if (this.distanceTo(target) >= distance)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines whether this Point object and the given point object are equal. They are equal if they have the same x and y values.
|
|
||||||
* @method equals
|
|
||||||
* @param {Point} point - The point to compare against.
|
|
||||||
* @return {Boolean} A value of true if the object is equal to this Point object; false if it is not equal.
|
|
||||||
**/
|
|
||||||
public equals(toCompare: Point): bool {
|
|
||||||
|
|
||||||
if (this.x === toCompare.x && this.y === toCompare.y)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines a point between two specified points. The parameter f determines where the new interpolated point is located relative to the two end points specified by parameters pt1 and pt2.
|
|
||||||
* The closer the value of the parameter f is to 1.0, the closer the interpolated point is to the first point (parameter pt1). The closer the value of the parameter f is to 0, the closer the interpolated point is to the second point (parameter pt2).
|
|
||||||
* @method interpolate
|
|
||||||
* @param {Point} pointA - The first Point object.
|
|
||||||
* @param {Point} pointB - The second Point object.
|
|
||||||
* @param {Number} f - The level of interpolation between the two points. Indicates where the new point will be, along the line between pt1 and pt2. If f=1, pt1 is returned; if f=0, pt2 is returned.
|
|
||||||
* @return {Point} The new interpolated Point object.
|
|
||||||
**/
|
|
||||||
public interpolate(pointA, pointB, f) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Offsets the Point object by the specified amount. The value of dx is added to the original value of x to create the new x value.
|
|
||||||
* The value of dy is added to the original value of y to create the new y value.
|
|
||||||
* @method offset
|
|
||||||
* @param {Number} dx - The amount by which to offset the horizontal coordinate, x.
|
|
||||||
* @param {Number} dy - The amount by which to offset the vertical coordinate, y.
|
|
||||||
* @return {Point} This Point object. Useful for chaining method calls.
|
|
||||||
**/
|
|
||||||
public offset(dx: number, dy: number): Point {
|
|
||||||
|
|
||||||
this.x += dx;
|
|
||||||
this.y += dy;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a pair of polar coordinates to a Cartesian point coordinate.
|
|
||||||
* @method polar
|
|
||||||
* @param {Number} length - The length coordinate of the polar pair.
|
|
||||||
* @param {Number} angle - The angle, in radians, of the polar pair.
|
|
||||||
* @return {Point} The new Cartesian Point object.
|
|
||||||
**/
|
|
||||||
public polar(length, angle) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the x and y values of this Point object to the given coordinates.
|
|
||||||
* @method setTo
|
|
||||||
* @param {Number} x - The horizontal position of this point.
|
|
||||||
* @param {Number} y - The vertical position of this point.
|
|
||||||
* @return {Point} This Point object. Useful for chaining method calls.
|
|
||||||
**/
|
|
||||||
public setTo(x: number, y: number): Point {
|
|
||||||
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Subtracts the coordinates of another point from the coordinates of this point to create a new point.
|
|
||||||
* @method subtract
|
|
||||||
* @param {Point} point - The point to be subtracted.
|
|
||||||
* @param {Point} output Optional Point object. If given the values will be set into this object, otherwise a brand new Point object will be created and returned.
|
|
||||||
* @return {Point} The new Point object.
|
|
||||||
**/
|
|
||||||
public subtract(point: Point, output?: Point = new Point): Point {
|
|
||||||
|
|
||||||
return output.setTo(this.x - point.x, this.y - point.y);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a string representation of this object.
|
|
||||||
* @method toString
|
|
||||||
* @return {string} a string representation of the instance.
|
|
||||||
**/
|
|
||||||
public toString(): string {
|
|
||||||
|
|
||||||
return '[{Point (x=' + this.x + ' y=' + this.y + ')}]';
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,106 +0,0 @@
|
|||||||
/// <reference path="../Game.ts" />
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Phaser - Quad
|
|
||||||
*
|
|
||||||
* A Quad object is an area defined by its position, as indicated by its top-left corner (x,y) and width and height.
|
|
||||||
* Very much like a Rectangle only without all of the additional methods and properties of that class.
|
|
||||||
*/
|
|
||||||
|
|
||||||
module Phaser {
|
|
||||||
|
|
||||||
export class Quad {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new Quad object with the top-left corner specified by the x and y parameters and with the specified width and height parameters. If you call this function without parameters, a rectangle with x, y, width, and height properties set to 0 is created.
|
|
||||||
* @class Quad
|
|
||||||
* @constructor
|
|
||||||
* @param {Number} x The x coordinate of the top-left corner of the quad.
|
|
||||||
* @param {Number} y The y coordinate of the top-left corner of the quad.
|
|
||||||
* @param {Number} width The width of the quad.
|
|
||||||
* @param {Number} height The height of the quad.
|
|
||||||
* @return {Quad } This object
|
|
||||||
**/
|
|
||||||
constructor(x: number = 0, y: number = 0, width: number = 0, height: number = 0) {
|
|
||||||
|
|
||||||
this.setTo(x, y, width, height);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public x: number;
|
|
||||||
public y: number;
|
|
||||||
public width: number;
|
|
||||||
public height: number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the Quad to the specified size.
|
|
||||||
* @method setTo
|
|
||||||
* @param {Number} x The x coordinate of the top-left corner of the quad.
|
|
||||||
* @param {Number} y The y coordinate of the top-left corner of the quad.
|
|
||||||
* @param {Number} width The width of the quad.
|
|
||||||
* @param {Number} height The height of the quad.
|
|
||||||
* @return {Quad} This object
|
|
||||||
**/
|
|
||||||
public setTo(x: number, y: number, width: number, height: number): Quad {
|
|
||||||
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
this.width = width;
|
|
||||||
this.height = height;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public get left(): number {
|
|
||||||
return this.x;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get right(): number {
|
|
||||||
return this.x + this.width;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get top(): number {
|
|
||||||
return this.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get bottom(): number {
|
|
||||||
return this.y + this.height;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get halfWidth(): number {
|
|
||||||
return this.width / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get halfHeight(): number {
|
|
||||||
return this.height / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines whether the object specified intersects (overlaps) with this Quad object.
|
|
||||||
* This method checks the x, y, width, and height properties of the specified Quad object to see if it intersects with this Quad object.
|
|
||||||
* @method intersects
|
|
||||||
* @param {Object} q The object to check for intersection with this Quad. Must have left/right/top/bottom properties (Rectangle, Quad).
|
|
||||||
* @param {Number} t A tolerance value to allow for an intersection test with padding, default to 0
|
|
||||||
* @return {Boolean} A value of true if the specified object intersects with this Quad; otherwise false.
|
|
||||||
**/
|
|
||||||
public intersects(q, t?: number = 0): bool {
|
|
||||||
|
|
||||||
return !(q.left > this.right + t || q.right < this.left - t || q.top > this.bottom + t || q.bottom < this.top - t);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a string representation of this object.
|
|
||||||
* @method toString
|
|
||||||
* @return {string} a string representation of the object.
|
|
||||||
**/
|
|
||||||
public toString(): string {
|
|
||||||
|
|
||||||
return "[{Quad (x=" + this.x + " y=" + this.y + " width=" + this.width + " height=" + this.height + ")}]";
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,810 +0,0 @@
|
|||||||
/// <reference path="../Game.ts" />
|
|
||||||
/// <reference path="MicroPoint.ts" />
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Phaser - Rectangle
|
|
||||||
*
|
|
||||||
* A Rectangle object is an area defined by its position, as indicated by its top-left corner (x,y) and width and height.
|
|
||||||
*/
|
|
||||||
|
|
||||||
module Phaser {
|
|
||||||
|
|
||||||
export class Rectangle {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new Rectangle object with the top-left corner specified by the x and y parameters and with the specified width and height parameters.
|
|
||||||
* If you call this function without parameters, a rectangle with x, y, width, and height properties set to 0 is created.
|
|
||||||
* @class Rectangle
|
|
||||||
* @constructor
|
|
||||||
* @param {Number} x The x coordinate of the top-left corner of the rectangle.
|
|
||||||
* @param {Number} y The y coordinate of the top-left corner of the rectangle.
|
|
||||||
* @param {Number} width The width of the rectangle.
|
|
||||||
* @param {Number} height The height of the rectangle.
|
|
||||||
* @return {Rectangle} This rectangle object
|
|
||||||
**/
|
|
||||||
constructor(x: number = 0, y: number = 0, width: number = 0, height: number = 0) {
|
|
||||||
|
|
||||||
this._width = width;
|
|
||||||
|
|
||||||
if (width > 0)
|
|
||||||
{
|
|
||||||
this._halfWidth = Math.round(width / 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
this._height = height;
|
|
||||||
|
|
||||||
if (height > 0)
|
|
||||||
{
|
|
||||||
this._halfHeight = Math.round(height / 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.length = Math.max(this._width, this._height);
|
|
||||||
|
|
||||||
this.topLeft = new MicroPoint(x, y, this);
|
|
||||||
this.topCenter = new MicroPoint(x + this._halfWidth, y, this);
|
|
||||||
this.topRight = new MicroPoint(x + this._width - 1, y, this);
|
|
||||||
this.leftCenter = new MicroPoint(x, y + this._halfHeight, this);
|
|
||||||
this.center = new MicroPoint(x + this._halfWidth, y + this._halfHeight, this);
|
|
||||||
this.rightCenter = new MicroPoint(x + this._width - 1, y + this._halfHeight, this);
|
|
||||||
this.bottomLeft = new MicroPoint(x, y + this._height - 1, this);
|
|
||||||
this.bottomCenter = new MicroPoint(x + this._halfWidth, y + this._height - 1, this);
|
|
||||||
this.bottomRight = new MicroPoint(x + this._width - 1, y + this._height - 1, this);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private _tempX: number = null;
|
|
||||||
private _tempY: number = null;
|
|
||||||
private _tempWidth: number = null;
|
|
||||||
private _tempHeight: number = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The x coordinate of the top-left corner of the rectangle
|
|
||||||
* @property x
|
|
||||||
* @type Number
|
|
||||||
**/
|
|
||||||
public get x(): number {
|
|
||||||
|
|
||||||
return this.topLeft.x;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The y coordinate of the top-left corner of the rectangle
|
|
||||||
* @property y
|
|
||||||
* @type Number
|
|
||||||
**/
|
|
||||||
public get y(): number {
|
|
||||||
|
|
||||||
return this.topLeft.y;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The x coordinate of the top-left corner of the rectangle
|
|
||||||
* @property x
|
|
||||||
* @type Number
|
|
||||||
**/
|
|
||||||
public set x(value: number) {
|
|
||||||
|
|
||||||
this.topLeft.x = value;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The y coordinate of the top-left corner of the rectangle
|
|
||||||
* @property y
|
|
||||||
* @type Number
|
|
||||||
**/
|
|
||||||
public set y(value:number) {
|
|
||||||
|
|
||||||
this.topLeft.y = value;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The x and y coordinate of the top-left corner of the rectangle (same as x/y)
|
|
||||||
* @property topLeft
|
|
||||||
* @type MicroPoint
|
|
||||||
**/
|
|
||||||
public topLeft: MicroPoint;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The x and y coordinate of the top-center of the rectangle
|
|
||||||
* @property topCenter
|
|
||||||
* @type MicroPoint
|
|
||||||
**/
|
|
||||||
public topCenter: MicroPoint;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The x and y coordinate of the top-right corner of the rectangle
|
|
||||||
* @property topRight
|
|
||||||
* @type MicroPoint
|
|
||||||
**/
|
|
||||||
public topRight: MicroPoint;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The x and y coordinate of the left-center of the rectangle
|
|
||||||
* @property leftCenter
|
|
||||||
* @type MicroPoint
|
|
||||||
**/
|
|
||||||
public leftCenter: MicroPoint;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The x and y coordinate of the center of the rectangle
|
|
||||||
* @property center
|
|
||||||
* @type MicroPoint
|
|
||||||
**/
|
|
||||||
public center: MicroPoint;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The x and y coordinate of the right-center of the rectangle
|
|
||||||
* @property rightCenter
|
|
||||||
* @type MicroPoint
|
|
||||||
**/
|
|
||||||
public rightCenter: MicroPoint;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The x and y coordinate of the bottom-left corner of the rectangle
|
|
||||||
* @property bottomLeft
|
|
||||||
* @type MicroPoint
|
|
||||||
**/
|
|
||||||
public bottomLeft: MicroPoint;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The x and y coordinate of the bottom-center of the rectangle
|
|
||||||
* @property bottomCenter
|
|
||||||
* @type MicroPoint
|
|
||||||
**/
|
|
||||||
public bottomCenter: MicroPoint;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The x and y coordinate of the bottom-right corner of the rectangle
|
|
||||||
* @property bottomRight
|
|
||||||
* @type MicroPoint
|
|
||||||
**/
|
|
||||||
public bottomRight: MicroPoint;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The width of the rectangle
|
|
||||||
* @property width
|
|
||||||
* @type Number
|
|
||||||
**/
|
|
||||||
private _width: number = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The height of the rectangle
|
|
||||||
* @property height
|
|
||||||
* @type Number
|
|
||||||
**/
|
|
||||||
private _height: number = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Half of the width of the rectangle
|
|
||||||
* @property halfWidth
|
|
||||||
* @type Number
|
|
||||||
**/
|
|
||||||
private _halfWidth: number = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Half of the height of the rectangle
|
|
||||||
* @property halfHeight
|
|
||||||
* @type Number
|
|
||||||
**/
|
|
||||||
private _halfHeight: number = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The size of the longest side (width or height)
|
|
||||||
* @property length
|
|
||||||
* @type Number
|
|
||||||
**/
|
|
||||||
public length: number = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates all of the MicroPoints based on the values of width and height.
|
|
||||||
* You should not normally call this directly.
|
|
||||||
**/
|
|
||||||
public updateBounds() {
|
|
||||||
|
|
||||||
if (this._tempWidth !== null)
|
|
||||||
{
|
|
||||||
this._width = this._tempWidth;
|
|
||||||
this._halfWidth = 0;
|
|
||||||
|
|
||||||
if (this._width > 0)
|
|
||||||
{
|
|
||||||
this._halfWidth = Math.round(this._width / 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this._tempHeight !== null)
|
|
||||||
{
|
|
||||||
this._height = this._tempHeight;
|
|
||||||
this._halfHeight = 0;
|
|
||||||
|
|
||||||
if (this._height > 0)
|
|
||||||
{
|
|
||||||
this._halfHeight = Math.round(this._height / 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.length = Math.max(this._width, this._height);
|
|
||||||
|
|
||||||
if (this._tempX !== null && this._tempY !== null)
|
|
||||||
{
|
|
||||||
this.topLeft.setTo(this._tempX, this._tempY, false);
|
|
||||||
}
|
|
||||||
else if (this._tempX !== null && this._tempY == null)
|
|
||||||
{
|
|
||||||
this.topLeft.setTo(this._tempX, this.topLeft.y, false);
|
|
||||||
}
|
|
||||||
else if (this._tempX == null && this._tempY !== null)
|
|
||||||
{
|
|
||||||
this.topLeft.setTo(this.topLeft.x, this._tempY, false);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.topLeft.setTo(this.x, this.y, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.topCenter.setTo(this.x + this._halfWidth, this.y, false);
|
|
||||||
this.topRight.setTo(this.x + this._width - 1, this.y, false);
|
|
||||||
|
|
||||||
this.leftCenter.setTo(this.x, this.y + this._halfHeight, false);
|
|
||||||
this.center.setTo(this.x + this._halfWidth, this.y + this._halfHeight, false);
|
|
||||||
this.rightCenter.setTo(this.x + this._width - 1, this.y + this._halfHeight, false);
|
|
||||||
|
|
||||||
this.bottomLeft.setTo(this.x, this.y + this._height - 1, false);
|
|
||||||
this.bottomCenter.setTo(this.x + this._halfWidth, this.y + this._height - 1, false);
|
|
||||||
this.bottomRight.setTo(this.x + this._width - 1, this.y + this._height - 1, false);
|
|
||||||
|
|
||||||
this._tempX = null;
|
|
||||||
this._tempY = null;
|
|
||||||
this._tempWidth = null;
|
|
||||||
this._tempHeight = null;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The width of the rectangle
|
|
||||||
* @property width
|
|
||||||
* @type Number
|
|
||||||
**/
|
|
||||||
public set width(value: number) {
|
|
||||||
|
|
||||||
this._width = value;
|
|
||||||
this._halfWidth = Math.round(value / 2);
|
|
||||||
this.updateBounds();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The height of the rectangle
|
|
||||||
* @property height
|
|
||||||
* @type Number
|
|
||||||
**/
|
|
||||||
public set height(value: number) {
|
|
||||||
|
|
||||||
this._height = value;
|
|
||||||
this._halfHeight = Math.round(value / 2);
|
|
||||||
this.updateBounds();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The width of the rectangle
|
|
||||||
* @property width
|
|
||||||
* @type Number
|
|
||||||
**/
|
|
||||||
public get width(): number {
|
|
||||||
|
|
||||||
return this._width;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The height of the rectangle
|
|
||||||
* @property height
|
|
||||||
* @type Number
|
|
||||||
**/
|
|
||||||
public get height(): number {
|
|
||||||
|
|
||||||
return this._height;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Half of the width of the rectangle
|
|
||||||
* @property halfWidth
|
|
||||||
* @type Number
|
|
||||||
**/
|
|
||||||
public get halfWidth(): number {
|
|
||||||
|
|
||||||
return this._halfWidth;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Half of the height of the rectangle
|
|
||||||
* @property halfHeight
|
|
||||||
* @type Number
|
|
||||||
**/
|
|
||||||
public get halfHeight(): number {
|
|
||||||
|
|
||||||
return this._halfHeight;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The sum of the y and height properties.
|
|
||||||
* Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
|
|
||||||
* @method bottom
|
|
||||||
* @return {Number}
|
|
||||||
**/
|
|
||||||
public get bottom(): number {
|
|
||||||
|
|
||||||
return this.bottomCenter.y;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The sum of the y and height properties.
|
|
||||||
* Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
|
|
||||||
* @method bottom
|
|
||||||
* @param {Number} value
|
|
||||||
**/
|
|
||||||
public set bottom(value: number) {
|
|
||||||
|
|
||||||
if (value < this.y)
|
|
||||||
{
|
|
||||||
this._tempHeight = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this._tempHeight = this.y + value;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.updateBounds();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The x coordinate of the top-left corner of the rectangle.
|
|
||||||
* Changing the left property of a Rectangle object has no effect on the y and height properties.
|
|
||||||
* However it does affect the width property, whereas changing the x value does not affect the width property.
|
|
||||||
* @method left
|
|
||||||
* @ return {number}
|
|
||||||
**/
|
|
||||||
public get left(): number {
|
|
||||||
|
|
||||||
return this.x;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The x coordinate of the top-left corner of the rectangle.
|
|
||||||
* Changing the left property of a Rectangle object has no effect on the y and height properties.
|
|
||||||
* However it does affect the width property, whereas changing the x value does not affect the width property.
|
|
||||||
* @method left
|
|
||||||
* @param {Number} value
|
|
||||||
**/
|
|
||||||
public set left(value: number) {
|
|
||||||
|
|
||||||
var diff = this.x - value;
|
|
||||||
|
|
||||||
if (this._width + diff < 0)
|
|
||||||
{
|
|
||||||
this._tempWidth = 0;
|
|
||||||
this._tempX = value;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this._tempWidth = this._width + diff;
|
|
||||||
this._tempX = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.updateBounds();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The sum of the x and width properties.
|
|
||||||
* Changing the right property of a Rectangle object has no effect on the x, y and height properties.
|
|
||||||
* However it does affect the width property.
|
|
||||||
* @method right
|
|
||||||
* @return {Number}
|
|
||||||
**/
|
|
||||||
public get right(): number {
|
|
||||||
|
|
||||||
return this.rightCenter.x;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The sum of the x and width properties.
|
|
||||||
* Changing the right property of a Rectangle object has no effect on the x, y and height properties.
|
|
||||||
* However it does affect the width property.
|
|
||||||
* @method right
|
|
||||||
* @param {Number} value
|
|
||||||
**/
|
|
||||||
public set right(value: number) {
|
|
||||||
|
|
||||||
if (value < this.topLeft.x)
|
|
||||||
{
|
|
||||||
this._tempWidth = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this._tempWidth = (value - this.topLeft.x);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.updateBounds();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The size of the Rectangle object, expressed as a Point object with the values of the width and height properties.
|
|
||||||
* @method size
|
|
||||||
* @param {Point} output Optional Point object. If given the values will be set into the object, otherwise a brand new Point object will be created and returned.
|
|
||||||
* @return {Point} The size of the Rectangle object
|
|
||||||
**/
|
|
||||||
public size(output?: Point = new Point): Point {
|
|
||||||
|
|
||||||
return output.setTo(this._width, this._height);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The volume of the Rectangle object in pixels, derived from width * height
|
|
||||||
* @method volume
|
|
||||||
* @return {Number}
|
|
||||||
**/
|
|
||||||
public get volume(): number {
|
|
||||||
|
|
||||||
return this._width * this._height;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The perimeter size of the Rectangle object in pixels. This is the sum of all 4 sides.
|
|
||||||
* @method perimeter
|
|
||||||
* @return {Number}
|
|
||||||
**/
|
|
||||||
public get perimeter(): number {
|
|
||||||
|
|
||||||
return (this._width * 2) + (this._height * 2);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The y coordinate of the top-left corner of the rectangle.
|
|
||||||
* Changing the top property of a Rectangle object has no effect on the x and width properties.
|
|
||||||
* However it does affect the height property, whereas changing the y value does not affect the height property.
|
|
||||||
* @method top
|
|
||||||
* @return {Number}
|
|
||||||
**/
|
|
||||||
public get top(): number {
|
|
||||||
|
|
||||||
return this.topCenter.y;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The y coordinate of the top-left corner of the rectangle.
|
|
||||||
* Changing the top property of a Rectangle object has no effect on the x and width properties.
|
|
||||||
* However it does affect the height property, whereas changing the y value does not affect the height property.
|
|
||||||
* @method top
|
|
||||||
* @param {Number} value
|
|
||||||
**/
|
|
||||||
public set top(value: number) {
|
|
||||||
|
|
||||||
var diff = this.topCenter.y - value;
|
|
||||||
|
|
||||||
if (this._height + diff < 0)
|
|
||||||
{
|
|
||||||
this._tempHeight = 0;
|
|
||||||
this._tempY = value;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this._tempHeight = this._height + diff;
|
|
||||||
this._tempY = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.updateBounds();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a new Rectangle object with the same values for the x, y, width, and height properties as the original Rectangle object.
|
|
||||||
* @method clone
|
|
||||||
* @param {Rectangle} output Optional Rectangle object. If given the values will be set into the object, otherwise a brand new Rectangle object will be created and returned.
|
|
||||||
* @return {Rectangle}
|
|
||||||
**/
|
|
||||||
public clone(output?: Rectangle = new Rectangle): Rectangle {
|
|
||||||
|
|
||||||
return output.setTo(this.x, this.y, this.width, this.height);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines whether the specified coordinates are contained within the region defined by this Rectangle object.
|
|
||||||
* @method contains
|
|
||||||
* @param {Number} x The x coordinate of the point to test.
|
|
||||||
* @param {Number} y The y coordinate of the point to test.
|
|
||||||
* @return {Boolean} A value of true if the Rectangle object contains the specified point; otherwise false.
|
|
||||||
**/
|
|
||||||
public contains(x: number, y: number): bool {
|
|
||||||
|
|
||||||
if (x >= this.topLeft.x && x <= this.topRight.x && y >= this.topLeft.y && y <= this.bottomRight.y)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines whether the specified point is contained within the rectangular region defined by this Rectangle object.
|
|
||||||
* This method is similar to the Rectangle.contains() method, except that it takes a Point object as a parameter.
|
|
||||||
* @method containsPoint
|
|
||||||
* @param {Point} point The point object being checked. Can be Point or any object with .x and .y values.
|
|
||||||
* @return {Boolean} A value of true if the Rectangle object contains the specified point; otherwise false.
|
|
||||||
**/
|
|
||||||
public containsPoint(point: any): bool {
|
|
||||||
|
|
||||||
return this.contains(point.x, point.y);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines whether the Rectangle object specified by the rect parameter is contained within this Rectangle object.
|
|
||||||
* A Rectangle object is said to contain another if the second Rectangle object falls entirely within the boundaries of the first.
|
|
||||||
* @method containsRect
|
|
||||||
* @param {Rectangle} rect The rectangle object being checked.
|
|
||||||
* @return {Boolean} A value of true if the Rectangle object contains the specified point; otherwise false.
|
|
||||||
**/
|
|
||||||
public containsRect(rect: Rectangle): bool {
|
|
||||||
|
|
||||||
// If the given rect has a larger volume than this one then it can never contain it
|
|
||||||
if (rect.volume > this.volume)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rect.x >= this.topLeft.x && rect.y >= this.topLeft.y && rect.rightCenter.x <= this.rightCenter.x && rect.bottomCenter.y <= this.bottomCenter.y)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copies all of rectangle data from the source Rectangle object into the calling Rectangle object.
|
|
||||||
* @method copyFrom
|
|
||||||
* @param {Rectangle} rect The source rectangle object to copy from
|
|
||||||
* @return {Rectangle} This rectangle object
|
|
||||||
**/
|
|
||||||
public copyFrom(source: Rectangle): Rectangle {
|
|
||||||
|
|
||||||
return this.setTo(source.x, source.y, source.width, source.height);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copies all the rectangle data from this Rectangle object into the destination Rectangle object.
|
|
||||||
* @method copyTo
|
|
||||||
* @param {Rectangle} rect The destination rectangle object to copy in to
|
|
||||||
* @return {Rectangle} The destination rectangle object
|
|
||||||
**/
|
|
||||||
public copyTo(target: Rectangle): Rectangle {
|
|
||||||
|
|
||||||
return target.copyFrom(this);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines whether the object specified in the toCompare parameter is equal to this Rectangle object.
|
|
||||||
* This method compares the x, y, width, and height properties of an object against the same properties of this Rectangle object.
|
|
||||||
* @method equals
|
|
||||||
* @param {Rectangle} toCompare The rectangle to compare to this Rectangle object.
|
|
||||||
* @return {Boolean} A value of true if the object has exactly the same values for the x, y, width, and height properties as this Rectangle object; otherwise false.
|
|
||||||
**/
|
|
||||||
public equals(toCompare: Rectangle): bool {
|
|
||||||
|
|
||||||
if (this.topLeft.equals(toCompare.topLeft) && this.bottomRight.equals(toCompare.bottomRight))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Increases the size of the Rectangle object by the specified amounts.
|
|
||||||
* The center point of the Rectangle object stays the same, and its size increases to the left and right by the dx value,
|
|
||||||
* and to the top and the bottom by the dy value.
|
|
||||||
* @method inflate
|
|
||||||
* @param {Number} dx The amount to be added to the left side of this Rectangle.
|
|
||||||
* @param {Number} dy The amount to be added to the bottom side of this Rectangle.
|
|
||||||
* @return {Rectangle} This Rectangle object.
|
|
||||||
**/
|
|
||||||
public inflate(dx: number, dy: number): Rectangle {
|
|
||||||
|
|
||||||
this._tempX = this.topLeft.x - dx;
|
|
||||||
this._tempWidth = this._width + (2 * dx);
|
|
||||||
this._tempY = this.topLeft.y - dy;
|
|
||||||
this._tempHeight = this._height + (2 * dy);
|
|
||||||
|
|
||||||
this.updateBounds();
|
|
||||||
|
|
||||||
return this;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Increases the size of the Rectangle object.
|
|
||||||
* This method is similar to the Rectangle.inflate() method except it takes a Point object as a parameter.
|
|
||||||
* @method inflatePoint
|
|
||||||
* @param {Point} point The x property of this Point object is used to increase the horizontal dimension of the Rectangle object. The y property is used to increase the vertical dimension of the Rectangle object.
|
|
||||||
* @return {Rectangle} This Rectangle object.
|
|
||||||
**/
|
|
||||||
public inflatePoint(point: Point): Rectangle {
|
|
||||||
|
|
||||||
return this.inflate(point.x, point.y);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If the Rectangle object specified in the toIntersect parameter intersects with this Rectangle object,
|
|
||||||
* returns the area of intersection as a Rectangle object. If the rectangles do not intersect, this method
|
|
||||||
* returns an empty Rectangle object with its properties set to 0.
|
|
||||||
* @method intersection
|
|
||||||
* @param {Rectangle} toIntersect The Rectangle object to compare against to see if it intersects with this Rectangle object.
|
|
||||||
* @param {Rectangle} output Optional Rectangle object. If given the intersection values will be set into this object, otherwise a brand new Rectangle object will be created and returned.
|
|
||||||
* @return {Rectangle} A Rectangle object that equals the area of intersection. If the rectangles do not intersect, this method returns an empty Rectangle object; that is, a rectangle with its x, y, width, and height properties set to 0.
|
|
||||||
**/
|
|
||||||
public intersection(toIntersect: Rectangle, output?: Rectangle = new Rectangle): Rectangle {
|
|
||||||
|
|
||||||
if (this.intersects(toIntersect) === true)
|
|
||||||
{
|
|
||||||
output.x = Math.max(toIntersect.topLeft.x, this.topLeft.x);
|
|
||||||
output.y = Math.max(toIntersect.topLeft.y, this.topLeft.y);
|
|
||||||
output.width = Math.min(toIntersect.rightCenter.x, this.rightCenter.x) - output.x;
|
|
||||||
output.height = Math.min(toIntersect.bottomCenter.y, this.bottomCenter.y) - output.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
return output;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines whether the object specified intersects (overlaps) with this Rectangle object.
|
|
||||||
* This method checks the x, y, width, and height properties of the specified Rectangle object to see if it intersects with this Rectangle object.
|
|
||||||
* @method intersects
|
|
||||||
* @param {Rectangle} r2 The Rectangle object to compare against to see if it intersects with this Rectangle object.
|
|
||||||
* @param {Number} t A tolerance value to allow for an intersection test with padding, default to 0
|
|
||||||
* @return {Boolean} A value of true if the specified object intersects with this Rectangle object; otherwise false.
|
|
||||||
**/
|
|
||||||
public intersects(r2: Rectangle, t?: number = 0): bool {
|
|
||||||
|
|
||||||
return !(r2.left > this.right + t || r2.right < this.left - t || r2.top > this.bottom + t || r2.bottom < this.top - t);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines whether or not this Rectangle object is empty.
|
|
||||||
* @method isEmpty
|
|
||||||
* @return {Boolean} A value of true if the Rectangle object's width or height is less than or equal to 0; otherwise false.
|
|
||||||
**/
|
|
||||||
public get isEmpty(): bool {
|
|
||||||
|
|
||||||
if (this.width < 1 || this.height < 1)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adjusts the location of the Rectangle object, as determined by its top-left corner, by the specified amounts.
|
|
||||||
* @method offset
|
|
||||||
* @param {Number} dx Moves the x value of the Rectangle object by this amount.
|
|
||||||
* @param {Number} dy Moves the y value of the Rectangle object by this amount.
|
|
||||||
* @return {Rectangle} This Rectangle object.
|
|
||||||
**/
|
|
||||||
public offset(dx: number, dy: number): Rectangle {
|
|
||||||
|
|
||||||
if (!isNaN(dx) && !isNaN(dy))
|
|
||||||
{
|
|
||||||
this.x += dx;
|
|
||||||
this.y += dy;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adjusts the location of the Rectangle object using a Point object as a parameter. This method is similar to the Rectangle.offset() method, except that it takes a Point object as a parameter.
|
|
||||||
* @method offsetPoint
|
|
||||||
* @param {Point} point A Point object to use to offset this Rectangle object.
|
|
||||||
* @return {Rectangle} This Rectangle object.
|
|
||||||
**/
|
|
||||||
public offsetPoint(point: Point): Rectangle {
|
|
||||||
|
|
||||||
return this.offset(point.x, point.y);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets all of the Rectangle object's properties to 0. A Rectangle object is empty if its width or height is less than or equal to 0.
|
|
||||||
* @method setEmpty
|
|
||||||
* @return {Rectangle} This rectangle object
|
|
||||||
**/
|
|
||||||
public setEmpty() {
|
|
||||||
|
|
||||||
return this.setTo(0, 0, 0, 0);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the members of Rectangle to the specified values.
|
|
||||||
* @method setTo
|
|
||||||
* @param {Number} x The x coordinate of the top-left corner of the rectangle.
|
|
||||||
* @param {Number} y The y coordinate of the top-left corner of the rectangle.
|
|
||||||
* @param {Number} width The width of the rectangle in pixels.
|
|
||||||
* @param {Number} height The height of the rectangle in pixels.
|
|
||||||
* @return {Rectangle} This rectangle object
|
|
||||||
**/
|
|
||||||
public setTo(x: number, y: number, width: number, height: number): Rectangle {
|
|
||||||
|
|
||||||
this._tempX = x;
|
|
||||||
this._tempY = y;
|
|
||||||
this._tempWidth = width;
|
|
||||||
this._tempHeight = height;
|
|
||||||
|
|
||||||
this.updateBounds();
|
|
||||||
|
|
||||||
return this;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds two rectangles together to create a new Rectangle object, by filling in the horizontal and vertical space between the two rectangles.
|
|
||||||
* @method union
|
|
||||||
* @param {Rectangle} toUnion A Rectangle object to add to this Rectangle object.
|
|
||||||
* @param {Rectangle} output Optional Rectangle object. If given the new values will be set into this object, otherwise a brand new Rectangle object will be created and returned.
|
|
||||||
* @return {Rectangle} A Rectangle object that is the union of the two rectangles.
|
|
||||||
**/
|
|
||||||
public union(toUnion: Rectangle, output?: Rectangle = new Rectangle): Rectangle {
|
|
||||||
|
|
||||||
return output.setTo(
|
|
||||||
Math.min(toUnion.x, this.x),
|
|
||||||
Math.min(toUnion.y, this.y),
|
|
||||||
Math.max(toUnion.right, this.right),
|
|
||||||
Math.max(toUnion.bottom, this.bottom)
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a string representation of this object.
|
|
||||||
* @method toString
|
|
||||||
* @return {string} a string representation of the instance.
|
|
||||||
**/
|
|
||||||
public toString(): string {
|
|
||||||
|
|
||||||
return "[{Rectangle (x=" + this.x + " y=" + this.y + " width=" + this.width + " height=" + this.height + " empty=" + this.isEmpty + ")}]";
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
node_modules
|
|
||||||
.npm-debug.log
|
|
||||||
tmp
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
language: node_js
|
|
||||||
node_js:
|
|
||||||
- 0.8
|
|
||||||
before_script:
|
|
||||||
- npm install -g grunt-cli
|
|
||||||