mirror of
https://github.com/Relintai/broken_seals.git
synced 2025-04-05 17:12:46 +02:00
Moved the module initialization code to a new DataManager autoload. Also added a new on_request_instance method to GameModule, and also added a request_instance method to the new DataManager. player_ui is requested through this new api.
This commit is contained in:
parent
2a0f36a03f
commit
4c902fe7a7
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -639,8 +639,9 @@ func on_c_controlled_changed(val):
|
|||||||
add_child(camera_pivot)
|
add_child(camera_pivot)
|
||||||
camera = camera_pivot.get_node("Camera") as Camera
|
camera = camera_pivot.get_node("Camera") as Camera
|
||||||
|
|
||||||
var uiscn : PackedScene = ResourceLoader.load("res://ui/player_ui/player_ui.tscn")
|
# var uiscn : PackedScene = ResourceLoader.load("res://ui/player_ui/player_ui.tscn")
|
||||||
var ui = uiscn.instance()
|
# var ui = uiscn.instance()
|
||||||
|
var ui = DataManager.request_instance(DataManager.PLAYER_UI_INSTANCE)
|
||||||
add_child(ui)
|
add_child(ui)
|
||||||
|
|
||||||
|
|
||||||
|
@ -174,6 +174,7 @@ WorldNumbers="*res://ui/autoload/WorldNumbers.tscn"
|
|||||||
ThemeAtlas="*res://ui/autoload/ThemeAtlas.tscn"
|
ThemeAtlas="*res://ui/autoload/ThemeAtlas.tscn"
|
||||||
Server="*res://autoload/Server.tscn"
|
Server="*res://autoload/Server.tscn"
|
||||||
EntitySpawner="*res://player/bs_entity_spawner.tscn"
|
EntitySpawner="*res://player/bs_entity_spawner.tscn"
|
||||||
|
DataManager="*res://scripts/game_modules/DataManager.tscn"
|
||||||
|
|
||||||
[debug]
|
[debug]
|
||||||
|
|
||||||
|
@ -36,62 +36,11 @@ var _loading_screen : Node
|
|||||||
var current_scene : Node
|
var current_scene : Node
|
||||||
var current_character_file_name : String = ""
|
var current_character_file_name : String = ""
|
||||||
|
|
||||||
var _modules : Array
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
_loading_screen = get_node(loading_screen_path)
|
_loading_screen = get_node(loading_screen_path)
|
||||||
|
|
||||||
ProfileManager.load()
|
|
||||||
# ESS.resource_db = ESSResourceDBMap.new()
|
|
||||||
ESS.resource_db = ESSResourceDBStatic.new()
|
|
||||||
ESS.resource_db.remap_ids = true
|
|
||||||
# ESS.load_all()
|
|
||||||
|
|
||||||
initialize_modules()
|
|
||||||
|
|
||||||
switch_scene(start_scene)
|
switch_scene(start_scene)
|
||||||
|
|
||||||
func initialize_modules() -> void:
|
|
||||||
_modules.clear()
|
|
||||||
|
|
||||||
load_modules_at("res://")
|
|
||||||
|
|
||||||
_modules.sort_custom(ModulePathSorter, "sort_ascending")
|
|
||||||
|
|
||||||
for module in _modules:
|
|
||||||
if module.has_method("load_module"):
|
|
||||||
module.load_module()
|
|
||||||
|
|
||||||
func load_modules_at(path : String) -> void:
|
|
||||||
var dir = Directory.new()
|
|
||||||
if dir.open(path) == OK:
|
|
||||||
dir.list_dir_begin()
|
|
||||||
var file_name = dir.get_next()
|
|
||||||
while file_name != "":
|
|
||||||
if file_name == "." or file_name == "..":
|
|
||||||
file_name = dir.get_next()
|
|
||||||
continue
|
|
||||||
|
|
||||||
if dir.current_is_dir():
|
|
||||||
if path == "res://":
|
|
||||||
load_modules_at(path + file_name)
|
|
||||||
else:
|
|
||||||
load_modules_at(path + "/" + file_name)
|
|
||||||
else:
|
|
||||||
if file_name == "game_module.tres":
|
|
||||||
var res : Resource = null
|
|
||||||
|
|
||||||
if path == "res://":
|
|
||||||
res = ResourceLoader.load(path + file_name)
|
|
||||||
else:
|
|
||||||
res = ResourceLoader.load(path + "/" + file_name)
|
|
||||||
|
|
||||||
_modules.append(res)
|
|
||||||
|
|
||||||
file_name = dir.get_next()
|
|
||||||
else:
|
|
||||||
print("An error occurred when trying to access the path: " + path)
|
|
||||||
|
|
||||||
func switch_scene(scene : int) -> void:
|
func switch_scene(scene : int) -> void:
|
||||||
if current_scene != null:
|
if current_scene != null:
|
||||||
for s in get_tree().get_nodes_in_group("save"):
|
for s in get_tree().get_nodes_in_group("save"):
|
||||||
@ -159,8 +108,3 @@ func show_loading_screen() -> void:
|
|||||||
func hide_loading_screen() -> void:
|
func hide_loading_screen() -> void:
|
||||||
_loading_screen.hide()
|
_loading_screen.hide()
|
||||||
|
|
||||||
class ModulePathSorter:
|
|
||||||
static func sort_ascending(a, b):
|
|
||||||
if a.resource_path < b.resource_path:
|
|
||||||
return true
|
|
||||||
return false
|
|
||||||
|
76
game/scripts/game_modules/DataManager.gd
Normal file
76
game/scripts/game_modules/DataManager.gd
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
extends Node
|
||||||
|
|
||||||
|
const PLAYER_UI_INSTANCE : int = 0
|
||||||
|
|
||||||
|
export(PackedScene) var player_ui : PackedScene
|
||||||
|
|
||||||
|
var _modules : Array
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
ProfileManager.load()
|
||||||
|
# ESS.resource_db = ESSResourceDBMap.new()
|
||||||
|
ESS.resource_db = ESSResourceDBStatic.new()
|
||||||
|
ESS.resource_db.remap_ids = true
|
||||||
|
# ESS.load_all()
|
||||||
|
|
||||||
|
initialize_modules()
|
||||||
|
|
||||||
|
func initialize_modules() -> void:
|
||||||
|
_modules.clear()
|
||||||
|
|
||||||
|
load_modules_at("res://")
|
||||||
|
|
||||||
|
_modules.sort_custom(ModulePathSorter, "sort_ascending")
|
||||||
|
|
||||||
|
for module in _modules:
|
||||||
|
if module.has_method("load_module"):
|
||||||
|
module.load_module()
|
||||||
|
|
||||||
|
func load_modules_at(path : String) -> void:
|
||||||
|
var dir = Directory.new()
|
||||||
|
if dir.open(path) == OK:
|
||||||
|
dir.list_dir_begin()
|
||||||
|
var file_name = dir.get_next()
|
||||||
|
while file_name != "":
|
||||||
|
if file_name == "." or file_name == "..":
|
||||||
|
file_name = dir.get_next()
|
||||||
|
continue
|
||||||
|
|
||||||
|
if dir.current_is_dir():
|
||||||
|
if path == "res://":
|
||||||
|
load_modules_at(path + file_name)
|
||||||
|
else:
|
||||||
|
load_modules_at(path + "/" + file_name)
|
||||||
|
else:
|
||||||
|
if file_name == "game_module.tres":
|
||||||
|
var res : Resource = null
|
||||||
|
|
||||||
|
if path == "res://":
|
||||||
|
res = ResourceLoader.load(path + file_name)
|
||||||
|
else:
|
||||||
|
res = ResourceLoader.load(path + "/" + file_name)
|
||||||
|
|
||||||
|
_modules.append(res)
|
||||||
|
|
||||||
|
file_name = dir.get_next()
|
||||||
|
else:
|
||||||
|
print("An error occurred when trying to access the path: " + path)
|
||||||
|
|
||||||
|
|
||||||
|
func request_instance(what : int) -> Node:
|
||||||
|
var inst : Node = null
|
||||||
|
|
||||||
|
if what == PLAYER_UI_INSTANCE:
|
||||||
|
inst = player_ui.instance()
|
||||||
|
|
||||||
|
for module in _modules:
|
||||||
|
# if module.has_method("on_request_instance"):
|
||||||
|
module.on_request_instance(what, inst)
|
||||||
|
|
||||||
|
return inst
|
||||||
|
|
||||||
|
class ModulePathSorter:
|
||||||
|
static func sort_ascending(a, b):
|
||||||
|
if a.resource_path < b.resource_path:
|
||||||
|
return true
|
||||||
|
return false
|
8
game/scripts/game_modules/DataManager.tscn
Normal file
8
game/scripts/game_modules/DataManager.tscn
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
[gd_scene load_steps=3 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://scripts/game_modules/DataManager.gd" type="Script" id=1]
|
||||||
|
[ext_resource path="res://ui/player_ui/player_ui.tscn" type="PackedScene" id=2]
|
||||||
|
|
||||||
|
[node name="DataManager" type="Node"]
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
player_ui = ExtResource( 2 )
|
@ -18,3 +18,6 @@ func load_module():
|
|||||||
# for s in r.get_spells():
|
# for s in r.get_spells():
|
||||||
# print(s.resource_name)
|
# print(s.resource_name)
|
||||||
# print(s.get_id())
|
# print(s.get_id())
|
||||||
|
|
||||||
|
func on_request_instance(what : int, node : Node) -> void:
|
||||||
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user