CCDirectLink / CCLoader

Modloader for crosscode
35 stars 11 forks source link

Correctly handle asset paths in manifests as being relative to mod's assets directory #90

Closed dmitmel closed 3 years ago

dmitmel commented 3 years ago

For context:

This PR has to do with handling of the assets field in mod manifests (both ccmod.json and package.json). For a long time (before ccmod.json, so only in package.json) it was assumed that the paths listed in this field are relative to the mod's root directory not to the mod's assets directory, so much so that this is how it had been implemented in CCLoader, and that we discussed this point when designing ccmod.json, and that I considered this while implementing CCLoader3 (spoiler: its implementation of package.json not affected by this PR). We have decided to improve this situation in ccmod.json by making the asset paths relative to the assets directory. However, since ccmod.json support was implemented in CCLoader2, I and (to my knowledge) @L-Sherry have discovered that it continues to treat asset paths in ccmod.json as relative to the root directory, thus making browser support tricky. This is due to the fact that the same function (_findAssets) was being used for collecting assets from mods with both ccmod.json and package.json. Which is, of course, a violation of the "specification" (imagine me making the harold face while writing this sentence). HOWEVER, apparently this field has been broken altogether ever since babe5f819bbbfc674d0885ff07f024a193d4a945, and that commit was made almost a year ago at this point. As such we have decided to fix path relativeness by making them relative to the assets directory in BOTH manifest formats, since in package.json it wasn't working in the first place for a while now.

L-Sherry commented 3 years ago

The PR description could need some newlines.

Which is, of course, a violation of the "specification" (imagine me making the harold face while writing this sentence).

If you read this "specification" :unamused: more carefully, then you would have probably also seen that the assets/ directory is actually configurable via the assetsDir option in ccmod.json, something CCLoader2 never implemented, and is thus another difference between v2 and v3 (other than the baseDirectory kerfuffle).

Of course, it would be hard to notice this without an actual documentation, something that, in general, is best written by the person that actually wrote the code. :wink:

This change will break bobrank (as published in ccmoddb) when run in a browser, but I don't really care :woman_shrugging: