do some changes with XLib and started working on main menu
This commit is contained in:
@@ -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:
|
||||
|
||||
Binary file not shown.
7
GameShit/MainGame/World.gd
Normal file
7
GameShit/MainGame/World.gd
Normal file
@@ -0,0 +1,7 @@
|
||||
extends Node3D
|
||||
|
||||
func execUpdate():
|
||||
$XLightingUpdate3D.updateLighting.emit()
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
$objects.child_entered_tree.connect(execUpdate)
|
||||
1
GameShit/MainGame/World.gd.uid
Normal file
1
GameShit/MainGame/World.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://f4qnisqbv4gm
|
||||
9
GameShit/UI/Scenes/MainMenuUI.tscn
Normal file
9
GameShit/UI/Scenes/MainMenuUI.tscn
Normal file
@@ -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
|
||||
20
SaveManager/Config.gd
Normal file
20
SaveManager/Config.gd
Normal file
@@ -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()
|
||||
|
||||
|
||||
1
SaveManager/Config.gd.uid
Normal file
1
SaveManager/Config.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://4druvilwa0gc
|
||||
5
SaveManager/ConfigResource.gd
Normal file
5
SaveManager/ConfigResource.gd
Normal file
@@ -0,0 +1,5 @@
|
||||
class_name Config extends Resource
|
||||
|
||||
@export var username : String
|
||||
@export var language : String
|
||||
@export var keybinds : Dictionary
|
||||
1
SaveManager/ConfigResource.gd.uid
Normal file
1
SaveManager/ConfigResource.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://b8jxsghucippq
|
||||
@@ -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")
|
||||
|
||||
17
addons/xlib/nodes/XLightingUpdate3D.gd
Normal file
17
addons/xlib/nodes/XLightingUpdate3D.gd
Normal file
@@ -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)
|
||||
1
addons/xlib/nodes/XLightingUpdate3D.gd.uid
Normal file
1
addons/xlib/nodes/XLightingUpdate3D.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://de8gtv3fwwfvr
|
||||
5
addons/xlib/scripts/GameSaveResource.gd
Normal file
5
addons/xlib/scripts/GameSaveResource.gd
Normal file
@@ -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
|
||||
1
addons/xlib/scripts/GameSaveResource.gd.uid
Normal file
1
addons/xlib/scripts/GameSaveResource.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://i5d1qc430pfd
|
||||
63
addons/xlib/scripts/Save.gd
Normal file
63
addons/xlib/scripts/Save.gd
Normal file
@@ -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!")
|
||||
1
addons/xlib/scripts/Save.gd.uid
Normal file
1
addons/xlib/scripts/Save.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bxo4gihn43kx
|
||||
@@ -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]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user