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.

72 lines
1.5 KiB

  1. //gets the trending data
  2. const trendingAPI = require("./trendsAPI.js");
  3. class Player
  4. {
  5. constructor(s)
  6. {
  7. //name of the user
  8. this.name = null;
  9. //players socket
  10. this.socket = s;
  11. //score of the player
  12. this.score = 0;
  13. //reference to the room -- might not need this
  14. this.room = null;
  15. //the word the user selected for current round
  16. this.submission = '';
  17. this.roundScore = 0;
  18. //logs the user data so we can record it to data base at end of round
  19. this.log = [];
  20. }
  21. /**
  22. * generate the json object used in 'roomUpdate' socket io event
  23. *
  24. * return {name: score: word:}
  25. */
  26. genJASON()
  27. {
  28. var result = new Object();
  29. result.name = this.name;
  30. result.score = this.score;
  31. result.word = this.submission;
  32. return result;
  33. }
  34. /**
  35. * data -- literally a string
  36. * @param data
  37. */
  38. selectWord(data)
  39. {
  40. var w = data + " " + this.room.currentWord;
  41. this.submission = data;
  42. //console.log(w);
  43. this.room.update();
  44. return new Promise(function(resolve, reject)
  45. {
  46. trendingAPI.getPopularity(w).then(function(result)
  47. {
  48. console.log("api result for " + result + w);
  49. resolve(result);
  50. }).catch(function(err){
  51. console.log(err);
  52. })
  53. });
  54. }
  55. }
  56. module.exports = Player;