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

Feature: Add alias for loading resource #1786

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

HypnosNova
Copy link
Contributor

resourceManager.getFromCache is very difficult to use. For example

await engine.resourceManager.load([{
    url: "xxx.com/83b812c361e2c2d0bd68626b2b07a58a20fc0839.jpg",
}]);

xxxMaterial.texture = engine.resourceManager.getFromCache("xxx.com/83b812c361e2c2d0bd68626b2b07a58a20fc0839.jpg");

Sometimes a resource url is a hash string and we don't know what is it util we check the resource by url. We can't know what is it when writing code. And another much worse situation is loading a spine, it has 3 urls and we must join the url array. The code would be very ugly.

If we give LoadItem a name, we can just get cache by their name, for example:

await engine.resourceManager.load([{
    urls: [
        "xxx.com/83b812c361e2c2d0bd68626b2b07a58a20fc0839.jpg",
        "xxx.com/83b812c361e2c2d0bd68626b2b07a58a20fc0839.atlas",
        "xxx.com/83b812c361e2c2d0bd68626b2b07a58a20fc0839.json",
    ],
    type: "spine",
    name: "boy"
}]);


const spine1 = engine.resourceManager.getFromCache('boy'); // it would be very easy to know what we get
// and the up code is the same as
const spine2 = engine.resourceManager.getFromCache([
    "xxx.com/83b812c361e2c2d0bd68626b2b07a58a20fc0839.jpg",
    "xxx.com/83b812c361e2c2d0bd68626b2b07a58a20fc0839.atlas",
    "xxx.com/83b812c361e2c2d0bd68626b2b07a58a20fc0839.json",
].join(','));

spine1 === spine2; // true

@codecov
Copy link

codecov bot commented Sep 21, 2023

Codecov Report

Patch coverage: 58.82% and project coverage change: +0.01% 🎉

Comparison is base (b499f94) 65.10% compared to head (2502283) 65.11%.
Report is 7 commits behind head on main.

❗ Current head 2502283 differs from pull request most recent head f4fd985. Consider uploading reports for the commit f4fd985 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1786      +/-   ##
==========================================
+ Coverage   65.10%   65.11%   +0.01%     
==========================================
  Files         473      473              
  Lines       23641    23654      +13     
  Branches     3362     3366       +4     
==========================================
+ Hits        15392    15403      +11     
  Misses       7045     7045              
- Partials     1204     1206       +2     
Files Changed Coverage Δ
packages/core/src/particle/ParticleGenerator.ts 4.53% <ø> (ø)
...re/src/particle/modules/ParticleGeneratorModule.ts 25.00% <ø> (ø)
packages/core/src/asset/ResourceManager.ts 57.07% <40.90%> (-3.02%) ⬇️
packages/core/src/Background.ts 77.63% <88.88%> (+25.00%) ⬆️
packages/core/src/input/pointer/PointerManager.ts 92.34% <100.00%> (ø)
packages/loader/src/ProjectLoader.ts 30.00% <100.00%> (ø)

... and 3 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@HypnosNova HypnosNova changed the base branch from main to dev/1.2 November 28, 2023 12:41
@GuoLei1990 GuoLei1990 changed the base branch from dev/1.2 to main March 11, 2024 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants