rezoner / playground

Playground.js is a framework for your javascript based games. It gives you out-of-box access to essentials like mouse, keyboard, sound and well designed architecture that you can expand to your needs.
MIT License
459 stars 50 forks source link

Added the ability to load via `require` #18

Closed shovon closed 8 years ago

shovon commented 8 years ago

If this pull request is merged, some users (such as myself) will now be able to load playground.js by simply using require (the CommonJS-style of importing modules), depending on their set-up:

var playground = require('playground');

Much easier for people like me, and it will definitely make it easier for developers to organize their code. Again, no need of script tags.

This pull request adds a package.json file for the sake of compatibility with npm, a .gitignore file to ignore the node_modules folder, enhances plugins/playground.three.js to be loadable via require and enhances build.js to distribute a CommonJS-equivalent of the build files.


Now, what about plugins?

The answer to that is to turn plugins into mixins, but only on CommonJS environments, so that those who are not using CommonJS, they won't be affected. As a preview of how things would work out, I converted playground.three.js so that you can see it for ourself. And, in order to use the mixin, one can manually extend the Application class with the plugin, like so:

var Application = require('playground.js').Application;
var playgroundThreeMixin = require('playground.js/plugins/playground.three.js').playgroundThreeMixin;

Object.assign(Application.prototype, playgroundThreeMixin);

// Application should now be extended.

Demo | Source

shovon commented 8 years ago

@rezoner by the ways, playground.js is an amazing project! Adding CommonJS support would make it even more awesome!

TNick commented 8 years ago

:+1: