Finished basic PickupableItem
This commit is contained in:
parent
63e87e86d5
commit
88c56f8aed
21 changed files with 163 additions and 35 deletions
35
base/scripts/autoload/resource_handler.gd
Normal file
35
base/scripts/autoload/resource_handler.gd
Normal file
|
@ -0,0 +1,35 @@
|
|||
extends Node
|
||||
|
||||
## Dictionary, that holds resource id and path to it
|
||||
var resource_registry: Dictionary = {}
|
||||
|
||||
const DEFAULT_WEAPON_RESOURCE_ID: StringName = "weapon_base"
|
||||
|
||||
## Recursively add resources to registry
|
||||
func add_resource_path(_path: String) -> void:
|
||||
var dir = DirAccess.open(_path)
|
||||
if dir == null:
|
||||
return
|
||||
# Used to ignore last slash if it was provided in _path
|
||||
var path = dir.get_current_dir()
|
||||
for subdir in dir.get_directories():
|
||||
var subdir_path = "%s/%s" % [ path, subdir ]
|
||||
add_resource_path(subdir_path)
|
||||
|
||||
for filename in dir.get_files():
|
||||
if !filename.ends_with('.tres'):
|
||||
continue
|
||||
var filepath = "%s/%s" % [ path, filename ]
|
||||
var res: IdentifiedResource = ResourceLoader.load(filepath, 'IdentifiedResource')
|
||||
resource_registry[res.id] = filepath
|
||||
|
||||
func get_resource(id: String) -> IdentifiedResource:
|
||||
var path = resource_registry.get(id)
|
||||
if path == null:
|
||||
return null
|
||||
var res: IdentifiedResource = ResourceLoader.load(path, 'IdentifiedResource')
|
||||
return res
|
||||
|
||||
func _init() -> void:
|
||||
add_resource_path('res://base/assets/resources')
|
||||
assert(resource_registry.has(DEFAULT_WEAPON_RESOURCE_ID))
|
1
base/scripts/autoload/resource_handler.gd.uid
Normal file
1
base/scripts/autoload/resource_handler.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://b67umubha4odj
|
Loading…
Add table
Add a link
Reference in a new issue