Skip to content

Commit

Permalink
Refactor progress reset
Browse files Browse the repository at this point in the history
  • Loading branch information
GarboMuffin committed Jan 3, 2024
1 parent b02dfa1 commit ea4e613
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/engine/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -2275,9 +2275,7 @@ class Runtime extends EventEmitter {
this.addCloudVariable = this._initializeAddCloudVariable(newCloudDataManager);
this.removeCloudVariable = this._initializeRemoveCloudVariable(newCloudDataManager);

this.totalAssetRequests = 0;
this.finishedAssetRequests = 0;
this.emitAssetProgress();
this.resetProgress();
}

/**
Expand Down Expand Up @@ -3420,6 +3418,12 @@ class Runtime extends EventEmitter {
this.emit(Runtime.ASSET_PROGRESS, this.finishedAssetRequests, this.totalAssetRequests);
}

resetProgress () {
this.finishedAssetRequests = 0;
this.totalAssetRequests = 0;
this.emitAssetProgress();
}

/**
* Wrap an asset loading promise with progress support.
* @template T
Expand Down
14 changes: 12 additions & 2 deletions test/integration/tw_asset_progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ test('emitAssetProgress', t => {
t.end();
});

test('dispose', t => {
test('resetProgress', t => {
t.plan(4);

const runtime = new Runtime();
Expand All @@ -43,13 +43,23 @@ test('dispose', t => {
t.equal(total, 0, 'event total');
});

runtime.dispose();
runtime.resetProgress();

t.equal(runtime.finishedAssetRequests, 0, 'property finishedAssetRequests');
t.equal(runtime.totalAssetRequests, 0, 'property totalAssetRequests');
t.end();
});

test('dispose', t => {
t.plan(1);
const runtime = new Runtime();
runtime.resetProgress = () => {
t.pass();
};
runtime.dispose();
t.end();
});

test('wrapAssetRequest', t => {
const runtime = new Runtime();

Expand Down

0 comments on commit ea4e613

Please sign in to comment.