How to check if an asset exists

10 views
Skip to first unread message

guille.r...@gmail.com

unread,
Feb 20, 2018, 11:30:06 AM2/20/18
to PlayN
Hi all,

I am writing a "UI theme / UI skin" thing on a PlayN app where there is a "default theme" which defines colors, fonts, icons, etc. and then other themes which can optionally override some of the colors, fonts, or icons.

For this, I am organizing my assets as follows:

assets/fonts
assets/icons
assets/<theme>/fonts
assets/<theme>/icons

When selecting a theme, I need to reload fonts and icons. What I want to achieve is:

- If the theme overrides the font/icon, then the theme-specific version of the asset is loaded
- Otherwise, the generic version of the asset (from the default theme) is loaded.

My problem is that I can't find a way to check if an asset exists, given its path. Methods such as Platform.assets().getImage() will not fail even if the path does not exist. ONe option would be to load everything synchronously but I don't want to do that as this means the app will be less responsive. Ideally I would like to:

1. Use Platform.assets().getImage(), but have it fail immediately (i.e. return null or whatever) if the asset does not exist at the specified path. If the asset exists, then load it asynchronously as it does now
2. Use a separate API to check if an asset exists at a given path, so that I can select the right path before using assets().getImage()

Has anyone faced this problem before? Any suggestions?

Thanks,

Guillermo

Michael Bayne

unread,
Feb 20, 2018, 11:52:52 AM2/20/18
to pl...@googlegroups.com
There's no way to check if an asset exists because on the HTML5 backend, we have no idea whether an asset exists until we issue an HTTP request to load it. It would be possible to issue an HTTP request to find out if an asset exists, but that is insanely expensive and would be a very misleading API.

I would recommend that themes provide a "manifest" file which enumerates all of the assets that the contain, then you can load that as part of the theme loading process and use it to know whether a theme provides a particular resource.

--

---
You received this message because you are subscribed to the Google Groups "PlayN" group.
To unsubscribe from this group and stop receiving emails from it, send an email to playn+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

Guillermo Rodriguez Garcia

unread,
Feb 21, 2018, 6:15:26 AM2/21/18
to pl...@googlegroups.com
Hi Michael,

Thanks for your answer. I would rather avoid doing that as it's yet another step in the build process and thus another thing that can go wrong.

Since I don't really care for HTML5, I think I will implement an API to check if the asset exists for the platforms I am targetting (robovm, Android, and Java for development)

Thanks,

Guillermo

To unsubscribe from this group and stop receiving emails from it, send an email to playn+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--

--

---
You received this message because you are subscribed to a topic in the Google Groups "PlayN" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/playn/LrzPG5ltrWg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to playn+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Guillermo Rodriguez Garcia
guille.r...@gmail.com
Reply all
Reply to author
Forward
0 new messages