eddited clock glitches times and added battery logic
authorEduardo <[email protected]>
Fri, 9 Feb 2024 16:07:06 +0000 (17:07 +0100)
committerEduardo <[email protected]>
Fri, 9 Feb 2024 16:07:06 +0000 (17:07 +0100)
levels/ui.gd
levels/ui.tscn

index 9838283754f6d1d7c0050f4aceec3bcdb5665911..620aec50dd41b8c828862c4958ed801bb72a584a 100644 (file)
@@ -1,6 +1,7 @@
 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
@@ -9,33 +10,29 @@ extends Control
 @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
@@ -50,16 +47,23 @@ func set_rand_timer() -> String:
        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)) + "%"
index b1439ef693532451f15a4fb4cfd0bb8ed2302a0a..5a348661dfa14f3af4785aaa739b320e720c1710 100644 (file)
@@ -18,6 +18,7 @@ anchor_bottom = 1.0
 grow_horizontal = 2
 grow_vertical = 2
 script = ExtResource("1_sm2ld")
+unChargeSpeedMod = 0.1
 
 [node name="HBoxContainer" type="HBoxContainer" parent="."]
 layout_mode = 0
@@ -102,8 +103,12 @@ text = "item"
 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"]