Open farazxameer opened 6 years ago
Sounds like a great idea. But what about Windows?
Yes I thought about that, I guess in windows we run this game on git-bash, I saw there was a directory /usr/lib/ and we can access this dir with git-bash , so it will be cross platform.
I'll try to implement this and test it both on Windows and linux, and with this I also want to properly deploy the binary and able to play the game from anywhere just like a command.
This will be great! Waiting on it :)
We can use code for checking the operating system and if it find windows then the files can be saved in the windows user/documents directly or if it finds linux then /use/lib/2048.
@farazxameer, @vishwast has made a good point
@farazxameer Any progress? 😄
I think it would be better to use ~/.config/2048.cpp/data
in Linux and C:\Users\%USERNAME%\AppData\2048.cpp\data
Instead of checking the operating system and write a lot of code to do so, use conditional compiling. After all, where data will be stored is dependent on the operating system. So, it makes little sense make system calls to evaluate what is the operating system in order to decide where to save stuff.
The best approach is to save data into user's home folder. For *nix operating systems you can do it on a single file on $HOME in a name like .2048. If you need several files, it can be a directory.
For Windows users, it should be a file or directory under user's home directory. There is a special directory only for that. The best is to encapsulate the way user's home directory is determined and let the implementation do the job. So, you can conditionally compile the implementation, letting the interface independent.
Hey @ronflima! Thanks a lot for your inputs, your way certainly seems like the neatest and most correct way to do so. If you have time in your hands, please consider proposing a PR to implement the same. Thanks again 😄!
You can take a look at this repo for finding user data folder on operating systems, but I'd do as what @ronflima suggested.
Hi, I got busy with my exam, it will be really good if anybody wants to implement this functionality.
No problem! You can try implementing it, I don't think anyone has taken it up right now :smile:
Hey! Can I try writing creating a PR if nobody is working on it already? I'm comfortable with C++ but this would be my first PR ever
We should be storing the game data in some centralised folder like
/usr/lib/2048/
.