2048.cpp icon indicating copy to clipboard operation
2048.cpp copied to clipboard

Centralised place to store all data

Open farazxameer opened this issue 7 years ago • 14 comments
trafficstars

We should be storing the game data in some centralised folder like/usr/lib/2048/ .

farazxameer avatar Oct 03 '18 15:10 farazxameer

Sounds like a great idea. But what about Windows?

plibither8 avatar Oct 03 '18 15:10 plibither8

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.

farazxameer avatar Oct 04 '18 05:10 farazxameer

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.

farazxameer avatar Oct 04 '18 05:10 farazxameer

This will be great! Waiting on it :)

plibither8 avatar Oct 04 '18 11:10 plibither8

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.

VishwasTamta avatar Oct 05 '18 07:10 VishwasTamta

@farazxameer, @vishwast has made a good point

plibither8 avatar Oct 05 '18 08:10 plibither8

@farazxameer Any progress? 😄

plibither8 avatar Oct 08 '18 10:10 plibither8

I think it would be better to use ~/.config/2048.cpp/data in Linux and C:\Users\%USERNAME%\AppData\2048.cpp\data

Carlovan avatar Oct 11 '18 09:10 Carlovan

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.

ronflima avatar Oct 21 '18 13:10 ronflima

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 😄!

plibither8 avatar Oct 21 '18 16:10 plibither8

You can take a look at this repo for finding user data folder on operating systems, but I'd do as what @ronflima suggested.

tiendq avatar Oct 26 '18 02:10 tiendq

Hi, I got busy with my exam, it will be really good if anybody wants to implement this functionality.

farazxameer avatar Oct 31 '18 07:10 farazxameer

No problem! You can try implementing it, I don't think anyone has taken it up right now :smile:

plibither8 avatar Oct 31 '18 08:10 plibither8

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

aadit-n3rdy avatar Sep 30 '23 03:09 aadit-n3rdy