Parse in shapes

This commit is contained in:
Ketchetwahmeegwun T. Southall 2022-01-29 16:30:48 -08:00
parent ec113bd348
commit 66eb1f79ee

View File

@ -1,5 +1,34 @@
import * as PIXI from 'pixi.js'
export class Shape {
key: string
sensor: boolean
constructor(o: any) {
this.key = o.key
this.sensor = o.sensor
}
}
export class ShapeCircle extends Shape {
radius: number = 8
x: number = 0
y: number = 0
constructor(o: any) {
super(o)
this.radius = o.circle.radius
this.x = o.circle.x
this.y = o.circle.y
}
}
export class ShapePoints extends Shape {
points: [number, number][]
constructor(o: any) {
super(o)
this.points = o.points
}
}
export class Sprite {
uuid: string
texture: PIXI.Texture
@ -40,6 +69,7 @@ export interface SpritePartI {
time: number
source: string
children?: Record<string, SpritePart>
shapes?: (ShapeCircle|ShapePoints)[]
}
export class SpritePart {
@ -54,6 +84,7 @@ export class SpritePart {
source: string = ''
children: Record<string, SpritePart> = {}
frames?: SpritePart[]
shapes: (ShapeCircle|ShapePoints)[] = []
constructor(o: any, p: SpritePartI, t: PIXI.Texture) {
this.time = o.time ?? p.time
@ -90,5 +121,15 @@ export class SpritePart {
return new SpritePart(v, this, t)
})
}
if (o.shapes) {
for (let s of o.shapes) {
if (s.circle) {
this.shapes.push(new ShapeCircle(s))
} else {
this.shapes.push(new ShapePoints(s))
}
}
}
}
}