13
13
angular . module ( 'starter.controllers' , [ ] )
14
14
15
15
. controller ( 'MapCtrl' , [ '$scope' , '$ionicPlatform' , 'Settings' , 'Favorites' , 'Image' , 'Faker' , 'Id' ,
16
- function ( $scope , $ionicPlatform , Settings , Favorites , Image , Faker , Id ) {
17
-
18
- $scope . generate = function ( ) {
19
- // generate map tiles
20
- var mapData = new MapData ( ) ;
21
- mapData . map = Catan . Generator . Map . generate ( Settings . getTileTrioScoreLimit ( ) , Settings . getHarborGenerationStrategy ( ) ) ;
22
-
23
- // generate map id
24
- mapData . id = Id . next ( ) ;
25
-
26
- // generate map name and catchphrase
27
- mapData . name = Faker . getMapName ( ) ;
28
- mapData . catchPhrase = Faker . getMapCatchPhrase ( ) ;
29
-
30
- // store generation metadata
31
- mapData . harborGenerationPhrase = {
32
- 'separate-tiles' : 'Separate Tiles (18 tiles)' ,
33
- 'coast-bars' : 'Enclosing edges bars (6 long pieces)'
34
- } [ Settings . getHarborGenerationStrategy ( ) ] ;
35
- mapData . fairnessPhrase = {
36
- 11 : 'Fair' ,
37
- 12 : 'Normal' ,
38
- 13 : 'Unfair'
39
- } [ Settings . getTileTrioScoreLimit ( ) ] ;
40
-
41
- $scope . mapData = mapData ;
42
- $scope . starred = false ;
43
- } ;
16
+ function ( $scope , $ionicPlatform , Settings , Favorites , Image , Faker , Id ) {
17
+
18
+ $scope . generate = function ( ) {
19
+ // generate map tiles
20
+ var mapData = new MapData ( ) ;
21
+ mapData . map = Catan . Generator . Map . generate ( Settings . getTileTrioScoreLimit ( ) , Settings . getHarborGenerationStrategy ( ) ) ;
22
+
23
+ // generate map id
24
+ mapData . id = Id . next ( ) ;
25
+
26
+ // generate map name and catchphrase
27
+ mapData . name = Faker . getMapName ( ) ;
28
+ mapData . catchPhrase = Faker . getMapCatchPhrase ( ) ;
29
+
30
+ // store generation metadata
31
+ mapData . harborGenerationPhrase = {
32
+ 'separate-tiles' : 'Separate Tiles (18 tiles)' ,
33
+ 'coast-bars' : 'Enclosing edges bars (6 long pieces)'
34
+ } [ Settings . getHarborGenerationStrategy ( ) ] ;
35
+ mapData . fairnessPhrase = {
36
+ 11 : 'Fair' ,
37
+ 12 : 'Normal' ,
38
+ 13 : 'Unfair'
39
+ } [ Settings . getTileTrioScoreLimit ( ) ] ;
40
+
41
+ $scope . mapData = mapData ;
42
+ $scope . starred = false ;
43
+ } ;
44
44
45
- $scope . starred = false ;
46
- $scope . star = function ( ) {
47
- Favorites . save ( $scope . mapData ) ;
48
- $scope . starred = true ;
49
- } ;
50
- } ] )
45
+ $scope . starred = false ;
46
+ $scope . star = function ( ) {
47
+ Favorites . save ( $scope . mapData ) ;
48
+ $scope . starred = true ;
49
+ } ;
50
+ } ] )
51
51
52
- . controller ( 'SettingsCtrl' , [ '$scope' , 'Settings' , function ( $scope , Settings ) {
52
+ . controller ( 'SettingsCtrl' , [ '$scope' , 'Settings' , function ( $scope , Settings ) {
53
53
$scope . tileTrioScoreLimitOptions = [
54
54
{ id : 11 , label : 'High (slower)' } ,
55
55
{ id : 12 , label : 'Normal' } ,
98
98
} ;
99
99
} ] )
100
100
101
- . controller ( 'FavoritesCtrl' , [ '$scope' , 'Favorites' , '$ionicListDelegate' ,
102
- function ( $scope , Favorites , $ionicListDelegate ) {
103
- $scope . items = Favorites . fetchAll ( ) ;
101
+ . controller ( 'FavoritesCtrl' , [ '$scope' , 'Favorites' , '$ionicListDelegate' , '$timeout' ,
102
+ function ( $scope , Favorites , $ionicListDelegate , $timeout ) {
103
+ $timeout ( function ( ) {
104
+ $scope . items = Favorites . fetchAll ( ) ;
105
+ } ) ;
104
106
105
- $scope . $on ( '$ionicView.enter' , function ( event , data ) {
106
- $scope . items = Favorites . fetchAll ( ) ;
107
- } ) ;
107
+ $scope . $on ( '$ionicView.enter' , function ( event , data ) {
108
+ $timeout ( function ( ) {
109
+ $scope . items = Favorites . fetchAll ( ) ;
110
+ } ) ;
111
+ } ) ;
108
112
109
- $scope . toggleDeleteButtons = function ( ) {
110
- $ionicListDelegate . showDelete ( ! $ionicListDelegate . showDelete ( ) ) ;
111
- } ;
113
+ $scope . toggleDeleteButtons = function ( ) {
114
+ $ionicListDelegate . showDelete ( ! $ionicListDelegate . showDelete ( ) ) ;
115
+ } ;
112
116
113
- $scope . deleteItem = function ( mapData ) {
114
- Favorites . remove ( mapData ) ;
115
- $scope . items = Favorites . fetchAll ( ) ;
116
- } ;
117
- } ] )
117
+ $scope . deleteItem = function ( mapData ) {
118
+ Favorites . remove ( mapData ) ;
119
+ $scope . items = Favorites . fetchAll ( ) ;
120
+ } ;
121
+ } ] )
118
122
119
- . directive ( "map" , [ 'Settings' , 'Image' , function ( Settings , Image )
120
- {
123
+ . directive ( "map" , [ 'Settings' , 'Image' , function ( Settings , Image ) {
121
124
return {
122
125
restrict : 'E' ,
123
126
scope : {
124
127
mapData : '=mapData' ,
125
128
generateThumbnail : '@generateThumbnail'
126
129
} ,
127
130
template : '<canvas></canvas>' ,
128
- link : function ( scope , element , attrs ) {
131
+ link : function ( scope , element , attrs ) {
129
132
var assetLoaded = false ;
130
133
131
134
scope . canvasContainer = element [ 0 ] ;
134
137
scope . canvasContainer ,
135
138
scope . canvasContainer . parentElement . offsetWidth ,
136
139
scope . canvasContainer . parentElement . offsetHeight ,
137
- function ( renderer ) {
140
+ function ( renderer ) {
138
141
assetLoaded = true ;
139
142
}
140
143
) ;
141
144
142
- scope . $watch ( 'mapData' , function ( mapData ) {
143
- if ( ! mapData ) {
145
+ scope . $watch ( 'mapData' , function ( mapData ) {
146
+ if ( ! mapData ) {
144
147
return ;
145
148
}
146
149
var uiDefinition = Settings . getUiDefinition ( ) ;
160
163
}
161
164
162
165
if ( scope . generateThumbnail ) {
163
- Image . getCroppedAndResizedBase64Uri ( canvas , function ( thumbnailImageUri ) {
164
- scope . $apply ( function ( ) {
166
+ Image . getCroppedAndResizedBase64Uri ( canvas , function ( thumbnailImageUri ) {
167
+ scope . $apply ( function ( ) {
165
168
scope . mapData . thumbnailImageUri = thumbnailImageUri ;
166
169
} ) ;
167
170
} ) ;
176
179
;
177
180
178
181
179
-
180
182
} ) ( angular , Catan ) ;
0 commit comments