83 lines
2.1 KiB
GDScript
83 lines
2.1 KiB
GDScript
extends Spatial
|
|
|
|
# export variables
|
|
export(NodePath) var outline_path
|
|
export(NodePath) var mesh_path
|
|
export(NodePath) var color_cast_left
|
|
export(NodePath) var color_cast_up
|
|
export(bool) var can_turn
|
|
export(bool) var is_turned
|
|
export(int) var x_rot
|
|
export(int) var y_rot
|
|
export(int) var z_rot
|
|
export(Color) var content_color
|
|
|
|
# signals
|
|
signal flow_changed
|
|
|
|
# constant variables
|
|
const NULL_COLOR = Color(0, 0, 0, 1)
|
|
|
|
# private variables
|
|
var _left_cast : RayCast
|
|
var _up_cast : RayCast
|
|
var _left_color : Color
|
|
var _up_color : Color
|
|
var _mesh : MeshInstance
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
_left_cast = get_node(color_cast_left) as RayCast
|
|
_up_cast = get_node(color_cast_up) as RayCast
|
|
_mesh = get_node(mesh_path) as MeshInstance
|
|
|
|
func do_interact(var player):
|
|
if(is_turned):
|
|
rotate_x(x_rot * PI/180)
|
|
rotate_y(y_rot * PI/180)
|
|
rotate_z(z_rot * PI/180)
|
|
is_turned = false;
|
|
else:
|
|
rotate_x(-x_rot * PI/180)
|
|
rotate_y(-y_rot * PI/180)
|
|
rotate_z(-z_rot * PI/180)
|
|
is_turned = true;
|
|
emit_signal("flow_changed")
|
|
|
|
func _get_color_from_cast(ray_cast : RayCast):
|
|
if ray_cast.is_colliding():
|
|
var collider = ray_cast.get_collider()
|
|
if collider.is_in_group("Pipes"):
|
|
var new_color = collider.content_color
|
|
if new_color != null:
|
|
return new_color
|
|
|
|
func update_content_color():
|
|
if _left_cast != null:
|
|
var new_color = _get_color_from_cast(_left_cast)
|
|
if new_color != null:
|
|
_left_color = new_color
|
|
if _up_cast != null:
|
|
var new_color = _get_color_from_cast(_up_cast)
|
|
if new_color != null:
|
|
_up_color = new_color
|
|
|
|
if _left_color != NULL_COLOR and _up_color != NULL_COLOR:
|
|
pass
|
|
elif _left_color != NULL_COLOR:
|
|
content_color = _left_color
|
|
elif _up_color != NULL_COLOR:
|
|
content_color = _up_color
|
|
|
|
if content_color != NULL_COLOR:
|
|
if _mesh != null:
|
|
var material = _mesh.get_surface_material(0)
|
|
if material == null:
|
|
material = SpatialMaterial.new()
|
|
_mesh.material_override = material
|
|
material.albedo_color = content_color
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
#func _process(delta):
|
|
# pass
|