room.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /** This class represents room. */
  2. export class room {
  3. #id;
  4. #name;
  5. #description;
  6. #texture;
  7. /**
  8. * This create new room from the config object.
  9. *
  10. * @param {string} id - ID of the room
  11. * @param {object} config - Config from the assets
  12. * @return {room} - New room from the config
  13. */
  14. constructor(id, config) {
  15. this.#id = id;
  16. this.#name = this.#save_get("name", config);
  17. this.#description = this.#save_get("description", config);
  18. this.#texture = this.#save_get("texture", config);
  19. }
  20. /**
  21. * @return {string} - Name of the room
  22. */
  23. get name() {
  24. return this.#name;
  25. }
  26. /**
  27. * @return {string} - ID of the room
  28. */
  29. get id() {
  30. return this.#id;
  31. }
  32. /**
  33. * @return {string} - Description of the room
  34. */
  35. get description() {
  36. return this.#description;
  37. }
  38. /**
  39. * @return {string} - Link to the texture file
  40. */
  41. get texture() {
  42. return this.#texture;
  43. }
  44. /**
  45. * This function return property of the object, if it exists. When it no
  46. * exists, the return null.
  47. *
  48. * @param {string} property - Property to get from object
  49. * @param {object} source - Source object to get property from
  50. * @return Property of the object or null
  51. */
  52. #save_get(property, source) {
  53. if (!source.hasOwnProperty(property)) {
  54. return null;
  55. }
  56. return source[property];
  57. }
  58. }