msokalski / ascii-patrol

Ascii Patrol is an ASCII game project. It was mainly inspired by "Moon Patrol", my favourite arcade game at the times I was a child.
GNU General Public License v3.0
220 stars 20 forks source link

Allow editing of paths using environment variable #15

Closed keianrao closed 4 years ago

keianrao commented 4 years ago

Hi,

This pull request is more of a suggestion and/or discussion thing, rather than an actual pull request.

In the attached commits are code I've written for myself to have ASCII Patrol's config, high score record, etc. saved to a directory of my choice, rather than my home directory. They're UNIX-specific (viz. I only edited spec_nix.cpp).

I personally would really like if there was an official way to do this..! It's like one thorn in an otherwise perfect game.

keianrao commented 4 years ago

The way I'm using it right now - as part of a GUI launch script

#!/bin/sh

export ASCII_PATROL_CONFIG_PATH="$HOME/.config/asciipat"
export ASCII_PATROL_RECORD_PATH="$ASCII_PATROL_CONFIG_PATH"
export ASCII_PATROL_SHOT_PATH="$ASCII_PATROL_CONFIG_PATH"

konsole \
    --profile "Gaming" \
    --hide-tabbar --hide-menubar \
    -e "sh -c '/usr/local/bin/asciipat-dir/asciipat "$@"'"
msokalski commented 4 years ago

Hey, thanks for adding config vars! I like it, could you please add some usage help to README.md? I'd be happy to pull it then :)

clort81 commented 4 years ago

Nothing wrong with configurable save and config, but it's standard practice to put them in ~/.whatever or ~/.config/whatever.

If users want the files stored elsewhere, a symlink can be created with "ln -s" command.

keianrao commented 4 years ago

Hello everyone,

I sincerely apologise for the late reply. I had to think things through a bit as well... But I still prefer that @msokalski decide what is best, as it's their game..

"XDG"?

~/.config/ is actually the default directory for 'XDG_CONFIG_HOME' in the XDG Base Directory Specification. It sounds super bureaucratic but a lot of Linux applications follow it, including games. If ASCII Patrol tags along, then while asciipat.cfg definitely should go in $XDG_CONFIG_HOME/asciipat/asciipat.cfg, I think asciipat.rec and the shot files should go in $XDG_DATA_HOME/asciipat/asciipat.rec, etc. instead.

Above are two more commits following this behaviour (with really wacky code).

Optional?

Following those directories should be optional - XDG_CONFIG_HOME and XDG_DATA_HOME are not set by default for the user, so without explicitly setting them, the game should continue to do things as it currently does. But there is a chance that their operating system sets it for them, which doesn't exist if we use custom variables. So maybe custom variables would be better after all.

Edit to README.md?

I'm really slow but I'm working on it now, for both using the XDG environment variables and using custom ones.

This pull request has 4 commits which is a lot - so I think I'm going to close this pull request, create two new branches that changes the code cleanly in one commit, and then make a pull request for whichever msokalski wants.

Thank you for your patience with me so far.

keianrao commented 4 years ago

Hello again,

For the XDG case, I have to make a directory 'asciipat' using mkdir(2), but I have no idea where and how to put this. So I think I will close this pull request after all, and redo the custom environment variable path.