sources
1
sources
|
@ -1 +0,0 @@
|
||||||
Subproject commit df2369883cc1a6af96370758c91196ddd593fd8c
|
|
93
sources/License.txt
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
Kshitij Banerjee is the owner of this work and distributes his work subject to the following license.
|
||||||
|
|
||||||
|
Creative Commons Attribution-NonCommercial 4.0 International Public License
|
||||||
|
|
||||||
|
By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-NonCommercial 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions.
|
||||||
|
|
||||||
|
Section 1 – Definitions
|
||||||
|
|
||||||
|
Adapted Material means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. For purposes of this Public License, where the Licensed Material is a musical work, performance, or sound recording, Adapted Material is always produced where the Licensed Material is synched in timed relation with a moving image.
|
||||||
|
Adapter's License means the license You apply to Your Copyright and Similar Rights in Your contributions to Adapted Material in accordance with the terms and conditions of this Public License.
|
||||||
|
Copyright and Similar Rights means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this Public License, the rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights.
|
||||||
|
Effective Technological Measures means those measures that, in the absence of proper authority, may not be circumvented under laws fulfilling obligations under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, and/or similar international agreements.
|
||||||
|
Exceptions and Limitations means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material.
|
||||||
|
Licensed Material means the artistic or literary work, database, or other material to which the Licensor applied this Public License.
|
||||||
|
Licensed Rights means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license.
|
||||||
|
Licensor means the individual(s) or entity(ies) granting rights under this Public License.
|
||||||
|
NonCommercial means not primarily intended for or directed towards commercial advantage or monetary compensation. For purposes of this Public License, the exchange of the Licensed Material for other material subject to Copyright and Similar Rights by digital file-sharing or similar means is NonCommercial provided there is no payment of monetary compensation in connection with the exchange.
|
||||||
|
Share means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them.
|
||||||
|
Sui Generis Database Rights means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world.
|
||||||
|
You means the individual or entity exercising the Licensed Rights under this Public License. Your has a corresponding meaning.
|
||||||
|
Section 2 – Scope.
|
||||||
|
|
||||||
|
License grant.
|
||||||
|
Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to:
|
||||||
|
reproduce and Share the Licensed Material, in whole or in part, for NonCommercial purposes only; and
|
||||||
|
produce, reproduce, and Share Adapted Material for NonCommercial purposes only.
|
||||||
|
Exceptions and Limitations. For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions.
|
||||||
|
Term. The term of this Public License is specified in Section 6(a).
|
||||||
|
Media and formats; technical modifications allowed. The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section 2(a)(4) never produces Adapted Material.
|
||||||
|
Downstream recipients.
|
||||||
|
Offer from the Licensor – Licensed Material. Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License.
|
||||||
|
No downstream restrictions. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material.
|
||||||
|
No endorsement. Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i).
|
||||||
|
Other rights.
|
||||||
|
|
||||||
|
Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise.
|
||||||
|
Patent and trademark rights are not licensed under this Public License.
|
||||||
|
To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties, including when the Licensed Material is used other than for NonCommercial purposes.
|
||||||
|
Section 3 – License Conditions.
|
||||||
|
|
||||||
|
Your exercise of the Licensed Rights is expressly made subject to the following conditions.
|
||||||
|
|
||||||
|
Attribution.
|
||||||
|
|
||||||
|
If You Share the Licensed Material (including in modified form), You must:
|
||||||
|
|
||||||
|
retain the following if it is supplied by the Licensor with the Licensed Material:
|
||||||
|
identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated);
|
||||||
|
a copyright notice;
|
||||||
|
a notice that refers to this Public License;
|
||||||
|
a notice that refers to the disclaimer of warranties;
|
||||||
|
a URI or hyperlink to the Licensed Material to the extent reasonably practicable;
|
||||||
|
indicate if You modified the Licensed Material and retain an indication of any previous modifications; and
|
||||||
|
indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License.
|
||||||
|
You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information.
|
||||||
|
If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable.
|
||||||
|
If You Share Adapted Material You produce, the Adapter's License You apply must not prevent recipients of the Adapted Material from complying with this Public License.
|
||||||
|
Section 4 – Sui Generis Database Rights.
|
||||||
|
|
||||||
|
Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material:
|
||||||
|
|
||||||
|
for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database for NonCommercial purposes only;
|
||||||
|
if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material; and
|
||||||
|
You must comply with the conditions in Section 3(a) if You Share all or a substantial portion of the contents of the database.
|
||||||
|
For the avoidance of doubt, this Section 4 supplements and does not replace Your obligations under this Public License where the Licensed Rights include other Copyright and Similar Rights.
|
||||||
|
Section 5 – Disclaimer of Warranties and Limitation of Liability.
|
||||||
|
|
||||||
|
Unless otherwise separately undertaken by the Licensor, to the extent possible, the Licensor offers the Licensed Material as-is and as-available, and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You.
|
||||||
|
To the extent possible, in no event will the Licensor be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this Public License or use of the Licensed Material, even if the Licensor has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You.
|
||||||
|
The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability.
|
||||||
|
Section 6 – Term and Termination.
|
||||||
|
|
||||||
|
This Public License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this Public License, then Your rights under this Public License terminate automatically.
|
||||||
|
Where Your right to use the Licensed Material has terminated under Section 6(a), it reinstates:
|
||||||
|
|
||||||
|
automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or
|
||||||
|
upon express reinstatement by the Licensor.
|
||||||
|
For the avoidance of doubt, this Section 6(b) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License.
|
||||||
|
For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this Public License.
|
||||||
|
Sections 1, 5, 6, 7, and 8 survive termination of this Public License.
|
||||||
|
Section 7 – Other Terms and Conditions.
|
||||||
|
|
||||||
|
The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed.
|
||||||
|
Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License.
|
||||||
|
Section 8 – Interpretation.
|
||||||
|
|
||||||
|
For the avoidance of doubt, this Public License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this Public License.
|
||||||
|
To the extent possible, if any provision of this Public License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this Public License without affecting the enforceability of the remaining terms and conditions.
|
||||||
|
No term or condition of this Public License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor.
|
||||||
|
Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority.
|
||||||
|
Creative Commons is not a party to its public licenses. Notwithstanding, Creative Commons may elect to apply one of its public licenses to material it publishes and in those instances will be considered the “Licensor.” Except for the limited purpose of indicating that material is shared under a Creative Commons public license or as otherwise permitted by the Creative Commons policies published at creativecommons.org/policies, Creative Commons does not authorize the use of the trademark “Creative Commons” or any other trademark or logo of Creative Commons without its prior written consent including, without limitation, in connection with any unauthorized modifications to any of its public licenses or any other arrangements, understandings, or agreements concerning use of licensed material. For the avoidance of doubt, this paragraph does not form part of the public licenses.
|
||||||
|
|
||||||
|
Creative Commons may be contacted at creativecommons.org.
|
13
sources/README.md
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
Cubiks-2048
|
||||||
|
===========
|
||||||
|
|
||||||
|
**Game:**
|
||||||
|
Create the number 2048. Cubes with same number merge!
|
||||||
|
|
||||||
|
===========
|
||||||
|
**HOW TO PLAY:**
|
||||||
|
* Use arrow keys to rotate the cube.
|
||||||
|
* Use space bar or mouse click to view all cubes.
|
||||||
|
* Everything falls down by gravity. Topple the cubes over one another
|
||||||
|
|
||||||
|
<a rel="license" href="http://creativecommons.org/licenses/by-nc/4.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-nc/4.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc/4.0/">Creative Commons Attribution-NonCommercial 4.0 International License</a>..
|
BIN
sources/Textures/Texture_1024.gif
Normal file
After Width: | Height: | Size: 9.2 KiB |
BIN
sources/Textures/Texture_128.gif
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
sources/Textures/Texture_16.gif
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
sources/Textures/Texture_2.gif
Normal file
After Width: | Height: | Size: 2 KiB |
BIN
sources/Textures/Texture_2048.gif
Normal file
After Width: | Height: | Size: 6.9 KiB |
BIN
sources/Textures/Texture_256.gif
Normal file
After Width: | Height: | Size: 9.1 KiB |
BIN
sources/Textures/Texture_32.gif
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
sources/Textures/Texture_4.gif
Normal file
After Width: | Height: | Size: 2 KiB |
BIN
sources/Textures/Texture_512.gif
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
sources/Textures/Texture_64.gif
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
sources/Textures/Texture_8.gif
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
sources/imgs/Demo_2.png
Normal file
After Width: | Height: | Size: 84 KiB |
BIN
sources/imgs/Demo_start.png
Normal file
After Width: | Height: | Size: 84 KiB |
BIN
sources/imgs/badge.png
Normal file
After Width: | Height: | Size: 3 KiB |
128
sources/index.html
Normal file
|
@ -0,0 +1,128 @@
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||||
|
<meta name="description" content="A 3D version of 2048. Best intuitive alternative to 2048 puzzle game." />
|
||||||
|
<meta name="keywords" content="2048, 3D, cubiks, webgl, puzzle, game, rubik's, cube, brain, teaser" />
|
||||||
|
<meta property="og:title" content="3D cubiks 2048 ">
|
||||||
|
<meta property="og:description" content="A 3D version of 2048. Best intuitive alternative to 2048 puzzle game." />
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title> Cubiks-2048 3D</title>
|
||||||
|
|
||||||
|
<link rel="stylesheet" type="text/css" href="./styles/container.css">
|
||||||
|
<script>
|
||||||
|
(function (i, s, o, g, r, a, m) {
|
||||||
|
i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
|
||||||
|
(i[r].q = i[r].q || []).push(arguments)
|
||||||
|
}, i[r].l = 1 * new Date(); a = s.createElement(o),
|
||||||
|
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
|
||||||
|
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
|
||||||
|
|
||||||
|
ga('create', 'UA-50428840-1', 'kshitij-banerjee.github.io');
|
||||||
|
ga('require', 'displayfeatures');
|
||||||
|
ga('send', 'pageview');
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div id="fb-root"></div>
|
||||||
|
<script>
|
||||||
|
(function (d, s, id) {
|
||||||
|
var js, fjs = d.getElementsByTagName(s)[0];
|
||||||
|
if (d.getElementById(id)) return;
|
||||||
|
js = d.createElement(s); js.id = id;
|
||||||
|
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.0";
|
||||||
|
fjs.parentNode.insertBefore(js, fjs);
|
||||||
|
}(document, 'script', 'facebook-jssdk'));</script>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- <h1 style="font-size :80px ; text-align:center"> Cube-2048</h1> -->
|
||||||
|
<script src="./libs/jquery.min.js"> </script>
|
||||||
|
<script src="./libs/three.js"> </script>
|
||||||
|
<script src="./libs/keyboard.js"></script>
|
||||||
|
<script src="./libs/Tween.js"></script>
|
||||||
|
<script src="./js/cube.js"></script>
|
||||||
|
<script src="./js/gravity.js"></script>
|
||||||
|
<script src="./js/Game.js"></script>
|
||||||
|
<script src="./js/rotation_anim.js"></script>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<div class="heading">
|
||||||
|
<h1 class="title">Cubik's 2048</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="above-game">
|
||||||
|
<p class="game-intro"><strong>Topple</strong> the cubes over one another.<br>When two cubes of the same number touch, they <strong>merge</strong> into one!<br> Get to the <strong>2048 cube to win! </strong></p>
|
||||||
|
<a class="restart-button">New Game</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<img src="./imgs/Demo_start.png" class="demo-start">
|
||||||
|
<img src="./imgs/Demo_2.png" class="demo-2">
|
||||||
|
|
||||||
|
<div id="game_container" class="game-container" >
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p class="game-explanation">
|
||||||
|
<strong class="important">How to play:</strong> Use your <strong>arrow keys</strong> to rotate the cube.<br>
|
||||||
|
Use <strong>space bar or mouse click</strong> to view from above. Everything <strong>falls</strong> down!<br>
|
||||||
|
Use <strong>Enter</strong> to recollapse on the same configuration<br><br />
|
||||||
|
<strong>Topple</strong> the cubes over one another.<br> When two cubes of the same number touch, they <strong>merge</strong> into one! <br>
|
||||||
|
Get to the <strong>2048 cube to win! </strong>
|
||||||
|
</p>
|
||||||
|
<hr>
|
||||||
|
<p>
|
||||||
|
Created by <a href="mailto:kshitij_libra%40yahoo.com?subject=give_me_the_app&body=Hi%2C%0A%0AI%20would%20like%20this%20game%20on%20my%20phone.%20Please%20create%20an%20app%20for%20%3Cyour-OS%3E%20mobile.%0A%0ARegards%2C%20%0A%3Cyourname%3E">Kshitij Banerjee</a>, Inspired by <a href="http://gabrielecirulli.github.io/2048/" target="_blank">2048 by Gabriele Cirulli</a>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Good karmas are rewarded with free mobile versions :) Dont forget to send me your details!
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<a href="http://www.chromeexperiments.com/detail/cubiks-2048/"><img src="imgs/badge.png" alt="See my Experiment on ChromeExperiments.com" /></a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<form class="pp-donate" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
|
||||||
|
<input type="hidden" name="cmd" value="_s-xclick">
|
||||||
|
<input type="hidden" name="hosted_button_id" value="GQKCW8P7MBKD4">
|
||||||
|
<button class="donate_button" name="submit"><img src="meta/pp.svg">Donate</button>
|
||||||
|
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a data-size="large" href="https://twitter.com/share/?text=Check out this amazing 3D version of 2048 @ " class="twitter-share-button" data-lang="en">Tweet</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div class="fb-share-button" data-href="http://kshitij-banerjee.github.io/Cubiks-2048/" data-type="button_count"></div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a target="_blank" style="font-size:x-large"href="http://www.reddit.com/r/2048/comments/24hcjl/3d_2048_with_webgl_technology/" > <img src="http://sc.reddit.com/static/spreddit5.gif" alt="submit to reddit" border="0"> Discuss!</a>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<br />
|
||||||
|
<a rel="license" href="http://creativecommons.org/licenses/by-nc/4.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-nc/4.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc/4.0/">Creative Commons Attribution-NonCommercial 4.0 International License</a>.
|
||||||
|
<script>
|
||||||
|
!function (d, s, id) {
|
||||||
|
var js, fjs = d.getElementsByTagName(s)[0];
|
||||||
|
if (!d.getElementById(id))
|
||||||
|
{
|
||||||
|
js = d.createElement(s); js.id = id; js.src = "https://platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs);
|
||||||
|
}
|
||||||
|
}(document, "script", "twitter-wjs");
|
||||||
|
</script>
|
||||||
|
<br>
|
||||||
|
<br />
|
||||||
|
<div class="fb-comments" data-href="http://kshitij-banerjee.github.io/Cubiks-2048/" data-width="500" data-numposts="10" data-colorscheme="light"></div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<script src="./js/main.js"></script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
5
sources/index_2.html
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<iframe src="./index.html" width="1000" height="1400" > </iframe>
|
||||||
|
</body>
|
||||||
|
</html>
|
45
sources/js/Debug.js
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
// DEBUG information....
|
||||||
|
cube_debug = new THREE.Object3D();
|
||||||
|
volumeGeometry = new THREE.CubeGeometry(100/5,33/5,100/5, 3, 1, 3);
|
||||||
|
volumeMaterial = new THREE.MeshBasicMaterial({
|
||||||
|
color : 0x0099ff,
|
||||||
|
wireframe : true,
|
||||||
|
transparent : true,
|
||||||
|
opacity : 0.4
|
||||||
|
});
|
||||||
|
volumeMesh = new THREE.Mesh(volumeGeometry, volumeMaterial);
|
||||||
|
volumeMesh.position.set( -50, 0 , 0 );
|
||||||
|
cube_debug.add(volumeMesh);
|
||||||
|
|
||||||
|
volumeGeometry = new THREE.CubeGeometry(100/5,33/5,100/5, 3, 1, 3);
|
||||||
|
volumeMaterial = new THREE.MeshBasicMaterial({
|
||||||
|
color : 0x002245,
|
||||||
|
wireframe : true,
|
||||||
|
transparent : true,
|
||||||
|
opacity : 0.4
|
||||||
|
});
|
||||||
|
volumeMesh = new THREE.Mesh(volumeGeometry, volumeMaterial);
|
||||||
|
volumeMesh.position.set( -50, -33, 0 );
|
||||||
|
cube_debug.add(volumeMesh);
|
||||||
|
|
||||||
|
volumeGeometry = new THREE.CubeGeometry(100/5,33/5,100/5, 3, 1, 3);
|
||||||
|
volumeMaterial = new THREE.MeshBasicMaterial({
|
||||||
|
color : 0x00ff25,
|
||||||
|
wireframe : true,
|
||||||
|
transparent : true,
|
||||||
|
opacity : 0.4
|
||||||
|
});
|
||||||
|
volumeMesh = new THREE.Mesh(volumeGeometry, volumeMaterial);
|
||||||
|
volumeMesh.position.set( -50, -66, 0 );
|
||||||
|
cube_debug.add(volumeMesh);
|
||||||
|
|
||||||
|
var arrowHelper = new THREE.ArrowHelper( new THREE.Vector3( 0, 0, 0 ),
|
||||||
|
new THREE.Vector3( 0, 1, 0 ), 33, 0xffff00 );
|
||||||
|
arrowHelper.setDirection( new THREE.Vector3( 0, -1, 0 ) );
|
||||||
|
arrowHelper.position.set( -50, 0 , 0 );
|
||||||
|
cube_debug.add( arrowHelper );
|
||||||
|
|
||||||
|
var axis_debug = new THREE.AxisHelper(5) ;
|
||||||
|
axis_debug.position.set( -5, 0, 0 );
|
||||||
|
cube_debug.add( axis_debug );
|
||||||
|
cube_group.add( cube_debug );
|
499
sources/js/Game.js
Normal file
|
@ -0,0 +1,499 @@
|
||||||
|
function createcoord() {
|
||||||
|
this.x = 0;
|
||||||
|
this.y = 0;
|
||||||
|
this.z = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
function GAME(size) {
|
||||||
|
this.game_size = size;
|
||||||
|
this.cube_count = size * size * size;
|
||||||
|
this.filled_cubes = 0;
|
||||||
|
this.cube_array = {};
|
||||||
|
|
||||||
|
// Initialize the array .
|
||||||
|
|
||||||
|
for (var i = 0 ; i < this.cube_count; i++) {
|
||||||
|
this.cube_array[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.gravity = new threeD_vector();
|
||||||
|
this.coord = new createcoord();
|
||||||
|
|
||||||
|
this.removal_queue = [];
|
||||||
|
this.premerges = [];
|
||||||
|
this.five_one_two_anims = {};
|
||||||
|
|
||||||
|
this.add_random_cube( 2 );
|
||||||
|
this.shift_cubes();
|
||||||
|
|
||||||
|
this.showing_view = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
GAME.prototype.create_random_number = function (limit) {
|
||||||
|
return Math.floor(Math.random() * 100) % limit;
|
||||||
|
};
|
||||||
|
|
||||||
|
GAME.prototype.index_to_ijk = function ( rand )
|
||||||
|
{
|
||||||
|
coord = new createcoord();
|
||||||
|
coord.z = Math.floor(rand / (this.game_size * this.game_size)); // z level
|
||||||
|
rand = rand % (this.game_size * this.game_size); // remaining in level
|
||||||
|
|
||||||
|
coord.y = Math.floor(rand / this.game_size);
|
||||||
|
coord.x = rand % this.game_size;
|
||||||
|
return coord;
|
||||||
|
};
|
||||||
|
|
||||||
|
GAME.prototype.get_coord = function (rand, coord) {
|
||||||
|
var coord = this.index_to_ijk(rand);
|
||||||
|
coord.x = Math.floor(coord.x - Math.floor(this.game_size / 2));
|
||||||
|
coord.y = Math.floor(coord.y - Math.floor(this.game_size / 2));
|
||||||
|
coord.z = Math.floor(coord.z - Math.floor(this.game_size / 2));
|
||||||
|
|
||||||
|
coord.x *= (100 / this.game_size);
|
||||||
|
coord.y *= (100/ this.game_size);
|
||||||
|
coord.z *= (100 / this.game_size);
|
||||||
|
|
||||||
|
return coord;
|
||||||
|
};
|
||||||
|
|
||||||
|
GAME.prototype.coord_to_index = function( i, j, k ){
|
||||||
|
var numb = 0;
|
||||||
|
numb += this.game_size * this.game_size * k;
|
||||||
|
numb += j * this.game_size;
|
||||||
|
numb += i;
|
||||||
|
|
||||||
|
return numb;
|
||||||
|
};
|
||||||
|
|
||||||
|
GAME.prototype.add_random_cube = function ( count ) {
|
||||||
|
|
||||||
|
if (count == 0)
|
||||||
|
{
|
||||||
|
while (this.premerges.length)
|
||||||
|
this.premerges.pop();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( this.filled_cubes == this.cube_count )
|
||||||
|
return;
|
||||||
|
|
||||||
|
var rand = this.create_random_number(this.cube_count);
|
||||||
|
|
||||||
|
while (this.cube_array[rand] != 0 ) {
|
||||||
|
rand++;
|
||||||
|
if (rand == this.cube_count)
|
||||||
|
rand = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.coord = this.get_coord( rand );
|
||||||
|
|
||||||
|
var cube = create_inner_cube(33);
|
||||||
|
cube.position.set(this.coord.x, this.coord.y, this.coord.z);
|
||||||
|
cube.scale = { x: 0.0, y: 0.0, z: 0.0 };
|
||||||
|
var scaling = 1.0;
|
||||||
|
new TWEEN.Tween(cube.scale).to({ x: scaling, y: scaling, z: scaling }, 300).delay(400).start();
|
||||||
|
new TWEEN.Tween(cube.material).to({ opacity:1.0},300).delay(400).start();
|
||||||
|
cube_group.add(cube);
|
||||||
|
this.cube_array[rand] = cube;
|
||||||
|
|
||||||
|
this.filled_cubes++;
|
||||||
|
var ijk = this.index_to_ijk(rand);
|
||||||
|
this.sift_cube( ijk.x, ijk.y, ijk.z, this.gravity.direction );
|
||||||
|
this.add_random_cube(--count);
|
||||||
|
};
|
||||||
|
|
||||||
|
function get_map_id( map )
|
||||||
|
{
|
||||||
|
var underscore_idx = map.sourceFile.indexOf("_");
|
||||||
|
var dot_idx = map.sourceFile.lastIndexOf(".");
|
||||||
|
var index = map.sourceFile.substring(++underscore_idx, dot_idx);
|
||||||
|
return parseInt(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
function next_map(map) {
|
||||||
|
var index = get_map_id( map );
|
||||||
|
return index + index;
|
||||||
|
};
|
||||||
|
|
||||||
|
GAME.prototype.is_in_bound = function( i2, j2 , k2 ){
|
||||||
|
if( i2 < 0 || i2 >= this.game_size)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if( j2 < 0 || j2 >= this.game_size)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if( k2 < 0 || k2 >= this.game_size)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
GAME.prototype.get_512_and_above_count = function () {
|
||||||
|
var count = 0;
|
||||||
|
|
||||||
|
for (var i = 0; i < this.cube_count; i++) {
|
||||||
|
if( this.cube_array[i] != 0 )
|
||||||
|
if (get_map_id(this.cube_array[i].material.map) >= 512)
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
};
|
||||||
|
|
||||||
|
GAME.prototype.do_texture_events = function (index, index2, i2, j2, k2) {
|
||||||
|
var next_texture = this.cube_array[index].material.map;
|
||||||
|
|
||||||
|
// Win!
|
||||||
|
if (next_texture == textures[2048]) {
|
||||||
|
TWEEN.removeAll();
|
||||||
|
this.view_sides( true );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Almost there!
|
||||||
|
else if (next_texture == textures[512]) {
|
||||||
|
|
||||||
|
var go = new TWEEN.Tween(this.cube_array[index].scale)
|
||||||
|
.to({ x: 1.2, y: 1.2, z: 1.2 }, 500)
|
||||||
|
.easing(TWEEN.Easing.Sinusoidal.In)
|
||||||
|
.start();
|
||||||
|
|
||||||
|
var back = new TWEEN.Tween(this.cube_array[index].scale)
|
||||||
|
.to({ x: 1.0, y: 1.0, z: 1.0 }, 500)
|
||||||
|
.easing(TWEEN.Easing.Sinusoidal.In);
|
||||||
|
|
||||||
|
go.chain(back);
|
||||||
|
back.chain(go);
|
||||||
|
|
||||||
|
// Record these for future..
|
||||||
|
|
||||||
|
this.five_one_two_anims[ this.cube_array[index].uuid ] = go;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
GAME.prototype.merge_cubes = function(last_index)
|
||||||
|
{
|
||||||
|
// Remove from 512 array as well
|
||||||
|
|
||||||
|
if (this.five_one_two_anims[this.cube_array[last_index].uuid ] != undefined) {
|
||||||
|
this.five_one_two_anims[this.cube_array[last_index].uuid].stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cube to be removed expands a little.
|
||||||
|
this.removal_queue.push(this.cube_array[last_index]);
|
||||||
|
this.cube_array[last_index].transparent = false;
|
||||||
|
this.cube_array[last_index] = 0;
|
||||||
|
this.filled_cubes--;
|
||||||
|
|
||||||
|
|
||||||
|
var length = 200;
|
||||||
|
var tween = new TWEEN.Tween(this.removal_queue[0].scale).
|
||||||
|
to({ x: 1.3, y: 1.3, z: 1.3 }, length).
|
||||||
|
easing(TWEEN.Easing.Sinusoidal.In)
|
||||||
|
.start();
|
||||||
|
|
||||||
|
var tween2 = new TWEEN.Tween(this.removal_queue[0].scale).
|
||||||
|
to({ x: 1.0, y: 1.0, z: 1.0 }, length/2).
|
||||||
|
easing(TWEEN.Easing.Sinusoidal.In)
|
||||||
|
.onComplete(function () {
|
||||||
|
|
||||||
|
// Remove from removal queue of settles..
|
||||||
|
|
||||||
|
var removal = CUBE2048.removal_queue.shift();
|
||||||
|
cube_group.remove(removal);
|
||||||
|
delete removal;
|
||||||
|
});
|
||||||
|
|
||||||
|
tween.chain(tween2);
|
||||||
|
};
|
||||||
|
|
||||||
|
GAME.prototype.is_premerged = function ( cube ) {
|
||||||
|
|
||||||
|
for (var i = 0; i < this.premerges.length ; i++) {
|
||||||
|
if (this.premerges[i] == cube)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
var counter = 0;
|
||||||
|
GAME.prototype.sift_cube = function ( i, j, k, direction ) {
|
||||||
|
|
||||||
|
var start_index = this.coord_to_index(i, j, k)
|
||||||
|
|
||||||
|
this.coord = this.get_coord( start_index );
|
||||||
|
|
||||||
|
// No cube at this location.
|
||||||
|
if (this.cube_array[start_index] == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var i2 = i + direction.x;
|
||||||
|
var j2 = j + direction.y;
|
||||||
|
var k2 = k + direction.z;
|
||||||
|
var last_index = this.coord_to_index(i2, j2, k2);
|
||||||
|
|
||||||
|
while( this.is_in_bound( i2, j2, k2) && (this.cube_array[last_index] == 0) )
|
||||||
|
{
|
||||||
|
i2 += direction.x;
|
||||||
|
j2 += direction.y;
|
||||||
|
k2 += direction.z;
|
||||||
|
|
||||||
|
last_index = this.coord_to_index(i2, j2, k2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Either we are out of bound or we are filled..
|
||||||
|
|
||||||
|
if( this.is_in_bound( i2, j2, k2) )
|
||||||
|
{
|
||||||
|
// We found an existing cube. Is it the same texture?
|
||||||
|
// If this was from a previous merge.skip..
|
||||||
|
|
||||||
|
if ( !this.is_premerged(this.cube_array[last_index])
|
||||||
|
&& (this.cube_array[start_index] != 0)
|
||||||
|
&& (this.cube_array[last_index] != 0)
|
||||||
|
&& (this.cube_array[start_index].material.map == this.cube_array[last_index].material.map))
|
||||||
|
{
|
||||||
|
this.merge_cubes( last_index );
|
||||||
|
var next_text = next_map( this.cube_array[start_index].material.map );
|
||||||
|
//console.log("Merging " + start_index + " with " + last_index + " New texture : " + next_text);
|
||||||
|
|
||||||
|
this.cube_array[start_index].material.map = textures[next_text];
|
||||||
|
|
||||||
|
// Dont merge on this again.
|
||||||
|
this.premerges.push(this.cube_array[start_index]);
|
||||||
|
|
||||||
|
if ( this.do_texture_events(start_index, last_index, i2, j2, k2) )
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// Move to the next free block.
|
||||||
|
i2 -= direction.x;
|
||||||
|
j2 -= direction.y;
|
||||||
|
k2 -= direction.z;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// Move to the next free block.
|
||||||
|
i2 -= direction.x;
|
||||||
|
j2 -= direction.y;
|
||||||
|
k2 -= direction.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
start_index = this.coord_to_index( i, j, k );
|
||||||
|
last_index = this.coord_to_index( i2, j2, k2 );
|
||||||
|
|
||||||
|
|
||||||
|
if (start_index == last_index)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var start_coord = new createcoord();
|
||||||
|
var last_coord = new createcoord();
|
||||||
|
|
||||||
|
var start_coord = this.get_coord( start_index );
|
||||||
|
var last_coord = this.get_coord( last_index );
|
||||||
|
|
||||||
|
//console.log("Final coord : \t" + last_coord.x + "\t " + last_coord.y+ "\t " + last_coord.z);
|
||||||
|
|
||||||
|
this.settled = false;
|
||||||
|
new TWEEN.Tween(this.cube_array[start_index].position)
|
||||||
|
.to({ x: last_coord.x, y: last_coord.y, z: last_coord.z }, 600)
|
||||||
|
.easing(TWEEN.Easing.Bounce.Out)
|
||||||
|
.onComplete( function (){ CUBE2048.settled = true;} )
|
||||||
|
.start();
|
||||||
|
|
||||||
|
this.cube_array[last_index] = this.cube_array[start_index];
|
||||||
|
this.cube_array[start_index] = 0;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
GAME.prototype.shift_cubes = function () {
|
||||||
|
var shifted = false;
|
||||||
|
if (this.gravity.direction.x != 0) {
|
||||||
|
var start = this.gravity.direction.x > 0 ? this.game_size-1 : 0;
|
||||||
|
var end = this.gravity.direction.x > 0 ? -1 : this.game_size;
|
||||||
|
|
||||||
|
start -= this.gravity.direction.x;
|
||||||
|
|
||||||
|
for (var i = start; i != end ; i -= this.gravity.direction.x) {
|
||||||
|
for (var j = 0 ; j < this.game_size; j++) {
|
||||||
|
for (var k = 0; k < this.game_size; k++) {
|
||||||
|
shifted |= this.sift_cube(i, j, k, this.gravity.direction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (this.gravity.direction.y != 0)
|
||||||
|
{
|
||||||
|
var start = this.gravity.direction.y > 0 ? this.game_size-1 : 0;
|
||||||
|
var end = this.gravity.direction.y > 0 ? -1 : this.game_size;
|
||||||
|
start -= this.gravity.direction.y;
|
||||||
|
|
||||||
|
for (var j = start; j != end ; j -= this.gravity.direction.y) {
|
||||||
|
for (var i = 0 ; i < this.game_size; i++) {
|
||||||
|
for (var k = 0; k < this.game_size; k++) {
|
||||||
|
shifted |= this.sift_cube(i, j, k, this.gravity.direction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (this.gravity.direction.z != 0) {
|
||||||
|
var start = this.gravity.direction.z > 0 ? this.game_size-1 : 0;
|
||||||
|
var end = this.gravity.direction.z > 0 ? -1 : this.game_size;
|
||||||
|
start -= this.gravity.direction.z;
|
||||||
|
for (var k = start; k != end ; k -= this.gravity.direction.z) {
|
||||||
|
for (var i = 0 ; i < this.game_size; i++) {
|
||||||
|
for (var j = 0; j < this.game_size; j++) {
|
||||||
|
shifted |= this.sift_cube(i, j, k, this.gravity.direction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return shifted;
|
||||||
|
};
|
||||||
|
|
||||||
|
GAME.prototype.translate = function (i, j, k, direction) {
|
||||||
|
var start_index = this.coord_to_index(i, j, k);
|
||||||
|
var coord = this.get_coord(start_index, coord);
|
||||||
|
if (this.cube_array[start_index] != 0) {
|
||||||
|
new TWEEN.Tween(this.cube_array[start_index].position)
|
||||||
|
.to({
|
||||||
|
x: coord.x + (121 * direction.x),
|
||||||
|
y: coord.y + (121 * direction.y),
|
||||||
|
z: coord.z + (121 * direction.z)
|
||||||
|
}, 100)
|
||||||
|
.start();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
GAME.prototype.view_sides = function ( is_win ) {
|
||||||
|
|
||||||
|
if (TWEEN.getAll().length > this.get_512_and_above_count())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (this.showing_view)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var right = this.gravity.right();
|
||||||
|
var left = new THREE.Vector3(0, 0, 0);
|
||||||
|
left.copy( right );
|
||||||
|
left.negate();
|
||||||
|
|
||||||
|
var dirs = [];
|
||||||
|
dirs.push( left );
|
||||||
|
dirs.push( new THREE.Vector3(0, 0, 0) );
|
||||||
|
dirs.push( right );
|
||||||
|
|
||||||
|
if (this.gravity.direction.x != 0) {
|
||||||
|
var start = this.gravity.direction.x > 0 ? this.game_size - 1 : 0;
|
||||||
|
var end = this.gravity.direction.x > 0 ? -1 : this.game_size;
|
||||||
|
|
||||||
|
for (var i = start; i != end ; i -= this.gravity.direction.x) {
|
||||||
|
for (var j = 0 ; j < this.game_size; j++) {
|
||||||
|
for (var k = 0; k < this.game_size; k++) {
|
||||||
|
this.translate(i, j, k, dirs[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (this.gravity.direction.y != 0) {
|
||||||
|
var start = this.gravity.direction.y > 0 ? this.game_size - 1 : 0;
|
||||||
|
var end = this.gravity.direction.y > 0 ? -1 : this.game_size;
|
||||||
|
for (var j = start; j != end ; j -= this.gravity.direction.y) {
|
||||||
|
for (var i = 0 ; i < this.game_size; i++) {
|
||||||
|
for (var k = 0; k < this.game_size; k++) {
|
||||||
|
this.translate(i, j, k, dirs[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (this.gravity.direction.z != 0) {
|
||||||
|
var start = this.gravity.direction.z > 0 ? this.game_size - 1 : 0;
|
||||||
|
var end = this.gravity.direction.z > 0 ? -1 : this.game_size;
|
||||||
|
for (var k = start; k != end ; k -= this.gravity.direction.z) {
|
||||||
|
for (var i = 0 ; i < this.game_size; i++) {
|
||||||
|
for (var j = 0; j < this.game_size; j++) {
|
||||||
|
this.translate(i, j, k, dirs[k]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_win) {
|
||||||
|
new TWEEN.Tween(camera.position)
|
||||||
|
.to({
|
||||||
|
x: camera.position.x,
|
||||||
|
y: camera.position.y + 100,
|
||||||
|
z: camera.position.z
|
||||||
|
}, 150)
|
||||||
|
.onUpdate(function () {
|
||||||
|
camera.lookAt(new THREE.Vector3(50, 50, 0));
|
||||||
|
})
|
||||||
|
.delay( 2000 )
|
||||||
|
.onComplete(function () {
|
||||||
|
renderer.render(scene, camera);
|
||||||
|
alert(" Did you just win? !!");
|
||||||
|
release('Yes you did! You won! Yay!! :) ');
|
||||||
|
})
|
||||||
|
.start();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
new TWEEN.Tween(camera.position)
|
||||||
|
.to({
|
||||||
|
x: camera.position.x,
|
||||||
|
y: camera.position.y + 100,
|
||||||
|
z: camera.position.z
|
||||||
|
}, 150)
|
||||||
|
.onUpdate(function () {
|
||||||
|
camera.lookAt(new THREE.Vector3(50, 50, 0));
|
||||||
|
})
|
||||||
|
.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
this.showing_view = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
GAME.prototype.reset_positions = function()
|
||||||
|
{
|
||||||
|
|
||||||
|
if (!this.showing_view)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for( var i = 0 ; i < this.cube_count ; i ++ )
|
||||||
|
{
|
||||||
|
if (this.cube_array[i] != 0) {
|
||||||
|
var coord = this.get_coord( i );
|
||||||
|
new TWEEN.Tween(this.cube_array[i].position)
|
||||||
|
.to({ x: coord.x, y: coord.y, z: coord.z }, 100)
|
||||||
|
.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
new TWEEN.Tween(camera.position)
|
||||||
|
.to({
|
||||||
|
x: 50,
|
||||||
|
y: dist/5,
|
||||||
|
z: dist/6
|
||||||
|
},100)
|
||||||
|
.onUpdate(function () {
|
||||||
|
camera.lookAt(new THREE.Vector3(50, 50, 0));
|
||||||
|
})
|
||||||
|
.start();
|
||||||
|
|
||||||
|
this.showing_view = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
76
sources/js/cube.js
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
function create_inner_cube(cube_dim) {
|
||||||
|
var offset = 0;
|
||||||
|
|
||||||
|
cube_dim -= offset;
|
||||||
|
cube_geo = new THREE.CubeGeometry(cube_dim, cube_dim, cube_dim);
|
||||||
|
|
||||||
|
var texture = null;
|
||||||
|
|
||||||
|
texture = textures[2];
|
||||||
|
|
||||||
|
cube_mat = new THREE.MeshBasicMaterial({ map: texture, transparent: true, opacity: 0.5 });
|
||||||
|
return new THREE.Mesh(cube_geo, cube_mat);
|
||||||
|
};
|
||||||
|
|
||||||
|
function create_frame(frame_dim) {
|
||||||
|
var frame = new THREE.BoxHelper();
|
||||||
|
frame.material.color.setRGB(0, 0, 0);
|
||||||
|
frame.material.transparent = true;
|
||||||
|
frame.scale.set(frame_dim, frame_dim, frame_dim);
|
||||||
|
return frame;
|
||||||
|
};
|
||||||
|
|
||||||
|
function bind_keyboard_keys() {
|
||||||
|
|
||||||
|
KeyboardJS.on('down', function () { // Rotate about x clockwise.
|
||||||
|
|
||||||
|
if (!rotation_animation.is_animating()) {
|
||||||
|
rotation_animation.animation_residue = rotation_animation.animation_duration;
|
||||||
|
rotation_animation.rotation_direction = +1;
|
||||||
|
rotation_animation.rotate_x = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
KeyboardJS.on('up', function () { // Rotate about x anti-clockwise
|
||||||
|
|
||||||
|
if (!rotation_animation.is_animating()) {
|
||||||
|
|
||||||
|
rotation_animation.animation_residue = rotation_animation.animation_duration;
|
||||||
|
rotation_animation.rotation_direction = -1;
|
||||||
|
rotation_animation.rotate_x = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
KeyboardJS.on('left', function () { // Rotate about z anticlockwise
|
||||||
|
|
||||||
|
|
||||||
|
if (!rotation_animation.is_animating()) {
|
||||||
|
rotation_animation.animation_residue = rotation_animation.animation_duration;
|
||||||
|
rotation_animation.rotation_direction = +1
|
||||||
|
rotation_animation.rotate_z = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
KeyboardJS.on('right', function () { // Rotate about z clockwise
|
||||||
|
|
||||||
|
if (!rotation_animation.is_animating()) {
|
||||||
|
rotation_animation.animation_residue = rotation_animation.animation_duration;
|
||||||
|
rotation_animation.rotation_direction = -1;
|
||||||
|
rotation_animation.rotate_z = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
KeyboardJS.on('enter', function () {
|
||||||
|
if( CUBE2048.shift_cubes() )
|
||||||
|
CUBE2048.add_random_cube(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
KeyboardJS.on("space",
|
||||||
|
function () {
|
||||||
|
CUBE2048.view_sides()
|
||||||
|
},
|
||||||
|
function () {
|
||||||
|
CUBE2048.reset_positions()
|
||||||
|
});
|
||||||
|
};
|
60
sources/js/gravity.js
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
function threeD_vector() {
|
||||||
|
this.direction = new THREE.Vector3(0, -1, 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
function normalize( x )
|
||||||
|
{
|
||||||
|
if( x > 0 )
|
||||||
|
{
|
||||||
|
if( x < 0.001 )
|
||||||
|
x = 0;
|
||||||
|
else if( x > 0.99 )
|
||||||
|
x = 1;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if( x > -0.001 )
|
||||||
|
x = 0;
|
||||||
|
else if( x < -0.99 )
|
||||||
|
x = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return x;
|
||||||
|
};
|
||||||
|
|
||||||
|
threeD_vector.prototype.rotate = function (angle, axis) {
|
||||||
|
|
||||||
|
var dir = new THREE.Vector3( 0, -1, 0 );
|
||||||
|
|
||||||
|
var quat = new THREE.Quaternion();
|
||||||
|
quat.copy( cube_group.quaternion );
|
||||||
|
quat.inverse();
|
||||||
|
|
||||||
|
dir.applyQuaternion( quat );
|
||||||
|
|
||||||
|
dir.x = normalize( dir.x );
|
||||||
|
dir.y = normalize( dir.y );
|
||||||
|
dir.z = normalize( dir.z );
|
||||||
|
|
||||||
|
this.direction = dir;
|
||||||
|
|
||||||
|
// $("#i").text(this.direction.x);
|
||||||
|
// $("#j").text(this.direction.y);
|
||||||
|
// $("#k").text(this.direction.z);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
threeD_vector.prototype.right = function () {
|
||||||
|
var dir = new THREE.Vector3(1, 0, 0);
|
||||||
|
|
||||||
|
var quat = new THREE.Quaternion();
|
||||||
|
quat.copy(cube_group.quaternion);
|
||||||
|
quat.inverse();
|
||||||
|
|
||||||
|
dir.applyQuaternion(quat);
|
||||||
|
|
||||||
|
dir.x = normalize(dir.x);
|
||||||
|
dir.y = normalize(dir.y);
|
||||||
|
dir.z = normalize(dir.z);
|
||||||
|
|
||||||
|
return dir;
|
||||||
|
}
|
274
sources/js/main.js
Normal file
|
@ -0,0 +1,274 @@
|
||||||
|
var renderer, scene, camera, cube_group;
|
||||||
|
var cube_size = 3;
|
||||||
|
var CUBE2048;
|
||||||
|
var X_axis = new THREE.Vector3(1, 0, 0);
|
||||||
|
var Y_axis = new THREE.Vector3(0, 1, 0);
|
||||||
|
var Z_axis = new THREE.Vector3(0, 0, 1);
|
||||||
|
|
||||||
|
var textures;
|
||||||
|
|
||||||
|
var clock = new THREE.Clock();
|
||||||
|
var container = $("#game_container");
|
||||||
|
var dist;
|
||||||
|
var height_zoom = container.height() / 5;
|
||||||
|
var width_zoom = container.width() / 5;
|
||||||
|
init();
|
||||||
|
|
||||||
|
animate();
|
||||||
|
|
||||||
|
function init() {
|
||||||
|
|
||||||
|
$(".demo-start").click(function () {
|
||||||
|
$(".demo-2").width('69vw');
|
||||||
|
$(".demo-2").height('38.8vw');
|
||||||
|
|
||||||
|
$(".demo-start").height('0%');
|
||||||
|
});
|
||||||
|
|
||||||
|
$(".demo-2").click(function () {
|
||||||
|
$(".demo-2").width('0%');
|
||||||
|
$(".demo-2").height('0%');
|
||||||
|
|
||||||
|
$(".demo-start").width('0%');
|
||||||
|
$(".demo-start").height('0%');
|
||||||
|
|
||||||
|
$("#game_container").show();
|
||||||
|
release();
|
||||||
|
});
|
||||||
|
|
||||||
|
textures = {
|
||||||
|
2: THREE.ImageUtils.loadTexture('./Textures/Texture_2.gif'),
|
||||||
|
4: THREE.ImageUtils.loadTexture('./Textures/Texture_4.gif'),
|
||||||
|
8: THREE.ImageUtils.loadTexture('./Textures/Texture_8.gif'),
|
||||||
|
16: THREE.ImageUtils.loadTexture('./Textures/Texture_16.gif'),
|
||||||
|
32: THREE.ImageUtils.loadTexture('./Textures/Texture_32.gif'),
|
||||||
|
64: THREE.ImageUtils.loadTexture('./Textures/Texture_64.gif'),
|
||||||
|
128: THREE.ImageUtils.loadTexture('./Textures/Texture_128.gif'),
|
||||||
|
256: THREE.ImageUtils.loadTexture('./Textures/Texture_256.gif'),
|
||||||
|
512: THREE.ImageUtils.loadTexture('./Textures/Texture_512.gif'),
|
||||||
|
1024: THREE.ImageUtils.loadTexture('./Textures/Texture_1024.gif'),
|
||||||
|
2048: THREE.ImageUtils.loadTexture('./Textures/Texture_2048.gif')
|
||||||
|
};
|
||||||
|
|
||||||
|
scene = new THREE.Scene();
|
||||||
|
// The plane platform.
|
||||||
|
|
||||||
|
var plane = new THREE.PlaneGeometry(1000, 1000, 100, 100);
|
||||||
|
var plane_mat = new THREE.MeshBasicMaterial({ color: 0x708090, transparent: true, opacity: 0.4 });
|
||||||
|
var plane_mesh = new THREE.Mesh(plane, plane_mat);
|
||||||
|
scene.add(plane_mesh);
|
||||||
|
plane_mesh.position.set(50, -1000 / cube_size, 0);
|
||||||
|
plane_mesh.rotation.x -= 1.5;
|
||||||
|
|
||||||
|
// Cameras
|
||||||
|
|
||||||
|
var aspect = container.width() / container.height();
|
||||||
|
camera = new THREE.PerspectiveCamera(60, aspect, 1, 10000);
|
||||||
|
|
||||||
|
var vFOV = camera.fov * Math.PI / 180; // convert vertical fov to radians
|
||||||
|
dist = 1000 / (2 * Math.tan(vFOV / 2)) ; // visible height
|
||||||
|
|
||||||
|
camera.position.set(50, dist/5, dist/6);
|
||||||
|
camera.lookAt(new THREE.Vector3(50, 50, 0));
|
||||||
|
scene.add(camera);
|
||||||
|
|
||||||
|
// Lights
|
||||||
|
|
||||||
|
var spotLight = new THREE.SpotLight(0xffffff);
|
||||||
|
spotLight.position.set(300, 300, 300);
|
||||||
|
scene.add(spotLight);
|
||||||
|
scene.add(new THREE.AmbientLight(0xffffff));
|
||||||
|
|
||||||
|
// Geometries
|
||||||
|
cube_group = new THREE.Object3D();
|
||||||
|
cube_group.position.set(50, 50, 0);
|
||||||
|
|
||||||
|
//==================================================
|
||||||
|
// Insert debug code from debug.js here...
|
||||||
|
//==================================================
|
||||||
|
|
||||||
|
// Refresh the game.
|
||||||
|
|
||||||
|
CUBE2048 = new GAME(3);
|
||||||
|
|
||||||
|
scene.add(cube_group);
|
||||||
|
|
||||||
|
// Renderer
|
||||||
|
try{
|
||||||
|
renderer = new THREE.WebGLRenderer({ antialias: true });
|
||||||
|
renderer.setSize( container.width(), container.height());
|
||||||
|
renderer.setClearColor(0xe9eaed);
|
||||||
|
|
||||||
|
// Add the canvas to the dom.
|
||||||
|
|
||||||
|
$("#game_container").append(renderer.domElement);
|
||||||
|
$("#game_container").hide(); // Add the canvas to the dom.
|
||||||
|
|
||||||
|
}
|
||||||
|
catch( ex ){
|
||||||
|
alert(" Your Browser does not support this games technology.. Get chrome/mozilla!");
|
||||||
|
$(".container").text(" Your browser is unsupported/not updated. Please get the latest version of chrome/mozilla to play.");
|
||||||
|
$(".container").append(" <br><br> For Safari: <br><br> Open the Safari menu and select Preferences.<br> <br> Then, click the Advanced tab in the Preferences window.<br> <br> Then, at the bottom of the window, check the Show Develop menu in menu bar checkbox.<br> <br> Then, open the Develop menu in the menu bar and select Enable WebGL.<br> <br> Have fun!<br> " );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make the outer frame..
|
||||||
|
|
||||||
|
var outer_frame = create_frame(50);
|
||||||
|
cube_group.add(outer_frame);
|
||||||
|
|
||||||
|
// And fade it away...
|
||||||
|
|
||||||
|
new TWEEN.Tween(outer_frame.material)
|
||||||
|
.to({ opacity: 0.0 }, 5000)
|
||||||
|
.onComplete(function () {
|
||||||
|
cube_group.remove(outer_frame);
|
||||||
|
})
|
||||||
|
.start();
|
||||||
|
|
||||||
|
|
||||||
|
// Add the mouse events
|
||||||
|
|
||||||
|
$("#game_container").mousedown(function () {
|
||||||
|
CUBE2048.view_sides();
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#game_container").mouseup(function () {
|
||||||
|
CUBE2048.reset_positions();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Keyboard events..
|
||||||
|
|
||||||
|
bind_keyboard_keys();
|
||||||
|
|
||||||
|
// Buttons..
|
||||||
|
|
||||||
|
$(".restart-button").click(function () {
|
||||||
|
release();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener("keydown", function (e) {
|
||||||
|
// space and arrow keys
|
||||||
|
if ([32, 37, 38, 39, 40].indexOf(e.keyCode) > -1) {
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
|
||||||
|
function animate() {
|
||||||
|
requestAnimationFrame(animate);
|
||||||
|
TWEEN.update();
|
||||||
|
|
||||||
|
if (rotation_animation.is_animating()) {
|
||||||
|
if (rotation_animation.rotate_x) {
|
||||||
|
if (rotation_animation.animation_residue > 0)
|
||||||
|
rotateAroundWorldAxis(cube_group, X_axis, rotation_animation.rotation_direction * rotation_animation.get_offset());
|
||||||
|
|
||||||
|
if (--rotation_animation.animation_residue == -10) {
|
||||||
|
rotation_animation.rotate_x = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rotation_animation.animation_residue == 0) {
|
||||||
|
CUBE2048.gravity.rotate((-rotation_animation.rotation_direction) * Math.PI / 2, X_axis);
|
||||||
|
if( CUBE2048.shift_cubes() )
|
||||||
|
{
|
||||||
|
CUBE2048.add_random_cube(2);
|
||||||
|
}
|
||||||
|
else if (CUBE2048.filled_cubes == CUBE2048.cube_count)
|
||||||
|
{
|
||||||
|
renderer.render(scene, camera);
|
||||||
|
release('Game Over!!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (rotation_animation.rotate_y) {
|
||||||
|
if (rotation_animation.animation_residue > 0)
|
||||||
|
rotateAroundWorldAxis(cube_group, Y_axis, rotation_animation.rotation_direction * rotation_animation.get_offset());
|
||||||
|
|
||||||
|
if (--rotation_animation.animation_residue == -10) {
|
||||||
|
rotation_animation.rotate_y = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rotation_animation.animation_residue == 0) {
|
||||||
|
CUBE2048.gravity.rotate((-rotation_animation.rotation_direction) * Math.PI / 2, Y_axis);
|
||||||
|
if( CUBE2048.shift_cubes() )
|
||||||
|
{
|
||||||
|
CUBE2048.add_random_cube(2);
|
||||||
|
}
|
||||||
|
else if (CUBE2048.filled_cubes == CUBE2048.cube_count) {
|
||||||
|
renderer.render(scene, camera);
|
||||||
|
release('Game Over!!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (rotation_animation.rotate_z) {
|
||||||
|
if(rotation_animation.animation_residue > 0 )
|
||||||
|
rotateAroundWorldAxis(cube_group, Z_axis, rotation_animation.rotation_direction * rotation_animation.get_offset());
|
||||||
|
|
||||||
|
if (--rotation_animation.animation_residue == -10) {
|
||||||
|
rotation_animation.rotate_z = false;
|
||||||
|
}
|
||||||
|
if (rotation_animation.animation_residue == 0) {
|
||||||
|
CUBE2048.gravity.rotate((-rotation_animation.rotation_direction) * Math.PI / 2, Z_axis);
|
||||||
|
if( CUBE2048.shift_cubes() )
|
||||||
|
{
|
||||||
|
CUBE2048.add_random_cube(2);
|
||||||
|
}
|
||||||
|
else if (CUBE2048.filled_cubes == CUBE2048.cube_count) {
|
||||||
|
renderer.render(scene, camera);
|
||||||
|
release('Game Over!!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer.render(scene, camera);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
function release(msg) {
|
||||||
|
|
||||||
|
$("canvas").css({ opacity: 0.5 });
|
||||||
|
|
||||||
|
if (msg != undefined)
|
||||||
|
alert(msg);
|
||||||
|
|
||||||
|
$("#game_container").empty();
|
||||||
|
|
||||||
|
var len = cube_group.children.length;
|
||||||
|
for (var i = 0 ; i < len ; i++) {
|
||||||
|
cube_group.remove(cube_group.children[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
len = scene.children.length;
|
||||||
|
for (var i = 0 ; i < len; i++) {
|
||||||
|
scene.remove(scene.children[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer.render(scene, camera);
|
||||||
|
|
||||||
|
delete CUBE2048;
|
||||||
|
delete cube_group;
|
||||||
|
delete scene;
|
||||||
|
delete camera;
|
||||||
|
delete renderer;
|
||||||
|
|
||||||
|
KeyboardJS.clear('down');
|
||||||
|
KeyboardJS.clear('up');
|
||||||
|
KeyboardJS.clear('left');
|
||||||
|
KeyboardJS.clear('right');
|
||||||
|
KeyboardJS.clear('space');
|
||||||
|
KeyboardJS.clear('enter');
|
||||||
|
|
||||||
|
|
||||||
|
// Restart..
|
||||||
|
|
||||||
|
init();
|
||||||
|
$("#game_container").show();
|
||||||
|
};
|
32
sources/js/rotation_anim.js
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
function rot_animation(angle_in) {
|
||||||
|
this.animation_duration = 10; // 2 seconds apprx
|
||||||
|
this.angle = angle_in;
|
||||||
|
this.animation_residue = 0;
|
||||||
|
this.rotate_x = false;
|
||||||
|
this.rotate_y = false;
|
||||||
|
this.rotate_z = false;
|
||||||
|
this.rotation_direction = +1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
rot_animation.prototype.is_animating = function () {
|
||||||
|
return (this.rotate_x || this.rotate_y || this.rotate_z || CUBE2048.showing_view );
|
||||||
|
};
|
||||||
|
|
||||||
|
rot_animation.prototype.get_offset = function () {
|
||||||
|
return this.angle / this.animation_duration;
|
||||||
|
};
|
||||||
|
|
||||||
|
var rotation_animation = new rot_animation(Math.PI / 2);
|
||||||
|
|
||||||
|
// Utility Functions.
|
||||||
|
|
||||||
|
var rotWorldMatrix;
|
||||||
|
// Rotate an object around an arbitrary axis in world space
|
||||||
|
function rotateAroundWorldAxis(object, axis, radians) {
|
||||||
|
rotWorldMatrix = new THREE.Matrix4();
|
||||||
|
rotWorldMatrix.makeRotationAxis(axis.normalize(), radians);
|
||||||
|
rotWorldMatrix.multiply(object.matrix); // pre-multiply
|
||||||
|
object.matrix = rotWorldMatrix;
|
||||||
|
object.rotation.setFromRotationMatrix(object.matrix);
|
||||||
|
}
|
143
sources/libs/Stats.js
Normal file
|
@ -0,0 +1,143 @@
|
||||||
|
/**
|
||||||
|
* @author mrdoob / http://mrdoob.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
var Stats = function () {
|
||||||
|
|
||||||
|
var startTime = Date.now(), prevTime = startTime;
|
||||||
|
var ms = 0, msMin = Infinity, msMax = 0;
|
||||||
|
var fps = 0, fpsMin = Infinity, fpsMax = 0;
|
||||||
|
var frames = 0, mode = 0;
|
||||||
|
|
||||||
|
var container = document.createElement( 'div' );
|
||||||
|
container.id = 'stats';
|
||||||
|
container.addEventListener( 'mousedown', function ( event ) { event.preventDefault(); setMode( ++ mode % 2 ) }, false );
|
||||||
|
container.style.cssText = 'width:80px;opacity:0.9;cursor:pointer';
|
||||||
|
|
||||||
|
var fpsDiv = document.createElement( 'div' );
|
||||||
|
fpsDiv.id = 'fps';
|
||||||
|
fpsDiv.style.cssText = 'padding:0 0 3px 3px;text-align:left;background-color:#002';
|
||||||
|
container.appendChild( fpsDiv );
|
||||||
|
|
||||||
|
var fpsText = document.createElement( 'div' );
|
||||||
|
fpsText.id = 'fpsText';
|
||||||
|
fpsText.style.cssText = 'color:#0ff;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px';
|
||||||
|
fpsText.innerHTML = 'FPS';
|
||||||
|
fpsDiv.appendChild( fpsText );
|
||||||
|
|
||||||
|
var fpsGraph = document.createElement( 'div' );
|
||||||
|
fpsGraph.id = 'fpsGraph';
|
||||||
|
fpsGraph.style.cssText = 'position:relative;width:74px;height:30px;background-color:#0ff';
|
||||||
|
fpsDiv.appendChild( fpsGraph );
|
||||||
|
|
||||||
|
while ( fpsGraph.children.length < 74 ) {
|
||||||
|
|
||||||
|
var bar = document.createElement( 'span' );
|
||||||
|
bar.style.cssText = 'width:1px;height:30px;float:left;background-color:#113';
|
||||||
|
fpsGraph.appendChild( bar );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var msDiv = document.createElement( 'div' );
|
||||||
|
msDiv.id = 'ms';
|
||||||
|
msDiv.style.cssText = 'padding:0 0 3px 3px;text-align:left;background-color:#020;display:none';
|
||||||
|
container.appendChild( msDiv );
|
||||||
|
|
||||||
|
var msText = document.createElement( 'div' );
|
||||||
|
msText.id = 'msText';
|
||||||
|
msText.style.cssText = 'color:#0f0;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px';
|
||||||
|
msText.innerHTML = 'MS';
|
||||||
|
msDiv.appendChild( msText );
|
||||||
|
|
||||||
|
var msGraph = document.createElement( 'div' );
|
||||||
|
msGraph.id = 'msGraph';
|
||||||
|
msGraph.style.cssText = 'position:relative;width:74px;height:30px;background-color:#0f0';
|
||||||
|
msDiv.appendChild( msGraph );
|
||||||
|
|
||||||
|
while ( msGraph.children.length < 74 ) {
|
||||||
|
|
||||||
|
var bar = document.createElement( 'span' );
|
||||||
|
bar.style.cssText = 'width:1px;height:30px;float:left;background-color:#131';
|
||||||
|
msGraph.appendChild( bar );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var setMode = function ( value ) {
|
||||||
|
|
||||||
|
mode = value;
|
||||||
|
|
||||||
|
switch ( mode ) {
|
||||||
|
|
||||||
|
case 0:
|
||||||
|
fpsDiv.style.display = 'block';
|
||||||
|
msDiv.style.display = 'none';
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
fpsDiv.style.display = 'none';
|
||||||
|
msDiv.style.display = 'block';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var updateGraph = function ( dom, value ) {
|
||||||
|
|
||||||
|
var child = dom.appendChild( dom.firstChild );
|
||||||
|
child.style.height = value + 'px';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
|
||||||
|
REVISION: 11,
|
||||||
|
|
||||||
|
domElement: container,
|
||||||
|
|
||||||
|
setMode: setMode,
|
||||||
|
|
||||||
|
begin: function () {
|
||||||
|
|
||||||
|
startTime = Date.now();
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
end: function () {
|
||||||
|
|
||||||
|
var time = Date.now();
|
||||||
|
|
||||||
|
ms = time - startTime;
|
||||||
|
msMin = Math.min( msMin, ms );
|
||||||
|
msMax = Math.max( msMax, ms );
|
||||||
|
|
||||||
|
msText.textContent = ms + ' MS (' + msMin + '-' + msMax + ')';
|
||||||
|
updateGraph( msGraph, Math.min( 30, 30 - ( ms / 200 ) * 30 ) );
|
||||||
|
|
||||||
|
frames ++;
|
||||||
|
|
||||||
|
if ( time > prevTime + 1000 ) {
|
||||||
|
|
||||||
|
fps = Math.round( ( frames * 1000 ) / ( time - prevTime ) );
|
||||||
|
fpsMin = Math.min( fpsMin, fps );
|
||||||
|
fpsMax = Math.max( fpsMax, fps );
|
||||||
|
|
||||||
|
fpsText.textContent = fps + ' FPS (' + fpsMin + '-' + fpsMax + ')';
|
||||||
|
updateGraph( fpsGraph, Math.min( 30, 30 - ( fps / 100 ) * 30 ) );
|
||||||
|
|
||||||
|
prevTime = time;
|
||||||
|
frames = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return time;
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
update: function () {
|
||||||
|
|
||||||
|
startTime = this.end();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
741
sources/libs/Tween.js
Normal file
|
@ -0,0 +1,741 @@
|
||||||
|
/**
|
||||||
|
* @author sole / http://soledadpenades.com
|
||||||
|
* @author mrdoob / http://mrdoob.com
|
||||||
|
* @author Robert Eisele / http://www.xarg.org
|
||||||
|
* @author Philippe / http://philippe.elsass.me
|
||||||
|
* @author Robert Penner / http://www.robertpenner.com/easing_terms_of_use.html
|
||||||
|
* @author Paul Lewis / http://www.aerotwist.com/
|
||||||
|
* @author lechecacharro
|
||||||
|
* @author Josh Faul / http://jocafa.com/
|
||||||
|
* @author egraether / http://egraether.com/
|
||||||
|
* @author endel / http://endel.me
|
||||||
|
* @author Ben Delarre / http://delarre.net
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Date.now shim for (ahem) Internet Explo(d|r)er
|
||||||
|
if ( Date.now === undefined ) {
|
||||||
|
|
||||||
|
Date.now = function () {
|
||||||
|
|
||||||
|
return new Date().valueOf();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var TWEEN = TWEEN || ( function () {
|
||||||
|
|
||||||
|
var _tweens = [];
|
||||||
|
|
||||||
|
return {
|
||||||
|
|
||||||
|
REVISION: '12',
|
||||||
|
|
||||||
|
getAll: function () {
|
||||||
|
|
||||||
|
return _tweens;
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
removeAll: function () {
|
||||||
|
|
||||||
|
_tweens = [];
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
add: function ( tween ) {
|
||||||
|
|
||||||
|
_tweens.push( tween );
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
remove: function ( tween ) {
|
||||||
|
|
||||||
|
var i = _tweens.indexOf( tween );
|
||||||
|
|
||||||
|
if ( i !== -1 ) {
|
||||||
|
|
||||||
|
_tweens.splice( i, 1 );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
update: function ( time ) {
|
||||||
|
|
||||||
|
if ( _tweens.length === 0 ) return false;
|
||||||
|
|
||||||
|
var i = 0;
|
||||||
|
|
||||||
|
time = time !== undefined ? time : ( typeof window !== 'undefined' && window.performance !== undefined && window.performance.now !== undefined ? window.performance.now() : Date.now() );
|
||||||
|
|
||||||
|
while ( i < _tweens.length ) {
|
||||||
|
|
||||||
|
if ( _tweens[ i ].update( time ) ) {
|
||||||
|
|
||||||
|
i++;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
_tweens.splice( i, 1 );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} )();
|
||||||
|
|
||||||
|
TWEEN.Tween = function ( object ) {
|
||||||
|
|
||||||
|
var _object = object;
|
||||||
|
var _valuesStart = {};
|
||||||
|
var _valuesEnd = {};
|
||||||
|
var _valuesStartRepeat = {};
|
||||||
|
var _duration = 1000;
|
||||||
|
var _repeat = 0;
|
||||||
|
var _yoyo = false;
|
||||||
|
var _isPlaying = false;
|
||||||
|
var _reversed = false;
|
||||||
|
var _delayTime = 0;
|
||||||
|
var _startTime = null;
|
||||||
|
var _easingFunction = TWEEN.Easing.Linear.None;
|
||||||
|
var _interpolationFunction = TWEEN.Interpolation.Linear;
|
||||||
|
var _chainedTweens = [];
|
||||||
|
var _onStartCallback = null;
|
||||||
|
var _onStartCallbackFired = false;
|
||||||
|
var _onUpdateCallback = null;
|
||||||
|
var _onCompleteCallback = null;
|
||||||
|
|
||||||
|
// Set all starting values present on the target object
|
||||||
|
for ( var field in object ) {
|
||||||
|
|
||||||
|
_valuesStart[ field ] = parseFloat(object[field], 10);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
this.to = function ( properties, duration ) {
|
||||||
|
|
||||||
|
if ( duration !== undefined ) {
|
||||||
|
|
||||||
|
_duration = duration;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
_valuesEnd = properties;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
this.start = function ( time ) {
|
||||||
|
|
||||||
|
TWEEN.add( this );
|
||||||
|
|
||||||
|
_isPlaying = true;
|
||||||
|
|
||||||
|
_onStartCallbackFired = false;
|
||||||
|
|
||||||
|
_startTime = time !== undefined ? time : ( typeof window !== 'undefined' && window.performance !== undefined && window.performance.now !== undefined ? window.performance.now() : Date.now() );
|
||||||
|
_startTime += _delayTime;
|
||||||
|
|
||||||
|
for ( var property in _valuesEnd ) {
|
||||||
|
|
||||||
|
// check if an Array was provided as property value
|
||||||
|
if ( _valuesEnd[ property ] instanceof Array ) {
|
||||||
|
|
||||||
|
if ( _valuesEnd[ property ].length === 0 ) {
|
||||||
|
|
||||||
|
continue;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// create a local copy of the Array with the start value at the front
|
||||||
|
_valuesEnd[ property ] = [ _object[ property ] ].concat( _valuesEnd[ property ] );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
_valuesStart[ property ] = _object[ property ];
|
||||||
|
|
||||||
|
if( ( _valuesStart[ property ] instanceof Array ) === false ) {
|
||||||
|
_valuesStart[ property ] *= 1.0; // Ensures we're using numbers, not strings
|
||||||
|
}
|
||||||
|
|
||||||
|
_valuesStartRepeat[ property ] = _valuesStart[ property ] || 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
this.stop = function () {
|
||||||
|
|
||||||
|
if ( !_isPlaying ) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
TWEEN.remove( this );
|
||||||
|
_isPlaying = false;
|
||||||
|
this.stopChainedTweens();
|
||||||
|
return this;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
this.stopChainedTweens = function () {
|
||||||
|
|
||||||
|
for ( var i = 0, numChainedTweens = _chainedTweens.length; i < numChainedTweens; i++ ) {
|
||||||
|
|
||||||
|
_chainedTweens[ i ].stop();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
this.delay = function ( amount ) {
|
||||||
|
|
||||||
|
_delayTime = amount;
|
||||||
|
return this;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
this.repeat = function ( times ) {
|
||||||
|
|
||||||
|
_repeat = times;
|
||||||
|
return this;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
this.yoyo = function( yoyo ) {
|
||||||
|
|
||||||
|
_yoyo = yoyo;
|
||||||
|
return this;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
this.easing = function ( easing ) {
|
||||||
|
|
||||||
|
_easingFunction = easing;
|
||||||
|
return this;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
this.interpolation = function ( interpolation ) {
|
||||||
|
|
||||||
|
_interpolationFunction = interpolation;
|
||||||
|
return this;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
this.chain = function () {
|
||||||
|
|
||||||
|
_chainedTweens = arguments;
|
||||||
|
return this;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
this.onStart = function ( callback ) {
|
||||||
|
|
||||||
|
_onStartCallback = callback;
|
||||||
|
return this;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
this.onUpdate = function ( callback ) {
|
||||||
|
|
||||||
|
_onUpdateCallback = callback;
|
||||||
|
return this;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
this.onComplete = function ( callback ) {
|
||||||
|
|
||||||
|
_onCompleteCallback = callback;
|
||||||
|
return this;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
this.update = function ( time ) {
|
||||||
|
|
||||||
|
var property;
|
||||||
|
|
||||||
|
if ( time < _startTime ) {
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( _onStartCallbackFired === false ) {
|
||||||
|
|
||||||
|
if ( _onStartCallback !== null ) {
|
||||||
|
|
||||||
|
_onStartCallback.call( _object );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
_onStartCallbackFired = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var elapsed = ( time - _startTime ) / _duration;
|
||||||
|
elapsed = elapsed > 1 ? 1 : elapsed;
|
||||||
|
|
||||||
|
var value = _easingFunction( elapsed );
|
||||||
|
|
||||||
|
for ( property in _valuesEnd ) {
|
||||||
|
|
||||||
|
var start = _valuesStart[ property ] || 0;
|
||||||
|
var end = _valuesEnd[ property ];
|
||||||
|
|
||||||
|
if ( end instanceof Array ) {
|
||||||
|
|
||||||
|
_object[ property ] = _interpolationFunction( end, value );
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// Parses relative end values with start as base (e.g.: +10, -3)
|
||||||
|
if ( typeof(end) === "string" ) {
|
||||||
|
end = start + parseFloat(end, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
// protect against non numeric properties.
|
||||||
|
if ( typeof(end) === "number" ) {
|
||||||
|
_object[ property ] = start + ( end - start ) * value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( _onUpdateCallback !== null ) {
|
||||||
|
|
||||||
|
_onUpdateCallback.call( _object, value );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( elapsed == 1 ) {
|
||||||
|
|
||||||
|
if ( _repeat > 0 ) {
|
||||||
|
|
||||||
|
if( isFinite( _repeat ) ) {
|
||||||
|
_repeat--;
|
||||||
|
}
|
||||||
|
|
||||||
|
// reassign starting values, restart by making startTime = now
|
||||||
|
for( property in _valuesStartRepeat ) {
|
||||||
|
|
||||||
|
if ( typeof( _valuesEnd[ property ] ) === "string" ) {
|
||||||
|
_valuesStartRepeat[ property ] = _valuesStartRepeat[ property ] + parseFloat(_valuesEnd[ property ], 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_yoyo) {
|
||||||
|
var tmp = _valuesStartRepeat[ property ];
|
||||||
|
_valuesStartRepeat[ property ] = _valuesEnd[ property ];
|
||||||
|
_valuesEnd[ property ] = tmp;
|
||||||
|
_reversed = !_reversed;
|
||||||
|
}
|
||||||
|
_valuesStart[ property ] = _valuesStartRepeat[ property ];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
_startTime = time + _delayTime;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if ( _onCompleteCallback !== null ) {
|
||||||
|
|
||||||
|
_onCompleteCallback.call( _object );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( var i = 0, numChainedTweens = _chainedTweens.length; i < numChainedTweens; i++ ) {
|
||||||
|
|
||||||
|
_chainedTweens[ i ].start( time );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
TWEEN.Easing = {
|
||||||
|
|
||||||
|
Linear: {
|
||||||
|
|
||||||
|
None: function ( k ) {
|
||||||
|
|
||||||
|
return k;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
Quadratic: {
|
||||||
|
|
||||||
|
In: function ( k ) {
|
||||||
|
|
||||||
|
return k * k;
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
Out: function ( k ) {
|
||||||
|
|
||||||
|
return k * ( 2 - k );
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
InOut: function ( k ) {
|
||||||
|
|
||||||
|
if ( ( k *= 2 ) < 1 ) return 0.5 * k * k;
|
||||||
|
return - 0.5 * ( --k * ( k - 2 ) - 1 );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
Cubic: {
|
||||||
|
|
||||||
|
In: function ( k ) {
|
||||||
|
|
||||||
|
return k * k * k;
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
Out: function ( k ) {
|
||||||
|
|
||||||
|
return --k * k * k + 1;
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
InOut: function ( k ) {
|
||||||
|
|
||||||
|
if ( ( k *= 2 ) < 1 ) return 0.5 * k * k * k;
|
||||||
|
return 0.5 * ( ( k -= 2 ) * k * k + 2 );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
Quartic: {
|
||||||
|
|
||||||
|
In: function ( k ) {
|
||||||
|
|
||||||
|
return k * k * k * k;
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
Out: function ( k ) {
|
||||||
|
|
||||||
|
return 1 - ( --k * k * k * k );
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
InOut: function ( k ) {
|
||||||
|
|
||||||
|
if ( ( k *= 2 ) < 1) return 0.5 * k * k * k * k;
|
||||||
|
return - 0.5 * ( ( k -= 2 ) * k * k * k - 2 );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
Quintic: {
|
||||||
|
|
||||||
|
In: function ( k ) {
|
||||||
|
|
||||||
|
return k * k * k * k * k;
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
Out: function ( k ) {
|
||||||
|
|
||||||
|
return --k * k * k * k * k + 1;
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
InOut: function ( k ) {
|
||||||
|
|
||||||
|
if ( ( k *= 2 ) < 1 ) return 0.5 * k * k * k * k * k;
|
||||||
|
return 0.5 * ( ( k -= 2 ) * k * k * k * k + 2 );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
Sinusoidal: {
|
||||||
|
|
||||||
|
In: function ( k ) {
|
||||||
|
|
||||||
|
return 1 - Math.cos( k * Math.PI / 2 );
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
Out: function ( k ) {
|
||||||
|
|
||||||
|
return Math.sin( k * Math.PI / 2 );
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
InOut: function ( k ) {
|
||||||
|
|
||||||
|
return 0.5 * ( 1 - Math.cos( Math.PI * k ) );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
Exponential: {
|
||||||
|
|
||||||
|
In: function ( k ) {
|
||||||
|
|
||||||
|
return k === 0 ? 0 : Math.pow( 1024, k - 1 );
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
Out: function ( k ) {
|
||||||
|
|
||||||
|
return k === 1 ? 1 : 1 - Math.pow( 2, - 10 * k );
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
InOut: function ( k ) {
|
||||||
|
|
||||||
|
if ( k === 0 ) return 0;
|
||||||
|
if ( k === 1 ) return 1;
|
||||||
|
if ( ( k *= 2 ) < 1 ) return 0.5 * Math.pow( 1024, k - 1 );
|
||||||
|
return 0.5 * ( - Math.pow( 2, - 10 * ( k - 1 ) ) + 2 );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
Circular: {
|
||||||
|
|
||||||
|
In: function ( k ) {
|
||||||
|
|
||||||
|
return 1 - Math.sqrt( 1 - k * k );
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
Out: function ( k ) {
|
||||||
|
|
||||||
|
return Math.sqrt( 1 - ( --k * k ) );
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
InOut: function ( k ) {
|
||||||
|
|
||||||
|
if ( ( k *= 2 ) < 1) return - 0.5 * ( Math.sqrt( 1 - k * k) - 1);
|
||||||
|
return 0.5 * ( Math.sqrt( 1 - ( k -= 2) * k) + 1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
Elastic: {
|
||||||
|
|
||||||
|
In: function ( k ) {
|
||||||
|
|
||||||
|
var s, a = 0.1, p = 0.4;
|
||||||
|
if ( k === 0 ) return 0;
|
||||||
|
if ( k === 1 ) return 1;
|
||||||
|
if ( !a || a < 1 ) { a = 1; s = p / 4; }
|
||||||
|
else s = p * Math.asin( 1 / a ) / ( 2 * Math.PI );
|
||||||
|
return - ( a * Math.pow( 2, 10 * ( k -= 1 ) ) * Math.sin( ( k - s ) * ( 2 * Math.PI ) / p ) );
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
Out: function ( k ) {
|
||||||
|
|
||||||
|
var s, a = 0.1, p = 0.4;
|
||||||
|
if ( k === 0 ) return 0;
|
||||||
|
if ( k === 1 ) return 1;
|
||||||
|
if ( !a || a < 1 ) { a = 1; s = p / 4; }
|
||||||
|
else s = p * Math.asin( 1 / a ) / ( 2 * Math.PI );
|
||||||
|
return ( a * Math.pow( 2, - 10 * k) * Math.sin( ( k - s ) * ( 2 * Math.PI ) / p ) + 1 );
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
InOut: function ( k ) {
|
||||||
|
|
||||||
|
var s, a = 0.1, p = 0.4;
|
||||||
|
if ( k === 0 ) return 0;
|
||||||
|
if ( k === 1 ) return 1;
|
||||||
|
if ( !a || a < 1 ) { a = 1; s = p / 4; }
|
||||||
|
else s = p * Math.asin( 1 / a ) / ( 2 * Math.PI );
|
||||||
|
if ( ( k *= 2 ) < 1 ) return - 0.5 * ( a * Math.pow( 2, 10 * ( k -= 1 ) ) * Math.sin( ( k - s ) * ( 2 * Math.PI ) / p ) );
|
||||||
|
return a * Math.pow( 2, -10 * ( k -= 1 ) ) * Math.sin( ( k - s ) * ( 2 * Math.PI ) / p ) * 0.5 + 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
Back: {
|
||||||
|
|
||||||
|
In: function ( k ) {
|
||||||
|
|
||||||
|
var s = 1.70158;
|
||||||
|
return k * k * ( ( s + 1 ) * k - s );
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
Out: function ( k ) {
|
||||||
|
|
||||||
|
var s = 1.70158;
|
||||||
|
return --k * k * ( ( s + 1 ) * k + s ) + 1;
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
InOut: function ( k ) {
|
||||||
|
|
||||||
|
var s = 1.70158 * 1.525;
|
||||||
|
if ( ( k *= 2 ) < 1 ) return 0.5 * ( k * k * ( ( s + 1 ) * k - s ) );
|
||||||
|
return 0.5 * ( ( k -= 2 ) * k * ( ( s + 1 ) * k + s ) + 2 );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
Bounce: {
|
||||||
|
|
||||||
|
In: function ( k ) {
|
||||||
|
|
||||||
|
return 1 - TWEEN.Easing.Bounce.Out( 1 - k );
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
Out: function ( k ) {
|
||||||
|
|
||||||
|
if ( k < ( 1 / 2.75 ) ) {
|
||||||
|
|
||||||
|
return 7.5625 * k * k;
|
||||||
|
|
||||||
|
} else if ( k < ( 2 / 2.75 ) ) {
|
||||||
|
|
||||||
|
return 7.5625 * ( k -= ( 1.5 / 2.75 ) ) * k + 0.75;
|
||||||
|
|
||||||
|
} else if ( k < ( 2.5 / 2.75 ) ) {
|
||||||
|
|
||||||
|
return 7.5625 * ( k -= ( 2.25 / 2.75 ) ) * k + 0.9375;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
return 7.5625 * ( k -= ( 2.625 / 2.75 ) ) * k + 0.984375;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
InOut: function ( k ) {
|
||||||
|
|
||||||
|
if ( k < 0.5 ) return TWEEN.Easing.Bounce.In( k * 2 ) * 0.5;
|
||||||
|
return TWEEN.Easing.Bounce.Out( k * 2 - 1 ) * 0.5 + 0.5;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
TWEEN.Interpolation = {
|
||||||
|
|
||||||
|
Linear: function ( v, k ) {
|
||||||
|
|
||||||
|
var m = v.length - 1, f = m * k, i = Math.floor( f ), fn = TWEEN.Interpolation.Utils.Linear;
|
||||||
|
|
||||||
|
if ( k < 0 ) return fn( v[ 0 ], v[ 1 ], f );
|
||||||
|
if ( k > 1 ) return fn( v[ m ], v[ m - 1 ], m - f );
|
||||||
|
|
||||||
|
return fn( v[ i ], v[ i + 1 > m ? m : i + 1 ], f - i );
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
Bezier: function ( v, k ) {
|
||||||
|
|
||||||
|
var b = 0, n = v.length - 1, pw = Math.pow, bn = TWEEN.Interpolation.Utils.Bernstein, i;
|
||||||
|
|
||||||
|
for ( i = 0; i <= n; i++ ) {
|
||||||
|
b += pw( 1 - k, n - i ) * pw( k, i ) * v[ i ] * bn( n, i );
|
||||||
|
}
|
||||||
|
|
||||||
|
return b;
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
CatmullRom: function ( v, k ) {
|
||||||
|
|
||||||
|
var m = v.length - 1, f = m * k, i = Math.floor( f ), fn = TWEEN.Interpolation.Utils.CatmullRom;
|
||||||
|
|
||||||
|
if ( v[ 0 ] === v[ m ] ) {
|
||||||
|
|
||||||
|
if ( k < 0 ) i = Math.floor( f = m * ( 1 + k ) );
|
||||||
|
|
||||||
|
return fn( v[ ( i - 1 + m ) % m ], v[ i ], v[ ( i + 1 ) % m ], v[ ( i + 2 ) % m ], f - i );
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if ( k < 0 ) return v[ 0 ] - ( fn( v[ 0 ], v[ 0 ], v[ 1 ], v[ 1 ], -f ) - v[ 0 ] );
|
||||||
|
if ( k > 1 ) return v[ m ] - ( fn( v[ m ], v[ m ], v[ m - 1 ], v[ m - 1 ], f - m ) - v[ m ] );
|
||||||
|
|
||||||
|
return fn( v[ i ? i - 1 : 0 ], v[ i ], v[ m < i + 1 ? m : i + 1 ], v[ m < i + 2 ? m : i + 2 ], f - i );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
Utils: {
|
||||||
|
|
||||||
|
Linear: function ( p0, p1, t ) {
|
||||||
|
|
||||||
|
return ( p1 - p0 ) * t + p0;
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
Bernstein: function ( n , i ) {
|
||||||
|
|
||||||
|
var fc = TWEEN.Interpolation.Utils.Factorial;
|
||||||
|
return fc( n ) / fc( i ) / fc( n - i );
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
Factorial: ( function () {
|
||||||
|
|
||||||
|
var a = [ 1 ];
|
||||||
|
|
||||||
|
return function ( n ) {
|
||||||
|
|
||||||
|
var s = 1, i;
|
||||||
|
if ( a[ n ] ) return a[ n ];
|
||||||
|
for ( i = n; i > 1; i-- ) s *= i;
|
||||||
|
return a[ n ] = s;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} )(),
|
||||||
|
|
||||||
|
CatmullRom: function ( p0, p1, p2, p3, t ) {
|
||||||
|
|
||||||
|
var v0 = ( p2 - p0 ) * 0.5, v1 = ( p3 - p1 ) * 0.5, t2 = t * t, t3 = t * t2;
|
||||||
|
return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
4
sources/libs/jquery.min.js
vendored
Normal file
934
sources/libs/keyboard.js
Normal file
|
@ -0,0 +1,934 @@
|
||||||
|
/**
|
||||||
|
* Title: KeyboardJS
|
||||||
|
* Version: v0.4.1
|
||||||
|
* Description: KeyboardJS is a flexible and easy to use keyboard binding
|
||||||
|
* library.
|
||||||
|
* Author: Robert Hurst.
|
||||||
|
*
|
||||||
|
* Copyright 2011, Robert William Hurst
|
||||||
|
* Licenced under the BSD License.
|
||||||
|
* See https://raw.github.com/RobertWHurst/KeyboardJS/master/license.txt
|
||||||
|
*/
|
||||||
|
(function(context, factory) {
|
||||||
|
|
||||||
|
//INDEXOF POLLYFILL
|
||||||
|
[].indexOf||(Array.prototype.indexOf=function(a,b,c){for(c=this.length,b=(c+~~b)%c;b<c&&(!(b in this)||this[b]!==a);b++);return b^c?b:-1;});
|
||||||
|
|
||||||
|
//AMD
|
||||||
|
if(typeof define === 'function' && define.amd) { define(constructAMD); }
|
||||||
|
|
||||||
|
//GLOBAL
|
||||||
|
else { constructGlobal(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct AMD version of the library
|
||||||
|
*/
|
||||||
|
function constructAMD() {
|
||||||
|
|
||||||
|
//create a library instance
|
||||||
|
return init();
|
||||||
|
|
||||||
|
//spawns a library instance
|
||||||
|
function init() {
|
||||||
|
var library;
|
||||||
|
library = factory('amd');
|
||||||
|
library.fork = init;
|
||||||
|
return library;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a Global version of the library
|
||||||
|
*/
|
||||||
|
function constructGlobal() {
|
||||||
|
var library;
|
||||||
|
|
||||||
|
//create a library instance
|
||||||
|
library = init();
|
||||||
|
library.noConflict('KeyboardJS', 'k');
|
||||||
|
|
||||||
|
//spawns a library instance
|
||||||
|
function init() {
|
||||||
|
var library, namespaces = [], previousValues = {};
|
||||||
|
|
||||||
|
library = factory('global');
|
||||||
|
library.fork = init;
|
||||||
|
library.noConflict = noConflict;
|
||||||
|
return library;
|
||||||
|
|
||||||
|
//sets library namespaces
|
||||||
|
function noConflict( ) {
|
||||||
|
var args, nI, newNamespaces;
|
||||||
|
|
||||||
|
newNamespaces = Array.prototype.slice.apply(arguments);
|
||||||
|
|
||||||
|
for(nI = 0; nI < namespaces.length; nI += 1) {
|
||||||
|
if(typeof previousValues[namespaces[nI]] === 'undefined') {
|
||||||
|
delete context[namespaces[nI]];
|
||||||
|
} else {
|
||||||
|
context[namespaces[nI]] = previousValues[namespaces[nI]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
previousValues = {};
|
||||||
|
|
||||||
|
for(nI = 0; nI < newNamespaces.length; nI += 1) {
|
||||||
|
if(typeof newNamespaces[nI] !== 'string') {
|
||||||
|
throw new Error('Cannot replace namespaces. All new namespaces must be strings.');
|
||||||
|
}
|
||||||
|
previousValues[newNamespaces[nI]] = context[newNamespaces[nI]];
|
||||||
|
context[newNamespaces[nI]] = library;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespaces = newNamespaces;
|
||||||
|
|
||||||
|
return namespaces;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})(this, function(env) {
|
||||||
|
var KeyboardJS = {}, locales = {}, locale, map, macros, activeKeys = [], bindings = [], activeBindings = [],
|
||||||
|
activeMacros = [], aI, usLocale;
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////
|
||||||
|
// DEFUALT US LOCALE //
|
||||||
|
///////////////////////
|
||||||
|
|
||||||
|
//define US locale
|
||||||
|
//If you create a new locale please submit it as a pull request or post
|
||||||
|
// it in the issue tracker at
|
||||||
|
// http://github.com/RobertWhurst/KeyboardJS/issues/
|
||||||
|
usLocale = {
|
||||||
|
"map": {
|
||||||
|
|
||||||
|
//general
|
||||||
|
"3": ["cancel"],
|
||||||
|
"8": ["backspace"],
|
||||||
|
"9": ["tab"],
|
||||||
|
"12": ["clear"],
|
||||||
|
"13": ["enter"],
|
||||||
|
"16": ["shift"],
|
||||||
|
"17": ["ctrl"],
|
||||||
|
"18": ["alt", "menu"],
|
||||||
|
"19": ["pause", "break"],
|
||||||
|
"20": ["capslock"],
|
||||||
|
"27": ["escape", "esc"],
|
||||||
|
"32": ["space", "spacebar"],
|
||||||
|
"33": ["pageup"],
|
||||||
|
"34": ["pagedown"],
|
||||||
|
"35": ["end"],
|
||||||
|
"36": ["home"],
|
||||||
|
"37": ["left"],
|
||||||
|
"38": ["up"],
|
||||||
|
"39": ["right"],
|
||||||
|
"40": ["down"],
|
||||||
|
"41": ["select"],
|
||||||
|
"42": ["printscreen"],
|
||||||
|
"43": ["execute"],
|
||||||
|
"44": ["snapshot"],
|
||||||
|
"45": ["insert", "ins"],
|
||||||
|
"46": ["delete", "del"],
|
||||||
|
"47": ["help"],
|
||||||
|
"91": ["command", "windows", "win", "super", "leftcommand", "leftwindows", "leftwin", "leftsuper"],
|
||||||
|
"92": ["command", "windows", "win", "super", "rightcommand", "rightwindows", "rightwin", "rightsuper"],
|
||||||
|
"145": ["scrolllock", "scroll"],
|
||||||
|
"186": ["semicolon", ";"],
|
||||||
|
"187": ["equal", "equalsign", "="],
|
||||||
|
"188": ["comma", ","],
|
||||||
|
"189": ["dash", "-"],
|
||||||
|
"190": ["period", "."],
|
||||||
|
"191": ["slash", "forwardslash", "/"],
|
||||||
|
"192": ["graveaccent", "`"],
|
||||||
|
"219": ["openbracket", "["],
|
||||||
|
"220": ["backslash", "\\"],
|
||||||
|
"221": ["closebracket", "]"],
|
||||||
|
"222": ["apostrophe", "'"],
|
||||||
|
|
||||||
|
//0-9
|
||||||
|
"48": ["zero", "0"],
|
||||||
|
"49": ["one", "1"],
|
||||||
|
"50": ["two", "2"],
|
||||||
|
"51": ["three", "3"],
|
||||||
|
"52": ["four", "4"],
|
||||||
|
"53": ["five", "5"],
|
||||||
|
"54": ["six", "6"],
|
||||||
|
"55": ["seven", "7"],
|
||||||
|
"56": ["eight", "8"],
|
||||||
|
"57": ["nine", "9"],
|
||||||
|
|
||||||
|
//numpad
|
||||||
|
"96": ["numzero", "num0"],
|
||||||
|
"97": ["numone", "num1"],
|
||||||
|
"98": ["numtwo", "num2"],
|
||||||
|
"99": ["numthree", "num3"],
|
||||||
|
"100": ["numfour", "num4"],
|
||||||
|
"101": ["numfive", "num5"],
|
||||||
|
"102": ["numsix", "num6"],
|
||||||
|
"103": ["numseven", "num7"],
|
||||||
|
"104": ["numeight", "num8"],
|
||||||
|
"105": ["numnine", "num9"],
|
||||||
|
"106": ["nummultiply", "num*"],
|
||||||
|
"107": ["numadd", "num+"],
|
||||||
|
"108": ["numenter"],
|
||||||
|
"109": ["numsubtract", "num-"],
|
||||||
|
"110": ["numdecimal", "num."],
|
||||||
|
"111": ["numdevide", "num/"],
|
||||||
|
"144": ["numlock", "num"],
|
||||||
|
|
||||||
|
//function keys
|
||||||
|
"112": ["f1"],
|
||||||
|
"113": ["f2"],
|
||||||
|
"114": ["f3"],
|
||||||
|
"115": ["f4"],
|
||||||
|
"116": ["f5"],
|
||||||
|
"117": ["f6"],
|
||||||
|
"118": ["f7"],
|
||||||
|
"119": ["f8"],
|
||||||
|
"120": ["f9"],
|
||||||
|
"121": ["f10"],
|
||||||
|
"122": ["f11"],
|
||||||
|
"123": ["f12"]
|
||||||
|
},
|
||||||
|
"macros": [
|
||||||
|
|
||||||
|
//secondary key symbols
|
||||||
|
['shift + `', ["tilde", "~"]],
|
||||||
|
['shift + 1', ["exclamation", "exclamationpoint", "!"]],
|
||||||
|
['shift + 2', ["at", "@"]],
|
||||||
|
['shift + 3', ["number", "#"]],
|
||||||
|
['shift + 4', ["dollar", "dollars", "dollarsign", "$"]],
|
||||||
|
['shift + 5', ["percent", "%"]],
|
||||||
|
['shift + 6', ["caret", "^"]],
|
||||||
|
['shift + 7', ["ampersand", "and", "&"]],
|
||||||
|
['shift + 8', ["asterisk", "*"]],
|
||||||
|
['shift + 9', ["openparen", "("]],
|
||||||
|
['shift + 0', ["closeparen", ")"]],
|
||||||
|
['shift + -', ["underscore", "_"]],
|
||||||
|
['shift + =', ["plus", "+"]],
|
||||||
|
['shift + (', ["opencurlybrace", "opencurlybracket", "{"]],
|
||||||
|
['shift + )', ["closecurlybrace", "closecurlybracket", "}"]],
|
||||||
|
['shift + \\', ["verticalbar", "|"]],
|
||||||
|
['shift + ;', ["colon", ":"]],
|
||||||
|
['shift + \'', ["quotationmark", "\""]],
|
||||||
|
['shift + !,', ["openanglebracket", "<"]],
|
||||||
|
['shift + .', ["closeanglebracket", ">"]],
|
||||||
|
['shift + /', ["questionmark", "?"]]
|
||||||
|
]
|
||||||
|
};
|
||||||
|
//a-z and A-Z
|
||||||
|
for (aI = 65; aI <= 90; aI += 1) {
|
||||||
|
usLocale.map[aI] = String.fromCharCode(aI + 32);
|
||||||
|
usLocale.macros.push(['shift + ' + String.fromCharCode(aI + 32) + ', capslock + ' + String.fromCharCode(aI + 32), [String.fromCharCode(aI)]]);
|
||||||
|
}
|
||||||
|
registerLocale('us', usLocale);
|
||||||
|
getSetLocale('us');
|
||||||
|
|
||||||
|
|
||||||
|
//////////
|
||||||
|
// INIT //
|
||||||
|
//////////
|
||||||
|
|
||||||
|
//enable the library
|
||||||
|
enable();
|
||||||
|
|
||||||
|
|
||||||
|
/////////
|
||||||
|
// API //
|
||||||
|
/////////
|
||||||
|
|
||||||
|
//assemble the library and return it
|
||||||
|
KeyboardJS.enable = enable;
|
||||||
|
KeyboardJS.disable = disable;
|
||||||
|
KeyboardJS.activeKeys = getActiveKeys;
|
||||||
|
KeyboardJS.on = createBinding;
|
||||||
|
KeyboardJS.clear = removeBindingByKeyCombo;
|
||||||
|
KeyboardJS.clear.key = removeBindingByKeyName;
|
||||||
|
KeyboardJS.locale = getSetLocale;
|
||||||
|
KeyboardJS.locale.register = registerLocale;
|
||||||
|
KeyboardJS.macro = createMacro;
|
||||||
|
KeyboardJS.macro.remove = removeMacro;
|
||||||
|
KeyboardJS.key = {};
|
||||||
|
KeyboardJS.key.name = getKeyName;
|
||||||
|
KeyboardJS.key.code = getKeyCode;
|
||||||
|
KeyboardJS.combo = {};
|
||||||
|
KeyboardJS.combo.active = isSatisfiedCombo;
|
||||||
|
KeyboardJS.combo.parse = parseKeyCombo;
|
||||||
|
KeyboardJS.combo.stringify = stringifyKeyCombo;
|
||||||
|
return KeyboardJS;
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////
|
||||||
|
// INSTANCE METHODS //
|
||||||
|
//////////////////////
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables KeyboardJS
|
||||||
|
*/
|
||||||
|
function enable() {
|
||||||
|
if(window.addEventListener) {
|
||||||
|
document.addEventListener('keydown', keydown, false);
|
||||||
|
document.addEventListener('keyup', keyup, false);
|
||||||
|
window.addEventListener('blur', reset, false);
|
||||||
|
window.addEventListener('webkitfullscreenchange', reset, false);
|
||||||
|
window.addEventListener('mozfullscreenchange', reset, false);
|
||||||
|
} else if(window.attachEvent) {
|
||||||
|
document.attachEvent('onkeydown', keydown);
|
||||||
|
document.attachEvent('onkeyup', keyup);
|
||||||
|
window.attachEvent('onblur', reset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exits all active bindings and disables KeyboardJS
|
||||||
|
*/
|
||||||
|
function disable() {
|
||||||
|
reset();
|
||||||
|
if(window.removeEventListener) {
|
||||||
|
document.removeEventListener('keydown', keydown, false);
|
||||||
|
document.removeEventListener('keyup', keyup, false);
|
||||||
|
window.removeEventListener('blur', reset, false);
|
||||||
|
window.removeEventListener('webkitfullscreenchange', reset, false);
|
||||||
|
window.removeEventListener('mozfullscreenchange', reset, false);
|
||||||
|
} else if(window.detachEvent) {
|
||||||
|
document.detachEvent('onkeydown', keydown);
|
||||||
|
document.detachEvent('onkeyup', keyup);
|
||||||
|
window.detachEvent('onblur', reset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////
|
||||||
|
// EVENT HANDLERS //
|
||||||
|
////////////////////
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exits all active bindings. Optionally passes an event to all binding
|
||||||
|
* handlers.
|
||||||
|
* @param {KeyboardEvent} event [Optional]
|
||||||
|
*/
|
||||||
|
function reset(event) {
|
||||||
|
activeKeys = [];
|
||||||
|
pruneMacros();
|
||||||
|
pruneBindings(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Key down event handler.
|
||||||
|
* @param {KeyboardEvent} event
|
||||||
|
*/
|
||||||
|
function keydown(event) {
|
||||||
|
var keyNames, keyName, kI;
|
||||||
|
keyNames = getKeyName(event.keyCode);
|
||||||
|
if(keyNames.length < 1) { return; }
|
||||||
|
event.isRepeat = false;
|
||||||
|
for(kI = 0; kI < keyNames.length; kI += 1) {
|
||||||
|
keyName = keyNames[kI];
|
||||||
|
if (getActiveKeys().indexOf(keyName) != -1)
|
||||||
|
event.isRepeat = true;
|
||||||
|
addActiveKey(keyName);
|
||||||
|
}
|
||||||
|
executeMacros();
|
||||||
|
executeBindings(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Key up event handler.
|
||||||
|
* @param {KeyboardEvent} event
|
||||||
|
*/
|
||||||
|
function keyup(event) {
|
||||||
|
var keyNames, kI;
|
||||||
|
keyNames = getKeyName(event.keyCode);
|
||||||
|
if(keyNames.length < 1) { return; }
|
||||||
|
for(kI = 0; kI < keyNames.length; kI += 1) {
|
||||||
|
removeActiveKey(keyNames[kI]);
|
||||||
|
}
|
||||||
|
pruneMacros();
|
||||||
|
pruneBindings(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accepts a key code and returns the key names defined by the current
|
||||||
|
* locale.
|
||||||
|
* @param {Number} keyCode
|
||||||
|
* @return {Array} keyNames An array of key names defined for the key
|
||||||
|
* code as defined by the current locale.
|
||||||
|
*/
|
||||||
|
function getKeyName(keyCode) {
|
||||||
|
return map[keyCode] || [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accepts a key name and returns the key code defined by the current
|
||||||
|
* locale.
|
||||||
|
* @param {Number} keyName
|
||||||
|
* @return {Number|false}
|
||||||
|
*/
|
||||||
|
function getKeyCode(keyName) {
|
||||||
|
var keyCode;
|
||||||
|
for(keyCode in map) {
|
||||||
|
if(!map.hasOwnProperty(keyCode)) { continue; }
|
||||||
|
if(map[keyCode].indexOf(keyName) > -1) { return keyCode; }
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////
|
||||||
|
// MACROS //
|
||||||
|
////////////
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accepts a key combo and an array of key names to inject once the key
|
||||||
|
* combo is satisfied.
|
||||||
|
* @param {String} combo
|
||||||
|
* @param {Array} injectedKeys
|
||||||
|
*/
|
||||||
|
function createMacro(combo, injectedKeys) {
|
||||||
|
if(typeof combo !== 'string' && (typeof combo !== 'object' || typeof combo.push !== 'function')) {
|
||||||
|
throw new Error("Cannot create macro. The combo must be a string or array.");
|
||||||
|
}
|
||||||
|
if(typeof injectedKeys !== 'object' || typeof injectedKeys.push !== 'function') {
|
||||||
|
throw new Error("Cannot create macro. The injectedKeys must be an array.");
|
||||||
|
}
|
||||||
|
macros.push([combo, injectedKeys]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accepts a key combo and clears any and all macros bound to that key
|
||||||
|
* combo.
|
||||||
|
* @param {String} combo
|
||||||
|
*/
|
||||||
|
function removeMacro(combo) {
|
||||||
|
var macro;
|
||||||
|
if(typeof combo !== 'string' && (typeof combo !== 'object' || typeof combo.push !== 'function')) { throw new Error("Cannot remove macro. The combo must be a string or array."); }
|
||||||
|
for(mI = 0; mI < macros.length; mI += 1) {
|
||||||
|
macro = macros[mI];
|
||||||
|
if(compareCombos(combo, macro[0])) {
|
||||||
|
removeActiveKey(macro[1]);
|
||||||
|
macros.splice(mI, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes macros against the active keys. Each macro's key combo is
|
||||||
|
* checked and if found to be satisfied, the macro's key names are injected
|
||||||
|
* into active keys.
|
||||||
|
*/
|
||||||
|
function executeMacros() {
|
||||||
|
var mI, combo, kI;
|
||||||
|
for(mI = 0; mI < macros.length; mI += 1) {
|
||||||
|
combo = parseKeyCombo(macros[mI][0]);
|
||||||
|
if(activeMacros.indexOf(macros[mI]) === -1 && isSatisfiedCombo(combo)) {
|
||||||
|
activeMacros.push(macros[mI]);
|
||||||
|
for(kI = 0; kI < macros[mI][1].length; kI += 1) {
|
||||||
|
addActiveKey(macros[mI][1][kI]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prunes active macros. Checks each active macro's key combo and if found
|
||||||
|
* to no longer to be satisfied, each of the macro's key names are removed
|
||||||
|
* from active keys.
|
||||||
|
*/
|
||||||
|
function pruneMacros() {
|
||||||
|
var mI, combo, kI;
|
||||||
|
for(mI = 0; mI < activeMacros.length; mI += 1) {
|
||||||
|
combo = parseKeyCombo(activeMacros[mI][0]);
|
||||||
|
if(isSatisfiedCombo(combo) === false) {
|
||||||
|
for(kI = 0; kI < activeMacros[mI][1].length; kI += 1) {
|
||||||
|
removeActiveKey(activeMacros[mI][1][kI]);
|
||||||
|
}
|
||||||
|
activeMacros.splice(mI, 1);
|
||||||
|
mI -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//////////////
|
||||||
|
// BINDINGS //
|
||||||
|
//////////////
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a binding object, and, if provided, binds a key down hander and
|
||||||
|
* a key up handler. Returns a binding object that emits keyup and
|
||||||
|
* keydown events.
|
||||||
|
* @param {String} keyCombo
|
||||||
|
* @param {Function} keyDownCallback [Optional]
|
||||||
|
* @param {Function} keyUpCallback [Optional]
|
||||||
|
* @return {Object} binding
|
||||||
|
*/
|
||||||
|
function createBinding(keyCombo, keyDownCallback, keyUpCallback) {
|
||||||
|
var api = {}, binding, subBindings = [], bindingApi = {}, kI,
|
||||||
|
subCombo;
|
||||||
|
|
||||||
|
//break the combo down into a combo array
|
||||||
|
if(typeof keyCombo === 'string') {
|
||||||
|
keyCombo = parseKeyCombo(keyCombo);
|
||||||
|
}
|
||||||
|
|
||||||
|
//bind each sub combo contained within the combo string
|
||||||
|
for(kI = 0; kI < keyCombo.length; kI += 1) {
|
||||||
|
binding = {};
|
||||||
|
|
||||||
|
//stringify the combo again
|
||||||
|
subCombo = stringifyKeyCombo([keyCombo[kI]]);
|
||||||
|
|
||||||
|
//validate the sub combo
|
||||||
|
if(typeof subCombo !== 'string') { throw new Error('Failed to bind key combo. The key combo must be string.'); }
|
||||||
|
|
||||||
|
//create the binding
|
||||||
|
binding.keyCombo = subCombo;
|
||||||
|
binding.keyDownCallback = [];
|
||||||
|
binding.keyUpCallback = [];
|
||||||
|
|
||||||
|
//inject the key down and key up callbacks if given
|
||||||
|
if(keyDownCallback) { binding.keyDownCallback.push(keyDownCallback); }
|
||||||
|
if(keyUpCallback) { binding.keyUpCallback.push(keyUpCallback); }
|
||||||
|
|
||||||
|
//stash the new binding
|
||||||
|
bindings.push(binding);
|
||||||
|
subBindings.push(binding);
|
||||||
|
}
|
||||||
|
|
||||||
|
//build the binding api
|
||||||
|
api.clear = clear;
|
||||||
|
api.on = on;
|
||||||
|
return api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the binding
|
||||||
|
*/
|
||||||
|
function clear() {
|
||||||
|
var bI;
|
||||||
|
for(bI = 0; bI < subBindings.length; bI += 1) {
|
||||||
|
bindings.splice(bindings.indexOf(subBindings[bI]), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accepts an event name. and any number of callbacks. When the event is
|
||||||
|
* emitted, all callbacks are executed. Available events are key up and
|
||||||
|
* key down.
|
||||||
|
* @param {String} eventName
|
||||||
|
* @return {Object} subBinding
|
||||||
|
*/
|
||||||
|
function on(eventName ) {
|
||||||
|
var api = {}, callbacks, cI, bI;
|
||||||
|
|
||||||
|
//validate event name
|
||||||
|
if(typeof eventName !== 'string') { throw new Error('Cannot bind callback. The event name must be a string.'); }
|
||||||
|
if(eventName !== 'keyup' && eventName !== 'keydown') { throw new Error('Cannot bind callback. The event name must be a "keyup" or "keydown".'); }
|
||||||
|
|
||||||
|
//gather the callbacks
|
||||||
|
callbacks = Array.prototype.slice.apply(arguments, [1]);
|
||||||
|
|
||||||
|
//stash each the new binding
|
||||||
|
for(cI = 0; cI < callbacks.length; cI += 1) {
|
||||||
|
if(typeof callbacks[cI] === 'function') {
|
||||||
|
if(eventName === 'keyup') {
|
||||||
|
for(bI = 0; bI < subBindings.length; bI += 1) {
|
||||||
|
subBindings[bI].keyUpCallback.push(callbacks[cI]);
|
||||||
|
}
|
||||||
|
} else if(eventName === 'keydown') {
|
||||||
|
for(bI = 0; bI < subBindings.length; bI += 1) {
|
||||||
|
subBindings[bI].keyDownCallback.push(callbacks[cI]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//construct and return the sub binding api
|
||||||
|
api.clear = clear;
|
||||||
|
return api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the binding
|
||||||
|
*/
|
||||||
|
function clear() {
|
||||||
|
var cI, bI;
|
||||||
|
for(cI = 0; cI < callbacks.length; cI += 1) {
|
||||||
|
if(typeof callbacks[cI] === 'function') {
|
||||||
|
if(eventName === 'keyup') {
|
||||||
|
for(bI = 0; bI < subBindings.length; bI += 1) {
|
||||||
|
subBindings[bI].keyUpCallback.splice(subBindings[bI].keyUpCallback.indexOf(callbacks[cI]), 1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for(bI = 0; bI < subBindings.length; bI += 1) {
|
||||||
|
subBindings[bI].keyDownCallback.splice(subBindings[bI].keyDownCallback.indexOf(callbacks[cI]), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears all binding attached to a given key combo. Key name order does not
|
||||||
|
* matter as long as the key combos equate.
|
||||||
|
* @param {String} keyCombo
|
||||||
|
*/
|
||||||
|
function removeBindingByKeyCombo(keyCombo) {
|
||||||
|
var bI, binding, keyName;
|
||||||
|
for(bI = 0; bI < bindings.length; bI += 1) {
|
||||||
|
binding = bindings[bI];
|
||||||
|
if(compareCombos(keyCombo, binding.keyCombo)) {
|
||||||
|
bindings.splice(bI, 1); bI -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears all binding attached to key combos containing a given key name.
|
||||||
|
* @param {String} keyName
|
||||||
|
*/
|
||||||
|
function removeBindingByKeyName(keyName) {
|
||||||
|
var bI, kI, binding;
|
||||||
|
if(keyName) {
|
||||||
|
for(bI = 0; bI < bindings.length; bI += 1) {
|
||||||
|
binding = bindings[bI];
|
||||||
|
for(kI = 0; kI < binding.keyCombo.length; kI += 1) {
|
||||||
|
if(binding.keyCombo[kI].indexOf(keyName) > -1) {
|
||||||
|
bindings.splice(bI, 1); bI -= 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
bindings = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes bindings that are active. Only allows the keys to be used once
|
||||||
|
* as to prevent binding overlap.
|
||||||
|
* @param {KeyboardEvent} event The keyboard event.
|
||||||
|
*/
|
||||||
|
function executeBindings(event) {
|
||||||
|
var bI, sBI, binding, bindingKeys, remainingKeys, cI, killEventBubble, kI, bindingKeysSatisfied,
|
||||||
|
index, sortedBindings = [], bindingWeight;
|
||||||
|
|
||||||
|
remainingKeys = [].concat(activeKeys);
|
||||||
|
for(bI = 0; bI < bindings.length; bI += 1) {
|
||||||
|
bindingWeight = extractComboKeys(bindings[bI].keyCombo).length;
|
||||||
|
if(!sortedBindings[bindingWeight]) { sortedBindings[bindingWeight] = []; }
|
||||||
|
sortedBindings[bindingWeight].push(bindings[bI]);
|
||||||
|
}
|
||||||
|
for(sBI = sortedBindings.length - 1; sBI >= 0; sBI -= 1) {
|
||||||
|
if(!sortedBindings[sBI]) { continue; }
|
||||||
|
for(bI = 0; bI < sortedBindings[sBI].length; bI += 1) {
|
||||||
|
binding = sortedBindings[sBI][bI];
|
||||||
|
bindingKeys = extractComboKeys(binding.keyCombo);
|
||||||
|
bindingKeysSatisfied = true;
|
||||||
|
for(kI = 0; kI < bindingKeys.length; kI += 1) {
|
||||||
|
if(remainingKeys.indexOf(bindingKeys[kI]) === -1) {
|
||||||
|
bindingKeysSatisfied = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(bindingKeysSatisfied && isSatisfiedCombo(binding.keyCombo)) {
|
||||||
|
activeBindings.push(binding);
|
||||||
|
for(kI = 0; kI < bindingKeys.length; kI += 1) {
|
||||||
|
index = remainingKeys.indexOf(bindingKeys[kI]);
|
||||||
|
if(index > -1) {
|
||||||
|
remainingKeys.splice(index, 1);
|
||||||
|
kI -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(cI = 0; cI < binding.keyDownCallback.length; cI += 1) {
|
||||||
|
if (binding.keyDownCallback[cI](event, getActiveKeys(), binding.keyCombo) === false) {
|
||||||
|
killEventBubble = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(killEventBubble === true) {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes bindings that are no longer satisfied by the active keys. Also
|
||||||
|
* fires the key up callbacks.
|
||||||
|
* @param {KeyboardEvent} event
|
||||||
|
*/
|
||||||
|
function pruneBindings(event) {
|
||||||
|
var bI, cI, binding, killEventBubble;
|
||||||
|
for(bI = 0; bI < activeBindings.length; bI += 1) {
|
||||||
|
binding = activeBindings[bI];
|
||||||
|
if(isSatisfiedCombo(binding.keyCombo) === false) {
|
||||||
|
for(cI = 0; cI < binding.keyUpCallback.length; cI += 1) {
|
||||||
|
if (binding.keyUpCallback[cI](event, getActiveKeys(), binding.keyCombo) === false) {
|
||||||
|
killEventBubble = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(killEventBubble === true) {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
}
|
||||||
|
activeBindings.splice(bI, 1);
|
||||||
|
bI -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////
|
||||||
|
// COMBO STRINGS //
|
||||||
|
///////////////////
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compares two key combos returning true when they are functionally
|
||||||
|
* equivalent.
|
||||||
|
* @param {String} keyComboArrayA keyCombo A key combo string or array.
|
||||||
|
* @param {String} keyComboArrayB keyCombo A key combo string or array.
|
||||||
|
* @return {Boolean}
|
||||||
|
*/
|
||||||
|
function compareCombos(keyComboArrayA, keyComboArrayB) {
|
||||||
|
var cI, sI, kI;
|
||||||
|
keyComboArrayA = parseKeyCombo(keyComboArrayA);
|
||||||
|
keyComboArrayB = parseKeyCombo(keyComboArrayB);
|
||||||
|
if(keyComboArrayA.length !== keyComboArrayB.length) { return false; }
|
||||||
|
for(cI = 0; cI < keyComboArrayA.length; cI += 1) {
|
||||||
|
if(keyComboArrayA[cI].length !== keyComboArrayB[cI].length) { return false; }
|
||||||
|
for(sI = 0; sI < keyComboArrayA[cI].length; sI += 1) {
|
||||||
|
if(keyComboArrayA[cI][sI].length !== keyComboArrayB[cI][sI].length) { return false; }
|
||||||
|
for(kI = 0; kI < keyComboArrayA[cI][sI].length; kI += 1) {
|
||||||
|
if(keyComboArrayB[cI][sI].indexOf(keyComboArrayA[cI][sI][kI]) === -1) { return false; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks to see if a key combo string or key array is satisfied by the
|
||||||
|
* currently active keys. It does not take into account spent keys.
|
||||||
|
* @param {String} keyCombo A key combo string or array.
|
||||||
|
* @return {Boolean}
|
||||||
|
*/
|
||||||
|
function isSatisfiedCombo(keyCombo) {
|
||||||
|
var cI, sI, stage, kI, stageOffset = 0, index, comboMatches;
|
||||||
|
keyCombo = parseKeyCombo(keyCombo);
|
||||||
|
for(cI = 0; cI < keyCombo.length; cI += 1) {
|
||||||
|
comboMatches = true;
|
||||||
|
stageOffset = 0;
|
||||||
|
for(sI = 0; sI < keyCombo[cI].length; sI += 1) {
|
||||||
|
stage = [].concat(keyCombo[cI][sI]);
|
||||||
|
for(kI = stageOffset; kI < activeKeys.length; kI += 1) {
|
||||||
|
index = stage.indexOf(activeKeys[kI]);
|
||||||
|
if(index > -1) {
|
||||||
|
stage.splice(index, 1);
|
||||||
|
stageOffset = kI;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(stage.length !== 0) { comboMatches = false; break; }
|
||||||
|
}
|
||||||
|
if(comboMatches) { return true; }
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accepts a key combo array or string and returns a flat array containing all keys referenced by
|
||||||
|
* the key combo.
|
||||||
|
* @param {String} keyCombo A key combo string or array.
|
||||||
|
* @return {Array}
|
||||||
|
*/
|
||||||
|
function extractComboKeys(keyCombo) {
|
||||||
|
var cI, sI, kI, keys = [];
|
||||||
|
keyCombo = parseKeyCombo(keyCombo);
|
||||||
|
for(cI = 0; cI < keyCombo.length; cI += 1) {
|
||||||
|
for(sI = 0; sI < keyCombo[cI].length; sI += 1) {
|
||||||
|
keys = keys.concat(keyCombo[cI][sI]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a key combo string into a 3 dimensional array.
|
||||||
|
* - Level 1 - sub combos.
|
||||||
|
* - Level 2 - combo stages. A stage is a set of key name pairs that must
|
||||||
|
* be satisfied in the order they are defined.
|
||||||
|
* - Level 3 - each key name to the stage.
|
||||||
|
* @param {String|Array} keyCombo A key combo string.
|
||||||
|
* @return {Array}
|
||||||
|
*/
|
||||||
|
function parseKeyCombo(keyCombo) {
|
||||||
|
var s = keyCombo, i = 0, op = 0, ws = false, nc = false, combos = [], combo = [], stage = [], key = '';
|
||||||
|
|
||||||
|
if(typeof keyCombo === 'object' && typeof keyCombo.push === 'function') { return keyCombo; }
|
||||||
|
if(typeof keyCombo !== 'string') { throw new Error('Cannot parse "keyCombo" because its type is "' + (typeof keyCombo) + '". It must be a "string".'); }
|
||||||
|
|
||||||
|
//remove leading whitespace
|
||||||
|
while(s.charAt(i) === ' ') { i += 1; }
|
||||||
|
while(true) {
|
||||||
|
if(s.charAt(i) === ' ') {
|
||||||
|
//white space & next combo op
|
||||||
|
while(s.charAt(i) === ' ') { i += 1; }
|
||||||
|
ws = true;
|
||||||
|
} else if(s.charAt(i) === ',') {
|
||||||
|
if(op || nc) { throw new Error('Failed to parse key combo. Unexpected , at character index ' + i + '.'); }
|
||||||
|
nc = true;
|
||||||
|
i += 1;
|
||||||
|
} else if(s.charAt(i) === '+') {
|
||||||
|
//next key
|
||||||
|
if(key.length) { stage.push(key); key = ''; }
|
||||||
|
if(op || nc) { throw new Error('Failed to parse key combo. Unexpected + at character index ' + i + '.'); }
|
||||||
|
op = true;
|
||||||
|
i += 1;
|
||||||
|
} else if(s.charAt(i) === '>') {
|
||||||
|
//next stage op
|
||||||
|
if(key.length) { stage.push(key); key = ''; }
|
||||||
|
if(stage.length) { combo.push(stage); stage = []; }
|
||||||
|
if(op || nc) { throw new Error('Failed to parse key combo. Unexpected > at character index ' + i + '.'); }
|
||||||
|
op = true;
|
||||||
|
i += 1;
|
||||||
|
} else if(i < s.length - 1 && s.charAt(i) === '!' && (s.charAt(i + 1) === '>' || s.charAt(i + 1) === ',' || s.charAt(i + 1) === '+')) {
|
||||||
|
key += s.charAt(i + 1);
|
||||||
|
op = false;
|
||||||
|
ws = false;
|
||||||
|
nc = false;
|
||||||
|
i += 2;
|
||||||
|
} else if(i < s.length && s.charAt(i) !== '+' && s.charAt(i) !== '>' && s.charAt(i) !== ',' && s.charAt(i) !== ' ') {
|
||||||
|
//end combo
|
||||||
|
if(op === false && ws === true || nc === true) {
|
||||||
|
if(key.length) { stage.push(key); key = ''; }
|
||||||
|
if(stage.length) { combo.push(stage); stage = []; }
|
||||||
|
if(combo.length) { combos.push(combo); combo = []; }
|
||||||
|
}
|
||||||
|
op = false;
|
||||||
|
ws = false;
|
||||||
|
nc = false;
|
||||||
|
//key
|
||||||
|
while(i < s.length && s.charAt(i) !== '+' && s.charAt(i) !== '>' && s.charAt(i) !== ',' && s.charAt(i) !== ' ') {
|
||||||
|
key += s.charAt(i);
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//unknown char
|
||||||
|
i += 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//end of combos string
|
||||||
|
if(i >= s.length) {
|
||||||
|
if(key.length) { stage.push(key); key = ''; }
|
||||||
|
if(stage.length) { combo.push(stage); stage = []; }
|
||||||
|
if(combo.length) { combos.push(combo); combo = []; }
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return combos;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stringifys a key combo.
|
||||||
|
* @param {Array|String} keyComboArray A key combo array. If a key
|
||||||
|
* combo string is given it will be returned.
|
||||||
|
* @return {String}
|
||||||
|
*/
|
||||||
|
function stringifyKeyCombo(keyComboArray) {
|
||||||
|
var cI, ccI, output = [];
|
||||||
|
if(typeof keyComboArray === 'string') { return keyComboArray; }
|
||||||
|
if(typeof keyComboArray !== 'object' || typeof keyComboArray.push !== 'function') { throw new Error('Cannot stringify key combo.'); }
|
||||||
|
for(cI = 0; cI < keyComboArray.length; cI += 1) {
|
||||||
|
output[cI] = [];
|
||||||
|
for(ccI = 0; ccI < keyComboArray[cI].length; ccI += 1) {
|
||||||
|
output[cI][ccI] = keyComboArray[cI][ccI].join(' + ');
|
||||||
|
}
|
||||||
|
output[cI] = output[cI].join(' > ');
|
||||||
|
}
|
||||||
|
return output.join(' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////
|
||||||
|
// ACTIVE KEYS //
|
||||||
|
/////////////////
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the a copy of the active keys array.
|
||||||
|
* @return {Array}
|
||||||
|
*/
|
||||||
|
function getActiveKeys() {
|
||||||
|
return [].concat(activeKeys);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a key to the active keys array, but only if it has not already been
|
||||||
|
* added.
|
||||||
|
* @param {String} keyName The key name string.
|
||||||
|
*/
|
||||||
|
function addActiveKey(keyName) {
|
||||||
|
if(keyName.match(/\s/)) { throw new Error('Cannot add key name ' + keyName + ' to active keys because it contains whitespace.'); }
|
||||||
|
if(activeKeys.indexOf(keyName) > -1) { return; }
|
||||||
|
activeKeys.push(keyName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a key from the active keys array.
|
||||||
|
* @param {String} keyNames The key name string.
|
||||||
|
*/
|
||||||
|
function removeActiveKey(keyName) {
|
||||||
|
var keyCode = getKeyCode(keyName);
|
||||||
|
if(keyCode === '91' || keyCode === '92') { activeKeys = []; } //remove all key on release of super.
|
||||||
|
else { activeKeys.splice(activeKeys.indexOf(keyName), 1); }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/////////////
|
||||||
|
// LOCALES //
|
||||||
|
/////////////
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a new locale. This is useful if you would like to add support for a new keyboard layout. It could also be useful for
|
||||||
|
* alternative key names. For example if you program games you could create a locale for your key mappings. Instead of key 65 mapped
|
||||||
|
* to 'a' you could map it to 'jump'.
|
||||||
|
* @param {String} localeName The name of the new locale.
|
||||||
|
* @param {Object} localeMap The locale map.
|
||||||
|
*/
|
||||||
|
function registerLocale(localeName, localeMap) {
|
||||||
|
|
||||||
|
//validate arguments
|
||||||
|
if(typeof localeName !== 'string') { throw new Error('Cannot register new locale. The locale name must be a string.'); }
|
||||||
|
if(typeof localeMap !== 'object') { throw new Error('Cannot register ' + localeName + ' locale. The locale map must be an object.'); }
|
||||||
|
if(typeof localeMap.map !== 'object') { throw new Error('Cannot register ' + localeName + ' locale. The locale map is invalid.'); }
|
||||||
|
|
||||||
|
//stash the locale
|
||||||
|
if(!localeMap.macros) { localeMap.macros = []; }
|
||||||
|
locales[localeName] = localeMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Swaps the current locale.
|
||||||
|
* @param {String} localeName The locale to activate.
|
||||||
|
* @return {Object}
|
||||||
|
*/
|
||||||
|
function getSetLocale(localeName) {
|
||||||
|
|
||||||
|
//if a new locale is given then set it
|
||||||
|
if(localeName) {
|
||||||
|
if(typeof localeName !== 'string') { throw new Error('Cannot set locale. The locale name must be a string.'); }
|
||||||
|
if(!locales[localeName]) { throw new Error('Cannot set locale to ' + localeName + ' because it does not exist. If you would like to submit a ' + localeName + ' locale map for KeyboardJS please submit it at https://github.com/RobertWHurst/KeyboardJS/issues.'); }
|
||||||
|
|
||||||
|
//set the current map and macros
|
||||||
|
map = locales[localeName].map;
|
||||||
|
macros = locales[localeName].macros;
|
||||||
|
|
||||||
|
//set the current locale
|
||||||
|
locale = localeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
//return the current locale
|
||||||
|
return locale;
|
||||||
|
}
|
||||||
|
});
|
37760
sources/libs/three.js
Normal file
722
sources/libs/three.min.js
vendored
Normal file
15
sources/libs/tween.min.js
vendored
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
// tween.js - http://github.com/sole/tween.js
|
||||||
|
'use strict';void 0===Date.now&&(Date.now=function(){return(new Date).valueOf()});
|
||||||
|
var TWEEN=TWEEN||function(){var a=[];return{REVISION:"12",getAll:function(){return a},removeAll:function(){a=[]},add:function(c){a.push(c)},remove:function(c){c=a.indexOf(c);-1!==c&&a.splice(c,1)},update:function(c){if(0===a.length)return!1;for(var b=0,c=void 0!==c?c:"undefined"!==typeof window&&void 0!==window.performance&&void 0!==window.performance.now?window.performance.now():Date.now();b<a.length;)a[b].update(c)?b++:a.splice(b,1);return!0}}}();
|
||||||
|
TWEEN.Tween=function(a){var c={},b={},d={},e=1E3,g=0,h=!1,j=!1,q=0,m=null,v=TWEEN.Easing.Linear.None,w=TWEEN.Interpolation.Linear,n=[],r=null,s=!1,t=null,u=null,k;for(k in a)c[k]=parseFloat(a[k],10);this.to=function(a,c){void 0!==c&&(e=c);b=a;return this};this.start=function(e){TWEEN.add(this);j=!0;s=!1;m=void 0!==e?e:"undefined"!==typeof window&&void 0!==window.performance&&void 0!==window.performance.now?window.performance.now():Date.now();m+=q;for(var f in b){if(b[f]instanceof Array){if(0===b[f].length)continue;
|
||||||
|
b[f]=[a[f]].concat(b[f])}c[f]=a[f];!1===c[f]instanceof Array&&(c[f]*=1);d[f]=c[f]||0}return this};this.stop=function(){if(!j)return this;TWEEN.remove(this);j=!1;this.stopChainedTweens();return this};this.stopChainedTweens=function(){for(var a=0,b=n.length;a<b;a++)n[a].stop()};this.delay=function(a){q=a;return this};this.repeat=function(a){g=a;return this};this.yoyo=function(a){h=a;return this};this.easing=function(a){v=a;return this};this.interpolation=function(a){w=a;return this};this.chain=function(){n=
|
||||||
|
arguments;return this};this.onStart=function(a){r=a;return this};this.onUpdate=function(a){t=a;return this};this.onComplete=function(a){u=a;return this};this.update=function(p){var f;if(p<m)return!0;!1===s&&(null!==r&&r.call(a),s=!0);var i=(p-m)/e,i=1<i?1:i,j=v(i);for(f in b){var k=c[f]||0,l=b[f];l instanceof Array?a[f]=w(l,j):("string"===typeof l&&(l=k+parseFloat(l,10)),"number"===typeof l&&(a[f]=k+(l-k)*j))}null!==t&&t.call(a,j);if(1==i)if(0<g){isFinite(g)&&g--;for(f in d)"string"===typeof b[f]&&
|
||||||
|
(d[f]+=parseFloat(b[f],10)),h&&(i=d[f],d[f]=b[f],b[f]=i),c[f]=d[f];m=p+q}else{null!==u&&u.call(a);f=0;for(i=n.length;f<i;f++)n[f].start(p);return!1}return!0}};
|
||||||
|
TWEEN.Easing={Linear:{None:function(a){return a}},Quadratic:{In:function(a){return a*a},Out:function(a){return a*(2-a)},InOut:function(a){return 1>(a*=2)?0.5*a*a:-0.5*(--a*(a-2)-1)}},Cubic:{In:function(a){return a*a*a},Out:function(a){return--a*a*a+1},InOut:function(a){return 1>(a*=2)?0.5*a*a*a:0.5*((a-=2)*a*a+2)}},Quartic:{In:function(a){return a*a*a*a},Out:function(a){return 1- --a*a*a*a},InOut:function(a){return 1>(a*=2)?0.5*a*a*a*a:-0.5*((a-=2)*a*a*a-2)}},Quintic:{In:function(a){return a*a*a*
|
||||||
|
a*a},Out:function(a){return--a*a*a*a*a+1},InOut:function(a){return 1>(a*=2)?0.5*a*a*a*a*a:0.5*((a-=2)*a*a*a*a+2)}},Sinusoidal:{In:function(a){return 1-Math.cos(a*Math.PI/2)},Out:function(a){return Math.sin(a*Math.PI/2)},InOut:function(a){return 0.5*(1-Math.cos(Math.PI*a))}},Exponential:{In:function(a){return 0===a?0:Math.pow(1024,a-1)},Out:function(a){return 1===a?1:1-Math.pow(2,-10*a)},InOut:function(a){return 0===a?0:1===a?1:1>(a*=2)?0.5*Math.pow(1024,a-1):0.5*(-Math.pow(2,-10*(a-1))+2)}},Circular:{In:function(a){return 1-
|
||||||
|
Math.sqrt(1-a*a)},Out:function(a){return Math.sqrt(1- --a*a)},InOut:function(a){return 1>(a*=2)?-0.5*(Math.sqrt(1-a*a)-1):0.5*(Math.sqrt(1-(a-=2)*a)+1)}},Elastic:{In:function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b?(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return-(b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4))},Out:function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b?(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return b*Math.pow(2,-10*a)*Math.sin((a-c)*
|
||||||
|
2*Math.PI/0.4)+1},InOut:function(a){var c,b=0.1;if(0===a)return 0;if(1===a)return 1;!b||1>b?(b=1,c=0.1):c=0.4*Math.asin(1/b)/(2*Math.PI);return 1>(a*=2)?-0.5*b*Math.pow(2,10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4):0.5*b*Math.pow(2,-10*(a-=1))*Math.sin((a-c)*2*Math.PI/0.4)+1}},Back:{In:function(a){return a*a*(2.70158*a-1.70158)},Out:function(a){return--a*a*(2.70158*a+1.70158)+1},InOut:function(a){return 1>(a*=2)?0.5*a*a*(3.5949095*a-2.5949095):0.5*((a-=2)*a*(3.5949095*a+2.5949095)+2)}},Bounce:{In:function(a){return 1-
|
||||||
|
TWEEN.Easing.Bounce.Out(1-a)},Out:function(a){return a<1/2.75?7.5625*a*a:a<2/2.75?7.5625*(a-=1.5/2.75)*a+0.75:a<2.5/2.75?7.5625*(a-=2.25/2.75)*a+0.9375:7.5625*(a-=2.625/2.75)*a+0.984375},InOut:function(a){return 0.5>a?0.5*TWEEN.Easing.Bounce.In(2*a):0.5*TWEEN.Easing.Bounce.Out(2*a-1)+0.5}}};
|
||||||
|
TWEEN.Interpolation={Linear:function(a,c){var b=a.length-1,d=b*c,e=Math.floor(d),g=TWEEN.Interpolation.Utils.Linear;return 0>c?g(a[0],a[1],d):1<c?g(a[b],a[b-1],b-d):g(a[e],a[e+1>b?b:e+1],d-e)},Bezier:function(a,c){var b=0,d=a.length-1,e=Math.pow,g=TWEEN.Interpolation.Utils.Bernstein,h;for(h=0;h<=d;h++)b+=e(1-c,d-h)*e(c,h)*a[h]*g(d,h);return b},CatmullRom:function(a,c){var b=a.length-1,d=b*c,e=Math.floor(d),g=TWEEN.Interpolation.Utils.CatmullRom;return a[0]===a[b]?(0>c&&(e=Math.floor(d=b*(1+c))),g(a[(e-
|
||||||
|
1+b)%b],a[e],a[(e+1)%b],a[(e+2)%b],d-e)):0>c?a[0]-(g(a[0],a[0],a[1],a[1],-d)-a[0]):1<c?a[b]-(g(a[b],a[b],a[b-1],a[b-1],d-b)-a[b]):g(a[e?e-1:0],a[e],a[b<e+1?b:e+1],a[b<e+2?b:e+2],d-e)},Utils:{Linear:function(a,c,b){return(c-a)*b+a},Bernstein:function(a,c){var b=TWEEN.Interpolation.Utils.Factorial;return b(a)/b(c)/b(a-c)},Factorial:function(){var a=[1];return function(c){var b=1,d;if(a[c])return a[c];for(d=c;1<d;d--)b*=d;return a[c]=b}}(),CatmullRom:function(a,c,b,d,e){var a=0.5*(b-a),d=0.5*(d-c),g=
|
||||||
|
e*e;return(2*c-2*b+a+d)*e*g+(-3*c+3*b-2*a-d)*g+a*e+c}}};
|
11
sources/meta/pp.svg
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Generator: Adobe Illustrator 15.0.2, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||||
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||||
|
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||||
|
width="20px" height="20px" viewBox="0 0 20 20" enable-background="new 0 0 20 20" xml:space="preserve">
|
||||||
|
<g>
|
||||||
|
<circle fill="#FFFFFF" cx="10" cy="10" r="10"/>
|
||||||
|
</g>
|
||||||
|
<path fill-rule="evenodd" clip-rule="evenodd" fill="#195A7F" d="M12.3,4.8h-5L5,15h3l0.7-3.4h2.1c2,0,3.7-1.2,4.2-3.4
|
||||||
|
C15.5,5.9,13.8,4.8,12.3,4.8z M12.2,8.3c-0.2,0.8-0.9,1.4-1.7,1.4H9.1l0.6-2.8h1.4C11.9,6.9,12.4,7.5,12.2,8.3z"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 756 B |
BIN
sources/psds/Texture_1024.psd
Normal file
BIN
sources/psds/Texture_128.psd
Normal file
BIN
sources/psds/Texture_16.psd
Normal file
BIN
sources/psds/Texture_2.psd
Normal file
BIN
sources/psds/Texture_2048.psd
Normal file
BIN
sources/psds/Texture_256.psd
Normal file
BIN
sources/psds/Texture_32.psd
Normal file
BIN
sources/psds/Texture_4.psd
Normal file
BIN
sources/psds/Texture_512.psd
Normal file
BIN
sources/psds/Texture_64.psd
Normal file
BIN
sources/psds/Texture_8.psd
Normal file
117
sources/styles/container.css
Normal file
|
@ -0,0 +1,117 @@
|
||||||
|
html, body {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
background: #e9eaed;
|
||||||
|
color: #776e65;
|
||||||
|
font-family: "Clear Sans", "Helvetica Neue", Arial, sans-serif;
|
||||||
|
font-size: 18px; }
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 5px 0; }
|
||||||
|
|
||||||
|
.heading:after {
|
||||||
|
content: "";
|
||||||
|
display: block;
|
||||||
|
clear: both; }
|
||||||
|
|
||||||
|
h1.title {
|
||||||
|
font-size: 80px;
|
||||||
|
font-weight: bold;
|
||||||
|
margin: 0;
|
||||||
|
display: block;
|
||||||
|
float: left; }
|
||||||
|
|
||||||
|
.scores-container {
|
||||||
|
float: right;
|
||||||
|
text-align: right; }
|
||||||
|
|
||||||
|
p {
|
||||||
|
margin-top: 0;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
line-height: 1.65; }
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: #776e65;
|
||||||
|
font-weight: bold;
|
||||||
|
text-decoration: underline;
|
||||||
|
cursor: pointer; }
|
||||||
|
|
||||||
|
strong.important {
|
||||||
|
text-transform: uppercase; }
|
||||||
|
|
||||||
|
hr {
|
||||||
|
border: none;
|
||||||
|
border-bottom: 1px solid #d8d4d0;
|
||||||
|
margin-top: 20px;
|
||||||
|
margin-bottom: 30px; }
|
||||||
|
|
||||||
|
.container {
|
||||||
|
width: 69%;
|
||||||
|
margin: 0 auto; }
|
||||||
|
|
||||||
|
.container:after {
|
||||||
|
padding-top: 56.25%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.game-container {
|
||||||
|
margin-top: 40px;
|
||||||
|
position: relative;
|
||||||
|
cursor: default;
|
||||||
|
touch-action: none;
|
||||||
|
background: #bbada0;
|
||||||
|
border-radius: 6px;
|
||||||
|
width: 69vw;
|
||||||
|
height: 38.8vw;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.game-container:after {
|
||||||
|
padding-top: 56.25%;
|
||||||
|
}
|
||||||
|
.container .demo-start{
|
||||||
|
width: 69vw;
|
||||||
|
height: 38.8vw;
|
||||||
|
}
|
||||||
|
|
||||||
|
.donate_button{
|
||||||
|
width: 163px;
|
||||||
|
height: 35px;
|
||||||
|
color: #776e65;
|
||||||
|
font-size: 15pt;
|
||||||
|
font-weight: bold;
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
td{
|
||||||
|
vertical-align:central;
|
||||||
|
}
|
||||||
|
.container .demo-2{
|
||||||
|
width: 0%;
|
||||||
|
height: 0%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.above-game:after {
|
||||||
|
content: "";
|
||||||
|
display: block;
|
||||||
|
clear: both; }
|
||||||
|
|
||||||
|
.game-intro {
|
||||||
|
float: left;
|
||||||
|
line-height: 42px;
|
||||||
|
margin-bottom: 0; }
|
||||||
|
|
||||||
|
.restart-button {
|
||||||
|
display: inline-block;
|
||||||
|
background: #8f7a66;
|
||||||
|
border-radius: 3px;
|
||||||
|
padding: 0 20px;
|
||||||
|
text-decoration: none;
|
||||||
|
color: #f9f6f2;
|
||||||
|
height: 40px;
|
||||||
|
line-height: 42px;
|
||||||
|
display: block;
|
||||||
|
text-align: center;
|
||||||
|
float: right; }
|
||||||
|
|
||||||
|
.game-explanation {
|
||||||
|
margin-top: 50px; }
|