not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
4.5 KiB

  1. // Main app class
  2. enyo.kind({
  3. name: "TankOp.App",
  4. kind: enyo.Control,
  5. published: {activity: null},
  6. classes: "home",
  7. components: [
  8. // Image
  9. {kind: "Image", classes: "home-image no-select-content", src: "images/home.png"},
  10. // Popup
  11. {classes: "start-button", ontap: "play", components: [
  12. {kind: "Image", classes: "start-button-image no-select-content", src: "images/button.png"},
  13. {name: "start", classes: "start-button-text no-select-content"}
  14. ]},
  15. // Credit
  16. {kind: "Image", classes: "credit-button no-select-content", src: "images/credit.png", ontap: "showCredit"},
  17. {name: "creditsPopup", kind: "TankOp.CreditsPopup"},
  18. // Next mission
  19. {classes: "mission-description no-select-content", components: [
  20. {components: [
  21. {name: "nextmission", classes: "mission-header mission-line"},
  22. {content: ":", classes: "mission-dot mission-line"}
  23. ]},
  24. {classes: "go-arrow go-left mission-line", ontap: "previousMission"},
  25. {name: "mission", content: " ", classes: "mission-text mission-line"},
  26. {classes: "go-arrow go-right mission-line", ontap: "nextMission"}
  27. ]},
  28. {classes: "mission-status no-select-content", components: [
  29. {components: [
  30. {name: "completed", classes: "mission-header mission-line"},
  31. {content: ":", classes: "mission-dot mission-line"}
  32. ]},
  33. {name: "stars", components: [
  34. {classes: "mission mission-completed mission-line"},
  35. {classes: "mission mission-tocomplete mission-line"},
  36. {classes: "mission mission-tocomplete mission-line"},
  37. {classes: "mission mission-tocomplete mission-line"},
  38. {classes: "mission mission-tocomplete mission-line"},
  39. {classes: "mission mission-tocomplete mission-line"},
  40. {classes: "mission mission-tocomplete mission-line"},
  41. {classes: "mission mission-tocomplete mission-line"},
  42. {classes: "mission mission-tocomplete mission-line"},
  43. {classes: "mission mission-tocomplete mission-line"},
  44. {classes: "mission mission-tocomplete mission-line"},
  45. {classes: "mission mission-tocomplete mission-line"}
  46. ]}
  47. ]}
  48. ],
  49. // Constructor
  50. create: function() {
  51. this.inherited(arguments);
  52. this.currentlevel = 0;
  53. this.$.mission.setContent(preferences.levels[this.currentlevel].name);
  54. this.init();
  55. },
  56. // Draw screen
  57. init: function() {
  58. this.setLocale();
  59. // Draw completed mission
  60. var items = [];
  61. enyo.forEach(this.$.stars.getControls(), function(item) { items.push(item); });
  62. for (var i = 0 ; i < items.length ; i++) { items[i].destroy(); };
  63. for (var i = 0 ; i < preferences.levels.length ; i++) {
  64. this.$.stars.createComponent({
  65. classes: (preferences.levels[i].completed ? "mission mission-completed mission-line" : "mission mission-tocomplete mission-line")
  66. },
  67. {owner: this}).render();
  68. }
  69. },
  70. // Localization, changed update UI and missions
  71. setLocale: function() {
  72. this.$.start.setContent(l10n.get("Start"));
  73. this.$.nextmission.setContent(l10n.get("NextMission"));
  74. this.$.completed.setContent(l10n.get("Completed"));
  75. this.$.mission.setContent(preferences.levels[this.currentlevel].name = l10n.get(preferences.levels[this.currentlevel].id));
  76. for (var i = 0 ; i < preferences.levels.length ; i++) {
  77. preferences.levels[i].name = l10n.get(preferences.levels[i].id);
  78. }
  79. },
  80. // Select mission
  81. previousMission: function() {
  82. this.currentlevel--;
  83. if (this.currentlevel < 0)
  84. this.currentlevel = preferences.levels.length-1;
  85. this.$.mission.setContent(preferences.levels[this.currentlevel].name);
  86. },
  87. nextMission: function() {
  88. this.currentlevel++;
  89. if (this.currentlevel == preferences.levels.length)
  90. this.currentlevel = 0;
  91. this.$.mission.setContent(preferences.levels[this.currentlevel].name);
  92. },
  93. // Show credit
  94. showCredit: function() {
  95. this.$.creditsPopup.show();
  96. },
  97. // Play theme
  98. playTheme: function() {
  99. sound.play("audio/soundtrack", true);
  100. },
  101. // Play game
  102. play: function() {
  103. // Stop sound
  104. sound.pause();
  105. // Start game
  106. new TankOp.Play({level: this.currentlevel}).renderInto(document.getElementById("board"));
  107. },
  108. // Load game from datastore
  109. load: function() {
  110. this.playTheme();
  111. var datastoreObject = this.activity.getDatastoreObject();
  112. var currentthis = this;
  113. datastoreObject.loadAsText(function (error, metadata, data) {
  114. var data = JSON.parse(data);
  115. preferences.setState(data);
  116. currentthis.init();
  117. });
  118. },
  119. // Save game in datastore
  120. save: function(count) {
  121. var datastoreObject = this.activity.getDatastoreObject();
  122. var jsonData = JSON.stringify(preferences.getState());
  123. datastoreObject.setDataAsText(jsonData);
  124. datastoreObject.save(function() {});
  125. }
  126. });