This repository has been archived on 2020-09-30. You can view files and clone it, but cannot push or open issues or pull requests.
odyssey-old/Actors/Objects/PowerStorage/PowerStorage.gd
2020-07-08 14:30:46 +02:00

58 lines
1.4 KiB
GDScript

extends StaticBody2D
class_name GameObjectPowerStorage
const MAX_CHARGE = 5000.0
var open = false
var attached = true
onready var activationRange = $ActivationRange as ActivationRange
var current_charge = MAX_CHARGE
func _ready():
if not Engine.editor_hint:
activationRange.visible = true
func _physics_process(delta):
if $PowerManager.wired:
if $PowerManager.DEBUG:
update()
func _input(event):
if event is InputEventMouseButton and event.pressed and not is_inside and open:
open = false
$UIAnimation.play("fadeout")
func _input_event(_viewport, event, _shape_idx):
if Engine.editor_hint:
return
if event is InputEventMouseButton and event.pressed and not open:
# Must be in range
if activationRange.in_range():
open = true
$Control/PowerUI.visible = true
$UIAnimation.play("fadein")
var is_inside = false
func _ui_focus_changed(entered):
is_inside = entered
func _ui_fade_completed(anim_name):
if anim_name == "fadeout":
$Control/PowerUI.visible = false
func _force_close_ui():
if open:
open = false
$UIAnimation.play("fadeout")
func _draw():
if $PowerManager.DEBUG:
var charge_px = int(current_charge / MAX_CHARGE * 32)
var charge_color = Color.greenyellow
if charge_px < 20:
charge_color = Color.yellow
if charge_px < 10:
charge_color = Color.red
draw_rect(Rect2(32, 32-charge_px, 4, charge_px), charge_color)