Add flake and format

This commit is contained in:
Mathilde Grapin 2024-05-25 21:14:03 +02:00
parent 88f8cf17aa
commit 78cc721580
7 changed files with 132 additions and 17 deletions

77
flake.lock Normal file
View file

@ -0,0 +1,77 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1716328825,
"narHash": "sha256-ZpKwUK97Cxkocx+Jx2O91Qhza5zhS8i1G/YzacnGvCI=",
"owner": "squarepear",
"repo": "nixpkgs",
"rev": "bb663f89b88a2b4a3e2a46d2266cfc5e0fd9c619",
"type": "github"
},
"original": {
"owner": "squarepear",
"ref": "gdtoolkit-4",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1708475490,
"narHash": "sha256-g1v0TsWBQPX97ziznfJdWhgMyMGtoBFs102xSYO4syU=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "0e74ca98a74bc7270d28838369593635a5db3260",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs",
"systems": "systems",
"treefmt-nix": "treefmt-nix"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"id": "systems",
"type": "indirect"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1715940852,
"narHash": "sha256-wJqHMg/K6X3JGAE9YLM0LsuKrKb4XiBeVaoeMNlReZg=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "2fba33a182602b9d49f0b2440513e5ee091d838b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

26
flake.nix Normal file
View file

@ -0,0 +1,26 @@
{
inputs = {
nixpkgs.url = github:squarepear/nixpkgs/gdtoolkit-4;
treefmt-nix.url = github:numtide/treefmt-nix;
};
outputs = {
self,
nixpkgs,
systems,
treefmt-nix,
}: let
# Small tool to iterate over each systems
eachSystem = f: nixpkgs.lib.genAttrs (import systems) (system: f nixpkgs.legacyPackages.${system});
# Eval the treefmt modules from ./treefmt.nix
treefmtEval = eachSystem (pkgs: treefmt-nix.lib.evalModule pkgs ./treefmt.nix);
in {
# for `nix fmt`
formatter = eachSystem (pkgs: treefmtEval.${pkgs.system}.config.build.wrapper);
# for `nix flake check`
checks = eachSystem (pkgs: {
formatting = treefmtEval.${pkgs.system}.config.build.check self;
});
};
}

View file

@ -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:

View file

@ -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])

View file

@ -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]

View file

@ -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

11
treefmt.nix Normal file
View file

@ -0,0 +1,11 @@
{pkgs, ...}: {
projectRootFile = "flake.nix";
programs = {
gdformat = {
enable = true;
package = pkgs.gdtoolkit_4;
};
alejandra.enable = true;
};
}