Skip to content

Commit

Permalink
Fix cclegacy in node.jsb.ts and fix _onPostActivated.
Browse files Browse the repository at this point in the history
  • Loading branch information
dumganhar committed Dec 17, 2024
1 parent d0057ba commit a503fb8
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions cocos/scene-graph/node.jsb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/

import { EDITOR, EDITOR_NOT_IN_PREVIEW } from 'internal:constants';
import { legacyCC } from '../core/global-exports';
import { cclegacy } from '../core/global-exports';
import { errorID, getError } from '../core/platform/debug';
import { Component } from './component';
import { NodeEventType } from './node-event';
Expand All @@ -43,10 +43,11 @@ import { DispatcherEventType, NodeEventProcessor } from './node-event-processor'
const reserveContentsForAllSyncablePrefabTag = Symbol('ReserveContentsForAllSyncablePrefab');

declare const jsb: any;
declare const EditorExtends: any;

export const Node: typeof JsbNode = jsb.Node;
export type Node = JsbNode;
legacyCC.Node = Node;
cclegacy.Node = Node;

const NodeCls: any = Node;

Expand Down Expand Up @@ -82,6 +83,7 @@ const TRANSFORMBIT_TRS = TransformBit.TRS;

const nodeProto: any = jsb.Node.prototype;
export const TRANSFORM_ON = 1 << 0;
const ACTIVE_ON = 1 << 1;
const Destroying = CCObject.Flags.Destroying;

// TODO: `_setTempFloatArray` is only implemented on Native platforms. @dumganhar
Expand Down Expand Up @@ -163,7 +165,7 @@ nodeProto.addComponent = function (typeOrClassName) {
if (typeof typeOrClassName === 'string') {
constructor = getClassByName(typeOrClassName);
if (!constructor) {
if (legacyCC._RF.peek()) {
if (cclegacy._RF.peek()) {
errorID(3808, typeOrClassName);
}
throw TypeError(getError(3807, typeOrClassName));
Expand Down Expand Up @@ -222,7 +224,7 @@ nodeProto.addComponent = function (typeOrClassName) {
}
this.emit(NodeEventType.COMPONENT_ADDED, component);
if (this._activeInHierarchy) {
legacyCC.director._nodeActivator.activateComp(component);
cclegacy.director._nodeActivator.activateComp(component);
}
if (EDITOR_NOT_IN_PREVIEW) {
component.resetInEditor?.();
Expand Down Expand Up @@ -420,7 +422,7 @@ nodeProto._onEditorAttached = function (attached: boolean) {
};

nodeProto._onRemovePersistRootNode = function () {
legacyCC.game.removePersistRootNode(this);
cclegacy.game.removePersistRootNode(this);
};

nodeProto._onDestroyComponents = function () {
Expand Down Expand Up @@ -497,10 +499,14 @@ nodeProto._onSiblingOrderChanged = function () {
};

nodeProto._onActivateNode = function (shouldActiveNow) {
legacyCC.director._nodeActivator.activateNode(this, shouldActiveNow);
cclegacy.director._nodeActivator.activateNode(this, shouldActiveNow);
};

nodeProto._onPostActivated = function (active: boolean) {
if (this._eventMask & ACTIVE_ON) {
this.emit(NodeEventType.ACTIVE_CHANGED, this, active);
}

const eventProcessor = this._eventProcessor;
if (eventProcessor.isEnabled === active) {
NodeEventProcessor.callbacksInvoker.emit(DispatcherEventType.MARK_LIST_DIRTY);
Expand Down Expand Up @@ -605,7 +611,7 @@ NodeCls._findChildComponents = function (children, constructor, components) {
// @ts-ignore
NodeCls.isNode = function (obj: unknown): obj is jsb.Node {
// @ts-ignore
return obj instanceof jsb.Node && (obj.constructor === jsb.Node || !(obj instanceof legacyCC.Scene));
return obj instanceof jsb.Node && (obj.constructor === jsb.Node || !(obj instanceof cclegacy.Scene));
};

let _tempQuat = new Quat();
Expand Down Expand Up @@ -1266,7 +1272,7 @@ nodeProto[serializeTag] = function (serializationOutput: SerializationOutput, co
};

nodeProto._onActiveNode = function (shouldActiveNow: boolean) {
legacyCC.director._nodeActivator.activateNode(this, shouldActiveNow);
cclegacy.director._nodeActivator.activateNode(this, shouldActiveNow);
};

nodeProto._onBatchCreated = function (dontSyncChildPrefab: boolean) {
Expand Down Expand Up @@ -1330,7 +1336,7 @@ nodeProto._onLocalPositionRotationScaleUpdated = function (px, py, pz, rx, ry, r

nodeProto._instantiate = function (cloned: Node, isSyncedNode: boolean) {
if (!cloned) {
cloned = legacyCC.instantiate._clone(this, this);
cloned = cclegacy.instantiate._clone(this, this);
}

// TODO(PP_Pro): after we support editorOnly tag, we could remove this any type assertion.
Expand Down

0 comments on commit a503fb8

Please sign in to comment.