Skip to content
This repository has been archived by the owner on Oct 4, 2019. It is now read-only.

Commit

Permalink
build for android
Browse files Browse the repository at this point in the history
  • Loading branch information
tirinox committed Apr 10, 2015
1 parent f62d5c6 commit 34f2862
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 107 deletions.
1 change: 1 addition & 0 deletions platforms/android/assets/www/index.html
Expand Up @@ -16,6 +16,7 @@

<!-- your app's js -->
<script src="js/app.js"></script>
<script src="js/auth.js"></script>
<script src="js/social.js"></script>
<script src="js/gameplay.js"></script>
<script src="js/selectletter.js"></script>
Expand Down
38 changes: 0 additions & 38 deletions platforms/android/assets/www/js/app.js
Expand Up @@ -105,41 +105,3 @@ app.controller('settingsController', function ($scope, server, $ionicLoading) {
m.prices = server.prices;
});
});

app.controller('authController', function ($scope, $state, $ionicLoading, socialProvider) {

var m = $scope.model = {
name: '',
loading: false,
isError: true
};


$scope.$watch('model.name', function() {
var name = m.name.trim();
m.isError = name.length < 2 || name.length >= 32;
socialProvider.name = name;
});

$scope.gotoGameplay = function() {
$state.go('gameplay');
};

$scope.authorizeMe = function() {
//if(user.name.length > 0) {
//
// $state.go('tabs.newgame');
// //user.name = '';
// //$scope.loading = true;
//
// // $ionicLoading.show({
// // template: 'Please wait while we register your device...'
// // });
//}
//else
// alert('No name');
if(!m.isError)
$state.go('tabs.newgame');
console.log(socialProvider.name);
};
});
39 changes: 38 additions & 1 deletion platforms/android/assets/www/js/auth.js
@@ -1,2 +1,39 @@
// auth.js

angular.module('balda').controller('authController', function ($scope, $state, $ionicLoading, socialProvider, server) {

var m = $scope.model = {
name: '',
loading: false,
isError: true
};


$scope.$watch('model.name', function() {
var name = m.name.trim();
m.isError = name.length < 2 || name.length >= 32;
socialProvider.name = name;
});

$scope.gotoGameplay = function() {
$state.go('gameplay');
};

$scope.authorizeMe = function() {
//if(user.name.length > 0) {
//
// $state.go('tabs.newgame');
// //user.name = '';
// //$scope.loading = true;
//
// // $ionicLoading.show({
// // template: 'Please wait while we register your device...'
// // });
//}
//else
// alert('No name');
if(!m.isError) {
server.login();
$state.go('tabs.newgame');
}
};
});
9 changes: 6 additions & 3 deletions platforms/android/assets/www/js/config.js
@@ -1,5 +1,8 @@
var cfg = angular.module('config', []);

cfg.constant('config', {
server: 'http://test.erudite-express.ru/balda/api/index.php?config=ios_pub'
});
cfg.constant('config', (function () {
var consts = {};
consts.host = 'test.erudite-express.ru';
consts.server = 'http://' + consts.host + '/balda/api/index.php?config=ios_pub';
return consts;
}()));
50 changes: 22 additions & 28 deletions platforms/android/assets/www/js/gameplay.js
@@ -1,4 +1,4 @@
var gp = angular.module('gameplay', ['ionic', 'selectLetter', 'server']);
var gp = angular.module('gameplay', ['ionic', 'server']);

gp.constant('fieldConst', {
max: 5,
Expand All @@ -12,19 +12,6 @@ gp.constant('fieldConst', {
nextPossible: ['fieldcell', 'fieldcell-can-be-next']
}
});
//
//gp.config(function ($stateProvider) {
// $stateProvider
// .state('tabs.gameplay', {
// url: '/gameplay',
// views: {
// 'matchlist': {
// templateUrl: 'tpl/gameplay.html',
// controller: 'gameplayController'
// }
// }
// });
//});

function isCellFree(cell) { return cell == null || !cell.val || cell.val == ''; }

Expand Down Expand Up @@ -60,13 +47,16 @@ function SelectionPath() {
}
return null;
};
t.hasInPathCoord = function(x, y) {
t.indexOfCellWithCoords = function(x, y) {
for(var i = 0; i < t.path.length; ++i)
{
var cell = t.path[i];
if(cell.x == x && cell.y == y) return true;
if(cell.x == x && cell.y == y) return i;
}
return false;
return null;
};
t.hasInPathCoord = function(x, y) {
return t.indexOfCellWithCoords(x, y) !== null;
};
t.isNeighborToLast = function(x, y, defaultIfNotLast) {
var last = t.getLast();
Expand All @@ -77,13 +67,10 @@ function SelectionPath() {
t.pushCell = function(cell) {
var l = t.getLength();
var x = cell.x, y = cell.y;
if(t.hasInPathCoord(x, y))
var i = t.indexOfCellWithCoords(x, y);
if(i !== null)
{
if(l >= 2) {
var cellBeforeLast = t.path[l - 2];
if(cellBeforeLast.x == x && cellBeforeLast.y == y)
t.deleteLast();
}
t.path = t.path.slice(0, i + 1);
return false;
}
else if(isCellFree(cell) && t.getNewCell() != null)
Expand Down Expand Up @@ -217,13 +204,20 @@ gp.controller('gameplayController', function ($scope, fieldConst) {

function finishLetterSelection(letter)
{
var newCell = m.selectedPath.getNewCell();
if(newCell)
if(letter == null)
{
m.selectedPath.clear();
}
else
{
newCell.val = letter;
syncField();
console.log('word = ', m.selectedPath.getWord());
var newCell = m.selectedPath.getNewCell();
if(newCell)
{
newCell.val = letter;
console.log('word = ', m.selectedPath.getWord());
}
}
syncField();
}

$scope.cellTrackerMove = function(x, y) {
Expand Down
21 changes: 11 additions & 10 deletions platforms/android/assets/www/js/selectletter.js
@@ -1,6 +1,5 @@
var sl = angular.module('selectLetter', ['ionic']);

sl.controller('selectLetterController', function ($ionicModal, $scope) {
angular.module('gameplay')
.controller('selectLetterController', function ($ionicModal, $scope) {

$ionicModal.fromTemplateUrl('tpl/selectletter.html', {
scope: $scope,
Expand All @@ -13,19 +12,21 @@ sl.controller('selectLetterController', function ($ionicModal, $scope) {

$scope.$on('showSelectLetter', function (e, arg) {
callback = arg.callback;
$scope.openModal();
$scope.modal.show();
});

function callCallback(i) {
if(callback) callback(i);
callback = null;
}

$scope.selectLetter = function(i) {
if(callback)
callback(i);
$scope.closeModal();
callCallback(i);
$scope.modal.hide();
};

$scope.openModal = function() {
$scope.modal.show();
};
$scope.closeModal = function() {
callCallback(null);
$scope.modal.hide();
};

Expand Down
79 changes: 52 additions & 27 deletions platforms/android/assets/www/js/server.js
@@ -1,33 +1,50 @@
var sv = angular.module('server', ['ionic', 'config', 'util', 'social']);

sv.service('server', function($http, config, $rootScope) {
sv.service('server', function($http, config, $rootScope, socialProvider) {

var that = this;
that.sessionKey = '';
that.sessionAcquireTS = 0;
that.prices = {};

that.makeGeneralRequest = function(data) {
var sessionExpiration = 60 * 59; // 59 min

function rawPromise(data) {
return $http.post(config.server, data);
};
}

that.onError = function(r) {
$rootScope.$broadcast('serverError', r);
};
function isGood(r) {
return r && r.result && r.result == 'good';
}

that.makeRequest = function(data) {
if(that.sessionKey !== '')
data.session = that.sessionKey;
return that.makeGeneralRequest(data).success(function (r) {
if(r.result == 'bad') {
function rawRequest(data) {
return rawPromise(data).success(function (r) {
if(!isGood(r)) {
r.type = 'logic';
that.onError(r);
}
}).error( function () {
that.onError({type: 'inet'});
});
}

that.login = function() {
var loginData = socialProvider.getLoginData();
loginData.method = 'login';

$rootScope.$broadcast('loggingIn', 'start');
rawRequest(loginData).success(function(r) {
console.log('login', r);
}).finally(function() {
$rootScope.$broadcast('loggingIn', 'end');
});
};

that.onError = function(r) {
$rootScope.$broadcast('serverError', r);
};


that.getAnswer = function(r, name) {
var a = r['answers'];
if(a)
Expand All @@ -37,8 +54,18 @@ sv.service('server', function($http, config, $rootScope) {
return null;
};

that.getAllAnswers = function(r, name) {
var a = r['answers'];
var res = [];
if(a)
for(var i = 0; i < a.length; ++i)
if(a[i][name])
res.push(a[i][name]);
return res;
};

that.getPrices = function() {
return that.makeRequest({
return rawRequest({
method: 'prices'
}).success(function (r) {
var prices = that.getAnswer(r, 'prices');
Expand All @@ -49,24 +76,10 @@ sv.service('server', function($http, config, $rootScope) {
});
};

that.login = function(uid, token, name, sex, photoURL) {

var data = {
method: 'login',
uid: uid,
token: token
};
if(name) data.name = name;
if(sex) data.sex = +sex;
if(photoURL) data.photoURL = photoURL;

return that.makeRequest(data);
};

});


app.controller('errorController', function ($rootScope, $scope, $ionicPopup) {
app.controller('errorController', function ($rootScope, $scope, $ionicPopup, $ionicLoading) {

$rootScope.$on('serverError', function (event, data) {
$scope.data = data;
Expand All @@ -80,4 +93,16 @@ app.controller('errorController', function ($rootScope, $scope, $ionicPopup) {
]
});
});

$rootScope.$on('loggingIn', function (event, state) {

$scope.loadingType = 'auth';
if(state == 'start')
$ionicLoading.show({
scope: $scope,
templateUrl: 'tpl/loading.html'
});
else
$ionicLoading.hide();
});
});
2 changes: 2 additions & 0 deletions platforms/android/assets/www/tpl/loading.html
@@ -0,0 +1,2 @@
<ion-spinner class="spinner-light" icon="android"></ion-spinner><br>
<span ng-if="loadingType == 'auth'">Авторизациия...</span>

0 comments on commit 34f2862

Please sign in to comment.