-
Notifications
You must be signed in to change notification settings - Fork 6
creating a game module
I've written a python script (newModule.py) which should handle creation of a new module. Just run it, enter your module name and it should do all this silly legwork.
The last two steps (6. require() your module from app.js and 7. include your directive in game page html) remain manual because there are additional, less tedious steps needed to fully integrate the module into the game. You should develop the module using your test html page first and then request integration on gitter; @7yl4r will help handle that kludgery. This script should get your test page set up with boilerplate code in <1s.
I'm leaving these instructions here for reference and also because they give some insight on what the script is doing.
The way this all fits together is a bit odd, so I'm going to walk through the steps of creating a new game "module". Our example module will be the "youWin" module, which shows the "you win" screen. I'll include code snippets here, but for a prettier diff of the changes view this commit.
Create a new directory in ng-modules for your module. To get started It's easiest to copy an existing module as a boilerplate. (TODO: add a real boilerplate module) For now, let's copy the contents of "./ng-modules/mainMenu" into our new directory "./ng-modules/youWin".
Here's a quick breakdown of a module's contents:
- mainMenu.html - the angular template for this module
- index.html - a page which loads the full application's javascript, but only shows this module in the dom. This is for testing & speedy development.
- mainMenu.less - a less (basically fancy css) file to define styles needed for your module
- mainMenu.js (OR mainMenu.coffee*) - defines an angular directive for your module and the relevant controller code.
*NOTE: you can use a javascript or coffeescript file for your controller. Don't worry about compiling the coffeescript, that's all handled at build-time.
we want to rename all mainMenu.* files in this new directory to be youWin.* The camel-case spelling is just a convention, but it's best we stick with it in case we get more clever about generating modules later.
Firstly, we want to replace instances of 'main-menu' with 'you-win' (note the use of html-friendly dashes in place of camel-case sometimes, this is another non-required convention to follow), and 'mainMenu'->'youWin'
// previously:
var app = angular.module('main-menu', []);
...
templateUrl: "/ng-modules/mainMenu/mainMenu.html"
...
module.exports = angular.module('main-menu').name;
// now:
var app = angular.module('you-win', []);
...
templateUrl: "/ng-modules/youWin/youWin.html"
...
module.exports = angular.module('you-win').name;
This sets up a new angular module, and connects your new template to the directive.
Setting up the new test file shouldn't be too hard. At it's simplest you just change the directive included:
<!-- before -->
main menu is the game's starting menu.
<main-menu></main-menu>
<!-- after -->
you win is what shows when you win.
<you-win></you-win>
To tell the build script where the new module is, we need to add the name of the module & the location of the script to the "browser" object in /package.json.
"browser":{
...
"main-menu": "./ng-modules/mainMenu/mainMenu.js", // added this comma and the next line
"you-win": "./ng-modules/youWin/youWin.js" // (or .coffee)
}
To include your module in the application we add a require statement to the "main" script, /app.js:
var app = angular.module('ng-boot-boiler-demo',
[
...
require('main-menu'), // added this comma and next line
require('you-win')
],
This connects your javascript in to the main application.
To add your module's html to the main application, we add your new directive to the main game page, /index.html.
<splash-header></splash-header>
<div class="container">
the sections below are toggled hide/show as needed
main menu
<main-menu></main-menu>
<!-- added new directive: -->
you win
<you-win></you-win>
</div><!-- /.container -->
To have your .less styles be included, you must add an import at the top of /app.less
@import "ng-modules/youWin/youWin";
Now you're finally ready to flesh out the module. Change the html in the template (ng-modules/youWin/youWin.html) and add controller code to go along with it in ng-modules/youWin/youWin.js. You can quickly develop and test by using localhost:8000/ng-modules/youWin to navigate to your module directly.
#Nav
- Locations
- KSC, Earth
- ISS, LEO
- Moonbase Alpha, Moon
- ...
- Planetary bodies
- Earth
- Moon
- Ceres
- Mars
- Jupiter
- Europa
- Ships
- J-R0D
- Orion mk3
- Trajectories
- story:
- Gameplay
- Characters
- art style:
- sound design
- UI