refactor: more semantic graphics internals
This commit is contained in:
parent
11d6337db5
commit
52a4c43059
|
@ -9,7 +9,7 @@ export class Container extends Renderable {
|
||||||
this._children = [];
|
this._children = [];
|
||||||
this._childrenIndexes = new Map();
|
this._childrenIndexes = new Map();
|
||||||
this._isDirty = false;
|
this._isDirty = false;
|
||||||
this.internal = PIXI ? new PIXI.Container() : undefined;
|
this.container = PIXI ? new PIXI.Container() : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
addChild(child) {
|
addChild(child) {
|
||||||
|
@ -17,7 +17,7 @@ export class Container extends Renderable {
|
||||||
this.isDirty = true;
|
this.isDirty = true;
|
||||||
const index = this._children.push(child) - 1;
|
const index = this._children.push(child) - 1;
|
||||||
this._childrenIndexes.set(child, index);
|
this._childrenIndexes.set(child, index);
|
||||||
this.internal.addChild(child.internal);
|
this.container.addChild(child.internal);
|
||||||
}
|
}
|
||||||
|
|
||||||
get children() {
|
get children() {
|
||||||
|
@ -31,6 +31,10 @@ export class Container extends Renderable {
|
||||||
super.destroy();
|
super.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get internal() {
|
||||||
|
return this.container;
|
||||||
|
}
|
||||||
|
|
||||||
get isDirty() {
|
get isDirty() {
|
||||||
return this._isDirty;
|
return this._isDirty;
|
||||||
}
|
}
|
||||||
|
@ -48,7 +52,7 @@ export class Container extends Renderable {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._children.splice(index, 1);
|
this._children.splice(index, 1);
|
||||||
this.internal.removeChild(child.internal);
|
this.container.removeChild(child.internal);
|
||||||
}
|
}
|
||||||
removeChild(child) {
|
removeChild(child) {
|
||||||
this._removeChild(child);
|
this._removeChild(child);
|
||||||
|
@ -90,7 +94,7 @@ export class Container extends Renderable {
|
||||||
const rIndex = this._childrenIndexes.get(r);
|
const rIndex = this._childrenIndexes.get(r);
|
||||||
return lIndex - rIndex;
|
return lIndex - rIndex;
|
||||||
});
|
});
|
||||||
this.internal.children = this._children.map((child) => {
|
this.container.children = this._children.map((child) => {
|
||||||
return child.internal;
|
return child.internal;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,29 +15,29 @@ export class Primitives extends Renderable {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.internal = new PIXI.Graphics();
|
this.primitives = new PIXI.Graphics();
|
||||||
}
|
}
|
||||||
|
|
||||||
clear() {
|
clear() {
|
||||||
this.internal.clear();
|
this.primitives.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
drawCircle(position, radius, lineStyle, fillStyle) {
|
drawCircle(position, radius, lineStyle, fillStyle) {
|
||||||
this._wrapStyle('drawCircle', '3rd', lineStyle, fillStyle, () => {
|
this._wrapStyle('drawCircle', '3rd', lineStyle, fillStyle, () => {
|
||||||
this.internal.drawCircle(position[0], position[1], radius);
|
this.primitives.drawCircle(position[0], position[1], radius);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
drawLine(p1, p2, lineStyle, fillStyle) {
|
drawLine(p1, p2, lineStyle, fillStyle) {
|
||||||
this._wrapStyle('drawLine', '3rd', lineStyle, fillStyle, () => {
|
this._wrapStyle('drawLine', '3rd', lineStyle, fillStyle, () => {
|
||||||
this.internal.moveTo(p1[0], p1[1]);
|
this.primitives.moveTo(p1[0], p1[1]);
|
||||||
this.internal.lineTo(p2[0], p2[1]);
|
this.primitives.lineTo(p2[0], p2[1]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
drawRectangle(rectangle, lineStyle, fillStyle) {
|
drawRectangle(rectangle, lineStyle, fillStyle) {
|
||||||
this._wrapStyle('drawLine', '2nd', lineStyle, fillStyle, () => {
|
this._wrapStyle('drawLine', '2nd', lineStyle, fillStyle, () => {
|
||||||
this.internal.drawRect(
|
this.primitives.drawRect(
|
||||||
rectangle[0],
|
rectangle[0],
|
||||||
rectangle[1],
|
rectangle[1],
|
||||||
rectangle[2],
|
rectangle[2],
|
||||||
|
@ -46,6 +46,10 @@ export class Primitives extends Renderable {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get internal() {
|
||||||
|
return this.primitives;
|
||||||
|
}
|
||||||
|
|
||||||
_wrapStyle(method, where, lineStyle, fillStyle, fn) {
|
_wrapStyle(method, where, lineStyle, fillStyle, fn) {
|
||||||
if (!lineStyle) {
|
if (!lineStyle) {
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
|
@ -54,13 +58,13 @@ export class Primitives extends Renderable {
|
||||||
}
|
}
|
||||||
if (fillStyle) {
|
if (fillStyle) {
|
||||||
const {color} = fillStyle;
|
const {color} = fillStyle;
|
||||||
this.internal.beginFill(color.toInteger(), color.alpha)
|
this.primitives.beginFill(color.toInteger(), color.alpha)
|
||||||
}
|
}
|
||||||
const {color, thickness} = lineStyle;
|
const {color, thickness} = lineStyle;
|
||||||
this.internal.lineStyle(thickness, color.toInteger(), color.alpha)
|
this.primitives.lineStyle(thickness, color.toInteger(), color.alpha)
|
||||||
fn();
|
fn();
|
||||||
if (fillStyle) {
|
if (fillStyle) {
|
||||||
this.internal.endFill();
|
this.primitives.endFill();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,11 @@ export class Sprite extends Renderable {
|
||||||
constructor(image) {
|
constructor(image) {
|
||||||
super();
|
super();
|
||||||
this._image = image;
|
this._image = image;
|
||||||
this.internal = new PIXI.Sprite(image.texture);
|
this.sprite = new PIXI.Sprite(image.texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
get internal() {
|
||||||
|
return this.sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
get image() {
|
get image() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user