jbox.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. jbox
  3. A JSON Component
  4. Version: 1.0
  5. Docs:
  6. - jbox(tags=[])
  7. - pack() json
  8. > jbox renders it's version in debug.inspect mode
  9. Currently Supported Components:
  10. - pos (Obtains X and Y)
  11. - health (Obtains current HP and maxHP)
  12. - scale (Obtains scale.X and scale.Y)
  13. - rotate (Obtains angle, in degrees)
  14. */
  15. function jbox(tags=[]) {
  16. let config = {
  17. tags: tags,
  18. };
  19. return {
  20. id: "jbox",
  21. require: tags,
  22. inspect() {
  23. return "[[email protected]]"
  24. },
  25. pack() {
  26. let j = {
  27. jbox: "[[email protected]]",
  28. comps: {},
  29. };
  30. for (let tag in config.tags) {
  31. switch (tag) {
  32. case "pos": {
  33. j.comps["pos"] = {
  34. x: this.pos.x,
  35. y: this.pos.y,
  36. }
  37. }
  38. case "health": {
  39. j.comps["health"] = {
  40. health: this.hp(),
  41. max_health: this.maxHP(),
  42. }
  43. }
  44. case "scale": {
  45. j.comps["scale"] = {
  46. x: this.scale.x,
  47. y: this.scale.y,
  48. }
  49. }
  50. case "rotate": {
  51. j.comps["rotate"] = {
  52. angle: this.angle,
  53. }
  54. }
  55. }
  56. }
  57. return j;
  58. }
  59. }
  60. }