Skip to content

Commit

Permalink
Merge pull request #1 from QueenOfSquiggles/main
Browse files Browse the repository at this point in the history
Added Pomodoro options to Jam countdown
  • Loading branch information
crsolver authored Feb 18, 2022
2 parents 808e8f0 + 1ac15af commit 8a50444
Show file tree
Hide file tree
Showing 17 changed files with 251 additions and 57 deletions.
1 change: 1 addition & 0 deletions .import/.gdignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 3 additions & 0 deletions .import/icon.png-487276ed1e3a0c39cad0279d744ee560.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source_md5="5ea43bd146f3f14908a84daa8f57322c"
dest_md5="cd22989dc39babe2b7478fbb68cc9c6c"

Binary file not shown.
3 changes: 3 additions & 0 deletions .import/image1.png-74d784a9909f532d3ed3cfc6c53c8d5b.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source_md5="e40abec7514a5b23ea20be4eb4409a55"
dest_md5="d00b3981d520fbcaa1641e563320353e"

Binary file not shown.
3 changes: 3 additions & 0 deletions .import/image2.png-a41d73cb53bcc04807a2e43b22dd517d.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source_md5="7bc45f67dcb158a4639b421373554bbc"
dest_md5="755dd8bb4051c4784d17b6872de6e36e"

Binary file not shown.
3 changes: 3 additions & 0 deletions .import/image3.png-90abca9baa4e1433f36a762af636f2b8.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source_md5="81127d0071df3a5ff7f61197786a667a"
dest_md5="e40a7cc7aaf41fea061d8fb82f8cda87"

Binary file not shown.
54 changes: 31 additions & 23 deletions addons/jamcountdown/countdown.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export var day:= 14
export var hour:= 16
export var minute:= 50
export var show_time_units := true
export var print_pomodoro_start_times := false

onready var title_label = get_node("HBoxContainer/TitleLabel")
onready var countdown_label = get_node("HBoxContainer/CountdownLabel")
Expand All @@ -17,12 +18,7 @@ var jam_date_unix
var time_left_unix: int
var timer: Timer


func _ready() -> void:
title_label.text = jam_title
countdown_label.text = ""
countdown_label.visible = true

jam_end_date = {
"year": year,
"month": month,
Expand All @@ -31,14 +27,24 @@ func _ready() -> void:
"minute": minute,
"second": 0
}

initialize_countdown()
# accomplishes original desired function
start_countdown(jam_end_date)

func start_countdown(end_date : Dictionary) -> void:
# moved ready func processes here to allow for starting from an arbitrary date set in code
jam_end_date = end_date
title_label.text = jam_title
countdown_label.text = ""
countdown_label.visible = true
initialize_countdown()
if print_pomodoro_start_times:
print("Countdown started for %s" % str(end_date))

func create_timer() -> void:
timer = Timer.new()
add_child(timer)
timer.connect("timeout", self, "_on_Timer_timeout")
if not is_instance_valid(timer):
timer = Timer.new()
add_child(timer)
timer.connect("timeout", self, "_on_Timer_timeout")
timer.process_mode = 0
timer.set_one_shot(false)

Expand All @@ -52,6 +58,8 @@ func create_timer() -> void:


func _on_Timer_timeout() -> void:
if not is_instance_valid(timer):
return
timer.set_wait_time(1)
update_countdown()

Expand Down Expand Up @@ -80,6 +88,7 @@ func update_countdown() -> void:


func update_countdown_label_text() -> void:

var time_left = get_datetime_from_unix(time_left_unix)

# time units
Expand All @@ -94,29 +103,28 @@ func update_countdown_label_text() -> void:
var str_seconds

if show_time_units:
str_days = str(time_left.days) + "d " if time_left.days > 0 else ""
str_hours = str(time_left.hours) + "h " if time_left.hours > 0 else ""
str_minutes = str(time_left.minutes) + "m " if time_left.minutes > 0 else ""
str_seconds = str(time_left.seconds) + "s" if time_left.seconds > 0 else ""
str_days = str(time_left.day) + "d " if time_left.day > 0 else ""
str_hours = str(time_left.hour) + "h " if time_left.hour > 0 else ""
str_minutes = str(time_left.minute) + "m " if time_left.minute > 0 else ""
str_seconds = str(time_left.second) + "s" if time_left.second > 0 else ""
else:
str_days = "%02d" % time_left.days +":"
str_hours = "%02d" % time_left.hours +":"
str_minutes = "%02d" % time_left.minutes +":"
str_seconds = "%02d" % time_left.seconds
str_days = "%02d" % time_left.day +":"
str_hours = "%02d" % time_left.hour +":"
str_minutes = "%02d" % time_left.minute +":"
str_seconds = "%02d" % time_left.second

countdown_label.text = str_days + str_hours + str_minutes + str_seconds


func get_datetime_from_unix(unix) -> Dictionary:
var seconds = floor(unix%60)
var minutes = floor((unix/60)%60)
var hours = floor((unix/3600)%24)
var days = floor(unix/86400)

var time = {
"days": days,
"hours": hours,
"minutes": minutes,
"seconds": seconds
"day": days,
"hour": hours,
"minute": minutes,
"second": seconds
}
return time
46 changes: 14 additions & 32 deletions addons/jamcountdown/countdown.tscn
Original file line number Diff line number Diff line change
@@ -1,28 +1,9 @@
[gd_scene load_steps=8 format=2]
[gd_scene load_steps=7 format=2]

[ext_resource path="res://addons/jamcountdown/countdown.gd" type="Script" id=1]
[ext_resource path="res://addons/jamcountdown/Roboto-Bold.ttf" type="DynamicFontData" id=2]
[ext_resource path="res://addons/jamcountdown/Roboto-Light.ttf" type="DynamicFontData" id=3]

[sub_resource type="StyleBoxFlat" id=1]
content_margin_left = 5.0
content_margin_right = 5.0
bg_color = Color( 0, 0, 0, 1 )
border_width_left = 1
border_width_top = 1
border_width_right = 1
border_width_bottom = 1
border_color = Color( 1, 1, 1, 0.882353 )
corner_radius_top_left = 8
corner_radius_top_right = 8
corner_radius_bottom_right = 8
corner_radius_bottom_left = 8
shadow_color = Color( 0, 0, 0, 0.34902 )
shadow_size = 3
shadow_offset = Vector2( 0, 2 )

[sub_resource type="Theme" id=2]
PanelContainer/styles/panel = SubResource( 1 )
[ext_resource path="res://addons/jamcountdown/element_theme.tres" type="Theme" id=4]

[sub_resource type="DynamicFont" id=3]
size = 15
Expand All @@ -39,14 +20,15 @@ margin_bottom = 24.0
grow_horizontal = 0
size_flags_horizontal = 5
size_flags_vertical = 5
theme = SubResource( 2 )
theme = ExtResource( 4 )
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
day = 11
hour = 12
minute = 17
month = 2
day = 17
hour = 17
minute = 0

[node name="HBoxContainer" type="HBoxContainer" parent="."]
margin_left = 5.0
Expand All @@ -62,28 +44,28 @@ __meta__ = {
}

[node name="TitleLabel" type="Label" parent="HBoxContainer"]
margin_left = 26.0
margin_right = 94.0
margin_left = 31.0
margin_right = 99.0
margin_bottom = 22.0
size_flags_horizontal = 5
size_flags_vertical = 5
custom_fonts/font = SubResource( 3 )
custom_colors/font_color = Color( 1, 1, 1, 1 )
custom_fonts/font = SubResource( 3 )
text = "GameJam"
__meta__ = {
"_edit_use_anchors_": false
}

[node name="CountdownLabel" type="Label" parent="HBoxContainer"]
margin_left = 98.0
margin_right = 161.0
margin_left = 103.0
margin_right = 156.0
margin_bottom = 22.0
grow_horizontal = 0
size_flags_horizontal = 5
size_flags_vertical = 3
custom_fonts/font = SubResource( 4 )
custom_colors/font_color = Color( 1, 1, 1, 1 )
text = "35m:15s"
custom_fonts/font = SubResource( 4 )
text = "12m 4s"
__meta__ = {
"_edit_use_anchors_": false
}
18 changes: 18 additions & 0 deletions addons/jamcountdown/element_theme.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[gd_resource type="Theme" load_steps=2 format=2]

[sub_resource type="StyleBoxFlat" id=1]
content_margin_left = 5.0
content_margin_right = 5.0
bg_color = Color( 0, 0, 0, 1 )
border_width_left = 1
border_width_top = 1
border_width_right = 1
border_width_bottom = 1
border_color = Color( 1, 1, 1, 1 )
corner_radius_top_left = 8
corner_radius_top_right = 8
corner_radius_bottom_right = 8
corner_radius_bottom_left = 8

[resource]
PanelContainer/styles/panel = SubResource( 1 )
37 changes: 35 additions & 2 deletions addons/jamcountdown/plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,44 @@ var countdown_scene = preload("res://addons/jamcountdown/countdown.tscn")
var countdown
var container = 0

func _enter_tree():
const POMO_5 := "Pomodoro 5 Minutes"
const POMO_25 := "Pomodoro 25 Minutes"
const POMO_45 := "Pomodoro 45 Minutes"
const POMO_60 := "Pomodoro 60 Minutes"
const POMO_120 := "Pomodoro 120 Minutes"

var UNIX_TIME_CALC_CORRECTION := 0

func _enter_tree():
# get offset from UTC for local time calculations:
var time_zone := OS.get_time_zone_info() # <--- this does have an edge case on windows machines during daylight savings time, not sure how to solve
# time_zone:bias is how many minutes offset local time is from UTC, convert to seconds for unix epoch offset
UNIX_TIME_CALC_CORRECTION = time_zone["bias"] * 60

countdown = countdown_scene.instance()
countdown.name = "addon_countdown"
add_control_to_container(container, countdown)

add_tool_menu_item(POMO_5, self, "_tool_pomodoro", 5)
add_tool_menu_item(POMO_25, self, "_tool_pomodoro", 25)
add_tool_menu_item(POMO_45, self, "_tool_pomodoro", 45)
add_tool_menu_item(POMO_60, self, "_tool_pomodoro", 60)
add_tool_menu_item(POMO_120, self, "_tool_pomodoro", 120)

func _exit_tree():
remove_control_from_container(container, countdown)
countdown.queue_free()
remove_tool_menu_item(POMO_5)
remove_tool_menu_item(POMO_25)
remove_tool_menu_item(POMO_45)
remove_tool_menu_item(POMO_60)
remove_tool_menu_item(POMO_120)

func _tool_pomodoro(minutes : int) -> void:

remove_control_from_container(container, countdown)
countdown.queue_free()
countdown = countdown_scene.instance()
add_control_to_container(container, countdown)
var offset :int = UNIX_TIME_CALC_CORRECTION + (minutes*60)
var time := OS.get_datetime_from_unix_time(OS.get_unix_time() + offset)
countdown.start_countdown(time)
35 changes: 35 additions & 0 deletions icon.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://icon.png"
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
35 changes: 35 additions & 0 deletions screenshots/image1.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/image1.png-74d784a9909f532d3ed3cfc6c53c8d5b.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://screenshots/image1.png"
dest_files=[ "res://.import/image1.png-74d784a9909f532d3ed3cfc6c53c8d5b.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
35 changes: 35 additions & 0 deletions screenshots/image2.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/image2.png-a41d73cb53bcc04807a2e43b22dd517d.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://screenshots/image2.png"
dest_files=[ "res://.import/image2.png-a41d73cb53bcc04807a2e43b22dd517d.stex" ]

[params]

compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
Loading

0 comments on commit 8a50444

Please sign in to comment.