Guest User

Untitled

a guest
Dec 9th, 2019
81
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void loadGameState(string fName) {
  2. std::ifstream MyFile("Saves/" + fName);
  3. string line;
  4.  
  5. //TIMESTAMP
  6.  
  7. getline(MyFile, line);
  8. std::cout << "Timestamp of save: " + line << std::endl;
  9.  
  10. //CURRENT ROOM
  11. getline(MyFile, line);
  12.  
  13. for(Room* iter: Room::rooms){
  14. string key = iter->getName()->data();
  15.  
  16. if (key.compare(0, ' ', line) == 0) {
  17. currentState->goTo(iter);
  18. }
  19. }
  20.  
  21. //INVENTORY
  22. getline(MyFile, line);
  23.  
  24. string intermediate;
  25. std::stringstream temp(line);
  26.  
  27. State::inventory.clear();
  28.  
  29. while (std::getline(temp, intermediate, ',')) {
  30.  
  31. for (GameObject* iter: objList) {
  32. if (intermediate.compare(0, ' ', iter->getKey()) == 0) {
  33. std::cout << intermediate + " Here" << std::endl;
  34. State::inventory.push_back(iter);
  35. }
  36. }
  37. }
  38.  
  39. //ROOM OBJECTS
  40. string strName;
  41. string strList;
  42.  
  43. while (!MyFile.eof()) {
  44. getline(MyFile, strName);
  45. getline(MyFile, strList);
  46.  
  47. std::vector<string> tokens;
  48. std::stringstream store(strList);
  49.  
  50. while (std::getline(store, intermediate, ',')) {
  51.  
  52.  
  53. for (Room *x: Room::rooms) {
  54. if (strName.compare(0, ' ', *x->getName()) == 0) {
  55. for (GameObject *y: objList) {
  56. if (y->getKey().compare(0, ' ', intermediate) == 0) {
  57. *x->addObject(y);
  58. }
  59. }
  60. }
  61. }
  62. }
  63. }
  64. MyFile.close();
  65. }
RAW Paste Data