forked from galacean/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix component denpendency bug (galacean#1427)
* fix: component dependencies bug * test: add component dependencies unit test
- Loading branch information
1 parent
5dc198f
commit 74df8aa
Showing
2 changed files
with
58 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Camera, dependentComponents, DependentMode, Entity, MeshRenderer, Script } from "@oasis-engine/core"; | ||
import { WebGLEngine } from "@oasis-engine/rhi-webgl"; | ||
import { expect } from "chai"; | ||
|
||
const canvasDOM = document.createElement("canvas"); | ||
canvasDOM.width = 1024; | ||
canvasDOM.height = 1024; | ||
|
||
describe("Component dependencies test", function () { | ||
let entity: Entity; | ||
let camera: Camera; | ||
before(() => { | ||
const engine = new WebGLEngine(canvasDOM); | ||
entity = engine.sceneManager.activeScene.createRootEntity(); | ||
camera = entity.addComponent(Camera); | ||
}); | ||
|
||
it("Super dependencies add check", () => { | ||
expect(() => { | ||
entity.addComponent(CustomScriptB); | ||
}).throw("Should add MeshRenderer before adding CustomScriptA"); | ||
}); | ||
|
||
it("Super dependencies remove check", () => { | ||
expect(() => { | ||
const meshRenderer = entity.addComponent(MeshRenderer); | ||
entity.addComponent(CustomScriptB); | ||
meshRenderer.destroy(); | ||
}).throw("Should remove CustomScriptA before adding MeshRenderer"); | ||
}); | ||
}); | ||
|
||
@dependentComponents(DependentMode.CheckOnly, MeshRenderer) | ||
export class CustomScriptA extends Script {} | ||
|
||
export class CustomScriptB extends CustomScriptA {} |