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.

57 lines
1.2 KiB

  1. extends Node
  2. const FILE_PATH = "user://local_storage"
  3. func _ready():
  4. TranslationServer.set_locale(read_value("locale","en"))
  5. func read_content():
  6. var f = File.new()
  7. var err = f.open(FILE_PATH, File.READ)
  8. var content = {}
  9. if err == OK:
  10. content = parse_json(f.get_as_text())
  11. f.close()
  12. if content == null:
  13. content = {}
  14. return content
  15. func write_content(content:Dictionary):
  16. var f = File.new()
  17. var err = f.open(FILE_PATH, File.WRITE)
  18. #var err = f.open_encrypted_with_pass(FILE_PATH, File.WRITE, OS.get_unique_id())
  19. f.store_string(to_json(content))
  20. f.close()
  21. func write_value(key:String, value):
  22. var content = read_content()
  23. content[key] = value
  24. write_content(content)
  25. func read_value(key:String, default = null):
  26. var content = read_content()
  27. if content.has(key) && content.get(key) != null:
  28. return content.get(key)
  29. else:
  30. return default
  31. func delete_value(key:String):
  32. var content = read_content()
  33. content.erase(key)
  34. write_content(content)
  35. func write_values(new_content:Dictionary):
  36. var content = read_content()
  37. for key in new_content:
  38. content[key] = new_content[key]
  39. write_content(content)
  40. func read_values():
  41. return read_content()