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

25
Game.gd
View File

@@ -1,5 +1,5 @@
extends Node3D
class_name Game
@onready var label : Label = $CanvasLayer/Label
@onready var player : CharacterBody3D = $PlayerQ3
@@ -7,17 +7,22 @@ extends Node3D
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
#var packer = PCKPacker.new()
#packer.pck_start("test_map.pck")
#packer.add_file("res://test_map.scn", "res://scoom/maps/test_maps.scn")
#packer.flush(true)
Runtimeloader.loadPCK("maps/test_map.pck", self)
var config = Runtimeloader.loadConfig("init.cfg") as ConfigFile
var res = load("res://test_maps.scn") as PackedScene
var node = res.instantiate()
add_child(node)
Runtimeloader.get_all_entities(node)
print("Loading PCK...")
for map_list in config.get_section_keys("MAPS"):
for map in config.get_value("MAPS", map_list):
Runtimeloader.loadPCK(map)
for weapons_list in config.get_section_keys("WEAPONS"):
for weapon in config.get_value("WEAPONS", weapons_list):
Runtimeloader.loadPCK(weapon)
print("Loading Resources Done.")
Runtimeloader.loadScene("maps/test_map.tscn", self)
#Runtimeloader.get_all_entities(node)
func _process(_delta):

View File

@@ -9,6 +9,11 @@
config_version=5
_global_script_classes=[{
"base": "Node3D",
"class": &"Game",
"language": &"GDScript",
"path": "res://Game.gd"
}, {
"base": "Node",
"class": &"Hitable",
"language": &"GDScript",
@@ -25,6 +30,7 @@ _global_script_classes=[{
"path": "res://scripts/player/Weapon.gd"
}]
_global_script_class_icons={
"Game": "",
"Hitable": "",
"TBPlugin": "",
"Weapon": ""

View File

@@ -12,7 +12,6 @@ grow_vertical = 2
metadata/_edit_use_anchors_ = true
[node name="VBoxContainer" type="VBoxContainer" parent="."]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
@@ -26,16 +25,21 @@ grow_horizontal = 2
grow_vertical = 2
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
layout_mode = 2
offset_left = 102.0
offset_right = 295.0
offset_bottom = 31.0
size_flags_horizontal = 4
size_flags_vertical = 2
[node name="Start" type="Button" parent="VBoxContainer/HBoxContainer"]
layout_mode = 2
offset_right = 96.0
offset_bottom = 31.0
text = "Start Game"
[node name="ModsMenu" type="MenuButton" parent="VBoxContainer/HBoxContainer"]
layout_mode = 2
offset_left = 100.0
offset_right = 193.0
offset_bottom = 31.0
text = "Select Mod"
flat = false
item_count = 2
@@ -45,15 +49,21 @@ popup/item_1/text = "test2"
popup/item_1/id = 1
[node name="VBoxContainer2" type="VBoxContainer" parent="VBoxContainer"]
layout_mode = 2
offset_left = 138.0
offset_top = 102.0
offset_right = 258.0
offset_bottom = 168.0
size_flags_horizontal = 4
size_flags_vertical = 10
[node name="SettingsButton" type="Button" parent="VBoxContainer/VBoxContainer2"]
layout_mode = 2
offset_right = 120.0
offset_bottom = 31.0
text = "Game Settings"
icon_alignment = 1
[node name="ExitButton" type="Button" parent="VBoxContainer/VBoxContainer2"]
layout_mode = 2
offset_top = 35.0
offset_right = 120.0
offset_bottom = 66.0
text = "Exit"

View File

@@ -1,21 +1,21 @@
[gd_scene load_steps=11 format=3 uid="uid://bq7p576e7a17i"]
[ext_resource type="Texture2D" uid="uid://bx4pdgghucl4k" path="res://textures/concrete_15.jpg" id="3_0q1g3"]
[ext_resource type="Texture2D" uid="uid://bj2qm3joiywso" path="res://textures/dark.png" id="4_mcb4j"]
[ext_resource type="Texture2D" uid="uid://bt671xkej3a2s" path="res://textures/shipping_container_01_side.jpg" id="5_wj0e7"]
[ext_resource type="Texture2D" uid="uid://c52qu6ad3taix" path="res://textures/shipping_container_01_front.jpg" id="6_g7sga"]
[ext_resource type="Texture2D" uid="uid://bx4pdgghucl4k" path="res://textures/concrete_15.jpg" id="1_os4mo"]
[ext_resource type="Texture2D" uid="uid://bj2qm3joiywso" path="res://textures/dark.png" id="2_53atb"]
[ext_resource type="Texture2D" uid="uid://bt671xkej3a2s" path="res://textures/shipping_container_01_side.jpg" id="3_am21j"]
[ext_resource type="Texture2D" uid="uid://c52qu6ad3taix" path="res://textures/shipping_container_01_front.jpg" id="4_tpukd"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_yhpph"]
albedo_texture = ExtResource("3_0q1g3")
albedo_texture = ExtResource("1_os4mo")
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_plg37"]
albedo_texture = ExtResource("4_mcb4j")
albedo_texture = ExtResource("2_53atb")
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_8xybu"]
albedo_texture = ExtResource("5_wj0e7")
albedo_texture = ExtResource("3_am21j")
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_rri1d"]
albedo_texture = ExtResource("6_g7sga")
albedo_texture = ExtResource("4_tpukd")
[sub_resource type="ArrayMesh" id="ArrayMesh_bdgr3"]
lightmap_size_hint = Vector2i(2802, 2814)

2
scoom

Submodule scoom updated: 10f7ee46ae...59e32bcbad

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