12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- /*
- jbox
- A JSON Component
- Version: 1.0
- Docs:
- - jbox(tags=[])
- - pack() json
- > jbox renders it's version in debug.inspect mode
- Currently Supported Components:
- - pos (Obtains X and Y)
- - health (Obtains current HP and maxHP)
- - scale (Obtains scale.X and scale.Y)
- - rotate (Obtains angle, in degrees)
- */
- function jbox(tags=[]) {
- let config = {
- tags: tags,
- };
- return {
- id: "jbox",
- require: tags,
- inspect() {
- return "[[email protected]]"
- },
- pack() {
- let j = {
- jbox: "[[email protected]]",
- comps: {},
- };
- for (let tag in config.tags) {
- switch (tag) {
- case "pos": {
- j.comps["pos"] = {
- x: this.pos.x,
- y: this.pos.y,
- }
- }
- case "health": {
- j.comps["health"] = {
- health: this.hp(),
- max_health: this.maxHP(),
- }
- }
- case "scale": {
- j.comps["scale"] = {
- x: this.scale.x,
- y: this.scale.y,
- }
- }
- case "rotate": {
- j.comps["rotate"] = {
- angle: this.angle,
- }
- }
- }
- }
- return j;
- }
- }
- }
|