diff --git a/GameShit/MainGame/MainGame.gd b/GameShit/MainGame/MainGame.gd index 2741e93..98d0c9f 100644 --- a/GameShit/MainGame/MainGame.gd +++ b/GameShit/MainGame/MainGame.gd @@ -1,5 +1,5 @@ extends Node3D - +signal hideChatbox ## define all of the game variables, ill replace this with a settings file later ## ignore duplicate keys, idrc atp @@ -8,13 +8,15 @@ var selectedBlockID : String = "base:testMachine" var selectedSlot = 0 var currentHeldItemID : String = "base:air" var canPlaceBlock : bool = false -var username = "Xtimhedi" +var username = "test" var loadedLanguage = "en-US" var isInputLocked = false -signal hideChatbox +func _ready() -> void: + var cfg = ConfigLoader.loadConfig() + username = cfg.username func getIfIDExists(ID:String) -> bool: diff --git a/GameShit/MainGame/MainGame.scn b/GameShit/MainGame/MainGame.scn index 5e24962..c9fdeea 100644 Binary files a/GameShit/MainGame/MainGame.scn and b/GameShit/MainGame/MainGame.scn differ diff --git a/GameShit/MainGame/World.gd b/GameShit/MainGame/World.gd new file mode 100644 index 0000000..7bd1061 --- /dev/null +++ b/GameShit/MainGame/World.gd @@ -0,0 +1,7 @@ +extends Node3D + +func execUpdate(): + $XLightingUpdate3D.updateLighting.emit() + +func _process(delta: float) -> void: + $objects.child_entered_tree.connect(execUpdate) diff --git a/GameShit/MainGame/World.gd.uid b/GameShit/MainGame/World.gd.uid new file mode 100644 index 0000000..01cc147 --- /dev/null +++ b/GameShit/MainGame/World.gd.uid @@ -0,0 +1 @@ +uid://f4qnisqbv4gm diff --git a/GameShit/UI/Scenes/MainMenuUI.tscn b/GameShit/UI/Scenes/MainMenuUI.tscn new file mode 100644 index 0000000..63d0604 --- /dev/null +++ b/GameShit/UI/Scenes/MainMenuUI.tscn @@ -0,0 +1,9 @@ +[gd_scene format=3 uid="uid://calo1poanr0i8"] + +[node name="MainMenuUi" type="Control" unique_id=122337977] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 diff --git a/SaveManager/Config.gd b/SaveManager/Config.gd new file mode 100644 index 0000000..d0e1eb6 --- /dev/null +++ b/SaveManager/Config.gd @@ -0,0 +1,20 @@ +extends Node + +const ConfigPath = "user://config.tres" + +func saveConfigs(): + var NewConfig = Config.new() + NewConfig.username = MainGame.username + NewConfig.language = MainGame.loadedLanguage + + var sc = ResourceSaver.save(NewConfig, ConfigPath) + +func loadConfig() -> Config: + if ResourceLoader.exists(ConfigPath): + var LoadedConfig = load(ConfigPath) + if LoadedConfig: + return LoadedConfig + + return Config.new() + + diff --git a/SaveManager/Config.gd.uid b/SaveManager/Config.gd.uid new file mode 100644 index 0000000..8e0c09c --- /dev/null +++ b/SaveManager/Config.gd.uid @@ -0,0 +1 @@ +uid://4druvilwa0gc diff --git a/SaveManager/ConfigResource.gd b/SaveManager/ConfigResource.gd new file mode 100644 index 0000000..68cdd5b --- /dev/null +++ b/SaveManager/ConfigResource.gd @@ -0,0 +1,5 @@ +class_name Config extends Resource + +@export var username : String +@export var language : String +@export var keybinds : Dictionary diff --git a/SaveManager/ConfigResource.gd.uid b/SaveManager/ConfigResource.gd.uid new file mode 100644 index 0000000..a61bddf --- /dev/null +++ b/SaveManager/ConfigResource.gd.uid @@ -0,0 +1 @@ +uid://b8jxsghucippq diff --git a/addons/xlib/main.gd b/addons/xlib/main.gd index 8ecc6d4..819a199 100644 --- a/addons/xlib/main.gd +++ b/addons/xlib/main.gd @@ -1,22 +1,18 @@ @tool extends EditorPlugin +var pluginDir func _enable_plugin() -> void: - # Add autoloads here. - pass - + var plugin_dir = get_script().resource_path.get_base_dir() func _disable_plugin() -> void: - # Remove autoloads here. pass func _enter_tree() -> void: - # Initialization of the plugin goes here. - pass - + var nodes = get_script().resource_path.get_base_dir() + "/nodes" + add_custom_type("XLightingUpdate3D", "Node3D", load(nodes + "/XLightingUpdate3D.gd"), null) func _exit_tree() -> void: - # Clean-up of the plugin goes here. - pass + remove_custom_type("XLightingUpdate3D") diff --git a/addons/xlib/nodes/XLightingUpdate3D.gd b/addons/xlib/nodes/XLightingUpdate3D.gd new file mode 100644 index 0000000..cefbf14 --- /dev/null +++ b/addons/xlib/nodes/XLightingUpdate3D.gd @@ -0,0 +1,17 @@ +@tool + +extends Node3D + +signal updateLighting + +@export var frame:int +@export var GameWorldEnv:WorldEnvironment + +func resetLighting(): + GameWorldEnv.environment.sdfgi_enabled = false + await get_tree().process_frame + GameWorldEnv.environment.sdfgi_enabled = true + +func _ready() -> void: + print("Lighting node entered tree!") + updateLighting.connect(resetLighting) diff --git a/addons/xlib/nodes/XLightingUpdate3D.gd.uid b/addons/xlib/nodes/XLightingUpdate3D.gd.uid new file mode 100644 index 0000000..c132003 --- /dev/null +++ b/addons/xlib/nodes/XLightingUpdate3D.gd.uid @@ -0,0 +1 @@ +uid://de8gtv3fwwfvr diff --git a/addons/xlib/scripts/GameSaveResource.gd b/addons/xlib/scripts/GameSaveResource.gd new file mode 100644 index 0000000..bd9bca9 --- /dev/null +++ b/addons/xlib/scripts/GameSaveResource.gd @@ -0,0 +1,5 @@ +class_name GameSaveResource extends Resource + +@export var stored_scenes: Array[PackedScene] = [] +@export var stored_player: PackedScene +@export var stored_hotbar: HotbarResource # Holds your active items diff --git a/addons/xlib/scripts/GameSaveResource.gd.uid b/addons/xlib/scripts/GameSaveResource.gd.uid new file mode 100644 index 0000000..6c8f151 --- /dev/null +++ b/addons/xlib/scripts/GameSaveResource.gd.uid @@ -0,0 +1 @@ +uid://i5d1qc430pfd diff --git a/addons/xlib/scripts/Save.gd b/addons/xlib/scripts/Save.gd new file mode 100644 index 0000000..31879fc --- /dev/null +++ b/addons/xlib/scripts/Save.gd @@ -0,0 +1,63 @@ +extends Node + +func saveGameData(file_name: String): + var save_data = GameSaveResource.new() + var objects_container = get_node_or_null("/root/World/objects") + if objects_container: + for object in objects_container.get_children(): + for child in object.get_children(): + child.owner = object + var packed_node = PackedScene.new() + if packed_node.pack(object) == OK: + save_data.stored_scenes.append(packed_node) + var player_node = get_node_or_null("/root/World/PlayerController") + if player_node: + var hotbar_control = player_node.get_node_or_null("Camera3D/CanvasLayer/HotBar") + if hotbar_control and "hotbar" in hotbar_control: + save_data.stored_hotbar = hotbar_control.hotbar.duplicate(true) + for child in player_node.get_children(): + child.owner = player_node + var packed_player = PackedScene.new() + if packed_player.pack(player_node) == OK: + save_data.stored_player = packed_player + var full_path = "user://" + file_name + var save_result = ResourceSaver.save(save_data, full_path) + if save_result == OK: + print("Successfully saved all nodes and items to: ", full_path) + + +func loadGameData(file_name: String): + var full_path = "user://" + file_name + if not ResourceLoader.exists(full_path): + print("Error: Save file '", full_path, "' does not exist.") + return + var save_data = ResourceLoader.load(full_path) as GameSaveResource + if not save_data: + print("Error: Could not parse save file.") + return + var objects_node = get_node_or_null("/root/World/objects") + if objects_node: + for child in objects_node.get_children(): + child.queue_free() + for packed_node in save_data.stored_scenes: + if packed_node: + objects_node.add_child(packed_node.instantiate()) + if save_data.stored_player: + var current_player = get_node_or_null("/root/World/PlayerController") + if current_player: + var player_parent = current_player.get_parent() + var restored_player = save_data.stored_player.instantiate() + restored_player.name = "PlayerController_New" + var hotbar_control = restored_player.get_node_or_null("Camera3D/CanvasLayer/HotBar") + if hotbar_control and save_data.stored_hotbar: + hotbar_control.hotbar = save_data.stored_hotbar.duplicate(true) + player_parent.add_child(restored_player) + current_player.queue_free() + await get_tree().process_frame + if is_instance_valid(restored_player): + restored_player.name = "PlayerController" + var final_hotbar = restored_player.get_node_or_null("Camera3D/CanvasLayer/HotBar") + if final_hotbar and final_hotbar.has_method("updateHotbar"): + final_hotbar.updateHotbar(final_hotbar.hotbar) + print("Player and inventory data successfully restored!") + print("Successfully reloaded game state from disk!") diff --git a/addons/xlib/scripts/Save.gd.uid b/addons/xlib/scripts/Save.gd.uid new file mode 100644 index 0000000..bf75bde --- /dev/null +++ b/addons/xlib/scripts/Save.gd.uid @@ -0,0 +1 @@ +uid://bxo4gihn43kx diff --git a/project.godot b/project.godot index da2074c..8d1539e 100644 --- a/project.godot +++ b/project.godot @@ -18,12 +18,12 @@ config/features=PackedStringArray("4.6", "Forward Plus") Globals="*uid://bu2uolph3gknp" MainGame="*uid://eudofx4u58h0" -SaveManager="*uid://ck4ih2layufdo" CommandHandler="*uid://jo7ml3jp3sd7" InventoryBus="*uid://1esfwguw47p3" CommandBus="*uid://csa2l3h2dohp1" LanguageManager="*uid://cq1njdji6gak6" Save="*uid://bxo4gihn43kx" +ConfigLoader="*uid://4druvilwa0gc" [display]