I think there are three types of files that games often deal with that are relevant for this discussion:
- Settings (keybindings, sound volume, fullscreen resolution, etc.)
- Important data files that are created by the game (high scores, replays, save files, etc.)
- Static data files that doesn't change after installation (e.g. sound, graphics, scripts, etc.)
Where should the game write files?
Settings should obviously be written to XDG_CONFIG_HOME.
What about other files (e.g. save files)? Should they also be written to XDG_CONFIG_HOME or should they be written to XDG_DATA_HOME? At first it seems like XDG_DATA_HOME would be the correct place to put them but when considering all the confusion below it becomes quite tempting to want to put these files in XDG_CONFIG_HOME. It makes some sense because the XDG specification doesn't specify what it means by "configuration files" and speaking in very general terms one could argue that save files are just complicated configuration files that describe how the game is "configured".
Where should the game search for static data files?
I understand that one would normally search the XDG_DATA_DIRS paths for the installed static data files (sound, graphics, etc.) but the question is whether XDG_DATA_HOME should be searched as well? I kind of get the impression that it should be when reading the XDG specification.
XDG Base Directory Specification {l Wrote}:$XDG_DATA_DIRS defines the preference-ordered set of base directories to search for data files in addition to the $XDG_DATA_HOME base directory.
XDG Base Directory Specification {l Wrote}:The order of base directories denotes their importance; the first directory listed is the most important. When the same information is defined in multiple places the information defined relative to the more important base directory takes precedent. The base directory defined by $XDG_DATA_HOME is considered more important than any of the base directories defined by $XDG_DATA_DIRS.
On the other hand, it specifically mentions "user-specific data files" but I'm not sure it could be different type of data files or if it simply refers to the same type of data files that can be found in the XDG_DATA_DIRS with only difference being that the user should have write permission.
XDG Base Directory Specification {l Wrote}:There is a single base directory relative to which user-specific data files should be written. This directory is defined by the environment variable $XDG_DATA_HOME.
Do the game need to handle static data files and created data files in the same base directory?
If the intention is that the user should be able to install the game files in XDG_DATA_HOME/mygame/ and the game should also write to that directory then I'm a little bit concerned. It means I would need to avoid name clashes (not too difficult because I could use extra subfolders) and the uninstall script would need to be more advanced than just removing all files in the directory to avoid deleting save files and other files that the user might want to keep.