Dear devs,
I just posted a new branch, bugfix/datadir, that finally tackles the fragile definition of the data dir in a robust and path independent way. Now all code will correctly find it, without any need of string manipulation, trailing "/" assumptions or other weird hacks (remember g.fix_data_dir() ?).
For the curious, the trick is code/g.py's __file__ builtin. g is always loaded as a module, so we can rely on this var to properly find ../data no matter where current dir is.
"Ok, great, kudos for you ML, but so what? Not worth a new topic.."
Sure, this is no big deal by itself. But let's think about the consequences and the world of new possibilities it allows:
- /All/ code that read files uses data_loc (now data_dir), directly or indirectly. That goes for music, fonts, sounds, translations, data files. /everything/ is tied to the data dir.
- That was, until now, the very reason why ./Endgame_Linux launcher existed: solely to change current dir to game dir so paths would work.
- Being g.data_dir now an absolute, properly handled path, independent from current dir, /linux launcher is not needed anymore/. Game can be started from /anywhere/ with "python /path/to/es/singularity.py" :)
- This probably means setup.py will now work for Linux! I didn't test this, but since the "must be in game dir" restriction is lifted, there is no reason for it not to work.
Phil once told me, "be bold". So, how about these future steps:
- Delete Endgame_Linux (and singularity shell script).
- Add a "#!/usr/bin/env python" shebang to singularity.py, and chmod +x it. BAM, new executable, E:S can now run from anywhere!
- Why is ./singularity.py a 1-liner that only imports ./code/singularity.py? Heck, copy all of its code to ./singularity.py, adjust imports, and ta-da! ./code/singularity.py is gone! ./singularity.py is now the entry module, the shell executable, and the file that handles argparse and starts the game, as it should be in any sane layout.
- setup.py can be used by user (or distro package maintainers) to actually install the game in Mac, Windows.. and Linux! As in *any* python app. No more silly "sorry, I don't work for linux. I must be in /usr/share/games or hell will break loose". We actualy /don't care/ where it will be installed/run. setup.py, .deb installer, or ~/downloads/im/only/testing/singularity.py, they all work fine
bugfix/datadir is ready to merge at
http://code.google.com/r/rodrigosilva-singularity/ , and if you guys like the "bolder" suggestions, I can promptly create another branch for them.
Eager for your feedback,
ML
If