Assets #2414
Replies: 4 comments 4 replies
-
Very valid points/concerns. The keys are indeed annoying overall, as they're forced afaik, instead of being purely optional. |
Beta Was this translation helpful? Give feedback.
-
Related: I don't currently see any Webpack-specific code in the game's modules.
Any ideas? I ask because Webpack has its own This is basically what E.g., putting this in
|
Beta Was this translation helpful? Give feedback.
-
No prob. It's pretty common just to poke at build configs until things work and not ask too many questions. I don't mean to suggest someone didn't know what they were doing when I ask about why a decision was made. I just want to know if I'm about to step into something: Sometimes there's knowledge out there – "We did this non-obvious thing because the obvious thing had these problems for this project ..." But sometimes things are the way they are just because they were good enough. And that's great, because it means we can go ahead and make them better. |
Beta Was this translation helpful? Give feedback.
-
This is mostly finished with the last PR I opened. One thing I haven't done is streamline loading of assets into Phaser. I'd like to do that as it took me a lot longer than necessary just to put a simple image on screen in Phaser:
Especially in
Ideally, we wouldn't need to write that out at all. If we just decide on an organization, the new Proposal
Blue sky proposalRegardless of path, all assets should simply be accessible by filename minus their extension. E.g.,
But ...
... will not be allowed because both of their keys are Right now, to get the |
Beta Was this translation helpful? Give feedback.
-
Assets are currently loaded in a sort of roundabout way.
assetLister.js
Runs at compile time, outputting
src/assets.js
: a JS object containing a representation of the directory structure and files of/assets
.assetLoader.js
loads
assets.js
at run time and exposes their paths viagetURL(str)
. ButgetURL(str)
doesn't take the asset path fromsrc/assets.js
. Instead, it wants that path, minusassets/
and minus the file extension.Phaser.load.image
Phaser needs to know about images at run time. This largely repeats
src/assets.js
. But usinggetURL
urls fromassetLoader
, e.g.,this.Phaser.load.image('input', getUrl('interface/hex_input'));
.What's more,
Phaser.load.image
needs a key as a first argument, but the provided key is often different than the name of the image.E.g., Load like this:
this.Phaser.load.image('input', getUrl('interface/hex_input'));
Use it like this:
this.display.loadTexture('input');
So a dev who's looking at the second line in code somewhere needs to figure out that the image is actually called
hex_input
. They can search, of course. But if the key is a common string in the codebase, as it is here, it's difficult to find the actual image name.Each step adds a little extra complexity. Data is duplicated.
Proposal
Delete
assetLister.js
andassetLoader.js
andassets.js
Most of the image assets are already written down in
src/game.ts
. In some cases, it appears they just need to be written out explicitly in order to be picked up by Webpack and bundled.Split HTML / Phaser images?
Doing this would allow us to load all the Phaser assets into Phaser without needing to write them down, assuming we changed the filenames to keys.
E.g., if the Phaser key is supposed to be 'input', the image should be called 'input.png', not 'hex_input.png'.
Just some ideas. Any thoughts?
Beta Was this translation helpful? Give feedback.
All reactions