Skip to content
This repository was archived by the owner on Nov 5, 2023. It is now read-only.

Commit

Permalink
VehicleSelect: Detect PaintPalette
Browse files Browse the repository at this point in the history
  • Loading branch information
CodedOre committed Aug 4, 2021
1 parent 57850f0 commit c5e2851
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 6 deletions.
7 changes: 7 additions & 0 deletions scripts/game/VehicleSelect.gd
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ func select_vehicle(index: int, fast: bool = false) -> void:
next_button.disabled = true if selected_vehicle == vehicle_lenght else false
name_label.text = vehicle_pool[selected_vehicle].VehicleName
info_label.text = vehicle_pool[selected_vehicle].VehicleInfo
# Set paint options
color_option.clear()
var palette : PaintPalette = vehicle_pool[selected_vehicle].PaintPalette
for paint in palette.PaintPalette:
var name : String = paint.resource_path.get_file().trim_suffix('.material')
color_option.add_item(name)
color_option.select(vehicle_pool[selected_vehicle].VehiclePaint)

# - Signals changes to 'Main'
func return_to_main() -> void:
Expand Down
34 changes: 28 additions & 6 deletions scripts/vehicles/Vehicle.gd
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ const MIN_CRUISE_SPEED : int = 25
export (String) var VehicleName
export (String) var VehicleInfo
export (Resource) var Data

# - Data to recolor the vehicle -
export (Resource) var PaintPalette
export (int) var VehiclePaint setget set_paint, get_paint

# - NodePaths from the Vehicle -
export (Array, NodePath) onready var Paintable
export (Array, NodePath) onready var Lights
export (Array, NodePath) onready var Cameras
export (NodePath) onready var OuterMirrorPoint
Expand All @@ -43,14 +47,16 @@ export (bool) var Controlled = false
var current_speed : float = 0.0
var _current_mps : float = 0
var _engine_rpm : int = 0
var _current_paint : int = 0

# - Internal objects -
var _light_manager : VehicleLightsManager
var _pid_controller : PIDController
var _light_nodes : Array = Array()
var _camera_nodes : Array = Array()
var _steer_wheel : MeshInstance
var _traction_wheel : VehicleWheel
var _light_manager : VehicleLightsManager
var _pid_controller : PIDController
var _light_nodes : Array = Array()
var _camera_nodes : Array = Array()
var _paintable_nodes : Array = Array()
var _steer_wheel : MeshInstance
var _traction_wheel : VehicleWheel

# - Camera variables -
var _camera_count : int
Expand Down Expand Up @@ -95,6 +101,14 @@ func _ready() -> void:
if Data == null:
push_error("Vehicle: Could not initialize vehicle without VehicleData!")
return
# Initialize Paintable
for path in Paintable:
var mesh = get_node(path)
if ! mesh is MeshInstance:
push_error("Vehicle: Paintable need to be a MeshInstance!")
continue
_paintable_nodes.append(mesh)
set_paint(_current_paint)
# Initialize VehicleLightManager
for path in Lights:
_light_nodes.append(get_node(path))
Expand Down Expand Up @@ -420,3 +434,11 @@ func _inform_camera() -> void:
_camera_point.state_request = CameraPoint.RequestState.BEHIND
else:
_camera_point.state_request = CameraPoint.RequestState.NONE

func set_paint(index : int) -> void:
_current_paint = index
for mesh in _paintable_nodes:
mesh.material_override = PaintPalette.PaintPalette[index]

func get_paint() -> int:
return _current_paint
1 change: 1 addition & 0 deletions vehicles/scenes/Ambulance.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ VehicleName = "Ambulance"
VehicleInfo = "A vehicle to respond to medical emergencies."
Data = ExtResource( 10 )
PaintPalette = ExtResource( 12 )
Paintable = [ NodePath("VehicleBody") ]
Lights = [ NodePath("VehicleBody/LightFrontLeft"), NodePath("VehicleBody/LightFrontRight"), NodePath("VehicleBody/LightRearLeft"), NodePath("VehicleBody/LightRearRight"), NodePath("VehicleBody/LightReverseLeft"), NodePath("VehicleBody/LightReverseRight"), NodePath("VehicleBody/LightTurningFrontLeft"), NodePath("VehicleBody/LightTurningFrontRight"), NodePath("VehicleBody/LightTurningRearLeft"), NodePath("VehicleBody/LightTurningRearRight") ]
Cameras = [ NodePath("CameraPoints/ChaseCamera"), NodePath("CameraPoints/DriverCamera") ]
OuterMirrorPoint = NodePath("MirrorPoints/OuterMirror")
Expand Down
2 changes: 2 additions & 0 deletions vehicles/scenes/Compact.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ VehicleName = "Compact"
VehicleInfo = "Small in size, great in usefullness."
Data = ExtResource( 2 )
PaintPalette = ExtResource( 12 )
VehiclePaint = 1
Paintable = [ NodePath("VehicleBody") ]
Lights = [ NodePath("VehicleBody/LightFrontLeft"), NodePath("VehicleBody/LightFrontRight"), NodePath("VehicleBody/LightFrontSmallLeft"), NodePath("VehicleBody/LightFrontSmallRight"), NodePath("VehicleBody/LightRearLeft"), NodePath("VehicleBody/LightRearRight"), NodePath("VehicleBody/LightRearSmallLeft"), NodePath("VehicleBody/LightRearSmallRight"), NodePath("VehicleBody/LightReverseLeft"), NodePath("VehicleBody/LightReverseRight"), NodePath("VehicleBody/LightTurningFrontLeft"), NodePath("VehicleBody/LightTurningFrontRight"), NodePath("VehicleBody/LightTurningRearLeft"), NodePath("VehicleBody/LightTurningRearRight"), NodePath("VehicleBody/LightBrakeLight") ]
Cameras = [ NodePath("CameraPoints/ChaseCamera"), NodePath("CameraPoints/DriverCamera") ]
OuterMirrorPoint = NodePath("MirrorPoints/OuterMirror")
Expand Down
2 changes: 2 additions & 0 deletions vehicles/scenes/Muscle.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ VehicleName = "Muscle"
VehicleInfo = "Classic, fast and powerful.\\nThe ideal car for car-based sports."
Data = ExtResource( 10 )
PaintPalette = ExtResource( 12 )
VehiclePaint = 1
Paintable = [ NodePath("VehicleBody") ]
Lights = [ NodePath("VehicleBody/LightFrontLeft"), NodePath("VehicleBody/LightFrontRight"), NodePath("VehicleBody/LightFrontSmallLeft"), NodePath("VehicleBody/LightFrontSmallRight"), NodePath("VehicleBody/LightRearLeftOne"), NodePath("VehicleBody/LightRearLeftTwo"), NodePath("VehicleBody/LightRearRightOne"), NodePath("VehicleBody/LightRearRightTwo"), NodePath("VehicleBody/LightRearSmallLeft"), NodePath("VehicleBody/LightRearSmallRight"), NodePath("VehicleBody/LightReverseLeft"), NodePath("VehicleBody/LightReverseRight"), NodePath("VehicleBody/LightTurningFrontLeft"), NodePath("VehicleBody/LightTurningFrontRight"), NodePath("VehicleBody/LightTurningRearLeft"), NodePath("VehicleBody/LightTurningRearRight") ]
Cameras = [ NodePath("CameraPoints/ChaseCamera"), NodePath("CameraPoints/DriverCamera") ]
OuterMirrorPoint = NodePath("MirrorPoints/OuterMirror")
Expand Down
1 change: 1 addition & 0 deletions vehicles/scenes/Police.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ VehicleName = "Police"
VehicleInfo = "The iconic vehicle to prevent crime on the streets."
Data = ExtResource( 12 )
PaintPalette = ExtResource( 9 )
Paintable = [ NodePath("VehicleBody") ]
Lights = [ NodePath("VehicleBody/LightBrakeLight"), NodePath("VehicleBody/LightFrontLeft"), NodePath("VehicleBody/LightFrontRight"), NodePath("VehicleBody/LightRearLeft"), NodePath("VehicleBody/LightRearRight"), NodePath("VehicleBody/LightReverseLeft"), NodePath("VehicleBody/LightReverseRight"), NodePath("VehicleBody/LightTurningLeft"), NodePath("VehicleBody/LightTurningRight") ]
Cameras = [ NodePath("CameraPoints/ChaseCamera"), NodePath("CameraPoints/DriverCamera") ]
OuterMirrorPoint = NodePath("MirrorPoints/OuterMirror")
Expand Down
2 changes: 2 additions & 0 deletions vehicles/scenes/SUV.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ VehicleName = "SUV"
VehicleInfo = "A modern car for modern roads with an modern size."
Data = ExtResource( 10 )
PaintPalette = ExtResource( 12 )
VehiclePaint = 1
Paintable = [ NodePath("VehicleBody") ]
Lights = [ NodePath("VehicleBody/LightFrontLeft"), NodePath("VehicleBody/LightFrontRight"), NodePath("VehicleBody/LightFrontSmallLeft"), NodePath("VehicleBody/LightFrontSmallRight"), NodePath("VehicleBody/LightRearLeft"), NodePath("VehicleBody/LightRearRight"), NodePath("VehicleBody/LightRearSmallLeft"), NodePath("VehicleBody/LightRearSmallRight"), NodePath("VehicleBody/LightReverseLeft"), NodePath("VehicleBody/LightReverseRight"), NodePath("VehicleBody/LightTurningFrontLeft"), NodePath("VehicleBody/LightTurningFrontRight"), NodePath("VehicleBody/LightTurningRearLeft"), NodePath("VehicleBody/LightTurningRearRight"), NodePath("VehicleBody/LightBrakeLight") ]
Cameras = [ NodePath("CameraPoints/ChaseCamera"), NodePath("CameraPoints/DriverCamera") ]
OuterMirrorPoint = NodePath("MirrorPoints/OuterMirror")
Expand Down
2 changes: 2 additions & 0 deletions vehicles/scenes/Sedan.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ VehicleName = "Sedan"
VehicleInfo = "A classic, mid-sized vehicle for all cases."
Data = ExtResource( 12 )
PaintPalette = ExtResource( 8 )
VehiclePaint = 1
Paintable = [ NodePath("VehicleBody") ]
Lights = [ NodePath("VehicleBody/LightBrakeLight"), NodePath("VehicleBody/LightFrontLeft"), NodePath("VehicleBody/LightFrontRight"), NodePath("VehicleBody/LightRearLeft"), NodePath("VehicleBody/LightRearRight"), NodePath("VehicleBody/LightReverseLeft"), NodePath("VehicleBody/LightReverseRight"), NodePath("VehicleBody/LightTurningLeft"), NodePath("VehicleBody/LightTurningRight") ]
Cameras = [ NodePath("CameraPoints/ChaseCamera"), NodePath("CameraPoints/DriverCamera") ]
OuterMirrorPoint = NodePath("MirrorPoints/OuterMirror")
Expand Down
1 change: 1 addition & 0 deletions vehicles/scenes/Taxi.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ VehicleName = "Taxi"
VehicleInfo = "The classic cab you call so you get stuck in traffic jam without even driving."
Data = ExtResource( 12 )
PaintPalette = ExtResource( 9 )
Paintable = [ NodePath("VehicleBody") ]
Lights = [ NodePath("VehicleBody/LightBrakeLight"), NodePath("VehicleBody/LightFrontLeft"), NodePath("VehicleBody/LightFrontRight"), NodePath("VehicleBody/LightRearLeft"), NodePath("VehicleBody/LightRearRight"), NodePath("VehicleBody/LightReverseLeft"), NodePath("VehicleBody/LightReverseRight"), NodePath("VehicleBody/LightTurningLeft"), NodePath("VehicleBody/LightTurningRight") ]
Cameras = [ NodePath("CameraPoints/ChaseCamera"), NodePath("CameraPoints/DriverCamera") ]
OuterMirrorPoint = NodePath("MirrorPoints/OuterMirror")
Expand Down
2 changes: 2 additions & 0 deletions vehicles/scenes/Van.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ VehicleName = "Van"
VehicleInfo = "Enough space to carry anything you might need to transport."
Data = ExtResource( 10 )
PaintPalette = ExtResource( 12 )
VehiclePaint = 1
Paintable = [ NodePath("VehicleBody") ]
Lights = [ NodePath("VehicleBody/LightFrontLeft"), NodePath("VehicleBody/LightFrontRight"), NodePath("VehicleBody/LightRearLeft"), NodePath("VehicleBody/LightRearRight"), NodePath("VehicleBody/LightReverseLeft"), NodePath("VehicleBody/LightReverseRight"), NodePath("VehicleBody/LightTurningFrontLeft"), NodePath("VehicleBody/LightTurningFrontRight"), NodePath("VehicleBody/LightTurningRearLeft"), NodePath("VehicleBody/LightTurningRearRight") ]
Cameras = [ NodePath("CameraPoints/ChaseCamera"), NodePath("CameraPoints/DriverCamera") ]
OuterMirrorPoint = NodePath("MirrorPoints/OuterMirror")
Expand Down

0 comments on commit c5e2851

Please sign in to comment.