Bladeren bron

📝 Add type anotations to all member variables

Pedro Schneider 3 jaren geleden
bovenliggende
commit
8da9b1ad3d

+ 3 - 1
src/elements/earth/rebus/game/RebusCardVisualEffect.js

@@ -21,10 +21,12 @@
 
 class RebusCardVisualEffect extends Object2D
 {
+    /** @type {number} */
     glowIterations = 7;
+    /** @type {number} */
     glowAmount = 0;
 
-    _draw(delta, db)
+    _draw( /** @type {number} */ delta, /** @type {p5.Graphics} */ db)
     {
         db.rectMode(CENTER);
         if (this.parent.selected)

+ 9 - 3
src/elements/earth/rebus/game/RebusGame.js

@@ -21,12 +21,18 @@
 
 class RebusGame extends Object2D
 {
+    /** @type {Object} */
     levelData = null;
+    /** @type {Boolean} */
     gameFinished = false;
+    /** @type {number} */
     points = 3;
 
+    /** @type {Button} */
     backButton = null;
+    /** @type {Button} */
     continueButton = null;
+    /** @type {Button} */
     timer = null;
 
     _setup()
@@ -48,7 +54,7 @@ class RebusGame extends Object2D
             newCard.connect("selected", this, "_onCardSelected");
             this.addChild(newCard);
         }
-        
+
         for (let i = 0; i < this.levelData.questionCards.length; i++)
         {
             var newCard = new RebusQuestionCard("OptionCard" + i);
@@ -82,7 +88,7 @@ class RebusGame extends Object2D
         this.addChild(this.timer);
     }
 
-    _draw(delta, db)
+    _draw( /** @type {number} */ delta, /** @type {p5.Graphics} */ db)
     {
         background(52);
     }
@@ -94,7 +100,7 @@ class RebusGame extends Object2D
         this.queueFree();
     }
 
-    _onCardSelected(isAnswer)
+    _onCardSelected( /** @type {Boolean} */ isAnswer)
     {
         if (!isAnswer)
             this.points--;

+ 4 - 1
src/elements/earth/rebus/game/RebusGameVisualEffects.js

@@ -21,11 +21,14 @@
 
 class RebusGameVisualEffects extends Object2D
 {
+    /** @type {String} */
     suffix = "";
+    /** @type {number} */
     bgOpacity = 0;
+    /** @type {number} */
     textOpacity = 0;
 
-    _draw(delta, db)
+    _draw( /** @type {number} */ delta, /** @type {p5.Graphics} */ db)
     {
         if (this.parent.gameFinished)
         {

+ 13 - 2
src/elements/earth/rebus/game/RebusOptionCard.js

@@ -21,18 +21,29 @@
 
 class RebusOptionCard extends Object2D
 {
+    /** @type {TextureRes} */
     thumb = null;
+    /** @type {String} */
     imgName = "";
+    /** @type {Boolean} */
     isAnswer = false;
+    /** @type {Boolean} */
     selected = false;
+    /** @type {Boolean} */
     selectable = true;
 
+    /** @type {Color} */
     fillColor = new Color(200, 200, 200);
+    /** @type {Boolean} */
     mouseOver = false;
+    /** @type  {Boolean} */
     mousePress = false;
 
+    /** @type {Boolean} */
     tweenStarted = false;
+    /** @type {Tween} */
     tween = null;
+    /** @type {Timer} */
     timer = null;
 
     _initSignals()
@@ -64,7 +75,7 @@ class RebusOptionCard extends Object2D
         this.addChild(this.timer);
     }
 
-    _update(delta)
+    _update( /** @type {number} */ delta)
     {
         if (this.visible && !this.tweenStarted)
         {
@@ -101,7 +112,7 @@ class RebusOptionCard extends Object2D
         }
     }
 
-    _draw(delta, db)
+    _draw( /** @type {number} */ delta, /** @type {p5.Graphics} */ db)
     {
         db.rectMode(CENTER);
         db.fill(this.fillColor.getP5Color());

+ 5 - 1
src/elements/earth/rebus/game/RebusQuestionCard.js

@@ -21,10 +21,14 @@
 
 class RebusQuestionCard extends Object2D
 {
+    /** @type {TextureRes} */
     thumb = null;
+    /** @type {String} */
     imgName = "";
 
+    /** @type {Color} */
     fillColor = new Color(200, 200, 200);
+    /** @type {Tween} */
     tween = null;
 
     _setup()
@@ -46,7 +50,7 @@ class RebusQuestionCard extends Object2D
         this.tween.startAll();
     }
 
-    _draw(delta, db)
+    _draw( /** @type {number} */ delta, /** @type {p5.Graphics} */ db)
     {
         if (this.visible) this.tween.startAll();
 

+ 1 - 0
src/elements/earth/rebus/level_selector/RebusLevelButton.js

@@ -21,6 +21,7 @@
 
 class RebusLevelButton extends Button
 {
+    /** @type {Object} */
     levelData = null;
 
     _initSignals()

+ 5 - 3
src/elements/earth/rebus/level_selector/RebusLevelSelector.js

@@ -21,6 +21,7 @@
 
 class RebusLevelSelector extends Object2D
 {
+    /** @type {Object} */
     gridMargins = {
         left: 0,
         right: 0,
@@ -28,6 +29,7 @@ class RebusLevelSelector extends Object2D
         down: 0
     };
 
+    /** @type {number} */
     gridCols = 5;
 
     _setup()
@@ -64,7 +66,7 @@ class RebusLevelSelector extends Object2D
         this.addChild(this.backButton);
     }
 
-    _draw(delta, db)
+    _draw( /** @type {number} */ delta, /** @type {p5.Graphics} */ db)
     {
         background(52);
 
@@ -76,7 +78,7 @@ class RebusLevelSelector extends Object2D
         db.text("Escolha o nível", 1920 / 2, 200);
     }
 
-    _onTutorialSelected(levelData)
+    _onTutorialSelected( /** @type {Object} */ levelData)
     {
         var rg = new RebusTutorial("RebusTutorial");
         rg.levelData = levelData;
@@ -84,7 +86,7 @@ class RebusLevelSelector extends Object2D
         this.queueFree();
     }
 
-    _onLevelSelected(levelData)
+    _onLevelSelected( /** @type {Object} */ levelData)
     {
         var rg = new RebusGame("RebusGame");
         rg.levelData = levelData;

+ 11 - 3
src/elements/earth/rebus/tutorial/RebusTutorial.js

@@ -21,17 +21,25 @@
 
 class RebusTutorial extends Object2D
 {
+    /** @type {Object} */
     levelData = null;
+    /** @type {Boolean} */
     gameFinished = false;
+    /** @type {Number} */
     points = 3;
 
+    /** @type {Button} */
     backButton = null;
     continueButton = null;
     timer = null;
 
+    /** @type {Number} */
     tutorialStep = 0;
+    /** @type {Array} */
     questionCards = [];
+    /** @type {Array} */
     optionCards = [];
+    /** @type {Number} */
     answerIdx = 0;
 
     _setup()
@@ -92,7 +100,7 @@ class RebusTutorial extends Object2D
         this.addChild(new RebusTutorialVisualEffects);
     }
 
-    _update(delta)
+    _update( /** @type {Number} */ delta)
     {
         switch (this.tutorialStep)
         {
@@ -111,7 +119,7 @@ class RebusTutorial extends Object2D
         }
     }
 
-    _draw(delta, db)
+    _draw( /** @type {number} */ delta, /** @type {p5.Graphics} */ db)
     {
         background(52);
     }
@@ -132,7 +140,7 @@ class RebusTutorial extends Object2D
     {
         this.continueButton.hide();
         this.tutorialStep++;
-        
+
         switch (this.tutorialStep)
         {
             case 4:

+ 4 - 1
src/elements/earth/rebus/tutorial/RebusTutorialVisualEffects.js

@@ -21,11 +21,14 @@
 
 class RebusTutorialVisualEffects extends Object2D
 {
+    /** @type {String} */
     text = "";
+    /** @type {Number} */
     bgOpacity = 0;
+    /** @type {Number} */
     textOpacity = 0;
 
-    _draw(delta, db)
+    _draw( /** @type {number} */ delta, /** @type {p5.Graphics} */ db)
     {
         switch (this.parent.tutorialStep)
         {