AssetLoader shortcut
Home › Forums › AssetLoader › Feature Requests › AssetLoader shortcut
This topic has 3 voices, contains 6 replies, and was last updated by Matan Uberstein 302 days ago.
| Author | Posts |
|---|---|
| Author | Posts |
| May 17, 2011 at 11:36 am #713 Quote | |
|
soundstep |
<p>Hi there,</p>
<p>Me again.</p> <p>Would it be nice to have some shortcuts when we deal group and config?</p> <p>See this from a complete handler:</p> <p> Code:
IAssetLoader(signal.loader)<br />
.getAssetLoader("group0")<br /> .getAssetLoader("group00")<br /> .getAsset("img0"); </p> Code:
IAssetLoader(signal.loader).getAsset("img0");
</p> Code:
IAssetLoader(signal.loader)<br />
.getAssetByGroupPath("group0/group00/img0"); </p> |
| May 19, 2011 at 12:49 pm #792 | |
|
soundstep |
I implemented a wrapper so now I can do stuff like: [Inject(name="group0/group00/img1")] or assets.getAsset(“group1/swf0″); It seems to work well, I might make the delimiter dynamic though. Romu |
| May 31, 2011 at 4:21 pm #799 | |
|
Matan Uberstein |
Good idea, but be very careful with that. I know that most robotlegs developers don’t use the “name” injection because it’s to concrete and currently there isn’t an IDE that can refactor/keep track of that. I personally agree with not using it, although I must admit to using it before, but this is in very small one-time injections. These will mainly be for services that requires more than one String injections. e.g. Woooo, got carried away there! I like the idea of having “shortcuts”, will indeed look into it! |
| July 20, 2011 at 12:29 pm #827 | |
|
|
no need to inject a custom asset loader. a function like findAsset would be nice: public function findAsset(assetId : String, assetLoader : IAssetLoader) : * if (assetLoader.hasAsset(assetId)) } // endIf return null; |
| July 20, 2011 at 12:52 pm #828 | |
|
Matan Uberstein |
Hi Marc, That has sprung to mind before, the only reason why it’s not part of AssetLoader is because it might yield confusing results. E.g. Let’s take an AssetLoader instance with 2 child groups. Each child group can contain assets with “same” id as one of it’s counter parts. group1->asset1 If you then invoke a “find” on your primary AssetLoader for “asset1″ – what should on return? One could return an Array containing all the matched ILoaders, but this would turn out to be a very expensive operation for big complex loading queues, because you have loop through everything with each “find” call. The second problem with returning an Array would be that you’ll need to check the Array each time manually to make sure that you get the ILoader you are looking for. So with our example from above, you receive [asset1, asset1] as ILoaders. Then you’ll need to check which one is the one you want. The only way is then loop through the array and the check the parents until you find it. The most inexpensive operation would be to return on the first match, but then this “find” function essentially becomes unreliable. Maybe I’m missing something, please enlighten me. Thanks for posting! |
| July 21, 2011 at 7:09 am #829 | |
|
|
yes in this case you’ll get the first asset with the correct id. it is the responsibility of the developer to manage the asset ids. i usually use unique ids or pass a specific assetloader/group with only one possible match. best, |
| July 21, 2011 at 7:24 am #830 | |
|
Matan Uberstein |
Agreed, developers should look after their ids. We might need to look into packaging a new util for AssetLoader. It should include “lookup” functions and functions like this: clearing loaded ids Then we can add these nice little extra functions without bloating the api. Thanks! |
You must be logged in to reply to this topic.







