Skip to content

Commit

Permalink
Fix CoreNode.checkRenderProps, cleanup constructor (#330)
Browse files Browse the repository at this point in the history
Addressing some of @elsassph comments in #314
  • Loading branch information
frank-weindel authored Jul 8, 2024
2 parents 8e3a736 + 2997fd4 commit f93b891
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
28 changes: 10 additions & 18 deletions src/core/CoreNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ export interface CoreNodeAnimateProps extends NumberProps<CoreNodeProps> {
export class CoreNode extends EventEmitter {
readonly children: CoreNode[] = [];
protected _id: number = getNewId();
readonly props: Required<CoreNodeProps>;
readonly props: CoreNodeProps;

public updateType = UpdateType.All;

Expand Down Expand Up @@ -673,7 +673,6 @@ export class CoreNode extends EventEmitter {
public calcZIndex = 0;
public hasRTTupdates = false;
public parentHasRenderTexture = false;
private _src = '';

constructor(readonly stage: Stage, props: CoreNodeProps) {
super();
Expand All @@ -682,19 +681,14 @@ export class CoreNode extends EventEmitter {
...props,
parent: null,
texture: null,
shader: stage.defShaderCtr,
src: '',
src: null,
rtt: false,
data: props.data || {},
};

// Assign props to instance
this.parent = props.parent;
this.shader = props.shader;
this.texture = props.texture;
this.src = props.src || '';
// FIXME
// this.data = props.data;
this.src = props.src;
this.rtt = props.rtt;

this.updateScaleRotateTransform();
Expand Down Expand Up @@ -1062,7 +1056,7 @@ export class CoreNode extends EventEmitter {
return false;
}

if (this.props.shader === this.stage.defShaderCtr) {
if (this.props.shader !== this.stage.defShaderCtr) {
return true;
}

Expand Down Expand Up @@ -1830,21 +1824,19 @@ export class CoreNode extends EventEmitter {

this.props.shader = value;

if (value === this.stage.defShaderCtr) {
this.setUpdateType(UpdateType.IsRenderable);
}
this.setUpdateType(UpdateType.IsRenderable);
}

get src(): string {
return this._src;
get src(): string | null {
return this.props.src;
}

set src(imageUrl: string) {
if (this._src === imageUrl) {
set src(imageUrl: string | null) {
if (this.props.src === imageUrl) {
return;
}

this._src = imageUrl;
this.props.src = imageUrl;

if (!imageUrl) {
this.texture = null;
Expand Down
2 changes: 1 addition & 1 deletion src/core/Stage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ export class Stage {
shader: props.shader ?? this.defShaderCtr,
// Since setting the `src` will trigger a texture load, we need to set it after
// we set the texture. Otherwise, problems happen.
src: props.src ?? '',
src: props.src ?? null,
scale: props.scale ?? null,
scaleX: props.scaleX ?? props.scale ?? 1,
scaleY: props.scaleY ?? props.scale ?? 1,
Expand Down

0 comments on commit f93b891

Please sign in to comment.