Simple charging setup for power cells
This commit is contained in:
parent
2283afbf51
commit
aca7f95a70
2 changed files with 24 additions and 10 deletions
|
@ -9,22 +9,27 @@ var attached = true
|
|||
onready var activationRange = $ActivationRange as ActivationRange
|
||||
onready var manager = $PowerManager as PowerManager
|
||||
|
||||
export var current_charge = MAX_CHARGE
|
||||
export var max_discharge_rate = 200
|
||||
export var current_charge = MAX_CHARGE setget set_charge
|
||||
export var max_charge_rate = 0 setget set_max_charge
|
||||
export var max_discharge_rate = 200 setget set_max_discharge
|
||||
|
||||
func _ready():
|
||||
func _ready() -> void:
|
||||
if not Engine.editor_hint:
|
||||
activationRange.visible = true
|
||||
$Control/PowerUI.set_current_charge(current_charge)
|
||||
$Control/PowerUI.set_max_charge(MAX_CHARGE)
|
||||
set_max_charge(max_charge_rate)
|
||||
|
||||
func _physics_process(delta: float):
|
||||
func _physics_process(delta: float) -> void:
|
||||
if manager.wired:
|
||||
if current_charge > 0:
|
||||
manager.power_source = min(current_charge, max_discharge_rate)
|
||||
if manager.power_load > 0:
|
||||
current_charge -= manager.power_load * delta
|
||||
set_charge(current_charge - manager.power_load * delta)
|
||||
if PowerNetwork.DEBUG:
|
||||
update()
|
||||
$Control/PowerUI.displayed_charge = current_charge
|
||||
if manager.powered:
|
||||
set_charge(current_charge + max_charge_rate * delta)
|
||||
|
||||
func _input(event):
|
||||
if event is InputEventMouseButton and event.pressed and not is_inside and open:
|
||||
|
@ -63,3 +68,15 @@ func _draw():
|
|||
if charge_px < 10:
|
||||
charge_color = Color.red
|
||||
draw_rect(Rect2(32, 32-charge_px, 4, charge_px), charge_color)
|
||||
|
||||
func set_max_discharge(val: float) -> void:
|
||||
max_discharge_rate = val
|
||||
|
||||
func set_max_charge(val: float) -> void:
|
||||
max_charge_rate = val
|
||||
if manager != null:
|
||||
manager.power_usage = val
|
||||
|
||||
func set_charge(val: float) -> void:
|
||||
current_charge = val
|
||||
$Control/PowerUI.set_current_charge(current_charge)
|
||||
|
|
|
@ -2,12 +2,9 @@ extends Control
|
|||
|
||||
onready var scene = $"/root/scene" as GameInstance
|
||||
|
||||
var displayed_charge = 0 setget set_current_charge
|
||||
var max_charge = 1 setget set_max_charge
|
||||
|
||||
func set_current_charge(val):
|
||||
$Container/CurrentBox/HBoxContainer/CurrentChargeLabel.text = "(" + str(round(val/10)/100) + "kJ)"
|
||||
$Container/CurrentBox/ProgressBar.value = val
|
||||
|
||||
func set_max_charge(val: float):
|
||||
$Container/CurrentBox/ProgressBar.max_value = max_charge
|
||||
$Container/CurrentBox/ProgressBar.max_value = val
|
||||
|
|
Reference in a new issue