Pre-Release
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
extends Node3D
|
||||
|
||||
const CONFIG_PATH = "user://weapons.scoom"
|
||||
const CONFIG_PATH = "weapons.cfg"
|
||||
const REVOLVER = 0
|
||||
const UZI = 1
|
||||
const CHAINSAW = 2
|
||||
@@ -9,8 +9,6 @@ var state = 0
|
||||
@onready var player_root = get_node("../../../../PlayerQ3") as CharacterBody3D
|
||||
@onready var raycast = get_node("../Camera3D/AimCast") as RayCast3D
|
||||
#@onready var crosshair = $Crosshair
|
||||
@onready var MainCam = get_node("../Camera3D")
|
||||
@onready var GunCam = get_node("../Camera3D/SubViewportContainer/SubViewport/GunCam")
|
||||
|
||||
|
||||
var weapons = []
|
||||
@@ -21,7 +19,23 @@ var sway_lerp = 5
|
||||
|
||||
func _ready():
|
||||
var config = load_data() as ConfigFile
|
||||
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
|
||||
@@ -29,9 +43,6 @@ func _ready():
|
||||
var old_parent = weapon_model.get_parent()
|
||||
old_parent.remove_child(weapon_model)
|
||||
|
||||
var mesh = weapon_model.get_child(0) as MeshInstance3D
|
||||
var mat = mesh.material_override as Material
|
||||
//TODO
|
||||
#Set Weapon nodes
|
||||
root.add_child(weapon_model)
|
||||
root.position = config.get_value(weapon, "HAND_POS")
|
||||
@@ -64,9 +75,6 @@ func _ready():
|
||||
root.RELOAD_TIME = config.get_value(weapon, "RELOAD_TIME")
|
||||
|
||||
weapons.append(root)
|
||||
weapons[current_weapon].init()
|
||||
raycast.target_position.z = -weapons[current_weapon].RAY_LEN
|
||||
|
||||
|
||||
func _input(event):
|
||||
if event is InputEventMouseMotion:
|
||||
@@ -93,7 +101,6 @@ func ChangeWeapon(i):
|
||||
|
||||
var time = 0
|
||||
func _process(delta):
|
||||
GunCam.global_transform = MainCam.global_transform
|
||||
if Input.is_action_pressed("shoot") && weapons[current_weapon].Shoot():
|
||||
if(weapons[current_weapon].HITSCAN):
|
||||
HitScan()
|
||||
@@ -132,18 +139,4 @@ func HitScan():
|
||||
func Projectile():
|
||||
pass
|
||||
|
||||
func load_data():
|
||||
var path = ""
|
||||
if(OS.has_feature("editor")):
|
||||
path = "/home/kookroach/Documents/Projects/Scoom_test/"
|
||||
else:
|
||||
path = OS.get_executable_path() + "/"
|
||||
|
||||
var config = ConfigFile.new()
|
||||
var err = config.load(path+"weapons.cfg")
|
||||
|
||||
if err != OK:
|
||||
printerr("FAILED LOADING WEAPONS DATA")
|
||||
|
||||
return config
|
||||
|
||||
|
||||
@@ -1,70 +1,72 @@
|
||||
extends Node
|
||||
var PATH = "res://scoom/"
|
||||
const ENTITY_CONFIG = "entity.cfg"
|
||||
|
||||
func _ready():
|
||||
if(not OS.has_feature("editor")):
|
||||
PATH = OS.get_executable_path().get_base_dir() + "/scoom/"
|
||||
|
||||
print(PATH)
|
||||
|
||||
func _input(event):
|
||||
if event is InputEventKey and event.is_pressed():
|
||||
if event.keycode == KEY_T:
|
||||
load_gltf("runtime_loader_test.glb")
|
||||
load_gltf("models/runtime_loader_test.glb")
|
||||
|
||||
func load_gltf(path, hasCollision = false, trimesh = false):
|
||||
func get_all_children(in_node, arr = []):
|
||||
arr.push_back(in_node)
|
||||
for child in in_node.get_children():
|
||||
arr = get_all_children(child,arr)
|
||||
return arr
|
||||
|
||||
func load_gltf(file, hasCollision = false, trimesh = false):
|
||||
var gltf := GLTFDocument.new()
|
||||
var gltf_state := GLTFState.new()
|
||||
|
||||
if(OS.has_feature("editor")):
|
||||
path = "/home/kookroach/Documents/Projects/Scoom_test/"+path
|
||||
else:
|
||||
path = OS.get_executable_path() + "/"+path
|
||||
|
||||
var snd_file = FileAccess.open(path, FileAccess.READ)
|
||||
var snd_file = FileAccess.open(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)
|
||||
print("Loading ", PATH + file)
|
||||
var node = gltf.generate_scene(gltf_state)
|
||||
var entity_count = 0;
|
||||
|
||||
for o in node.get_children():
|
||||
if o.name.begins_with("entity_"):
|
||||
print("Loading entity ",o.name)
|
||||
for o in get_all_children(node):
|
||||
if o.name.begins_with("entity_") && not o.name.ends_with("_geometry"):
|
||||
print("Loading entity ", o.name)
|
||||
if loadEntity(o):
|
||||
entity_count += 1;
|
||||
else:
|
||||
if(hasCollision):
|
||||
var meshInstance = node.get_child(0) as MeshInstance3D
|
||||
elif o is MeshInstance3D:
|
||||
if hasCollision:
|
||||
if(trimesh):
|
||||
meshInstance.create_trimesh_collision()
|
||||
o.create_trimesh_collision()
|
||||
else:
|
||||
meshInstance.create_convex_collision()
|
||||
|
||||
if(entity_count > 0):
|
||||
print("Loaded gltf/glb file with ", entity_count, " entities.")
|
||||
o.create_convex_collision()
|
||||
add_child(node)
|
||||
if(entity_count > 0):
|
||||
print("Loaded ", entity_count, " entities.")
|
||||
|
||||
return node
|
||||
|
||||
func loadEntity(node):
|
||||
var path = ""
|
||||
if(OS.has_feature("editor")):
|
||||
path = "/home/kookroach/Documents/Projects/Scoom_test/"
|
||||
else:
|
||||
path = OS.get_executable_path() + "/"
|
||||
|
||||
var config = ConfigFile.new()
|
||||
var err = config.load(path+"/entity_test.cfg")
|
||||
var err = config.load(PATH + ENTITY_CONFIG)
|
||||
|
||||
if err != OK:
|
||||
printerr("COULD NOT LOAD ENTITY : ", node.name)
|
||||
node.queue_free()
|
||||
return false
|
||||
|
||||
var x = config.get_section_keys(node.name)
|
||||
if(x.size() < 1):
|
||||
node.queue_free()
|
||||
printerr("NO CONFIG FOUND FOR ENTITY : ", node.name)
|
||||
return false
|
||||
|
||||
var entity = load_gltf(config.get_value(node.name, "model")) as Node3D
|
||||
entity.transform.origin = node.transform.origin
|
||||
entity.scale = (Vector3(1.5,1.5,1.5))
|
||||
|
||||
node.queue_free()
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user