Skip to content

Commit

Permalink
style: reformat comments as JSDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
andretchen0 committed Jul 26, 2023
1 parent b48d278 commit a82c4c8
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 161 deletions.
130 changes: 43 additions & 87 deletions src/creature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,6 @@ export class Creature {
*
*/

/* Constructor(obj)
*
* obj : Object : Object containing all creature stats
*
*/
// Engine
game: Game;
name: string;
Expand Down Expand Up @@ -166,6 +161,11 @@ export class Creature {

creatureSprite: CreatureSprite;

/**
* @constructor
* @param{Object} obj - Object containing all creature stats
* @param{Game} game - Game instance
*/
constructor(obj, game: Game) {
// Engine
this.game = game;
Expand Down Expand Up @@ -429,10 +429,8 @@ export class Creature {
this.creatureSprite.showHealth(true);
}

/* activate()
*
/**
* Activate the creature by showing movement range and binding controls to this creature
*
*/
activate() {
this.travelDist = 0;
Expand Down Expand Up @@ -607,8 +605,8 @@ export class Creature {
game.updateQueueDisplay();
}

/* queryMove()
* launch move action query
/**
* Launch move action query
*/
// TODO: type `args` in `QueryMoveOptions`
queryMove(options?: QueryMoveOptions) {
Expand Down Expand Up @@ -740,12 +738,9 @@ export class Creature {
}
}

/* previewPosition(hex)
*
* hex : Hex : Position
*
/**
* Preview the creature position at the given Hex
*
* @param{Hex} hex - Position
*/
previewPosition(hex: Hex) {
const game = this.game;
Expand Down Expand Up @@ -791,10 +786,8 @@ export class Creature {
}
}

/* cleanHex()
*
/**
* Clean current creature hexagons
*
*/
cleanHex() {
this.hexagons.forEach((hex) => {
Expand All @@ -803,10 +796,8 @@ export class Creature {
this.hexagons = [];
}

/* updateHex()
*
/**
* Update the current hexes containing the creature and their display
*
*/
updateHex() {
const count = this.size;
Expand All @@ -821,13 +812,10 @@ export class Creature {
});
}

/* faceHex(facefrom,faceto)
*
* facefrom : Hex or Creature : Hex to face from
* faceto : Hex or Creature : Hex to face
*
/**
* Face creature at given hex
*
* @param{Hex | Creature} facefrom - Hex to face from
* @param{Hex | Creature} faceto - Hex to face
*/
faceHex(
faceto: Hex | Creature,
Expand Down Expand Up @@ -894,10 +882,8 @@ export class Creature {
this.sprite.texture.width / 2;
}

/* facePlayerDefault()
*
* Face default direction
*
/**
* Make creature face the default direction of its player
*/
facePlayerDefault() {
if (this.player.flipped) {
Expand All @@ -912,13 +898,10 @@ export class Creature {
this.sprite.texture.width / 2;
}

/* moveTo(hex,opts)
*
* hex : Hex : Destination Hex
* opts : Object : Optional args object
*
/**
* Move the creature along a calculated path to the given coordinates
*
* @param{Hex} hex - Destination Hex
* @param{Object} opts - Optional args object
*/
moveTo(hex, opts) {
const game = this.game,
Expand Down Expand Up @@ -977,12 +960,8 @@ export class Creature {
}

/**
* tracePath()
*
* @param{Point} destination: the end of the path.
*
* Trace the path from the current position to the given coordinates
*
* @param{Point} destination: the end of the path.
*/
tracePath(destination: Point) {
const path = this.calculatePath(destination); // Store path in grid to be able to compare it later
Expand Down Expand Up @@ -1044,12 +1023,8 @@ export class Creature {
}

/**
* calculatePath(destination:Point)
*
* @param{Point} destination: the end of the path.
*
* return : Array : Array containing the path hexes
*
* @returns{Point[]} Array containing the path points.
*/
calculatePath(destination: Point) {
const game = this.game;
Expand All @@ -1063,15 +1038,11 @@ export class Creature {
); // Calculate path
}

/* calcOffset(x,y)
*
* x : Integer : Destination coordinates
* y : Integer : Destination coordinates
*
* return : Object : New position taking into acount the size, orientation and obstacle {x,y}
*
/**
* Return the first possible position for the creature at the given coordinates
*
* @param{number} x - Integer, Destination coordinates
* @param{number} y - Integer, Destination coordinates
* @returns{Object} New position taking into acount the size, orientation and obstacle {x,y}
*/
calcOffset(x: number, y: number) {
const game = this.game,
Expand All @@ -1096,22 +1067,17 @@ export class Creature {
};
}

/* getInitiative()
*
* return : Integer : Initiative value to order the queue
*
/**
* @returns{number} Initiative value to order the queue
*/
getInitiative(): number {
// To avoid 2 identical initiative
return this.stats.initiative * 500 - this.id;
}

/* adjacentHexes(dist)
*
* dist : Integer : Distance in hexagons
*
* return : Array : Array of adjacent hexagons
*
/**
* @param{number} dist - Integer, Distance in hexagons
* @returns{Hex[]} Array of adjacent hexagons
*/
adjacentHexes(dist: number, clockwise?: boolean) {
const game = this.game;
Expand Down Expand Up @@ -1267,7 +1233,7 @@ export class Creature {
}
}

/** recharge
/**
* @param {number} amount: amount of energy to restore
* @return {void}
* Restore energy up to the max limit
Expand All @@ -1283,7 +1249,6 @@ export class Creature {
/**
* Restore endurance to a creature. Will be capped against the creature's maximum
* endurance (this.stats.endurance).
*
* @param {*} amount Number of endurance points to restore.
*/
restoreEndurance(amount: number, log = true) {
Expand All @@ -1308,9 +1273,8 @@ export class Creature {
}
}

/* heal(amount)
*
* amount : Damage : Amount of health point to restore
/**
* @param{number} amount - Amount of health point to restore
*/
heal(amount: number, isRegrowth: boolean, log = true) {
const game = this.game;
Expand Down Expand Up @@ -1358,11 +1322,9 @@ export class Creature {
game.onHeal(this, amount);
}

/* takeDamage(damage)
*
* damage : Damage : Damage object
*
* return : Object : Contains damages dealt and if creature is killed or not
/**
* @param{Damage} damage - Damage object
* @returns{Object} Contains damages dealt and if creature is killed or not
*/
takeDamage(damage: Damage, o) {
const game = this.game;
Expand Down Expand Up @@ -1748,10 +1710,8 @@ export class Creature {
);
}

/* updateAlteration()
*
/**
* Update the stats taking into account the effects' alteration
*
*/
updateAlteration() {
this.stats = { ...this.baseStats };
Expand Down Expand Up @@ -1797,12 +1757,9 @@ export class Creature {
this.remainingMove = Math.min(this.remainingMove, this.stats.movement);
}

/* die()
*
* kill animation. remove creature from queue and from hexes
*
* killer : Creature : Killer of this creature
*
/**
* Play kill animation. Remove creature from queue and from hexes.
* @param{Creature | {player:Player}} killerCreature - Killer of this creature
*/
die(killerCreature: Creature | { player: Player }) {
const game = this.game;
Expand Down Expand Up @@ -1941,9 +1898,8 @@ export class Creature {
return this.stats.endurance === 1;
}

/* getHexMap()
*
* shortcut convenience function to grid.getHexMap
/**
* Shortcut convenience function to grid.getHexMap
*/
getHexMap(map: AugmentedMatrix, invertFlipped: boolean) {
const x = (this.player.flipped ? !invertFlipped : invertFlipped)
Expand Down
15 changes: 8 additions & 7 deletions src/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ export class Effect {
// Refactor to remove.
attacker: Creature | undefined = undefined;

/* Constructor(name, owner, target, trigger, optArgs)
*
* name: name of the effect
* owner : Creature : Creature that casted the effect
* target : Object : Creature or Hex : the object that possess the effect
* trigger : String : Event that trigger the effect
* optArgs: dictionary of optional arguments
/**
* @param{string} name - name of the effect
* @param{EffectOwner} owner - Creature that created the effect
* @param{EffectTarget} target - Creature or Hex : the object that possess the effect
* @param{string} trigger - Event that trigger the effect
* @param{EffectOptions} optArgs - dictionary of optional arguments
* @param{Game} game
* @constructor
*/
constructor(
name: string,
Expand Down
5 changes: 2 additions & 3 deletions src/ui/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import * as $j from 'jquery';
import * as str from '../utility/string';

export class Chat {
/* Constructor
*
/**
* Chat/Log Functions
*
* @constructor
*/
constructor(game) {
this.game = game;
Expand Down
22 changes: 7 additions & 15 deletions src/ui/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ export class UI {
*
*/

/* Constructor
*
/**
* Create attributes and default buttons
*
* @constructor
*/
constructor(game) {
this.game = game;
Expand Down Expand Up @@ -1182,11 +1181,9 @@ export class UI {
}
}

/* changePlayerTab(id)
*
* id : Integer : player id
*
/**
* Change to the specified player tab in the dash
* @param{number} id - player id (integer)
*/
changePlayerTab(id) {
const game = this.game;
Expand Down Expand Up @@ -1459,12 +1456,10 @@ export class UI {
this.$scoreboard.addClass('hide');
}

/* toggleDash()
*
/**
* Show the dash and hide some buttons
* Takes optional 'randomize' parameter to select a random creature from the grid.
* @param{boolean} [randomize] - True selects a random creature from the grid.
*/

toggleDash(randomize) {
const game = this.game;

Expand Down Expand Up @@ -1717,8 +1712,7 @@ export class UI {

this.gridSelectPrevious();
}
/* changeAbilityButtons()
*
/**
* Change ability buttons and bind events
*/
changeAbilityButtons() {
Expand Down Expand Up @@ -1961,8 +1955,6 @@ export class UI {
}
}

/* updateTimer()
*/
updateTimer() {
const game = this.game,
date = new Date() - game.pauseTime;
Expand Down
Loading

0 comments on commit a82c4c8

Please sign in to comment.