curiousdannii / parchment

The Interactive Fiction web app
https://iplayif.com
MIT License
421 stars 60 forks source link

More accurate file format detection #73

Closed juhana closed 3 years ago

juhana commented 3 years ago

Checking that the file extension exists anywhere in the filename will easily lead to choosing the wrong format, especially .gam (game.z8 is categorized as a TADS file.) Added . in front of all extensions and changed the I7 template to check the end of the file as Inform generates always the same extensions.

curiousdannii commented 3 years ago

Oops, I should've thought of that. Is there any reason not to also anchor the tests in formats.js too?

juhana commented 3 years ago

I was thinking you could have a URL that doesn't end in a file extension like example.com/game.z8?version=2 or something similar so you'd need to add at least & and ? to the end. Optimally there would be a setting to override the automatic detection e.g. if you have a URL that doesn't have a file ending (I need to do default_story: [ "data:text/javascript,processBase64Zcode('" + data + "'); // .ulx .js" ] to make it detect Glulx and use the correct loader)

curiousdannii commented 3 years ago

Ahh, yeah that makes sense.

Do you need to use a data URL, or if you could simply pass a typed array to a launcher function would that be okay? I'd have thought data URLs are a last resort option, so happy to work out something else.

juhana commented 3 years ago

Yeah, if I could just pass in a typed array that would work best for me.

curiousdannii commented 3 years ago

I saw in the snippets that you're doing this:

borogove.loader( function( data ) {
  const extension = ( window.location.search.indexOf( "vm=quixe" ) > -1 ) ? "ulx" : "z8";
   
  window.parchment_options = {
  default_story: [ `data:text/javascript,processBase64Zcode('${data}'); // ${extension} .js` ],
  lib_path: 'https://assets.borogove.app/interpreters/parchment/2/',
  lock_options: 0,
  lock_story: 0
  };
  //            <script src="main.js" type="module"></s cript>
   
  $.getScript( "https://assets.borogove.app/interpreters/parchment/2/main.js" );
});

Which is quite hacky.

So I'm thinking of the follow changes:

Does that sound like it would meet your needs?

juhana commented 3 years ago

That would indeed sound like the best solution, and that's close to how Quixe works (different launchers for different data inputs.)