Some init polishing, and beginning of main menu
This commit is contained in:
parent
98733dc94b
commit
dd2d5949ef
|
@ -43,8 +43,6 @@ packages =
|
|||
gulp-connect
|
||||
gulp-gh-pages
|
||||
gulp-karma
|
||||
gulp-less
|
||||
gulp-minify-css
|
||||
gulp-minify-html
|
||||
gulp-open
|
||||
gulp-processhtml
|
||||
|
|
19
gulpfile.js
19
gulpfile.js
|
@ -1,7 +1,5 @@
|
|||
var gulp = require('gulp'),
|
||||
ts = require('gulp-typescript'),
|
||||
less = require('gulp-less'),
|
||||
minifyCSS = require('gulp-minify-css'),
|
||||
concat = require('gulp-concat-sourcemap'),
|
||||
sourcemaps = require('gulp-sourcemaps'),
|
||||
processhtml = require('gulp-processhtml'),
|
||||
|
@ -16,7 +14,6 @@ var gulp = require('gulp'),
|
|||
|
||||
var paths = {
|
||||
assets: 'src/assets/**/*',
|
||||
less: 'src/css/main.less',
|
||||
index: 'src/index.html',
|
||||
libs: [
|
||||
'src/vendor/jasmine/lib/jasmine-core/jasmine.js',
|
||||
|
@ -57,12 +54,6 @@ gulp.task('typescript', function () {
|
|||
.pipe(gulp.dest(paths.build));
|
||||
});
|
||||
|
||||
gulp.task('less', function () {
|
||||
return gulp.src(paths.less)
|
||||
.pipe(less())
|
||||
.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'}))
|
||||
|
@ -117,12 +108,6 @@ gulp.task('minifyJs', ['typescript'], function () {
|
|||
.pipe(gulp.dest(paths.dist));
|
||||
});
|
||||
|
||||
gulp.task('minifyCss', ['less'], function () {
|
||||
return gulp.src(paths.build + 'main.css')
|
||||
.pipe(minifyCSS())
|
||||
.pipe(gulp.dest(paths.dist))
|
||||
});
|
||||
|
||||
gulp.task('deploy', function () {
|
||||
return gulp.src('./dist/**/*')
|
||||
.pipe(deploy({
|
||||
|
@ -131,10 +116,10 @@ gulp.task('deploy', function () {
|
|||
});
|
||||
|
||||
gulp.task('default', function () {
|
||||
runSequence('clean', ['typescript', 'tslint', 'less', 'connect', 'watch'], ['tests', 'open']);
|
||||
runSequence('clean', ['typescript', 'tslint', 'connect', 'watch'], ['tests', 'open']);
|
||||
});
|
||||
gulp.task('build', function () {
|
||||
return runSequence('clean', ['typescript', 'tslint', 'less', 'copy', 'minifyJs', 'minifyCss', 'processhtml']);
|
||||
return runSequence('clean', ['typescript', 'tslint', 'copy', 'minifyJs', 'processhtml']);
|
||||
});
|
||||
gulp.task('strict', function () {
|
||||
return runSequence('clean', ['typescript', 'tslintstrict', 'tests']);
|
||||
|
|
BIN
src/assets/images/menu/button.png
Normal file
BIN
src/assets/images/menu/button.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 167 B |
|
@ -1,15 +0,0 @@
|
|||
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
background: rgba(166, 167, 247, 0.32);
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.game {
|
||||
width: 1280px;
|
||||
height: 720px;
|
||||
margin: 20px auto;
|
||||
}
|
|
@ -4,7 +4,23 @@
|
|||
<meta charset="utf-8"/>
|
||||
<title>SpaceTac</title>
|
||||
|
||||
<link rel="stylesheet" href="main.css">
|
||||
<style>
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
background: #101010;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.game {
|
||||
width: 1280px;
|
||||
height: 720px;
|
||||
margin: 20px auto;
|
||||
}
|
||||
</style>
|
||||
|
||||
<!-- build:remove -->
|
||||
<link rel="stylesheet" href="vendor/jasmine/lib/jasmine-core/jasmine.css">
|
||||
<!-- /build -->
|
||||
|
@ -28,7 +44,7 @@
|
|||
|
||||
<script>
|
||||
var currentWindowOnload = window.onload;
|
||||
window.oncontextmenu = function (e) { e.preventDefault(); }
|
||||
window.oncontextmenu = function (e) { e.preventDefault(); };
|
||||
window.onload = function () {
|
||||
<!-- build:remove -->
|
||||
if (currentWindowOnload) {
|
||||
|
@ -41,7 +57,7 @@
|
|||
if (queryString.getParam('onlytests') || queryString.getParam('spec')) {
|
||||
document.getElementById("-space-tac").hidden = true;
|
||||
} else {
|
||||
new SpaceTac.GameRouter();
|
||||
new SpaceTac.GameUI();
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
|
|
@ -4,31 +4,24 @@ module SpaceTac {
|
|||
"use strict";
|
||||
|
||||
// Router between game views
|
||||
export class GameRouter extends Phaser.Game {
|
||||
export class GameUI extends Phaser.Game {
|
||||
// Currently playing universe
|
||||
universe: Game.Universe;
|
||||
|
||||
constructor() {
|
||||
super(1280, 720, Phaser.AUTO, '-space-tac');
|
||||
|
||||
this.universe = this.newGame();
|
||||
this.universe = null;
|
||||
|
||||
this.state.add('boot', View.Boot);
|
||||
this.state.add('preload', View.Preload);
|
||||
this.state.add('main', View.Main);
|
||||
this.state.add('mainmenu', View.MainMenu);
|
||||
this.state.add('router', View.Router);
|
||||
this.state.add('battle', View.BattleView);
|
||||
|
||||
this.state.start('boot');
|
||||
}
|
||||
|
||||
// Start a new game
|
||||
newGame(): Game.Universe {
|
||||
// Currently create a quick battle
|
||||
var universe = new Game.Universe();
|
||||
universe.startQuickBattle(true);
|
||||
return universe;
|
||||
}
|
||||
|
||||
// Save current game in local browser storage
|
||||
saveGame(): boolean {
|
||||
if (typeof(Storage) !== "undefined") {
|
||||
|
@ -46,7 +39,6 @@ module SpaceTac {
|
|||
var loaded = localStorage.getItem("spacetac-savegame");
|
||||
if (loaded) {
|
||||
this.universe = Game.Universe.loadFromString(loaded);
|
||||
this.state.start('main');
|
||||
console.log("Game loaded");
|
||||
return true;
|
||||
} else {
|
|
@ -2,7 +2,7 @@ module SpaceTac.Game.AI {
|
|||
"use strict";
|
||||
|
||||
// A chain of Maneuver to execute sequentially
|
||||
export class ManeuverChain {
|
||||
export class ManeuverSequence {
|
||||
// Concerned ship
|
||||
ship: Ship;
|
||||
|
||||
|
|
|
@ -3,12 +3,14 @@ module SpaceTac.View {
|
|||
|
||||
export class Boot extends Phaser.State {
|
||||
preload() {
|
||||
this.game.stage.backgroundColor = 0x202020;
|
||||
this.add.text(640, 340, "... Loading ...", {align: "center", font: "bold 20px Arial", fill: "#c0c0c0"})
|
||||
.anchor.set(0.5, 0.5);
|
||||
|
||||
this.load.image("preload-bar", "assets/images/preloader.gif");
|
||||
}
|
||||
|
||||
create() {
|
||||
this.game.stage.backgroundColor = 0xFFFFFF;
|
||||
|
||||
this.input.maxPointers = 1;
|
||||
this.stage.disableVisibilityChange = true;
|
||||
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
module SpaceTac.View {
|
||||
"use strict";
|
||||
|
||||
export class Main extends Phaser.State {
|
||||
create() {
|
||||
var universe = (<GameRouter>this.game).universe;
|
||||
|
||||
if (universe.battle) {
|
||||
// A battle is raging, go to it
|
||||
this.game.state.start("battle", true, false, universe.player, universe.battle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
56
src/scripts/view/MainMenu.ts
Normal file
56
src/scripts/view/MainMenu.ts
Normal file
|
@ -0,0 +1,56 @@
|
|||
module SpaceTac.View {
|
||||
"use strict";
|
||||
|
||||
export class MainMenu extends Phaser.State {
|
||||
button_quick_battle: Phaser.Button;
|
||||
button_load_game: Phaser.Button;
|
||||
|
||||
preload() {
|
||||
this.button_quick_battle = this.addButton(1280 / 2 - 300, 400, "Quick Battle", this.onQuickBattle);
|
||||
this.button_load_game = this.addButton(1280 / 2 + 300, 400, "Load game", this.onLoadGame);
|
||||
}
|
||||
|
||||
addButton(x: number, y: number, caption: string, callback: Function): Phaser.Button {
|
||||
var button = this.add.button(x, y, "menu-button", callback, this);
|
||||
button.anchor.set(0.5, 0.5);
|
||||
button.input.useHandCursor = true;
|
||||
|
||||
var text = new Phaser.Text(this.game, 0, 0, caption,
|
||||
{align: "center", font: "bold 20px Arial", fill: "#303030"});
|
||||
text.anchor.set(0.5, 0.5);
|
||||
button.addChild(text);
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
// Called when "Quick Battle" is clicked
|
||||
onQuickBattle(): void {
|
||||
var gameui = <GameUI>this.game;
|
||||
|
||||
gameui.universe = new Game.Universe();
|
||||
gameui.universe.startQuickBattle(true);
|
||||
|
||||
this.game.state.start("router");
|
||||
}
|
||||
|
||||
// Called when "Load game" is clicked
|
||||
onLoadGame(): void {
|
||||
var gameui = <GameUI>this.game;
|
||||
|
||||
if (gameui.loadGame()) {
|
||||
this.game.state.start("router");
|
||||
} else {
|
||||
var error = this.game.add.text(this.button_load_game.x, this.button_load_game.y + 40,
|
||||
"No saved game found",
|
||||
{font: "bold 16px Arial", fill: "#e04040"});
|
||||
error.anchor.set(0.5, 0.5);
|
||||
var tween = this.game.tweens.create(error);
|
||||
tween.to({y: error.y + 100, alpha: 0}, 1000, Phaser.Easing.Exponential.In);
|
||||
tween.onComplete.addOnce(() => {
|
||||
error.destroy();
|
||||
});
|
||||
tween.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,11 +6,14 @@ module SpaceTac.View {
|
|||
|
||||
preload() {
|
||||
// Add preload sprite
|
||||
this.add.text(640, 340, "... Loading ...", {align: "center", font: "bold 20px Arial", fill: "#c0c0c0"})
|
||||
.anchor.set(0.5, 0.5);
|
||||
this.preloadBar = this.add.sprite(0, 0, "preload-bar");
|
||||
this.preloadBar.position.set((1280 - this.preloadBar.width) / 2, (720 - this.preloadBar.height) / 2);
|
||||
this.load.setPreloadSprite(this.preloadBar);
|
||||
|
||||
// Load images
|
||||
this.loadImage("menu/button.png");
|
||||
this.loadImage("battle/waiting.png");
|
||||
this.loadImage("battle/shiplist-base.png");
|
||||
this.loadImage("battle/shiplist-normal.png");
|
||||
|
@ -57,7 +60,7 @@ module SpaceTac.View {
|
|||
}
|
||||
|
||||
create() {
|
||||
this.game.state.start("main");
|
||||
this.game.state.start("mainmenu");
|
||||
}
|
||||
|
||||
private loadImage(path: string) {
|
||||
|
|
18
src/scripts/view/Router.ts
Normal file
18
src/scripts/view/Router.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
module SpaceTac.View {
|
||||
"use strict";
|
||||
|
||||
// Router to other states
|
||||
export class Router extends Phaser.State {
|
||||
create() {
|
||||
var universe = (<GameUI>this.game).universe;
|
||||
|
||||
if (!universe) {
|
||||
// No universe, go back to main menu
|
||||
this.game.state.start("mainmenu");
|
||||
} else if (universe.battle) {
|
||||
// A battle is raging, go to it
|
||||
this.game.state.start("battle", true, false, universe.player, universe.battle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
module SpaceTac.View {
|
||||
"use strict";
|
||||
|
||||
// Phaser Group to hold UI related objects
|
||||
export class UIGroup extends Phaser.Group {
|
||||
|
||||
}
|
||||
}
|
|
@ -11,7 +11,7 @@ module SpaceTac.View {
|
|||
player: Game.Player;
|
||||
|
||||
// UI container
|
||||
ui: UIGroup;
|
||||
ui: Phaser.Group;
|
||||
|
||||
// Battleground container
|
||||
arena: Arena;
|
||||
|
@ -76,7 +76,7 @@ module SpaceTac.View {
|
|||
game.add.existing(this.arena);
|
||||
|
||||
// Add UI layer
|
||||
this.ui = new UIGroup(game);
|
||||
this.ui = new Phaser.Group(game);
|
||||
game.add.existing(this.ui);
|
||||
|
||||
// Add UI elements
|
||||
|
@ -106,11 +106,11 @@ module SpaceTac.View {
|
|||
key_space.onUp.add(this.onSpaceKeyPressed, this);
|
||||
var key_s = this.input.keyboard.addKey(Phaser.Keyboard.S);
|
||||
key_s.onUp.add(() => {
|
||||
(<GameRouter>this.game).saveGame();
|
||||
(<GameUI>this.game).saveGame();
|
||||
});
|
||||
var key_l = this.input.keyboard.addKey(Phaser.Keyboard.L);
|
||||
key_l.onUp.add(() => {
|
||||
(<GameRouter>this.game).loadGame();
|
||||
(<GameUI>this.game).loadGame();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue