2020-07-07 00:47:29 +00:00
|
|
|
tool
|
|
|
|
|
|
|
|
extends Area2D
|
|
|
|
|
2020-07-07 11:01:12 +00:00
|
|
|
class_name GameObjectLightbulb
|
|
|
|
|
2020-07-07 00:47:29 +00:00
|
|
|
enum Direction { LEFT, RIGHT, UP, DOWN }
|
|
|
|
|
|
|
|
export(Direction) var direction = Direction.DOWN setget set_direction
|
|
|
|
export var lit = true setget set_lit
|
|
|
|
|
2020-07-07 07:40:20 +00:00
|
|
|
onready var activationRange = $ActivationRange as ActivationRange
|
|
|
|
|
2020-07-07 00:47:29 +00:00
|
|
|
func _ready():
|
2020-07-07 08:38:32 +00:00
|
|
|
if not Engine.editor_hint:
|
|
|
|
activationRange.visible = true
|
2020-07-07 00:47:29 +00:00
|
|
|
|
|
|
|
func set_direction(dir):
|
|
|
|
direction = dir
|
|
|
|
refresh_sprite()
|
|
|
|
|
|
|
|
func set_lit(val):
|
|
|
|
lit = val
|
|
|
|
$Light2D.enabled = val
|
|
|
|
refresh_sprite()
|
|
|
|
|
|
|
|
func refresh_sprite():
|
2020-07-07 07:40:20 +00:00
|
|
|
var rot = 0
|
2020-07-07 00:47:29 +00:00
|
|
|
var lit_offset = 0
|
|
|
|
if not lit:
|
|
|
|
lit_offset = 32
|
|
|
|
match direction:
|
|
|
|
Direction.DOWN:
|
|
|
|
$light.region_rect.position = Vector2(32, lit_offset)
|
2020-07-07 07:40:20 +00:00
|
|
|
rot =0
|
2020-07-07 00:47:29 +00:00
|
|
|
Direction.UP:
|
|
|
|
$light.region_rect.position = Vector2(0, lit_offset)
|
2020-07-07 07:40:20 +00:00
|
|
|
rot = PI
|
2020-07-07 00:47:29 +00:00
|
|
|
Direction.LEFT:
|
|
|
|
$light.region_rect.position = Vector2(96, lit_offset)
|
2020-07-07 12:20:04 +00:00
|
|
|
rot = -PI/2
|
2020-07-07 00:47:29 +00:00
|
|
|
Direction.RIGHT:
|
|
|
|
$light.region_rect.position = Vector2(64, lit_offset)
|
2020-07-07 12:20:04 +00:00
|
|
|
rot = PI/2
|
2020-07-07 07:40:20 +00:00
|
|
|
$Light2D.rotation = rot
|
|
|
|
$ActivationRange.rotation = rot
|
2020-07-07 00:47:29 +00:00
|
|
|
|
|
|
|
|
2020-07-07 16:08:56 +00:00
|
|
|
func _input_event(_viewport, event, _shape_idx):
|
2020-07-07 00:47:29 +00:00
|
|
|
if Engine.editor_hint:
|
|
|
|
return
|
|
|
|
if event is InputEventMouseButton and event.pressed:
|
2020-07-07 07:40:20 +00:00
|
|
|
if activationRange.in_range():
|
|
|
|
set_lit(!lit)
|