plibither8 / 2048.cpp

🎮 Fully featured terminal version of the game "2048" written in C++
MIT License
2.19k stars 325 forks source link

Centralised place to store all data #38

Open farazxameer opened 6 years ago

farazxameer commented 6 years ago

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

plibither8 commented 6 years ago

Sounds like a great idea. But what about Windows?

farazxameer commented 6 years ago

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 commented 6 years ago

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.

plibither8 commented 6 years ago

This will be great! Waiting on it :)

VishwasTamta commented 6 years ago

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.

plibither8 commented 6 years ago

@farazxameer, @vishwast has made a good point

plibither8 commented 6 years ago

@farazxameer Any progress? 😄

Carlovan commented 6 years ago

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

ronflima commented 6 years ago

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.

plibither8 commented 6 years ago

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

tiendq commented 6 years ago

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

farazxameer commented 6 years ago

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

plibither8 commented 6 years ago

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

aadit-n3rdy commented 1 year ago

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