extends Control
-@export var battery := 100
+@export var battery := 100.0
+@export_range(0, 2) var unChargeSpeedMod: float = 1
@onready var dateLabel := $HBoxContainer/Date
@onready var batteryLabel := $HBoxContainer/Battery
@onready var timeLabel := $Time
@onready var rightBottomLabel := $RightBottomText
-# Called when the node enters the scene tree for the first time.
-func _ready():
- batteryLabel.text = " ⚡ " + str(battery) + "%"
+# each 1 seconds
+func _on_timer_1_timeout():
+ battery = set_battery_percentage(battery)
+ batteryLabel.set_text(format_battery_text(battery))
-# Called every frame. 'delta' is the elapsed time since the previous frame.
-func _process(delta):
- pass
+# each 0.25 seconds
+func _on_timer_0_25_timeout():
+ timeLabel.set_text(set_rand_timer(timeLabel.get_text()))
-# each second
-func _on_timer_timeout():
- timeLabel.set_text(set_rand_timer())
-
-
-func set_rand_timer() -> String:
- var random := randf()
+func set_rand_timer(prev_text: String) -> String:
+ var random := randf() * 100
var block: String = "?"
var text: String
- if .01 < random && random < .02:
+ if 0 < random && random < 3:
block = "▓"
- elif .02 < random && random < .03:
+ elif 3 < random && random < 6:
block = "▒"
- elif .03 < random && random < .04:
+ elif 6 < random && random < 9:
block = "░"
- elif .04 < random && random < .05:
+ elif 9 < random && random < 12:
block = "█"
random = randf() * 10
else:
text = "??:??"
- random = randf() * 10
- if 0 < random && random < 1:
+ random = randf() * 100
+ if 0 < random && random < 5:
text += " AM"
- elif 2 < random && random < 3:
+ elif 5 < random && random < 10:
text += " PM"
- elif 6 < random && random < 7:
+ elif 10 < random && random < 15:
text += " " + block + "M"
else:
- text += timeLabel.get_text().substr(
- len(timeLabel.get_text()) - 3, len(timeLabel.get_text()) - 1
- )
+ text += prev_text.substr(len(prev_text) - 3, len(prev_text) - 1)
return text
+
+
+func set_battery_percentage(battery_percentage: float) -> float:
+ var t = log(battery_percentage + 1)
+ return battery_percentage - t * unChargeSpeedMod
+
+
+func format_battery_text(battery_percentage: float) -> String:
+ return " ⚡ " + str(int(battery_percentage)) + "%"
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_sm2ld")
+unChargeSpeedMod = 0.1
[node name="HBoxContainer" type="HBoxContainer" parent="."]
layout_mode = 0
label_settings = SubResource("LabelSettings_hbd1r")
uppercase = true
-[node name="Timer" type="Timer" parent="."]
+[node name="Timer_0_25" type="Timer" parent="."]
wait_time = 0.25
autostart = true
-[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]
+[node name="Timer_1" type="Timer" parent="."]
+autostart = true
+
+[connection signal="timeout" from="Timer_0_25" to="." method="_on_timer_0_25_timeout"]
+[connection signal="timeout" from="Timer_1" to="." method="_on_timer_1_timeout"]