Advertisement
Guest User

Untitled

a guest
May 29th, 2015
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. define(function (require) {
  2. "use strict";
  3.  
  4. var Config = require('config'),
  5. configHelper = require('helpers/config');
  6.  
  7. var hasCocoon = (typeof CocoonJS !== "undefined" && CocoonJS.nativeExtensionObjectAvailable !== false),
  8. constants = {};
  9.  
  10. constants.ACH_REENACTMENT_WIN_21 = 'yourgoogleachievementidhere';
  11. constants.ACH_PUNISHMENT = 'yourgoogleachievementidhere';
  12. constants.ACH_FAILURE = 'yourgoogleachievementidhere';
  13. constants.ACH_WHAT = 'yourgoogleachievementidhere';
  14. constants.ACH_DRAW = 'yourgoogleachievementidhere';
  15. constants.LEADERBOARD = 'yourgoogleleaderboardidhere';
  16.  
  17. if (hasCocoon) {
  18. var gp = CocoonJS.Social.GooglePlayGames;
  19. gp.init({defaultLeaderboard: constants.LEADERBOARD});
  20. var socialService = gp.getSocialInterface();
  21. }
  22.  
  23. return {
  24. constants: constants,
  25. hasCocoon: hasCocoon,
  26. isLoggedIn: function () {
  27. if (!hasCocoon) {
  28. return false;
  29. }
  30.  
  31. return socialService.isLoggedIn();
  32. },
  33. login: function (callback) {
  34. if (!hasCocoon) {
  35. return;
  36. }
  37.  
  38. try {
  39. socialService.login(callback);
  40. } catch (e) {
  41. console.error("submitAchievement error: " + e.message);
  42. return;
  43. }
  44. },
  45. postScore: function (score) {
  46. if (!hasCocoon || !this.isLoggedIn()) {
  47. return;
  48. }
  49.  
  50. var params = new CocoonJS.Social.ScoreParams(null, constants.LEADERBOARD);
  51.  
  52. try {
  53. socialService.submitScore(score, function (error) {
  54. if (error) {
  55. console.error("submit Score error: " + error.message);
  56. }
  57. }, params);
  58. } catch (e) {
  59. console.error("submitAchievement error: " + e.message);
  60. return;
  61. }
  62. },
  63. showLeaderboard: function (opponent) {
  64. if (!hasCocoon || !this.isLoggedIn()) {
  65. return;
  66. }
  67.  
  68. var params = new CocoonJS.Social.ScoreParams(null, constants.LEADERBOARD);
  69.  
  70. try {
  71. socialService.showLeaderboard(function (error) {
  72. if (error) {
  73. console.error("showLeaderbord error: " + error.message);
  74. }
  75. }, params);
  76. } catch (e) {
  77. console.error("submitAchievement error: " + e.message);
  78. return;
  79. }
  80. },
  81. showAchievements: function () {
  82. if (!hasCocoon || !this.isLoggedIn()) {
  83. return;
  84. }
  85.  
  86. try {
  87. socialService.showAchievements();
  88. } catch (e) {
  89. console.error("submitAchievement error: " + e.message);
  90. return;
  91. }
  92. },
  93. winAchievement: function (achievement) {
  94. if (!hasCocoon || !this.isLoggedIn()) {
  95. return;
  96. }
  97.  
  98. try {
  99. socialService.submitAchievement(achievement, function (error) {
  100. if (error) {
  101. console.error("submitAchievement error: " + error.message);
  102. }
  103. });
  104. } catch (e) {
  105. console.error("submitAchievement error: " + e.message);
  106. return;
  107. }
  108. }
  109. };
  110. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement