Open Xananax opened 2 years ago
Suggestions by @Razoric480:
load_resource()
(smart!)Details: https://github.com/GDQuest/learn-gdscript/pull/688#issuecomment-1267241917
I'll continue the conversation here:
I'm not too concerned about how to load the files on web, my main concern is how to do it in a way that is consistent across platforms without too much divergent code or branches.
I think the simplest and most restrained version that isn't future blocking is:
preload()
. For example, load gdquest.github.com/lang.cn.pck
if the URL contains &lang=en
(also sets internal language, on load, from the URL). Uses the browser's natural caching mechanisms for deciding whether to load a new version or not.Three possible ways of handling additional resources on web:
user://
, more likely than res://
). Parallel to those two mechanisms, on a Desktop app, that'd mean:
user://
<user dir>
at the right locationI'm going to discuss the pros and cons of those implementations below. Bear in mind we don't have to bear the full weight of the cons as of right now (or the full benefits of the pros) but if the intent is to support multiple languages and localization (not just translation), which might entail more than just a font file, then these are still considerations for the long term.
Pros:
Cons:
note: We might need custom handling of changed assets if they affect loaded scenes (At worst, we can ask people to reset the entire app).
Pros:
Cons:
preload()
behavior with the right URLsHere are some mitigations for con 2, based on easiest to do to hardest:
In both cases, we need to build a caching and versioning logic to check for presence of a package, invalidate it (if an update is out), and tell the user.
(note that we could load the font also on Desktop, it just doesn't make a lot of sense)
Pros:
Cons:
However it seems in principle, exporting with/ without assets seems doable through filtering. We only have to ensure the assets are always conditionally loaded
I'll have to re-read the above to really get it, but at least to me, we could have a desktop export with all fonts included. My concern's mostly the html5 one, that it's relatively quick to launch (on slow ADSL each 5mb font would add 5+s of initial loading of the page for everyone).
Some good insights on generating PCK files here: https://twitter.com/Lauson1ex/status/1577455482410631168
This person uses system fonts, that could be an option too if the browser gives us access to that? That would save the need for downloading any fonts at least.
I'm currently working on an app heavily focused on user generated content, and the best way I found to do it was through loading exported PCK projects. I don't know how well it works for Web platforms, but here are a few tips I've gathered when working with them:
master
, and backported it for 3.x
in a custom engine fork.master
and cherry-picked for 3.6, but I think this doesn't entirely get rid of all issues (for example, you still need to setup a platform to be able to set resource export filters and/or feature tags). I'm looking into opening a proposal for improving this behavior in the near future (if there isn't any yet)godot --export-pack "Export Name" exported_project.pck
, and it can easily be integrated in CI workflows. This was something I was worrying during development, but thankfully it's been smooth so far (you still need an export template installed, but this requirement should disappear in the near future, see above point).Hope these help you in development :slightly_smiling_face:
Thanks much for the insights,they're most appreciated! It sounds a little cumbersome for our needs then. Someone mentioned that we can just zip the resources and download and load them at runtime like a PCK file.
If it's this simple it's something to consider as all we need is downloading fonts.
Wether zip or pck doesn't really change much.
The principle is the same for whatever format we want to use. Either we load:
a) at runtime, which implies a UI, error reporting (to the user), integrity check, invalidation b) before loading the game, which requires loading assets in JS following some logic, and custom builds for Desktop and Web, respectively with and without the assets
In both cases we need the assets packaged and stored somewhere on a canonical URL
(also, I don't think you can unzip in Godot natively)
(also, I don't think you can https://github.com/godotengine/godot/pull/34444)
Godot can, pck are zip files as far as I know, but you don't have an API to do more with zips. Just something like load_resource().
integrity check, invalidation
Can't we rely on Godot's load() to error out and return null?
I'm leaning towards a) right now because of the ability to keep as possible the app's logic in gdscript, and I feel it's straightforward, but what do you think?
Tentative plan:
learn-gdscript-translations
to contain a fonthttps://GDQuest.github.io/learn-gdscript-translations/<file>.pck
. Export also a json file listing them all, and each language's coverageFor 5
, some research is required regarding how Godot handles translations. Can we load translations at runtime, or do we need to process them somehow?
https://github.com/godotengine/godot/pull/65281 is merged (Expose minizip API to allow creating zips using scripts).
Related to #688
Translations and fonts add weight to the package.
For this reason, mainly, we want to split the additional assets that will not serve everyone in a different bundle.
There's a recommended method, but it isn't clear how to manage this.
Requirements:
These are all completely unanswered questions.
Before answering them, however, there is the question of packaging and distributing packages in a cross-platform way.
Therefore, here's the plan
Answers to automation can be found along the way or later (but this issue should not be closed before they are, or another issue is opened)
Note: if loading packages on Web and Desktop is sufficiently divergent, it might be easier to build a version with all packages for Desktop, and use a specific mechanism on the web. This would be also considered a valid resolution, provided the build system doesn't get overly complex as a result.