From 66eb1f79eea0be4a31a7d144567415c41bdc3bda Mon Sep 17 00:00:00 2001 From: kts of kettek <kts@kettek.net> Date: Sat, 29 Jan 2022 16:30:48 -0800 Subject: [PATCH] Parse in shapes --- Engine/src/data/sprite.ts | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/Engine/src/data/sprite.ts b/Engine/src/data/sprite.ts index 7acc232..d5a2dd7 100644 --- a/Engine/src/data/sprite.ts +++ b/Engine/src/data/sprite.ts @@ -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)) + } + } + } } } \ No newline at end of file