44function GameboardController ( CardshifterServerAPI , $scope , $timeout , $rootScope , $location ) {
55 var STARTING_CARD_AMT = 5 ; // not very flexible
66
7- $scope . hand = [ ] ;
7+ var playerInfos = {
8+ user : {
9+ index : null ,
10+ id : null ,
11+ name : null ,
12+ properties : { } ,
13+ hand : [ ]
14+ } ,
15+ opponent : {
16+ index : null ,
17+ id : null ,
18+ name : null ,
19+ properties : { } ,
20+ hand : [ ]
21+ }
22+ } ;
23+
824 $scope . actions = [ ] ;
925 $scope . doingAction = false ;
10- $scope . playerInfos = [ ] ;
26+ $scope . playersProperties = [ ] ;
1127
1228 var commandMap = {
1329 "card" : addToHand ,
@@ -25,7 +41,7 @@ function GameboardController(CardshifterServerAPI, $scope, $timeout, $rootScope,
2541
2642 $scope . doAction = function ( action ) {
2743 var getTargets = new CardshifterServerAPI . messageTypes . RequestTargetsMessage ( currentUser . game . id ,
28- currentUser . game . playerInfo . id ,
44+ playerInfos . user . id
2945 action . action ) ;
3046 CardshifterServerAPI . sendMessage ( getTargets ) ;
3147
@@ -48,8 +64,8 @@ function GameboardController(CardshifterServerAPI, $scope, $timeout, $rootScope,
4864 * Work on finding a better way to handle these.
4965 */
5066 function addToHand ( card ) {
51- if ( $scope . hand . length < STARTING_CARD_AMT ) {
52- $scope . hand . push ( card ) ;
67+ if ( playerInfos . user . hand . length < STARTING_CARD_AMT ) {
68+ playerInfos . user . hand . push ( card ) ;
5369 } else {
5470 // what needs to be done here?
5571 // keep analyzing server messages
@@ -76,27 +92,28 @@ function GameboardController(CardshifterServerAPI, $scope, $timeout, $rootScope,
7692
7793 /*
7894 * Stores the information in player into either
79- * currentUser.game.playerInfo if this user is being
80- * described in the message, or currentUser.game.oppInfo
95+ * playerInfos.user if this user is being
96+ * described in the message, or playerInfos.opponent
8197 * if the opponent is being described in the message.
8298 *
8399 * @param player:PlayerMessage -- The player info to store
84100 *
85101 */
86102 function storePlayerInfo ( player ) {
87- var playerType ;
88- if ( player . index === currentUser . game . playerInfo . index ) {
89- playerType = "playerInfo" ;
103+ var playerInfo ;
104+
105+ if ( player . index === currentUser . game . playerIndex ) {
106+ playerInfo = playerInfos . user ;
90107 } else {
91- playerType = "oppInfo" ;
108+ playerInfo = playerInfos . opponent ;
92109 }
93110
94- currentUser . game [ playerType ] . index = player . index ;
95- currentUser . game [ playerType ] . id = player . id ;
96- currentUser . game [ playerType ] . name = player . name ;
97- currentUser . game [ playerType ] . properties = player . properties ;
111+ playerInfo . index = player . index ;
112+ playerInfo . id = player . id ;
113+ playerInfo . name = player . name ;
114+ playerInfo . properties = player . properties ;
98115
99- $scope . playerInfos . push ( currentUser . game [ playerType ] ) ;
116+ $scope . playersProperties . push ( playerInfo ) ; // will this allow for dynamic updating?
100117 }
101118}
102119
0 commit comments