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.

62 lines
2.2 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("system", "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("system","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. OS.set_window_position(Vector2((OS.get_screen_size().x - resolution.x) / 2, (OS.get_screen_size().y - resolution.y) / 2)) # center screen
  30. get_tree().set_screen_stretch(SceneTree.STRETCH_MODE_VIEWPORT,SceneTree.STRETCH_ASPECT_IGNORE,OS.get_window_size(),1)
  31. func apply_controls():
  32. InputMap.load_from_globals()
  33. var control_map = config.get_value("controls","mapping",{})
  34. for action in InputMap.get_actions():
  35. if control_map.has(action):
  36. for event in InputMap.get_action_list(action):
  37. if event is InputEventKey && control_map[action].has("key"):
  38. InputMap.action_erase_event(action, event)
  39. event.set_scancode(OS.find_scancode_from_string(control_map[action]["key"]))
  40. InputMap.action_add_event(action,event)
  41. elif event is InputEventJoypadButton && control_map[action].has("joypad"):
  42. InputMap.action_erase_event(action, event)
  43. event.set_button_index(control_map[action]["joypad"])
  44. InputMap.action_add_event(action,event)
  45. for ui_mapping in config.INPUT_UI_MAPPING:
  46. for event in InputMap.get_action_list(config.INPUT_UI_MAPPING[ui_mapping]):
  47. InputMap.action_add_event(ui_mapping, event)