Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix unit and case test problems #26

Merged
merged 8 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions web-packages/test/case/2d/src/common/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,41 +56,40 @@ export class TestPlayer {
}

Math.seedrandom('mars-runtime');
if (!this.player.oldVersion) {
if (this.oldVersion) {
this.scene = await this.player.loadSceneAsync(url, { ...loadOptions, timeout: 100 });
Math.seedrandom('mars-runtime');
this.composition = await this.player.play(this.scene, playerOptions ?? { pauseOnFirstFrame: true });
} else {
getDefaultTemplateCanvasPool().dispose();
const assetManager = new AssetManager();
const assetManager = new AssetManager({ ...loadOptions, timeout: 100, autoplay: false });
const json = await assetManager.loadScene(url);

compatibleCalculateItem(json.jsonScene.compositions[0]);

this.player.destroyCurrentCompositions();
Math.seedrandom('mars-runtime');
this.composition = this.scene = await this.player.loadScene(json, { ...loadOptions, timeout: 100, autoplay: false });
this.player.gotoAndStop(0);
} else {
// 旧版Mars调用
this.scene = await this.player.loadSceneAsync(url, { ...loadOptions, timeout: 100 });
Math.seedrandom('mars-runtime');
this.composition = await this.player.play(this.scene, playerOptions ?? { pauseOnFirstFrame: true });
this.player.gotoAndStop(0);
}
}

gotoTime (time) {
gotoTime (newtime) {

let time = newtime;

// 兼容旧 Player 设置结束行为为重播时在第duration秒会回到第0帧
if (this.composition.content.endBehavior === 5 && newtime === this.composition.content.duration) {
time -= 0.01;
}
const deltaTime = time - this.lastTime;

this.lastTime = time;
//
this.lastTime = newtime;
Math.seedrandom(`mars-runtime${time}`);
if (this.player.gotoAndStop) {
this.player.gotoAndStop(time);
const comp = this.player.getCompositions()[0];

if (comp.time === comp.duration && comp.content.endBehavior === 5) {
this.player.gotoAndStop(0);
}
} else {
this.composition.forwardTime(deltaTime);
this.player.tick(0);
this.player.doTick(0, true);
}
}

Expand Down Expand Up @@ -122,7 +121,7 @@ export class TestPlayer {
}

duration () {
return this.composition.compositionSourceManager.totalTime;
return this.composition.content.duration;
}

isLoop () {
Expand Down
10 changes: 5 additions & 5 deletions web-packages/test/case/2d/src/inspire/inspire.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ async function checkScene (keyName, name, url) {
console.info(`[Compare]: Begin ${name}, ${url}`);
const { oldPlayer, newPlayer, renderFramework } = controller;

runtimePlayer.player.compositions.length = 0;
newPlayer.player.compositions.length = 0;
await oldPlayer.initialize(url);
await newPlayer.initialize(url);
const imageCmp = new ImageComparator(pixelDiffThreshold);
const namePrefix = getCurrnetTimeStr();
const timeList = [
0, 0.11, 0.22, 0.34, 0.45, 0.57, 0.65, 0.71, 0.83, 0.96, 1.0,
1.1, 1.2, 1.3, 1.4, 1.5, 1.7, 1.9, 2.0, 2.2, 2.5, 2.7, 3.0, 3.3, 3.8,
4.1, 4.7, 5.2, 5.9, 6.8, 7.5, 8.6, 9.7, 9.99, 11.23, 12.5, 15.8, 18.9,
0, 0.11, 0.22, 0.34, 0.45, 0.57, 0.71, 0.83, 0.96,
1.1, 1.2, 1.4, 1.7, 1.9, 2.2, 2.5, 2.7, 3.3, 3.8,
4.7, 5.2, 6.8, 7.5, 8.6, 9.7, 9.99, 12.5, 18.9,
];
let maxDiffValue = 0;

Expand Down Expand Up @@ -130,6 +130,6 @@ async function checkScene (keyName, name, url) {
);

console.info(`[Compare]: End ${name}, ${url}`);
runtimePlayer.disposeScene();
newPlayer.disposeScene();
});
}
3 changes: 2 additions & 1 deletion web-packages/test/case/spine/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ async function checkScene (keyName, name, url) {
await newPlayer.initialize(url);
const imageCmp = new ImageComparator(pixelDiffThreshold);
const namePrefix = getCurrnetTimeStr();
const duration = oldPlayer.composition.duration;
const duration = oldPlayer.duration();

const timeList = [
0, 0.045, 0.11, 0.13, 0.17, 0.22, 0.28, 0.3, 0.34, 0.38,
0.41, 0.45, 0.51, 0.57, 0.63, 0.65, 0.69, 0.74, 0.77,
Expand Down
8 changes: 4 additions & 4 deletions web-packages/test/case/spine/src/scene-list.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export default {
spring: {
name: '找春天',
url: 'https://mdn.alipayobjects.com/mars/afts/file/A*DKH6SIWKIt4AAAAAAAAAAAAADlB4AQ',
},
// spring: {
// name: '找春天',
// url: 'https://mdn.alipayobjects.com/mars/afts/file/A*DKH6SIWKIt4AAAAAAAAAAAAADlB4AQ',
// },
tiger: {
name: '818理财',
url: 'https://mdn.alipayobjects.com/mars/afts/file/A*JaLiQYyUqhoAAAAAAAAAAAAADlB4AQ',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ describe('combine sprite meshes according to items', () => {

// 粒子元素不参与合并
it('[getMeshSplits] combine composition items ignore invisible items and other type', async () => {
player = new Player({
canvas: document.createElement('canvas'),
manualRender: true,
});

const comp = await player.loadScene(generateSceneByOpts([
{}, { delay: 1 }, {},
{ blending: 1, delay: 1 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ describe('sprite transform', () => {

const position = item.transform.getWorldPosition().toArray();
const rotation = item.transform.getWorldRotation().toArray();
const scale = item.transform.getWorldScale().toArray();
const scale = item.content.basicTransform.scale;

expect(position).to.deep.equals([0, 1, 0], 'position');
expect(rotation[0]).to.eql(0);
expect(rotation[1]).to.eql(90);
expect(rotation[2] === 0).to.be.true;
expect(item.content.startSize[0]).to.be.closeTo(0.15, 0.0001);
expect(item.content.startSize[1]).to.be.closeTo(0.15, 0.0001);
expect(scale.x).to.be.closeTo(0.15, 0.0001);
expect(scale.y).to.be.closeTo(0.15, 0.0001);
const spriteGroup = comp.loaderData.spriteGroup;
const mesh = spriteGroup.meshes[0];
const data = mesh.material.getMatrixArray('uMainData');
Expand Down
Loading