feat: added clock

This commit is contained in:
Gerard Gascón 2025-04-09 18:43:34 +02:00
parent c422a83f59
commit c5dcf3d9d1
9 changed files with 103 additions and 1 deletions

14
scenes/clock/clock.gd Normal file
View file

@ -0,0 +1,14 @@
extends Label
func _process(delta: float) -> void:
var time: Dictionary = Time.get_time_dict_from_system()
var hour: int = time['hour']
var minute: int = time['minute']
var second: int = time['second']
if second % 2 == 0:
text = "%02d:%02d" % [hour, minute]
else:
text = "%02d %02d" % [hour, minute]

View file

@ -0,0 +1 @@
uid://drnne01ksnlqv

41
scenes/clock/clock.tscn Normal file
View file

@ -0,0 +1,41 @@
[gd_scene load_steps=4 format=3 uid="uid://bj5ptaniasaaj"]
[ext_resource type="Script" uid="uid://ddsdlhbepjrm3" path="res://scenes/clock/day.gd" id="1_4o2gw"]
[ext_resource type="Script" uid="uid://catrd7ir3ekyj" path="res://scenes/clock/clock_window.gd" id="1_yxh3l"]
[ext_resource type="Script" uid="uid://drnne01ksnlqv" path="res://scenes/clock/clock.gd" id="2_ngmfe"]
[node name="Clock" type="Window"]
transparent_bg = true
size = Vector2i(200, 100)
unresizable = true
borderless = true
transparent = true
script = ExtResource("1_yxh3l")
[node name="ColorRect" type="ColorRect" parent="."]
offset_right = 200.0
offset_bottom = 100.0
color = Color(0, 0.5, 0.2, 1)
[node name="Clock" type="Label" parent="."]
offset_right = 146.0
offset_bottom = 49.0
theme_override_font_sizes/font_size = 41
text = "00:00"
script = ExtResource("2_ngmfe")
[node name="Coins" type="Label" parent="."]
offset_left = 126.0
offset_right = 200.0
offset_bottom = 57.0
theme_override_font_sizes/font_size = 41
text = "00"
horizontal_alignment = 2
[node name="Day" type="Label" parent="."]
offset_top = 65.0
offset_right = 146.0
offset_bottom = 100.0
theme_override_font_sizes/font_size = 25
text = "dl. 23-04"
script = ExtResource("1_4o2gw")

View file

@ -0,0 +1,15 @@
extends Window
func _ready() -> void:
move_window_to_top_right()
func move_window_to_top_right():
var display_index: int = DisplayServer.window_get_current_screen()
var work_area_position: Vector2i = DisplayServer.screen_get_usable_rect(display_index).position
var work_area_size: Vector2i = DisplayServer.screen_get_usable_rect(display_index).size
var offset: int = 30
position = work_area_position + Vector2i(work_area_size.x - size.x - offset, offset)

View file

@ -0,0 +1 @@
uid://catrd7ir3ekyj

22
scenes/clock/day.gd Normal file
View file

@ -0,0 +1,22 @@
extends Label
const _weekday_converter: Dictionary[int, String] = {
0: 'Dg.',
1: 'Dl.',
2: 'Dm.',
3: 'Dc.',
4: 'Dj.',
5: 'Dv.',
6: 'Ds.',
}
func _process(delta: float) -> void:
var time: Dictionary = Time.get_date_dict_from_system()
var weekday: int = time['weekday']
var month: int = time['month']
var day: int = time['day']
text = "%s %02d/%02d" % [_weekday_converter[weekday], day, month]

1
scenes/clock/day.gd.uid Normal file
View file

@ -0,0 +1 @@
uid://ddsdlhbepjrm3

View file

@ -6,6 +6,8 @@ class_name GameManager
@export var dragon_ingame: PackedScene @export var dragon_ingame: PackedScene
@export var dragon_spots: Array[Node2D] @export var dragon_spots: Array[Node2D]
@export var clock: PackedScene
var _filled_spots: Dictionary[Node2D, int] var _filled_spots: Dictionary[Node2D, int]
@export var hat_outfits: DragonOutfit @export var hat_outfits: DragonOutfit
@ -34,6 +36,9 @@ func _ready():
_load_game() _load_game()
_queue_dragon_instantiation() _queue_dragon_instantiation()
var clock_window: Window = clock.instantiate()
add_child(clock_window)
func _queue_dragon_instantiation(): func _queue_dragon_instantiation():
await get_tree().create_timer(rng.randf_range(min_dragon_instantiation_time, max_dragon_instantiation_time)).timeout await get_tree().create_timer(rng.randf_range(min_dragon_instantiation_time, max_dragon_instantiation_time)).timeout

View file

@ -1,9 +1,10 @@
[gd_scene load_steps=14 format=3 uid="uid://ctytpqaed0yqx"] [gd_scene load_steps=15 format=3 uid="uid://ctytpqaed0yqx"]
[ext_resource type="Script" uid="uid://3kyt3shje5r1" path="res://scenes/main.gd" id="1_sugp2"] [ext_resource type="Script" uid="uid://3kyt3shje5r1" path="res://scenes/main.gd" id="1_sugp2"]
[ext_resource type="PackedScene" uid="uid://c7nfcgjxqeg7l" path="res://scenes/window/dragon_popup.tscn" id="2_jyhfs"] [ext_resource type="PackedScene" uid="uid://c7nfcgjxqeg7l" path="res://scenes/window/dragon_popup.tscn" id="2_jyhfs"]
[ext_resource type="Texture2D" uid="uid://fdqnc2qrrvn1" path="res://assets/sprites/icon.svg" id="3_tbgi4"] [ext_resource type="Texture2D" uid="uid://fdqnc2qrrvn1" path="res://assets/sprites/icon.svg" id="3_tbgi4"]
[ext_resource type="Resource" uid="uid://cnhwn6kfcbjl5" path="res://assets/outfits/hats.tres" id="4_85g3d"] [ext_resource type="Resource" uid="uid://cnhwn6kfcbjl5" path="res://assets/outfits/hats.tres" id="4_85g3d"]
[ext_resource type="PackedScene" uid="uid://bj5ptaniasaaj" path="res://scenes/clock/clock.tscn" id="4_a8y0u"]
[ext_resource type="PackedScene" uid="uid://miutbdsgccd1" path="res://scenes/dragons/dragon.tscn" id="4_jyhfs"] [ext_resource type="PackedScene" uid="uid://miutbdsgccd1" path="res://scenes/dragons/dragon.tscn" id="4_jyhfs"]
[ext_resource type="Script" uid="uid://cj4l3a6a8ro0r" path="res://scenes/create_button.gd" id="4_tbgi4"] [ext_resource type="Script" uid="uid://cj4l3a6a8ro0r" path="res://scenes/create_button.gd" id="4_tbgi4"]
[ext_resource type="Resource" uid="uid://etegcak2sphs" path="res://assets/outfits/shirts.tres" id="5_choun"] [ext_resource type="Resource" uid="uid://etegcak2sphs" path="res://assets/outfits/shirts.tres" id="5_choun"]
@ -19,6 +20,7 @@ script = ExtResource("1_sugp2")
dragon_template = ExtResource("2_jyhfs") dragon_template = ExtResource("2_jyhfs")
dragon_ingame = ExtResource("4_jyhfs") dragon_ingame = ExtResource("4_jyhfs")
dragon_spots = [NodePath("DragonSpot1"), NodePath("DragonSpot2"), NodePath("DragonSpot3")] dragon_spots = [NodePath("DragonSpot1"), NodePath("DragonSpot2"), NodePath("DragonSpot3")]
clock = ExtResource("4_a8y0u")
hat_outfits = ExtResource("4_85g3d") hat_outfits = ExtResource("4_85g3d")
shirt_outfits = ExtResource("5_choun") shirt_outfits = ExtResource("5_choun")
shoes_outfits = ExtResource("6_ya4ey") shoes_outfits = ExtResource("6_ya4ey")