Add flake and format
This commit is contained in:
parent
88f8cf17aa
commit
78cc721580
7 changed files with 132 additions and 17 deletions
|
@ -11,20 +11,21 @@ var last_focused_day = null
|
|||
var new_focused_day = null
|
||||
var all_days = []
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
var current_year = Time.get_date_dict_from_system().year
|
||||
|
||||
|
||||
year_label.text = "%s" % current_year
|
||||
|
||||
for i in range (1, 13):
|
||||
for i in range(1, 13):
|
||||
var month = month_scene.instantiate()
|
||||
month.year = current_year
|
||||
month.month = i
|
||||
month.day_toggled.connect(_on_day_toggled)
|
||||
month.fill_days.connect(_on_fill_days)
|
||||
year.add_child(month)
|
||||
|
||||
|
||||
for element in month.days.get_children():
|
||||
if element is Day:
|
||||
all_days.append(element)
|
||||
|
@ -32,7 +33,7 @@ func _ready():
|
|||
|
||||
func _on_day_toggled(date):
|
||||
# period_manager.add(date)
|
||||
|
||||
|
||||
# Update last focused day.
|
||||
var focused_node = get_viewport().gui_get_focus_owner()
|
||||
if focused_node is Day:
|
||||
|
@ -41,18 +42,20 @@ func _on_day_toggled(date):
|
|||
|
||||
func _on_fill_days(shift_clicked_day):
|
||||
# Toogle day from last focused day to current day.
|
||||
|
||||
|
||||
# Assert that last focused day is different from date.
|
||||
if last_focused_day == null:
|
||||
return
|
||||
|
||||
if shift_clicked_day == last_focused_day:
|
||||
return
|
||||
|
||||
|
||||
# Determine if date is before or after the last focused day.
|
||||
var first_day = last_focused_day if last_focused_day.is_before(shift_clicked_day) else shift_clicked_day
|
||||
var first_day = (
|
||||
last_focused_day if last_focused_day.is_before(shift_clicked_day) else shift_clicked_day
|
||||
)
|
||||
var last_day = shift_clicked_day if first_day == last_focused_day else last_focused_day
|
||||
|
||||
|
||||
# Toggle days between the two days.
|
||||
var toggle = false
|
||||
for day in all_days:
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
class_name Day
|
||||
extends Button
|
||||
|
||||
|
||||
signal day_toggled(date)
|
||||
signal fill_days(date)
|
||||
|
||||
|
@ -9,7 +8,7 @@ var date = {}
|
|||
|
||||
|
||||
func _ready():
|
||||
set_toggle_mode(true);
|
||||
set_toggle_mode(true)
|
||||
toggled.connect(self._on_day_toggled)
|
||||
|
||||
|
||||
|
@ -30,10 +29,11 @@ func set_date(year, month, day):
|
|||
func is_before(other_day):
|
||||
var day_unix_time = Time.get_unix_time_from_datetime_dict(date)
|
||||
var other_day_unix_time = Time.get_unix_time_from_datetime_dict(other_day.date)
|
||||
|
||||
|
||||
if day_unix_time < other_day_unix_time:
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
func dump():
|
||||
print("%s - %s - %s" % [date.year, date.month, date.day])
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
class_name Month
|
||||
extends Control
|
||||
|
||||
|
||||
signal day_toggled(date)
|
||||
signal fill_days(date)
|
||||
|
||||
|
@ -18,11 +17,11 @@ var month: int
|
|||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
month_label.text = "%s" % month
|
||||
|
||||
|
||||
var days_in_month = find_days_in_month(year, month)
|
||||
var date_string = "%s-%s-%s" % [year, month, 1]
|
||||
var first_day = Time.get_datetime_dict_from_datetime_string(date_string, true)
|
||||
|
||||
|
||||
# Fill the container with number corresponding to days
|
||||
for i in range(first_day.weekday):
|
||||
var empty_label = Label.new()
|
||||
|
@ -46,7 +45,7 @@ func _on_fill_days(day):
|
|||
|
||||
func find_days_in_month(year: int, month: int):
|
||||
assert(month >= 1 and month <= 12)
|
||||
if (month == 2 and is_leap_year(year)):
|
||||
if month == 2 and is_leap_year(year):
|
||||
return 29
|
||||
return DAYS_IN_MONTH[month - 1]
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
extends Node
|
||||
|
||||
|
||||
var periods = []
|
||||
var last_period = null
|
||||
|
||||
|
@ -11,7 +10,7 @@ func add(date):
|
|||
last_period = null
|
||||
dump()
|
||||
return
|
||||
|
||||
|
||||
# If no new period has begun
|
||||
var period = Period.new()
|
||||
period.begin = date
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue