extend PCK support

This commit is contained in:
2023-01-03 01:00:11 +01:00
parent 4c8499f4f0
commit b5286a5f54
8 changed files with 95 additions and 50 deletions

View File

@@ -67,8 +67,8 @@ func Shoot():
tween.set_ease(Tween.EASE_OUT)
tween.set_parallel(true)
tween.tween_property(MODEL, "position", Vector3(.0, MOMENTUM.x, MOMENTUM.y), RECOIL_COOLDOWN / 2)
var rand_rot_y = randi_range(-ANGULAR_MOMENTUM.y,ANGULAR_MOMENTUM.y)
var rand_rot_z = randi_range(-ANGULAR_MOMENTUM.z,ANGULAR_MOMENTUM.z)
var rand_rot_y = randf_range(-ANGULAR_MOMENTUM.y,ANGULAR_MOMENTUM.y)
var rand_rot_z = randf_range(-ANGULAR_MOMENTUM.z,ANGULAR_MOMENTUM.z)
tween.tween_property(MODEL, "rotation", Vector3(deg_to_rad(ANGULAR_MOMENTUM.x),deg_to_rad(rand_rot_y),deg_to_rad(rand_rot_z)),RECOIL_COOLDOWN /2)
tween.tween_callback(InitialPos).set_delay(SHOOTING_SPEED / 2)
return true

View File

@@ -18,28 +18,32 @@ var mouse_mov : Vector3
var sway_lerp = 5
func _ready():
var config = load_data() as ConfigFile
Init_Config(config)
get_tree().get_current_scene().ready.connect(init)
func init():
var config = Runtimeloader.loadConfig(CONFIG_PATH) as ConfigFile
if(config == null):
return
Init_Config(config)
weapons[current_weapon].init()
raycast.target_position.z = -weapons[current_weapon].RAY_LEN
func load_data():
var path = Runtimeloader.PATH
var config = ConfigFile.new()
var err = config.load(path + CONFIG_PATH)
if err != OK:
printerr("FAILED LOADING WEAPONS DATA @ ",path + CONFIG_PATH)
return config
func Init_Config(config):
for weapon in config.get_sections():
var root = Weapon.new()
root.name = weapon
var weapon_model = Runtimeloader.load_gltf(config.get_value(weapon, "MODEL"), root) as Node3D
var model_path = config.get_value(weapon, "MODEL") as String
var weapon_model
if(model_path.ends_with(".glb") or model_path.ends_with(".gltf")):
weapon_model = Runtimeloader.load_gltf(model_path, root) as Node3D
elif(model_path.ends_with(".tscn") or model_path.ends_with(".scn")):
weapon_model = Runtimeloader.loadScene(model_path, root)
else:
printerr("Invalid file extension for "+ model_path)
continue
root.position = config.get_value(weapon, "HAND_POS")
root.rotation = config.get_value(weapon, "HAND_ROT")

View File

@@ -7,7 +7,6 @@ func _ready():
if(not OS.has_feature("editor")):
EXTERNAL_PATH = OS.get_executable_path().get_base_dir() + "/scoom/"
func _input(event):
if event is InputEventKey and event.is_pressed():
if event.keycode == KEY_T:
@@ -20,17 +19,21 @@ func get_all_children(in_node, arr = []):
return arr
func load_gltf(file, parent = self, hasCollision = false, trimesh = false):
if(file == null):
printerr("No model provided to load")
return
var gltf := GLTFDocument.new()
var gltf_state := GLTFState.new()
var snd_file = FileAccess.open(PATH + file, FileAccess.READ)
var snd_file = FileAccess.open(EXTERNAL_PATH + file, FileAccess.READ)
var fileBytes = PackedByteArray()
fileBytes = snd_file.get_buffer(snd_file.get_length())
gltf.append_from_buffer(fileBytes, "", gltf_state)
print("Loading ", PATH + file)
print("Loading ", EXTERNAL_PATH + file)
var node = gltf.generate_scene(gltf_state)
var entity_count = 0;
for o in get_all_children(node):
@@ -67,21 +70,38 @@ func loadEntity(node):
printerr("COULD NOT LOAD ENTITY : ", node.name)
return false
var x = config.get_section_keys(node.name)
if(x.size() < 1):
if(not config.has_section(node.name)):
printerr("NO CONFIG FOUND FOR ENTITY : ", node.name)
return false
var entity = load_gltf(config.get_value(node.name, "model"), node.get_parent()) as Node3D
if(entity == null):
printerr("ENTITY COULD NOT BE CREATED : ", node.name)
return false
entity.transform.origin = node.transform.origin
entity.scale = config.get_value(node.name, "scale")
node.queue_free()
return true
func loadPCK(file, parent = self):
func loadPCK(file):
var success = ProjectSettings.load_resource_pack(EXTERNAL_PATH + file)
if success:
print("Resource pack loaded ", EXTERNAL_PATH + file)
func loadConfig(file):
var config = ConfigFile.new()
var err = config.load(EXTERNAL_PATH + file)
if err != OK:
printerr("FAILED LOADING CONFIG DATA @ ",EXTERNAL_PATH + file)
return config
func loadScene(file, parent = self):
var res = load(PATH + file) as PackedScene
var scene = res.instantiate()
get_all_entities(scene)
parent.add_child(scene)
return scene