SpilAPI.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /**
  2. * @fileOverview Pack the SpilAPI for Highscore and other features
  3. * @author Yu Jianrong
  4. */
  5. (function()
  6. {
  7. /**
  8. * @namespace The namespace to pack the SpilAPI
  9. */
  10. FZ.SpilAPI={
  11. /**
  12. * Submit the high-score
  13. * @param {Number} theScore The Highscore
  14. */
  15. SubmitScore:function(theScore)
  16. {
  17. FZ.SpilAPI.checkSpilAPI();
  18. SpilGames.Highscores.insert({score: theScore});
  19. },
  20. /**
  21. * Show the highscore screen
  22. * @param {Number} theScore The Highscore
  23. */
  24. ShowHighscore:function()
  25. {
  26. FZ.SpilAPI.checkSpilAPI();
  27. if (!FZ.SpilAPI.___noSpilGamesAPI && FZ.GameBase)
  28. FZ.GameBase.pauseGame();
  29. SpilGames.Highscores.showScoreboard(function(){
  30. if (FZ.GameBase)
  31. FZ.GameBase.resumeGame();
  32. });
  33. },
  34. /**
  35. * return the Splash screen data url or empty string if SpilAPI does not exist
  36. * @returns {String} the dataurl of the image
  37. */
  38. GetSplashScreenURL:function()
  39. {
  40. FZ.SpilAPI.checkSpilAPI();
  41. if (FZ.SpilAPI.___noSpilGamesAPI)
  42. return "";
  43. else
  44. return SpilGames.Settings.get('currentGameInfo').splashScreen;
  45. },
  46. /**
  47. * return the portrait rotationLockSreen data url or empty string if SpilAPI does not exist
  48. * @returns {String} the dataurl of the image
  49. */
  50. GetPortraitLockURL:function()
  51. {
  52. FZ.SpilAPI.checkSpilAPI();
  53. if (FZ.SpilAPI.___noSpilGamesAPI)
  54. return "";
  55. else
  56. return SpilGames.Settings.get('currentGameInfo').rotationLockSreen.portrait;
  57. },
  58. /**
  59. * return the landscape rotationLockSreen data url or empty string if SpilAPI does not exist
  60. * @returns {String} the dataurl of the image
  61. */
  62. GetLandscapeLockURL:function()
  63. {
  64. FZ.SpilAPI.checkSpilAPI();
  65. if (FZ.SpilAPI.___noSpilGamesAPI)
  66. return "";
  67. else
  68. return SpilGames.Settings.get('currentGameInfo').rotationLockSreen.landscape;
  69. },
  70. /**
  71. * Check if the SpilAPI exist or not.
  72. * @returns {Boolean} True if SpilAPI exist
  73. */
  74. checkSpilAPI:function()
  75. {
  76. return !FZ.SpilAPI.___noSpilGamesAPI;
  77. },
  78. /**
  79. * Initial the iterface to SpilAPI
  80. * @private
  81. */
  82. init:function()
  83. {
  84. // For debug and non-SpilAPI supported site
  85. FZ.SpilAPI.___noSpilGamesAPI=!window.SpilGames;
  86. if (!window.SpilGames)
  87. {
  88. window.SpilGames = {
  89. _:function(text){
  90. var args= arguments,index = 0;
  91. return text.replace(/%s/g, function(){ index++; return (args[index] !== undefined) ? args[index] : arguments[0]; });
  92. },
  93. Highscores:{
  94. insert:function(score)
  95. {
  96. if (FZ.__localSubmitHighscore)
  97. FZ.__localSubmitHighscore(score.score);
  98. },
  99. showScoreboard:function(callback)
  100. {
  101. if (FZ.__localShowHighscore)
  102. FZ.__localShowHighscore(callback);
  103. }
  104. }
  105. };
  106. };
  107. }
  108. };
  109. FZ.SpilAPI.init();
  110. })();