SettingsManager.gd 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. extends Node
  2. var file := {
  3. "video": {
  4. "mode": 0,
  5. "size": 0,
  6. "vsync": 1,
  7. "drop_shadows": 1,
  8. "scaling": 0,
  9. "visuals": 0,
  10. "hud_size": 0
  11. },
  12. "audio": {
  13. "master": 10.0,
  14. "music": 10.0,
  15. "sfx": 10.0,
  16. "athletic_bgm": 1,
  17. "extra_bgm": 1,
  18. "skid_sfx": 1,
  19. "extra_sfx": 0,
  20. "menu_bgm": 0
  21. },
  22. "game": {
  23. "campaign": "SMB1",
  24. "lang": "en",
  25. "character": "0000"
  26. },
  27. "keyboard":
  28. {
  29. "jump": "Z",
  30. "run": "X",
  31. "action": "X",
  32. "move_left": "Left",
  33. "move_right": "Right",
  34. "move_up": "Up",
  35. "move_down": "Down"
  36. },
  37. "controller":
  38. {
  39. "jump": 0,
  40. "run": 2,
  41. "action": 2,
  42. "move_left": "0,-1",
  43. "move_right": "0,1",
  44. "move_up": "1,-1",
  45. "move_down": "1,1"
  46. },
  47. "visuals":
  48. {
  49. "parallax_style": 2,
  50. "resource_packs": [Global.ROM_PACK_NAME],
  51. "modern_hud": 0,
  52. "rainbow_style": 0,
  53. "extra_bgs": 1,
  54. "bg_particles": 1,
  55. "transform_style": 0,
  56. "athletic_bgm": 1,
  57. "skid_sfx": 1,
  58. "text_shadows": 1,
  59. "bridge_animation": 0,
  60. "visible_timers": 0,
  61. "transition_animation": 0,
  62. "colour_pipes": 1
  63. },
  64. "difficulty":
  65. {
  66. "damage_style": 1,
  67. "checkpoint_style": 0,
  68. "inf_lives": 0,
  69. "flagpole_lives": 0,
  70. "game_over_behaviour": 0,
  71. "level_design": 0,
  72. "extra_checkpoints": 0,
  73. "back_scroll": 0,
  74. "time_limit": 1,
  75. "lakitu_style": 0
  76. }
  77. }
  78. const SETTINGS_DIR := "user://settings.cfg"
  79. func _enter_tree() -> void:
  80. DirAccess.make_dir_absolute("user://resource_packs")
  81. load_settings()
  82. await get_tree().physics_frame
  83. apply_settings()
  84. TranslationServer.set_locale(Settings.file.game.lang)
  85. func save_settings() -> void:
  86. var cfg_file = ConfigFile.new()
  87. for section in file.keys():
  88. for key in file[section].keys():
  89. cfg_file.set_value(section, key, file[section][key])
  90. cfg_file.set_value("game", "seen_disclaimer", true)
  91. cfg_file.set_value("game", "campaign", Global.current_campaign)
  92. cfg_file.save(SETTINGS_DIR)
  93. func load_settings() -> void:
  94. if FileAccess.file_exists(SETTINGS_DIR) == false:
  95. save_settings()
  96. var cfg_file = ConfigFile.new()
  97. cfg_file.load(SETTINGS_DIR)
  98. for section in cfg_file.get_sections():
  99. for key in cfg_file.get_section_keys(section):
  100. file[section][key] = cfg_file.get_value(section, key)
  101. func apply_settings() -> void:
  102. for i in file.video.keys():
  103. $Apply/Video.set_value(i, file.video[i])
  104. for i in file.audio.keys():
  105. $Apply/Audio.set_value(i, file.audio[i])
  106. if Settings.file.game.has("characters"):
  107. Global.player_characters = Settings.file.game.characters