diff --git a/.bowerrc b/.bowerrc new file mode 100644 index 0000000..1f15d09 --- /dev/null +++ b/.bowerrc @@ -0,0 +1,3 @@ +{ + "directory": "src/vendor/" +} diff --git a/.gitignore b/.gitignore index 1cc7fdb..f4eee7e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,7 @@ .* -/bin -/bootstrap.py -/build -/parts -/venv -/dist -/eggs /coverage -/core /node_modules /src/vendor +/src/build.* /graphics/**/*.blend?* - +*.log diff --git a/bootstrap-venv.py b/bootstrap-venv.py deleted file mode 100644 index e00e2fa..0000000 --- a/bootstrap-venv.py +++ /dev/null @@ -1,165 +0,0 @@ -#!/usr/bin/env python -# Copyright (c) 2014, Jonathan Ballet -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# 1. Redistributions of source code must retain the above copyright notice, this -# list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR -# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -""" -Bootstrap a Buildout into its own virtualenv environment. - -This script creates a new empty virtualenv, download Buildout's bootstrap script -and execute it in the context of the previously created virtualenv. - - python bootstrap-venv.py - -Then, you only have to edit your `buildout.cfg` file and run:: - - ./bin/buildout - -You can also specify another directory to bootstrap the whole thing in:: - - python bootstrap-venv.py some-directory - cd some-directory - [ edit buildout.cfg ] - ./bin/buildout - -""" - - -# This URL is supposed to be stable -BOOTSTRAP_BUILDOUT_URL = "https://bootstrap.pypa.io/bootstrap-buildout.py" - -# TODO: find a place where Virtualenv is FOR EVER AND EVER available. -VIRTUALENV_URL = "https://pypi.python.org/packages/source/v/virtualenv/" + \ - "virtualenv-1.11.6.tar.gz" - - -import io -import gzip -import os -import subprocess -import sys -import tarfile -try: - from urllib.request import urlopen -except ImportError: - from urllib2 import urlopen - - -def download_virtualenv(destination): - print("Downloading virtualenv from %s" % VIRTUALENV_URL) - url = urlopen(VIRTUALENV_URL) - - string_fp = io.BytesIO(url.read()) - gz_fp = gzip.GzipFile(fileobj=string_fp) - tar_fp = tarfile.TarFile(fileobj=gz_fp) - tar_fp.extractall(destination) - - path = os.path.join(destination, os.listdir(destination)[0]) - sys.path.insert(0, path) - import virtualenv - print("Using virtualenv module at %s" % virtualenv.__file__) - return virtualenv - - -def create_virtualenv(destination): - venv_dir = os.path.join(destination, "parts", "venv") - - try: - import virtualenv - except ImportError: - venv_dist = os.path.join(destination, "parts", "venv-dist") - virtualenv = download_virtualenv(venv_dist) - - - print("Creating virtual environment in %s..." % venv_dir) - virtualenv.create_environment(venv_dir, - site_packages=False, - clear=True, - unzip_setuptools=False) - print("Virtual environment created in %s." % venv_dir) - return venv_dir - - -def download_bootstrap(destination): - bootstrap_path = os.path.join(destination, "bootstrap.py") - print("Downloading Buildout bootstrap from %s..." % BOOTSTRAP_BUILDOUT_URL) - url = urlopen(BOOTSTRAP_BUILDOUT_URL) - - with open(bootstrap_path, "wb") as fp: - fp.write(url.read()) - - print("Downloaded Buildout bootstrap into %s." % bootstrap_path) - return bootstrap_path - - -def make_default_buildout_cfg(buildout_cfg): - content = [ - "[buildout]", - "parts = default", - "", - "[default]", - "recipe = zc.recipe.egg", - "eggs = zc.recipe.egg", - "interpreter = python", - ] - with open(buildout_cfg, "w") as fp: - fp.writelines(l + "\n" for l in content) - - -def bootstrap_buildout(venv_dir, bootstrap_path): - python_bin = os.path.join(venv_dir, "bin", "python") - assert os.path.exists(python_bin) - - buildout_cfg = os.path.join(os.path.dirname(bootstrap_path), "buildout.cfg") - try: - fp = open(buildout_cfg) - except IOError as err: - if err.errno != 2: - raise - print("Creating a default buildout.cfg file in %s" % buildout_cfg) - make_default_buildout_cfg(buildout_cfg) - else: - fp.close() - - print("Bootstrapping Buildout using: %s %s..." % ( - python_bin, bootstrap_path)) - subprocess.check_call([python_bin, bootstrap_path]) - - print("Invoking bootstrapped buildout...") - buildout_bin = os.path.join(os.path.dirname(bootstrap_path), "bin", "buildout") - subprocess.check_call([buildout_bin]) - - -if len(sys.argv) == 2: - real_destination = sys.argv[1] -else: - real_destination = os.getcwd() - - -print("About to create Buildout environment in %s..." % real_destination) - -os.chdir(real_destination) -destination = "." -venv_dir = create_virtualenv(destination) -bootstrap_path = download_bootstrap(destination) -bootstrap_buildout(venv_dir, bootstrap_path) - diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..7a321fd --- /dev/null +++ b/bower.json @@ -0,0 +1,16 @@ +{ + "name": "spacetac", + "description": "A tactical RPG set in space", + "main": "out/build.js", + "authors": [ + "Michael Lemaire" + ], + "license": "MIT", + "homepage": "", + "private": true, + "dependencies": { + "phaser": "2.3.0", + "jasmine-core": "jasmine#^2.5.2", + "deep-diff": "0.3.0" + } +} diff --git a/buildout.cfg b/buildout.cfg deleted file mode 100644 index b1bfa72..0000000 --- a/buildout.cfg +++ /dev/null @@ -1,78 +0,0 @@ -[buildout] -update-versions-file = versions.cfg -extends = - versions.cfg -parts = - watch - js-tools - js-libraries - init-compile - -[init-compile] -recipe = collective.recipe.cmd -on_install = true -on_update = true -cmds = ${buildout:bin-directory}/${compile:name} - -[compile] -recipe = yt.recipe.shell -name = compile -script = ${js-tools:bin-gulp} build - -[watch] -recipe = yt.recipe.shell -name = watch -script = ${js-tools:bin-gulp} - -[nodejs] -recipe = gp.recipe.node -executable_node = ${buildout:bin-directory}/node -executable_npm = ${buildout:bin-directory}/npm - -[js-tools] -recipe = rodacom.buildout.npm -node_path = ${nodejs:executable_node} -npm_path = ${nodejs:executable_npm} -strip_extension = true -packages = - bower - del - gulp - gulp-concat - gulp-concat-sourcemap - gulp-connect - gulp-gh-pages - gulp-karma - gulp-minify-html - gulp-open - gulp-processhtml - gulp-sourcemaps - gulp-tslint - gulp-typescript - gulp-uglifyjs - gulp-util - gulp-watch - run-sequence - karma - karma-coverage - karma-jasmine - karma-phantomjs-launcher - karma-firefox-launcher -bin-bower = ${buildout:bin-directory}/bower -bin-gulp = ${buildout:bin-directory}/gulp - -[js-libraries] -recipe = bowerrecipe -executable = ${js-tools:bin-bower} -base-directory = ${buildout:directory}/src/vendor -downloads = . -packages = - phaser#2.3.0 - jasmine#2.1.3 - deep-diff#0.3.0 - -[mkdir-var] -recipe = z3c.recipe.mkdir -paths = - var - var/cache diff --git a/git_hooks/pre-commit b/git_hooks/pre-commit deleted file mode 100755 index b43b99c..0000000 --- a/git_hooks/pre-commit +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -set -e - -git_root=$(git rev-parse --show-toplevel) -PATH=${PATH}:${git_root}/bin ${git_root}/bin/gulp strict - diff --git a/gulpfile.js b/gulpfile.js deleted file mode 100644 index c32973c..0000000 --- a/gulpfile.js +++ /dev/null @@ -1,126 +0,0 @@ -var gulp = require('gulp'), - ts = require('gulp-typescript'), - concat = require('gulp-concat-sourcemap'), - sourcemaps = require('gulp-sourcemaps'), - processhtml = require('gulp-processhtml'), - connect = require('gulp-connect'), - karma = require('gulp-karma'), - tslint = require('gulp-tslint'), - open = require('gulp-open'), - del = require('del'), - uglify = require('gulp-uglifyjs'), - deploy = require('gulp-gh-pages'), - runSequence = require('run-sequence'); - -var paths = { - assets: 'src/assets/**/*', - index: 'src/index.html', - libs: [ - 'src/vendor/jasmine/lib/jasmine-core/jasmine.js', - 'src/vendor/jasmine/lib/jasmine-core/jasmine-html.js', - 'src/vendor/jasmine/lib/jasmine-core/boot.js', - 'src/vendor/phaser/build/phaser.min.js' - ], - ts: 'src/app/**/*.ts', - build: './build/', - dist: './dist/' -}; - -gulp.task('clean', function (cb) { - return del([paths.build, paths.dist], cb); -}); - -gulp.task('copy', function () { - return gulp.src(paths.assets) - .pipe(gulp.dest(paths.dist + 'assets')); -}); - -var tsProject = ts.createProject({ - declarationFiles: true, - noExternalResolve: true, - noImplicitAny: false, // Handled by tslint - sortOutput: true, - sourceRoot: '../app' -}); - -gulp.task('typescript', function () { - var tsResult = gulp.src(paths.ts) - .pipe(sourcemaps.init()) - .pipe(ts(tsProject)); - - return tsResult.js - .pipe(concat('main.js')) - .pipe(sourcemaps.write()) - .pipe(gulp.dest(paths.build)); -}); - -gulp.task('tests', ['typescript'], function () { - return gulp.src(paths.libs + [paths.build + 'main.js']) - .pipe(karma({configFile: 'karma.conf.js', action: 'run'})) -}); - -gulp.task('tslint', function () { - return gulp.src(['src/app/game/**/*.ts', 'src/app/view/**/*.ts']) - .pipe(tslint()) - .pipe(tslint.report('verbose', { - emitError: false - })); -}); -gulp.task('tslintstrict', function () { - return gulp.src(['src/app/game/**/*.ts', 'src/app/view/**/*.ts']) - .pipe(tslint()) - .pipe(tslint.report('verbose')); -}); - -gulp.task('processhtml', function () { - return gulp.src(paths.index) - .pipe(processhtml()) - .pipe(gulp.dest(paths.dist)); -}); - -gulp.task('reload', ['typescript'], function () { - gulp.src('src/*.html') - .pipe(connect.reload()); -}); - -gulp.task('watch', function () { - gulp.watch(paths.ts, ['typescript', 'tslint', 'tests', 'reload']); - gulp.watch(paths.less, ['less', 'reload']); - gulp.watch(paths.index, ['reload']); -}); - -gulp.task('connect', function () { - connect.server({ - root: [__dirname + '/src', paths.build], - port: 9000, - livereload: true - }); -}); - -gulp.task("open", function () { - gulp.src(paths.index) - .pipe(open("", {url: "http://localhost:9000"})); -}); - -gulp.task('minifyJs', ['typescript'], function () { - return gulp.src(paths.libs.concat(paths.build + 'main.js')) - .pipe(uglify('all.min.js', {outSourceMap: false})) - .pipe(gulp.dest(paths.dist)); -}); - -gulp.task('deploy', function () { - return gulp.src('./dist/**/*') - .pipe(deploy({ - remoteUrl: "git@github.com:thunderk/spacetac.git" - })); -}); - -gulp.task('default', function () { - runSequence('clean', ['typescript', 'tslint', 'connect', 'watch'], ['tests', 'open']); -}); -gulp.task('build', function () { - return runSequence('clean', ['typescript', 'tslint', 'copy', 'minifyJs', 'processhtml']); -}); -gulp.task('strict', function () { - return runSequence('clean', ['typescript', 'tslintstrict', 'tests']); -}); diff --git a/karma.conf.js b/karma.conf.js deleted file mode 100644 index 493688e..0000000 --- a/karma.conf.js +++ /dev/null @@ -1,20 +0,0 @@ -// Configuration for running unit testing using karma -module.exports = function (config) { - config.set({ - basePath: '', - frameworks: ['jasmine'], - files: [ - 'src/vendor/phaser/build/phaser.js', - 'src/vendor/deep-diff/releases/deep-diff-0.3.0.min.js', - 'build/main.js' - ], - client: { - captureConsole: false - }, - logLevel: config.LOG_WARN, - browsers: ['PhantomJS'], - singleRun: true, - reporters: ['progress', 'coverage'], - preprocessors: {'build/main.js': ['coverage']} - }); -}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..ee0f296 --- /dev/null +++ b/package.json @@ -0,0 +1,23 @@ +{ + "name": "spacetac", + "version": "0.1.0", + "description": "A tactical RPG set in space", + "main": "src/build.js", + "scripts": { + "build": "tsc -p .", + "test": "echo \"Error: no test specified\" && exit 1", + "serve": "simple-server out 8012" + }, + "repository": { + "type": "git", + "url": "https://code.thunderk.net/michael/spacetac.git" + }, + "author": "Michael Lemaire", + "license": "MIT", + "devDependencies": { + "bower": "^1.7.9", + "jasmine": "^2.5.2", + "simple-server": "^1.0.1", + "typescript": "^2.0.6" + } +} diff --git a/src/app/GameUI.ts b/src/app/GameUI.ts index 970591b..243d478 100644 --- a/src/app/GameUI.ts +++ b/src/app/GameUI.ts @@ -41,6 +41,7 @@ module SpaceTac { return true; } else { (this.state.getCurrentState()).messages.addMessage("Your browser does not support saving"); + return false; } } @@ -58,6 +59,7 @@ module SpaceTac { } } else { console.error("localStorage not available"); + return false; } } diff --git a/src/app/game/Attribute.ts b/src/app/game/Attribute.ts index 5410a6d..53188a3 100644 --- a/src/app/game/Attribute.ts +++ b/src/app/game/Attribute.ts @@ -70,9 +70,7 @@ module SpaceTac.Game { // Iterator over each code static forEachCode(callback: (code: AttributeCode) => void) { for (var val in AttributeCode) { - if (!isNaN(val)) { - callback(parseInt(val, 10)); - } + callback(parseInt(val, 10)); } } diff --git a/src/app/game/BattleLog.ts b/src/app/game/BattleLog.ts index ccd385e..a978f90 100644 --- a/src/app/game/BattleLog.ts +++ b/src/app/game/BattleLog.ts @@ -41,7 +41,6 @@ module SpaceTac.Game { this.filters.forEach((code: string) => { if (event.code === code) { filtered = true; - return false; } }); if (filtered) { diff --git a/src/app/view/battle/ActionBar.ts b/src/app/view/battle/ActionBar.ts index d09e4c5..27c8277 100644 --- a/src/app/view/battle/ActionBar.ts +++ b/src/app/view/battle/ActionBar.ts @@ -24,11 +24,12 @@ module SpaceTac.View { // Create an empty action bar constructor(battleview: BattleView) { + super(battleview.game); + this.battleview = battleview; this.actions = []; this.ship = null; - super(battleview.game); this.x = 230; this.y = 0; battleview.ui.add(this); diff --git a/src/app/view/battle/ActionIcon.ts b/src/app/view/battle/ActionIcon.ts index 9a3d90c..42691f8 100644 --- a/src/app/view/battle/ActionIcon.ts +++ b/src/app/view/battle/ActionIcon.ts @@ -35,12 +35,13 @@ module SpaceTac.View { // Create an icon for a single ship action constructor(bar: ActionBar, x: number, y: number, ship: Game.Ship, action: Game.BaseAction) { + super(bar.game, x, y, "battle-action-inactive"); + this.bar = bar; this.battleview = bar.battleview; this.ship = ship; this.action = action; - super(bar.game, x, y, "battle-action-inactive"); bar.addChild(this); // Active layer diff --git a/src/app/view/battle/Arena.ts b/src/app/view/battle/Arena.ts index 673f1ab..4266e61 100644 --- a/src/app/view/battle/Arena.ts +++ b/src/app/view/battle/Arena.ts @@ -26,14 +26,14 @@ module SpaceTac.View { // Create a graphical arena for ship sprites to fight in a 2D space constructor(battleview: BattleView) { + super(battleview.game); + this.battleview = battleview; this.ship_sprites = []; this.playing = null; this.hovered = null; this.range_hint = null; - super(battleview.game); - var offset_x = 206; var offset_y = 84; diff --git a/src/app/view/battle/ArenaShip.ts b/src/app/view/battle/ArenaShip.ts index 31422c4..ac5774b 100644 --- a/src/app/view/battle/ArenaShip.ts +++ b/src/app/view/battle/ArenaShip.ts @@ -17,10 +17,10 @@ module SpaceTac.View { // Create a ship sprite usable in the Arena constructor(battleview: BattleView, ship: Game.Ship) { - this.ship = ship; - super(battleview.game); + this.ship = ship; + // Add ship sprite this.sprite = new Phaser.Button(battleview.game, 0, 0, "ship-" + ship.model + "-sprite"); this.sprite.rotation = ship.arena_angle; diff --git a/src/app/view/battle/ShipList.ts b/src/app/view/battle/ShipList.ts index 7806b26..30871ca 100644 --- a/src/app/view/battle/ShipList.ts +++ b/src/app/view/battle/ShipList.ts @@ -17,12 +17,13 @@ module SpaceTac.View { // Create an empty action bar constructor(battleview: BattleView) { + super(battleview.game, battleview.ui); + this.battleview = battleview; this.ships = []; this.playing = null; this.hovered = null; - super(battleview.game, battleview.ui); battleview.ui.add(this); this.addBackground(); diff --git a/src/app/view/battle/ShipListItem.ts b/src/app/view/battle/ShipListItem.ts index 6c877c6..08dc659 100644 --- a/src/app/view/battle/ShipListItem.ts +++ b/src/app/view/battle/ShipListItem.ts @@ -26,10 +26,10 @@ module SpaceTac.View { // Create a ship button for the battle ship list constructor(list: ShipList, x: number, y: number, ship: Game.Ship, owned: boolean) { - this.ship = ship; - super(list.battleview.game, x, y, owned ? "battle-shiplist-own" : "battle-shiplist-enemy"); + this.ship = ship; + this.input.useHandCursor = true; this.onInputOver.add(() => { list.battleview.cursorOnShip(ship); diff --git a/src/index.html b/src/index.html index f714b04..3299db4 100644 --- a/src/index.html +++ b/src/index.html @@ -35,11 +35,11 @@ - - - + + + - + - \ No newline at end of file + diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..8ad86c3 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "system", + "forceConsistentCasingInFileNames": true, + "noFallthroughCasesInSwitch": true, + "noImplicitAny": false, + "noImplicitThis": true, + "noImplicitReturns": true, + "removeComments": true, + "preserveConstEnums": true, + "out": "src/build.js", + "strictNullChecks": false, + "sourceMap": true, + "target": "es5" + }, + "exclude": [ + "out", + "src/vendor", + "coverage", + "node_modules" + ] +} + diff --git a/tslint.json b/tslint.json deleted file mode 100644 index 547680a..0000000 --- a/tslint.json +++ /dev/null @@ -1,87 +0,0 @@ -{ - "rules": { - "ban": [true, - ["_", "extend"], - ["_", "isNull"], - ["_", "isDefined"] - ], - "class-name": true, - "comment-format": [true, - "check-space", - "!check-lowercase" - ], - "curly": true, - "eofline": true, - "forin": true, - "indent": [true, 4], - "interface-name": true, - "jsdoc-format": true, - "label-position": true, - "label-undefined": true, - "max-line-length": [true, 140], - "member-ordering": [true, - "public-before-private", - "static-before-instance", - "variables-before-functions" - ], - "no-arg": true, - "no-bitwise": true, - "no-console": [true, - "debug", - "info", - "time", - "timeEnd", - "trace" - ], - "no-construct": true, - "no-constructor-vars": true, - "no-debugger": true, - "no-duplicate-key": true, - "no-duplicate-variable": true, - "no-empty": true, - "no-eval": true, - "no-string-literal": true, - "no-switch-case-fall-through": true, - "no-trailing-comma": true, - "no-trailing-whitespace": true, - "no-unused-expression": false, - "no-unused-variable": true, - "no-unreachable": true, - "no-use-before-declare": true, - "no-var-requires": true, - "one-line": [true, - "check-open-brace", - "check-catch", - "check-else", - "check-whitespace" - ], - "quotemark": [true, "double"], - "radix": true, - "semicolon": true, - "triple-equals": [true, "allow-null-check"], - "typedef": [true, - "callSignature", - "indexSignature", - "parameter", - "propertySignature", - "variableDeclarator" - ], - "typedef-whitespace": [true, - ["callSignature", "noSpace"], - ["catchClause", "noSpace"], - ["indexSignature", "space"] - ], - "use-strict": [true, - "check-module", - "check-function" - ], - "variable-name": false, - "whitespace": [true, - "check-branch", - "check-decl", - "check-operator", - "check-separator", - "check-type" - ] - } -} diff --git a/versions.cfg b/versions.cfg deleted file mode 100644 index 142404d..0000000 --- a/versions.cfg +++ /dev/null @@ -1,28 +0,0 @@ -[versions] - -# Added by buildout at 2014-12-28 20:27:17.084358 -bowerrecipe = 0.1.1 -collective.recipe.cmd = 0.9 -gp.recipe.node = 0.10.28.0 -rodacom.buildout.npm = 0.6 -yt.recipe.shell = 0.1.7 -zc.buildout = 2.3.1 -zc.recipe.egg = 2.0.1 - -# Required by: -# gp.recipe.node==0.10.28.0 -hexagonit.recipe.cmmi = 2.0 - -# Required by: -# hexagonit.recipe.cmmi==2.0 -hexagonit.recipe.download = 1.7 - -# Required by: -# gp.recipe.node==0.10.28.0 -python-archive = 0.2 - -# Required by: -# gp.recipe.node==0.10.28.0 -# hexagonit.recipe.cmmi==2.0 -# zc.recipe.egg==2.0.1 -setuptools = 8.3