Permalink
Browse files

think I figured out the plan for typescript

  • Loading branch information...
seanhess committed Nov 9, 2012
1 parent 9b6ca78 commit f8d0e9098239b04a8e22f95a4a08e5938a3236b4
View
@@ -12,6 +12,15 @@ Install
* node_modules/.bin/coffee app.coffee
+Compiling
+---------
+
+This should compile EVERYTHING, since app includes the controllers, and the controllers import the services
+
+ tsc --module amd public/app.ts
+
+You still need to add everything to public/main.js to get it to load
+
Todo
----
View
@@ -14,3 +14,8 @@ var app = angular.module('uarbg2', [], function ($routeProvider: ng.IRouteProvid
export var main = app
// I want to EXPORT this thing.
+
+// RequireJS = MUST HAVE (but could ignore it, if you go the ANGULAR way)
+// ok, so ignore it
+// you'll be fine
+
@@ -1,7 +1,7 @@
///<reference path="../def/jquery.d.ts"/>
///<reference path="../def/angular.d.ts"/>
-import Players = module("../services/Players")
+import ps = module("../services/Players")
export interface Scope extends ng.IScope {
@@ -11,7 +11,7 @@ export interface Scope extends ng.IScope {
version:any;
player:any;
gameId:string;
- players:Players.Players;
+ players:ps.IPlayers;
avatars:string [];
freeAvatars:string [];
@@ -25,7 +25,7 @@ export interface Scope extends ng.IScope {
}
export class Controller {
- constructor ($scope: Scope, $location: any, Players: Function, CurrentPlayer: any, AppVersion: any) {
+ constructor ($scope: Scope, $location: any, Players: ps.IPlayerFactory, CurrentPlayer: any, AppVersion: any) {
// HACKY way to do the transition
$scope.intro = "intro"
@@ -43,7 +43,7 @@ export class Controller {
$scope.gameId = $scope.player.gameId || "global"
// [ ] detect which game to join ("global")
- var players:Players.Players = Players($scope.gameId)
+ var players = Players($scope.gameId)
$scope.players = players
// available avatars
@@ -1,6 +1,10 @@
-define(function(require) {
- var app = require('app')
- app.main.factory('AppVersion', function($rootScope) {
- return "1.1"
- })
-})
+define(["require", "exports", "../app"], function(require, exports, __app__) {
+ var app = __app__;
+
+ app.main.factory('AppVersion', function ($rootScope) {
+ return {
+ num: "1.1"
+ };
+ });
+})
+
@@ -0,0 +1,9 @@
+import app = module("../app")
+
+export interface IAppVersion {
+ num: string;
+}
+
+app.main.factory('AppVersion', function($rootScope) {
+ return {num: "1.1"}
+})
View
@@ -1,37 +1,45 @@
define(["require", "exports", "../app"], function(require, exports, __app__) {
var app = __app__;
- var Players = (function () {
- function Players() {
- this.all = [];
- }
- return Players;
- })();
- exports.Players = Players;
+
+ var TAUNT_LIST = [
+ "Oooh yeah!",
+ "I fart in your general direction.",
+ "Your mother was a hamster and your father smelt of elderberries.",
+ "All your base are belong to us!",
+ "OK, next round, try it WITH your glasses on.",
+ "If your daddy's aim is as bad as yours, I'm surprised you're here at all!"
+ ];
+ var STATE = {
+ DEAD: "dead",
+ ALIVE: "alive"
+ };
app.main.factory('Players', function ($rootScope, FB, Board, AppVersion) {
return function (gameId) {
- var taunt_list = [
- "Oooh yeah!",
- "I fart in your general direction.",
- "Your mother was a hamster and your father smelt of elderberries.",
- "All your base are belong to us!",
- "OK, next round, try it WITH your glasses on.",
- "If your daddy's aim is as bad as yours, I'm surprised you're here at all!"
- ];
- var STATE_ALIVE = "alive";
- var STATE_DEAD = "dead";
var gameRef = new FB(gameId);
var playersRef = gameRef.child('players');
- var all = [];
- var myname = null;
- var isPaidVal = isPaid();
+ var myname;
+ var players = {
+ current: null,
+ winner: null,
+ taunt: null,
+ isPaid: isPaid(),
+ all: [],
+ alivePlayers: alivePlayers,
+ join: join,
+ listen: listen,
+ move: move,
+ killPlayer: killPlayer,
+ playerByName: playerByName,
+ latestVersion: latestVersion
+ };
function join(player) {
myname = player.name;
player.x = Board.randomX();
player.y = Board.randomY();
player.sprite = '1';
player.facing = "down";
- player.state = STATE_ALIVE;
+ player.state = STATE.ALIVE;
player.wins = player.wins || 0;
player.losses = player.losses || 0;
player.message = null;
@@ -44,13 +52,12 @@ define(["require", "exports", "../app"], function(require, exports, __app__) {
playersRef.on('child_added', FB.apply(onJoin));
playersRef.on('child_changed', FB.apply(onUpdate));
playersRef.on('child_removed', FB.apply(onQuit));
- gameRef.child('winner').on('value', FB.apply(onWinner));
}
function onJoin(player) {
if(!players.current && player.name == myname) {
players.current = player;
}
- all.push(player);
+ players.all.push(player);
}
function onUpdate(remotePlayer) {
var player = playerByName(remotePlayer.name);
@@ -63,17 +70,16 @@ define(["require", "exports", "../app"], function(require, exports, __app__) {
player.state = remotePlayer.state;
player.wins = remotePlayer.wins;
player.losses = remotePlayer.losses;
- player.walking = remotePlayer.walking;
if(remotePlayer.killer) {
player.killer = remotePlayer.killer;
}
- if(player.state == STATE_DEAD) {
+ if(player.state == STATE.DEAD) {
$rootScope.$broadcast("kill", player);
checkWin();
}
}
function onQuit(player) {
- all = all.filter(function (p) {
+ players.all = players.all.filter(function (p) {
return p.name != player.name;
});
}
@@ -101,25 +107,25 @@ define(["require", "exports", "../app"], function(require, exports, __app__) {
return;
}
players.winner = player;
- players.taunt = taunt_list[Math.floor(Math.random() * taunt_list.length)];
+ players.taunt = TAUNT_LIST[Math.floor(Math.random() * TAUNT_LIST.length)];
if(players.current && players.current.name == player.name) {
setTimeout(resetGame, 3000);
}
}
function resetGame() {
console.log("Initialize Game");
gameRef.child('winner').remove();
- all.forEach(function (player) {
+ players.all.forEach(function (player) {
player.x = Board.randomX();
player.y = Board.randomY();
player.sprite = '1';
player.facing = "down";
- player.state = STATE_ALIVE;
+ player.state = STATE.ALIVE;
FB.update(playersRef.child(player.name), player);
});
}
function killPlayer(player, killerName) {
- player.state = STATE_DEAD;
+ player.state = STATE.DEAD;
player.losses += 1;
player.killer = killerName;
console.log("KILL PLAYER", player);
@@ -133,36 +139,24 @@ define(["require", "exports", "../app"], function(require, exports, __app__) {
return playersRef.child(name);
}
function playerByName(name) {
- return all.filter(function (p) {
+ return players.all.filter(function (p) {
return (p.name == name);
})[0];
}
function isAlive(p) {
- return (p.state == STATE_ALIVE);
+ return (p.state == STATE.ALIVE);
}
function alivePlayers() {
- return all.filter(isAlive);
+ return players.all.filter(isAlive);
}
function isPaid() {
return (localStorage.getItem("payment_status") == "paid");
}
- console.log("isPaid()= ", isPaid());
- console.log("isPaidVal= ", isPaidVal);
function latestVersion() {
- return _.max(all, function (player) {
+ return _.max(players.all, function (player) {
return player.version;
});
}
- var players = new Players();
- players.isPaid = isPaidVal;
- players.all = all;
- players.alivePlayers = alivePlayers;
- players.join = join;
- players.listen = listen;
- players.move = move;
- players.killPlayer = killPlayer;
- players.playerByName = playerByName;
- players.latestVersion = latestVersion;
return players;
}
});
Oops, something went wrong.

0 comments on commit f8d0e90

Please sign in to comment.