├── .gitignore ├── template_src ├── assets │ └── .gitignore ├── www │ └── .gitignore ├── src │ ├── translations │ │ └── .gitignore │ ├── ts │ │ ├── states │ │ │ ├── states.ts │ │ │ ├── boot.ts │ │ │ └── preload.ts │ │ ├── window.ts │ │ ├── startup.ts │ │ ├── config.ts │ │ └── main.ts │ └── html │ │ └── index.html ├── tslint.json ├── .gitignore ├── typings.json ├── config.json ├── tsconfig.json ├── package.json ├── webpack.config.js └── Gruntfile.js ├── package.json ├── index.js ├── README.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .idea 3 | -------------------------------------------------------------------------------- /template_src/assets/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /template_src/www/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /template_src/src/translations/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /template_src/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./node_modules/phaser/v2/typescript/tslint.json" 3 | } -------------------------------------------------------------------------------- /template_src/.gitignore: -------------------------------------------------------------------------------- 1 | .tscache/ 2 | node_modules/ 3 | .idea/ 4 | .baseDir.ts 5 | typings/ 6 | src/ts/**/*.js 7 | src/ts/**/*.map 8 | -------------------------------------------------------------------------------- /template_src/typings.json: -------------------------------------------------------------------------------- 1 | { 2 | "globalDependencies": { 3 | "cordova": "registry:dt/cordova#0.0.0+20160819210047", 4 | "phaser": "github:photonstorm/phaser/v2/typescript/typings.json" 5 | }, 6 | "dependencies": { 7 | "lodash": "registry:npm/lodash#4.0.0+20161015015725" 8 | } 9 | } -------------------------------------------------------------------------------- /template_src/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "viewport": { 3 | "width": 800, 4 | "height": 600 5 | }, 6 | "platforms": { 7 | "browser": { 8 | "viewport": { 9 | "width": 640, 10 | "height": 480 11 | } 12 | }, 13 | "android": { 14 | "viewport": { 15 | "width": 320, 16 | "height": 200 17 | } 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /template_src/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es5", 5 | "sourceMap": false 6 | }, 7 | "include": [ 8 | "typings/index.d.ts", 9 | "src/ts/**/*.ts" 10 | ], 11 | "exclude": [ 12 | "node_modules", 13 | "bower_components", 14 | "platforms", 15 | "plugins", 16 | "assets", 17 | "hooks", 18 | "www" 19 | ] 20 | } -------------------------------------------------------------------------------- /template_src/src/ts/states/states.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Craig A. Hancock 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | export * from "./boot"; 18 | export * from "./preload"; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cordova-phaser-ts-jed", 3 | "version": "0.3.1", 4 | "description": "Cordova template that provides Phaser Typescript support, plus Jed for i18n.", 5 | "main": "index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+ssh://git@github.com/fractile81/cordova-phaser-ts-jed.git" 9 | }, 10 | "keywords": [ 11 | "cordova:template", 12 | "phaser", 13 | "typescript", 14 | "ts", 15 | "jed", 16 | "ecosystem:cordova" 17 | ], 18 | "author": "Craig A. Hancock", 19 | "license": "Apache-2.0", 20 | "bugs": { 21 | "url": "https://github.com/fractile81/cordova-phaser-ts-jed/issues" 22 | }, 23 | "homepage": "https://github.com/fractile81/cordova-phaser-ts-jed#readme" 24 | } 25 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Craig A. Hancock 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | var path = require('path'); 18 | 19 | module.exports = { 20 | dirname : path.join(__dirname, 'template_src') 21 | }; 22 | -------------------------------------------------------------------------------- /template_src/src/ts/window.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Craig A. Hancock 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Any window properties you need access to in TypeScript need to be defined here as outlined. 19 | */ 20 | interface Window { 21 | appConfig: any; 22 | device: any; 23 | StatusBar: any; 24 | } 25 | -------------------------------------------------------------------------------- /template_src/src/ts/startup.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Craig A. Hancock 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { Main } from "./main"; 18 | 19 | // Entry point for the app 20 | window.onload = () => { 21 | // tslint:disable-next-line:no-unused-new no-unused-variable 22 | let app = new Main(window.appConfig || {}); 23 | }; 24 | -------------------------------------------------------------------------------- /template_src/src/ts/states/boot.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Craig A. Hancock 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | export class Boot extends Phaser.State { 18 | public preload(): void { 19 | 20 | } 21 | 22 | public create(): void { 23 | this.game.stage.backgroundColor = "#000080"; 24 | this.game.state.start("Preload"); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /template_src/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "yourapp", 3 | "description": "Your description here.", 4 | "version": "1.0.0", 5 | "private": true, 6 | "license": "UNLICENSED", 7 | "scripts": { 8 | "install": "grunt clean:postinstall typings:install" 9 | }, 10 | "devDependencies": { 11 | "express": "^4.14.0", 12 | "grunt": "^1.0.1", 13 | "grunt-contrib-clean": "^1.0.0", 14 | "grunt-contrib-copy": "^1.0.0", 15 | "grunt-contrib-watch": "^1.0.0", 16 | "grunt-express": "^1.4.1", 17 | "grunt-open": "^0.2.3", 18 | "grunt-parallel": "^0.5.1", 19 | "grunt-po2json": "^0.3.0", 20 | "grunt-ts": "^6.0.0-beta.3", 21 | "grunt-tslint": "^3.3.0", 22 | "grunt-typings": "^0.1.5", 23 | "grunt-webpack": "^1.0.18", 24 | "jed": "^1.1.1", 25 | "po2json": "^0.4.5", 26 | "ts-loader": "^1.2.2", 27 | "tslint": "^3.15.1", 28 | "typescript": "^2.1.4", 29 | "typings": "^2.0.0", 30 | "webpack": "^1.13.3", 31 | "webpack-dev-server": "^1.16.2" 32 | }, 33 | "dependencies": { 34 | "lodash": "^4.17.2", 35 | "phaser": "^2.6.2" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /template_src/src/ts/states/preload.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Craig A. Hancock 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | export class Preload extends Phaser.State { 18 | public preload(): void { 19 | 20 | } 21 | 22 | public create(): void { 23 | let style = { 24 | font: "Arial", 25 | fontSize: 24, 26 | fill: "#ffffff", 27 | align: "center" 28 | }; 29 | 30 | let text = this.game.add.text(this.game.world.centerX, this.game.world.centerY, "Lorem Ipsum Dolor Sit Amet", style); 31 | text.anchor.set(0.5); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /template_src/webpack.config.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Craig A. Hancock 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | module.exports = { 18 | entry: "./src/ts/startup.ts", 19 | output: { 20 | path: __dirname + "/www/js", 21 | filename: "bundle.js" 22 | }, 23 | resolve: { 24 | extensions: [ 25 | "", 26 | ".webpack.js", 27 | ".web.js", 28 | ".ts", 29 | ".js" 30 | ] 31 | }, 32 | module: { 33 | loaders: [ 34 | { test: /\.ts/, loader: "ts-loader" } 35 | ] 36 | } 37 | }; 38 | -------------------------------------------------------------------------------- /template_src/src/html/index.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | Your App Name 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 |
38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /template_src/src/ts/config.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Craig A. Hancock 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import * as _ from "lodash"; 18 | 19 | /** 20 | * Provides a singleton configuration class. 21 | */ 22 | export default class Config { 23 | /** 24 | * An instance of of Config class for singleton use. 25 | * @type {Configuration} 26 | */ 27 | private static instance: Config = null; 28 | 29 | /** 30 | * Get the singleton instance of the configuration. 31 | * @returns {Config} Returns the configuration instance 32 | */ 33 | public static getInstance(): Config { 34 | if (Config.instance == null) { 35 | Config.instance = new Config(); 36 | } 37 | 38 | return Config.instance; 39 | } 40 | 41 | /** 42 | * Config storage. 43 | * @type {{}} 44 | */ 45 | protected config: Object = {}; 46 | 47 | /** 48 | * Process an object and add it to the configuration. 49 | * @param config Object to include 50 | */ 51 | public process(config: Object): void { 52 | if (this.config === {}) { 53 | this.config = config; 54 | } else { 55 | for (let k in config) { 56 | if (config.hasOwnProperty(k)) { 57 | this.set(k, config[k]); 58 | } 59 | } 60 | } 61 | } 62 | 63 | /** 64 | * Set a key to a particular value. 65 | * @param key Name of the key 66 | * @param value Value for the key 67 | */ 68 | public set(key: string, value: any): void { 69 | _.set(this.config, key, value); 70 | } 71 | 72 | /** 73 | * Get a particular key or the instance of all configurations. 74 | * @param key Name of the key (optional) 75 | * @param fallback If key doesn't exist, return this value instead (optional) 76 | * @returns {any} Returns the value of a found key if key is set, all settings if no key set, or null on error 77 | */ 78 | public get(key: string = null, fallback: any = null): any { 79 | return _.get(this.config, key, fallback); 80 | } 81 | 82 | /** 83 | * Unset a key by setting it to null. 84 | * @param key Name of the key 85 | */ 86 | public unset(key: string): void { 87 | _.unset(this.config, key); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /template_src/src/ts/main.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Craig A. Hancock 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import Config from "./config"; 18 | import * as States from "./states/states"; 19 | 20 | /** 21 | * A lightweight wrapper for game creation and configuration management. 22 | */ 23 | export class Main { 24 | /** 25 | * Instance of the Game. 26 | */ 27 | protected game: Phaser.Game; 28 | 29 | /** 30 | * Store a pointer to the configuration. 31 | * @type {Configuration} 32 | */ 33 | protected config: Config = Config.getInstance(); 34 | 35 | /** 36 | * Default values to include as part of the configuration. 37 | * @type {{}} 38 | */ 39 | private defaults: Object = {}; 40 | 41 | /** 42 | * Constructor which incorporates configuration options and instantiates the Phaser Game app. 43 | * @param config 44 | */ 45 | constructor(config: {platforms?: {}, platform?: string} = {}) { 46 | // Setup our configuration information 47 | this.config.process(this.defaults); 48 | 49 | // Screen platform-specific configurations into config.platform 50 | if (config.hasOwnProperty("platforms")) { 51 | // Keep track of platform configurations 52 | let platforms = config.platforms; 53 | delete config.platforms; 54 | 55 | // Removed platforms so that what exists are the defaults 56 | this.config.process(config); 57 | 58 | // Find the target platform, default to browser (since that's where the build is tested) 59 | let platformTarget = "browser"; 60 | 61 | if (config.hasOwnProperty("platform")) { 62 | platformTarget = config.platform; 63 | } else if (window.hasOwnProperty("device") && window.device) { 64 | platformTarget = window.device.platform.toLowerCase(); 65 | } 66 | 67 | if (platforms.hasOwnProperty(platformTarget)) { 68 | this.config.process(platforms[platformTarget]); 69 | } 70 | } else { 71 | // No platform-specific configurations 72 | this.config.process(config); 73 | } 74 | 75 | // Create the game object 76 | this.game = new Phaser.Game(this.config.get("viewport.width"), this.config.get("viewport.height"), Phaser.AUTO, "container", this); 77 | } 78 | 79 | /** 80 | * Preload any necessary assets before moving to the Boot state. 81 | */ 82 | public preload(): void {} 83 | 84 | /** 85 | * Used to execute once the preload() method is called. 86 | */ 87 | public create(): void { 88 | // If a statusbar plugin is provided, let's hide it 89 | if (window.hasOwnProperty("StatusBar")) { 90 | window.StatusBar.hide(); 91 | } 92 | 93 | // Set the fullscreen scaling option 94 | this.game.scale.fullScreenScaleMode = Phaser.ScaleManager.SHOW_ALL; 95 | 96 | // Define all of the game states we plan to use 97 | this.game.state.add("Boot", States.Boot); 98 | this.game.state.add("Preload", States.Preload); 99 | 100 | // Change to the Boot state to start the real work 101 | this.game.state.start("Boot"); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /template_src/Gruntfile.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Craig A. Hancock 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | var path = require("path"); 18 | var fs = require("fs"); 19 | 20 | "use strict"; 21 | 22 | module.exports = function (grunt) { 23 | grunt.initConfig({ 24 | clean: { 25 | build: [ 26 | "./www/**/*" 27 | ], 28 | postinstall: [ 29 | "./assets/.gitignore", 30 | "./assets/.npmignore", 31 | "./src/translations/.gitignore", 32 | "./src/translations/.npmignore", 33 | "./www/.gitignore", 34 | "./www/.npmignore" 35 | ] 36 | }, 37 | copy: { 38 | assets: { 39 | files: [ 40 | { 41 | expand: true, 42 | src: ["./assets/**"], 43 | dest: path.join(".", "www") 44 | } 45 | ] 46 | }, 47 | html: { 48 | files: [ 49 | { 50 | expand: true, 51 | cwd: path.join(".", "src", "html"), 52 | src: ["**"], 53 | dest: path.join(".", "www"), 54 | filter: "isFile" 55 | } 56 | ] 57 | }, 58 | libs: { 59 | files: [ 60 | { 61 | expand: true, 62 | src: [ 63 | "./node_modules/jed/jed.js", 64 | "./node_modules/phaser/build/phaser.js" 65 | ], 66 | dest: path.join(".", "www", "js"), 67 | filter: "isFile", 68 | flatten: true 69 | } 70 | ] 71 | } 72 | }, 73 | express: { 74 | default: { 75 | options: { 76 | port: 9000, 77 | hostname: "localhost", 78 | bases: ["www"] 79 | } 80 | } 81 | }, 82 | open: { 83 | default: { 84 | path: "http://<%= express.default.options.hostname %>:<%= express.default.options.port %>" 85 | } 86 | }, 87 | po2json: { 88 | options: { 89 | format: "jed", 90 | stringOnly: true 91 | }, 92 | build: { 93 | src: ["./src/translations/**/*.po"], 94 | dest: path.join(".", "www", "translations") 95 | } 96 | }, 97 | tslint: { 98 | options: { 99 | configuration: "./tslint.json" 100 | }, 101 | files: ["./src/ts/**/*.ts"] 102 | }, 103 | typings: { 104 | install: {} 105 | }, 106 | watch: { 107 | assets: { 108 | files: ["./assets/**"], 109 | tasks: ["copy:assets"], 110 | livereload: true 111 | }, 112 | config: { 113 | files: ["./config.json"], 114 | tasks: ["process-config"], 115 | livereload: true 116 | }, 117 | html: { 118 | files: ["./src/html/**"], 119 | tasks: ["copy:html"], 120 | livereload: true 121 | }, 122 | po2json: { 123 | files: ["./src/translations/**/*.po"], 124 | tasks: ["po2json:build"], 125 | livereload: true 126 | }, 127 | ts: { 128 | files: ["./src/ts/**/*.ts"], 129 | tasks: ["webpack:build"], 130 | livereload: true 131 | } 132 | }, 133 | webpack: { 134 | build: require("./webpack.config.js") 135 | } 136 | }); 137 | 138 | grunt.loadNpmTasks("grunt-contrib-clean"); 139 | grunt.loadNpmTasks("grunt-contrib-copy"); 140 | grunt.loadNpmTasks("grunt-contrib-watch"); 141 | grunt.loadNpmTasks("grunt-express"); 142 | grunt.loadNpmTasks("grunt-open"); 143 | grunt.loadNpmTasks("grunt-po2json"); 144 | grunt.loadNpmTasks("grunt-tslint"); 145 | grunt.loadNpmTasks("grunt-typings"); 146 | grunt.loadNpmTasks("grunt-webpack"); 147 | 148 | grunt.registerTask("default", []); 149 | grunt.registerTask("build", ["clean:build", "copy", "webpack:build", "process-config", "po2json:build"]); 150 | grunt.registerTask('serve', ['express', 'express-keepalive']); 151 | grunt.registerTask('debug', ['express', 'watch']); 152 | grunt.registerTask("lint", ["tslint"]); 153 | 154 | grunt.registerTask("process-config", "Converts the config.json file into a usable JavaScript file for the app.", function () { 155 | var targetPath = path.join(".", "www", "js"); 156 | var json = require("./config.json"); 157 | var target = path.join(targetPath, "config.js"); 158 | 159 | fs.writeFileSync(target, "window.appConfig = " + JSON.stringify(json) + ";"); 160 | }); 161 | }; 162 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cordova Template for Phaser, using Typescript and Jed 2 | A Cordova/PhoneGap template for building a Phaser game using Typescript. Both [Jed](https://slexaxton.github.io/Jed/) and [po2json](https://github.com/mikeedwards/po2json) have been included to assist in any internationalization (i18n) efforts. 3 | 4 | The workflow provided by this template will assume control of the `www` directory. Any content added or changed in this directory manually will be overridden or removed by the provided Grunt tasks. 5 | 6 | Features include: 7 | * [Phaser](http://phaser.io/) 8 | * [Grunt](http://gruntjs.com/) - New to Grunt? Check out [http://gruntjs.com/getting-started](http://gruntjs.com/getting-started) to see how to set it up. 9 | * [Express](https://github.com/blai/grunt-express) - Provides a Grunt-based server used in tandem with `grunt-contrib-watch` to provide live-reloading when debugging. 10 | * [Typescript](https://www.typescriptlang.org/) 11 | * [TSLint](https://palantir.github.io/tslint/) - Verify TypeScript against Phaser's recommended code styles. 12 | * [Typings](https://www.npmjs.com/package/typings) - Provides typing information for TypeScript development. 13 | * [webpack](https://webpack.js.org/) - Combines source code and typings to compile TypeScript into a single JavaScript package. 14 | * [Jed](https://slexaxton.github.io/Jed/) 15 | * [po2json](https://github.com/mikeedwards/po2json) - Convert your translation files into JSON that can be used by Jed. 16 | 17 | ## Quickstart 18 | To use this template with `cordova`, create a new Cordova project with the `--template` parameter. 19 | 20 | ``` 21 | cordova create --template cordova-phaser-ts-jed 22 | ``` 23 | 24 | NOTE: `` should resemble `com.example.`, although the decision is ultimately yours. 25 | 26 | Once the project has been created, run the following: 27 | 28 | ``` 29 | npm install 30 | ``` 31 | 32 | After installation, all packages should be ready to use in the `` indicated. You should update the generic `package.json` and `src/html/index.html` files to with the name and version of the project, as applicable. 33 | 34 | To initially populate the `www` directory, or update the `www` directory with any changes, use the following command: 35 | 36 | ``` 37 | grunt build 38 | ``` 39 | 40 | Top start a server for the project, use the command: 41 | 42 | ``` 43 | grunt serve 44 | ``` 45 | 46 | This will start a server at [http://localhost:9000](http://localhost:9000) on your computer. You can open this page in your default browser by changing the command to `grunt open serve`. 47 | 48 | While being served, you can use `F5` (or `-R`) to reload the page in the browser. Use `-C` on the command line to stop the server. 49 | 50 | Or, if you plan to actively develop your project and need live reload, use the command: 51 | 52 | ``` 53 | grunt debug 54 | ``` 55 | 56 | This will copy any asset or static file changes immediately, as well as recompile any changed TypeScript files. The task will automatically reload the page opened in your browser once the changes propagate into the `www` directory. 57 | 58 | The page served by this task can also be manually reloaded in the browser, or aborted on the command line. 59 | 60 | If you only want to update code changes without a server, you can use the command: 61 | 62 | ``` 63 | grunt watch 64 | ``` 65 | 66 | ## Project Structure 67 | This template organizes content with the following structure: 68 | 69 | - **assets** - Used to store all of your project's assets. All content will be copied into `www/assets` when the project is built. 70 | - **src** - All source files related to your project. 71 | - **html** - All files and directories here are copied into `www` without any processing. 72 | - **index.html** - A default HTML file. 73 | - **translations** - Store all `.po` files in this directory. 74 | - **ts** - All TypeScript files should be placed in this directory. 75 | - **states** - A sample directory of Phaser states. 76 | - **boot.ts** - A sample Phaser state that is called when the app is started. 77 | - **preload.ts** - A sample Phaser state that is called directly after the boot state is completed. 78 | - **states.ts** - A unified include file to load all sample states. 79 | - **config.ts** - A sample settings management class. 80 | - **main.ts** - A sample Phaser bootstrap that loads Phaser on page load and begins the boot state. 81 | - **startup.ts** - A sample entry point for the game. 82 | - **window.ts** - An interface used to expose JavaScript-based libraries to TypeScript. 83 | - **www** - All compiled code and static files are housed here for Cordova/PhoneGap to access. 84 | 85 | Once `grunt build` has been run, the `www` directory will have the following structure. 86 | 87 | - **assets** - Copy of the base `assets` directory. 88 | - **js** - All JavaScript files are copied into this directory. 89 | - **bundle.js** - All TypeScript files are compiled and placed into this singular JavaScript file. 90 | - **config.js** - A processed copy of the `config.json` file in the root. 91 | - **jed.js** - Needed for using Jed. Copied from NPM. 92 | - **phaser.js** - Needed for using Phaser. Copied from NPM. 93 | - **index.html** - The same file found under `src/html`. 94 | 95 | The following configuration files are provided to ease into the workflow provided by this template. 96 | 97 | - **config.json** - Unused at this time. 98 | - **tsconfig.json** - Configuration used when compiling TypeScript code. 99 | - **tslint.json** - Configuration for using TSLint to check for code style mistakes. Defers to Phaser's recommended settings. 100 | - **typings.json** - Used by the Typings library to provide type-hinting `.d.ts` files in the `typings` directory. 101 | - **webpack.config.js** - Configuration used by webpack to package particular source files. 102 | 103 | ## Grunt Tasks 104 | You can always use `grunt -h` to list all available tasks. Below is a list of useful tasks provided by this template. 105 | 106 | - **build** - Clears all content out of `www`, then compiles and copies code and assets into the same directory. 107 | - **serve** - Start a server at [http://localhost:9000](http://localhost:9000). Press `-C` on the command line to stop the task. 108 | - **debug** - Same as `serve`, but provides live reload for the served files. The `watch` task is called to trigger the live reload. Press `-C` on the command line to stop the task. 109 | - **lint** - Run all linters and code validation tasks. 110 | - **open** - Open [http://localhost:9000](http://localhost:9000) in your default browser. 111 | 112 | ## License 113 | Copyright 2017 Craig A. Hancock 114 | 115 | Licensed under the Apache License, Version 2.0 (the "License"); 116 | you may not use this file except in compliance with the License. 117 | You may obtain a copy of the License at 118 | 119 |     http://www.apache.org/licenses/LICENSE-2.0 120 | 121 | Unless required by applicable law or agreed to in writing, software 122 | distributed under the License is distributed on an "AS IS" BASIS, 123 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124 | See the License for the specific language governing permissions and 125 | limitations under the License. 126 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | --------------------------------------------------------------------------------