mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-20 10:47:35 -05:00
Compare commits
584 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
156c23d550 | ||
|
|
30396ba79a | ||
|
|
a4343c62ca | ||
|
|
4b89c84692 | ||
|
|
df68449b82 | ||
|
|
48e3383f66 | ||
|
|
e750fa7393 | ||
|
|
5a15199a3a | ||
|
|
1801472fc4 | ||
|
|
ab15ac37ff | ||
|
|
0955a6be49 | ||
|
|
d58237ea15 | ||
|
|
2d50ca86a6 | ||
|
|
f1a46be738 | ||
|
|
3e2a67d434 | ||
|
|
aef028be6e | ||
|
|
c8ec29a3d8 | ||
|
|
e81830a2ea | ||
|
|
54df7171a2 | ||
|
|
b31af823d1 | ||
|
|
72f266532b | ||
|
|
d9bf5cae12 | ||
|
|
cd95a42e5e | ||
|
|
e67eb06d8b | ||
|
|
28d37cdead | ||
|
|
13604e0a47 | ||
|
|
aeb6f1a755 | ||
|
|
92e6f711b7 | ||
|
|
a24113f42b | ||
|
|
7a6f8ab3ad | ||
|
|
6dd242f3ce | ||
|
|
88fa82c61a | ||
|
|
2299ba5f61 | ||
|
|
117df6ca38 | ||
|
|
4256a81653 | ||
|
|
d5b6935c0b | ||
|
|
b4503ef729 | ||
|
|
a00a6750b4 | ||
|
|
a08f891b20 | ||
|
|
bc1cac9c41 | ||
|
|
50f7ab0f34 | ||
|
|
fdc35ce3ed | ||
|
|
5c4e400d32 | ||
|
|
7a23e355b9 | ||
|
|
dffac642a1 | ||
|
|
97699eaded | ||
|
|
c6aaacdbf1 | ||
|
|
abfc68765f | ||
|
|
3ac2ac0982 | ||
|
|
b9a1227e47 | ||
|
|
801c63947a | ||
|
|
ffee4add4a | ||
|
|
f0be7ef418 | ||
|
|
e4eedd80bc | ||
|
|
c9e7fe16e4 | ||
|
|
5079dd19cb | ||
|
|
b4c686f411 | ||
|
|
287d0fa1af | ||
|
|
b78455c4c1 | ||
|
|
312b6b0706 | ||
|
|
924e530096 | ||
|
|
ef8918f3a7 | ||
|
|
91ae242e49 | ||
|
|
fd307e52ae | ||
|
|
a68967c773 | ||
|
|
52da45bb9c | ||
|
|
ad0dde3f17 | ||
|
|
8f3c36deea | ||
|
|
23e1ab81b3 | ||
|
|
77b40aa348 | ||
|
|
f6decfd93d | ||
|
|
e8d5138cfa | ||
|
|
a088fbd6fb | ||
|
|
19214901f9 | ||
|
|
c330a623b2 | ||
|
|
f77241e977 | ||
|
|
ed6de66c08 | ||
|
|
5191c45113 | ||
|
|
840bc803b7 | ||
|
|
00fdc73015 | ||
|
|
9660976d1d | ||
|
|
7f666dc6a0 | ||
|
|
e2a2292a6f | ||
|
|
4d89cbde01 | ||
|
|
d8e1cb8b0f | ||
|
|
3aef5a99dc | ||
|
|
7994207c78 | ||
|
|
f376097a15 | ||
|
|
2a2ff4066d | ||
|
|
32c3fb72cc | ||
|
|
e44e18114d | ||
|
|
7d2df4895e | ||
|
|
59db56feec | ||
|
|
fd60b4789a | ||
|
|
0696e4682d | ||
|
|
d56eeb59ed | ||
|
|
1d015c7534 | ||
|
|
264675d0c3 | ||
|
|
37d4cb7c48 | ||
|
|
cabb1c72b6 | ||
|
|
489a2bb20e | ||
|
|
d5f42e57ce | ||
|
|
94b0bf4131 | ||
|
|
12428c0617 | ||
|
|
ef44df5dda | ||
|
|
da3b43abdd | ||
|
|
4cc9647dc6 | ||
|
|
74cd7c840a | ||
|
|
0f2deeb71a | ||
|
|
93539c9b5a | ||
|
|
e48e6276e1 | ||
|
|
75a57a49f5 | ||
|
|
8a1db288fc | ||
|
|
84dcde188b | ||
|
|
27c91e9703 | ||
|
|
b5a0cd4057 | ||
|
|
77d8fe3562 | ||
|
|
a484aff457 | ||
|
|
c96f5912df | ||
|
|
8a01a56e51 | ||
|
|
2774e49ab9 | ||
|
|
26e7a54f1f | ||
|
|
f0e69cbc36 | ||
|
|
413428f535 | ||
|
|
0c54036466 | ||
|
|
2555833831 | ||
|
|
7e0aceced1 | ||
|
|
77234f6df3 | ||
|
|
45af96aad4 | ||
|
|
184d29055e | ||
|
|
9e73181816 | ||
|
|
0b0e03456c | ||
|
|
c6b5ce7f55 | ||
|
|
a14e701be4 | ||
|
|
7813c3f03f | ||
|
|
3a3cb7b11d | ||
|
|
d7b0731385 | ||
|
|
df8973736f | ||
|
|
9121071ba3 | ||
|
|
bf6470c046 | ||
|
|
3b7099cd3d | ||
|
|
f6dfc5361e | ||
|
|
0a7e1ce0d7 | ||
|
|
d6b1c393f6 | ||
|
|
bccd5e3750 | ||
|
|
6df5905b2b | ||
|
|
6284c02032 | ||
|
|
db27d52352 | ||
|
|
8ba28989fb | ||
|
|
da544929ac | ||
|
|
bb364b0524 | ||
|
|
818614b798 | ||
|
|
50b1a1d7c5 | ||
|
|
7d3b792a79 | ||
|
|
af72e232c3 | ||
|
|
0cdbfbeb30 | ||
|
|
339e40063a | ||
|
|
4467898473 | ||
|
|
17d16b987f | ||
|
|
8e86daac71 | ||
|
|
856720da49 | ||
|
|
8f2c150d1e | ||
|
|
7d8b4c980a | ||
|
|
932756c7a0 | ||
|
|
538aac9a28 | ||
|
|
856bf8f5fb | ||
|
|
e1758ae2e2 | ||
|
|
61b3154461 | ||
|
|
fb9b30d144 | ||
|
|
b0df96b13f | ||
|
|
a469062a32 | ||
|
|
89d5d5c7db | ||
|
|
b8c2d6b05d | ||
|
|
b247864414 | ||
|
|
d3bcd87cfa | ||
|
|
82e5b64bad | ||
|
|
73e0271c23 | ||
|
|
a2dabee0e9 | ||
|
|
6a27c6d9f2 | ||
|
|
213ced0c7f | ||
|
|
5086c23d47 | ||
|
|
ee345a5206 | ||
|
|
f74cddc3b1 | ||
|
|
5b986b8b26 | ||
|
|
14887b9814 | ||
|
|
ecc40315b3 | ||
|
|
e7aed7fcf0 | ||
|
|
cd1aa948f9 | ||
|
|
82613d016a | ||
|
|
3a66be585f | ||
|
|
0a4e36ae09 | ||
|
|
92643539cf | ||
|
|
a1281d1331 | ||
|
|
074ca0ef8f | ||
|
|
464a9633dc | ||
|
|
fc2d91c5bb | ||
|
|
d68169bffb | ||
|
|
7efdb04e1e | ||
|
|
0155e122fd | ||
|
|
eb03f16a77 | ||
|
|
5ac39641ab | ||
|
|
8d1e48e400 | ||
|
|
0021ccb49f | ||
|
|
8590c7e5b8 | ||
|
|
8c5475f78f | ||
|
|
dfa116eb70 | ||
|
|
3a9fd3c074 | ||
|
|
5a92ef3c11 | ||
|
|
d3902f5c93 | ||
|
|
c886f887ae | ||
|
|
fc5089ac59 | ||
|
|
e3602f464b | ||
|
|
f3db6a339c | ||
|
|
c05195c045 | ||
|
|
af981fc719 | ||
|
|
088a264910 | ||
|
|
d7e80ad51b | ||
|
|
b53ddd401f | ||
|
|
e9122bca9d | ||
|
|
b61e8435d1 | ||
|
|
146afb6532 | ||
|
|
854e9d1378 | ||
|
|
689878ce32 | ||
|
|
d7ab177cc5 | ||
|
|
f4c6093c47 | ||
|
|
9fedfe3699 | ||
|
|
26f07246e1 | ||
|
|
3ae4b3c4de | ||
|
|
c8f9f16791 | ||
|
|
88f0738500 | ||
|
|
03c79d5f2f | ||
|
|
e7c3b7bcfe | ||
|
|
c8becca044 | ||
|
|
543a27271f | ||
|
|
a62aba83a0 | ||
|
|
53c6cf5f45 | ||
|
|
89842e20da | ||
|
|
ef793aecf3 | ||
|
|
51d51409d3 | ||
|
|
371b5eac45 | ||
|
|
5319bd13d5 | ||
|
|
e10d055453 | ||
|
|
716254e655 | ||
|
|
4c00b1683f | ||
|
|
37c9db09c6 | ||
|
|
653e2c9be4 | ||
|
|
a2a9613da1 | ||
|
|
e8d92d0d34 | ||
|
|
755b98a8c0 | ||
|
|
13e9252260 | ||
|
|
6a9c27325a | ||
|
|
a1cb78eb85 | ||
|
|
716b57ebd3 | ||
|
|
8e231313b8 | ||
|
|
84e4e361c5 | ||
|
|
41a8d804e3 | ||
|
|
03e798a079 | ||
|
|
34a0205757 | ||
|
|
ba145f04ea | ||
|
|
22fd023635 | ||
|
|
08f34f748b | ||
|
|
7ffe6a598e | ||
|
|
71d24a445e | ||
|
|
6bcbbfb085 | ||
|
|
04fe1348d8 | ||
|
|
3033c779b0 | ||
|
|
4483f0db0f | ||
|
|
727267ae22 | ||
|
|
b5d15c2f7e | ||
|
|
589c614e57 | ||
|
|
4588e90226 | ||
|
|
8665a14dec | ||
|
|
43d598d951 | ||
|
|
68018cf078 | ||
|
|
ef4ab0d7a8 | ||
|
|
e66a2702df | ||
|
|
c57d4a7054 | ||
|
|
a36f08f0f1 | ||
|
|
760a8c75a5 | ||
|
|
740fd921e1 | ||
|
|
065c697070 | ||
|
|
e2c2459290 | ||
|
|
11c79a5344 | ||
|
|
429fe4c356 | ||
|
|
a18b4edfc0 | ||
|
|
b14a2bba5f | ||
|
|
1f825edc28 | ||
|
|
6ed834807a | ||
|
|
9a908e5fd0 | ||
|
|
4c30359b71 | ||
|
|
34dfe2d80b | ||
|
|
25bcff10b7 | ||
|
|
81268d0545 | ||
|
|
8f0a7706d7 | ||
|
|
46150f9b80 | ||
|
|
247745b7e7 | ||
|
|
94cc09b610 | ||
|
|
a210b2d5f5 | ||
|
|
12bf6db331 | ||
|
|
697ac9de9a | ||
|
|
4124bb5edc | ||
|
|
d55340a817 | ||
|
|
0de8cd9ab7 | ||
|
|
4e8281c749 | ||
|
|
357fbc644d | ||
|
|
7947a8a2dc | ||
|
|
35de3aa154 | ||
|
|
1ea687beb8 | ||
|
|
bb5c59307a | ||
|
|
5a3c414c8f | ||
|
|
cc4b460183 | ||
|
|
470c3489dd | ||
|
|
e1b4415193 | ||
|
|
77d98a565e | ||
|
|
412da2de08 | ||
|
|
dbdcd0b3d0 | ||
|
|
5c67384fbf | ||
|
|
35b0f9d377 | ||
|
|
95783bc284 | ||
|
|
4b840f7cbd | ||
|
|
f73d6cd9f2 | ||
|
|
15bb8f03ea | ||
|
|
059dbc88c9 | ||
|
|
c0f36aa047 | ||
|
|
d4120d2af3 | ||
|
|
dd1c008447 | ||
|
|
3721d2cd72 | ||
|
|
e0dda0e547 | ||
|
|
3c7568c72c | ||
|
|
6be1758548 | ||
|
|
25809660ef | ||
|
|
6b9eff45bb | ||
|
|
08e83feaf5 | ||
|
|
4f05b5afc6 | ||
|
|
9a5bf9918e | ||
|
|
1c7cf0ba7d | ||
|
|
ce2d1a4513 | ||
|
|
7d50d7eea0 | ||
|
|
e9411dc796 | ||
|
|
5cf2de16d1 | ||
|
|
e53bcf15a9 | ||
|
|
bec70b60b8 | ||
|
|
8b7fb89c68 | ||
|
|
b2bbdda73d | ||
|
|
ee2f46cfb9 | ||
|
|
4337e6833a | ||
|
|
a73c73b814 | ||
|
|
e8318a98f0 | ||
|
|
94f2ac6204 | ||
|
|
cc6cb4ded0 | ||
|
|
c61d4191c3 | ||
|
|
e284da7c09 | ||
|
|
9992096654 | ||
|
|
c696d92f40 | ||
|
|
af60299324 | ||
|
|
5aa9135a34 | ||
|
|
72e23ac86f | ||
|
|
33d49ad87d | ||
|
|
aa2335ca2e | ||
|
|
b31428006c | ||
|
|
dc1d583791 | ||
|
|
4299a74e40 | ||
|
|
3e408b7baa | ||
|
|
446c131ccb | ||
|
|
b062efcf17 | ||
|
|
30e31a86ef | ||
|
|
182272e8c7 | ||
|
|
06df21e8e3 | ||
|
|
cafebd68f2 | ||
|
|
061d4b3f72 | ||
|
|
6586e79d5e | ||
|
|
cda6c6bc7e | ||
|
|
a628026838 | ||
|
|
6700856b9f | ||
|
|
411aa0bbed | ||
|
|
0d79d31b96 | ||
|
|
cb05a9b067 | ||
|
|
536f359fb9 | ||
|
|
56e888ed33 | ||
|
|
687b93d148 | ||
|
|
0e1c396d7c | ||
|
|
7e24289703 | ||
|
|
0b23310a06 | ||
|
|
41ebaaf366 | ||
|
|
b79ceea7a8 | ||
|
|
b990bcb67a | ||
|
|
3f0f2d9910 | ||
|
|
4333f5f979 | ||
|
|
07e75293b8 | ||
|
|
a9ca7106cb | ||
|
|
da2728e6df | ||
|
|
adfa9a9b05 | ||
|
|
be9b9f66d3 | ||
|
|
9521bc7175 | ||
|
|
b445f8a834 | ||
|
|
3c3dffd5ed | ||
|
|
4c8443fd00 | ||
|
|
06a5a54103 | ||
|
|
0d3c3eef4e | ||
|
|
f0a6fb913f | ||
|
|
5f0c508fed | ||
|
|
16d9657982 | ||
|
|
40d098310e | ||
|
|
1345449d57 | ||
|
|
515858f313 | ||
|
|
2f452e9dc7 | ||
|
|
66119157a7 | ||
|
|
5b671dd1d0 | ||
|
|
1017362eec | ||
|
|
f67b8e0285 | ||
|
|
4c635fe84c | ||
|
|
68e463493e | ||
|
|
f1979d60b7 | ||
|
|
9150ebafec | ||
|
|
9543019336 | ||
|
|
1c53d91c6b | ||
|
|
4850f39b5a | ||
|
|
ab085c2d92 | ||
|
|
bf4d835948 | ||
|
|
214e39537b | ||
|
|
2d33afc195 | ||
|
|
87ea24ebd4 | ||
|
|
5380f8b9b3 | ||
|
|
00121ff8ba | ||
|
|
80e5d20e37 | ||
|
|
58f7c2137d | ||
|
|
f9194cc833 | ||
|
|
d9b8b48972 | ||
|
|
aa85f5f596 | ||
|
|
5341a0be4a | ||
|
|
0cfe20ca65 | ||
|
|
c352b502c4 | ||
|
|
58b4df6b3d | ||
|
|
29ba9436c8 | ||
|
|
2a044e88ad | ||
|
|
63092f9d72 | ||
|
|
0209324d57 | ||
|
|
1587273868 | ||
|
|
beb3aa1574 | ||
|
|
fe708c9fb4 | ||
|
|
e45d8bf973 | ||
|
|
b184c92f01 | ||
|
|
6c8afb05a7 | ||
|
|
d3dd4573cf | ||
|
|
d5cf68391a | ||
|
|
4e54e93450 | ||
|
|
e4f6387f18 | ||
|
|
54cb35b60a | ||
|
|
18ede2b729 | ||
|
|
f138b5a4f4 | ||
|
|
11a517bba4 | ||
|
|
66b57bf812 | ||
|
|
a9357bd97e | ||
|
|
d7c6d42c3d | ||
|
|
4dd1dc28b1 | ||
|
|
1e05ff7c95 | ||
|
|
e8e2e65584 | ||
|
|
3727e60152 | ||
|
|
0254012db6 | ||
|
|
8b97e4757f | ||
|
|
c70e121078 | ||
|
|
a4f97e6e46 | ||
|
|
800145a83c | ||
|
|
c75f885cb4 | ||
|
|
4011a51013 | ||
|
|
f4165dabcf | ||
|
|
de6c26eb05 | ||
|
|
5f319452d5 | ||
|
|
60d505d2d1 | ||
|
|
f64cc4dcae | ||
|
|
60e6f4293a | ||
|
|
00ab9a8d02 | ||
|
|
7d5f6c9ead | ||
|
|
a295edf19d | ||
|
|
b674515d06 | ||
|
|
d033ab04da | ||
|
|
304d76d088 | ||
|
|
978afdad97 | ||
|
|
d4e41e679d | ||
|
|
146264ff12 | ||
|
|
dcb107ae65 | ||
|
|
c236269d13 | ||
|
|
8f658e6d85 | ||
|
|
d203b60f44 | ||
|
|
a1a16aba74 | ||
|
|
6ded003447 | ||
|
|
4841e29fc6 | ||
|
|
0b014eea56 | ||
|
|
1c0be16f30 | ||
|
|
27ba8bea2f | ||
|
|
c566977749 | ||
|
|
5c1b785b4b | ||
|
|
8657dfb5da | ||
|
|
dfa837754e | ||
|
|
0a7df78770 | ||
|
|
066ecbe022 | ||
|
|
6c80db810f | ||
|
|
6023c413ab | ||
|
|
7910d040b6 | ||
|
|
5bd99f5224 | ||
|
|
f3157b377f | ||
|
|
e31e03afde | ||
|
|
eddde7c94c | ||
|
|
7be72ee4c1 | ||
|
|
6731467514 | ||
|
|
8dd699d235 | ||
|
|
6cb81b5c3d | ||
|
|
17187ba3ec | ||
|
|
531ee928b0 | ||
|
|
db806a5df9 | ||
|
|
9de154595a | ||
|
|
9e4cb79679 | ||
|
|
b7834073b8 | ||
|
|
b0e56577b5 | ||
|
|
ccb0e6b269 | ||
|
|
edfd4baa1f | ||
|
|
0f50f4a9fd | ||
|
|
47494e62a7 | ||
|
|
7aa25712d9 | ||
|
|
1db155570d | ||
|
|
1054e8e644 | ||
|
|
aa429f34d8 | ||
|
|
e351889811 | ||
|
|
24a70a8273 | ||
|
|
3f26657116 | ||
|
|
d41669af8b | ||
|
|
56466c2a00 | ||
|
|
fa7a97ca30 | ||
|
|
8aba271a42 | ||
|
|
8275aa2810 | ||
|
|
410ddf314c | ||
|
|
fa217bee20 | ||
|
|
817d0edc69 | ||
|
|
513dfe0b42 | ||
|
|
bd7a20309b | ||
|
|
a726be3c7c | ||
|
|
10f2054e9a | ||
|
|
2fa47f310d | ||
|
|
5b927a70c2 | ||
|
|
2a59ff8e68 | ||
|
|
e4d1befcdb | ||
|
|
844e04ff96 | ||
|
|
cc05a98b0e | ||
|
|
006d161a32 | ||
|
|
a4839db79a | ||
|
|
87e3b5b1dc | ||
|
|
faa900d502 | ||
|
|
a5275db3ec | ||
|
|
77e017a574 | ||
|
|
8ed8ddbf76 | ||
|
|
eb31978488 | ||
|
|
677d708588 | ||
|
|
ade0dca8f9 | ||
|
|
8e1cd0b268 | ||
|
|
9102768366 | ||
|
|
0c722b9164 | ||
|
|
b6f514451a | ||
|
|
c49fdfc56c | ||
|
|
676e04b28e | ||
|
|
6aa864a351 | ||
|
|
72acb4826c | ||
|
|
734be5f355 | ||
|
|
cede06ae19 | ||
|
|
19491d8010 | ||
|
|
c580aac991 | ||
|
|
032d1aaad7 | ||
|
|
afa216dc5e | ||
|
|
69339fe3de | ||
|
|
571bb2b294 | ||
|
|
91a09a09f7 | ||
|
|
9b3433f6ae | ||
|
|
ee9b0960f7 | ||
|
|
506ac2574f | ||
|
|
dc84d7c1b5 | ||
|
|
fcaa57307f | ||
|
|
d25e754beb | ||
|
|
7f6f411ea8 | ||
|
|
96a73e31f3 | ||
|
|
c7942d7d8f | ||
|
|
479348eec9 | ||
|
|
ebfed27630 | ||
|
|
8923485169 | ||
|
|
d62de26683 | ||
|
|
1dd9c5b009 |
9
.github/ISSUE_TEMPLATE/config.yml
vendored
9
.github/ISSUE_TEMPLATE/config.yml
vendored
@@ -1,5 +1,8 @@
|
||||
blank_issues_enabled: false
|
||||
blank_issues_enabled: true
|
||||
contact_links:
|
||||
- name: Question
|
||||
url: https://community.anaconda.cloud/c/tech-topics/pyscript
|
||||
- name: Feature Proposals
|
||||
url: https://github.com/pyscript/pyscript/discussions/new?category=proposals
|
||||
about: Create a feature request to make PyScript even better
|
||||
- name: Questions
|
||||
url: https://github.com/pyscript/pyscript/discussions/new?category=q-a
|
||||
about: For questions or discussions about pyscript
|
||||
|
||||
67
.github/ISSUE_TEMPLATE/feature-request.yml
vendored
67
.github/ISSUE_TEMPLATE/feature-request.yml
vendored
@@ -1,67 +0,0 @@
|
||||
name: Feature Request
|
||||
description: Create a feature request to make PyScript even better
|
||||
labels: ["type: enhancement", "needs-triage"]
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
### Thanks for helping PyScript! 🐍
|
||||
|
||||
Going through feature requests and issues takes up a lot of time, so please be so kind and take a few minutes to fill out all the areas to the best of your ability.
|
||||
|
||||
There will always be more great ideas than there is time to do them, and so we will need to selectively close issues that don't provide enough information, so everyone can focus our time on helping people like you who fill out the form completely. Thank you for your collaboration!
|
||||
|
||||
There are also already a lot of open requests, so please take 2 minutes and search through existing ones to see if your idea already exists. If you find something close, please upvote that request and comment.
|
||||
|
||||
Thanks for helping PyScript be amazing. We are nothing without people like you helping build a better community 💐!
|
||||
|
||||
### Lets make sure you are in the right place. If you have an idea/request for:
|
||||
|
||||
- #### A specific package/library (such as pandas or scikit learn):
|
||||
|
||||
Search for that respective library on github repo or website. You will have much more success there.
|
||||
|
||||
- #### A general Python question/feature request:
|
||||
|
||||
Try out a forum post [here](https://discuss.python.org/c/users/7)
|
||||
|
||||
- type: checkboxes
|
||||
id: checks
|
||||
attributes:
|
||||
label: Checklist
|
||||
description: Please confirm and check all the following options
|
||||
options:
|
||||
- label: I added a descriptive title
|
||||
required: true
|
||||
- label: I searched for other feature requests and couldn't find a duplicate (including also the ``type-feature`` tag)
|
||||
required: true
|
||||
- label: I confirmed that it's not related to another project are area (see the above section)
|
||||
required: true
|
||||
- type: textarea
|
||||
id: request-idea
|
||||
attributes:
|
||||
label: What is the idea?
|
||||
description: Describe what the feature is and the desired state
|
||||
placeholder: This feature would allow any user of PyScript to type in a simple command in the console and show all variables currently in use
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: why
|
||||
attributes:
|
||||
label: Why is this needed
|
||||
description: |
|
||||
Who would benefit from this and why would this add value to them? What problem does this solve?
|
||||
placeholder: This would benefit users who would like to see what is being used so they can learn and debug faster
|
||||
- type: textarea
|
||||
id: what
|
||||
attributes:
|
||||
label: What should happen?
|
||||
description: |
|
||||
What should be the user experience with the feature? Describe from a user perpective what they would do and see
|
||||
placeholder: A user would type in ``PyScript debug`` in the browser console and see a list of all variables created.
|
||||
- type: textarea
|
||||
id: context
|
||||
attributes:
|
||||
label: Additional Context
|
||||
description: |
|
||||
Is there any other information that you think would be valuable for the team to know?
|
||||
37
.github/ISSUE_TEMPLATE/misc.yml
vendored
37
.github/ISSUE_TEMPLATE/misc.yml
vendored
@@ -1,37 +0,0 @@
|
||||
name: Miscellaneous
|
||||
description: For issues that don't belong in other categories
|
||||
labels: ["type: misc", "needs-triage"]
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Thanks for helping PyScript! 🐍
|
||||
|
||||
This issue is for things that doesn't make sense to put into the other issue categories and we don't want it to get lost.
|
||||
|
||||
Going through issues takes up a lot of time, so please be so kind and take a few minutes to fill out all the areas to the best of your ability.
|
||||
|
||||
There will always be more issues than there is time to do them, and so we will need to selectively close issues that don't provide enough information, so we can focus our time on helping people like you who fill out the issue form completely. Thank you for your collaboration!
|
||||
|
||||
There are also already a lot of open issues, so please take 2 minutes and search through existing ones to see if what you are experiencing already exists
|
||||
|
||||
Thanks for helping PyScript be amazing. We are nothing without people like you helping build a better community 💐!
|
||||
- type: checkboxes
|
||||
id: checks
|
||||
attributes:
|
||||
label: Checklist
|
||||
description: Please confirm and check all the following options.
|
||||
options:
|
||||
- label: I added a descriptive title
|
||||
required: true
|
||||
- label: I searched for other issues and couldn't find a duplication
|
||||
required: true
|
||||
- label: I already searched in Google and didn't find any good information or help
|
||||
required: true
|
||||
- type: textarea
|
||||
id: what
|
||||
attributes:
|
||||
label: What is the issue/comment/problem?
|
||||
description: This is a miscellaneous issue so this could be just about anything. We simply ask that you provide as many details as you can to help spur discussion or the outcome you want.
|
||||
validations:
|
||||
required: true
|
||||
15
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
15
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
## Description
|
||||
|
||||
<!--Please describe the changes in your pull request in few words here. -->
|
||||
|
||||
## Changes
|
||||
|
||||
<!-- List the changes done to fix a bug or introduce a new feature.Please note both user-facing changes and changes to internal API's here -->
|
||||
|
||||
## Checklist
|
||||
|
||||
<!-- Note: Only user-facing changes require a changelog entry. Internal-only API changes do not require a changelog entry. Changes in documentation do not require a changelog entry. -->
|
||||
|
||||
- [ ] All tests pass locally
|
||||
- [ ] I have updated `CHANGELOG.md`
|
||||
- [ ] I have created documentation for this(if applicable)
|
||||
18
.github/dashboard.yaml
vendored
18
.github/dashboard.yaml
vendored
@@ -1,18 +0,0 @@
|
||||
name: Push issue to Github Project dashboard
|
||||
|
||||
on:
|
||||
issues:
|
||||
types:
|
||||
- opened
|
||||
pull_request_target:
|
||||
types:
|
||||
- opened
|
||||
|
||||
jobs:
|
||||
add_to_project:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/add-to-project@v0.0.3
|
||||
with:
|
||||
project-url: https://github.com/orgs/pyscript/projects/4/
|
||||
github-token: ${{ secrets.PROJECT_TOKEN }}
|
||||
74
.github/workflows/build-latest.yml
vendored
74
.github/workflows/build-latest.yml
vendored
@@ -1,74 +0,0 @@
|
||||
name: '[CI] Build Latest'
|
||||
|
||||
on:
|
||||
push: # Only run on merges into main that modify files under pyscriptjs/
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- pyscriptjs/**
|
||||
- .github/workflows/build-latest.yml # Test that workflow works when changed
|
||||
|
||||
pull_request: # Run on any PR that modifies files in pyscriptjs/
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- pyscriptjs/**
|
||||
- .github/workflows/build-latest.yml # Test that workflow works when changed
|
||||
|
||||
env:
|
||||
MINICONDA_PYTHON_VERSION: py38
|
||||
MINICONDA_VERSION: 4.11.0
|
||||
|
||||
defaults:
|
||||
run:
|
||||
working-directory: pyscriptjs
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
id-token: write
|
||||
steps:
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install node
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 18.x
|
||||
|
||||
- name: Cache node modules
|
||||
uses: actions/cache@v3
|
||||
env:
|
||||
cache-name: cache-node-modules
|
||||
with:
|
||||
# npm cache files are stored in `~/.npm` on Linux/macOS
|
||||
path: ~/.npm
|
||||
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-build-${{ env.cache-name }}-
|
||||
${{ runner.os }}-build-
|
||||
${{ runner.os }}-
|
||||
|
||||
- name: setup Miniconda
|
||||
uses: conda-incubator/setup-miniconda@v2
|
||||
|
||||
- name: Setup Environment
|
||||
run: make setup
|
||||
|
||||
- name: Build and Test
|
||||
run: make test
|
||||
|
||||
# Deploy to S3
|
||||
- name: Configure AWS credentials
|
||||
if: github.ref == 'refs/heads/main' # Only deploy on merge into main
|
||||
uses: aws-actions/configure-aws-credentials@v1.6.1
|
||||
with:
|
||||
aws-region: ${{secrets.AWS_REGION}}
|
||||
role-to-assume: ${{ secrets.AWS_OIDC_RUNNER_ROLE }}
|
||||
|
||||
- name: Sync to S3
|
||||
if: github.ref == 'refs/heads/main'
|
||||
run: aws s3 sync --quiet ./examples/build/ s3://pyscript.net/latest/
|
||||
56
.github/workflows/build-release.yml
vendored
56
.github/workflows/build-release.yml
vendored
@@ -1,56 +0,0 @@
|
||||
name: '[CI] Build Release'
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '[0-9][0-9][0-9][0-9].[0-9][0-9].[0-9]+' # YYYY.MM.MICRO
|
||||
|
||||
env:
|
||||
MINICONDA_PYTHON_VERSION: py38
|
||||
MINICONDA_VERSION: 4.11.0
|
||||
|
||||
defaults:
|
||||
run:
|
||||
working-directory: pyscriptjs
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install node
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 18.x
|
||||
|
||||
- name: Cache node modules
|
||||
uses: actions/cache@v3
|
||||
env:
|
||||
cache-name: cache-node-modules
|
||||
with:
|
||||
# npm cache files are stored in `~/.npm` on Linux/macOS
|
||||
path: ~/.npm
|
||||
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-build-${{ env.cache-name }}-
|
||||
${{ runner.os }}-build-
|
||||
${{ runner.os }}-
|
||||
|
||||
- name: setup Miniconda
|
||||
uses: conda-incubator/setup-miniconda@v2
|
||||
|
||||
- name: Setup Environment
|
||||
run: make setup
|
||||
|
||||
- name: Build and Test
|
||||
run: make test
|
||||
|
||||
- name: Prepare Release
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
draft: true
|
||||
prerelease: true
|
||||
generate_release_notes: true
|
||||
60
.github/workflows/docs-latest.yml
vendored
60
.github/workflows/docs-latest.yml
vendored
@@ -1,60 +0,0 @@
|
||||
name: '[Docs] Build Latest'
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- docs/**
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
id-token: write
|
||||
env:
|
||||
SPHINX_HTML_BASE_URL: https://docs.pyscript.net/
|
||||
steps:
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token.
|
||||
fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository.
|
||||
|
||||
- name: Setup
|
||||
uses: conda-incubator/setup-miniconda@v2
|
||||
with:
|
||||
auto-update-conda: true
|
||||
activate-environment: docs
|
||||
environment-file: docs/environment.yml
|
||||
python-version: '3.9'
|
||||
|
||||
- name: Build
|
||||
shell: bash -l {0}
|
||||
run: |
|
||||
cd docs/
|
||||
make html
|
||||
|
||||
- name: Upload artifacts
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: pyscript-docs-latest
|
||||
path: docs/_build/html/
|
||||
|
||||
# Deploy to S3
|
||||
- name: Configure AWS credentials
|
||||
uses: aws-actions/configure-aws-credentials@v1.6.1
|
||||
with:
|
||||
aws-region: ${{secrets.AWS_REGION}}
|
||||
role-to-assume: ${{ secrets.AWS_OIDC_RUNNER_ROLE }}
|
||||
|
||||
- name: Copy redirect file
|
||||
run: aws s3 cp --quiet ./docs/_build/html/_static/redirect.html s3://docs.pyscript.net/index.html
|
||||
|
||||
# - name: Delete latest directory
|
||||
# run: aws s3 rm --recursive s3://docs.pyscript.net/latest/
|
||||
|
||||
- name: Sync to S3
|
||||
run: aws s3 sync --quiet ./docs/_build/html/ s3://docs.pyscript.net/latest/
|
||||
57
.github/workflows/docs-release.yml
vendored
57
.github/workflows/docs-release.yml
vendored
@@ -1,57 +0,0 @@
|
||||
name: '[Docs] Build Release'
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
id-token: write
|
||||
env:
|
||||
SPHINX_HTML_BASE_URL: https://docs.pyscript.net/
|
||||
steps:
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token.
|
||||
fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository.
|
||||
|
||||
- name: Setup
|
||||
uses: conda-incubator/setup-miniconda@v2
|
||||
with:
|
||||
auto-update-conda: true
|
||||
activate-environment: docs
|
||||
environment-file: docs/environment.yml
|
||||
python-version: '3.9'
|
||||
|
||||
- name: Build
|
||||
shell: bash -l {0}
|
||||
run: |
|
||||
cd docs/
|
||||
make html
|
||||
|
||||
- name: Upload artifacts
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: pyscript-docs-${{ github.ref_name }}
|
||||
path: docs/_build/html/
|
||||
|
||||
# Deploy to S3
|
||||
- name: Configure AWS credentials
|
||||
uses: aws-actions/configure-aws-credentials@v1.6.1
|
||||
with:
|
||||
aws-region: ${{secrets.AWS_REGION}}
|
||||
role-to-assume: ${{ secrets.AWS_OIDC_RUNNER_ROLE }}
|
||||
|
||||
- name: Copy redirect file
|
||||
run: aws s3 cp --quiet ./docs/_build/html/_static/redirect.html s3://docs.pyscript.net/index.html
|
||||
|
||||
# - name: Delete release directory
|
||||
# run: aws s3 rm --recursive s3://docs.pyscript.net/${{ github.ref_name }}/
|
||||
|
||||
- name: Sync to S3
|
||||
run: aws s3 sync --quiet ./docs/_build/html/ s3://docs.pyscript.net/${{ github.ref_name }}/
|
||||
78
.github/workflows/docs-review.yml
vendored
78
.github/workflows/docs-review.yml
vendored
@@ -1,78 +0,0 @@
|
||||
name: '[Docs] Build Review'
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- '*'
|
||||
paths:
|
||||
- docs/**
|
||||
|
||||
concurrency:
|
||||
# Concurrency group that uses the workflow name and PR number if available
|
||||
# or commit SHA as a fallback. If a new build is triggered under that
|
||||
# concurrency group while a previous build is running it will be canceled.
|
||||
# Repeated pushes to a PR will cancel all previous builds, while multiple
|
||||
# merges to main will not cancel.
|
||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
build:
|
||||
if: >-
|
||||
!github.event.repository.fork
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
id-token: write
|
||||
env:
|
||||
SPHINX_HTML_BASE_URL: https://docs.pyscript.net/
|
||||
steps:
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token.
|
||||
fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository.
|
||||
|
||||
- name: Setup
|
||||
uses: conda-incubator/setup-miniconda@v2
|
||||
with:
|
||||
auto-update-conda: true
|
||||
activate-environment: docs
|
||||
environment-file: docs/environment.yml
|
||||
python-version: '3.9'
|
||||
|
||||
- name: Build
|
||||
shell: bash -l {0}
|
||||
run: |
|
||||
cd docs/
|
||||
make html
|
||||
|
||||
- name: Upload artifacts
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: pyscript-docs-review-${{ github.event.number }}
|
||||
path: docs/_build/html/
|
||||
|
||||
# Deploy to S3
|
||||
- name: Configure AWS credentials
|
||||
uses: aws-actions/configure-aws-credentials@v1.6.1
|
||||
with:
|
||||
aws-region: ${{secrets.AWS_REGION}}
|
||||
role-to-assume: ${{ secrets.AWS_OIDC_RUNNER_ROLE }}
|
||||
|
||||
- name: Copy redirect file
|
||||
run: aws s3 cp --quiet ./docs/_build/html/_static/redirect.html s3://docs.pyscript.net/index.html
|
||||
|
||||
# - name: Delete review directory
|
||||
# run: aws s3 rm --recursive s3://docs.pyscript.net/review/${{ github.event.number }}/
|
||||
|
||||
- name: Sync to S3
|
||||
run: aws s3 sync --quiet ./docs/_build/html/ s3://docs.pyscript.net/review/${{ github.event.number }}/
|
||||
|
||||
- name: Adding step summary
|
||||
run: |
|
||||
echo "### Review documentation" >> $GITHUB_STEP_SUMMARY
|
||||
echo "As with any pull request, you can find the rendered documentation version for pull request ${{ github.event.number }} here:"
|
||||
echo "" >> $GITHUB_STEP_SUMMARY # this is a blank line
|
||||
echo "https://docs.pyscript.net/review/${{ github.event.number }}/" >> $GITHUB_STEP_SUMMARY
|
||||
56
.github/workflows/prepare-release.yml
vendored
Normal file
56
.github/workflows/prepare-release.yml
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
name: "Prepare Release"
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "[0-9][0-9][0-9][0-9].[0-9][0-9].[0-9]+" # YYYY.MM.MICRO
|
||||
|
||||
defaults:
|
||||
run:
|
||||
working-directory: ./pyscript.core
|
||||
|
||||
jobs:
|
||||
prepare-release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install node
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 18.x
|
||||
|
||||
- name: Cache node modules
|
||||
uses: actions/cache@v3
|
||||
env:
|
||||
cache-name: cache-node-modules
|
||||
with:
|
||||
# npm cache files are stored in `~/.npm` on Linux/macOS
|
||||
path: ~/.npm
|
||||
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-build-${{ env.cache-name }}-
|
||||
${{ runner.os }}-build-
|
||||
${{ runner.os }}-
|
||||
|
||||
- name: NPM Install
|
||||
run: npm install && npx playwright install
|
||||
|
||||
- name: Build
|
||||
run: npm run build
|
||||
|
||||
- name: Generate index.html
|
||||
working-directory: .
|
||||
run: sed 's#_PATH_#./#' ./public/index.html > ./pyscript.core/dist/index.html
|
||||
|
||||
- name: Zip dist folder
|
||||
run: zip -r -q ./build.zip ./dist
|
||||
|
||||
- name: Prepare Release
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
draft: true
|
||||
prerelease: true
|
||||
generate_release_notes: true
|
||||
files: ./build.zip
|
||||
36
.github/workflows/publish-release.yml
vendored
36
.github/workflows/publish-release.yml
vendored
@@ -1,26 +1,22 @@
|
||||
name: '[CI] Publish Release'
|
||||
name: "Publish Release"
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
|
||||
env:
|
||||
MINICONDA_PYTHON_VERSION: py38
|
||||
MINICONDA_VERSION: 4.11.0
|
||||
|
||||
defaults:
|
||||
run:
|
||||
working-directory: pyscriptjs
|
||||
working-directory: ./pyscript.core
|
||||
|
||||
jobs:
|
||||
build:
|
||||
publish-release:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
id-token: write
|
||||
contents: read
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install node
|
||||
uses: actions/setup-node@v3
|
||||
@@ -40,22 +36,24 @@ jobs:
|
||||
${{ runner.os }}-build-
|
||||
${{ runner.os }}-
|
||||
|
||||
- name: setup Miniconda
|
||||
uses: conda-incubator/setup-miniconda@v2
|
||||
- name: npm install
|
||||
run: npm install && npx playwright install
|
||||
|
||||
- name: Setup Environment
|
||||
run: make setup
|
||||
- name: build
|
||||
run: npm run build
|
||||
|
||||
- name: Build and Test
|
||||
run: make test
|
||||
- name: Generate index.html in snapshot
|
||||
working-directory: .
|
||||
run: sed 's#_PATH_#https://pyscript.net/releases/${{ github.ref_name }}/#' ./public/index.html > ./pyscript.core/dist/index.html
|
||||
|
||||
# Upload to S3
|
||||
- name: Configure AWS credentials
|
||||
uses: aws-actions/configure-aws-credentials@v1.6.1
|
||||
uses: aws-actions/configure-aws-credentials@v4
|
||||
with:
|
||||
aws-region: ${{ secrets.AWS_REGION }}
|
||||
role-to-assume: ${{ secrets.AWS_OIDC_RUNNER_ROLE }}
|
||||
|
||||
- name: Sync to S3
|
||||
run: | # Overwrite "latest" alpha + versioned subdirectory
|
||||
aws s3 sync --quiet ./examples/build/ s3://pyscript.net/releases/${{ github.ref_name }}
|
||||
run:
|
||||
| # Update /latest and create an explicitly versioned directory under releases/YYYY.MM.MICRO/
|
||||
aws s3 sync --quiet ./dist/ s3://pyscript.net/latest/
|
||||
aws s3 sync --quiet ./dist/ s3://pyscript.net/releases/${{ github.ref_name }}/
|
||||
|
||||
61
.github/workflows/publish-snapshot.yml
vendored
Normal file
61
.github/workflows/publish-snapshot.yml
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
name: "Publish Snapshot"
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
snapshot_version:
|
||||
description: "The calver version of this snapshot: 2022.09.1 or 2022.09.1.RC1"
|
||||
type: string
|
||||
required: true
|
||||
|
||||
defaults:
|
||||
run:
|
||||
working-directory: ./pyscript.core
|
||||
|
||||
jobs:
|
||||
publish-snapshot:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
id-token: write
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install node
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 18.x
|
||||
|
||||
- name: Cache node modules
|
||||
uses: actions/cache@v3
|
||||
env:
|
||||
cache-name: cache-node-modules
|
||||
with:
|
||||
# npm cache files are stored in `~/.npm` on Linux/macOS
|
||||
path: ~/.npm
|
||||
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-build-${{ env.cache-name }}-
|
||||
${{ runner.os }}-build-
|
||||
${{ runner.os }}-
|
||||
|
||||
- name: Install Dependencies
|
||||
run: npm install && npx playwright install
|
||||
|
||||
- name: Build Pyscript.core
|
||||
run: npm run build
|
||||
|
||||
- name: Configure AWS credentials
|
||||
uses: aws-actions/configure-aws-credentials@v4
|
||||
with:
|
||||
aws-region: ${{ secrets.AWS_REGION }}
|
||||
role-to-assume: ${{ secrets.AWS_OIDC_RUNNER_ROLE }}
|
||||
|
||||
- name: Generate index.html in snapshot
|
||||
working-directory: .
|
||||
run: sed 's#_PATH_#https://pyscript.net/snapshots/${{ inputs.snapshot_version }}/#' ./public/index.html > ./pyscript.core/dist/index.html
|
||||
|
||||
- name: Copy to Snapshot
|
||||
run: >
|
||||
aws s3 sync ./dist/ s3://pyscript.net/snapshots/${{ inputs.snapshot_version }}/
|
||||
61
.github/workflows/publish-unstable.yml
vendored
Normal file
61
.github/workflows/publish-unstable.yml
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
name: "Publish Unstable"
|
||||
|
||||
on:
|
||||
push: # Only run on merges into main that modify files under pyscript.core/ and examples/
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- pyscript.core/**
|
||||
- examples/**
|
||||
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
publish-unstable:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
id-token: write
|
||||
contents: read
|
||||
defaults:
|
||||
run:
|
||||
working-directory: ./pyscript.core
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install node
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 18.x
|
||||
|
||||
- name: Cache node modules
|
||||
uses: actions/cache@v3
|
||||
env:
|
||||
cache-name: cache-node-modules
|
||||
with:
|
||||
# npm cache files are stored in `~/.npm` on Linux/macOS
|
||||
path: ~/.npm
|
||||
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-build-${{ env.cache-name }}-
|
||||
${{ runner.os }}-build-
|
||||
${{ runner.os }}-
|
||||
|
||||
- name: NPM Install
|
||||
run: npm install && npx playwright install
|
||||
|
||||
- name: Build
|
||||
run: npm run build
|
||||
|
||||
- name: Generate index.html in snapshot
|
||||
working-directory: .
|
||||
run: sed 's#_PATH_#https://pyscript.net/unstable/#' ./public/index.html > ./pyscript.core/dist/index.html
|
||||
|
||||
- name: Configure AWS credentials
|
||||
uses: aws-actions/configure-aws-credentials@v4
|
||||
with:
|
||||
aws-region: ${{ secrets.AWS_REGION }}
|
||||
role-to-assume: ${{ secrets.AWS_OIDC_RUNNER_ROLE }}
|
||||
|
||||
- name: Sync to S3
|
||||
run: aws s3 sync --quiet ./dist/ s3://pyscript.net/unstable/
|
||||
33
.github/workflows/sync-examples.yml
vendored
33
.github/workflows/sync-examples.yml
vendored
@@ -1,33 +0,0 @@
|
||||
name: '[CI] Sync Examples'
|
||||
|
||||
on:
|
||||
push: # Only run on merges into main that modify files under examples/
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- examples/**
|
||||
- .github/workflows/sync-examples.yml # Test that workflow works when changed
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
id-token: write
|
||||
defaults:
|
||||
run:
|
||||
working-directory: examples
|
||||
|
||||
steps:
|
||||
|
||||
# Deploy to S3
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: Configure AWS credentials
|
||||
uses: aws-actions/configure-aws-credentials@v1.6.1
|
||||
with:
|
||||
aws-region: ${{secrets.AWS_REGION}}
|
||||
role-to-assume: ${{ secrets.AWS_OIDC_RUNNER_ROLE }}
|
||||
- name: Sync to S3
|
||||
# Sync outdated or new files, delete ones no longer in source
|
||||
run: aws s3 sync --quiet --delete . s3://pyscript.net/examples/ # Sync directory, delete what is not in source
|
||||
92
.github/workflows/test.yml
vendored
Normal file
92
.github/workflows/test.yml
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
name: "[CI] Test"
|
||||
|
||||
on:
|
||||
push: # Only run on merges into main that modify certain files
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- pyscript.core/**
|
||||
- .github/workflows/test.yml
|
||||
|
||||
pull_request: # Only run on merges into main that modify certain files
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- pyscript.core/**
|
||||
- .github/workflows/test.yml
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
BuildAndTest:
|
||||
runs-on: ubuntu-latest-8core
|
||||
env:
|
||||
MINICONDA_PYTHON_VERSION: py38
|
||||
MINICONDA_VERSION: 4.11.0
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 3
|
||||
|
||||
# display a git log: when you run CI on PRs, github automatically
|
||||
# merges the PR into main and run the CI on that commit. The idea
|
||||
# here is to show enough of git log to understand what is the
|
||||
# actual commit (in the PR) that we are using. See also
|
||||
# 'fetch-depth: 3' above.
|
||||
- name: git log
|
||||
run: git log --graph -3
|
||||
|
||||
- name: Install node
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 20.x
|
||||
|
||||
- name: Cache node modules
|
||||
uses: actions/cache@v3
|
||||
env:
|
||||
cache-name: cache-node-modules
|
||||
with:
|
||||
# npm cache files are stored in `~/.npm` on Linux/macOS
|
||||
path: ~/.npm
|
||||
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-build-${{ env.cache-name }}-
|
||||
${{ runner.os }}-build-
|
||||
${{ runner.os }}-
|
||||
|
||||
- name: setup Miniconda
|
||||
uses: conda-incubator/setup-miniconda@v2
|
||||
|
||||
- name: Create and activate virtual environment
|
||||
run: |
|
||||
python3 -m venv test_venv
|
||||
source test_venv/bin/activate
|
||||
echo PATH=$PATH >> $GITHUB_ENV
|
||||
echo VIRTUAL_ENV=$VIRTUAL_ENV >> $GITHUB_ENV
|
||||
|
||||
- name: Setup dependencies in virtual environment
|
||||
run: |
|
||||
make setup
|
||||
|
||||
- name: Build
|
||||
run: make build
|
||||
|
||||
- name: Integration Tests
|
||||
#run: make test-integration-parallel
|
||||
run: |
|
||||
make test-integration
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: pyscript
|
||||
path: |
|
||||
pyscript.core/dist/
|
||||
if-no-files-found: error
|
||||
retention-days: 7
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
if: success() || failure()
|
||||
with:
|
||||
name: test_results
|
||||
path: test_results/
|
||||
if-no-files-found: error
|
||||
16
.github/workflows/test_report.yml
vendored
Normal file
16
.github/workflows/test_report.yml
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
name: Test Report
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ['\[CI\] Test']
|
||||
types:
|
||||
- completed
|
||||
jobs:
|
||||
report:
|
||||
runs-on: ubuntu-latest-8core
|
||||
steps:
|
||||
- uses: dorny/test-reporter@v1.6.0
|
||||
with:
|
||||
artifact: test_results
|
||||
name: Test reports
|
||||
path: "*.xml"
|
||||
reporter: java-junit
|
||||
15
.gitignore
vendored
15
.gitignore
vendored
@@ -51,7 +51,6 @@ coverage.xml
|
||||
*.py,cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
pyscriptjs/examples
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
@@ -136,3 +135,17 @@ dmypy.json
|
||||
.pyre/
|
||||
|
||||
node_modules/
|
||||
|
||||
coverage/
|
||||
|
||||
# junit xml for test results
|
||||
test_results
|
||||
|
||||
# @pyscript/core npm artifacts
|
||||
pyscript.core/core.*
|
||||
pyscript.core/dist
|
||||
pyscript.core/dist.zip
|
||||
pyscript.core/src/plugins.js
|
||||
pyscript.core/src/stdlib/pyscript.js
|
||||
pyscript.core/src/3rd-party/*
|
||||
!pyscript.core/src/3rd-party/READMEmd
|
||||
|
||||
@@ -1,89 +1,53 @@
|
||||
# This is the configuration for pre-commit, a local framework for managing pre-commit hooks
|
||||
# Check out the docs at: https://pre-commit.com/
|
||||
ci:
|
||||
#skip: [eslint]
|
||||
autoupdate_schedule: monthly
|
||||
|
||||
default_stages: [commit]
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.3.0
|
||||
rev: v4.4.0
|
||||
hooks:
|
||||
- id: check-builtin-literals
|
||||
- id: check-case-conflict
|
||||
- id: check-docstring-first
|
||||
- id: check-executables-have-shebangs
|
||||
- id: check-json
|
||||
exclude: tsconfig.json
|
||||
exclude: tsconfig\.json
|
||||
- id: check-toml
|
||||
exclude: bad\.toml
|
||||
- id: check-xml
|
||||
- id: check-yaml
|
||||
- id: detect-private-key
|
||||
- id: end-of-file-fixer
|
||||
exclude: \.min\.js$
|
||||
exclude: pyscript\.core/dist|\.min\.js$
|
||||
- id: trailing-whitespace
|
||||
|
||||
- repo: https://github.com/PyCQA/bandit
|
||||
rev: 1.7.4
|
||||
hooks:
|
||||
- id: bandit
|
||||
args:
|
||||
- --skip=B201
|
||||
|
||||
- repo: https://github.com/psf/black
|
||||
rev: 22.3.0
|
||||
rev: 23.1.0
|
||||
hooks:
|
||||
- id: black
|
||||
exclude: pyscript\.core/src/stdlib/pyscript/__init__\.py
|
||||
|
||||
- repo: https://github.com/codespell-project/codespell
|
||||
rev: v2.1.0
|
||||
rev: v2.2.4
|
||||
hooks:
|
||||
- id: codespell # See 'setup.cfg' for args
|
||||
- id: codespell # See 'pyproject.toml' for args
|
||||
exclude: \.js\.map$
|
||||
additional_dependencies:
|
||||
- tomli
|
||||
|
||||
- repo: https://github.com/PyCQA/flake8
|
||||
rev: 4.0.1
|
||||
- repo: https://github.com/hoodmane/pyscript-prettier-precommit
|
||||
rev: "v3.0.0-alpha.6"
|
||||
hooks:
|
||||
- id: flake8 # See 'setup.cfg' for args
|
||||
additional_dependencies: [flake8-bugbear, flake8-comprehensions]
|
||||
- id: prettier
|
||||
exclude: pyscript\.core/test|pyscript\.core/dist|pyscript\.core/types|pyscript.core/src/stdlib/pyscript.js|pyscript\.sw/|pyscript.core/src/3rd-party
|
||||
args: [--tab-width, "4"]
|
||||
|
||||
- repo: https://github.com/pycqa/isort
|
||||
rev: 5.10.1
|
||||
rev: 5.12.0
|
||||
hooks:
|
||||
- id: isort
|
||||
name: isort (python)
|
||||
args: [--profile, black]
|
||||
|
||||
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
|
||||
rev: v2.3.0
|
||||
hooks:
|
||||
- id: pretty-format-yaml
|
||||
args: [--autofix, --indent, '4']
|
||||
exclude: .github/ISSUE_TEMPLATE/.*\.yml$
|
||||
|
||||
- repo: https://github.com/asottile/pyupgrade
|
||||
rev: v2.34.0
|
||||
hooks:
|
||||
- id: pyupgrade
|
||||
args:
|
||||
- --py310-plus
|
||||
|
||||
- repo: https://github.com/pre-commit/mirrors-eslint
|
||||
rev: v8.18.0
|
||||
hooks:
|
||||
- id: eslint
|
||||
files: pyscriptjs/src/.*\.[jt]sx?$ # *.js, *.jsx, *.ts and *.tsx
|
||||
types: [file]
|
||||
additional_dependencies:
|
||||
- eslint
|
||||
- eslint-plugin-svelte3
|
||||
- typescript
|
||||
- '@typescript-eslint/eslint-plugin'
|
||||
- '@typescript-eslint/parser'
|
||||
|
||||
# Commented out until mdformat-myst supports custom extensions
|
||||
# See https://github.com/executablebooks/mdformat-myst/pull/9
|
||||
# - repo: https://github.com/executablebooks/mdformat
|
||||
# rev: 0.7.14 # Use the ref you want to point at
|
||||
# hooks:
|
||||
# - id: mdformat
|
||||
# additional_dependencies:
|
||||
# - mdformat-gfm
|
||||
# - mdformat-myst
|
||||
# - mdformat-black
|
||||
|
||||
5
.prettierignore
Normal file
5
.prettierignore
Normal file
@@ -0,0 +1,5 @@
|
||||
ISSUE_TEMPLATE
|
||||
*.min.*
|
||||
package-lock.json
|
||||
docs
|
||||
examples/panel.html
|
||||
87
CHANGELOG.md
Normal file
87
CHANGELOG.md
Normal file
@@ -0,0 +1,87 @@
|
||||
# Release Notes
|
||||
|
||||
## 2023.05.01
|
||||
|
||||
### Features
|
||||
|
||||
- Added the `xterm` attribute to `py-config`. When set to `True` or `xterm`, an (output-only) [xterm.js](http://xtermjs.org/) terminal will be used in place of the default py-terminal.
|
||||
- The default version of Pyodide is now `0.23.2`. See the [Pyodide Changelog](https://pyodide.org/en/stable/project/changelog.html#version-0-23-2) for a detailed list of changes.
|
||||
- Added the `@when` decorator for attaching Python functions as event handlers
|
||||
- The `py-mount` attribute on HTML elements has been deprecated, and will be removed in a future release.
|
||||
|
||||
#### Runtime py- attributes
|
||||
|
||||
- Added logic to react to `py-*` attributes changes, removal, `py-*` attributes added to already live nodes but also `py-*` attributes added or defined via injected nodes (either appended or via `innerHTML` operations). ([#1435](https://github.com/pyscript/pyscript/pull/1435))
|
||||
|
||||
#### <script type="py">
|
||||
|
||||
- Added the ability to optionally use `<script type="py">`, `<script type="pyscript">` or `<script type="py-script">` instead of a `<py-script>` custom element, in order to tackle cases where the content of the `<py-script>` tag, inevitably parsed by browsers, could accidentally contain _HTML_ able to break the surrounding page layout. ([#1396](https://github.com/pyscript/pyscript/pull/1396))
|
||||
|
||||
#### <py-terminal>
|
||||
|
||||
- Added a `docked` field and attribute for the `<py-terminal>` custom element, enabled by default when the terminal is in `auto` mode, and able to dock the terminal at the bottom of the page with auto scroll on new code execution.
|
||||
|
||||
#### <py-script>
|
||||
|
||||
- Restored the `output` attribute of `py-script` tags to route `sys.stdout` to a DOM element with the given ID. ([#1063](https://github.com/pyscript/pyscript/pull/1063))
|
||||
- Added a `stderr` attribute of `py-script` tags to route `sys.stderr` to a DOM element with the given ID. ([#1063](https://github.com/pyscript/pyscript/pull/1063))
|
||||
|
||||
#### <py-repl>
|
||||
|
||||
- The `output` attribute of `py-repl` tags now specifies the id of the DOM element that `sys.stdout`, `sys.stderr`, and the results of a REPL execution are written to. It no longer affects the location of calls to `display()`
|
||||
- Added a `stderr` attribute of `py-repl` tags to route `sys.stderr` to a DOM element with the given ID. ([#1106](https://github.com/pyscript/pyscript/pull/1106))
|
||||
- Resored the `output-mode` attribute of `py-repl` tags. If `output-mode` == 'append', the DOM element where output is printed is _not_ cleared before writing new results.
|
||||
- Load code from the attribute src of py-repl and preload it into the corresponding py-repl tag by use the attribute `str` in your `py-repl` tag([#1292](https://github.com/pyscript/pyscript/pull/1292))
|
||||
- <py-repl> elements now have a `getPySrc()` method, which returns the code inside the REPL as a string.([#1516](https://github.com/pyscript/pyscript/pull/1292))
|
||||
|
||||
#### Plugins
|
||||
|
||||
- Plugins may now implement the `beforePyReplExec()` and `afterPyReplExec()` hooks, which are called immediately before and after code in a `py-repl` tag is executed. ([#1106](https://github.com/pyscript/pyscript/pull/1106))
|
||||
|
||||
#### Web worker support
|
||||
|
||||
- introduced the new experimental `execution_thread` config option: if you set `execution_thread = "worker"`, the python interpreter runs inside a web worker
|
||||
- worker support is still **very** experimental: not everything works, use it at your own risk
|
||||
|
||||
### Bug fixes
|
||||
|
||||
- Fixes [#1280](https://github.com/pyscript/pyscript/issues/1280), which describes the errors on the PyRepl tests related to having auto-gen tags that shouldn't be there.
|
||||
|
||||
### Enhancements
|
||||
|
||||
- Py-REPL tests now run on both osx and non osx OSs
|
||||
- migrated from _rollup_ to _esbuild_ to create artifacts
|
||||
- updated `@codemirror` dependency to its latest
|
||||
|
||||
### Docs
|
||||
|
||||
- Add docs for event handlers
|
||||
|
||||
## 2023.03.1
|
||||
|
||||
### Features
|
||||
|
||||
### Bug fixes
|
||||
|
||||
- Fixed an issue where `pyscript` would not be available when using the minified version of PyScript. ([#1054](https://github.com/pyscript/pyscript/pull/1054))
|
||||
- Fixed missing closing tag when rendering an image with `display`. ([#1058](https://github.com/pyscript/pyscript/pull/1058))
|
||||
- Fixed a bug where Python plugins methods were being executed twice. ([#1064](https://github.com/pyscript/pyscript/pull/1064))
|
||||
|
||||
### Enhancements
|
||||
|
||||
- When adding a `py-` attribute to an element but didn't added an `id` attribute, PyScript will now generate a random ID for the element instead of throwing an error which caused the splash screen to not shutdown. ([#1122](https://github.com/pyscript/pyscript/pull/1122))
|
||||
- You can now disable the splashscreen by setting `enabled = false` in your `py-config` under the `[splashscreen]` configuration section. ([#1138](https://github.com/pyscript/pyscript/pull/1138))
|
||||
|
||||
### Documentation
|
||||
|
||||
- Fixed 'Direct usage of document is deprecated' warning in the getting started guide. ([#1052](https://github.com/pyscript/pyscript/pull/1052))
|
||||
- Added reference documentation for the `py-splashscreen` plugin ([#1138](https://github.com/pyscript/pyscript/pull/1138))
|
||||
- Adds doc for installing tests ([#1156](https://github.com/pyscript/pyscript/pull/1156))
|
||||
- Adds docs for custom Pyscript attributes (`py-*`) that allow you to add event listeners to an element ([#1125](https://github.com/pyscript/pyscript/pull/1125))
|
||||
|
||||
### Deprecations and Removals
|
||||
|
||||
- The py-config `runtimes` to specify an interpreter has been deprecated. The `interpreters` config should be used instead. ([#1082](https://github.com/pyscript/pyscript/pull/1082))
|
||||
- The attributes `pys-onClick` and `pys-onKeyDown` have been deprecated, but the warning was only shown in the console. An alert banner will now be shown on the page if the attributes are used. They will be removed in the next release. ([#1084](https://github.com/pyscript/pyscript/pull/1084))
|
||||
- The pyscript elements `py-button`, `py-inputbox`, `py-box` and `py-title` have now completed their deprecation cycle and have been removed. ([#1084](https://github.com/pyscript/pyscript/pull/1084))
|
||||
- The attributes `pys-onClick` and `pys-onKeyDown` have been removed. Use `py-click` and `py-keydown` instead ([#1361](https://github.com/pyscript/pyscript/pull/1361))
|
||||
@@ -4,87 +4,69 @@ Thank you for wanting to contribute to the PyScript project!
|
||||
|
||||
## Table of contents
|
||||
|
||||
* [Code of Conduct](#code-of-conduct)
|
||||
* [Contributing](#contributing)
|
||||
* [Reporting bugs](#reporting-bugs)
|
||||
* [Reporting security issues](#reporting-security-issues)
|
||||
* [Asking questions](#asking-questions)
|
||||
* [Setting up your environment](#setting-up-your-environment)
|
||||
* [Places to start](#places-to-start)
|
||||
* [Submitting a change](#submitting-a-change)
|
||||
* [License terms for contributions](#license-terms-for-contributions)
|
||||
* [Becoming a maintainer](#becoming-a-maintainer)
|
||||
* [Trademarks](#trademarks)
|
||||
- [Contributing to PyScript](#contributing-to-pyscript)
|
||||
- [Table of contents](#table-of-contents)
|
||||
- [Code of Conduct](#code-of-conduct)
|
||||
- [Contributing](#contributing)
|
||||
- [Reporting bugs](#reporting-bugs)
|
||||
- [Creating useful issues](#creating-useful-issues)
|
||||
- [Reporting security issues](#reporting-security-issues)
|
||||
- [Asking questions](#asking-questions)
|
||||
- [Setting up your local environment and developing](#setting-up-your-local-environment-and-developing)
|
||||
- [Developing](#developing)
|
||||
- [Rebasing changes](#rebasing-changes)
|
||||
- [Building the docs](#building-the-docs)
|
||||
- [Places to start](#places-to-start)
|
||||
- [Setting up your local environment and developing](#setting-up-your-local-environment-and-developing)
|
||||
- [Submitting a change](#submitting-a-change)
|
||||
- [License terms for contributions](#license-terms-for-contributions)
|
||||
- [Becoming a maintainer](#becoming-a-maintainer)
|
||||
- [Trademarks](#trademarks)
|
||||
|
||||
## Code of Conduct
|
||||
# Code of Conduct
|
||||
|
||||
The [PyScript Code of Conduct](https://github.com/pyscript/governance/blob/main/CODE-OF-CONDUCT.md) governs the project and everyone participating in it. By participating, you are expected to uphold this code. Please report unacceptable behavior to the maintainers or administrators as described in that document.
|
||||
|
||||
## Contributing
|
||||
# Contributing
|
||||
|
||||
### Reporting bugs
|
||||
## Reporting bugs
|
||||
|
||||
Bugs are tracked on the [project issues page](https://github.com/pyscript/pyscript/issues). Please check if your issue has already been filed by someone else by searching the existing issues before filing a new one. Once your issue is filed, it will be triaged by another contributor or maintainer. If there are questions raised about your issue, please respond promptly.
|
||||
|
||||
#### Creating useful issues
|
||||
## Creating useful issues
|
||||
|
||||
* Use a clear and descriptive title.
|
||||
* Describe the specific steps that reproduce the problem with as many details as possible so that someone can verify the issue.
|
||||
* Describe the behavior you observed, and the behavior you had expected.
|
||||
* Include screenshots if they help make the issue clear.
|
||||
- Use a clear and descriptive title.
|
||||
- Describe the specific steps that reproduce the problem with as many details as possible so that someone can verify the issue.
|
||||
- Describe the behavior you observed, and the behavior you had expected.
|
||||
- Include screenshots if they help make the issue clear.
|
||||
|
||||
### Reporting security issues
|
||||
## Reporting security issues
|
||||
|
||||
If you aren't confident that it is appropriate to submit a security issue using the above process, you can e-mail it to security@pyscript.net
|
||||
|
||||
### Asking questions
|
||||
## Asking questions
|
||||
|
||||
If you have questions about the project, using PyScript, or anything else, please ask in the [PyScript forum](https://community.anaconda.cloud/c/tech-topics/pyscript).
|
||||
|
||||
### Setting up your environment
|
||||
## Places to start
|
||||
|
||||
* clone the repo
|
||||
```
|
||||
git clone https://github.com/pyscript/pyscript
|
||||
```
|
||||
* cd into the main project folder
|
||||
```
|
||||
cd pyscript/pyscriptjs
|
||||
```
|
||||
* install the dependencies with npm install - make sure to use nodejs version >= 16
|
||||
```
|
||||
npm install
|
||||
```
|
||||
* run npm run dev to build and run the dev server. This will also watch for changes and rebuild when a file is saved.
|
||||
```
|
||||
npm run dev
|
||||
```
|
||||
If you would like to contribute to PyScript, but you aren't sure where to begin, here are some suggestions:
|
||||
|
||||
### Places to start
|
||||
- **Read over the existing documentation.** Are there things missing, or could they be clearer? Make some changes/additions to those documents.
|
||||
- **Review the open issues.** Are they clear? Can you reproduce them? You can add comments, clarifications, or additions to those issues. If you think you have an idea of how to address the issue, submit a fix!
|
||||
- **Look over the open pull requests.** Do you have comments or suggestions for the proposed changes? Add them.
|
||||
- **Check out the examples.** Is there a use case that would be good to have sample code for? Create an example for it.
|
||||
|
||||
If you would like to contribute to PyScript, but you aren't sure where to begin, here are some suggestions.
|
||||
## Setting up your local environment and developing
|
||||
|
||||
* **Read over the existing documentation.** Are there things missing, or could they be clearer? Make some changes/additions to those documents.
|
||||
* **Review the open issues.** Are they clear? Can you reproduce them? You can add comments, clarifications, or additions to those issues. If you think you have an idea of how to address the issue, submit a fix!
|
||||
* **Look over the open pull requests.** Do you have comments or suggestions for the proposed changes? Add them.
|
||||
* **Check out the examples.** Is there a use case that would be good to have sample code for? Create an example for it.
|
||||
If you would like to contribute to PyScript, you will need to set up a local development environment. The [following instructions](https://docs.pyscript.net/latest/development/setting-up-environment.html) will help you get started.
|
||||
|
||||
### Submitting a change
|
||||
|
||||
All contributions must be licensed Apache 2.0, and all files must have a copy of the boilerplate license comment (can be copied from an existing file).
|
||||
|
||||
To create a change for PyScript, you can follow the process described [here](https://docs.github.com/en/get-started/quickstart/contributing-to-projects).
|
||||
|
||||
* Fork a personal copy of the PyScript project.
|
||||
* Make the changes you would like (don't forget to test them!)
|
||||
* Please squash all commits for a change into a single commit (this can be done using "git rebase -i"). Do your best to have a well-formed commit message for the change.
|
||||
* Open a pull request back to the PyScript project and address any comments/questions from the maintainers and other contributors.
|
||||
You can also read about PyScript's [development process](https://docs.pyscript.net/latest/development/developing.html) to learn how to contribute code to PyScript, how to run tests and what's the PR etiquette of the community!
|
||||
|
||||
## License terms for contributions
|
||||
|
||||
This Project welcomes contributions, suggestions, and feedback. All contributions, suggestions, and feedback you submitted are accepted under the [Apache 2.0](./LICENSE) license. You represent that if you do not own copyright in the code that you have the authority to submit it under the [Apache 2.0](./LICENSE) license. All feedback, suggestions, or contributions are not confidential.
|
||||
|
||||
|
||||
## Becoming a maintainer
|
||||
|
||||
Contributors are invited to be maintainers of the project by demonstrating good decision making in their contributions, a commitment to the goals of the project, and consistent adherence to the [code of conduct](https://github.com/pyscript/governance/blob/main/CODE-OF-CONDUCT.md). New maintainers are invited by a 3/4 vote of the existing maintainers.
|
||||
@@ -94,5 +76,6 @@ Contributors are invited to be maintainers of the project by demonstrating good
|
||||
The Project abides by the Organization's [trademark policy](https://github.com/pyscript/governance/blob/main/TRADEMARKS.md).
|
||||
|
||||
---
|
||||
|
||||
Part of MVG-0.1-beta.
|
||||
Made with love by GitHub. Licensed under the [CC-BY 4.0 License](https://creativecommons.org/licenses/by-sa/4.0/).
|
||||
|
||||
@@ -41,5 +41,6 @@ Any names, trademarks, logos, or goodwill developed by and associated with the P
|
||||
Amendments to this governance policy may be made by affirmative vote of 2/3 of all Maintainers, with approval by the Organization's Steering Committee.
|
||||
|
||||
---
|
||||
|
||||
Part of MVG-0.1-beta.
|
||||
Made with love by GitHub. Licensed under the [CC-BY 4.0 License](https://creativecommons.org/licenses/by-sa/4.0/).
|
||||
|
||||
@@ -3,16 +3,22 @@
|
||||
This document lists the Maintainers of the Project. Maintainers may be added once approved by the existing maintainers as described in the [Governance document](https://github.com/pyscript/pyscript/blob/main/GOVERNANCE.md). By adding your name to this list you are agreeing to abide by the Project governance documents and to abide by all of the Organization's polices, including the [code of conduct](https://github.com/pyscript/governance/blob/main/CODE-OF-CONDUCT.md), [trademark policy](https://github.com/pyscript/governance/blob/main/TRADEMARKS.md), and [antitrust policy](https://github.com/pyscript/governance/blob/main/TRADEMARKS.md). If you are participating because of your affiliation with another organization (designated below), you represent that you have the authority to bind that organization to these policies.
|
||||
|
||||
| **NAME** | **Organization** |
|
||||
| ---------------- | ---------------- |
|
||||
| -------------------- | ---------------- |
|
||||
| Fabio Pliger | Anaconda, Inc |
|
||||
| Antonio Cuni | Anaconda, Inc |
|
||||
| Philipp Rudiger | Anaconda, Inc |
|
||||
| Peter Wang | Anaconda, Inc |
|
||||
| Kevin Goldsmith | Anaconda, Inc |
|
||||
| Mariana Meireles | Anaconda, Inc |
|
||||
| --- | --- |
|
||||
| Mariana Meireles | |
|
||||
| Nicholas H.Tollervey | Anaconda, Inc |
|
||||
| Madhur Tandon | Anaconda, Inc |
|
||||
| Ted Patrick | Anaconda, Inc |
|
||||
| Jeff Glass | |
|
||||
| Paul Everitt | |
|
||||
| Fabio Rosado | Anaconda, Inc |
|
||||
| Andrea Giammarchi | Anaconda, Inc |
|
||||
|
||||
______________________________________________________________________
|
||||
---
|
||||
|
||||
Part of MVG-0.1-beta.
|
||||
Made with love by GitHub. Licensed under the [CC-BY 4.0 License](https://creativecommons.org/licenses/by-sa/4.0/).
|
||||
|
||||
92
Makefile
Normal file
92
Makefile
Normal file
@@ -0,0 +1,92 @@
|
||||
MIN_NODE_VER := 20
|
||||
MIN_NPM_VER := 6
|
||||
MIN_PY3_VER := 8
|
||||
NODE_VER := $(shell node -v | cut -d. -f1 | sed 's/^v\(.*\)/\1/')
|
||||
NPM_VER := $(shell npm -v | cut -d. -f1)
|
||||
PY3_VER := $(shell python3 -c "import sys;t='{v[1]}'.format(v=list(sys.version_info[:2]));print(t)")
|
||||
PY_OK := $(shell python3 -c "print(int($(PY3_VER) >= $(MIN_PY3_VER)))")
|
||||
|
||||
all:
|
||||
@echo "\nThere is no default Makefile target right now. Try:\n"
|
||||
@echo "make setup - check your environment and install the dependencies."
|
||||
@echo "make clean - clean up auto-generated assets."
|
||||
@echo "make build - build PyScript."
|
||||
@echo "make precommit-check - run the precommit checks (run eslint)."
|
||||
@echo "make test-integration - run all integration tests sequentially."
|
||||
@echo "make fmt - format the code."
|
||||
@echo "make fmt-check - check the code formatting.\n"
|
||||
|
||||
.PHONY: check-node
|
||||
check-node:
|
||||
@if [ $(NODE_VER) -lt $(MIN_NODE_VER) ]; then \
|
||||
echo "\033[0;31mBuild requires Node $(MIN_NODE_VER).x or higher: $(NODE_VER) detected.\033[0m"; \
|
||||
false; \
|
||||
fi
|
||||
|
||||
.PHONY: check-npm
|
||||
check-npm:
|
||||
@if [ $(NPM_VER) -lt $(MIN_NPM_VER) ]; then \
|
||||
echo "\033[0;31mBuild requires Node $(MIN_NPM_VER).x or higher: $(NPM_VER) detected.\033[0m"; \
|
||||
false; \
|
||||
fi
|
||||
|
||||
.PHONY: check-python
|
||||
check-python:
|
||||
@if [ $(PY_OK) -eq 0 ]; then \
|
||||
echo "\033[0;31mRequires Python 3.$(MIN_PY3_VER).x or higher: 3.$(PY3_VER) detected.\033[0m"; \
|
||||
false; \
|
||||
fi
|
||||
|
||||
# Check the environment, install the dependencies.
|
||||
setup: check-node check-npm check-python
|
||||
cd pyscript.core && npm install && cd ..
|
||||
ifeq ($(VIRTUAL_ENV),)
|
||||
echo "\n\n\033[0;31mCannot install Python dependencies. Your virtualenv is not activated.\033[0m"
|
||||
false
|
||||
else
|
||||
python -m pip install -r requirements.txt
|
||||
playwright install
|
||||
endif
|
||||
|
||||
# Clean up generated assets.
|
||||
clean:
|
||||
find . -name \*.py[cod] -delete
|
||||
rm -rf $(env) *.egg-info
|
||||
rm -rf .pytest_cache .coverage coverage.xml
|
||||
|
||||
# Build PyScript.
|
||||
build:
|
||||
cd pyscript.core && npx playwright install && npm run build
|
||||
|
||||
# Run the precommit checks (run eslint).
|
||||
precommit-check:
|
||||
pre-commit run --all-files
|
||||
|
||||
# Run all integration tests sequentially.
|
||||
test-integration:
|
||||
mkdir -p test_results
|
||||
pytest -vv $(ARGS) pyscript.core/tests/integration/ --log-cli-level=warning --junitxml=test_results/integration.xml
|
||||
|
||||
# Run all integration tests in parallel.
|
||||
test-integration-parallel:
|
||||
mkdir -p test_results
|
||||
pytest --numprocesses auto -vv $(ARGS) pyscript.core/tests/integration/ --log-cli-level=warning --junitxml=test_results/integration.xml
|
||||
|
||||
# Format the code.
|
||||
fmt: fmt-py
|
||||
@echo "Format completed"
|
||||
|
||||
# Check the code formatting.
|
||||
fmt-check: fmt-py-check
|
||||
@echo "Format check completed"
|
||||
|
||||
# Format Python code.
|
||||
fmt-py:
|
||||
black -l 88 --skip-string-normalization .
|
||||
isort --profile black .
|
||||
|
||||
# Check the format of Python code.
|
||||
fmt-py-check:
|
||||
black -l 88 --check .
|
||||
|
||||
.PHONY: $(MAKECMDGOALS)
|
||||
63
README.md
63
README.md
@@ -4,43 +4,80 @@
|
||||
|
||||
### Summary
|
||||
|
||||
PyScript is a Pythonic alternative to Scratch, JSFiddle, and other "easy to use" programming frameworks, with the goal of making the web a friendly, hackable place where anyone can author interesting and interactive applications.
|
||||
PyScript is a framework that allows users to create rich Python applications in the browser using HTML's interface and the power of [Pyodide](https://pyodide.org/en/stable/), [MicroPython](https://micropython.org/) and [WASM](https://webassembly.org/), and modern web technologies.
|
||||
|
||||
To get started see the [getting started tutorial](docs/tutorials/getting-started.md).
|
||||
|
||||
For examples see [here](examples).
|
||||
|
||||
### Longer Version
|
||||
|
||||
PyScript is a meta project that aims to combine multiple open technologies into a framework that allows users to create sophisticated browser applications with Python. It integrates seamlessly with the way the DOM works in the browser and allows users to add Python logic in a way that feels natural both to web and Python developers.
|
||||
|
||||
## Try PyScript
|
||||
|
||||
To try PyScript, import the appropriate pyscript files to your html page with:
|
||||
To try PyScript, import the appropriate pyscript files into the `<head>` tag of your html page:
|
||||
|
||||
```html
|
||||
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
|
||||
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
|
||||
<head>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://pyscript.net/releases/2023.11.1/core.css"
|
||||
/>
|
||||
<script
|
||||
type="module"
|
||||
src="https://pyscript.net/releases/2023.11.1/core.js"
|
||||
></script>
|
||||
</head>
|
||||
<body>
|
||||
<script type="py" terminal>
|
||||
from pyscript import display
|
||||
display("Hello World!") # this goes to the DOM
|
||||
print("Hello terminal") # this goes to the terminal
|
||||
</script>
|
||||
</body>
|
||||
```
|
||||
You can then use PyScript components in your html page. PyScript currently implements the following elements:
|
||||
|
||||
* `<py-script>`: can be used to define python code that is executable within the web page. The element itself is not rendered to the page and is only used to add logic
|
||||
* `<py-repl>`: creates a REPL component that is rendered to the page as a code editor and allows users to write executable code
|
||||
You can then use PyScript components in your html page. PyScript currently offers various ways of running Python code:
|
||||
|
||||
Check out the [the examples directory](examples) folder for more examples on how to use it, all you need to do is open them in Chrome.
|
||||
- `<script type="py">`: can be used to define python code that is executable within the web page.
|
||||
- `<script type="py" src="hello.py">`: same as above, but the python source is fetched from the given URL.
|
||||
- `<script type="py" terminal>`: same as above, but also creates a terminal where to display stdout and stderr (e.g., the output of `print()`); `input()` does not work.
|
||||
- `<script type="py" terminal worker>`: run Python inside a web worker: the terminal is fully functional and `input()` works.
|
||||
- `<py-script>`: same as `<script type="py">`, but it is not recommended because if the code contains HTML tags, they could be parsed wrongly.
|
||||
- `<script type="mpy">`: same as above but use MicroPython instead of Python.
|
||||
|
||||
Check out the [official docs](https://docs.pyscript.net) for more detailed documentation.
|
||||
|
||||
## How to Contribute
|
||||
|
||||
Read the [contributing guide](CONTRIBUTING.md) to learn about our development process, reporting bugs and improvements, creating issues and asking questions.
|
||||
|
||||
Check out the [developing process](https://docs.pyscript.net/latest/contributing) documentation for more information on how to setup your development environment.
|
||||
|
||||
## Community calls and events
|
||||
|
||||
Every Tuesday at 15:30 UTC there is the _PyScript Community Call_ on zoom, where we can talk about PyScript development in the open. Most of the maintainers regularly participate in the call, and everybody is welcome to join.
|
||||
|
||||
Every other Thursday at 16:00 UTC there is the _PyScript FUN_ call: this is a call in which everybody is encouraged to show what they did with PyScript.
|
||||
|
||||
For more details on how to join the calls and up to date schedule, consult the official calendar:
|
||||
|
||||
- [Google calendar](https://calendar.google.com/calendar/u/0/embed?src=d3afdd81f9c132a8c8f3290f5cc5966adebdf61017fca784eef0f6be9fd519e0@group.calendar.google.com&ctz=UTC) in UTC time;
|
||||
- [iCal format](https://calendar.google.com/calendar/ical/d3afdd81f9c132a8c8f3290f5cc5966adebdf61017fca784eef0f6be9fd519e0%40group.calendar.google.com/public/basic.ics).
|
||||
|
||||
## Resources
|
||||
|
||||
* [Discussion board](https://community.anaconda.cloud/c/tech-topics/pyscript)
|
||||
* [Home Page](https://pyscript.net/)
|
||||
* [Blog Post](https://engineering.anaconda.com/2022/04/welcome-pyscript.html)
|
||||
- [Official docs](https://docs.pyscript.net)
|
||||
- [Discussion board](https://community.anaconda.cloud/c/tech-topics/pyscript)
|
||||
- [Home Page](https://pyscript.net/)
|
||||
- [Blog Post](https://engineering.anaconda.com/2022/04/welcome-pyscript.html)
|
||||
- [Discord Channel](https://discord.gg/BYB2kvyFwm)
|
||||
|
||||
## Notes
|
||||
|
||||
* This is an extremely experimental project, so expect things to break!
|
||||
* PyScript has been only tested on Chrome at the moment.
|
||||
- This is an extremely experimental project, so expect things to break!
|
||||
- PyScript has been only tested on Chrome at the moment.
|
||||
|
||||
## Governance
|
||||
|
||||
|
||||
19
TROUBLESHOOTING.md
Normal file
19
TROUBLESHOOTING.md
Normal file
@@ -0,0 +1,19 @@
|
||||
# Troubleshooting
|
||||
|
||||
This page is meant for troubleshooting common problems with PyScript.
|
||||
|
||||
## Table of contents:
|
||||
|
||||
- [Make Setup](#make-setup)
|
||||
|
||||
## Make setup
|
||||
|
||||
A lot of problems related to `make setup` are related to node and npm being outdated. Once npm and node are updated, `make setup` should work. You can follow the steps on the [npm documentation](https://docs.npmjs.com/try-the-latest-stable-version-of-npm) to update npm (the update command for Linux should work for Mac as well). Once npm has been updated you can continue to the instructions to update node below.
|
||||
|
||||
To update Node run the following commands in order (Most likely you'll be prompted for your user password, this is normal):
|
||||
|
||||
```
|
||||
sudo npm cache clean -f
|
||||
sudo npm install -g n
|
||||
sudo n stable
|
||||
```
|
||||
@@ -1,45 +0,0 @@
|
||||
# Minimal makefile for Sphinx documentation
|
||||
#
|
||||
|
||||
# You can set these variables from the command line, and also
|
||||
# from the environment for the first two.
|
||||
SPHINXOPTS ?=
|
||||
SPHINXBUILD ?= sphinx-build
|
||||
SOURCEDIR = .
|
||||
BUILDDIR = _build
|
||||
CONDA_ENV ?= _env
|
||||
|
||||
# Put it first so that "make" without argument is like "make help".
|
||||
help:
|
||||
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
||||
|
||||
env := $(CONDA_ENV)
|
||||
conda_run := conda run -p $(env)
|
||||
|
||||
setup:
|
||||
@if [ -z "$${CONDA_SHLVL:+x}" ]; then echo "Conda is not installed." && exit 1; fi
|
||||
$(CONDA_EXE) env $(shell [ -d $(env) ] && echo update || echo create) -p $(env) --file environment.yml
|
||||
|
||||
clean:
|
||||
rm -rf $(BUILDDIR)
|
||||
|
||||
clean-all: clean
|
||||
rm -rf $(env) *.egg-info
|
||||
|
||||
shell:
|
||||
@export CONDA_ENV_PROMPT='<{name}>'
|
||||
@echo 'conda activate $(env)'
|
||||
|
||||
htmlserve:
|
||||
python -m http.server -d "$(BUILDDIR)/html/"
|
||||
|
||||
livehtml:
|
||||
sphinx-autobuild "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
||||
|
||||
|
||||
.PHONY: help Makefile setup clean clean-all shell
|
||||
|
||||
# Catch-all target: route all unknown targets to Sphinx using the new
|
||||
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
||||
%: Makefile
|
||||
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
||||
@@ -1,17 +0,0 @@
|
||||
# PyScript documentation
|
||||
|
||||
Welcome to the PyScript documentation directory, where you can find
|
||||
and contribute to discussions around PyScript and related topics.
|
||||
|
||||
## Getting started
|
||||
|
||||
Before you start contributing to the documentation, it's worthwhile to
|
||||
take a look at the general contributing guidelines for the PyScript project. You can find these guidelines here
|
||||
[Contributing Guidelines](https://github.com/pyscript/pyscript/blob/main/CONTRIBUTING.md)
|
||||
|
||||
### Setup
|
||||
|
||||
The `docs` directory in the pyscript repository contains a
|
||||
[Sphinx](https://www.sphinx-doc.org/) documentation project. Sphinx is a system
|
||||
that takes plaintext files containing documentation written in Markdown, along with
|
||||
and static files like templates and themes, to build the static end result.
|
||||
44
docs/_static/examples/what-is-pyscript.html
vendored
44
docs/_static/examples/what-is-pyscript.html
vendored
@@ -1,44 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
|
||||
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
|
||||
<style>
|
||||
.pulse {
|
||||
animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0%, 100% {
|
||||
opacity: 1;
|
||||
}
|
||||
50% {
|
||||
opacity: .2;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<py-env>
|
||||
- numpy
|
||||
- matplotlib
|
||||
</py-env>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Let's plot random numbers</h1>
|
||||
<div id="plot">
|
||||
<div class="pulse" >
|
||||
<p style='font-family: monospace sans-serif;'><big><big><big><big>❰py❱</big></big></big></big></p>
|
||||
</div>
|
||||
</div>
|
||||
<py-script>
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
x = np.random.randn(1000)
|
||||
y = np.random.randn(1000)
|
||||
|
||||
fig, ax = plt.subplots()
|
||||
ax.scatter(x, y)
|
||||
pyscript.write('plot', fig)
|
||||
</py-script>
|
||||
</body>
|
||||
</html>
|
||||
BIN
docs/_static/fonts/Hack-Bold.woff
vendored
BIN
docs/_static/fonts/Hack-Bold.woff
vendored
Binary file not shown.
BIN
docs/_static/fonts/Hack-BoldItalic.woff
vendored
BIN
docs/_static/fonts/Hack-BoldItalic.woff
vendored
Binary file not shown.
BIN
docs/_static/fonts/Hack-Italic.woff
vendored
BIN
docs/_static/fonts/Hack-Italic.woff
vendored
Binary file not shown.
BIN
docs/_static/fonts/Hack-Regular.woff
vendored
BIN
docs/_static/fonts/Hack-Regular.woff
vendored
Binary file not shown.
BIN
docs/_static/images/avatar.jpg
vendored
BIN
docs/_static/images/avatar.jpg
vendored
Binary file not shown.
|
Before Width: | Height: | Size: 11 KiB |
1
docs/_static/redirect.html
vendored
1
docs/_static/redirect.html
vendored
@@ -1 +0,0 @@
|
||||
<html><head><meta http-equiv="refresh" content="0; URL='/latest/'" /></head><body></body></html>
|
||||
@@ -1 +0,0 @@
|
||||
../../../MAINTAINERS.md
|
||||
@@ -1 +0,0 @@
|
||||
../../../GOVERNANCE.md
|
||||
@@ -1,12 +0,0 @@
|
||||
# Concepts
|
||||
|
||||
This section contains various topics that are higher-level and useful to know.
|
||||
|
||||
```{toctree}
|
||||
---
|
||||
maxdepth: 2
|
||||
glob:
|
||||
---
|
||||
what-is-pyscript
|
||||
governance/*
|
||||
```
|
||||
@@ -1,34 +0,0 @@
|
||||
# What is PyScript?
|
||||
|
||||
The PyScript library provides HTML tags for embedding and executing Python code in your browser. PyScript is built using [Pyodide](https://pyodide.org/en/stable/), the WebAssembly port of CPython, which is compiled using [Emscripten](https://emscripten.org/).
|
||||
|
||||
PyScript turns the browser into a code deployment tool that anyone can learn to use.
|
||||
|
||||
## Example
|
||||
|
||||
In this example, we are using the `<py-script>` HTML tag to generate a Matplotlib figure and display it as an image.
|
||||
Click **Preview** to see the rendered HTML.
|
||||
|
||||
To try it in your browser, copy the code below into an online HTML editor like W3School's [Tryit Editor](https://www.w3schools.com/html/tryit.asp?filename=tryhtml_default_default), which allows you to modify, run, and even save your code. Watch the video below to see it in action!
|
||||
|
||||
```{youtube} ZtC7TCt_LhU
|
||||
```
|
||||
|
||||
::::{tab-set}
|
||||
:::{tab-item} HTML Source
|
||||
|
||||
```{literalinclude} ../_static/examples/what-is-pyscript.html
|
||||
---
|
||||
linenos:
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
:::{tab-item} Preview
|
||||
|
||||
```{raw} html
|
||||
<iframe height="600px" width="100%" scrolling="auto" frameborder="0" src="../_static/examples/what-is-pyscript.html"></iframe>
|
||||
```
|
||||
|
||||
:::
|
||||
::::
|
||||
103
docs/conf.py
103
docs/conf.py
@@ -1,103 +0,0 @@
|
||||
# Configuration file for the Sphinx documentation builder.
|
||||
#
|
||||
# This file only contains a selection of the most common options. For a full
|
||||
# list see the documentation:
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html
|
||||
|
||||
# -- Path setup --------------------------------------------------------------
|
||||
|
||||
# If extensions (or modules to document with autodoc) are in another directory,
|
||||
# add these directories to sys.path here. If the directory is relative to the
|
||||
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
||||
#
|
||||
import os
|
||||
|
||||
# import sys
|
||||
# sys.path.insert(0, os.path.abspath('.'))
|
||||
|
||||
|
||||
# -- Project information -----------------------------------------------------
|
||||
|
||||
project = "PyScript"
|
||||
copyright = "(c) 2022, Anaconda, Inc."
|
||||
author = "Anaconda, Inc."
|
||||
language = "en"
|
||||
|
||||
# -- General configuration ---------------------------------------------------
|
||||
|
||||
# Add any Sphinx extension module names here, as strings. They can be
|
||||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
||||
# ones.
|
||||
extensions = [
|
||||
"myst_parser",
|
||||
"sphinx_copybutton",
|
||||
"sphinx_design",
|
||||
"sphinx_togglebutton",
|
||||
"sphinx_sitemap",
|
||||
"sphinxemoji.sphinxemoji",
|
||||
"sphinxcontrib.youtube",
|
||||
]
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
templates_path = ["_templates"]
|
||||
|
||||
# List of patterns, relative to source directory, that match files and
|
||||
# directories to ignore when looking for source files.
|
||||
# This pattern also affects html_static_path and html_extra_path.
|
||||
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "_env", "README.md"]
|
||||
|
||||
|
||||
# -- Options for HTML output -------------------------------------------------
|
||||
|
||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||
# a list of builtin themes.
|
||||
#
|
||||
html_theme = "pydata_sphinx_theme"
|
||||
|
||||
html_logo = "_static/images/avatar.jpg"
|
||||
|
||||
# Add any paths that contain custom static files (such as style sheets) here,
|
||||
# relative to this directory. They are copied after the builtin static files,
|
||||
# so a file named "default.css" will overwrite the builtin "default.css".
|
||||
html_static_path = ["_static"]
|
||||
# html_css_files = ["styles/custom.css"]
|
||||
|
||||
html_baseurl = os.environ.get("SPHINX_HTML_BASE_URL", "http://127.0.0.1:8000/")
|
||||
sitemap_locales = [None]
|
||||
sitemap_url_scheme = "{link}"
|
||||
|
||||
html_extra_path = ["robots.txt"]
|
||||
|
||||
html_theme_options = {
|
||||
"github_url": "https://github.com/pyscript/pyscript",
|
||||
"twitter_url": "https://twitter.com/pyscript_dev",
|
||||
"icon_links_label": "Quick Links",
|
||||
# "google_analytics_id": "G-XXXXXXXXXX",
|
||||
"use_edit_page_button": True,
|
||||
"show_nav_level": 2,
|
||||
"external_links": [
|
||||
# {"name": "GitHub repo", "url": "https://github.com/pyscript/pyscript"},
|
||||
],
|
||||
}
|
||||
|
||||
html_context = {
|
||||
"default_mode": "dark",
|
||||
"pygment_light_style": "tango",
|
||||
"pygment_dark_style": "native",
|
||||
"github_user": "pyscript",
|
||||
"github_repo": "pyscript",
|
||||
"github_version": "main",
|
||||
"doc_path": "docs",
|
||||
}
|
||||
|
||||
|
||||
myst_enable_extensions = [
|
||||
"dollarmath",
|
||||
"amsmath",
|
||||
"deflist",
|
||||
"html_admonition",
|
||||
"html_image",
|
||||
"colon_fence",
|
||||
"smartquotes",
|
||||
"replacements",
|
||||
]
|
||||
@@ -1,18 +0,0 @@
|
||||
channels:
|
||||
- conda-forge
|
||||
- defaults
|
||||
dependencies:
|
||||
- python=3.9
|
||||
- pip=20.2.2
|
||||
- Sphinx=4.5.0
|
||||
- myst-parser=0.17.2
|
||||
- pydata-sphinx-theme
|
||||
- sphinx-copybutton
|
||||
- sphinx-design
|
||||
- sphinx-togglebutton
|
||||
|
||||
- pip:
|
||||
- sphinxemoji
|
||||
- sphinx-sitemap
|
||||
- sphinx-autobuild
|
||||
- sphinxcontrib-youtube
|
||||
@@ -1,18 +0,0 @@
|
||||
# How-to guides
|
||||
|
||||
Welcome to the how-to documentation section for PyScript. If you've already
|
||||
gained some experience with PyScript before and just need practical guides
|
||||
to get your ideas realized, you can learn step by step how to use PyScript here.
|
||||
|
||||
```{note}
|
||||
Please head over to the [tutorials](../tutorials/index.md) section if you're only getting started.
|
||||
```
|
||||
|
||||
```{toctree}
|
||||
---
|
||||
maxdepth: 2
|
||||
glob:
|
||||
caption: 'Contents:'
|
||||
---
|
||||
*
|
||||
```
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 24 KiB |
@@ -1,54 +0,0 @@
|
||||
# PyScript
|
||||
|
||||
```{warning}
|
||||
Please note, this documentation is just a placeholder and **should not be used
|
||||
in reference material**. Thank you!
|
||||
```
|
||||
|
||||
Welcome to the PyScript documentation!
|
||||
|
||||
PyScript provides a way for you to run Python code directly in your browser, giving
|
||||
anyone the ability to program without infrastructure barriers. Add an interactive
|
||||
Python REPL directly to your website, share an interactive dashboard with a colleague
|
||||
as an HTML file, or create a client-side Python-powered web application. This documentation
|
||||
will show you how.
|
||||
|
||||
::::{grid} 2
|
||||
:gutter: 3
|
||||
|
||||
:::{grid-item-card} [Tutorials](tutorials/index.md)
|
||||
|
||||
Just getting started with PyScript?
|
||||
|
||||
Check out our [getting started guide](tutorials/getting-started.md)!
|
||||
:::
|
||||
:::{grid-item-card} [How-to guides](howtos/index.md)
|
||||
|
||||
**Coming soon!**
|
||||
|
||||
:::
|
||||
:::{grid-item-card} [Concepts](concepts/index.md)
|
||||
|
||||
[What is PyScript?](concepts/what-is-pyscript.md)
|
||||
|
||||
:::
|
||||
:::{grid-item-card} [Reference](reference/index.md)
|
||||
|
||||
[Frequently asked questions](reference/faq.md)
|
||||
|
||||
:::{toctree}
|
||||
:maxdepth: 1
|
||||
|
||||
:::
|
||||
::::
|
||||
|
||||
```{toctree}
|
||||
---
|
||||
maxdepth: 1
|
||||
hidden:
|
||||
---
|
||||
tutorials/index
|
||||
howtos/index
|
||||
concepts/index
|
||||
reference/index
|
||||
```
|
||||
@@ -1,35 +0,0 @@
|
||||
@ECHO OFF
|
||||
|
||||
pushd %~dp0
|
||||
|
||||
REM Command file for Sphinx documentation
|
||||
|
||||
if "%SPHINXBUILD%" == "" (
|
||||
set SPHINXBUILD=sphinx-build
|
||||
)
|
||||
set SOURCEDIR=.
|
||||
set BUILDDIR=_build
|
||||
|
||||
%SPHINXBUILD% >NUL 2>NUL
|
||||
if errorlevel 9009 (
|
||||
echo.
|
||||
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
|
||||
echo.installed, then set the SPHINXBUILD environment variable to point
|
||||
echo.to the full path of the 'sphinx-build' executable. Alternatively you
|
||||
echo.may add the Sphinx directory to PATH.
|
||||
echo.
|
||||
echo.If you don't have Sphinx installed, grab it from
|
||||
echo.https://www.sphinx-doc.org/
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
if "%1" == "" goto help
|
||||
|
||||
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
|
||||
goto end
|
||||
|
||||
:help
|
||||
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
|
||||
|
||||
:end
|
||||
popd
|
||||
@@ -1,160 +0,0 @@
|
||||
# Frequently asked questions
|
||||
|
||||
As the world’s most popular programming language, Python is powerful in its capabilities and comparatively easy to learn, yet the limitations cannot be ignored: it’s hard to install Python and all necessary dependencies; it’s glued to the backend without the ability to make apps or websites; and it’s difficult to share your work.
|
||||
|
||||
What if we could remove those limitations, making the power of Python accessible to the masses? The makers of PyScript set out to do just that by enabling Python in the browser for frontend web and application development. No more complicated installs. Projects can be shared with anyone, anywhere—all you need is a browser.
|
||||
|
||||
We are fully leaning into the idea that the browser is the most ubiquitous VM by using Python to build a graphical, programmable OS on top to make and share applications. Harness the full power of canvas, webGL, WASI, and even in-browser support for P2P and CRDTs for serverless data sharing and collaboration.
|
||||
|
||||
> “This is the exciting beginning for supporting new ways of programming, building, sharing, and deploying applications. Ultimately, we should be spending our time thinking and writing applications to solve the real problems we have, not dealing with mundane, hardware-induced challenges. Let's make programming more fun and simple.” - Fabio Pliger
|
||||
|
||||
## Why PyScript?
|
||||
|
||||
Exponentially expand accessibility and use cases for Python by enabling Python in the browser for building UIs. Reproduce environments without having to download Python or conda or install other packages. Projects can be shared with anyone and deployed anywhere—all you need is a browser and a web-accessible device (computer, tablet, or mobile).
|
||||
|
||||
We are fully leaning into the idea that the browser is the most ubiquitous VM by using Python to build a graphical, programmable operating system on top of the browser to make and share applications. Harness the full power of canvas, webGL, WASI, and even in-browser support for P2P and CRDTs for serverless data sharing and collaboration.
|
||||
|
||||
- [PyCon US 2022 Keynote with Peter Wang](https://anaconda.cloud/pyscript-pycon2022-peter-wang-keynote)
|
||||
- [Example demos from Keynote](https://pyscript.net/examples/index.html)
|
||||
|
||||
## What is PyScript?
|
||||
|
||||
PyScript is a framework that allows users to create rich Python applications in the browser using HTML's interface and the power of [Pyodide — Version 0.20.0](https://pyodide.org/en/stable/), [WebAssembly](https://webassembly.org/), and modern web technologies. The PyScript framework provides users at every experience level with access to an expressive, easy-to-learn programming language with countless applications.
|
||||
|
||||
What is PyScript? Well, here are some of the core components:
|
||||
|
||||
- Python in the browser: Enable drop-in content, external file hosting, and application hosting without the reliance on server-side configuration
|
||||
|
||||
- Python ecosystem: Run many popular packages of Python and the scientific stack (such as numpy, pandas, scikit-learn, and more)
|
||||
|
||||
- Python with JavaScript: Bi-directional communication between Python and Javascript objects and namespaces
|
||||
|
||||
- Environment management: Allow users to define what packages and files to include for the page code to run
|
||||
|
||||
- Visual application development: Use readily available curated UI components, such as buttons, containers, text boxes, and more
|
||||
|
||||
- Flexible framework: A flexible framework that can be leveraged to create and share new pluggable and extensible components directly in Python
|
||||
|
||||
All that to say... PyScript is just HTML, only a bit (okay, maybe a lot) more powerful, thanks to the rich and accessible ecosystem of Python libraries.
|
||||
|
||||
In short, our mission is to enable programming for the 99%.
|
||||
|
||||
## How can a user get started?
|
||||
|
||||
Leveraging Python in HTML is literally as simple as adding a few lines of code to your page. The best place to learn more, get started, and stay updated on all things PyScript is [Pyscript.net](http://pyscript.net/). Additional shareable resources below:
|
||||
|
||||
- [PyScript Repo](https://github.com/pyscript/pyscript)
|
||||
- [PyScript Announcement Blog](https://www.anaconda.com/blog/pyscript-python-in-the-browser)
|
||||
- [PyScript Technical Blog](https://engineering.anaconda.com/2022/04/welcome-pyscript.html)
|
||||
- [PyScript Nucleus Project](https://anaconda.cloud/s/pyscript)
|
||||
- [PyScript Documentation](https://docs.pyscript.net/)
|
||||
|
||||
## Why isn't this going to be as terrible as PHP?
|
||||
|
||||
This comparison is based on both PHP and PyScript having a similar way of declaring things: put a tag on the page and the interpreter handles it. PHP works on the server side and is itself a whole different programming language that has its own directives and semantics.
|
||||
|
||||
The choice of using tags to allow people to execute Python is explicit; even if this functionality is similar to PHP, it works differently. First of all, everything runs in the browser itself rather than going to the server side. Secondly, PyScript lives close to the text and allows changes to be made to the visual elements. The PyScript REPL can generate output, plus it provides additional visual elements like buttons, titles, and input boxes. PyScript functions as a framework that generates UIs that makes sense as a tag in the html code.
|
||||
|
||||
Currently, both PHP and PyScript operate with only one namespace. However, PyScript will soon support multiple namespaces and different types of isolation of code (scope), along with support for languages beyond Python.
|
||||
|
||||
## Why not just learn JavaScript?
|
||||
|
||||
JavaScript is not only a different language from python, but a challenging language at that. With PyScript, you now have two languages to choose from, with even more on the roadmap. PyScript allows you to use both libraries and makes JavaScript and Python compatible with one another.
|
||||
|
||||
Python is incredibly powerful, super intuitive, and easy to learn. By adding Python to your toolkit, you can use Numpy, SciPy, Pandas, and more, seamlessly. One tradeoff is longer download times, so it isn’t the right tool for everything—but where it is the right tool, it’s almost irreplaceable.
|
||||
|
||||
Ultimately, PyScript will enable the use of a variety of languages, offer a standard set of components that is well linked to the REPLs, and allow you to do an introspection on the code base—you can have, for example, a *modifiable* chart as a python object.
|
||||
|
||||
## Will PyScript replace JavaScript?
|
||||
|
||||
No. PyScript allows Python to leverage HTML, CSS, and JavaScript conventions to build elegant UIs and address general web application building, packaging, distribution, and deployment challenges (a huge pain). We expect the popularity and adoption of HTML, CSS, and JavaScript to rise alongside Python, ultimately making the web a more friendly and hackable place for everyone. That said, we do believe:
|
||||
|
||||
- PyScript will displace some use cases that people have to rely on Javascript for now
|
||||
- PyScript will heavily leverage and interface with existing powerful, feature-full JS libraries, as appropriate
|
||||
- PyScript will open up web programming to tens of millions of people who would otherwise not have touched JavaScript; so in this way, it will outpace JavaScript
|
||||
|
||||
But none of these above scenarios lead to a situation where "PyScript replaces all existing JavaScript." Just as Python itself didn't replace C, C++, or Java. But, it did take a LOT of market share for new use cases where those languages would otherwise have been used.
|
||||
|
||||
## What is the difference between PyScript and Pyodide?
|
||||
|
||||

|
||||
|
||||
PyScript provides HTML tags for embedding and executing Python code in your browser. As a ‘glue’ framework, it sits on top of a variety of tools and provides users access to Pyodide, the WebAssembly port of CPython, which is compiled using Emscripten. In other words, Pyodide enables PyScript users to take advantage of real CPython on the browser.
|
||||
|
||||
Together, PyScript and Pyodide allow users to author applications by turning the browser into a code deployment tool that anyone can learn to use.
|
||||
|
||||
With respect to the UI, PyScript is opinionated and purposeful, while Pyodide is agnostic, unopinionated, and intended for more general use.
|
||||
|
||||
## What packages can I use? Can I use anything from PyPI?
|
||||
|
||||
You can use anything within the Pyodide library, and pure python packages from PyPi that do not contain C dependencies should be supported by Pyodide.
|
||||
|
||||
There is a list of packages built in Pyodide in [Packages built in Pyodide — Version 0.20.0](https://pyodide.org/en/stable/usage/packages-in-pyodide.html) (these are mostly packages with C extensions). You can also install pure Python packages from PyPI or custom URLs, assuming they have a wheel.
|
||||
|
||||
In general, Pyodide doesn’t support all Python features—not because of Pyodide itself, but because some concepts just work differently on the browser (think of sockets/websockets, IO, threading, etc.). If it’s a pure python package that doesn’t have any non-supported features, you should expect it to work. If it has C dependencies, etc., don’t expect it to work unless someone builds/ports them. A lot of the features that don’t work can be made to work, but it will take human power to fix. For example, the PyTorch community wanted those features to work, so they rallied around it to make it happen. Expect the set of libraries that work to grow quickly given the volume of package builds coming from the community.
|
||||
|
||||
## This package XXX is not supported because it has C dependencies. How can I make it work?
|
||||
|
||||
See [Creating a Pyodide package — Version 0.20.0](https://pyodide.org/en/stable/development/new-packages.html).
|
||||
|
||||
## Why is PyScript loading so slowly? Why can’t we put things behind a CDN?
|
||||
|
||||
Packages are already served from the JsDelivr CDN. This is not a downloading speed problem—it's WASM assembly time. PyScript loads slowly because the Python standard library and packages are large and WebAssembly code needs to be compiled and run by the browser after they are loaded for the first time.
|
||||
|
||||
Currently, there are efforts to mitigate the problem, and Pyodide is currently working on a bundler, for instance.
|
||||
|
||||
## Is PyScript owned by Anaconda?
|
||||
|
||||
Anaconda doesn’t own PyScript. It is an open source project developed by Anaconda internally, and Anaconda team members are currently the main contributors, but the repo itself is public. We are working on a steering council to ensure the project stays public and owned by the community.
|
||||
|
||||
See [Maintainers](../concepts/governance/maintainers.md).
|
||||
|
||||
See [Governance Policy](../concepts/governance/policy.md).
|
||||
|
||||
## What is the governing model for PyScript?
|
||||
|
||||
See [Governance Policy](../concepts/governance/policy.md).
|
||||
|
||||
## What is the license?
|
||||
|
||||
PyScript uses the Apache-2.0 license.
|
||||
|
||||
Pyodide uses MPL-2.0 license. Various packages are distributed under their corresponding license.
|
||||
|
||||
## Is Pyodide a replacement for CPython? How does PyScript and Pyodide compare to CPython on WASM?
|
||||
|
||||
No. They have different elements that do different things, both of which are additive.
|
||||
|
||||
PyScript sits on top of everything. Pyodide came before the work on CPython and WASM. Patches were created in order for it to work, but now that CPython/WASM are progressing, Pyodide is able to remove a few of those patches. Additionally, CPython doesn’t deal with building Python packages for WASM. WASM related work on upstream CPython will integrate into Pyodide in the near future.
|
||||
|
||||
For a list of differences from “standard” CPython, see [Pyodide Python compatibility — Version 0.20.0](https://pyodide.org/en/stable/usage/wasm-constraints.html).
|
||||
|
||||
## Hasn’t this already been done before by Brython/skulpt?
|
||||
|
||||
No. Brython and Skulpt accomplish different things than PyScript and Pyodide.
|
||||
|
||||
Brython is client-side and functions as syntax on top of Javascript—it is a reimplementation of Python on top of Javascript, without support for packages or a file system. The extraction of a package in normal Python has been replaced completely by something else. You should be able to run code with minimal changes; however, that isn’t possible with Brython.
|
||||
|
||||
Skulpt is a cross compiler from Python to Javascript, leveraged for compatibility with the Python ecosystem. If you want to do any more Python, you would have to send it over.
|
||||
|
||||
Fairly similar syntax to normal Python, but not exactly the same. If Brython was an interpreter and a full Python implementation, it could be used with PyScript to leverage packages like Numpy, but that isn’t possible as it stands today. They do have the Python script tag, but it is a smaller API and not as feature rich—which is why PyScript is built on Pyodide, Emscripten, and WebAssembly.
|
||||
|
||||
## How can I contribute/help?
|
||||
|
||||
**PyScript** - we are currently working on building documentation and a contributing guide. In the meantime, just ask to help on the PyScript [discussions page](https://anaconda.cloud/s/pyscript) or in the [repo](http://github.com/pyscript/pyscript).
|
||||
|
||||
**Pyodide** - refer to [Pyodide docs](https://pyodide.org/en/stable/development/contributing.html).
|
||||
|
||||
## WebAssembly Security
|
||||
|
||||
See [WebAssembly docs](https://webassembly.org/docs/security/).
|
||||
|
||||
## Why don’t Requests and Black work?
|
||||
|
||||
Requests and Black do not work out of the box because they weren’t meant for the browser. On the browser, sockets multiprocessing works differently, so there is work to be done to actually match things.
|
||||
|
||||
For Black, it’s a design choice that can be patched. This is currently being addressed by the team at Pyodide.
|
||||
|
||||
Requests do not work because of the sockets issue (sockets and websockets are two different things) and requests are blocking—which you don’t want in the browser. It’ll require putting the runtime on a webworker and utilizing an assistant, but on the main thread it’s unlikely that it’ll work.
|
||||
|
||||
There are options as a path forward. For example, Requests can be leveraged using javascript libraries, or building a python async version of Requests API or a python wrapper for fetch (pyfetch), etc. The websockets library has a client side that could be made to work—given that it has all asynchronous APIs, there’s nothing fundamentally difficult about getting it to work.
|
||||
@@ -1,11 +0,0 @@
|
||||
# Reference
|
||||
|
||||
This reference section will have manually documented or fully
|
||||
automated code documentation. **Coming soon!**
|
||||
|
||||
```{toctree}
|
||||
---
|
||||
maxdepth: 1
|
||||
glob:
|
||||
---
|
||||
faq
|
||||
@@ -1,5 +0,0 @@
|
||||
User-agent: *
|
||||
Disallow: /review/
|
||||
|
||||
Sitemap: https://docs.pyscript.net/sitemap.xml
|
||||
Host: docs.pyscript.net
|
||||
@@ -1,3 +0,0 @@
|
||||
# Deployment
|
||||
|
||||
**Coming soon!**
|
||||
@@ -1,267 +0,0 @@
|
||||
# Getting started with PyScript
|
||||
|
||||
This page will guide you through getting started with PyScript.
|
||||
|
||||
## Development setup
|
||||
|
||||
PyScript does not require any development environment other
|
||||
than a web browser. We recommend using [Chrome](https://www.google.com/chrome/).
|
||||
|
||||
If you're using [VSCode](https://code.visualstudio.com/), the
|
||||
[Live Server extension](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer)
|
||||
can be used to reload the page as you edit the HTML file.
|
||||
|
||||
## Installation
|
||||
|
||||
There is no installation required. In this document, we'll use
|
||||
the PyScript assets served on https://pyscript.net.
|
||||
|
||||
If you want to download the source and build it yourself, follow
|
||||
the instructions in the [README.md](https://github.com/pyscript/pyscript/blob/main/README.md) file.
|
||||
|
||||
## Your first PyScript HTML file
|
||||
|
||||
Here's a "Hello, world!" example using PyScript.
|
||||
|
||||
Using your favorite editor, create a new file called `hello.html` in
|
||||
the same directory as your PyScript, JavaScript, and CSS files with the
|
||||
following content, and open the file in your web browser. You can typically
|
||||
open an HTML by double-clicking it in your file explorer.
|
||||
|
||||
```html
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
|
||||
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
|
||||
</head>
|
||||
<body> <py-script> print('Hello, World!') </py-script> </body>
|
||||
</html>
|
||||
```
|
||||
|
||||
Notice the use of the `<py-script>` tag in the HTML body. This
|
||||
is where you'll write your Python code. In the following sections, we'll
|
||||
introduce the eight tags provided by PyScript.
|
||||
|
||||
## The py-script tag
|
||||
|
||||
The `<py-script>` tag lets you execute multi-line Python scripts and
|
||||
print back onto the page. For example, we can compute π.
|
||||
|
||||
```html
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
|
||||
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<py-script>
|
||||
print("Let's compute π:")
|
||||
def compute_pi(n):
|
||||
pi = 2
|
||||
for i in range(1,n):
|
||||
pi *= 4 * i ** 2 / (4 * i ** 2 - 1)
|
||||
return pi
|
||||
|
||||
pi = compute_pi(100000)
|
||||
s = f"π is approximately {pi:.3f}"
|
||||
print(s)
|
||||
</py-script>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
### Writing into labeled elements
|
||||
|
||||
In the example above, we had a single `<py-script>` tag printing
|
||||
one or more lines onto the page in order. Within the `<py-script>`, you
|
||||
have access to the `pyscript` module, which provides a `.write()` method
|
||||
to send strings into labeled elements on the page.
|
||||
|
||||
For example, we'll add some style elements and provide placeholders for
|
||||
the `<py-script>` tag to write to.
|
||||
|
||||
```html
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
|
||||
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<b><p>Today is <u><label id='today'></label></u></p></b>
|
||||
<br>
|
||||
<div id="pi" class="alert alert-primary"></div>
|
||||
<py-script>
|
||||
import datetime as dt
|
||||
pyscript.write('today', dt.date.today().strftime('%A %B %d, %Y'))
|
||||
|
||||
def compute_pi(n):
|
||||
pi = 2
|
||||
for i in range(1,n):
|
||||
pi *= 4 * i ** 2 / (4 * i ** 2 - 1)
|
||||
return pi
|
||||
|
||||
pi = compute_pi(100000)
|
||||
pyscript.write('pi', f'π is approximately {pi:.3f}')
|
||||
</py-script>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
## The py-env tag
|
||||
|
||||
In addition to the [Python Standard Library](https://docs.python.org/3/library/) and
|
||||
the `pyscript` module, many 3rd-party OSS packages will work out-of-the-box with PyScript.
|
||||
|
||||
In order to use them, you will need to declare the dependencies using the `<py-env>` tag in the
|
||||
HTML head. You can also link to `.whl` files directly on disk like in our [toga example](https://github.com/pyscript/pyscript/blob/main/examples/toga/freedom.html).
|
||||
|
||||
```
|
||||
<py-env>
|
||||
- './static/wheels/travertino-0.1.3-py3-none-any.whl'
|
||||
</py-env>
|
||||
```
|
||||
|
||||
If your `.whl` is not a pure Python wheel, then open a PR or issue with [pyodide](https://github.com/pyodide/pyodide) to get it added [here](https://github.com/pyodide/pyodide/tree/main/packages).
|
||||
If there's enough popular demand, the pyodide team will likely work on supporting your package. Regardless, things will likely move faster if you make the PR and consult with the team to get unblocked.
|
||||
|
||||
For example, NumPy and Matplotlib are available. Notice here we're using `<py-script output="plot">`
|
||||
as a shortcut, which takes the expression on the last line of the script and runs `pyscript.write('plot', fig)`.
|
||||
|
||||
```html
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
|
||||
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
|
||||
<py-env>
|
||||
- numpy
|
||||
- matplotlib
|
||||
</py-env>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Let's plot random numbers</h1>
|
||||
<div id="plot"></div>
|
||||
<py-script output="plot">
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
x = np.random.randn(1000)
|
||||
y = np.random.randn(1000)
|
||||
|
||||
fig, ax = plt.subplots()
|
||||
ax.scatter(x, y)
|
||||
fig
|
||||
</py-script>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
### Local modules
|
||||
|
||||
In addition to packages, you can declare local Python modules that will
|
||||
be imported in the `<py-script>` tag. For example, we can place the random
|
||||
number generation steps in a function in the file `data.py`.
|
||||
|
||||
```python
|
||||
# data.py
|
||||
import numpy as np
|
||||
|
||||
|
||||
def make_x_and_y(n):
|
||||
x = np.random.randn(n)
|
||||
y = np.random.randn(n)
|
||||
return x, y
|
||||
```
|
||||
|
||||
In the HTML tag `<py-env>`, paths to local modules are provided in the
|
||||
`paths:` key.
|
||||
|
||||
```html
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
|
||||
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
|
||||
<py-env>
|
||||
- numpy
|
||||
- matplotlib
|
||||
- paths:
|
||||
- ./data.py
|
||||
</py-env>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Let's plot random numbers</h1>
|
||||
<div id="plot"></div>
|
||||
<py-script output="plot">
|
||||
import matplotlib.pyplot as plt
|
||||
from data import make_x_and_y
|
||||
|
||||
x, y = make_x_and_y(n=1000)
|
||||
|
||||
fig, ax = plt.subplots()
|
||||
ax.scatter(x, y)
|
||||
fig
|
||||
</py-script>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
## The py-repl tag
|
||||
|
||||
The `<py-repl>` tag creates a REPL component that is rendered to the page as a code editor, allowing you to write executable code inline.
|
||||
```html
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
|
||||
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
|
||||
</head>
|
||||
<py-repl></py-repl>
|
||||
</html>
|
||||
```
|
||||
|
||||
## The py-config tag
|
||||
|
||||
Use the `<py-config>` tag to set and configure general metadata about your PyScript application in YAML format. If you are unfamiliar with YAML, consider reading [Red Hat's YAML for beginners](https://www.redhat.com/sysadmin/yaml-beginners) guide for more information.
|
||||
|
||||
The `<py-config>` tag can be used as follows:
|
||||
|
||||
```html
|
||||
<py-config>
|
||||
autoclose_loader: false
|
||||
runtimes:
|
||||
- src: "https://cdn.jsdelivr.net/pyodide/v0.20.0/full/pyodide.js"
|
||||
name: pyodide-0.20
|
||||
lang: python
|
||||
</py-config>
|
||||
```
|
||||
|
||||
The following optional values are supported by `<py-config>`:
|
||||
| Value | Type | Description |
|
||||
| ------ | ---- | ----------- |
|
||||
| `autoclose_loader` | boolean | If false, PyScript will not close the loading splash screen when the startup operations finish. |
|
||||
| `name` | string | Name of the user application. This field can be any string and is to be used by the application author for their own customization purposes. |
|
||||
| `version` | string | Version of the user application. This field can be any string and is to be used by the application author for their own customization purposes. It is not related to the PyScript version. |
|
||||
| `runtimes` | List of Runtimes | List of runtime configurations, described below.
|
||||
|
||||
A runtime configuration consists of the following:
|
||||
| Value | Type | Description |
|
||||
| ----- | ---- | ----------- |
|
||||
| `src` | string (Required) | URL to the runtime source. |
|
||||
| `name` | string | Name of the runtime. This field can be any string and is to be used by the application author for their own customization purposes |
|
||||
| `lang` | string | Programming language supported by the runtime. This field can be used by the application author to provide clarification. It currently has no implications on how PyScript behaves. |
|
||||
|
||||
## Visual component tags
|
||||
|
||||
The following tags can be used to add visual attributes to your HTML page.
|
||||
|
||||
| Tag | Description |
|
||||
| --- | ----------- |
|
||||
| `<py-inputbox>` | Adds an input box that can be used to prompt users to enter input values. |
|
||||
| `<py-box>` | Creates a container object that can be used to host one or more visual components that define how elements of `<py-box>` should align and show on the page. |
|
||||
| `<py-button>` | Adds a button to which authors can add labels and event handlers for actions on the button, such as `on_focus` or `on_click`. |
|
||||
| `<py-title>` | Adds a static text title component that styles the text inside the tag as a page title. |
|
||||
|
||||
```{note}
|
||||
All the elements above are experimental and not implemented at their full functionality. Use them with the understanding that the APIs or full support might change or be removed until the visual components are more mature.
|
||||
```
|
||||
@@ -1,12 +0,0 @@
|
||||
# Tutorials
|
||||
|
||||
This is the tutorials section for beginners.
|
||||
|
||||
```{toctree}
|
||||
---
|
||||
maxdepth: 2
|
||||
---
|
||||
getting-started
|
||||
deployment
|
||||
setup
|
||||
```
|
||||
@@ -1,3 +0,0 @@
|
||||
# Setup
|
||||
|
||||
**Coming soon!**
|
||||
@@ -1,19 +1,47 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Altair</title>
|
||||
<meta charset="utf-8">
|
||||
<link rel="icon" type="image/x-icon" href="./favicon.png">
|
||||
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
|
||||
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
|
||||
<py-env>
|
||||
- altair
|
||||
- pandas
|
||||
- vega_datasets
|
||||
</py-env>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" type="image/x-icon" href="./favicon.png" />
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://pyscript.net/latest/pyscript.css"
|
||||
/>
|
||||
<link rel="stylesheet" href="./assets/css/examples.css" />
|
||||
<style>
|
||||
py-script {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
<script
|
||||
type="module"
|
||||
src="https://esm.sh/@pyscript/core@latest/core.js"
|
||||
></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="altair" style="width: 100%; height: 100%"></div>
|
||||
<py-script output="altair">
|
||||
<nav class="navbar" style="background-color: #000000">
|
||||
<div class="app-header">
|
||||
<a href="/">
|
||||
<img src="./logo.png" class="logo" />
|
||||
</a>
|
||||
<a class="title" href="" style="color: #f0ab3c">Altair</a>
|
||||
</div>
|
||||
</nav>
|
||||
<section class="pyscript">
|
||||
<div id="altair"></div>
|
||||
<py-tutor>
|
||||
<py-config>
|
||||
packages = [
|
||||
"altair",
|
||||
"pandas",
|
||||
"vega_datasets"
|
||||
]
|
||||
plugins = [
|
||||
"https://pyscript.net/latest/plugins/python/py_tutor.py"
|
||||
]
|
||||
</py-config>
|
||||
<py-script>
|
||||
from pyscript import display
|
||||
import altair as alt
|
||||
from vega_datasets import data
|
||||
|
||||
@@ -48,13 +76,15 @@ bar = alt.Chart(source).mark_bar().encode(
|
||||
height=200
|
||||
).add_selection(pts)
|
||||
|
||||
alt.vconcat(
|
||||
display(alt.vconcat(
|
||||
rect + circ,
|
||||
bar
|
||||
).resolve_legend(
|
||||
color="independent",
|
||||
size="independent"
|
||||
)
|
||||
), target="altair")
|
||||
</py-script>
|
||||
</py-tutor>
|
||||
</section>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,20 +1,39 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Antigravity</title>
|
||||
<meta charset="utf-8">
|
||||
<link rel="icon" type="image/x-icon" href="./favicon.png">
|
||||
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
|
||||
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" type="image/x-icon" href="./favicon.png" />
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://pyscript.net/latest/pyscript.css"
|
||||
/>
|
||||
<link rel="stylesheet" href="./assets/css/examples.css" />
|
||||
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
|
||||
</head>
|
||||
<py-env>
|
||||
- paths:
|
||||
- ./antigravity.py
|
||||
</py-env>
|
||||
<body>
|
||||
<nav class="navbar" style="background-color: #000000">
|
||||
<div class="app-header">
|
||||
<a href="/">
|
||||
<img src="./logo.png" class="logo" />
|
||||
</a>
|
||||
<a class="title" href="" style="color: #f0ab3c">Antigravity</a>
|
||||
</div>
|
||||
</nav>
|
||||
<py-tutor modules="antigravity.py">
|
||||
<section class="pyscript">
|
||||
<py-config>
|
||||
plugins = [
|
||||
"https://pyscript.net/latest/plugins/python/py_tutor.py"
|
||||
]
|
||||
[[fetch]]
|
||||
files = ["./antigravity.py"]
|
||||
</py-config>
|
||||
<b>Based on xkcd: antigravity https://xkcd.com/353/.</b>
|
||||
<py-script>
|
||||
import antigravity
|
||||
antigravity.fly()
|
||||
</py-script>
|
||||
</section>
|
||||
</py-tutor>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
import random
|
||||
import sys
|
||||
|
||||
from js import DOMParser, document, setInterval
|
||||
from pyodide import create_proxy
|
||||
from pyodide.ffi import create_proxy
|
||||
from pyodide.http import open_url
|
||||
|
||||
|
||||
class Antigravity:
|
||||
|
||||
url = "./antigravity.svg"
|
||||
|
||||
def __init__(self, target=None, interval=10, append=True, fly=False):
|
||||
target = target or sys.stdout._out
|
||||
self.target = (
|
||||
document.getElementById(target) if isinstance(target, str) else target
|
||||
document.getElementById(target)
|
||||
if isinstance(target, str)
|
||||
else document.body
|
||||
)
|
||||
doc = DOMParser.new().parseFromString(
|
||||
open_url(self.url).read(), "image/svg+xml"
|
||||
|
||||
91
examples/assets/css/examples.css
Normal file
91
examples/assets/css/examples.css
Normal file
@@ -0,0 +1,91 @@
|
||||
body {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.pyscript {
|
||||
margin: 0.5rem;
|
||||
}
|
||||
|
||||
.code {
|
||||
display: flex;
|
||||
position: absolute;
|
||||
right: 0px;
|
||||
z-index: 9998;
|
||||
top: 7rem;
|
||||
}
|
||||
|
||||
@media (max-width: 1300px) {
|
||||
.code:has(> .code-section-visible) {
|
||||
width: 90%;
|
||||
/* Absolute position is messing up the layout on small screens */
|
||||
right: 70px;
|
||||
}
|
||||
}
|
||||
|
||||
.code-section-hidden {
|
||||
width: 0px;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.code-section-visible {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
background-color: rgb(45 46 53 / 90%);
|
||||
padding: 1rem;
|
||||
border-radius: 10px 0px 0px 10px;
|
||||
color: #c6c6c8;
|
||||
}
|
||||
.code-section-visible p {
|
||||
margin: 0;
|
||||
font-style: italic;
|
||||
font-size: small;
|
||||
}
|
||||
|
||||
.language-html,
|
||||
.language-python {
|
||||
float: left;
|
||||
}
|
||||
|
||||
#view-code-button {
|
||||
writing-mode: tb-rl;
|
||||
text-orientation: sideways-right;
|
||||
background-color: #1d1d22;
|
||||
color: white;
|
||||
padding: 0.5rem;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
height: 81px;
|
||||
}
|
||||
|
||||
nav {
|
||||
position: sticky;
|
||||
width: 100%;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 9999;
|
||||
}
|
||||
|
||||
.logo {
|
||||
padding-right: 10px;
|
||||
font-size: 28px;
|
||||
height: 30px;
|
||||
max-width: inherit;
|
||||
}
|
||||
|
||||
.title {
|
||||
text-decoration: none;
|
||||
text-decoration-line: none;
|
||||
text-decoration-style: initial;
|
||||
text-decoration-color: initial;
|
||||
font-weight: 400;
|
||||
font-size: 1.5em;
|
||||
line-height: 2em;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.app-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0.5rem 1rem;
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
}
|
||||
|
||||
.example h2 {
|
||||
color: #000000;
|
||||
/* color: #000000; */
|
||||
font-family: "Inconsolata", monospace;
|
||||
font-size: 2.25rem;
|
||||
margin-bottom: 1rem;
|
||||
@@ -11,10 +11,17 @@
|
||||
|
||||
.card {
|
||||
height: 15rem;
|
||||
background-color: #FFFFFF;
|
||||
background-color: var(--color-secondary);
|
||||
padding: 1rem;
|
||||
-webkit-box-shadow: var(--card-shadow);
|
||||
box-shadow: var(--card-shadow);
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.card:hover,
|
||||
.card:hover a,
|
||||
.card:hover a:visited,
|
||||
.card:hover h2 {
|
||||
background-color: var(--color-primary);
|
||||
color: #1d1d22;
|
||||
}
|
||||
|
||||
.card a h2 {
|
||||
@@ -24,6 +31,17 @@
|
||||
font-size: 2.25rem;
|
||||
}
|
||||
|
||||
.card a p {
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
a .card {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.card-content {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
@@ -31,6 +49,11 @@
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.card-content a,
|
||||
.card-content a:visited {
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.container-card {
|
||||
max-width: 1500px;
|
||||
margin: 0 auto;
|
||||
|
||||
@@ -2,6 +2,15 @@
|
||||
@import "./variables.css";
|
||||
@import "./reset.css";
|
||||
|
||||
body {
|
||||
background: #2d2e35
|
||||
url("https://assets.anaconda.com/production/Content/1650828148240.png?w=3240&auto=compress%2Cformat&fit=crop&dm=1650828161&s=c558dc55e0ed1f8419a892e842a5728f")
|
||||
repeat-x center bottom / 250px;
|
||||
background-attachment: fixed;
|
||||
overflow-x: hidden;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1510px;
|
||||
margin: auto;
|
||||
@@ -9,7 +18,6 @@
|
||||
}
|
||||
|
||||
.title-main {
|
||||
color: #000000;
|
||||
font-size: 4.25rem;
|
||||
font-family: "Inconsolata", monospace;
|
||||
text-align: center;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
:root {
|
||||
--color-primary: #2563eb;
|
||||
--color-primary: #fda703;
|
||||
--color-secondary: #1d1d22;
|
||||
--text-color: white;
|
||||
--card-shadow: 0px 5px 11px 0px rgb(0 0 0 / 15%);
|
||||
}
|
||||
|
||||
3
examples/assets/prism/prism.min.css
vendored
Normal file
3
examples/assets/prism/prism.min.css
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
/* PrismJS 1.29.0
|
||||
https://prismjs.com/download.html#themes=prism-okaidia&languages=markup+clike+javascript+python */
|
||||
code[class*=language-],pre[class*=language-]{color:#f8f8f2;background:0 0;text-shadow:0 1px rgba(0,0,0,.3);font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;font-size:1em;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}pre[class*=language-]{padding:1em;margin:.5em 0;overflow:auto;border-radius:.3em}:not(pre)>code[class*=language-],pre[class*=language-]{background:#272822}:not(pre)>code[class*=language-]{padding:.1em;border-radius:.3em;white-space:normal}.token.cdata,.token.comment,.token.doctype,.token.prolog{color:#8292a2}.token.punctuation{color:#f8f8f2}.token.namespace{opacity:.7}.token.constant,.token.deleted,.token.property,.token.symbol,.token.tag{color:#f92672}.token.boolean,.token.number{color:#ae81ff}.token.attr-name,.token.builtin,.token.char,.token.inserted,.token.selector,.token.string{color:#a6e22e}.language-css .token.string,.style .token.string,.token.entity,.token.operator,.token.url,.token.variable{color:#f8f8f2}.token.atrule,.token.attr-value,.token.class-name,.token.function{color:#e6db74}.token.keyword{color:#66d9ef}.token.important,.token.regex{color:#fd971f}.token.bold,.token.important{font-weight:700}.token.italic{font-style:italic}.token.entity{cursor:help}
|
||||
7
examples/assets/prism/prism.min.js
vendored
Normal file
7
examples/assets/prism/prism.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
29
examples/await/await0.html
Normal file
29
examples/await/await0.html
Normal file
@@ -0,0 +1,29 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<title>Async Await BLOCKING LOOP Pyscript Twice</title>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://pyscript.net/latest/pyscript.css"
|
||||
/>
|
||||
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<py-script>
|
||||
import js
|
||||
import asyncio
|
||||
for i in range(3):
|
||||
js.console.log('A', i)
|
||||
await asyncio.sleep(0.1)
|
||||
</py-script>
|
||||
<py-script>
|
||||
import js
|
||||
import asyncio
|
||||
for i in range(3):
|
||||
js.console.log('B', i)
|
||||
await asyncio.sleep(0.1)
|
||||
</py-script>
|
||||
</body>
|
||||
</html>
|
||||
45
examples/await/await1.html
Normal file
45
examples/await/await1.html
Normal file
@@ -0,0 +1,45 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<title>Async Await BLOCKING LOOP Pyscript Twice</title>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://pyscript.net/latest/pyscript.css"
|
||||
/>
|
||||
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Pyscript - FIRST ASYNC WITH INVOKED LOOP BLOCKING AWAIT AT SAME
|
||||
LEVEL AS LOOP Pyscript writing to console.log:
|
||||
<py-script>
|
||||
import js
|
||||
import asyncio
|
||||
|
||||
async def asyncCallLoop1():
|
||||
for i in range(3):
|
||||
js.console.log('A', i)
|
||||
await asyncio.sleep(2)
|
||||
|
||||
asyncCallLoop1()
|
||||
</py-script>
|
||||
</div>
|
||||
<div>
|
||||
Pyscript - SECOND ASYNC WITH INVOKED LOOP BLOCKING AWAIT AT SAME
|
||||
LEVEL AS LOOP Pyscript writing to console.log:
|
||||
<py-script>
|
||||
import js
|
||||
import asyncio
|
||||
|
||||
async def asyncCallLoop2():
|
||||
for i in range(3):
|
||||
js.console.log('B', i)
|
||||
await asyncio.sleep(2)
|
||||
|
||||
asyncCallLoop2()
|
||||
</py-script>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
42
examples/await/await2.html
Normal file
42
examples/await/await2.html
Normal file
@@ -0,0 +1,42 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<title>Async Await BLOCKING LOOP Pyscript Twice</title>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://pyscript.net/latest/pyscript.css"
|
||||
/>
|
||||
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Pyscript - FIRST ASYNC WITH INVOKED LOOP BLOCKING AWAIT AT SAME
|
||||
LEVEL AS LOOP Pyscript writing to console.log:
|
||||
<py-script>
|
||||
import js
|
||||
import asyncio
|
||||
|
||||
async def asyncCallLoop1():
|
||||
for i in range(3):
|
||||
js.console.log('A', i)
|
||||
await asyncio.sleep(2)
|
||||
|
||||
asyncCallLoop1()
|
||||
</py-script>
|
||||
</div>
|
||||
<div>
|
||||
Pyscript - SECOND ASYNC WITH TOP-LEVEL LOOP BLOCKING AWAIT AT SAME
|
||||
LEVEL AS LOOP Pyscript writing to console.log:
|
||||
<py-script>
|
||||
import js
|
||||
import asyncio
|
||||
|
||||
for i in range(3):
|
||||
js.console.log('B', i)
|
||||
await asyncio.sleep(2)
|
||||
</py-script>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
45
examples/await/await3.html
Normal file
45
examples/await/await3.html
Normal file
@@ -0,0 +1,45 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<title>Async Await NON-BLOCKING Pyscript Twice</title>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://pyscript.net/latest/pyscript.css"
|
||||
/>
|
||||
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Pyscript - FIRST ASYNC WITH NON-BLOCKING AWAIT AT ONE LEVEL LOWER
|
||||
THAN LOOP Pyscript writing to console.log:
|
||||
<py-script>
|
||||
import js
|
||||
import asyncio
|
||||
|
||||
async def asyncCall1():
|
||||
await asyncio.sleep(2)
|
||||
|
||||
for i in range(3):
|
||||
js.console.log('A', i)
|
||||
asyncCall1()
|
||||
</py-script>
|
||||
</div>
|
||||
<div>
|
||||
Pyscript - SECOND ASYNC WITH NON-BLOCKING AWAIT AT ONE LEVEL LOWER
|
||||
THAN LOOP Pyscript writing to console.log:
|
||||
<py-script>
|
||||
import js
|
||||
import asyncio
|
||||
|
||||
async def asyncCall2():
|
||||
await asyncio.sleep(2)
|
||||
|
||||
for i in range(3):
|
||||
js.console.log('B', i)
|
||||
asyncCall2()
|
||||
</py-script>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
39
examples/await/await4.html
Normal file
39
examples/await/await4.html
Normal file
@@ -0,0 +1,39 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<title>Async Await BLOCKING LOOP Pyscript Twice</title>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://pyscript.net/latest/pyscript.css"
|
||||
/>
|
||||
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
Pyscript - FIRST ASYNC WITH TOP-LEVEL LOOP BLOCKING AWAIT AT SAME
|
||||
LEVEL AS LOOP Pyscript writing to console.log:
|
||||
<py-script>
|
||||
import js
|
||||
import asyncio
|
||||
|
||||
for i in range(3):
|
||||
js.console.log('A', i)
|
||||
await asyncio.sleep(2)
|
||||
</py-script>
|
||||
</div>
|
||||
<div>
|
||||
Pyscript - SECOND ASYNC WITH TOP-LEVEL LOOP BLOCKING AWAIT AT SAME
|
||||
LEVEL AS LOOP Pyscript writing to console.log:
|
||||
<py-script>
|
||||
import js
|
||||
import asyncio
|
||||
|
||||
for i in range(3):
|
||||
js.console.log('B', i)
|
||||
await asyncio.sleep(2)
|
||||
</py-script>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
22
examples/await/await5.html
Normal file
22
examples/await/await5.html
Normal file
@@ -0,0 +1,22 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<title>Async Await BLOCKING LOOP Pyscript Twice</title>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://pyscript.net/latest/pyscript.css"
|
||||
/>
|
||||
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<py-script>
|
||||
import asyncio
|
||||
from itertools import count
|
||||
for i in count():
|
||||
print(f"Count: {i}")
|
||||
await asyncio.sleep(1)
|
||||
</py-script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,29 +1,74 @@
|
||||
<html><head>
|
||||
<html>
|
||||
<head>
|
||||
<title>Bokeh Example</title>
|
||||
<meta charset="iso-8859-1">
|
||||
<link rel="icon" type="image/x-icon" href="./favicon.png">
|
||||
<script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-2.4.2.min.js"></script>
|
||||
<script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.4.2.min.js"></script>
|
||||
<script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.4.2.min.js"></script>
|
||||
<script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.4.2.min.js"></script>
|
||||
<script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-2.4.2.min.js"></script>
|
||||
<meta charset="iso-8859-1" />
|
||||
<link rel="icon" type="image/x-icon" href="./favicon.png" />
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="https://cdn.bokeh.org/bokeh/release/bokeh-3.0.3.min.js"
|
||||
></script>
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="https://cdn.bokeh.org/bokeh/release/bokeh-gl-3.0.3.min.js"
|
||||
></script>
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="https://cdn.bokeh.org/bokeh/release/bokeh-widgets-3.0.3.min.js"
|
||||
></script>
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="https://cdn.bokeh.org/bokeh/release/bokeh-tables-3.0.3.min.js"
|
||||
></script>
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-3.0.3.min.js"
|
||||
></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
Bokeh.set_log_level("info");
|
||||
</script>
|
||||
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
|
||||
|
||||
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://pyscript.net/latest/pyscript.css"
|
||||
/>
|
||||
|
||||
<link rel="stylesheet" href="./assets/css/examples.css" />
|
||||
<style>
|
||||
py-script {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
<script
|
||||
type="module"
|
||||
src="https://esm.sh/@pyscript/core@latest/core.js"
|
||||
></script>
|
||||
</head>
|
||||
<body>
|
||||
<py-env>
|
||||
- bokeh
|
||||
- numpy
|
||||
</py-env>
|
||||
<h1>Bokeh Example</h1>
|
||||
<nav class="navbar" style="background-color: #000000">
|
||||
<div class="app-header">
|
||||
<a href="/">
|
||||
<img src="./logo.png" class="logo" />
|
||||
</a>
|
||||
<a class="title" href="" style="color: #f0ab3c"
|
||||
>Bokeh Example</a
|
||||
>
|
||||
</div>
|
||||
</nav>
|
||||
<py-tutor>
|
||||
<section class="pyscript">
|
||||
<div id="myplot"></div>
|
||||
|
||||
<py-config>
|
||||
packages = [
|
||||
"pandas",
|
||||
"bokeh",
|
||||
"xyzservices"
|
||||
]
|
||||
plugins = [
|
||||
"https://pyscript.net/latest/plugins/python/py_tutor.py"
|
||||
]
|
||||
</py-config>
|
||||
|
||||
<py-script id="main">
|
||||
import json
|
||||
import pyodide
|
||||
@@ -35,7 +80,7 @@ from bokeh.plotting import figure
|
||||
from bokeh.resources import CDN
|
||||
|
||||
# create a new plot with default tools, using figure
|
||||
p = figure(plot_width=400, plot_height=400)
|
||||
p = figure(width=400, height=400)
|
||||
|
||||
# add a circle renderer with x and y coordinates, size, color, and alpha
|
||||
p.circle([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=15, line_color="navy", fill_color="orange", fill_alpha=0.5)
|
||||
@@ -43,6 +88,7 @@ p_json = json.dumps(json_item(p, "myplot"))
|
||||
|
||||
Bokeh.embed.embed_item(JSON.parse(p_json))
|
||||
</py-script>
|
||||
|
||||
</section>
|
||||
</py-tutor>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,29 +1,66 @@
|
||||
<html><head>
|
||||
<html>
|
||||
<head>
|
||||
<title>Bokeh Example</title>
|
||||
<meta charset="iso-8859-1">
|
||||
<link rel="icon" type="image/x-icon" href="./favicon.png">
|
||||
<script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-2.4.2.js"></script>
|
||||
<script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.4.2.min.js"></script>
|
||||
<script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.4.2.min.js"></script>
|
||||
<script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.4.2.min.js"></script>
|
||||
<script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-2.4.2.min.js"></script>
|
||||
<meta charset="iso-8859-1" />
|
||||
<link rel="icon" type="image/x-icon" href="./favicon.png" />
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="https://cdn.bokeh.org/bokeh/release/bokeh-2.4.3.js"
|
||||
></script>
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.4.3.min.js"
|
||||
></script>
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.4.3.min.js"
|
||||
></script>
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.4.3.min.js"
|
||||
></script>
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-2.4.3.min.js"
|
||||
></script>
|
||||
<link rel="stylesheet" href="./assets/css/examples.css" />
|
||||
|
||||
<script type="text/javascript">
|
||||
Bokeh.set_log_level("info");
|
||||
</script>
|
||||
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
|
||||
|
||||
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://pyscript.net/latest/pyscript.css"
|
||||
/>
|
||||
|
||||
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<py-env>
|
||||
- bokeh
|
||||
- numpy
|
||||
</py-env>
|
||||
<nav class="navbar" style="background-color: #000000">
|
||||
<div class="app-header">
|
||||
<a href="/">
|
||||
<img src="./logo.png" class="logo" />
|
||||
</a>
|
||||
<a class="title" href="" style="color: #f0ab3c"
|
||||
>Bokeh Example</a
|
||||
>
|
||||
</div>
|
||||
</nav>
|
||||
<py-tutor>
|
||||
<section class="pyscript">
|
||||
<h1>Bokeh Example</h1>
|
||||
<div id="myplot"></div>
|
||||
|
||||
<py-config>
|
||||
packages = [
|
||||
"https://cdn.holoviz.org/panel/0.14.3/dist/wheels/bokeh-2.4.3-py3-none-any.whl",
|
||||
"numpy",
|
||||
]
|
||||
plugins = [
|
||||
"https://pyscript.net/latest/plugins/python/py_tutor.py"
|
||||
]
|
||||
</py-config>
|
||||
|
||||
<py-script id="main">
|
||||
import asyncio
|
||||
import json
|
||||
@@ -71,17 +108,17 @@ def _link_docs(pydoc, jsdoc):
|
||||
if getattr(event, 'setter_id', None) is not None:
|
||||
return
|
||||
events = [event]
|
||||
json_patch = jsdoc.create_json_patch_string(pyodide.to_js(events))
|
||||
json_patch = jsdoc.create_json_patch_string(pyodide.ffi.to_js(events))
|
||||
pydoc.apply_json_patch(json.loads(json_patch))
|
||||
|
||||
jsdoc.on_change(pyodide.create_proxy(jssync), pyodide.to_js(False))
|
||||
jsdoc.on_change(pyodide.ffi.create_proxy(jssync), pyodide.ffi.to_js(False))
|
||||
|
||||
def pysync(event):
|
||||
json_patch, buffers = process_document_events([event], use_buffers=True)
|
||||
buffer_map = {}
|
||||
for (ref, buffer) in buffers:
|
||||
buffer_map[ref['id']] = buffer
|
||||
jsdoc.apply_json_patch(JSON.parse(json_patch), pyodide.to_js(buffer_map), setter_id='js')
|
||||
jsdoc.apply_json_patch(JSON.parse(json_patch), pyodide.ffi.to_js(buffer_map), setter_id='js')
|
||||
|
||||
pydoc.on_change(pysync)
|
||||
|
||||
@@ -91,8 +128,9 @@ async def show(plot, target):
|
||||
jsdoc = views[0].model.document
|
||||
_link_docs(pydoc, jsdoc)
|
||||
|
||||
await show(row, 'myplot')
|
||||
asyncio.ensure_future(show(row, 'myplot'))
|
||||
</py-script>
|
||||
|
||||
</section>
|
||||
</py-tutor>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
152
examples/d3.html
152
examples/d3.html
@@ -1,12 +1,16 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>d3: JavaScript & PyScript visualizations side-by-side</title>
|
||||
<meta charset="utf-8">
|
||||
<link rel="icon" type="image/x-icon" href="./favicon.png">
|
||||
|
||||
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
|
||||
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" type="image/x-icon" href="./favicon.png" />
|
||||
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://pyscript.net/latest/pyscript.css"
|
||||
/>
|
||||
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
|
||||
<link rel="stylesheet" href="./assets/css/examples.css" />
|
||||
<script src="https://d3js.org/d3.v7.min.js"></script>
|
||||
<style>
|
||||
.loading {
|
||||
display: inline-block;
|
||||
@@ -24,11 +28,38 @@
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar" style="background-color: #000000">
|
||||
<div class="app-header">
|
||||
<a href="/">
|
||||
<img src="./logo.png" class="logo" />
|
||||
</a>
|
||||
<a class="title" href="" style="color: #f0ab3c"
|
||||
>Simple d3 visualization</a
|
||||
>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<section class="pyscript">
|
||||
<py-tutor modules="d3.py">
|
||||
<py-config>
|
||||
plugins = [
|
||||
"https://pyscript.net/latest/plugins/python/py_tutor.py"
|
||||
]
|
||||
[[fetch]]
|
||||
files = ["./d3.py"]
|
||||
</py-config>
|
||||
</py-tutor>
|
||||
<b>
|
||||
Based on <i><a href="https://observablehq.com/@d3/learn-d3-shapes?collection=@d3/learn-d3>">Learn D3: Shapes</a></i> tutorial.
|
||||
Based on
|
||||
<i
|
||||
><a
|
||||
href="https://observablehq.com/@d3/learn-d3-shapes?collection=@d3/learn-d3>"
|
||||
>Learn D3: Shapes</a
|
||||
></i
|
||||
>
|
||||
tutorial.
|
||||
</b>
|
||||
<div style="display: flex; flex-direction: row">
|
||||
<div>
|
||||
@@ -44,18 +75,10 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="importmap">
|
||||
{
|
||||
"imports": {
|
||||
"d3": "https://cdn.skypack.dev/d3@7"
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<py-script src="d3.py"></py-script>
|
||||
</section>
|
||||
|
||||
<script type="module">
|
||||
import * as d3 from "https://cdn.skypack.dev/d3@7";
|
||||
|
||||
const fruits = [
|
||||
{ name: "🍊", count: 21 },
|
||||
{ name: "🍇", count: 13 },
|
||||
@@ -65,106 +88,51 @@ const fruits = [
|
||||
{ name: "🍋", count: 2 },
|
||||
{ name: "🍎", count: 1 },
|
||||
{ name: "🍉", count: 1 },
|
||||
]
|
||||
];
|
||||
|
||||
const fn = (d) => d.count
|
||||
const data = d3.pie().value(fn)(fruits)
|
||||
const fn = (d) => d.count;
|
||||
const data = d3.pie().value(fn)(fruits);
|
||||
|
||||
const arc = d3.arc()
|
||||
const arc = d3
|
||||
.arc()
|
||||
.innerRadius(210)
|
||||
.outerRadius(310)
|
||||
.padRadius(300)
|
||||
.padAngle(2 / 300)
|
||||
.cornerRadius(8)
|
||||
.cornerRadius(8);
|
||||
|
||||
const js = d3.select("#js")
|
||||
js.select(".loading").remove()
|
||||
const js = d3.select("#js");
|
||||
js.select(".loading").remove();
|
||||
|
||||
const svg = js
|
||||
.append("svg")
|
||||
.attr("viewBox", "-320 -320 640 640")
|
||||
.attr("width", "400")
|
||||
.attr("height", "400")
|
||||
.attr("height", "400");
|
||||
|
||||
for (const d of data) {
|
||||
svg.append("path")
|
||||
.style("fill", "steelblue")
|
||||
.attr("d", arc(d))
|
||||
svg.append("path").style("fill", "steelblue").attr("d", arc(d));
|
||||
|
||||
const text = svg.append("text")
|
||||
const text = svg
|
||||
.append("text")
|
||||
.style("fill", "white")
|
||||
.attr("transform", `translate(${arc.centroid(d).join(",")})`)
|
||||
.attr("text-anchor", "middle")
|
||||
.attr(
|
||||
"transform",
|
||||
`translate(${arc.centroid(d).join(",")})`,
|
||||
)
|
||||
.attr("text-anchor", "middle");
|
||||
|
||||
text.append("tspan")
|
||||
.style("font-size", "24")
|
||||
.attr("x", "0").text(d.data.name)
|
||||
.attr("x", "0")
|
||||
.text(d.data.name);
|
||||
|
||||
text.append("tspan")
|
||||
.style("font-size", "18")
|
||||
.attr("x", "0")
|
||||
.attr("dy", "1.3em")
|
||||
.text(d.value)
|
||||
.text(d.value);
|
||||
}
|
||||
</script>
|
||||
|
||||
<py-script>
|
||||
from pyodide import create_proxy, to_js
|
||||
import d3
|
||||
|
||||
fruits = [
|
||||
dict(name="🍊", count=21),
|
||||
dict(name="🍇", count=13),
|
||||
dict(name="🍏", count=8),
|
||||
dict(name="🍌", count=5),
|
||||
dict(name="🍐", count=3),
|
||||
dict(name="🍋", count=2),
|
||||
dict(name="🍎", count=1),
|
||||
dict(name="🍉", count=1),
|
||||
]
|
||||
|
||||
fn = create_proxy(lambda d, *_: d["count"])
|
||||
data = d3.pie().value(fn)(to_js(fruits))
|
||||
|
||||
arc = (d3.arc()
|
||||
.innerRadius(210)
|
||||
.outerRadius(310)
|
||||
.padRadius(300)
|
||||
.padAngle(2 / 300)
|
||||
.cornerRadius(8))
|
||||
|
||||
py = d3.select("#py")
|
||||
py.select(".loading").remove()
|
||||
|
||||
svg = (py
|
||||
.append("svg")
|
||||
.attr("viewBox", "-320 -320 640 640")
|
||||
.attr("width", "400")
|
||||
.attr("height", "400"))
|
||||
|
||||
for d in data:
|
||||
d_py = d.to_py()
|
||||
|
||||
(svg.append("path")
|
||||
.style("fill", "steelblue")
|
||||
.attr("d", arc(d)))
|
||||
|
||||
text = (svg.append("text")
|
||||
.style("fill", "white")
|
||||
.attr("transform", f"translate({arc.centroid(d).join(',')})")
|
||||
.attr("text-anchor", "middle"))
|
||||
|
||||
(text.append("tspan")
|
||||
.style("font-size", "24")
|
||||
.attr("x", "0")
|
||||
.text(d_py["data"]["name"]))
|
||||
|
||||
(text.append("tspan")
|
||||
.style("font-size", "18")
|
||||
.attr("x", "0")
|
||||
.attr("dy", "1.3em")
|
||||
.text(d_py["value"]))
|
||||
</py-script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
64
examples/d3.py
Normal file
64
examples/d3.py
Normal file
@@ -0,0 +1,64 @@
|
||||
import js
|
||||
from pyodide.ffi import create_proxy, to_js
|
||||
|
||||
d3 = js.d3
|
||||
|
||||
fruits = [
|
||||
{"name": "🍊", "count": 21},
|
||||
{"name": "🍇", "count": 13},
|
||||
{"name": "🍏", "count": 8},
|
||||
{"name": "🍌", "count": 5},
|
||||
{"name": "🍐", "count": 3},
|
||||
{"name": "🍋", "count": 2},
|
||||
{"name": "🍎", "count": 1},
|
||||
{"name": "🍉", "count": 1},
|
||||
]
|
||||
|
||||
fn = create_proxy(lambda d, *_: d["count"])
|
||||
data = d3.pie().value(fn)(to_js(fruits))
|
||||
|
||||
arc = (
|
||||
d3.arc()
|
||||
.innerRadius(210)
|
||||
.outerRadius(310)
|
||||
.padRadius(300)
|
||||
.padAngle(2 / 300)
|
||||
.cornerRadius(8)
|
||||
)
|
||||
|
||||
py = d3.select("#py")
|
||||
py.select(".loading").remove()
|
||||
|
||||
svg = (
|
||||
py.append("svg")
|
||||
.attr("viewBox", "-320 -320 640 640")
|
||||
.attr("width", "400")
|
||||
.attr("height", "400")
|
||||
)
|
||||
|
||||
for d in data:
|
||||
d_py = d.to_py()
|
||||
|
||||
(svg.append("path").style("fill", "steelblue").attr("d", arc(d)))
|
||||
|
||||
text = (
|
||||
svg.append("text")
|
||||
.style("fill", "white")
|
||||
.attr("transform", f"translate({arc.centroid(d).join(',')})")
|
||||
.attr("text-anchor", "middle")
|
||||
)
|
||||
|
||||
(
|
||||
text.append("tspan")
|
||||
.style("font-size", "24")
|
||||
.attr("x", "0")
|
||||
.text(d_py["data"]["name"])
|
||||
)
|
||||
|
||||
(
|
||||
text.append("tspan")
|
||||
.style("font-size", "18")
|
||||
.attr("x", "0")
|
||||
.attr("dy", "1.3em")
|
||||
.text(d_py["value"])
|
||||
)
|
||||
@@ -1,18 +1,48 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Folium</title>
|
||||
<meta charset="utf-8">
|
||||
<link rel="icon" type="image/x-icon" href="./favicon.png">
|
||||
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
|
||||
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
|
||||
<py-env>
|
||||
- folium
|
||||
- pandas
|
||||
</py-env>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" type="image/x-icon" href="./favicon.png" />
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://pyscript.net/latest/pyscript.css"
|
||||
/>
|
||||
<link rel="stylesheet" href="./assets/css/examples.css" />
|
||||
<style>
|
||||
py-script {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
<script
|
||||
type="module"
|
||||
src="https://esm.sh/@pyscript/core@latest/core.js"
|
||||
></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="folium" style="width: 100%; height: 100%"></div>
|
||||
<py-script output="folium">
|
||||
<nav class="navbar" style="background-color: #000000">
|
||||
<div class="app-header">
|
||||
<a href="/">
|
||||
<img src="./logo.png" class="logo" />
|
||||
</a>
|
||||
<a class="title" href="" style="color: #f0ab3c">Folium</a>
|
||||
</div>
|
||||
</nav>
|
||||
<section class="pyscript">
|
||||
<div id="folium"></div>
|
||||
|
||||
<py-tutor>
|
||||
<py-config>
|
||||
packages = [
|
||||
"folium",
|
||||
"pandas"
|
||||
]
|
||||
plugins = [
|
||||
"https://pyscript.net/latest/plugins/python/py_tutor.py"
|
||||
]
|
||||
</py-config>
|
||||
|
||||
<py-script>
|
||||
from pyscript import display
|
||||
import folium
|
||||
import json
|
||||
import pandas as pd
|
||||
@@ -43,7 +73,9 @@ folium.Choropleth(
|
||||
|
||||
folium.LayerControl().add_to(m)
|
||||
|
||||
m
|
||||
display(m, target="folium")
|
||||
</py-script>
|
||||
</py-tutor>
|
||||
</section>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,23 +1,28 @@
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
|
||||
<title>Svelte app</title>
|
||||
<title>Say Hello</title>
|
||||
|
||||
<link rel="icon" type="image/png" href="../favicon.png" />
|
||||
<link rel="stylesheet" href="../https://pyscript.net/alpha/pyscript.css" />
|
||||
|
||||
<script defer src="../https://pyscript.net/alpha/pyscript.js"></script>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://pyscript.net/latest/pyscript.css"
|
||||
/>
|
||||
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<py-script>
|
||||
from js import handTrack, requestAnimationFrame
|
||||
from js import handTrack, requestAnimationFrame, console
|
||||
from pyodide import create_once_callable
|
||||
import asyncio
|
||||
|
||||
update_note = Element("update-note")
|
||||
canvas = Element("canvas")
|
||||
video = Element("myvideo")
|
||||
context = canvas.element.getContext("2d")
|
||||
|
||||
isVideo = False
|
||||
@@ -30,7 +35,7 @@ modelParams = {
|
||||
"scoreThreshold": 0.6, # confidence threshold for predictions.
|
||||
}
|
||||
|
||||
def toggle_video(evt):
|
||||
def toggle_video():
|
||||
global isVideo
|
||||
if (not isVideo):
|
||||
update_note.write("Starting video")
|
||||
@@ -102,21 +107,31 @@ async def start():
|
||||
pyscript.run_until_complete(start())
|
||||
|
||||
#});
|
||||
|
||||
</py-script>
|
||||
|
||||
<div class="mb10">
|
||||
<button id="trackbutton" class="bx--btn bx--btn--secondary" type="button" pys-onClick="toggle_video">
|
||||
<button
|
||||
id="trackbutton"
|
||||
class="bx--btn bx--btn--secondary"
|
||||
type="button"
|
||||
py-click="toggle_video()"
|
||||
>
|
||||
Toggle Video
|
||||
</button>
|
||||
<button id="nextimagebutton" class="mt10 bx--btn bx--btn--secondary" type="button" disabled>
|
||||
<button
|
||||
id="nextimagebutton"
|
||||
class="mt10 bx--btn bx--btn--secondary"
|
||||
type="button"
|
||||
disabled
|
||||
>
|
||||
Next Image
|
||||
</button>
|
||||
<div id="update-note" py-mount class="updatenote mt10">loading model ..</div>
|
||||
<div id="update-note" class="updatenote mt10">loading model ..</div>
|
||||
</div>
|
||||
<div>
|
||||
<video autoplay="autoplay" id="myvideo" py-mount="video"></video>
|
||||
<canvas id="canvas" py-mount class="border canvasbox"></canvas>
|
||||
<canvas id="canvas" class="border canvasbox"></canvas>
|
||||
</div>
|
||||
<script src="lib/handtrack.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
@@ -7,18 +7,49 @@
|
||||
<title>PyScript Hello World</title>
|
||||
|
||||
<link rel="icon" type="image/png" href="favicon.png" />
|
||||
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
|
||||
|
||||
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://pyscript.net/latest/pyscript.css"
|
||||
/>
|
||||
<link rel="stylesheet" href="./assets/css/examples.css" />
|
||||
<style>
|
||||
py-script {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
<script
|
||||
type="module"
|
||||
src="https://esm.sh/@pyscript/core@latest/core.js"
|
||||
></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
Hello world! <br>
|
||||
<nav class="navbar" style="background-color: #000000">
|
||||
<div class="app-header">
|
||||
<a href="/">
|
||||
<img src="./logo.png" class="logo" />
|
||||
</a>
|
||||
<a class="title" href="" style="color: #f0ab3c">Hello World</a>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<py-tutor>
|
||||
<py-config>
|
||||
plugins = [
|
||||
"https://pyscript.net/latest/plugins/python/py_tutor.py"
|
||||
]
|
||||
</py-config>
|
||||
|
||||
<section class="pyscript">
|
||||
Hello world! <br />
|
||||
This is the current date and time, as computed by Python:
|
||||
<py-script>
|
||||
from pyscript import display
|
||||
from datetime import datetime
|
||||
now = datetime.now()
|
||||
now.strftime("%m/%d/%Y, %H:%M:%S")
|
||||
display(now.strftime("%m/%d/%Y, %H:%M:%S"))
|
||||
</py-script>
|
||||
</section>
|
||||
</py-tutor>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
@@ -20,7 +20,8 @@
|
||||
<h2>Hello world</h2>
|
||||
</a>
|
||||
<p>
|
||||
A static demo of the <code><py-script></code> tag
|
||||
A static demo of the
|
||||
<code><py-script></code> tag
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -31,7 +32,8 @@
|
||||
<h2>Simple clock</h2>
|
||||
</a>
|
||||
<p>
|
||||
A dynamic demo of the <code><py-script></code> tag
|
||||
A dynamic demo of the
|
||||
<code><py-script></code> tag
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -41,9 +43,7 @@
|
||||
<a href="./repl.html" target="_blank">
|
||||
<h2>REPL</h2>
|
||||
</a>
|
||||
<p>
|
||||
A Python REPL (Read Eval Print Loop).
|
||||
</p>
|
||||
<p>A Python REPL (Read Eval Print Loop)</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -53,7 +53,8 @@
|
||||
<h2>REPL2</h2>
|
||||
</a>
|
||||
<p>
|
||||
A Python REPL (Read Eval Print Loop) with slightly better formatting..
|
||||
A Python REPL (Read Eval Print Loop) with slightly
|
||||
better formatting
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -63,9 +64,7 @@
|
||||
<a href="./todo.html" target="_blank">
|
||||
<h2>TODO App</h2>
|
||||
</a>
|
||||
<p>
|
||||
Demo showing how would a Simple TODO App would look like in PyScript</code> tag
|
||||
</p>
|
||||
<p>Simple TODO App</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -75,7 +74,7 @@
|
||||
<h2>PyScript Native TODO App</h2>
|
||||
</a>
|
||||
<p>
|
||||
Demo showing how would a Simple TODO App would look like in PyScript</code> tag
|
||||
Simple TODO App using <code><py-list></code>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -91,7 +90,11 @@
|
||||
<h2>Matplotlib</h2>
|
||||
</a>
|
||||
<p>
|
||||
Demonstrates rendering <a href="https://matplotlib.org/" target="_blank">Matplotlib</a> figure as output of the py-script tag
|
||||
Demonstrates rendering a
|
||||
<a href="https://matplotlib.org/" target="_blank"
|
||||
>Matplotlib</a
|
||||
>
|
||||
figure as output of the py-script tag
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -99,12 +102,16 @@
|
||||
<div class="card">
|
||||
<div class="card-content">
|
||||
<a href="./altair.html" target="_blank">
|
||||
<h2>
|
||||
Altair
|
||||
</h2>
|
||||
<h2>Altair</h2>
|
||||
</a>
|
||||
<p>
|
||||
Demonstrates rendering <a href="https://altair-viz.github.io/" target="_blank">Altair</a> plot as output of the py-script tag
|
||||
Demonstrates rendering a
|
||||
<a
|
||||
href="https://altair-viz.github.io/"
|
||||
target="_blank"
|
||||
>Altair</a
|
||||
>
|
||||
plot as output of the py-script tag
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -112,13 +119,15 @@
|
||||
<div class="card">
|
||||
<div class="card-content">
|
||||
<a href="./folium.html" target="_blank">
|
||||
<h2>
|
||||
Folium
|
||||
</h2>
|
||||
<h2>Folium</h2>
|
||||
</a>
|
||||
<p>
|
||||
Demonstrates rendering
|
||||
<a href="https://python-visualization.github.io/folium/" target="_blank">Folium</a>
|
||||
Demonstrates rendering a
|
||||
<a
|
||||
href="https://python-visualization.github.io/folium/"
|
||||
target="_blank"
|
||||
>Folium</a
|
||||
>
|
||||
map as output of the py-script tag
|
||||
</p>
|
||||
</div>
|
||||
@@ -132,12 +141,11 @@
|
||||
<div class="card">
|
||||
<div class="card-content">
|
||||
<a href="./d3.html" target="_blank">
|
||||
<h2>
|
||||
Simple d3 visualization
|
||||
</h2>
|
||||
<h2>Simple d3 visualization</h2>
|
||||
</a>
|
||||
<p>
|
||||
Minimal <a href="https://d3js.org/" target="_blank">D3</a>
|
||||
Minimal
|
||||
<a href="https://d3js.org/" target="_blank">D3</a>
|
||||
demo demonstrating how to create a visualization
|
||||
</p>
|
||||
</div>
|
||||
@@ -146,13 +154,17 @@
|
||||
<div class="card">
|
||||
<div class="card-content">
|
||||
<a href="./webgl/raycaster/index.html" target="_blank">
|
||||
<h2>
|
||||
Webgl Icosahedron Example
|
||||
</h2>
|
||||
<h2>Webgl Icosahedron Example</h2>
|
||||
</a>
|
||||
<p>
|
||||
Demo showing how a Simple <a href="https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API" target="_blank">WebGL</a>
|
||||
scene would work in PyScript</code> tag
|
||||
Demo showing how a Simple
|
||||
<a
|
||||
href="https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API"
|
||||
target="_blank"
|
||||
>WebGL</a
|
||||
>
|
||||
scene would work in the
|
||||
<code><py-script></code> tag
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -165,13 +177,14 @@
|
||||
<div class="card">
|
||||
<div class="card-content">
|
||||
<a href="./bokeh.html" target="_blank">
|
||||
<h2>
|
||||
Simple Static Bokeh Plot
|
||||
</h2>
|
||||
<h2>Simple Static Bokeh Plot</h2>
|
||||
</a>
|
||||
<p>
|
||||
Minimal Bokeh demo demonstrating how to create a simple
|
||||
<a href="https://bokeh.org/" target="_blank">Bokeh</a>
|
||||
Minimal Bokeh demo demonstrating how to create a
|
||||
simple
|
||||
<a href="https://bokeh.org/" target="_blank"
|
||||
>Bokeh</a
|
||||
>
|
||||
plot from code
|
||||
</p>
|
||||
</div>
|
||||
@@ -186,9 +199,12 @@
|
||||
</a>
|
||||
<p>
|
||||
Interactive demo using a
|
||||
<a href="https://bokeh.org/" target="_blank">Bokeh</a>
|
||||
slider widget to dynamically change a value in the page
|
||||
WARNING: This examples takes a little longer to load. So be patient :)
|
||||
<a href="https://bokeh.org/" target="_blank"
|
||||
>Bokeh</a
|
||||
>
|
||||
slider widget to dynamically change a value in the
|
||||
page WARNING: This examples takes a little longer to
|
||||
load. So be patient :)
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -202,8 +218,11 @@
|
||||
</a>
|
||||
<p>
|
||||
Interactive KMeans Chart using
|
||||
<a href="https://panel.holoviz.org/" target="_blank">Panel</a>
|
||||
WARNING: This examples takes a little longer to load. So be patient :)
|
||||
<a href="https://panel.holoviz.org/" target="_blank"
|
||||
>Panel</a
|
||||
>
|
||||
WARNING: This examples takes a little longer to
|
||||
load. So be patient :)
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -217,8 +236,11 @@
|
||||
</a>
|
||||
<p>
|
||||
Interactive Streaming Table and Bokeh plot using
|
||||
<a href="https://panel.holoviz.org/" target="_blank">Panel</a>
|
||||
WARNING: This examples takes a little longer to load. So be patient :)
|
||||
<a href="https://panel.holoviz.org/" target="_blank"
|
||||
>Panel</a
|
||||
>
|
||||
WARNING: This examples takes a little longer to
|
||||
load. So be patient :)
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -232,9 +254,12 @@
|
||||
</a>
|
||||
<p>
|
||||
Simple demo showing
|
||||
<a href="https://panel.holoviz.org/" target="_blank">Panel</a>
|
||||
widgets interacting with parts of the page
|
||||
WARNING: This examples takes a little longer to load. So be patient :)
|
||||
<a href="https://panel.holoviz.org/" target="_blank"
|
||||
>Panel</a
|
||||
>
|
||||
widgets interacting with parts of the page WARNING:
|
||||
This examples takes a little longer to load. So be
|
||||
patient :)
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -247,23 +272,17 @@
|
||||
</h2>
|
||||
</a>
|
||||
<p>
|
||||
Interactive application exploring the NYC Taxi dataset using
|
||||
<a href="https://panel.holoviz.org/" target="_blank">Panel</a> and <a href="https://deck.gl/" target="_blank">DeckGL</a>
|
||||
WARNING: This examples takes a little longer to load. So be patient :)
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-content">
|
||||
<a href="./toga/freedom.html" target="_blank">
|
||||
<h2 class="text-2xl font-bold text-blue-600">
|
||||
Freedom Units!
|
||||
</h2>
|
||||
</a>
|
||||
<p>
|
||||
A <a href="https://beeware.org/project/projects/libraries/toga/" target="_blank">Toga</a>
|
||||
application (a Fahrenheit to Celsius converter), rendered as a Single Page App
|
||||
Interactive application exploring the NYC Taxi
|
||||
dataset using
|
||||
<a href="https://panel.holoviz.org/" target="_blank"
|
||||
>Panel</a
|
||||
>
|
||||
and
|
||||
<a href="https://deck.gl/" target="_blank"
|
||||
>DeckGL</a
|
||||
>
|
||||
WARNING: This examples takes a little longer to
|
||||
load. So be patient :)
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -277,8 +296,14 @@
|
||||
</a>
|
||||
<p>
|
||||
Visualization of Mandelbrot and Julia sets with
|
||||
<a href="https://numpy.org/" target="_blank">Numpy</a> and
|
||||
<a href="https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API" target="_blank">
|
||||
<a href="https://numpy.org/" target="_blank"
|
||||
>Numpy</a
|
||||
>
|
||||
and
|
||||
<a
|
||||
href="https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API"
|
||||
target="_blank"
|
||||
>
|
||||
HTML5 canvas
|
||||
</a>
|
||||
</p>
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
html, body, ul, li {
|
||||
html,
|
||||
body,
|
||||
ul,
|
||||
li {
|
||||
margin: 0;
|
||||
border: 0;
|
||||
padding: 0;
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
(function () {
|
||||
if (typeof Mario === 'undefined')
|
||||
window.Mario = {};
|
||||
if (typeof Mario === "undefined") window.Mario = {};
|
||||
|
||||
var Bcoin = Mario.Bcoin = function(pos) {
|
||||
var Bcoin = (Mario.Bcoin = function (pos) {
|
||||
Mario.Entity.call(this, {
|
||||
pos: pos,
|
||||
sprite: level.bcoinSprite(),
|
||||
hitbox: [0,0,16,16]
|
||||
hitbox: [0, 0, 16, 16],
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Mario.Util.inherits(Bcoin, Mario.Entity);
|
||||
|
||||
@@ -23,7 +22,7 @@
|
||||
this.active = true;
|
||||
this.vel = -12;
|
||||
this.targetpos = this.pos[1] - 32;
|
||||
}
|
||||
};
|
||||
|
||||
Bcoin.prototype.update = function (dt) {
|
||||
if (!this.active) return;
|
||||
@@ -38,8 +37,7 @@
|
||||
this.vel += this.acc;
|
||||
this.pos[1] += this.vel;
|
||||
this.sprite.update(dt);
|
||||
}
|
||||
|
||||
Bcoin.prototype.checkCollisions = function() {;}
|
||||
};
|
||||
|
||||
Bcoin.prototype.checkCollisions = function () {};
|
||||
})();
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
(function () {
|
||||
if (typeof Mario === 'undefined')
|
||||
window.Mario = {};
|
||||
if (typeof Mario === "undefined") window.Mario = {};
|
||||
|
||||
//TODO: clean up the logic for sprite switching.
|
||||
//TODO: There's a weird bug with the collision logic. Look into it.
|
||||
|
||||
var Block = Mario.Block = function(options) {
|
||||
var Block = (Mario.Block = function (options) {
|
||||
this.item = options.item;
|
||||
this.usedSprite = options.usedSprite;
|
||||
this.bounceSprite = options.bounceSprite;
|
||||
@@ -14,20 +13,21 @@
|
||||
Mario.Entity.call(this, {
|
||||
pos: options.pos,
|
||||
sprite: options.sprite,
|
||||
hitbox: [0,0,16,16]
|
||||
hitbox: [0, 0, 16, 16],
|
||||
});
|
||||
|
||||
this.standing = true;
|
||||
}
|
||||
});
|
||||
|
||||
Mario.Util.inherits(Block, Mario.Floor);
|
||||
|
||||
Block.prototype.break = function () {
|
||||
sounds.breakBlock.play();
|
||||
(new Mario.Rubble()).spawn(this.pos);
|
||||
var x = this.pos[0] / 16, y = this.pos[1] / 16;
|
||||
new Mario.Rubble().spawn(this.pos);
|
||||
var x = this.pos[0] / 16,
|
||||
y = this.pos[1] / 16;
|
||||
delete level.blocks[y][x];
|
||||
}
|
||||
};
|
||||
|
||||
Block.prototype.bonk = function (power) {
|
||||
sounds.bump.play();
|
||||
@@ -51,7 +51,7 @@
|
||||
|
||||
this.vel[1] = -2;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Block.prototype.update = function (dt, gameTime) {
|
||||
if (!this.standing) {
|
||||
@@ -68,14 +68,17 @@
|
||||
}
|
||||
} else {
|
||||
if (this.sprite === this.usedSprite) {
|
||||
var x = this.pos[0] / 16, y = this.pos[1] / 16;
|
||||
level.statics[y][x] = new Mario.Floor(this.pos, this.usedSprite);
|
||||
var x = this.pos[0] / 16,
|
||||
y = this.pos[1] / 16;
|
||||
level.statics[y][x] = new Mario.Floor(
|
||||
this.pos,
|
||||
this.usedSprite,
|
||||
);
|
||||
delete level.blocks[y][x];
|
||||
}
|
||||
}
|
||||
|
||||
this.pos[1] += this.vel[1];
|
||||
this.sprite.update(dt, gameTime);
|
||||
}
|
||||
|
||||
};
|
||||
})();
|
||||
|
||||
@@ -1,47 +1,62 @@
|
||||
(function () {
|
||||
if (typeof Mario === 'undefined')
|
||||
window.Mario = {};
|
||||
if (typeof Mario === "undefined") window.Mario = {};
|
||||
|
||||
var Coin = Mario.Coin = function(pos, sprite) {
|
||||
var Coin = (Mario.Coin = function (pos, sprite) {
|
||||
Mario.Entity.call(this, {
|
||||
pos: pos,
|
||||
sprite: sprite,
|
||||
hitbox: [0,0,16,16]
|
||||
hitbox: [0, 0, 16, 16],
|
||||
});
|
||||
this.idx = level.items.length;
|
||||
});
|
||||
this.idx = level.items.length
|
||||
}
|
||||
|
||||
Mario.Util.inherits(Coin, Mario.Entity);
|
||||
|
||||
Coin.prototype.isPlayerCollided = function () {
|
||||
//the first two elements of the hitbox array are an offset, so let's do this now.
|
||||
var hpos1 = [this.pos[0] + this.hitbox[0], this.pos[1] + this.hitbox[1]];
|
||||
var hpos2 = [player.pos[0] + player.hitbox[0], player.pos[1] + player.hitbox[1]];
|
||||
var hpos1 = [
|
||||
this.pos[0] + this.hitbox[0],
|
||||
this.pos[1] + this.hitbox[1],
|
||||
];
|
||||
var hpos2 = [
|
||||
player.pos[0] + player.hitbox[0],
|
||||
player.pos[1] + player.hitbox[1],
|
||||
];
|
||||
|
||||
//if the hitboxes actually overlap
|
||||
if (!(hpos1[0] > hpos2[0]+player.hitbox[2] || (hpos1[0]+this.hitbox[2] < hpos2[0]))) {
|
||||
if (!(hpos1[1] > hpos2[1]+player.hitbox[3] || (hpos1[1]+this.hitbox[3] < hpos2[1]))) {
|
||||
if (
|
||||
!(
|
||||
hpos1[0] > hpos2[0] + player.hitbox[2] ||
|
||||
hpos1[0] + this.hitbox[2] < hpos2[0]
|
||||
)
|
||||
) {
|
||||
if (
|
||||
!(
|
||||
hpos1[1] > hpos2[1] + player.hitbox[3] ||
|
||||
hpos1[1] + this.hitbox[3] < hpos2[1]
|
||||
)
|
||||
) {
|
||||
this.collect();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Coin.prototype.render = function (ctx, vX, vY) {
|
||||
this.sprite.render(ctx, this.pos[0], this.pos[1], vX, vY);
|
||||
}
|
||||
};
|
||||
|
||||
//money is not affected by gravity, you see.
|
||||
Coin.prototype.update = function (dt) {
|
||||
this.sprite.update(dt);
|
||||
}
|
||||
};
|
||||
Coin.prototype.checkCollisions = function () {
|
||||
this.isPlayerCollided();
|
||||
}
|
||||
};
|
||||
|
||||
Coin.prototype.collect = function () {
|
||||
sounds.coin.currentTime = 0.05;
|
||||
sounds.coin.play();
|
||||
player.coins += 1;
|
||||
delete level.items[this.idx]
|
||||
}
|
||||
delete level.items[this.idx];
|
||||
};
|
||||
})();
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
(function () {
|
||||
if (typeof Mario === 'undefined')
|
||||
window.Mario = {};
|
||||
if (typeof Mario === "undefined") window.Mario = {};
|
||||
|
||||
var Entity = Mario.Entity = function(options) {
|
||||
var Entity = (Mario.Entity = function (options) {
|
||||
this.vel = [0, 0];
|
||||
this.acc = [0, 0];
|
||||
this.standing = true;
|
||||
@@ -10,11 +9,11 @@
|
||||
this.sprite = options.sprite;
|
||||
this.hitbox = options.hitbox;
|
||||
this.left = false;
|
||||
}
|
||||
});
|
||||
|
||||
Entity.prototype.render = function (ctx, vX, vY) {
|
||||
this.sprite.render(ctx, this.pos[0], this.pos[1], vX, vY)
|
||||
}
|
||||
this.sprite.render(ctx, this.pos[0], this.pos[1], vX, vY);
|
||||
};
|
||||
|
||||
Entity.prototype.collideWall = function (wall) {
|
||||
//the wall will always be a 16x16 block with hitbox = [0,0,16,16].
|
||||
@@ -24,11 +23,12 @@
|
||||
this.vel[0] = Math.max(0, this.vel[0]);
|
||||
this.acc[0] = Math.max(0, this.acc[0]);
|
||||
} else {
|
||||
this.pos[0] = wall.pos[0] + wall.hitbox[0] - this.hitbox[2] - this.hitbox[0];
|
||||
this.pos[0] =
|
||||
wall.pos[0] + wall.hitbox[0] - this.hitbox[2] - this.hitbox[0];
|
||||
this.vel[0] = Math.min(0, this.vel[0]);
|
||||
this.acc[0] = Math.min(0, this.acc[0]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Entity.prototype.bump = function() {;}
|
||||
Entity.prototype.bump = function () {};
|
||||
})();
|
||||
|
||||
@@ -1,17 +1,22 @@
|
||||
(function () {
|
||||
if (typeof Mario === 'undefined')
|
||||
window.Mario = {};
|
||||
if (typeof Mario === "undefined") window.Mario = {};
|
||||
|
||||
var Fireball = Mario.Fireball = function(pos) {
|
||||
var Fireball = (Mario.Fireball = function (pos) {
|
||||
this.hit = 0;
|
||||
this.standing = false;
|
||||
|
||||
Mario.Entity.call(this, {
|
||||
pos: pos,
|
||||
sprite: new Mario.Sprite('sprites/items.png', [96, 144], [8,8], 5, [0,1,2,3]),
|
||||
hitbox: [0,0,8,8]
|
||||
sprite: new Mario.Sprite(
|
||||
"sprites/items.png",
|
||||
[96, 144],
|
||||
[8, 8],
|
||||
5,
|
||||
[0, 1, 2, 3],
|
||||
),
|
||||
hitbox: [0, 0, 8, 8],
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Mario.Util.inherits(Fireball, Mario.Entity);
|
||||
|
||||
@@ -25,14 +30,14 @@
|
||||
this.idx = 0;
|
||||
fireballs[0] = this;
|
||||
}
|
||||
this.vel[0] = (left ? -5 : 5);
|
||||
this.vel[0] = left ? -5 : 5;
|
||||
this.standing = false;
|
||||
this.vel[1] = 0;
|
||||
}
|
||||
};
|
||||
|
||||
Fireball.prototype.render = function (ctx, vX, vY) {
|
||||
this.sprite.render(ctx, this.pos[0], this.pos[1], vX, vY);
|
||||
}
|
||||
};
|
||||
|
||||
Fireball.prototype.update = function (dt) {
|
||||
if (this.hit == 1) {
|
||||
@@ -67,11 +72,11 @@
|
||||
this.hit = 1;
|
||||
}
|
||||
this.sprite.update(dt);
|
||||
}
|
||||
};
|
||||
|
||||
Fireball.prototype.collideWall = function () {
|
||||
if (!this.hit) this.hit = 1;
|
||||
}
|
||||
};
|
||||
|
||||
Fireball.prototype.checkCollisions = function () {
|
||||
if (this.hit) return;
|
||||
@@ -100,27 +105,41 @@
|
||||
|
||||
var that = this;
|
||||
level.enemies.forEach(function (enemy) {
|
||||
if (enemy.flipping || enemy.pos[0] - vX > 336){ //stop checking once we get to far away dudes.
|
||||
if (enemy.flipping || enemy.pos[0] - vX > 336) {
|
||||
//stop checking once we get to far away dudes.
|
||||
return;
|
||||
} else {
|
||||
that.isCollideWith(enemy);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Fireball.prototype.isCollideWith = function (ent) {
|
||||
//the first two elements of the hitbox array are an offset, so let's do this now.
|
||||
var hpos1 = [this.pos[0] + this.hitbox[0], this.pos[1] + this.hitbox[1]];
|
||||
var hpos1 = [
|
||||
this.pos[0] + this.hitbox[0],
|
||||
this.pos[1] + this.hitbox[1],
|
||||
];
|
||||
var hpos2 = [ent.pos[0] + ent.hitbox[0], ent.pos[1] + ent.hitbox[1]];
|
||||
|
||||
//if the hitboxes actually overlap
|
||||
if (!(hpos1[0] > hpos2[0]+ent.hitbox[2] || (hpos1[0]+this.hitbox[2] < hpos2[0]))) {
|
||||
if (!(hpos1[1] > hpos2[1]+ent.hitbox[3] || (hpos1[1]+this.hitbox[3] < hpos2[1]))) {
|
||||
if (
|
||||
!(
|
||||
hpos1[0] > hpos2[0] + ent.hitbox[2] ||
|
||||
hpos1[0] + this.hitbox[2] < hpos2[0]
|
||||
)
|
||||
) {
|
||||
if (
|
||||
!(
|
||||
hpos1[1] > hpos2[1] + ent.hitbox[3] ||
|
||||
hpos1[1] + this.hitbox[3] < hpos2[1]
|
||||
)
|
||||
) {
|
||||
this.hit = 1;
|
||||
ent.bump();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Fireball.prototype.bump = function() {;}
|
||||
Fireball.prototype.bump = function () {};
|
||||
})();
|
||||
|
||||
@@ -1,24 +1,23 @@
|
||||
(function () {
|
||||
if (typeof Mario === 'undefined')
|
||||
window.Mario = {};
|
||||
if (typeof Mario === "undefined") window.Mario = {};
|
||||
|
||||
var Fireflower = Mario.Fireflower = function(pos) {
|
||||
var Fireflower = (Mario.Fireflower = function (pos) {
|
||||
this.spawning = false;
|
||||
this.waiting = 0;
|
||||
|
||||
Mario.Entity.call(this, {
|
||||
pos: pos,
|
||||
sprite: level.fireFlowerSprite,
|
||||
hitbox: [0,0,16,16]
|
||||
hitbox: [0, 0, 16, 16],
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Mario.Util.inherits(Fireflower, Mario.Entity);
|
||||
|
||||
Fireflower.prototype.render = function (ctx, vX, vY) {
|
||||
if (this.spawning > 1) return;
|
||||
this.sprite.render(ctx, this.pos[0], this.pos[1], vX, vY);
|
||||
}
|
||||
};
|
||||
|
||||
Fireflower.prototype.spawn = function () {
|
||||
sounds.itemAppear.play();
|
||||
@@ -28,12 +27,12 @@
|
||||
this.targetpos = [];
|
||||
this.targetpos[0] = this.pos[0];
|
||||
this.targetpos[1] = this.pos[1] - 16;
|
||||
}
|
||||
};
|
||||
|
||||
Fireflower.prototype.update = function (dt) {
|
||||
if (this.spawning > 1) {
|
||||
this.spawning -= 1;
|
||||
if (this.spawning == 1) this.vel[1] = -.5;
|
||||
if (this.spawning == 1) this.vel[1] = -0.5;
|
||||
return;
|
||||
}
|
||||
if (this.spawning) {
|
||||
@@ -48,27 +47,44 @@
|
||||
this.pos[0] += this.vel[0];
|
||||
this.pos[1] += this.vel[1];
|
||||
this.sprite.update(dt);
|
||||
}
|
||||
};
|
||||
|
||||
Fireflower.prototype.checkCollisions = function () {
|
||||
if (this.spawning) {return;}
|
||||
this.isPlayerCollided();
|
||||
if (this.spawning) {
|
||||
return;
|
||||
}
|
||||
this.isPlayerCollided();
|
||||
};
|
||||
|
||||
Fireflower.prototype.isPlayerCollided = function () {
|
||||
//the first two elements of the hitbox array are an offset, so let's do this now.
|
||||
var hpos1 = [this.pos[0] + this.hitbox[0], this.pos[1] + this.hitbox[1]];
|
||||
var hpos2 = [player.pos[0] + player.hitbox[0], player.pos[1] + player.hitbox[1]];
|
||||
var hpos1 = [
|
||||
this.pos[0] + this.hitbox[0],
|
||||
this.pos[1] + this.hitbox[1],
|
||||
];
|
||||
var hpos2 = [
|
||||
player.pos[0] + player.hitbox[0],
|
||||
player.pos[1] + player.hitbox[1],
|
||||
];
|
||||
|
||||
//if the hitboxes actually overlap
|
||||
if (!(hpos1[0] > hpos2[0]+player.hitbox[2] || (hpos1[0]+this.hitbox[2] < hpos2[0]))) {
|
||||
if (!(hpos1[1] > hpos2[1]+player.hitbox[3] || (hpos1[1]+this.hitbox[3] < hpos2[1]))) {
|
||||
if (
|
||||
!(
|
||||
hpos1[0] > hpos2[0] + player.hitbox[2] ||
|
||||
hpos1[0] + this.hitbox[2] < hpos2[0]
|
||||
)
|
||||
) {
|
||||
if (
|
||||
!(
|
||||
hpos1[1] > hpos2[1] + player.hitbox[3] ||
|
||||
hpos1[1] + this.hitbox[3] < hpos2[1]
|
||||
)
|
||||
) {
|
||||
player.powerUp(this.idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//This should never be called, but just in case.
|
||||
Fireflower.prototype.bump = function() {;}
|
||||
|
||||
Fireflower.prototype.bump = function () {};
|
||||
})();
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
(function () {
|
||||
if (typeof Mario === 'undefined')
|
||||
window.Mario = {};
|
||||
if (typeof Mario === "undefined") window.Mario = {};
|
||||
|
||||
Flag = Mario.Flag = function (pos) {
|
||||
//afaik flags always have the same height and Y-position
|
||||
@@ -8,10 +7,9 @@
|
||||
this.hitbox = [0, 0, 0, 0];
|
||||
this.vel = [0, 0];
|
||||
this.acc = [0, 0];
|
||||
}
|
||||
};
|
||||
|
||||
Flag.prototype.collideWall = function() {;
|
||||
}
|
||||
Flag.prototype.collideWall = function () {};
|
||||
|
||||
Flag.prototype.update = function (dt) {
|
||||
if (!this.done && this.pos[1] >= 170) {
|
||||
@@ -21,11 +19,11 @@
|
||||
this.done = true;
|
||||
}
|
||||
this.pos[1] += this.vel[1];
|
||||
}
|
||||
};
|
||||
|
||||
Flag.prototype.checkCollisions = function () {
|
||||
this.isPlayerCollided();
|
||||
}
|
||||
};
|
||||
|
||||
Flag.prototype.isPlayerCollided = function () {
|
||||
if (this.hit) return;
|
||||
@@ -39,9 +37,15 @@
|
||||
player.flag();
|
||||
this.vel = [0, 2];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Flag.prototype.render = function () {
|
||||
level.flagpoleSprites[2].render(ctx, this.pos[0]-8, this.pos[1], vX, vY);
|
||||
}
|
||||
level.flagpoleSprites[2].render(
|
||||
ctx,
|
||||
this.pos[0] - 8,
|
||||
this.pos[1],
|
||||
vX,
|
||||
vY,
|
||||
);
|
||||
};
|
||||
})();
|
||||
|
||||
@@ -1,41 +1,68 @@
|
||||
(function () {
|
||||
if (typeof Mario === 'undefined')
|
||||
window.Mario = {};
|
||||
|
||||
var Floor = Mario.Floor = function(pos, sprite) {
|
||||
if (typeof Mario === "undefined") window.Mario = {};
|
||||
|
||||
var Floor = (Mario.Floor = function (pos, sprite) {
|
||||
Mario.Entity.call(this, {
|
||||
pos: pos,
|
||||
sprite: sprite,
|
||||
hitbox: [0,0,16,16]
|
||||
hitbox: [0, 0, 16, 16],
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Mario.Util.inherits(Floor, Mario.Entity);
|
||||
|
||||
Floor.prototype.isCollideWith = function (ent) {
|
||||
//the first two elements of the hitbox array are an offset, so let's do this now.
|
||||
var hpos1 = [Math.floor(this.pos[0] + this.hitbox[0]), Math.floor(this.pos[1] + this.hitbox[1])];
|
||||
var hpos2 = [Math.floor(ent.pos[0] + ent.hitbox[0]), Math.floor(ent.pos[1] + ent.hitbox[1])];
|
||||
var hpos1 = [
|
||||
Math.floor(this.pos[0] + this.hitbox[0]),
|
||||
Math.floor(this.pos[1] + this.hitbox[1]),
|
||||
];
|
||||
var hpos2 = [
|
||||
Math.floor(ent.pos[0] + ent.hitbox[0]),
|
||||
Math.floor(ent.pos[1] + ent.hitbox[1]),
|
||||
];
|
||||
|
||||
//if the hitboxes actually overlap
|
||||
if (!(hpos1[0] > hpos2[0]+ent.hitbox[2] || (hpos1[0]+this.hitbox[2] < hpos2[0]))) {
|
||||
if (!(hpos1[1] > hpos2[1]+ent.hitbox[3] || (hpos1[1]+this.hitbox[3] < hpos2[1]))) {
|
||||
if (
|
||||
!(
|
||||
hpos1[0] > hpos2[0] + ent.hitbox[2] ||
|
||||
hpos1[0] + this.hitbox[2] < hpos2[0]
|
||||
)
|
||||
) {
|
||||
if (
|
||||
!(
|
||||
hpos1[1] > hpos2[1] + ent.hitbox[3] ||
|
||||
hpos1[1] + this.hitbox[3] < hpos2[1]
|
||||
)
|
||||
) {
|
||||
if (!this.standing) {
|
||||
ent.bump();
|
||||
} else {
|
||||
//if the entity is over the block, it's basically floor
|
||||
var center = hpos2[0] + ent.hitbox[2] / 2;
|
||||
if (Math.abs(hpos2[1] + ent.hitbox[3] - hpos1[1]) <= ent.vel[1]) {
|
||||
if (level.statics[(this.pos[1] / 16) - 1][this.pos[0] / 16]) {return};
|
||||
if (
|
||||
Math.abs(hpos2[1] + ent.hitbox[3] - hpos1[1]) <=
|
||||
ent.vel[1]
|
||||
) {
|
||||
if (
|
||||
level.statics[this.pos[1] / 16 - 1][
|
||||
this.pos[0] / 16
|
||||
]
|
||||
) {
|
||||
return;
|
||||
}
|
||||
ent.vel[1] = 0;
|
||||
ent.pos[1] = hpos1[1] - ent.hitbox[3] - ent.hitbox[1];
|
||||
ent.standing = true;
|
||||
if (ent instanceof Mario.Player) {
|
||||
ent.jumping = 0;
|
||||
}
|
||||
} else if (Math.abs(hpos2[1] - hpos1[1] - this.hitbox[3]) > ent.vel[1] &&
|
||||
center + 2 >= hpos1[0] && center - 2 <= hpos1[0] + this.hitbox[2]) {
|
||||
} else if (
|
||||
Math.abs(hpos2[1] - hpos1[1] - this.hitbox[3]) >
|
||||
ent.vel[1] &&
|
||||
center + 2 >= hpos1[0] &&
|
||||
center - 2 <= hpos1[0] + this.hitbox[2]
|
||||
) {
|
||||
//ent is under the block.
|
||||
ent.vel[1] = 0;
|
||||
ent.pos[1] = hpos1[1] + this.hitbox[3];
|
||||
@@ -50,7 +77,7 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Floor.prototype.bonk = function() {;}
|
||||
Floor.prototype.bonk = function () {};
|
||||
})();
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
var requestAnimFrame = (function () {
|
||||
return window.requestAnimationFrame ||
|
||||
return (
|
||||
window.requestAnimationFrame ||
|
||||
window.webkitRequestAnimationFrame ||
|
||||
window.mozRequestAnimationFrame ||
|
||||
window.oRequestAnimationFrame ||
|
||||
window.msRequestAnimationFrame ||
|
||||
function (callback) {
|
||||
window.setTimeout(callback, 1000 / 60);
|
||||
};
|
||||
}
|
||||
);
|
||||
})();
|
||||
|
||||
//create the canvas
|
||||
var canvas = document.createElement("canvas");
|
||||
var ctx = canvas.getContext('2d');
|
||||
var ctx = canvas.getContext("2d");
|
||||
var updateables = [];
|
||||
var fireballs = [];
|
||||
var player = new Mario.Player([0, 0]);
|
||||
@@ -34,12 +36,12 @@ var vX = 0,
|
||||
|
||||
//load our images
|
||||
resources.load([
|
||||
'sprites/player.png',
|
||||
'sprites/enemy.png',
|
||||
'sprites/tiles.png',
|
||||
'sprites/playerl.png',
|
||||
'sprites/items.png',
|
||||
'sprites/enemyr.png',
|
||||
"sprites/player.png",
|
||||
"sprites/enemy.png",
|
||||
"sprites/tiles.png",
|
||||
"sprites/playerl.png",
|
||||
"sprites/items.png",
|
||||
"sprites/enemyr.png",
|
||||
]);
|
||||
|
||||
resources.onReady(init);
|
||||
@@ -51,24 +53,24 @@ var music;
|
||||
var lastTime;
|
||||
function init() {
|
||||
music = {
|
||||
overworld: new Audio('sounds/aboveground_bgm.ogg'),
|
||||
underground: new Audio('sounds/underground_bgm.ogg'),
|
||||
clear: new Audio('sounds/stage_clear.wav'),
|
||||
death: new Audio('sounds/mariodie.wav')
|
||||
overworld: new Audio("sounds/aboveground_bgm.ogg"),
|
||||
underground: new Audio("sounds/underground_bgm.ogg"),
|
||||
clear: new Audio("sounds/stage_clear.wav"),
|
||||
death: new Audio("sounds/mariodie.wav"),
|
||||
};
|
||||
sounds = {
|
||||
smallJump: new Audio('sounds/jump-small.wav'),
|
||||
bigJump: new Audio('sounds/jump-super.wav'),
|
||||
breakBlock: new Audio('sounds/breakblock.wav'),
|
||||
bump: new Audio('sounds/bump.wav'),
|
||||
coin: new Audio('sounds/coin.wav'),
|
||||
fireball: new Audio('sounds/fireball.wav'),
|
||||
flagpole: new Audio('sounds/flagpole.wav'),
|
||||
kick: new Audio('sounds/kick.wav'),
|
||||
pipe: new Audio('sounds/pipe.wav'),
|
||||
itemAppear: new Audio('sounds/itemAppear.wav'),
|
||||
powerup: new Audio('sounds/powerup.wav'),
|
||||
stomp: new Audio('sounds/stomp.wav')
|
||||
smallJump: new Audio("sounds/jump-small.wav"),
|
||||
bigJump: new Audio("sounds/jump-super.wav"),
|
||||
breakBlock: new Audio("sounds/breakblock.wav"),
|
||||
bump: new Audio("sounds/bump.wav"),
|
||||
coin: new Audio("sounds/coin.wav"),
|
||||
fireball: new Audio("sounds/fireball.wav"),
|
||||
flagpole: new Audio("sounds/flagpole.wav"),
|
||||
kick: new Audio("sounds/kick.wav"),
|
||||
pipe: new Audio("sounds/pipe.wav"),
|
||||
itemAppear: new Audio("sounds/itemAppear.wav"),
|
||||
powerup: new Audio("sounds/powerup.wav"),
|
||||
stomp: new Audio("sounds/stomp.wav"),
|
||||
};
|
||||
Mario.oneone();
|
||||
lastTime = Date.now();
|
||||
@@ -101,28 +103,29 @@ function update(dt) {
|
||||
function handleInput(dt) {
|
||||
if (player.piping || player.dying || player.noInput) return; //don't accept input
|
||||
|
||||
if (input.isDown('RUN')){
|
||||
if (input.isDown("RUN")) {
|
||||
player.run();
|
||||
} else {
|
||||
player.noRun();
|
||||
}
|
||||
if (input.isDown('JUMP')) {
|
||||
if (input.isDown("JUMP")) {
|
||||
player.jump();
|
||||
} else {
|
||||
//we need this to handle the timing for how long you hold it
|
||||
player.noJump();
|
||||
}
|
||||
|
||||
if (input.isDown('DOWN')) {
|
||||
if (input.isDown("DOWN")) {
|
||||
player.crouch();
|
||||
} else {
|
||||
player.noCrouch();
|
||||
}
|
||||
|
||||
if (input.isDown('LEFT')) { // 'd' or left arrow
|
||||
if (input.isDown("LEFT")) {
|
||||
// 'd' or left arrow
|
||||
player.moveLeft();
|
||||
}
|
||||
else if (input.isDown('RIGHT')) { // 'k' or right arrow
|
||||
} else if (input.isDown("RIGHT")) {
|
||||
// 'k' or right arrow
|
||||
player.moveRight();
|
||||
} else {
|
||||
player.noWalk();
|
||||
@@ -138,13 +141,14 @@ function updateEntities(dt, gameTime) {
|
||||
|
||||
//This should stop the jump when he switches sides on the flag.
|
||||
if (player.exiting) {
|
||||
if (player.pos[0] > vX + 96)
|
||||
vX = player.pos[0] - 96
|
||||
if (player.pos[0] > vX + 96) vX = player.pos[0] - 96;
|
||||
} else if (level.scrolling && player.pos[0] > vX + 80) {
|
||||
vX = player.pos[0] - 80;
|
||||
}
|
||||
|
||||
if (player.powering.length !== 0 || player.dying) { return; }
|
||||
if (player.powering.length !== 0 || player.dying) {
|
||||
return;
|
||||
}
|
||||
level.items.forEach(function (ent) {
|
||||
ent.update(dt);
|
||||
});
|
||||
@@ -163,7 +167,9 @@ function updateEntities(dt, gameTime) {
|
||||
|
||||
//scan for collisions
|
||||
function checkCollisions() {
|
||||
if (player.powering.length !== 0 || player.dying) { return; }
|
||||
if (player.powering.length !== 0 || player.dying) {
|
||||
return;
|
||||
}
|
||||
player.checkCollisions();
|
||||
|
||||
//Apparently for each will just skip indices where things were deleted.
|
||||
@@ -190,7 +196,11 @@ function render() {
|
||||
|
||||
//scenery gets drawn first to get layering right.
|
||||
for (var i = 0; i < 15; i++) {
|
||||
for (var j = Math.floor(vX / 16) - 1; j < Math.floor(vX / 16) + 20; j++){
|
||||
for (
|
||||
var j = Math.floor(vX / 16) - 1;
|
||||
j < Math.floor(vX / 16) + 20;
|
||||
j++
|
||||
) {
|
||||
if (level.scenery[i][j]) {
|
||||
renderEntity(level.scenery[i][j]);
|
||||
}
|
||||
@@ -206,15 +216,17 @@ function render() {
|
||||
renderEntity(enemy);
|
||||
});
|
||||
|
||||
|
||||
|
||||
fireballs.forEach(function (fireball) {
|
||||
renderEntity(fireball);
|
||||
})
|
||||
});
|
||||
|
||||
//then we draw every static object.
|
||||
for (var i = 0; i < 15; i++) {
|
||||
for (var j = Math.floor(vX / 16) - 1; j < Math.floor(vX / 16) + 20; j++){
|
||||
for (
|
||||
var j = Math.floor(vX / 16) - 1;
|
||||
j < Math.floor(vX / 16) + 20;
|
||||
j++
|
||||
) {
|
||||
if (level.statics[i][j]) {
|
||||
renderEntity(level.statics[i][j]);
|
||||
}
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
(function () {
|
||||
if (typeof Mario === 'undefined')
|
||||
window.Mario = {};
|
||||
if (typeof Mario === "undefined") window.Mario = {};
|
||||
|
||||
//TODO: On console the hitbox is smaller. Measure it and edit this.
|
||||
|
||||
var Goomba = Mario.Goomba = function(pos, sprite) {
|
||||
var Goomba = (Mario.Goomba = function (pos, sprite) {
|
||||
this.dying = false;
|
||||
Mario.Entity.call(this, {
|
||||
pos: pos,
|
||||
sprite: sprite,
|
||||
hitbox: [0,0,16,16]
|
||||
hitbox: [0, 0, 16, 16],
|
||||
});
|
||||
this.vel[0] = -0.5;
|
||||
this.idx = level.enemies.length;
|
||||
};
|
||||
});
|
||||
|
||||
Goomba.prototype.render = function (ctx, vX, vY) {
|
||||
this.sprite.render(ctx, this.pos[0], this.pos[1], vX, vY);
|
||||
};
|
||||
|
||||
Goomba.prototype.update = function (dt, vX) {
|
||||
if (this.pos[0] - vX > 336) { //if we're too far away, do nothing.
|
||||
if (this.pos[0] - vX > 336) {
|
||||
//if we're too far away, do nothing.
|
||||
return;
|
||||
} else if (this.pos[0] - vX < -32) {
|
||||
delete level.enemies[this.idx];
|
||||
@@ -71,9 +71,11 @@
|
||||
}
|
||||
var that = this;
|
||||
level.enemies.forEach(function (enemy) {
|
||||
if (enemy === that) { //don't check collisions with ourselves.
|
||||
if (enemy === that) {
|
||||
//don't check collisions with ourselves.
|
||||
return;
|
||||
} else if (enemy.pos[0] - vX > 336){ //stop checking once we get to far away dudes.
|
||||
} else if (enemy.pos[0] - vX > 336) {
|
||||
//stop checking once we get to far away dudes.
|
||||
return;
|
||||
} else {
|
||||
that.isCollideWith(enemy);
|
||||
@@ -88,18 +90,34 @@
|
||||
}
|
||||
|
||||
//the first two elements of the hitbox array are an offset, so let's do this now.
|
||||
var hpos1 = [this.pos[0] + this.hitbox[0], this.pos[1] + this.hitbox[1]];
|
||||
var hpos1 = [
|
||||
this.pos[0] + this.hitbox[0],
|
||||
this.pos[1] + this.hitbox[1],
|
||||
];
|
||||
var hpos2 = [ent.pos[0] + ent.hitbox[0], ent.pos[1] + ent.hitbox[1]];
|
||||
|
||||
//if the hitboxes actually overlap
|
||||
if (!(hpos1[0] > hpos2[0]+ent.hitbox[2] || (hpos1[0]+this.hitbox[2] < hpos2[0]))) {
|
||||
if (!(hpos1[1] > hpos2[1]+ent.hitbox[3] || (hpos1[1]+this.hitbox[3] < hpos2[1]))) {
|
||||
if (ent instanceof Mario.Player) { //if we hit the player
|
||||
if (ent.vel[1] > 0) { //then the goomba dies
|
||||
if (
|
||||
!(
|
||||
hpos1[0] > hpos2[0] + ent.hitbox[2] ||
|
||||
hpos1[0] + this.hitbox[2] < hpos2[0]
|
||||
)
|
||||
) {
|
||||
if (
|
||||
!(
|
||||
hpos1[1] > hpos2[1] + ent.hitbox[3] ||
|
||||
hpos1[1] + this.hitbox[3] < hpos2[1]
|
||||
)
|
||||
) {
|
||||
if (ent instanceof Mario.Player) {
|
||||
//if we hit the player
|
||||
if (ent.vel[1] > 0) {
|
||||
//then the goomba dies
|
||||
this.stomp();
|
||||
} else if (ent.starTime) {
|
||||
this.bump();
|
||||
} else { //or the player gets hit
|
||||
} else {
|
||||
//or the player gets hit
|
||||
ent.damage();
|
||||
}
|
||||
} else {
|
||||
@@ -120,7 +138,7 @@
|
||||
|
||||
Goomba.prototype.bump = function () {
|
||||
sounds.kick.play();
|
||||
this.sprite.img = 'sprites/enemyr.png';
|
||||
this.sprite.img = "sprites/enemyr.png";
|
||||
this.flipping = true;
|
||||
this.pos[1] -= 1;
|
||||
this.vel[0] = 0;
|
||||
|
||||
@@ -7,19 +7,26 @@
|
||||
|
||||
switch (code) {
|
||||
case 32:
|
||||
key = 'SPACE'; break;
|
||||
key = "SPACE";
|
||||
break;
|
||||
case 37:
|
||||
key = 'LEFT'; break;
|
||||
key = "LEFT";
|
||||
break;
|
||||
case 38:
|
||||
key = 'UP'; break;
|
||||
key = "UP";
|
||||
break;
|
||||
case 39:
|
||||
key = 'RIGHT'; break;
|
||||
key = "RIGHT";
|
||||
break;
|
||||
case 40:
|
||||
key = 'DOWN'; break;
|
||||
key = "DOWN";
|
||||
break;
|
||||
case 88:
|
||||
key = 'JUMP'; break;
|
||||
key = "JUMP";
|
||||
break;
|
||||
case 90:
|
||||
key = 'RUN'; break;
|
||||
key = "RUN";
|
||||
break;
|
||||
default:
|
||||
key = String.fromCharCode(code);
|
||||
}
|
||||
@@ -27,15 +34,15 @@
|
||||
pressedKeys[key] = status;
|
||||
}
|
||||
|
||||
document.addEventListener('keydown', function(e) {
|
||||
document.addEventListener("keydown", function (e) {
|
||||
setKey(e, true);
|
||||
});
|
||||
|
||||
document.addEventListener('keyup', function(e) {
|
||||
document.addEventListener("keyup", function (e) {
|
||||
setKey(e, false);
|
||||
});
|
||||
|
||||
window.addEventListener('blur', function() {
|
||||
window.addEventListener("blur", function () {
|
||||
pressedKeys = {};
|
||||
});
|
||||
|
||||
@@ -44,11 +51,11 @@
|
||||
return pressedKeys[key.toUpperCase()];
|
||||
},
|
||||
reset: function () {
|
||||
pressedKeys['RUN'] = false;
|
||||
pressedKeys['LEFT'] = false;
|
||||
pressedKeys['RIGHT'] = false;
|
||||
pressedKeys['DOWN'] = false;
|
||||
pressedKeys['JUMP'] = false;
|
||||
}
|
||||
pressedKeys["RUN"] = false;
|
||||
pressedKeys["LEFT"] = false;
|
||||
pressedKeys["RIGHT"] = false;
|
||||
pressedKeys["DOWN"] = false;
|
||||
pressedKeys["JUMP"] = false;
|
||||
},
|
||||
};
|
||||
})();
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
(function () {
|
||||
if (typeof Mario === 'undefined')
|
||||
window.Mario = {};
|
||||
if (typeof Mario === "undefined") window.Mario = {};
|
||||
|
||||
var Koopa = Mario.Koopa = function(pos, sprite, para) {
|
||||
var Koopa = (Mario.Koopa = function (pos, sprite, para) {
|
||||
this.dying = false;
|
||||
this.shell = false;
|
||||
|
||||
@@ -14,11 +13,11 @@
|
||||
Mario.Entity.call(this, {
|
||||
pos: pos,
|
||||
sprite: sprite,
|
||||
hitbox: [2,8,12,24]
|
||||
hitbox: [2, 8, 12, 24],
|
||||
});
|
||||
this.vel[0] = -0.5;
|
||||
this.idx = level.enemies.length;
|
||||
};
|
||||
});
|
||||
|
||||
Koopa.prototype.render = function (ctx, vX, vY) {
|
||||
this.sprite.render(ctx, this.pos[0], this.pos[1], vX, vY);
|
||||
@@ -31,16 +30,17 @@
|
||||
this.turn = false;
|
||||
}
|
||||
if (this.vel[0] != 0) {
|
||||
this.left = (this.vel[0] < 0);
|
||||
this.left = this.vel[0] < 0;
|
||||
}
|
||||
|
||||
if (this.left) {
|
||||
this.sprite.img = 'sprites/enemy.png';
|
||||
this.sprite.img = "sprites/enemy.png";
|
||||
} else {
|
||||
this.sprite.img = 'sprites/enemyr.png';
|
||||
this.sprite.img = "sprites/enemyr.png";
|
||||
}
|
||||
|
||||
if (this.pos[0] - vX > 336) { //if we're too far away, do nothing.
|
||||
if (this.pos[0] - vX > 336) {
|
||||
//if we're too far away, do nothing.
|
||||
return;
|
||||
} else if (this.pos[0] - vX < -32) {
|
||||
delete level.enemies[this.idx];
|
||||
@@ -61,9 +61,9 @@
|
||||
}
|
||||
if (this.shell == 0) {
|
||||
this.sprite = level.koopaSprite();
|
||||
this.hitbox = [2,8,12,24]
|
||||
this.hitbox = [2, 8, 12, 24];
|
||||
if (this.left) {
|
||||
this.sprite.img = 'sprites/enemyr.png';
|
||||
this.sprite.img = "sprites/enemyr.png";
|
||||
this.vel[0] = 0.5;
|
||||
this.left = false;
|
||||
} else {
|
||||
@@ -122,9 +122,11 @@
|
||||
}
|
||||
var that = this;
|
||||
level.enemies.forEach(function (enemy) {
|
||||
if (enemy === that) { //don't check collisions with ourselves.
|
||||
if (enemy === that) {
|
||||
//don't check collisions with ourselves.
|
||||
return;
|
||||
} else if (enemy.pos[0] - vX > 336){ //stop checking once we get to far away dudes.
|
||||
} else if (enemy.pos[0] - vX > 336) {
|
||||
//stop checking once we get to far away dudes.
|
||||
return;
|
||||
} else {
|
||||
that.isCollideWith(enemy);
|
||||
@@ -139,12 +141,25 @@
|
||||
}
|
||||
|
||||
//the first two elements of the hitbox array are an offset, so let's do this now.
|
||||
var hpos1 = [this.pos[0] + this.hitbox[0], this.pos[1] + this.hitbox[1]];
|
||||
var hpos1 = [
|
||||
this.pos[0] + this.hitbox[0],
|
||||
this.pos[1] + this.hitbox[1],
|
||||
];
|
||||
var hpos2 = [ent.pos[0] + ent.hitbox[0], ent.pos[1] + ent.hitbox[1]];
|
||||
|
||||
//if the hitboxes actually overlap
|
||||
if (!(hpos1[0] > hpos2[0]+ent.hitbox[2] || (hpos1[0]+this.hitbox[2] < hpos2[0]))) {
|
||||
if (!(hpos1[1] > hpos2[1]+ent.hitbox[3] || (hpos1[1]+this.hitbox[3] < hpos2[1]))) {
|
||||
if (
|
||||
!(
|
||||
hpos1[0] > hpos2[0] + ent.hitbox[2] ||
|
||||
hpos1[0] + this.hitbox[2] < hpos2[0]
|
||||
)
|
||||
) {
|
||||
if (
|
||||
!(
|
||||
hpos1[1] > hpos2[1] + ent.hitbox[3] ||
|
||||
hpos1[1] + this.hitbox[3] < hpos2[1]
|
||||
)
|
||||
) {
|
||||
if (ent instanceof Mario.Player) {
|
||||
if (ent.vel[1] > 0) {
|
||||
player.bounce = true;
|
||||
@@ -152,7 +167,8 @@
|
||||
if (this.shell) {
|
||||
sounds.kick.play();
|
||||
if (this.vel[0] === 0) {
|
||||
if (ent.left) { //I'm pretty sure this isn't the real logic.
|
||||
if (ent.left) {
|
||||
//I'm pretty sure this isn't the real logic.
|
||||
this.vel[0] = -4;
|
||||
} else {
|
||||
this.vel[0] = 4;
|
||||
@@ -162,13 +178,15 @@
|
||||
this.vel[0] = 0;
|
||||
} else ent.damage();
|
||||
}
|
||||
} else if (ent.vel[1] > 0) { //then we get BOPPED.
|
||||
} else if (ent.vel[1] > 0) {
|
||||
//then we get BOPPED.
|
||||
this.stomp();
|
||||
} else { //or the player gets hit
|
||||
} else {
|
||||
//or the player gets hit
|
||||
ent.damage();
|
||||
}
|
||||
} else {
|
||||
if (this.shell && (ent instanceof Mario.Goomba)) {
|
||||
if (this.shell && ent instanceof Mario.Goomba) {
|
||||
ent.bump();
|
||||
} else this.collideWall();
|
||||
}
|
||||
@@ -194,7 +212,6 @@
|
||||
this.vel = [0, 0];
|
||||
this.pos[1] += 16;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Koopa.prototype.bump = function () {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var oneone = Mario.oneone = function() {
|
||||
var oneone = (Mario.oneone = function () {
|
||||
//The things that need to be passed in are basically just dependent on what
|
||||
//tileset we're in, so it makes more sense to just make one variable for that, so
|
||||
//TODO: put as much of this in the Level object definition as possible.
|
||||
@@ -9,62 +9,165 @@ var oneone = Mario.oneone = function() {
|
||||
scrolling: true,
|
||||
invincibility: [144, 192, 240],
|
||||
exit: 204,
|
||||
floorSprite: new Mario.Sprite('sprites/tiles.png', [0,0],[16,16],0),
|
||||
cloudSprite: new Mario.Sprite('sprites/tiles.png', [0,320],[48,32],0),
|
||||
wallSprite: new Mario.Sprite('sprites/tiles.png', [0, 16],[16,16],0),
|
||||
brickSprite: new Mario.Sprite('sprites/tiles.png', [16, 0], [16,16], 0),
|
||||
brickBounceSprite: new Mario.Sprite('sprites/tiles.png',[32,0],[16,16],0),
|
||||
floorSprite: new Mario.Sprite("sprites/tiles.png", [0, 0], [16, 16], 0),
|
||||
cloudSprite: new Mario.Sprite(
|
||||
"sprites/tiles.png",
|
||||
[0, 320],
|
||||
[48, 32],
|
||||
0,
|
||||
),
|
||||
wallSprite: new Mario.Sprite("sprites/tiles.png", [0, 16], [16, 16], 0),
|
||||
brickSprite: new Mario.Sprite(
|
||||
"sprites/tiles.png",
|
||||
[16, 0],
|
||||
[16, 16],
|
||||
0,
|
||||
),
|
||||
brickBounceSprite: new Mario.Sprite(
|
||||
"sprites/tiles.png",
|
||||
[32, 0],
|
||||
[16, 16],
|
||||
0,
|
||||
),
|
||||
rubbleSprite: function () {
|
||||
return new Mario.Sprite('sprites/items.png', [64,0], [8,8], 3, [0,1])
|
||||
return new Mario.Sprite(
|
||||
"sprites/items.png",
|
||||
[64, 0],
|
||||
[8, 8],
|
||||
3,
|
||||
[0, 1],
|
||||
);
|
||||
},
|
||||
ublockSprite: new Mario.Sprite('sprites/tiles.png', [48, 0], [16,16],0),
|
||||
superShroomSprite: new Mario.Sprite('sprites/items.png', [0,0], [16,16], 0),
|
||||
fireFlowerSprite: new Mario.Sprite('sprites/items.png', [0,32], [16,16], 20, [0,1,2,3]),
|
||||
starSprite: new Mario.Sprite('sprites/items.png', [0,48], [16,16], 20, [0,1,2,3]),
|
||||
pipeLEndSprite: new Mario.Sprite('sprites/tiles.png', [0, 128], [16,16], 0),
|
||||
pipeREndSprite: new Mario.Sprite('sprites/tiles.png', [16, 128], [16,16], 0),
|
||||
pipeLMidSprite: new Mario.Sprite('sprites/tiles.png', [0, 144], [16,16], 0),
|
||||
pipeRMidSprite: new Mario.Sprite('sprites/tiles.png', [16, 144], [16,16], 0),
|
||||
ublockSprite: new Mario.Sprite(
|
||||
"sprites/tiles.png",
|
||||
[48, 0],
|
||||
[16, 16],
|
||||
0,
|
||||
),
|
||||
superShroomSprite: new Mario.Sprite(
|
||||
"sprites/items.png",
|
||||
[0, 0],
|
||||
[16, 16],
|
||||
0,
|
||||
),
|
||||
fireFlowerSprite: new Mario.Sprite(
|
||||
"sprites/items.png",
|
||||
[0, 32],
|
||||
[16, 16],
|
||||
20,
|
||||
[0, 1, 2, 3],
|
||||
),
|
||||
starSprite: new Mario.Sprite(
|
||||
"sprites/items.png",
|
||||
[0, 48],
|
||||
[16, 16],
|
||||
20,
|
||||
[0, 1, 2, 3],
|
||||
),
|
||||
pipeLEndSprite: new Mario.Sprite(
|
||||
"sprites/tiles.png",
|
||||
[0, 128],
|
||||
[16, 16],
|
||||
0,
|
||||
),
|
||||
pipeREndSprite: new Mario.Sprite(
|
||||
"sprites/tiles.png",
|
||||
[16, 128],
|
||||
[16, 16],
|
||||
0,
|
||||
),
|
||||
pipeLMidSprite: new Mario.Sprite(
|
||||
"sprites/tiles.png",
|
||||
[0, 144],
|
||||
[16, 16],
|
||||
0,
|
||||
),
|
||||
pipeRMidSprite: new Mario.Sprite(
|
||||
"sprites/tiles.png",
|
||||
[16, 144],
|
||||
[16, 16],
|
||||
0,
|
||||
),
|
||||
|
||||
pipeUpMid: new Mario.Sprite('sprites/tiles.png', [0, 144], [32,16], 0),
|
||||
pipeSideMid: new Mario.Sprite('sprites/tiles.png', [48, 128], [16,32], 0),
|
||||
pipeLeft: new Mario.Sprite('sprites/tiles.png', [32, 128], [16,32], 0),
|
||||
pipeTop: new Mario.Sprite('sprites/tiles.png', [0, 128], [32,16], 0),
|
||||
qblockSprite: new Mario.Sprite('sprites/tiles.png', [384, 0], [16,16], 8, [0,0,0,0,1,2,1]),
|
||||
pipeUpMid: new Mario.Sprite("sprites/tiles.png", [0, 144], [32, 16], 0),
|
||||
pipeSideMid: new Mario.Sprite(
|
||||
"sprites/tiles.png",
|
||||
[48, 128],
|
||||
[16, 32],
|
||||
0,
|
||||
),
|
||||
pipeLeft: new Mario.Sprite("sprites/tiles.png", [32, 128], [16, 32], 0),
|
||||
pipeTop: new Mario.Sprite("sprites/tiles.png", [0, 128], [32, 16], 0),
|
||||
qblockSprite: new Mario.Sprite(
|
||||
"sprites/tiles.png",
|
||||
[384, 0],
|
||||
[16, 16],
|
||||
8,
|
||||
[0, 0, 0, 0, 1, 2, 1],
|
||||
),
|
||||
bcoinSprite: function () {
|
||||
return new Mario.Sprite('sprites/items.png', [0,112],[16,16], 20,[0,1,2,3]);
|
||||
return new Mario.Sprite(
|
||||
"sprites/items.png",
|
||||
[0, 112],
|
||||
[16, 16],
|
||||
20,
|
||||
[0, 1, 2, 3],
|
||||
);
|
||||
},
|
||||
cloudSprites: [
|
||||
new Mario.Sprite('sprites/tiles.png', [0,320],[16,32],0),
|
||||
new Mario.Sprite('sprites/tiles.png', [16,320],[16,32],0),
|
||||
new Mario.Sprite('sprites/tiles.png', [32,320],[16,32],0)
|
||||
new Mario.Sprite("sprites/tiles.png", [0, 320], [16, 32], 0),
|
||||
new Mario.Sprite("sprites/tiles.png", [16, 320], [16, 32], 0),
|
||||
new Mario.Sprite("sprites/tiles.png", [32, 320], [16, 32], 0),
|
||||
],
|
||||
hillSprites: [
|
||||
new Mario.Sprite('sprites/tiles.png', [128,128],[16,16],0),
|
||||
new Mario.Sprite('sprites/tiles.png', [144,128],[16,16],0),
|
||||
new Mario.Sprite('sprites/tiles.png', [160,128],[16,16],0),
|
||||
new Mario.Sprite('sprites/tiles.png', [128,144],[16,16],0),
|
||||
new Mario.Sprite('sprites/tiles.png', [144,144],[16,16],0),
|
||||
new Mario.Sprite('sprites/tiles.png', [160,144],[16,16],0)
|
||||
new Mario.Sprite("sprites/tiles.png", [128, 128], [16, 16], 0),
|
||||
new Mario.Sprite("sprites/tiles.png", [144, 128], [16, 16], 0),
|
||||
new Mario.Sprite("sprites/tiles.png", [160, 128], [16, 16], 0),
|
||||
new Mario.Sprite("sprites/tiles.png", [128, 144], [16, 16], 0),
|
||||
new Mario.Sprite("sprites/tiles.png", [144, 144], [16, 16], 0),
|
||||
new Mario.Sprite("sprites/tiles.png", [160, 144], [16, 16], 0),
|
||||
],
|
||||
bushSprite: new Mario.Sprite('sprites/tiles.png', [176, 144], [48, 16], 0),
|
||||
bushSprite: new Mario.Sprite(
|
||||
"sprites/tiles.png",
|
||||
[176, 144],
|
||||
[48, 16],
|
||||
0,
|
||||
),
|
||||
bushSprites: [
|
||||
new Mario.Sprite('sprites/tiles.png', [176,144], [16,16],0),
|
||||
new Mario.Sprite('sprites/tiles.png', [192,144], [16,16],0),
|
||||
new Mario.Sprite('sprites/tiles.png', [208,144], [16,16],0)],
|
||||
new Mario.Sprite("sprites/tiles.png", [176, 144], [16, 16], 0),
|
||||
new Mario.Sprite("sprites/tiles.png", [192, 144], [16, 16], 0),
|
||||
new Mario.Sprite("sprites/tiles.png", [208, 144], [16, 16], 0),
|
||||
],
|
||||
goombaSprite: function () {
|
||||
return new Mario.Sprite('sprites/enemy.png', [0, 16], [16,16], 3, [0,1]);
|
||||
return new Mario.Sprite(
|
||||
"sprites/enemy.png",
|
||||
[0, 16],
|
||||
[16, 16],
|
||||
3,
|
||||
[0, 1],
|
||||
);
|
||||
},
|
||||
koopaSprite: function () {
|
||||
return new Mario.Sprite('sprites/enemy.png', [96,0], [16,32], 2, [0,1]);
|
||||
return new Mario.Sprite(
|
||||
"sprites/enemy.png",
|
||||
[96, 0],
|
||||
[16, 32],
|
||||
2,
|
||||
[0, 1],
|
||||
);
|
||||
},
|
||||
flagPoleSprites: [
|
||||
new Mario.Sprite('sprites/tiles.png', [256, 128], [16,16], 0),
|
||||
new Mario.Sprite('sprites/tiles.png', [256, 144], [16,16], 0),
|
||||
new Mario.Sprite('sprites/items.png', [128, 32], [16,16], 0)
|
||||
]
|
||||
new Mario.Sprite("sprites/tiles.png", [256, 128], [16, 16], 0),
|
||||
new Mario.Sprite("sprites/tiles.png", [256, 144], [16, 16], 0),
|
||||
new Mario.Sprite("sprites/items.png", [128, 32], [16, 16], 0),
|
||||
],
|
||||
});
|
||||
ground = [[0,69],[71,86],[89,153],[155,212]];
|
||||
ground = [
|
||||
[0, 69],
|
||||
[71, 86],
|
||||
[89, 153],
|
||||
[155, 212],
|
||||
];
|
||||
player.pos[0] = level.playerPos[0];
|
||||
player.pos[1] = level.playerPos[1];
|
||||
vX = 0;
|
||||
@@ -75,22 +178,41 @@ var oneone = Mario.oneone = function() {
|
||||
});
|
||||
|
||||
//build scenery
|
||||
clouds = [[7,3],[19, 2],[56, 3],[67, 2],[87, 2],[103, 2],[152, 3],[163, 2],[200, 3]];
|
||||
clouds = [
|
||||
[7, 3],
|
||||
[19, 2],
|
||||
[56, 3],
|
||||
[67, 2],
|
||||
[87, 2],
|
||||
[103, 2],
|
||||
[152, 3],
|
||||
[163, 2],
|
||||
[200, 3],
|
||||
];
|
||||
clouds.forEach(function (cloud) {
|
||||
level.putCloud(cloud[0], cloud[1]);
|
||||
});
|
||||
|
||||
twoClouds = [[36,2],[132,2],[180,2]];
|
||||
twoClouds = [
|
||||
[36, 2],
|
||||
[132, 2],
|
||||
[180, 2],
|
||||
];
|
||||
twoClouds.forEach(function (cloud) {
|
||||
level.putTwoCloud(cloud[0], cloud[1]);
|
||||
});
|
||||
|
||||
threeClouds = [[27,3],[75,3],[123,3],[171,3]];
|
||||
threeClouds = [
|
||||
[27, 3],
|
||||
[75, 3],
|
||||
[123, 3],
|
||||
[171, 3],
|
||||
];
|
||||
threeClouds.forEach(function (cloud) {
|
||||
level.putThreeCloud(cloud[0], cloud[1]);
|
||||
});
|
||||
|
||||
bHills = [0,48,96,144,192]
|
||||
bHills = [0, 48, 96, 144, 192];
|
||||
bHills.forEach(function (hill) {
|
||||
level.putBigHill(hill, 12);
|
||||
});
|
||||
@@ -216,4 +338,4 @@ var oneone = Mario.oneone = function() {
|
||||
music.underground.pause();
|
||||
// music.overworld.currentTime = 0;
|
||||
music.overworld.play();
|
||||
};
|
||||
});
|
||||
|
||||
@@ -1,35 +1,90 @@
|
||||
var oneonetunnel = Mario.oneonetunnel = function() {
|
||||
var oneonetunnel = (Mario.oneonetunnel = function () {
|
||||
level = new Mario.Level({
|
||||
playerPos: [40, 16],
|
||||
loader: Mario.oneonetunnel,
|
||||
background: "#000000",
|
||||
scrolling: false,
|
||||
coinSprite: function () {
|
||||
return new Mario.Sprite('sprites/items.png', [0,96],[16,16], 6,[0,0,0,0,1,2,1]);
|
||||
return new Mario.Sprite(
|
||||
"sprites/items.png",
|
||||
[0, 96],
|
||||
[16, 16],
|
||||
6,
|
||||
[0, 0, 0, 0, 1, 2, 1],
|
||||
);
|
||||
},
|
||||
floorSprite: new Mario.Sprite('sprites/tiles.png', [0,32],[16,16],0),
|
||||
wallSprite: new Mario.Sprite('sprites/tiles.png', [32, 32],[16,16],0),
|
||||
brickSprite: new Mario.Sprite('sprites/tiles.png', [16, 0], [16,16], 0),
|
||||
brickBounceSprite: new Mario.Sprite('sprites/tiles.png',[32,0],[16,16],0),
|
||||
ublockSprite: new Mario.Sprite('sprites/tiles.png', [48, 0], [16,16],0),
|
||||
pipeLMidSprite: new Mario.Sprite('sprites/tiles.png', [0, 144], [16,16], 0),
|
||||
pipeRMidSprite: new Mario.Sprite('sprites/tiles.png', [16, 144], [16,16], 0),
|
||||
pipeLEndSprite: new Mario.Sprite('sprites/tiles.png', [0, 128], [16,16], 0),
|
||||
pipeREndSprite: new Mario.Sprite('sprites/tiles.png', [16, 128], [16,16], 0),
|
||||
pipeUpMid: new Mario.Sprite('sprites/tiles.png', [0, 144], [32,16], 0),
|
||||
pipeSideMid: new Mario.Sprite('sprites/tiles.png', [48, 128], [16,32], 0),
|
||||
pipeLeft: new Mario.Sprite('sprites/tiles.png', [32, 128], [16,32], 0),
|
||||
pipeTop: new Mario.Sprite('sprites/tiles.png', [0, 128], [32,16], 0),
|
||||
floorSprite: new Mario.Sprite(
|
||||
"sprites/tiles.png",
|
||||
[0, 32],
|
||||
[16, 16],
|
||||
0,
|
||||
),
|
||||
wallSprite: new Mario.Sprite(
|
||||
"sprites/tiles.png",
|
||||
[32, 32],
|
||||
[16, 16],
|
||||
0,
|
||||
),
|
||||
brickSprite: new Mario.Sprite(
|
||||
"sprites/tiles.png",
|
||||
[16, 0],
|
||||
[16, 16],
|
||||
0,
|
||||
),
|
||||
brickBounceSprite: new Mario.Sprite(
|
||||
"sprites/tiles.png",
|
||||
[32, 0],
|
||||
[16, 16],
|
||||
0,
|
||||
),
|
||||
ublockSprite: new Mario.Sprite(
|
||||
"sprites/tiles.png",
|
||||
[48, 0],
|
||||
[16, 16],
|
||||
0,
|
||||
),
|
||||
pipeLMidSprite: new Mario.Sprite(
|
||||
"sprites/tiles.png",
|
||||
[0, 144],
|
||||
[16, 16],
|
||||
0,
|
||||
),
|
||||
pipeRMidSprite: new Mario.Sprite(
|
||||
"sprites/tiles.png",
|
||||
[16, 144],
|
||||
[16, 16],
|
||||
0,
|
||||
),
|
||||
pipeLEndSprite: new Mario.Sprite(
|
||||
"sprites/tiles.png",
|
||||
[0, 128],
|
||||
[16, 16],
|
||||
0,
|
||||
),
|
||||
pipeREndSprite: new Mario.Sprite(
|
||||
"sprites/tiles.png",
|
||||
[16, 128],
|
||||
[16, 16],
|
||||
0,
|
||||
),
|
||||
pipeUpMid: new Mario.Sprite("sprites/tiles.png", [0, 144], [32, 16], 0),
|
||||
pipeSideMid: new Mario.Sprite(
|
||||
"sprites/tiles.png",
|
||||
[48, 128],
|
||||
[16, 32],
|
||||
0,
|
||||
),
|
||||
pipeLeft: new Mario.Sprite("sprites/tiles.png", [32, 128], [16, 32], 0),
|
||||
pipeTop: new Mario.Sprite("sprites/tiles.png", [0, 128], [32, 16], 0),
|
||||
|
||||
LPipeSprites: [
|
||||
new Mario.Sprite('sprites/tiles.png', [32,128],[16,16],0),
|
||||
new Mario.Sprite('sprites/tiles.png', [32,144],[16,16],0),
|
||||
new Mario.Sprite('sprites/tiles.png', [48,128],[16,16],0),
|
||||
new Mario.Sprite('sprites/tiles.png', [48,144],[16,16],0),
|
||||
new Mario.Sprite('sprites/tiles.png', [64,128],[16,16],0),
|
||||
new Mario.Sprite('sprites/tiles.png', [64,144],[16,16],0),
|
||||
]
|
||||
|
||||
new Mario.Sprite("sprites/tiles.png", [32, 128], [16, 16], 0),
|
||||
new Mario.Sprite("sprites/tiles.png", [32, 144], [16, 16], 0),
|
||||
new Mario.Sprite("sprites/tiles.png", [48, 128], [16, 16], 0),
|
||||
new Mario.Sprite("sprites/tiles.png", [48, 144], [16, 16], 0),
|
||||
new Mario.Sprite("sprites/tiles.png", [64, 128], [16, 16], 0),
|
||||
new Mario.Sprite("sprites/tiles.png", [64, 144], [16, 16], 0),
|
||||
],
|
||||
});
|
||||
|
||||
player.pos[0] = level.playerPos[0];
|
||||
@@ -43,9 +98,27 @@ var oneonetunnel = Mario.oneonetunnel = function() {
|
||||
level.putWall(loc, 3, 1);
|
||||
});
|
||||
|
||||
coins = [[5,5], [6,5], [7,5], [8,5], [9,5],
|
||||
[4,7], [5,7], [6,7], [7,7], [8,7], [9,7], [10,7],
|
||||
[4,9], [5,9], [6,9], [7,9], [8,9], [9,9], [10,9]];
|
||||
coins = [
|
||||
[5, 5],
|
||||
[6, 5],
|
||||
[7, 5],
|
||||
[8, 5],
|
||||
[9, 5],
|
||||
[4, 7],
|
||||
[5, 7],
|
||||
[6, 7],
|
||||
[7, 7],
|
||||
[8, 7],
|
||||
[9, 7],
|
||||
[10, 7],
|
||||
[4, 9],
|
||||
[5, 9],
|
||||
[6, 9],
|
||||
[7, 9],
|
||||
[8, 9],
|
||||
[9, 9],
|
||||
[10, 9],
|
||||
];
|
||||
coins.forEach(function (pos) {
|
||||
level.putCoin(pos[0], pos[1]);
|
||||
});
|
||||
@@ -53,8 +126,8 @@ var oneonetunnel = Mario.oneonetunnel = function() {
|
||||
//level.putLeftPipe(13,11);
|
||||
level.putRealPipe(13, 11, 3, "RIGHT", function () {
|
||||
Mario.oneone.call();
|
||||
player.pos = [2616, 177]
|
||||
player.pipe("UP", function() {;});
|
||||
player.pos = [2616, 177];
|
||||
player.pipe("UP", function () {});
|
||||
});
|
||||
|
||||
level.putPipe(15, 13, 13);
|
||||
@@ -62,4 +135,4 @@ var oneonetunnel = Mario.oneonetunnel = function() {
|
||||
music.overworld.pause();
|
||||
music.underground.currentTime = 0;
|
||||
music.underground.play();
|
||||
};
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
(function () {
|
||||
var Level = Mario.Level = function(options) {
|
||||
var Level = (Mario.Level = function (options) {
|
||||
this.playerPos = options.playerPos;
|
||||
this.scrolling = options.scrolling;
|
||||
this.loader = options.loader;
|
||||
@@ -55,58 +55,97 @@
|
||||
this.scenery[i] = [];
|
||||
this.blocks[i] = [];
|
||||
}
|
||||
|
||||
};
|
||||
});
|
||||
|
||||
Level.prototype.putFloor = function (start, end) {
|
||||
for (var i = start; i < end; i++) {
|
||||
this.statics[13][i] = new Mario.Floor([16*i,208], this.floorSprite);
|
||||
this.statics[14][i] = new Mario.Floor([16*i,224], this.floorSprite);
|
||||
this.statics[13][i] = new Mario.Floor(
|
||||
[16 * i, 208],
|
||||
this.floorSprite,
|
||||
);
|
||||
this.statics[14][i] = new Mario.Floor(
|
||||
[16 * i, 224],
|
||||
this.floorSprite,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
Level.prototype.putGoomba = function (x, y) {
|
||||
this.enemies.push(new Mario.Goomba([16*x, 16*y], this.goombaSprite() ));
|
||||
this.enemies.push(
|
||||
new Mario.Goomba([16 * x, 16 * y], this.goombaSprite()),
|
||||
);
|
||||
};
|
||||
|
||||
Level.prototype.putKoopa = function (x, y) {
|
||||
this.enemies.push(new Mario.Koopa([16*x, 16*y], this.koopaSprite(), false));
|
||||
this.enemies.push(
|
||||
new Mario.Koopa([16 * x, 16 * y], this.koopaSprite(), false),
|
||||
);
|
||||
};
|
||||
|
||||
Level.prototype.putWall = function (x, y, height) {
|
||||
//y is the bottom of the wall in this case.
|
||||
for (var i = y - height; i < y; i++) {
|
||||
this.statics[i][x] = new Mario.Floor([16*x, 16*i], this.wallSprite);
|
||||
this.statics[i][x] = new Mario.Floor(
|
||||
[16 * x, 16 * i],
|
||||
this.wallSprite,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
Level.prototype.putPipe = function (x, y, height) {
|
||||
for (var i = y - height; i < y; i++) {
|
||||
if (i === y - height) {
|
||||
this.statics[i][x] = new Mario.Floor([16*x, 16*i], this.pipeLEndSprite);
|
||||
this.statics[i][x+1] = new Mario.Floor([16*x+16, 16*i], this.pipeREndSprite);
|
||||
this.statics[i][x] = new Mario.Floor(
|
||||
[16 * x, 16 * i],
|
||||
this.pipeLEndSprite,
|
||||
);
|
||||
this.statics[i][x + 1] = new Mario.Floor(
|
||||
[16 * x + 16, 16 * i],
|
||||
this.pipeREndSprite,
|
||||
);
|
||||
} else {
|
||||
this.statics[i][x] = new Mario.Floor([16*x, 16*i], this.pipeLMidSprite);
|
||||
this.statics[i][x+1] = new Mario.Floor([16*x+16, 16*i], this.pipeRMidSprite);
|
||||
this.statics[i][x] = new Mario.Floor(
|
||||
[16 * x, 16 * i],
|
||||
this.pipeLMidSprite,
|
||||
);
|
||||
this.statics[i][x + 1] = new Mario.Floor(
|
||||
[16 * x + 16, 16 * i],
|
||||
this.pipeRMidSprite,
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//sometimes, pipes don't go straight up and down.
|
||||
Level.prototype.putLeftPipe = function (x, y) {
|
||||
this.statics[y][x] = new Mario.Floor([16*x, 16*y], this.LPipeSprites[0]);
|
||||
this.statics[y+1][x] = new Mario.Floor([16*x,16*(y+1)], this.LPipeSprites[1]);
|
||||
this.statics[y][x+1] = new Mario.Floor([16*(x+1),16*y], this.LPipeSprites[2]);
|
||||
this.statics[y+1][x+1] = new Mario.Floor([16*(x+1),16*(y+1)], this.LPipeSprites[3]);
|
||||
this.statics[y][x+2] = new Mario.Floor([16*(x+2),16*y], this.LPipeSprites[4]);
|
||||
this.statics[y+1][x+2] = new Mario.Floor([16*(x+2),16*(y+1)], this.LPipeSprites[5]);
|
||||
this.statics[y][x] = new Mario.Floor(
|
||||
[16 * x, 16 * y],
|
||||
this.LPipeSprites[0],
|
||||
);
|
||||
this.statics[y + 1][x] = new Mario.Floor(
|
||||
[16 * x, 16 * (y + 1)],
|
||||
this.LPipeSprites[1],
|
||||
);
|
||||
this.statics[y][x + 1] = new Mario.Floor(
|
||||
[16 * (x + 1), 16 * y],
|
||||
this.LPipeSprites[2],
|
||||
);
|
||||
this.statics[y + 1][x + 1] = new Mario.Floor(
|
||||
[16 * (x + 1), 16 * (y + 1)],
|
||||
this.LPipeSprites[3],
|
||||
);
|
||||
this.statics[y][x + 2] = new Mario.Floor(
|
||||
[16 * (x + 2), 16 * y],
|
||||
this.LPipeSprites[4],
|
||||
);
|
||||
this.statics[y + 1][x + 2] = new Mario.Floor(
|
||||
[16 * (x + 2), 16 * (y + 1)],
|
||||
this.LPipeSprites[5],
|
||||
);
|
||||
};
|
||||
|
||||
Level.prototype.putCoin = function (x, y) {
|
||||
this.items.push(new Mario.Coin(
|
||||
[x*16, y*16],
|
||||
this.coinSprite()
|
||||
));
|
||||
this.items.push(new Mario.Coin([x * 16, y * 16], this.coinSprite()));
|
||||
};
|
||||
|
||||
Level.prototype.putCloud = function (x, y) {
|
||||
@@ -118,7 +157,7 @@
|
||||
pos: [x * 16, y * 16],
|
||||
item: item,
|
||||
sprite: this.qblockSprite,
|
||||
usedSprite: this.ublockSprite
|
||||
usedSprite: this.ublockSprite,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -129,21 +168,46 @@
|
||||
sprite: this.brickSprite,
|
||||
bounceSprite: this.brickBounceSprite,
|
||||
usedSprite: this.ublockSprite,
|
||||
breakable: !item
|
||||
breakable: !item,
|
||||
});
|
||||
};
|
||||
|
||||
Level.prototype.putBigHill = function (x, y) {
|
||||
var px = x*16, py = y*16;
|
||||
var px = x * 16,
|
||||
py = y * 16;
|
||||
this.scenery[y][x] = new Mario.Prop([px, py], this.hillSprites[0]);
|
||||
this.scenery[y][x+1] = new Mario.Prop([px+16, py], this.hillSprites[3]);
|
||||
this.scenery[y-1][x+1] = new Mario.Prop([px+16, py-16], this.hillSprites[0]);
|
||||
this.scenery[y][x+2] = new Mario.Prop([px+32, py], this.hillSprites[4]);
|
||||
this.scenery[y-1][x+2] = new Mario.Prop([px+32, py-16], this.hillSprites[3]);
|
||||
this.scenery[y-2][x+2] = new Mario.Prop([px+32, py-32], this.hillSprites[1]);
|
||||
this.scenery[y][x+3] = new Mario.Prop([px+48, py], this.hillSprites[5]);
|
||||
this.scenery[y-1][x+3] = new Mario.Prop([px+48, py-16], this.hillSprites[2]);
|
||||
this.scenery[y][x+4] = new Mario.Prop([px+64, py], this.hillSprites[2]);
|
||||
this.scenery[y][x + 1] = new Mario.Prop(
|
||||
[px + 16, py],
|
||||
this.hillSprites[3],
|
||||
);
|
||||
this.scenery[y - 1][x + 1] = new Mario.Prop(
|
||||
[px + 16, py - 16],
|
||||
this.hillSprites[0],
|
||||
);
|
||||
this.scenery[y][x + 2] = new Mario.Prop(
|
||||
[px + 32, py],
|
||||
this.hillSprites[4],
|
||||
);
|
||||
this.scenery[y - 1][x + 2] = new Mario.Prop(
|
||||
[px + 32, py - 16],
|
||||
this.hillSprites[3],
|
||||
);
|
||||
this.scenery[y - 2][x + 2] = new Mario.Prop(
|
||||
[px + 32, py - 32],
|
||||
this.hillSprites[1],
|
||||
);
|
||||
this.scenery[y][x + 3] = new Mario.Prop(
|
||||
[px + 48, py],
|
||||
this.hillSprites[5],
|
||||
);
|
||||
this.scenery[y - 1][x + 3] = new Mario.Prop(
|
||||
[px + 48, py - 16],
|
||||
this.hillSprites[2],
|
||||
);
|
||||
this.scenery[y][x + 4] = new Mario.Prop(
|
||||
[px + 64, py],
|
||||
this.hillSprites[2],
|
||||
);
|
||||
};
|
||||
|
||||
Level.prototype.putBush = function (x, y) {
|
||||
@@ -154,65 +218,131 @@
|
||||
px = x * 16;
|
||||
py = y * 16;
|
||||
this.scenery[y][x] = new Mario.Prop([px, py], this.bushSprites[0]);
|
||||
this.scenery[y][x+1] = new Mario.Prop([px+16, py], this.bushSprites[1]);
|
||||
this.scenery[y][x+2] = new Mario.Prop([px+32, py], this.bushSprites[1]);
|
||||
this.scenery[y][x+3] = new Mario.Prop([px+48, py], this.bushSprites[1]);
|
||||
this.scenery[y][x+4] = new Mario.Prop([px+64, py], this.bushSprites[2]);
|
||||
this.scenery[y][x + 1] = new Mario.Prop(
|
||||
[px + 16, py],
|
||||
this.bushSprites[1],
|
||||
);
|
||||
this.scenery[y][x + 2] = new Mario.Prop(
|
||||
[px + 32, py],
|
||||
this.bushSprites[1],
|
||||
);
|
||||
this.scenery[y][x + 3] = new Mario.Prop(
|
||||
[px + 48, py],
|
||||
this.bushSprites[1],
|
||||
);
|
||||
this.scenery[y][x + 4] = new Mario.Prop(
|
||||
[px + 64, py],
|
||||
this.bushSprites[2],
|
||||
);
|
||||
};
|
||||
|
||||
Level.prototype.putTwoBush = function (x, y) {
|
||||
px = x * 16;
|
||||
py = y * 16;
|
||||
this.scenery[y][x] = new Mario.Prop([px, py], this.bushSprites[0]);
|
||||
this.scenery[y][x+1] = new Mario.Prop([px+16, py], this.bushSprites[1]);
|
||||
this.scenery[y][x+2] = new Mario.Prop([px+32, py], this.bushSprites[1]);
|
||||
this.scenery[y][x+3] = new Mario.Prop([px+48, py], this.bushSprites[2]);
|
||||
this.scenery[y][x + 1] = new Mario.Prop(
|
||||
[px + 16, py],
|
||||
this.bushSprites[1],
|
||||
);
|
||||
this.scenery[y][x + 2] = new Mario.Prop(
|
||||
[px + 32, py],
|
||||
this.bushSprites[1],
|
||||
);
|
||||
this.scenery[y][x + 3] = new Mario.Prop(
|
||||
[px + 48, py],
|
||||
this.bushSprites[2],
|
||||
);
|
||||
};
|
||||
|
||||
Level.prototype.putSmallHill = function (x, y) {
|
||||
var px = x*16, py = y*16;
|
||||
var px = x * 16,
|
||||
py = y * 16;
|
||||
this.scenery[y][x] = new Mario.Prop([px, py], this.hillSprites[0]);
|
||||
this.scenery[y][x+1] = new Mario.Prop([px+16, py], this.hillSprites[3]);
|
||||
this.scenery[y-1][x+1] = new Mario.Prop([px+16, py-16], this.hillSprites[1]);
|
||||
this.scenery[y][x+2] = new Mario.Prop([px+32, py], this.hillSprites[2]);
|
||||
this.scenery[y][x + 1] = new Mario.Prop(
|
||||
[px + 16, py],
|
||||
this.hillSprites[3],
|
||||
);
|
||||
this.scenery[y - 1][x + 1] = new Mario.Prop(
|
||||
[px + 16, py - 16],
|
||||
this.hillSprites[1],
|
||||
);
|
||||
this.scenery[y][x + 2] = new Mario.Prop(
|
||||
[px + 32, py],
|
||||
this.hillSprites[2],
|
||||
);
|
||||
};
|
||||
|
||||
Level.prototype.putTwoCloud = function (x, y) {
|
||||
px = x * 16;
|
||||
py = y * 16;
|
||||
this.scenery[y][x] = new Mario.Prop([px, py], this.cloudSprites[0]);
|
||||
this.scenery[y][x+1] = new Mario.Prop([px+16, py], this.cloudSprites[1]);
|
||||
this.scenery[y][x+2] = new Mario.Prop([px+32, py], this.cloudSprites[1]);
|
||||
this.scenery[y][x+3] = new Mario.Prop([px+48, py], this.cloudSprites[2]);
|
||||
this.scenery[y][x + 1] = new Mario.Prop(
|
||||
[px + 16, py],
|
||||
this.cloudSprites[1],
|
||||
);
|
||||
this.scenery[y][x + 2] = new Mario.Prop(
|
||||
[px + 32, py],
|
||||
this.cloudSprites[1],
|
||||
);
|
||||
this.scenery[y][x + 3] = new Mario.Prop(
|
||||
[px + 48, py],
|
||||
this.cloudSprites[2],
|
||||
);
|
||||
};
|
||||
|
||||
Level.prototype.putThreeCloud = function (x, y) {
|
||||
px = x * 16;
|
||||
py = y * 16;
|
||||
this.scenery[y][x] = new Mario.Prop([px, py], this.cloudSprites[0]);
|
||||
this.scenery[y][x+1] = new Mario.Prop([px+16, py], this.cloudSprites[1]);
|
||||
this.scenery[y][x+2] = new Mario.Prop([px+32, py], this.cloudSprites[1]);
|
||||
this.scenery[y][x+3] = new Mario.Prop([px+48, py], this.cloudSprites[1]);
|
||||
this.scenery[y][x+4] = new Mario.Prop([px+64, py], this.cloudSprites[2]);
|
||||
this.scenery[y][x + 1] = new Mario.Prop(
|
||||
[px + 16, py],
|
||||
this.cloudSprites[1],
|
||||
);
|
||||
this.scenery[y][x + 2] = new Mario.Prop(
|
||||
[px + 32, py],
|
||||
this.cloudSprites[1],
|
||||
);
|
||||
this.scenery[y][x + 3] = new Mario.Prop(
|
||||
[px + 48, py],
|
||||
this.cloudSprites[1],
|
||||
);
|
||||
this.scenery[y][x + 4] = new Mario.Prop(
|
||||
[px + 64, py],
|
||||
this.cloudSprites[2],
|
||||
);
|
||||
};
|
||||
|
||||
Level.prototype.putRealPipe = function(x, y, length, direction, destination) {
|
||||
Level.prototype.putRealPipe = function (
|
||||
x,
|
||||
y,
|
||||
length,
|
||||
direction,
|
||||
destination,
|
||||
) {
|
||||
px = x * 16;
|
||||
py = y * 16;
|
||||
this.pipes.push(new Mario.Pipe({
|
||||
this.pipes.push(
|
||||
new Mario.Pipe({
|
||||
pos: [px, py],
|
||||
length: length,
|
||||
direction: direction,
|
||||
destination: destination
|
||||
}));
|
||||
}
|
||||
destination: destination,
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
Level.prototype.putFlagpole = function (x) {
|
||||
this.statics[12][x] = new Mario.Floor([16 * x, 192], this.wallSprite);
|
||||
for (i = 3; i < 12; i++) {
|
||||
this.scenery[i][x] = new Mario.Prop([16*x, 16*i], this.flagpoleSprites[1])
|
||||
this.scenery[i][x] = new Mario.Prop(
|
||||
[16 * x, 16 * i],
|
||||
this.flagpoleSprites[1],
|
||||
);
|
||||
}
|
||||
this.scenery[2][x] = new Mario.Prop([16*x, 32], this.flagpoleSprites[0]);
|
||||
this.scenery[2][x] = new Mario.Prop(
|
||||
[16 * x, 32],
|
||||
this.flagpoleSprites[0],
|
||||
);
|
||||
this.items.push(new Mario.Flag(16 * x));
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
@@ -1,29 +1,28 @@
|
||||
(function () {
|
||||
if (typeof Mario === 'undefined')
|
||||
window.Mario = {};
|
||||
if (typeof Mario === "undefined") window.Mario = {};
|
||||
|
||||
var Mushroom = Mario.Mushroom = function(pos) {
|
||||
var Mushroom = (Mario.Mushroom = function (pos) {
|
||||
this.spawning = false;
|
||||
this.waiting = 0;
|
||||
|
||||
Mario.Entity.call(this, {
|
||||
pos: pos,
|
||||
sprite: level.superShroomSprite,
|
||||
hitbox: [0,0,16,16]
|
||||
hitbox: [0, 0, 16, 16],
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Mario.Util.inherits(Mushroom, Mario.Entity);
|
||||
|
||||
Mushroom.prototype.render = function (ctx, vX, vY) {
|
||||
if (this.spawning > 1) return;
|
||||
this.sprite.render(ctx, this.pos[0], this.pos[1], vX, vY);
|
||||
}
|
||||
};
|
||||
|
||||
Mushroom.prototype.spawn = function () {
|
||||
if (player.power > 0) {
|
||||
//replace this with a fire flower
|
||||
var ff = new Mario.Fireflower(this.pos)
|
||||
var ff = new Mario.Fireflower(this.pos);
|
||||
ff.spawn();
|
||||
return;
|
||||
}
|
||||
@@ -34,12 +33,12 @@
|
||||
this.targetpos = [];
|
||||
this.targetpos[0] = this.pos[0];
|
||||
this.targetpos[1] = this.pos[1] - 16;
|
||||
}
|
||||
};
|
||||
|
||||
Mushroom.prototype.update = function (dt) {
|
||||
if (this.spawning > 1) {
|
||||
this.spawning -= 1;
|
||||
if (this.spawning == 1) this.vel[1] = -.5;
|
||||
if (this.spawning == 1) this.vel[1] = -0.5;
|
||||
return;
|
||||
}
|
||||
if (this.spawning) {
|
||||
@@ -62,11 +61,11 @@
|
||||
this.pos[1] += this.vel[1];
|
||||
this.sprite.update(dt);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Mushroom.prototype.collideWall = function () {
|
||||
this.vel[0] = -this.vel[0];
|
||||
}
|
||||
};
|
||||
|
||||
Mushroom.prototype.checkCollisions = function () {
|
||||
if (this.spawning) {
|
||||
@@ -95,24 +94,39 @@
|
||||
}
|
||||
|
||||
this.isPlayerCollided();
|
||||
}
|
||||
};
|
||||
|
||||
//we have access to player everywhere, so let's just do this.
|
||||
Mushroom.prototype.isPlayerCollided = function () {
|
||||
//the first two elements of the hitbox array are an offset, so let's do this now.
|
||||
var hpos1 = [this.pos[0] + this.hitbox[0], this.pos[1] + this.hitbox[1]];
|
||||
var hpos2 = [player.pos[0] + player.hitbox[0], player.pos[1] + player.hitbox[1]];
|
||||
var hpos1 = [
|
||||
this.pos[0] + this.hitbox[0],
|
||||
this.pos[1] + this.hitbox[1],
|
||||
];
|
||||
var hpos2 = [
|
||||
player.pos[0] + player.hitbox[0],
|
||||
player.pos[1] + player.hitbox[1],
|
||||
];
|
||||
|
||||
//if the hitboxes actually overlap
|
||||
if (!(hpos1[0] > hpos2[0]+player.hitbox[2] || (hpos1[0]+this.hitbox[2] < hpos2[0]))) {
|
||||
if (!(hpos1[1] > hpos2[1]+player.hitbox[3] || (hpos1[1]+this.hitbox[3] < hpos2[1]))) {
|
||||
if (
|
||||
!(
|
||||
hpos1[0] > hpos2[0] + player.hitbox[2] ||
|
||||
hpos1[0] + this.hitbox[2] < hpos2[0]
|
||||
)
|
||||
) {
|
||||
if (
|
||||
!(
|
||||
hpos1[1] > hpos2[1] + player.hitbox[3] ||
|
||||
hpos1[1] + this.hitbox[3] < hpos2[1]
|
||||
)
|
||||
) {
|
||||
player.powerUp(this.idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Mushroom.prototype.bump = function () {
|
||||
this.vel[1] = -2;
|
||||
}
|
||||
|
||||
};
|
||||
})();
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
(function () {
|
||||
if (typeof Mario === 'undefined')
|
||||
window.Mario = {};
|
||||
|
||||
if (typeof Mario === "undefined") window.Mario = {};
|
||||
|
||||
//there are too many possible configurations of pipe to capture in a reasonable
|
||||
//set of simple variables. Joints, etc. are just too much.
|
||||
//To that end, the pipe class handles simple pipes, and we'll put together
|
||||
//anything more complex with individual props. OK? OK.
|
||||
Pipe = Mario.Pipe = function (options) {
|
||||
this.pos = options.pos
|
||||
this.pos = options.pos;
|
||||
|
||||
//NOTE: direction is the direction you move INTO the pipe.
|
||||
this.direction = options.direction
|
||||
this.destination = options.destination
|
||||
this.direction = options.direction;
|
||||
this.destination = options.destination;
|
||||
this.length = options.length;
|
||||
|
||||
if (this.direction === "UP" || this.direction === "DOWN") {
|
||||
@@ -24,41 +22,54 @@
|
||||
this.midsection = level.pipeSideMid;
|
||||
this.endsection = level.pipeLeft;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Pipe.prototype.checkPipe = function () {
|
||||
if (this.destination === undefined || !input.isDown(this.direction)) return;
|
||||
if (this.destination === undefined || !input.isDown(this.direction))
|
||||
return;
|
||||
|
||||
var h = player.power === 0 ? 16 : 32;
|
||||
var x = Math.floor(player.pos[0]);
|
||||
var y = Math.floor(player.pos[1]);
|
||||
switch (this.direction) {
|
||||
case 'RIGHT': if (x === this.pos[0]-16 &&
|
||||
case "RIGHT":
|
||||
if (
|
||||
x === this.pos[0] - 16 &&
|
||||
y >= this.pos[1] &&
|
||||
y+h <= this.pos[1]+32) {
|
||||
player.pipe(this.direction, this.destination)
|
||||
y + h <= this.pos[1] + 32
|
||||
) {
|
||||
player.pipe(this.direction, this.destination);
|
||||
}
|
||||
break;
|
||||
case 'LEFT': if (x === this.pos[0]+16*this.length &&
|
||||
case "LEFT":
|
||||
if (
|
||||
x === this.pos[0] + 16 * this.length &&
|
||||
y >= this.pos[1] &&
|
||||
y+h <= this.pos[1]+32) {
|
||||
player.pipe(this.direction, this.destination)
|
||||
y + h <= this.pos[1] + 32
|
||||
) {
|
||||
player.pipe(this.direction, this.destination);
|
||||
}
|
||||
break;
|
||||
case 'UP': if (y === this.pos[1] + 16*this.length &&
|
||||
case "UP":
|
||||
if (
|
||||
y === this.pos[1] + 16 * this.length &&
|
||||
x >= this.pos[0] &&
|
||||
x+16 <= this.pos[0]+32) {
|
||||
player.pipe(this.direction, this.destination)
|
||||
x + 16 <= this.pos[0] + 32
|
||||
) {
|
||||
player.pipe(this.direction, this.destination);
|
||||
}
|
||||
break;
|
||||
case 'DOWN': if (y+h === this.pos[1] &&
|
||||
case "DOWN":
|
||||
if (
|
||||
y + h === this.pos[1] &&
|
||||
x >= this.pos[0] &&
|
||||
x+16 <= this.pos[0]+32) {
|
||||
x + 16 <= this.pos[0] + 32
|
||||
) {
|
||||
player.pipe(this.direction, this.destination);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//Note to self: next time, decide on a convention for which thing checks for collisions
|
||||
//and stick to it. This is a pain.
|
||||
@@ -73,36 +84,57 @@
|
||||
});
|
||||
|
||||
fireballs.forEach(function (ent) {
|
||||
that.isCollideWith(ent)
|
||||
that.isCollideWith(ent);
|
||||
});
|
||||
|
||||
if (!player.piping) this.isCollideWith(player);
|
||||
}
|
||||
};
|
||||
|
||||
Pipe.prototype.isCollideWith = function (ent) {
|
||||
//long story short: because we scan every item, and and one 'rubble' item is four things with separate positions
|
||||
//we'll crash without this line as soon as we destroy a block. OOPS.
|
||||
if (ent.pos === undefined) return;
|
||||
|
||||
|
||||
//the first two elements of the hitbox array are an offset, so let's do this now.
|
||||
var hpos1 = [Math.floor(this.pos[0] + this.hitbox[0]), Math.floor(this.pos[1] + this.hitbox[1])];
|
||||
var hpos2 = [Math.floor(ent.pos[0] + ent.hitbox[0]), Math.floor(ent.pos[1] + ent.hitbox[1])];
|
||||
var hpos1 = [
|
||||
Math.floor(this.pos[0] + this.hitbox[0]),
|
||||
Math.floor(this.pos[1] + this.hitbox[1]),
|
||||
];
|
||||
var hpos2 = [
|
||||
Math.floor(ent.pos[0] + ent.hitbox[0]),
|
||||
Math.floor(ent.pos[1] + ent.hitbox[1]),
|
||||
];
|
||||
|
||||
//if the hitboxes actually overlap
|
||||
if (!(hpos1[0] > hpos2[0]+ent.hitbox[2] || (hpos1[0]+this.hitbox[2] < hpos2[0]))) {
|
||||
if (!(hpos1[1] > hpos2[1]+ent.hitbox[3] || (hpos1[1]+this.hitbox[3] < hpos2[1]))) {
|
||||
if (
|
||||
!(
|
||||
hpos1[0] > hpos2[0] + ent.hitbox[2] ||
|
||||
hpos1[0] + this.hitbox[2] < hpos2[0]
|
||||
)
|
||||
) {
|
||||
if (
|
||||
!(
|
||||
hpos1[1] > hpos2[1] + ent.hitbox[3] ||
|
||||
hpos1[1] + this.hitbox[3] < hpos2[1]
|
||||
)
|
||||
) {
|
||||
//if the entity is over the block, it's basically floor
|
||||
var center = hpos2[0] + ent.hitbox[2] / 2;
|
||||
if (Math.abs(hpos2[1] + ent.hitbox[3] - hpos1[1]) <= ent.vel[1]) {
|
||||
if (
|
||||
Math.abs(hpos2[1] + ent.hitbox[3] - hpos1[1]) <= ent.vel[1]
|
||||
) {
|
||||
ent.vel[1] = 0;
|
||||
ent.pos[1] = hpos1[1] - ent.hitbox[3] - ent.hitbox[1];
|
||||
ent.standing = true;
|
||||
if (ent instanceof Mario.Player) {
|
||||
ent.jumping = 0;
|
||||
}
|
||||
} else if (Math.abs(hpos2[1] - hpos1[1] - this.hitbox[3]) > ent.vel[1] &&
|
||||
center + 2 >= hpos1[0] && center - 2 <= hpos1[0] + this.hitbox[2]) {
|
||||
} else if (
|
||||
Math.abs(hpos2[1] - hpos1[1] - this.hitbox[3]) >
|
||||
ent.vel[1] &&
|
||||
center + 2 >= hpos1[0] &&
|
||||
center - 2 <= hpos1[0] + this.hitbox[2]
|
||||
) {
|
||||
//ent is under the block.
|
||||
ent.vel[1] = 0;
|
||||
ent.pos[1] = hpos1[1] + this.hitbox[3];
|
||||
@@ -115,14 +147,14 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//we COULD try to write some shenanigans so that the check gets put into the
|
||||
//collision code, but there won't ever be more than a handful of pipes in a level
|
||||
//so the performance hit of scanning all of them is miniscule.
|
||||
Pipe.prototype.update = function (dt) {
|
||||
if (this.destination) this.checkPipe();
|
||||
}
|
||||
};
|
||||
|
||||
//http://stackoverflow.com/questions/11227809/why-is-processing-a-sorted-array-faster-than-an-unsorted-array
|
||||
//I honestly have no idea if javascript does this, but I feel like it makes sense
|
||||
@@ -134,27 +166,63 @@
|
||||
case "DOWN":
|
||||
this.endsection.render(ctx, this.pos[0], this.pos[1], vX, vY);
|
||||
for (var i = 1; i < this.length; i++) {
|
||||
this.midsection.render(ctx, this.pos[0], this.pos[1]+i*16, vX, vY)
|
||||
this.midsection.render(
|
||||
ctx,
|
||||
this.pos[0],
|
||||
this.pos[1] + i * 16,
|
||||
vX,
|
||||
vY,
|
||||
);
|
||||
}
|
||||
break;
|
||||
case "UP":
|
||||
this.endsection.render(ctx, this.pos[0], this.pos[1]+16*(this.length-1), vX, vY)
|
||||
this.endsection.render(
|
||||
ctx,
|
||||
this.pos[0],
|
||||
this.pos[1] + 16 * (this.length - 1),
|
||||
vX,
|
||||
vY,
|
||||
);
|
||||
for (var i = 0; i < this.length - 1; i++) {
|
||||
this.midsection.render(ctx, this.pos[0], this.pos[1]+i*16, vX, vY)
|
||||
this.midsection.render(
|
||||
ctx,
|
||||
this.pos[0],
|
||||
this.pos[1] + i * 16,
|
||||
vX,
|
||||
vY,
|
||||
);
|
||||
}
|
||||
break;
|
||||
case "RIGHT":
|
||||
this.endsection.render(ctx, this.pos[0], this.pos[1], vX, vY)
|
||||
this.endsection.render(ctx, this.pos[0], this.pos[1], vX, vY);
|
||||
for (var i = 1; i < this.length; i++) {
|
||||
this.midsection.render(ctx, this.pos[0]+16*i, this.pos[1], vX, vY)
|
||||
this.midsection.render(
|
||||
ctx,
|
||||
this.pos[0] + 16 * i,
|
||||
this.pos[1],
|
||||
vX,
|
||||
vY,
|
||||
);
|
||||
}
|
||||
break;
|
||||
case "LEFT":
|
||||
this.endsection.render(ctx, this.pos[0]+16*(this.length-1), this.pos[1], vX, vY)
|
||||
this.endsection.render(
|
||||
ctx,
|
||||
this.pos[0] + 16 * (this.length - 1),
|
||||
this.pos[1],
|
||||
vX,
|
||||
vY,
|
||||
);
|
||||
for (var i = 0; i < this.legth - 1; i++) {
|
||||
this.midsection.render(ctx, this.pos[0], this.pos[1]+i*16, vX, vY)
|
||||
this.midsection.render(
|
||||
ctx,
|
||||
this.pos[0],
|
||||
this.pos[1] + i * 16,
|
||||
vX,
|
||||
vY,
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
(function () {
|
||||
if (typeof Mario === 'undefined')
|
||||
window.Mario = {};
|
||||
if (typeof Mario === "undefined") window.Mario = {};
|
||||
|
||||
var Player = Mario.Player = function(pos) {
|
||||
var Player = (Mario.Player = function (pos) {
|
||||
//I know, I know, there are a lot of variables tracking Mario's state.
|
||||
//Maybe these can be consolidated some way? We'll see once they're all in.
|
||||
this.power = 0;
|
||||
@@ -20,10 +19,15 @@
|
||||
|
||||
Mario.Entity.call(this, {
|
||||
pos: pos,
|
||||
sprite: new Mario.Sprite('sprites/player.png', [80,32],[16,16],0),
|
||||
hitbox: [0,0,16,16]
|
||||
sprite: new Mario.Sprite(
|
||||
"sprites/player.png",
|
||||
[80, 32],
|
||||
[16, 16],
|
||||
0,
|
||||
),
|
||||
hitbox: [0, 0, 16, 16],
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Mario.Util.inherits(Player, Mario.Entity);
|
||||
|
||||
@@ -33,7 +37,7 @@
|
||||
this.shoot();
|
||||
}
|
||||
this.runheld = true;
|
||||
}
|
||||
};
|
||||
|
||||
Player.prototype.shoot = function () {
|
||||
if (this.fireballs >= 2) return; //Projectile limit!
|
||||
@@ -41,13 +45,13 @@
|
||||
var fb = new Mario.Fireball([this.pos[0] + 8, this.pos[1]]); //I hate you, Javascript.
|
||||
fb.spawn(this.left);
|
||||
this.shooting = 2;
|
||||
}
|
||||
};
|
||||
|
||||
Player.prototype.noRun = function () {
|
||||
this.maxSpeed = 1.5;
|
||||
this.moveAcc = 0.07;
|
||||
this.runheld = false;
|
||||
}
|
||||
};
|
||||
|
||||
Player.prototype.moveRight = function () {
|
||||
//we're on the ground
|
||||
@@ -84,7 +88,6 @@
|
||||
this.vel[0] = 0;
|
||||
this.acc[0] = 0;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Player.prototype.crouch = function () {
|
||||
@@ -94,11 +97,11 @@
|
||||
}
|
||||
|
||||
if (this.standing) this.crouching = true;
|
||||
}
|
||||
};
|
||||
|
||||
Player.prototype.noCrouch = function () {
|
||||
this.crouching = false;
|
||||
}
|
||||
};
|
||||
|
||||
Player.prototype.jump = function () {
|
||||
if (this.vel[1] > 0) {
|
||||
@@ -136,8 +139,7 @@
|
||||
|
||||
if (this.starTime) {
|
||||
var index;
|
||||
if (this.starTime > 60)
|
||||
index = Math.floor(this.starTime / 2) % 3;
|
||||
if (this.starTime > 60) index = Math.floor(this.starTime / 2) % 3;
|
||||
else index = Math.floor(this.starTime / 8) % 3;
|
||||
|
||||
this.sprite.pos[1] = level.invincibility[index];
|
||||
@@ -147,9 +149,15 @@
|
||||
this.starTime -= 1;
|
||||
if (this.starTime == 0) {
|
||||
switch (this.power) {
|
||||
case 0: this.sprite.pos[1] = 32; break;
|
||||
case 1: this.sprite.pos[1] = 0; break;
|
||||
case 2: this.sprite.pos[1] = 96; break;
|
||||
case 0:
|
||||
this.sprite.pos[1] = 32;
|
||||
break;
|
||||
case 1:
|
||||
this.sprite.pos[1] = 0;
|
||||
break;
|
||||
case 2:
|
||||
this.sprite.pos[1] = 96;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -173,7 +181,10 @@
|
||||
} else {
|
||||
this.sprite.speed = Math.abs(this.vel[0]) * 8;
|
||||
}
|
||||
} else if ((this.vel[0] > 0 && this.left) || (this.vel[0] < 0 && !this.left)){
|
||||
} else if (
|
||||
(this.vel[0] > 0 && this.left) ||
|
||||
(this.vel[0] < 0 && !this.left)
|
||||
) {
|
||||
this.sprite.pos[0] = 144;
|
||||
this.sprite.speed = 0;
|
||||
}
|
||||
@@ -196,9 +207,9 @@
|
||||
|
||||
//which way are we facing?
|
||||
if (this.left) {
|
||||
this.sprite.img = 'sprites/playerl.png';
|
||||
this.sprite.img = "sprites/playerl.png";
|
||||
} else {
|
||||
this.sprite.img = 'sprites/player.png';
|
||||
this.sprite.img = "sprites/player.png";
|
||||
}
|
||||
};
|
||||
|
||||
@@ -238,7 +249,7 @@
|
||||
}
|
||||
|
||||
if (Math.abs(this.vel[0]) > this.maxSpeed) {
|
||||
this.vel[0] -= 0.05 * this.vel[0] / Math.abs(this.vel[0]);
|
||||
this.vel[0] -= (0.05 * this.vel[0]) / Math.abs(this.vel[0]);
|
||||
this.acc[0] = 0;
|
||||
}
|
||||
|
||||
@@ -252,9 +263,8 @@
|
||||
level.loader.call();
|
||||
input.reset();
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.acc[1] = 0.25
|
||||
} else {
|
||||
this.acc[1] = 0.25;
|
||||
if (this.pos[1] > 240) {
|
||||
this.die();
|
||||
}
|
||||
@@ -262,7 +272,7 @@
|
||||
|
||||
if (this.piping) {
|
||||
this.acc = [0, 0];
|
||||
var pos = [Math.round(this.pos[0]), Math.round(this.pos[1])]
|
||||
var pos = [Math.round(this.pos[0]), Math.round(this.pos[1])];
|
||||
if (pos[0] === this.targetPos[0] && pos[1] === this.targetPos[1]) {
|
||||
this.piping = false;
|
||||
this.pipeLoc.call();
|
||||
@@ -281,7 +291,8 @@
|
||||
this.sprite.size = [0, 0];
|
||||
this.vel = [0, 0];
|
||||
window.setTimeout(function () {
|
||||
player.sprite.size = player.power===0 ? [16,16] : [16,32];
|
||||
player.sprite.size =
|
||||
player.power === 0 ? [16, 16] : [16, 32];
|
||||
player.exiting = false;
|
||||
player.noInput = false;
|
||||
level.loader();
|
||||
@@ -318,7 +329,9 @@
|
||||
for (var i = 0; i < h; i++) {
|
||||
if (baseY + i < 0 || baseY + i >= 15) continue;
|
||||
for (var j = 0; j < w; j++) {
|
||||
if (baseY < 0) { i++;}
|
||||
if (baseY < 0) {
|
||||
i++;
|
||||
}
|
||||
if (level.statics[baseY + i][baseX + j]) {
|
||||
level.statics[baseY + i][baseX + j].isCollideWith(this);
|
||||
}
|
||||
@@ -331,23 +344,41 @@
|
||||
|
||||
Player.prototype.powerUp = function (idx) {
|
||||
sounds.powerup.play();
|
||||
this.powering = [0,5,2,5,1,5,2,5,1,5,2,5,3,5,1,5,2,5,3,5,1,5,4];
|
||||
this.powering = [
|
||||
0, 5, 2, 5, 1, 5, 2, 5, 1, 5, 2, 5, 3, 5, 1, 5, 2, 5, 3, 5, 1, 5, 4,
|
||||
];
|
||||
this.touchedItem = idx;
|
||||
|
||||
if (this.power === 0) {
|
||||
this.sprite.pos[0] = 80;
|
||||
var newy = this.sprite.pos[1] - 32;
|
||||
this.powerSprites = [[80, newy+32], [80, newy+32], [320, newy], [80, newy], [128, newy]];
|
||||
this.powerSizes = [[16,16],[16,16],[16,32],[16,32],[16,32]];
|
||||
this.powerSprites = [
|
||||
[80, newy + 32],
|
||||
[80, newy + 32],
|
||||
[320, newy],
|
||||
[80, newy],
|
||||
[128, newy],
|
||||
];
|
||||
this.powerSizes = [
|
||||
[16, 16],
|
||||
[16, 16],
|
||||
[16, 32],
|
||||
[16, 32],
|
||||
[16, 32],
|
||||
];
|
||||
this.shift = [0, 16, -16, 0, -16];
|
||||
this.power = 1;
|
||||
this.hitbox = [0, 0, 16, 32];
|
||||
} else if (this.power == 1) {
|
||||
var curx = this.sprite.pos[0];
|
||||
this.powerSprites = [[curx, 96], [curx, level.invincibility[0]],
|
||||
[curx, level.invincibility[1]], [curx, level.invincibility[2]],
|
||||
[curx, 96]];
|
||||
this.powerSizes[[16,32],[16,32],[16,32],[16,32],[16,32]];
|
||||
this.powerSprites = [
|
||||
[curx, 96],
|
||||
[curx, level.invincibility[0]],
|
||||
[curx, level.invincibility[1]],
|
||||
[curx, level.invincibility[2]],
|
||||
[curx, 96],
|
||||
];
|
||||
this.powerSizes[([16, 32], [16, 32], [16, 32], [16, 32], [16, 32])];
|
||||
this.shift = [0, 0, 0, 0, 0];
|
||||
this.power = 2;
|
||||
} else {
|
||||
@@ -358,15 +389,30 @@
|
||||
};
|
||||
|
||||
Player.prototype.damage = function () {
|
||||
if (this.power === 0) { //if you're already small, you dead!
|
||||
if (this.power === 0) {
|
||||
//if you're already small, you dead!
|
||||
this.die();
|
||||
} else { //otherwise, you get turned into small mario
|
||||
} else {
|
||||
//otherwise, you get turned into small mario
|
||||
sounds.pipe.play();
|
||||
this.powering = [0,5,1,5,2,5,1,5,2,5,1,5,2,5,1,5,2,5,1,5,2,5,3];
|
||||
this.powering = [
|
||||
0, 5, 1, 5, 2, 5, 1, 5, 2, 5, 1, 5, 2, 5, 1, 5, 2, 5, 1, 5, 2,
|
||||
5, 3,
|
||||
];
|
||||
this.shift = [0, 16, -16, 16];
|
||||
this.sprite.pos = [160, 0];
|
||||
this.powerSprites = [[160,0], [240, 32], [240, 0], [160, 32]];
|
||||
this.powerSizes = [[16, 32], [16,16], [16,32], [16,16]];
|
||||
this.powerSprites = [
|
||||
[160, 0],
|
||||
[240, 32],
|
||||
[240, 0],
|
||||
[160, 32],
|
||||
];
|
||||
this.powerSizes = [
|
||||
[16, 32],
|
||||
[16, 16],
|
||||
[16, 32],
|
||||
[16, 16],
|
||||
];
|
||||
this.invincibility = 120;
|
||||
this.power = 0;
|
||||
this.hitbox = [0, 0, 16, 16];
|
||||
@@ -390,7 +436,8 @@
|
||||
this.waiting = 0.5;
|
||||
this.dying = 2;
|
||||
|
||||
if (this.pos[1] < 240) { //falling into a pit doesn't do the animation.
|
||||
if (this.pos[1] < 240) {
|
||||
//falling into a pit doesn't do the animation.
|
||||
this.targetPos = [this.pos[0], this.pos[1] - 128];
|
||||
this.vel = [0, -5];
|
||||
} else {
|
||||
@@ -402,7 +449,7 @@
|
||||
Player.prototype.star = function (idx) {
|
||||
delete level.items[idx];
|
||||
this.starTime = 660;
|
||||
}
|
||||
};
|
||||
|
||||
Player.prototype.pipe = function (direction, destination) {
|
||||
sounds.pipe.play();
|
||||
@@ -411,29 +458,41 @@
|
||||
switch (direction) {
|
||||
case "LEFT":
|
||||
this.vel = [-1, 0];
|
||||
this.targetPos = [Math.round(this.pos[0]-16), Math.round(this.pos[1])]
|
||||
this.targetPos = [
|
||||
Math.round(this.pos[0] - 16),
|
||||
Math.round(this.pos[1]),
|
||||
];
|
||||
break;
|
||||
case "RIGHT":
|
||||
this.vel = [1, 0];
|
||||
this.targetPos = [Math.round(this.pos[0]+16), Math.round(this.pos[1])]
|
||||
this.targetPos = [
|
||||
Math.round(this.pos[0] + 16),
|
||||
Math.round(this.pos[1]),
|
||||
];
|
||||
break;
|
||||
case "DOWN":
|
||||
this.vel = [0, 1];
|
||||
this.targetPos = [Math.round(this.pos[0]), Math.round(this.pos[1]+this.hitbox[3])]
|
||||
this.targetPos = [
|
||||
Math.round(this.pos[0]),
|
||||
Math.round(this.pos[1] + this.hitbox[3]),
|
||||
];
|
||||
break;
|
||||
case "UP":
|
||||
this.vel = [0, -1];
|
||||
this.targetPos = [Math.round(this.pos[0]), Math.round(this.pos[1]-this.hitbox[3])]
|
||||
this.targetPos = [
|
||||
Math.round(this.pos[0]),
|
||||
Math.round(this.pos[1] - this.hitbox[3]),
|
||||
];
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Player.prototype.flag = function () {
|
||||
this.noInput = true;
|
||||
this.flagging = true;
|
||||
this.vel = [0, 2];
|
||||
this.acc = [0, 0];
|
||||
}
|
||||
};
|
||||
|
||||
Player.prototype.exit = function () {
|
||||
this.pos[0] += 16;
|
||||
@@ -442,5 +501,5 @@
|
||||
this.setAnimation();
|
||||
this.waiting = 1;
|
||||
this.exiting = true;
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
(function () {
|
||||
if (typeof Mario === 'undefined')
|
||||
window.Mario = {};
|
||||
if (typeof Mario === "undefined") window.Mario = {};
|
||||
|
||||
//props do even less than entities, so they don't need to inherit really
|
||||
var Prop = Mario.Prop = function(pos, sprite) {
|
||||
var Prop = (Mario.Prop = function (pos, sprite) {
|
||||
this.pos = pos;
|
||||
this.sprite = sprite;
|
||||
}
|
||||
});
|
||||
|
||||
//but we will be using the same Render, more or less.
|
||||
Prop.prototype.render = function (ctx, vX, vY) {
|
||||
this.sprite.render(ctx, this.pos[0], this.pos[1], vX, vY);
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
@@ -10,8 +10,7 @@
|
||||
urlOrArr.forEach(function (url) {
|
||||
_load(url);
|
||||
});
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
_load(urlOrArr);
|
||||
}
|
||||
}
|
||||
@@ -19,14 +18,15 @@
|
||||
function _load(url) {
|
||||
if (resourceCache[url]) {
|
||||
return resourceCache[url];
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
var img = new Image();
|
||||
img.onload = function () {
|
||||
resourceCache[url] = img;
|
||||
|
||||
if (isReady()) {
|
||||
readyCallbacks.forEach(function(func) { func(); });
|
||||
readyCallbacks.forEach(function (func) {
|
||||
func();
|
||||
});
|
||||
}
|
||||
};
|
||||
resourceCache[url] = false;
|
||||
@@ -41,8 +41,7 @@
|
||||
function isReady() {
|
||||
var ready = true;
|
||||
for (var k in resourceCache) {
|
||||
if(resourceCache.hasOwnProperty(k) &&
|
||||
!resourceCache[k]) {
|
||||
if (resourceCache.hasOwnProperty(k) && !resourceCache[k]) {
|
||||
ready = false;
|
||||
}
|
||||
}
|
||||
@@ -57,6 +56,6 @@
|
||||
load: load,
|
||||
get: get,
|
||||
onReady: onReady,
|
||||
isReady: isReady
|
||||
isReady: isReady,
|
||||
};
|
||||
})();
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
(function () {
|
||||
if (typeof Mario === 'undefined')
|
||||
window.Mario = {};
|
||||
if (typeof Mario === "undefined") window.Mario = {};
|
||||
|
||||
//TODO: make each rubble an entity, use that render and write in Entity.update
|
||||
var Rubble = Mario.Rubble = function() {
|
||||
var Rubble = (Mario.Rubble = function () {
|
||||
this.sprites = [];
|
||||
this.poss = [];
|
||||
this.vels = [];
|
||||
}
|
||||
});
|
||||
|
||||
Rubble.prototype.spawn = function (pos) {
|
||||
this.idx = level.items.length;
|
||||
@@ -24,12 +23,12 @@
|
||||
this.vels[1] = [1.25, -5];
|
||||
this.vels[2] = [-1.25, -3];
|
||||
this.vels[3] = [1.25, -3];
|
||||
}
|
||||
};
|
||||
|
||||
Rubble.prototype.update = function (dt) {
|
||||
for (var i = 0; i < 4; i++) {
|
||||
if (this.sprites[i] === undefined) continue;
|
||||
this.vels[i][1] += .3;
|
||||
this.vels[i][1] += 0.3;
|
||||
this.poss[i][0] += this.vels[i][0];
|
||||
this.poss[i][1] += this.vels[i][1];
|
||||
this.sprites[i].update(dt);
|
||||
@@ -37,19 +36,29 @@
|
||||
delete this.sprites[i];
|
||||
}
|
||||
}
|
||||
if (this.sprites.every(function (el) {return !el})) {
|
||||
if (
|
||||
this.sprites.every(function (el) {
|
||||
return !el;
|
||||
})
|
||||
) {
|
||||
delete level.items[this.idx];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//You might argue that things that can't collide are more like scenery
|
||||
//but these move and need to be deleted, and i'd rather deal with the 1d array.
|
||||
Rubble.prototype.checkCollisions = function() {;}
|
||||
Rubble.prototype.checkCollisions = function () {};
|
||||
|
||||
Rubble.prototype.render = function () {
|
||||
for (var i = 0; i < 4; i++) {
|
||||
if (this.sprites[i] === undefined) continue;
|
||||
this.sprites[i].render(ctx, this.poss[i][0], this.poss[i][1], vX, vY);
|
||||
}
|
||||
this.sprites[i].render(
|
||||
ctx,
|
||||
this.poss[i][0],
|
||||
this.poss[i][1],
|
||||
vX,
|
||||
vY,
|
||||
);
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
(function () {
|
||||
if (typeof Mario === 'undefined')
|
||||
window.Mario = {};
|
||||
if (typeof Mario === "undefined") window.Mario = {};
|
||||
|
||||
var Sprite = Mario.Sprite = function(img, pos, size, speed, frames, once) {
|
||||
var Sprite = (Mario.Sprite = function (
|
||||
img,
|
||||
pos,
|
||||
size,
|
||||
speed,
|
||||
frames,
|
||||
once,
|
||||
) {
|
||||
this.pos = pos;
|
||||
this.size = size;
|
||||
this.speed = speed;
|
||||
@@ -10,17 +16,17 @@
|
||||
this.img = img;
|
||||
this.once = once;
|
||||
this.frames = frames;
|
||||
}
|
||||
});
|
||||
|
||||
Sprite.prototype.update = function (dt, gameTime) {
|
||||
if (gameTime && gameTime == this.lastUpdated) return;
|
||||
this._index += this.speed * dt;
|
||||
if (gameTime) this.lastUpdated = gameTime;
|
||||
}
|
||||
};
|
||||
|
||||
Sprite.prototype.setFrame = function (frame) {
|
||||
this._index = frame;
|
||||
}
|
||||
};
|
||||
|
||||
Sprite.prototype.render = function (ctx, posx, posy, vX, vY) {
|
||||
var frame;
|
||||
@@ -42,6 +48,16 @@
|
||||
var y = this.pos[1];
|
||||
|
||||
x += frame * this.size[0];
|
||||
ctx.drawImage(resources.get(this.img), x + (1/3),y + (1/3), this.size[0] - (2/3), this.size[1] - (2/3), Math.round(posx - vX), Math.round(posy - vY), this.size[0],this.size[1]);
|
||||
}
|
||||
ctx.drawImage(
|
||||
resources.get(this.img),
|
||||
x + 1 / 3,
|
||||
y + 1 / 3,
|
||||
this.size[0] - 2 / 3,
|
||||
this.size[1] - 2 / 3,
|
||||
Math.round(posx - vX),
|
||||
Math.round(posy - vY),
|
||||
this.size[0],
|
||||
this.size[1],
|
||||
);
|
||||
};
|
||||
})();
|
||||
|
||||
@@ -1,24 +1,23 @@
|
||||
(function () {
|
||||
if (typeof Mario === 'undefined')
|
||||
window.Mario = {};
|
||||
if (typeof Mario === "undefined") window.Mario = {};
|
||||
|
||||
var Star = Mario.Star = function(pos) {
|
||||
var Star = (Mario.Star = function (pos) {
|
||||
this.spawning = false;
|
||||
this.waiting = 0;
|
||||
|
||||
Mario.Entity.call(this, {
|
||||
pos: pos,
|
||||
sprite: level.starSprite,
|
||||
hitbox: [0,0,16,16]
|
||||
hitbox: [0, 0, 16, 16],
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Mario.Util.inherits(Star, Mario.Entity);
|
||||
|
||||
Star.prototype.render = function (ctx, vX, vY) {
|
||||
if (this.spawning > 1) return;
|
||||
this.sprite.render(ctx, this.pos[0], this.pos[1], vX, vY);
|
||||
}
|
||||
};
|
||||
|
||||
Star.prototype.spawn = function () {
|
||||
this.idx = level.items.length;
|
||||
@@ -27,12 +26,12 @@
|
||||
this.targetpos = [];
|
||||
this.targetpos[0] = this.pos[0];
|
||||
this.targetpos[1] = this.pos[1] - 16;
|
||||
}
|
||||
};
|
||||
|
||||
Star.prototype.update = function (dt) {
|
||||
if (this.spawning > 1) {
|
||||
this.spawning -= 1;
|
||||
if (this.spawning == 1) this.vel[1] = -.5;
|
||||
if (this.spawning == 1) this.vel[1] = -0.5;
|
||||
return;
|
||||
}
|
||||
if (this.spawning) {
|
||||
@@ -60,11 +59,11 @@
|
||||
this.pos[1] += this.vel[1];
|
||||
this.sprite.update(dt);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Star.prototype.collideWall = function () {
|
||||
this.vel[0] = -this.vel[0];
|
||||
}
|
||||
};
|
||||
|
||||
Star.prototype.checkCollisions = function () {
|
||||
if (this.spawning) {
|
||||
@@ -93,24 +92,39 @@
|
||||
}
|
||||
|
||||
this.isPlayerCollided();
|
||||
}
|
||||
};
|
||||
|
||||
//we have access to player everywhere, so let's just do this.
|
||||
Star.prototype.isPlayerCollided = function () {
|
||||
//the first two elements of the hitbox array are an offset, so let's do this now.
|
||||
var hpos1 = [this.pos[0] + this.hitbox[0], this.pos[1] + this.hitbox[1]];
|
||||
var hpos2 = [player.pos[0] + player.hitbox[0], player.pos[1] + player.hitbox[1]];
|
||||
var hpos1 = [
|
||||
this.pos[0] + this.hitbox[0],
|
||||
this.pos[1] + this.hitbox[1],
|
||||
];
|
||||
var hpos2 = [
|
||||
player.pos[0] + player.hitbox[0],
|
||||
player.pos[1] + player.hitbox[1],
|
||||
];
|
||||
|
||||
//if the hitboxes actually overlap
|
||||
if (!(hpos1[0] > hpos2[0]+player.hitbox[2] || (hpos1[0]+this.hitbox[2] < hpos2[0]))) {
|
||||
if (!(hpos1[1] > hpos2[1]+player.hitbox[3] || (hpos1[1]+this.hitbox[3] < hpos2[1]))) {
|
||||
if (
|
||||
!(
|
||||
hpos1[0] > hpos2[0] + player.hitbox[2] ||
|
||||
hpos1[0] + this.hitbox[2] < hpos2[0]
|
||||
)
|
||||
) {
|
||||
if (
|
||||
!(
|
||||
hpos1[1] > hpos2[1] + player.hitbox[3] ||
|
||||
hpos1[1] + this.hitbox[3] < hpos2[1]
|
||||
)
|
||||
) {
|
||||
player.star(this.idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Star.prototype.bump = function () {
|
||||
this.vel[1] = -2;
|
||||
}
|
||||
|
||||
};
|
||||
})();
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user