aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/comfy.odin17
-rw-r--r--src/main.odin49
-rw-r--r--src/time.odin100
3 files changed, 155 insertions, 11 deletions
diff --git a/src/comfy.odin b/src/comfy.odin
new file mode 100644
index 0000000..e7ef23c
--- /dev/null
+++ b/src/comfy.odin
@@ -0,0 +1,17 @@
+package main
+
+import "core:strings"
+import "core:strconv"
+
+f64_to_cstring :: proc(f: f64) -> cstring {
+ buf: [20]byte
+ result := strconv.ftoa(buf[:], f, 'f', 2, 64)
+
+ if f > 0 {
+ result = string(buf[1:])
+ }
+
+ output : cstring = strings.clone_to_cstring(string(result))
+
+ return output
+} \ No newline at end of file
diff --git a/src/main.odin b/src/main.odin
index 5f6449b..698f044 100644
--- a/src/main.odin
+++ b/src/main.odin
@@ -26,10 +26,30 @@ main :: proc() {
// for cache reasons, and to simplify the process of
// adding new Workdays to the array.
- workdays: [dynamic]^Workday
- resize(&workdays, 3)
+ dayrate : f64 = 3500
+ workdays : [dynamic]Workday
+ //resize(&workdays, 3)
+ the_big_sum : f64 = 0
- workday0: = new_workday({10, 22, 3, 5, 2023},
+ { // No need to keep this array in memory forever
+ c, _ := importICS("res/test.ics")
+
+ for thing, i in c {
+ fmt.println("\n\nAdding workday nr", i, "\n", toString(thing), "\n")
+ append(&workdays, new_workday({00, 00, 1, 1, 1850},
+ thing.start,
+ thing.end,
+ thing.end))
+ for each_block in workdays[i].blocks {
+ the_big_sum += f64(each_block.value) * (dayrate/7.5) * f64(hourcount(each_block))
+ }
+ }
+ }
+
+
+ //if true do return
+
+ /*workday0: = new_workday({10, 22, 3, 5, 2023},
{00, 08, 4, 5, 2023},
{00, 22, 4, 5, 2023},
{30, 21, 4, 5, 2023})
@@ -46,8 +66,9 @@ main :: proc() {
{15, 17, 6, 5, 2023},
{00, 17, 6, 5, 2023})
workdays[2] = &workday2
+ */
- slice.sort_by(workdays[:], lessWorkdayPtr)
+ slice.sort_by(workdays[:], lessWorkday)
//call_text: cstring = "00:00"
call_text: = make([]byte, 6)
@@ -58,12 +79,18 @@ main :: proc() {
defer delete(wrap_text)
wrap_text[len(wrap_text)-1] = 0
- date_text: = make([]byte, len(toString(workday0.call))+1 )
+ date_text: = make([]byte, len(toString(workdays[0].call))+1 )
defer delete(date_text)
wrap_text[len(wrap_text)-1] = 0
- total_sum: cstring = "3500 NOK + 26%" // Only here for legacy UI
- inc_soc: cstring = "4276 NOK" // Only here for legacy UI
+
+ total_sum: cstring = f64_to_cstring(the_big_sum)
+ defer delete(total_sum)
+
+ inc_soc: cstring = f64_to_cstring(the_big_sum*1.26)
+ defer delete(inc_soc)
+
+ text_height: f32
using rl
@@ -90,12 +117,12 @@ main :: proc() {
c0 = new(oui.Context)
defer free(c0)
- oui.context_init(c0, 1028, 1028 * 8)
+ oui.context_init(c0, 2048, 2048 * 8)
defer oui.context_destroy(c0)
// Setting up the timelines
- for day in workdays {
+ for day in &workdays {
beginning: Moment = {0, 0, day.call.day, day.call.month, day.call.year}
fmt.println("\nNew day!")
@@ -219,7 +246,7 @@ when true {
FRACT_MAX = workdays[0].fractions[0].start
FRACT_MIN = FRACT_MAX // TODO: Optimize this. It doesn't need to re-calculated every frame
- for day, i in workdays {
+ for day, i in &workdays {
for fract, i in day.fractions {
if fract.start < FRACT_MIN do FRACT_MIN = fract.start
@@ -240,7 +267,7 @@ when true {
oui.item_insert(line, label(clockprint(day.wrap), font, sizings.wrap, .Center))
line.layout_cut_children = .Fill
- timeline(line, day)
+ timeline(line, &day)
}
new_workday := button("+", 100)
middle_section.layout_cut_children = .Top
diff --git a/src/time.odin b/src/time.odin
index 1f2ffbd..90dca49 100644
--- a/src/time.odin
+++ b/src/time.odin
@@ -2,6 +2,7 @@ package main
import math "core:math"
import "core:fmt"
+import "core:os"
import "core:strings"
import "core:strconv"
import "core:slice"
@@ -366,6 +367,105 @@ upvalue :: proc(input_block: ^Timeblock, value: f32, reason: string) {
}
}
+importICS :: proc(path: string) -> ([dynamic]Timeblock, bool) {
+ output: [dynamic]Timeblock
+
+ c : Timeblock
+
+ raw, ok := os.read_entire_file_from_filename(path)
+ content := string(raw)
+
+ i := 1
+ line_nr := 1
+
+ if !ok {
+ // TODO: Actually check the content to see if it is an ICS file.
+ fmt.eprintf("ERROR: No file found at: \"%v\"", path)
+ return output, false
+ }
+
+ for line in strings.split_lines_iterator(&content) {
+
+ // BUG: This assumes that there will never be a line shorter than 10.
+ // That means this will try reading out of bounds at some point.
+
+ if line[0:10]=="DTSTART;TZ" {
+ // grab the timestamp from the end of the line, and set start to it
+
+ ll := len(line)
+ fmt.println("Found a DTSTART!")
+ fmt.println("length of line:", ll)
+ fmt.println(line)
+ date_start : int
+
+ fmt.printf("Time: %s:%s\n", line[ll-6:ll-4], line[ll-4:ll-2])
+
+ fmt.printf("Hours: %s\n", line[ll-6:ll-4])
+ c.start.hours = strconv.atoi(line[ll-6:ll-4])
+
+ fmt.printf("Minutes: %s\n", line[ll-4:ll-2])
+ c.start.minutes = strconv.atoi(line[ll-4:ll-2])
+
+ fmt.printf("Day: %s\n", line[ll-9:ll-7])
+ c.start.day = strconv.atoi(line[ll-9:ll-7])
+
+ fmt.printf("Month: %s\n", line[ll-11:ll-9])
+ c.start.month = strconv.atoi(line[ll-11:ll-9])
+
+ fmt.printf("Year: %s\n", line[ll-15:ll-11])
+ c.start.year = strconv.atoi(line[ll-15:ll-11])
+ }
+ if line[0:5]=="DTEND" {
+ // grab the timestamp from the end of the line, and set end to it
+ ll := len(line)
+ fmt.println("Found a DTEND!")
+ fmt.println(line)
+
+
+ fmt.printf("Time: %s:%s\n", line[ll-6:ll-4], line[ll-4:ll-2])
+
+ fmt.printf("Hours: %s\n", line[ll-6:ll-4])
+ c.end.hours = strconv.atoi(line[ll-6:ll-4])
+
+ fmt.printf("Minutes: %s\n", line[ll-4:ll-2])
+ c.end.minutes = strconv.atoi(line[ll-4:ll-2])
+
+ fmt.printf("Day: %s\n", line[ll-9:ll-7])
+ c.end.day = strconv.atoi(line[ll-9:ll-7])
+
+ fmt.printf("Month: %s\n", line[ll-11:ll-9])
+ c.end.month = strconv.atoi(line[ll-11:ll-9])
+
+ fmt.printf("Year: %s\n", line[ll-15:ll-11])
+ c.end.year = strconv.atoi(line[ll-15:ll-11])
+
+ }
+
+ // TODO: This is checking if the years are 0 to make sure it hasn't read from
+ // from a line containing "DTSTART;VALUE" instead of "DTSTART;TZID"
+ // VALUE days are events that are set to last the entire day,
+ // as opposed to having a defined start and end point.
+ //
+ // This should eventually not be needed, because these days
+ // should also be imported based on the session's default-day settings
+
+ if line=="END:VEVENT" && (c.end.year != 0) && (c.start.year != 0) {
+ fmt.println(line)
+ c.value = 1
+ append(&output, c)
+
+ blank_timeblock: Timeblock
+ c = blank_timeblock
+
+ fmt.println("\n\n", i, line_nr, "\n\n")
+ i += 1
+ }
+ line_nr += 1
+ }
+ return output, true
+}
+
+
//
// --- BASIC OPERATIONS ---
//