SaveLoad.gml 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. function initialize_save_data()
  2. {
  3. global.save_data =
  4. {
  5. player:
  6. {
  7. maxHP: 5,
  8. maxINK: 9,
  9. Credit: 0,
  10. abilities:
  11. {
  12. attack: false,
  13. accesscard : false,
  14. annotate: false,
  15. dash: false,
  16. wall_climb: false,
  17. double_jump: false
  18. },
  19. corpse:
  20. {
  21. targetRoom: noone,
  22. xPos: -1,
  23. yPos: -1,
  24. droppedCredit: 0
  25. },
  26. },
  27. world:
  28. {
  29. spRoom: "rTest1",
  30. spxPos: 192,
  31. spyPos: 864,
  32. activated_objects: {},
  33. defeated_boss: {},
  34. npc_flags: {}
  35. }
  36. };
  37. initialize_dialogue();
  38. var _npc_names = struct_get_names(global.dialogue);
  39. for(var i = 0; i < array_length(_npc_names); i++)
  40. {
  41. var _npc = _npc_names[i];
  42. var _flags = [-1, 0];
  43. for(var j = 2; j < array_length(_npc); j++)
  44. _flags[j] = -1;
  45. global.save_data.world.npc_flags[$ _npc] = _flags;
  46. }
  47. }
  48. function initialize_dialogue()
  49. {
  50. global.dialogue =
  51. {
  52. warden:
  53. [
  54. [//idle
  55. "Have a nice day!"
  56. ],
  57. [//first
  58. [
  59. "Good morning. " +
  60. "I haven't met you before! " +
  61. "Are you new here?",
  62. "By the way, my access card is lost, " +
  63. "so you probably can't leave the dorm right now. " +
  64. "I'm pretty sorry."
  65. ],
  66. [
  67. "Tell me if you see it anywhere!"
  68. ]
  69. ],
  70. [//accesscard
  71. [
  72. "Wow, thanks a lot! " +
  73. "Here, try this. ",
  74. "Oh, I can lend a card to you. " +
  75. "There may be other locked doors like these."
  76. ],
  77. [
  78. "Are you leaving? " +
  79. "Remember to pay a visit when you have spare time. " +
  80. "I'm planning to sell some daily necessities."
  81. ]
  82. ]
  83. ]
  84. };
  85. }
  86. function save_game_to_disk()
  87. {
  88. var _json_string = json_stringify(global.save_data);
  89. var _buffer = buffer_create(string_byte_length(_json_string) + 1, buffer_fixed, 1);
  90. buffer_write(_buffer, buffer_string, _json_string);
  91. buffer_save(_buffer, global.save_filename);
  92. buffer_delete(_buffer);
  93. if global.developer_mode
  94. show_debug_message("The game has been saved to " + global.save_filename);
  95. }
  96. function load_game_from_disk()
  97. {
  98. if !file_exists(global.save_filename)
  99. return;
  100. var _buffer = buffer_load(global.save_filename);
  101. var _json_string = buffer_read(_buffer, buffer_string);
  102. buffer_delete(_buffer);
  103. var _loaded_data = json_parse(_json_string);
  104. global.save_data = _loaded_data;
  105. room_goto(asset_get_index(global.save_data.world.spRoom));
  106. global.in_game_manager = icl(oInGameManager);
  107. }
  108. function self_check_activated()
  109. {
  110. return struct_exists(global.save_data.world.activated_objects, uuid)
  111. }
  112. function autosave()
  113. {
  114. var _list = global.save_data.world.activated_objects;
  115. _list[$ uuid] = true;
  116. save_game_to_disk();
  117. }