tophat2d / tophat

:tophat: a 2d game library for Umka
https://tophat2d.dev
BSD 3-Clause "New" or "Revised" License
72 stars 5 forks source link

mrms: Better path prefixes #129

Closed marekmaskarinec closed 2 months ago

marekmaskarinec commented 8 months ago

Original issue:

~mrms/tophat#39

Initial message:

Currently, paths work in the following way (which isn't documented anywhere):

Normally tophat will prepend the respath to the path. respath is empty by default, but can be modified using the -dir flag. If the user uses the raw:// prefix in the path, tophat will not modify the path.

Proposed solution:

  1. remove the respath logic altogether
  2. make the raw:// behavior default (raw:// will stay as an option for people who want to be explicit)
  3. Add the following prefixes:
    • res:// will evaluate to the resource directory of the game. By default that is the folder the main file is in
      • data:// will use a platform-dependent data storage path (%appdata%,~/.local/share`).

ske

I support this

mrms

I think the most explicit thing we can do is only allowing the user to use the data:// directory when they specify the name of the project in the flags. At some point, we might eventually need a project specification file.

Generally, I want to avoid the use of flags.

We can make user be able to make their own protocols, by doing something like th.bind("data", th.appdata("project name")) this is a more versatile solution though less declarative.

I don't think there will be that much use for this. If there is some protocol we find useful, it can always be part of tophat.


For now I'm going to go with the main.um's directory name, if that's ok with you.

ske

ske

Accidentally clicked resolve, my bad.

mrms

An interesting question arises: what folder should be used for the data:// prefix? More exactly, what comes after <platform_specific>/tophat/? All the games can't just share the same directory. There are various solutions I propose:

  1. Specify the game's name using an API function. th.setName("my_awesome_game")
  2. Guess it from something like the main.um's directory name
  3. Make some metadata file next to the main.um, this would open up many other possibilities.

What do you think ~ske?

I think the most explicit thing we can do is only allowing the user to use the data:// directory when they specify the name of the project in the flags. At some point, we might eventually need a project specification file.

Or maybe, find another solution.

We can make user be able to make their own protocols, by doing something like th.bind("data", th.appdata("project name")) this is a more versatile solution though less declarative.

Or hell, something even more generic, having the bind function execute a signal/callback which can allow for absolutely custom operations, like fetching something from the internet.

What are your thoughts?

ske

Totally ok!

mrms

I've implemented the behaviour (it's in the path-prefix branch). Please test if it works correctly on windows.

skejeton commented 8 months ago

Will test tomorrow.