jbox.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. export function jbox(tags=[]) {
  16. return {
  17. id: "jbox",
  18. require: tags,
  19. inspect() {
  20. return "[[email protected]]"
  21. },
  22. pack() {
  23. let j = {
  24. jbox: "[[email protected]]",
  25. comps: {},
  26. };
  27. for (let tag in tags) {
  28. switch (tag) {
  29. case "pos": {
  30. j.comps["pos"] = {
  31. x: this.pos.x,
  32. y: this.pos.y,
  33. }
  34. }
  35. case "health": {
  36. j.comps["health"] = {
  37. health: this.hp(),
  38. max_health: this.maxHP(),
  39. }
  40. }
  41. case "scale": {
  42. j.comps["scale"] = {
  43. x: this.scale.x,
  44. y: this.scale.y,
  45. }
  46. }
  47. case "rotate": {
  48. j.comps["rotate"] = {
  49. angle: this.angle,
  50. }
  51. }
  52. }
  53. }
  54. return j;
  55. }
  56. }
  57. }
  58. export default () => {
  59. return jbox
  60. }