Public repository for MUR pre alpha
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.0 KiB

  1. extends Node
  2. const FILE_PATH = "user://local_storage"
  3. func _ready():
  4. apply_settings()
  5. func apply_settings():
  6. apply_locale()
  7. apply_game_server()
  8. apply_resolution()
  9. apply_controls()
  10. func apply_locale():
  11. TranslationServer.set_locale(config.get_value("system","locale","en"))
  12. func apply_game_server():
  13. var server_addr = config.get_value("game_server", "server_addr")
  14. if server_addr != null && not server_addr.empty():
  15. game_server.set_server_addr(server_addr)
  16. var api_addr = config.get_value("game_server","api_addr")
  17. if api_addr != null && not api_addr.empty():
  18. game_server.set_api_addr(api_addr)
  19. func apply_resolution():
  20. var view_port = get_tree().get_root()
  21. OS.set_window_fullscreen(config.get_value("graphics","fullscreen", true))
  22. var resolution = config.get_value("graphics","resolution",config.RESOLUTIONS[0])
  23. if OS.is_window_fullscreen():
  24. var base_size = Vector2(1920, 1080)
  25. var scale= base_size.x / resolution.x
  26. get_tree().set_screen_stretch(SceneTree.STRETCH_MODE_2D,SceneTree.STRETCH_ASPECT_EXPAND,base_size,scale)
  27. else:
  28. OS.set_window_size(resolution)
  29. get_tree().set_screen_stretch(SceneTree.STRETCH_MODE_VIEWPORT,SceneTree.STRETCH_ASPECT_IGNORE,OS.get_window_size(),1)
  30. func apply_controls():
  31. InputMap.load_from_globals()
  32. var control_map = config.get_value("controls","mapping",{})
  33. for action in InputMap.get_actions():
  34. if control_map.has(action):
  35. for event in InputMap.get_action_list(action):
  36. if event is InputEventKey && control_map[action].has("key"):
  37. InputMap.action_erase_event(action, event)
  38. event.set_scancode(OS.find_scancode_from_string(control_map[action]["key"]))
  39. InputMap.action_add_event(action,event)
  40. elif event is InputEventJoypadButton && control_map[action].has("joypad"):
  41. InputMap.action_erase_event(action, event)
  42. event.set_button_index(control_map[action]["joypad"])
  43. InputMap.action_add_event(action,event)
  44. for ui_mapping in config.INPUT_UI_MAPPING:
  45. for event in InputMap.get_action_list(config.INPUT_UI_MAPPING[ui_mapping]):
  46. InputMap.action_add_event(ui_mapping, event)