Started work on loading and saving variables to a file

This commit is contained in:
Paul Black 2023-01-29 10:41:06 -07:00
parent 8c1583c928
commit 72648ac136
4 changed files with 38 additions and 11 deletions

View file

@ -28,3 +28,4 @@ animation/fps=15
animation/trimming=false
import_script/path=""
_subresources={}
meshes/handle_gltf_embedded_images=1

View file

@ -19,46 +19,43 @@ config/icon="res://icon.svg"
[autoload]
Global="*res://scripts/global.gd"
SettingsFile="*res://scripts/settings-file.gd"
[display]
window/size/mode=3
window/stretch/mode="canvas_items"
[editor]
export/convert_text_resources_to_binary=true
[input]
player_left={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"unicode":0,"echo":false,"script":null)
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
player_right={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"unicode":0,"echo":false,"script":null)
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
player_forward={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"unicode":0,"echo":false,"script":null)
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
player_backward={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"unicode":0,"echo":false,"script":null)
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
sprint={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194325,"unicode":0,"echo":false,"script":null)
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194325,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
menu={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194305,"unicode":0,"echo":false,"script":null)
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194305,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}
shoot={

30
scripts/settings-file.gd Normal file
View file

@ -0,0 +1,30 @@
extends Node
const SETTINGS_FILE = "user://settings.vars" # user:// path varies depending on operating system. See https://docs.godotengine.org/en/latest/tutorials/io/data_paths.html#accessing-persistent-user-data-user
var settings_template = { # Default values if we don't already have a settings file. Assigned in save_data()
'mousesense': 0.01,
'playername' : "string"
}
var settings_data = {} # This gets filled as soon as load_data() is called.
func _ready():
check_data()
load_data()
func check_data(): # Makes sure the save file exists
var file = FileAccess.open(SETTINGS_FILE, FileAccess.READ) #If we write, it writes an empty file over our existing one
if not file: # If there's no file, let's create one with FileAccess.WRITE
print("file does not exist, let's create one!")
var file2 = FileAccess.open(SETTINGS_FILE, FileAccess.WRITE)
file2.store_line(JSON.stringify(settings_template)) # Writes settings_template to our file SETTINGS_FILE
func save_data(mousesense, playername): # It's required you pass both the mouse sensitivity and the player name to save current data
var file = FileAccess.open(SETTINGS_FILE, FileAccess.WRITE)
func load_data():
var file = FileAccess.open(SETTINGS_FILE, FileAccess.READ)
settings_data = JSON.parse_string(file.get_line())
print(settings_data)

View file

@ -1,7 +1,6 @@
extends Control
func _ready():
pass