Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 2654768

Browse files
committed
smoother favorites screen
1 parent d098258 commit 2654768

File tree

2 files changed

+62
-59
lines changed

2 files changed

+62
-59
lines changed

gulpfile.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ gulp.task('css-concat-vendor', function () {
108108
gulp.task('fonts-concat-vendor', function () {
109109
return gulp.src(mainBowerFiles())
110110
.pipe(gulpFilter(function (file) {
111-
return /ionicons\/fonts/.test(file.path);
111+
return /ionic\/fonts/.test(file.path);
112112
}))
113+
.pipe(debug())
113114
.pipe(gulp.dest('./www/fonts/'));
114115
});

www/js/controllers.js

Lines changed: 60 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,43 @@
1313
angular.module('starter.controllers', [])
1414

1515
.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+
};
4444

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+
}])
5151

52-
.controller('SettingsCtrl', ['$scope', 'Settings', function($scope, Settings) {
52+
.controller('SettingsCtrl', ['$scope', 'Settings', function ($scope, Settings) {
5353
$scope.tileTrioScoreLimitOptions = [
5454
{id: 11, label: 'High (slower)'},
5555
{id: 12, label: 'Normal'},
@@ -98,34 +98,37 @@
9898
};
9999
}])
100100

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+
});
104106

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+
});
108112

109-
$scope.toggleDeleteButtons = function() {
110-
$ionicListDelegate.showDelete(! $ionicListDelegate.showDelete());
111-
};
113+
$scope.toggleDeleteButtons = function () {
114+
$ionicListDelegate.showDelete(!$ionicListDelegate.showDelete());
115+
};
112116

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+
}])
118122

119-
.directive("map",['Settings', 'Image', function (Settings, Image)
120-
{
123+
.directive("map", ['Settings', 'Image', function (Settings, Image) {
121124
return {
122125
restrict: 'E',
123126
scope: {
124127
mapData: '=mapData',
125128
generateThumbnail: '@generateThumbnail'
126129
},
127130
template: '<canvas></canvas>',
128-
link: function(scope, element, attrs) {
131+
link: function (scope, element, attrs) {
129132
var assetLoaded = false;
130133

131134
scope.canvasContainer = element[0];
@@ -134,13 +137,13 @@
134137
scope.canvasContainer,
135138
scope.canvasContainer.parentElement.offsetWidth,
136139
scope.canvasContainer.parentElement.offsetHeight,
137-
function(renderer) {
140+
function (renderer) {
138141
assetLoaded = true;
139142
}
140143
);
141144

142-
scope.$watch('mapData', function(mapData) {
143-
if (! mapData) {
145+
scope.$watch('mapData', function (mapData) {
146+
if (!mapData) {
144147
return;
145148
}
146149
var uiDefinition = Settings.getUiDefinition();
@@ -160,8 +163,8 @@
160163
}
161164

162165
if (scope.generateThumbnail) {
163-
Image.getCroppedAndResizedBase64Uri(canvas, function(thumbnailImageUri) {
164-
scope.$apply(function(){
166+
Image.getCroppedAndResizedBase64Uri(canvas, function (thumbnailImageUri) {
167+
scope.$apply(function () {
165168
scope.mapData.thumbnailImageUri = thumbnailImageUri;
166169
});
167170
});
@@ -176,5 +179,4 @@
176179
;
177180

178181

179-
180182
})(angular, Catan);

0 commit comments

Comments
 (0)