Skip to content

Commit

Permalink
REFACTOR: Preliminary refactoring of paths
Browse files Browse the repository at this point in the history
  • Loading branch information
roalyr committed Nov 19, 2021
1 parent f38834f commit c66bf7f
Show file tree
Hide file tree
Showing 12 changed files with 174 additions and 196 deletions.
68 changes: 33 additions & 35 deletions Scenes/Main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ shader_param/albedo = Color( 0.541176, 0.721569, 1, 1 )
shader_param/uv1_scale = Vector3( 1, 1, 1 )
shader_param/uv1_offset = null

[node name="Cont" type="ViewportContainer"]
[node name="Container" type="ViewportContainer"]
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 1
Expand All @@ -80,6 +80,25 @@ __meta__ = {
"_edit_use_anchors_": false
}

[node name="Paths" type="Node" parent="."]
script = ExtResource( 16 )

[node name="Signals" type="Node" parent="."]
script = ExtResource( 10 )

[node name="Options" type="Node" parent="."]

[node name="Engine" type="Node" parent="Options"]
script = ExtResource( 12 )

[node name="Camera" type="Node" parent="Options"]
script = ExtResource( 8 )

[node name="Input" type="Node" parent="."]
script = ExtResource( 6 )

[node name="Ship_state" parent="." instance=ExtResource( 9 )]

[node name="UI" parent="." instance=ExtResource( 3 )]

[node name="View" type="Viewport" parent="."]
Expand All @@ -88,51 +107,30 @@ handle_input_locally = false
render_target_update_mode = 3
script = ExtResource( 13 )

[node name="Main" type="Spatial" parent="View"]
[node name="Global_space" type="Position3D" parent="View"]
script = ExtResource( 1 )

[node name="World" type="WorldEnvironment" parent="View/Main"]
[node name="Environment" type="WorldEnvironment" parent="View/Global_space"]
environment = ExtResource( 11 )

[node name="Paths" type="Node" parent="View/Main"]
script = ExtResource( 16 )

[node name="Options" type="Node" parent="View/Main"]

[node name="Engine" type="Node" parent="View/Main/Options"]
script = ExtResource( 12 )

[node name="Camera" type="Node" parent="View/Main/Options"]
script = ExtResource( 8 )
camera_near = 0.01
camera_fov = 60

[node name="Input" type="Node" parent="View/Main"]
script = ExtResource( 6 )
[node name="Starsphere" type="Position3D" parent="View/Global_space"]
script = ExtResource( 14 )

[node name="Signals" type="Node" parent="View/Main/Input"]
script = ExtResource( 10 )
[node name="1500 stars" type="MeshInstance" parent="View/Global_space/Starsphere"]
mesh = SubResource( 1 )
material/0 = SubResource( 2 )
material/1 = SubResource( 3 )
material/2 = SubResource( 4 )

[node name="Local_space" type="Position3D" parent="View/Main"]
[node name="Local_space" type="Position3D" parent="View/Global_space"]
__meta__ = {
"_edit_group_": true
}

[node name="System_Gate" parent="View/Main/Local_space" instance=ExtResource( 4 )]
[node name="System_Gate" parent="View/Global_space/Local_space" instance=ExtResource( 4 )]

[node name="Ship" parent="View/Main" instance=ExtResource( 5 )]
[node name="Ship" parent="View/Global_space" instance=ExtResource( 5 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.709, 0, 1.923 )

[node name="Camera_rig" parent="View/Main/Ship" instance=ExtResource( 2 )]
[node name="Camera_rig" parent="View/Global_space/Ship" instance=ExtResource( 2 )]
script = ExtResource( 7 )

[node name="Ship_state" parent="View/Main/Ship" instance=ExtResource( 9 )]

[node name="Starsphere" type="Position3D" parent="View/Main"]
script = ExtResource( 14 )

[node name="1500 stars" type="MeshInstance" parent="View/Main/Starsphere"]
mesh = SubResource( 1 )
material/0 = SubResource( 2 )
material/1 = SubResource( 3 )
material/2 = SubResource( 4 )
3 changes: 2 additions & 1 deletion Scripts/Camera_rig.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ var horiz = 0
var velocity_factor = 0
# Objects.
var mouse_vector = Vector2(0,0)

# Paths node.
var p = Node

func _ready():
# ============================ Initialize nodes ===========================
p = get_node("/root/Cont/View/Main/Paths")
p = get_node("/root/Container/Paths")
# ============================ Connect signals ============================
p.signals.connect("sig_turret_mode_on", self, "is_turret_mode_on")
# =========================================================================
Expand Down
68 changes: 31 additions & 37 deletions Scripts/Input.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,22 @@ var LMB_held = false
var LMB_released = true
var mouse_on_viewport = true


# Nodes.
var camera_rig = Node
var ship_state = Node
var signals = Node
var ui = Node
var ui_button_turret = Node
# Paths node.
var p = Node
var ui_controls_bar = Node
var ui_button_turret = Node

func _ready():
# ============================ Initialize nodes ===========================
camera_rig = get_node("/root/Cont/View/Main/Ship/Camera_rig")
ship_state = get_node("/root/Cont/View/Main/Ship/Ship_state")
signals = get_node("/root/Cont/View/Main/Input/Signals")
ui = get_node("/root/Cont/UI")
ui_controls_bar = get_node("/root/Cont/UI/Controls")
ui_button_turret = get_node("/root/Cont/UI/Controls/Button_turret")
p = get_node("/root/Container/Paths")
ui_controls_bar = p.ui.get_node("Controls")
ui_button_turret = p.ui.get_node("Controls/Button_turret")

# ============================ Connect signals ============================
signals.connect("sig_mouse_on_viewport", self, "is_mouse_on_viewport")
signals.connect("sig_viewport_update", self, "is_viewport_update")
signals.connect("sig_quit_game", self, "is_quit_game")
signals.connect("sig_turret_mode_on", self, "is_turret_mode_on")
p.signals.connect("sig_mouse_on_viewport", self, "is_mouse_on_viewport")
p.signals.connect("sig_viewport_update", self, "is_viewport_update")
p.signals.connect("sig_quit_game", self, "is_quit_game")
p.signals.connect("sig_turret_mode_on", self, "is_turret_mode_on")
# =========================================================================

# Initial value require for the mouse coords.
Expand Down Expand Up @@ -71,21 +65,21 @@ func _input(event):
# Camera orbiting is in the camera script.

# Camera zoom.
if event is InputEventMouseButton and ship_state.turret_mode:
camera_rig.zoom_camera(event)
if event is InputEventMouseButton and p.ship_state.turret_mode:
p.camera_rig.zoom_camera(event)

# ======================= For keyboard buttons =========================
if event is InputEventKey:

# ============================ UI Controls =========================
# Mouse flight.
if event.pressed and event.scancode == KEY_SPACE:
if ship_state.mouse_flight:
ship_state.mouse_flight = false
signals.emit_signal("sig_mouse_flight_on", false)
if p.ship_state.mouse_flight:
p.ship_state.mouse_flight = false
p.signals.emit_signal("sig_mouse_flight_on", false)
else:
ship_state.mouse_flight = true
signals.emit_signal("sig_mouse_flight_on", true)
p.ship_state.mouse_flight = true
p.signals.emit_signal("sig_mouse_flight_on", true)

# TODO: Should also be accessible from other areas and windows.
# Show toolbar.
Expand All @@ -98,45 +92,45 @@ func _input(event):

# Turret mode. UI shortcut. Signal is emitted by UI.
if event.pressed and event.scancode == KEY_H:
if not ship_state.turret_mode:
if not p.ship_state.turret_mode:
ui_button_turret.pressed = true
else: ui_button_turret.pressed = false

# ============================= Ship controls ======================
# Accelerate forward.
# TODO: unique signals for simultaneous action.
if event.pressed and event.scancode == KEY_UP:
signals.emit_signal("sig_accelerate", true)
p.signals.emit_signal("sig_accelerate", true)

# Accelerate backward.
if event.pressed and event.scancode == KEY_DOWN:
signals.emit_signal("sig_accelerate", false)
p.signals.emit_signal("sig_accelerate", false)

# TODO: sort out acceleration WSAD keys
# Accelerate left sgtrafe.
if event.pressed and event.scancode == KEY_A:
signals.emit_signal("sig_accelerate", Vector3(1, 0, 0))
p.signals.emit_signal("sig_accelerate", Vector3(1, 0, 0))

# Accelerate right strafe.
if event.pressed and event.scancode == KEY_D:
signals.emit_signal("sig_accelerate", Vector3(-1, 0, 0))
p.signals.emit_signal("sig_accelerate", Vector3(-1, 0, 0))

# Accelerate up strafe.
if event.pressed and event.scancode == KEY_W:
signals.emit_signal("sig_accelerate", Vector3(0, -1, 0))
p.signals.emit_signal("sig_accelerate", Vector3(0, -1, 0))

# Accelerate down strafe.
if event.pressed and event.scancode == KEY_S:
signals.emit_signal("sig_accelerate", Vector3(0, 1, 0))
p.signals.emit_signal("sig_accelerate", Vector3(0, 1, 0))

# Accelerate down strafe.
if event.pressed and event.scancode == KEY_Z:
if not ship_state.engine_kill:
ship_state.engine_kill = true
signals.emit_signal("sig_engine_kill", true)
if not p.ship_state.engine_kill:
p.ship_state.engine_kill = true
p.signals.emit_signal("sig_engine_kill", true)
else:
ship_state.engine_kill = false
signals.emit_signal("sig_engine_kill", false)
p.ship_state.engine_kill = false
p.signals.emit_signal("sig_engine_kill", false)
# =================== For events outside of 3D viewport ===================
# Mouse not over 3D viewport.
else:
Expand Down Expand Up @@ -172,5 +166,5 @@ func is_quit_game():
get_tree().quit()

func is_turret_mode_on(flag):
ship_state.turret_mode = flag
p.ship_state.turret_mode = flag

2 changes: 1 addition & 1 deletion Scripts/Main.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extends Spatial
extends Position3D

var fps = 0

Expand Down
7 changes: 0 additions & 7 deletions Scripts/Mesh_rotation.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ export var rotation_speed_x = 0.0
export var rotation_speed_y = 0.0
export var rotation_speed_z = 0.0

# Nodes.
var engine_opts = Node

func _ready():
# ============================ Initialize nodes ===========================
engine_opts = get_node("/root/Cont/View/Main/Options/Engine")


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta):
Expand Down
6 changes: 3 additions & 3 deletions Scripts/Options/Camera.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ extends Node

# TODO: make a function to cap values and pass those through it.
export var camera_far = 500000 # 1000000 is a hard cap.
export var camera_near = 0.05 # 0.01 is a hard cap.
export var camera_fov = 40 # Is added to bounding box axis value.
export var camera_near = 0.03 # 0.01 is a hard cap.
export var camera_fov = 60 # Is added to bounding box axis value.
export var camera_inertia_factor = 1.1 # 1.05 ... 1.5 Affects camera inertia.
export var camera_sensitivity = 3 # 0.1 ... 0.5
export var camera_turret_roll_vert_limit = 70 # Deg +\-
Expand All @@ -16,7 +16,7 @@ var p = Node

func _ready():
# ============================ Initialize nodes ===========================
p = get_node("/root/Cont/View/Main/Paths")
p = get_node("/root/Container/Paths")
# ============================ Connect signals ============================
p.signals.connect("sig_fov_value_changed", self, "is_fov_value_changed")
# =========================================================================
Expand Down
27 changes: 20 additions & 7 deletions Scripts/Paths.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,32 @@ extends Node

# Nodes.
var camera = Node
var camera_rig = Node
var cam_opts = Node
var engine_opts = Node
var global_space = Node
var input = Node
var local_space = Node
var signals = Node
var ship_state = Node
var ship = Node
var ui = Node
var viewport = Node

func _ready():
# ============================ Initialize nodes ===========================
camera = get_node("/root/Cont/View/Main/Ship/Camera_rig/Camera")
cam_opts = get_node("/root/Cont/View/Main/Options/Camera")
input = get_node("/root/Cont/View/Main/Input")
signals = get_node("/root/Cont/View/Main/Input/Signals")
ship_state = get_node("/root/Cont/View/Main/Ship/Ship_state")
ship = get_node("/root/Cont/View/Main/Ship")
ui = get_node("/root/Cont/UI")
camera = get_node("/root/Container/View/Global_space/Ship/Camera_rig/Camera")
camera_rig = get_node("/root/Container/View/Global_space/Ship/Camera_rig")
cam_opts = get_node("/root/Container/Options/Camera")
engine_opts = get_node("/root/Container/Options/Engine")
global_space = get_node("/root/Container/View/Global_space")
input = get_node("/root/Container/Input")
local_space = get_node("/root/Container/View/Global_space/Local_space")
signals = get_node("/root/Container/Signals")
ship_state = get_node("/root/Container/Ship_state")
ship = get_node("/root/Container/View/Global_space/Ship")
ui = get_node("/root/Container/UI")
viewport = get_node("/root/Container/View")



Loading

0 comments on commit c66bf7f

Please sign in to comment.