about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-11-03 21:08:11 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-11-03 21:08:11 -0700
commitfd71bc7d945d991b00369eba716f1313d5806ac3 (patch)
tree1bf4cf9285ed469fd8c13106158de1e4aca00838
parenta68647ae223357455274d163eb927528399df05e (diff)
parent0e0f36f8b4a57bd9a13925c9f7e92f7bd8c59a81 (diff)
downloadtext.love-fd71bc7d945d991b00369eba716f1313d5806ac3.tar.gz
Merge lines.love
-rw-r--r--drawing_tests.lua18
-rw-r--r--edit.lua4
-rw-r--r--main.lua18
-rw-r--r--source_edit.lua4
-rw-r--r--source_tests.lua6
5 files changed, 26 insertions, 24 deletions
diff --git a/drawing_tests.lua b/drawing_tests.lua
index f1e39a6..80a91f1 100644
--- a/drawing_tests.lua
+++ b/drawing_tests.lua
@@ -16,7 +16,7 @@ function test_creating_drawing_saves()
   edit.update(Editor_state, 0.01)
   check_nil(App.filesystem['foo'], 'F - test_creating_drawing_saves/early')
   -- wait until save
-  App.wait_fake_time(3.1)
+  Current_time = Current_time + 3.1
   edit.update(Editor_state, 0)
   -- filesystem contains drawing and an empty line of text
   check_eq(App.filesystem['foo'], '```lines\n```\n\n', 'F - test_creating_drawing_saves')
@@ -51,7 +51,7 @@ function test_draw_line()
   check_eq(p2.x, 35, 'F - test_draw_line/p2:x')
   check_eq(p2.y, 36, 'F - test_draw_line/p2:y')
   -- wait until save
-  App.wait_fake_time(3.1)
+  Current_time = Current_time + 3.1
   edit.update(Editor_state, 0)
   -- The format on disk isn't perfectly stable. Table fields can be reordered.
   -- So just reload from disk to verify.
@@ -430,7 +430,7 @@ function test_name_point()
   check_eq(Editor_state.current_drawing_mode, 'line', 'F - test_name_point/mode:3')
   check_eq(p2.name, 'A', 'F - test_name_point')
   -- wait until save
-  App.wait_fake_time(3.1)
+  Current_time = Current_time + 3.1
   edit.update(Editor_state, 0)
   -- change is saved
   load_from_disk(Editor_state)
@@ -462,7 +462,7 @@ function test_move_point()
   check_eq(p2.x, 35, 'F - test_move_point/baseline/p2:x')
   check_eq(p2.y, 36, 'F - test_move_point/baseline/p2:y')
   -- wait until save
-  App.wait_fake_time(3.1)
+  Current_time = Current_time + 3.1
   edit.update(Editor_state, 0)
   -- line is saved to disk
   load_from_disk(Editor_state)
@@ -489,7 +489,7 @@ function test_move_point()
   check_eq(Editor_state.current_drawing_mode, 'line', 'F - test_move_point/mode:3')
   check_eq(drawing.pending, {}, 'F - test_move_point/pending')
   -- wait until save
-  App.wait_fake_time(3.1)
+  Current_time = Current_time + 3.1
   edit.update(Editor_state, 0)
   -- change is saved
   load_from_disk(Editor_state)
@@ -550,7 +550,7 @@ function test_delete_lines_at_point()
   check_eq(drawing.shapes[1].mode, 'deleted', 'F - test_delete_lines_at_point/shape:1')
   check_eq(drawing.shapes[2].mode, 'deleted', 'F - test_delete_lines_at_point/shape:2')
   -- wait for some time
-  App.wait_fake_time(3.1)
+  Current_time = Current_time + 3.1
   edit.update(Editor_state, 0)
   -- deleted points disappear after file is reloaded
   load_from_disk(Editor_state)
@@ -684,7 +684,7 @@ function test_undo_name_point()
   check_eq(Editor_state.next_history, 3, 'F - test_undo_name_point/next_history')
   check_eq(p2.name, '', 'F - test_undo_name_point')  -- not quite what it was before, but close enough
   -- wait until save
-  App.wait_fake_time(3.1)
+  Current_time = Current_time + 3.1
   edit.update(Editor_state, 0)
   -- undo is saved
   load_from_disk(Editor_state)
@@ -735,7 +735,7 @@ function test_undo_move_point()
   check_eq(p2.x, 35, 'F - test_undo_move_point/x')
   check_eq(p2.y, 36, 'F - test_undo_move_point/y')
   -- wait until save
-  App.wait_fake_time(3.1)
+  Current_time = Current_time + 3.1
   edit.update(Editor_state, 0)
   -- undo is saved
   load_from_disk(Editor_state)
@@ -776,7 +776,7 @@ function test_undo_delete_point()
   check_eq(drawing.shapes[1].mode, 'line', 'F - test_undo_delete_point/shape:1')
   check_eq(drawing.shapes[2].mode, 'line', 'F - test_undo_delete_point/shape:2')
   -- wait until save
-  App.wait_fake_time(3.1)
+  Current_time = Current_time + 3.1
   edit.update(Editor_state, 0)
   -- undo is saved
   load_from_disk(Editor_state)
diff --git a/edit.lua b/edit.lua
index dae6d77..5c487a0 100644
--- a/edit.lua
+++ b/edit.lua
@@ -106,7 +106,7 @@ function edit.draw(State)
 end
 
 function edit.update(State, dt)
-  if State.next_save and State.next_save < App.getTime() then
+  if State.next_save and State.next_save < Current_time then
     save_to_disk(State)
     State.next_save = nil
   end
@@ -114,7 +114,7 @@ end
 
 function schedule_save(State)
   if State.next_save == nil then
-    State.next_save = App.getTime() + 3  -- short enough that you're likely to still remember what you did
+    State.next_save = Current_time + 3  -- short enough that you're likely to still remember what you did
   end
 end
 
diff --git a/main.lua b/main.lua
index 87b867f..e9a7da5 100644
--- a/main.lua
+++ b/main.lua
@@ -79,8 +79,9 @@ function App.initialize_globals()
   end
 
   -- for hysteresis in a few places
-  Last_focus_time = App.getTime()  -- https://love2d.org/forums/viewtopic.php?p=249700
-  Last_resize_time = App.getTime()
+  Current_time = 0
+  Last_focus_time = 0  -- https://love2d.org/forums/viewtopic.php?p=249700
+  Last_resize_time = 0
 end
 
 function App.initialize(arg)
@@ -101,7 +102,7 @@ function App.resize(w,h)
   else
     assert(false, 'unknown app "'..Current_app..'"')
   end
-  Last_resize_time = App.getTime()
+  Last_resize_time = Current_time
 end
 
 function App.filedropped(file)
@@ -116,7 +117,7 @@ end
 
 function App.focus(in_focus)
   if in_focus then
-    Last_focus_time = App.getTime()
+    Last_focus_time = Current_time
   end
   if Current_app == 'run' then
     if run.focus then run.focus(in_focus) end
@@ -138,8 +139,9 @@ function App.draw()
 end
 
 function App.update(dt)
+  Current_time = Current_time + dt
   -- some hysteresis while resizing
-  if App.getTime() < Last_resize_time + 0.1 then
+  if Current_time < Last_resize_time + 0.1 then
     return
   end
   --
@@ -154,7 +156,7 @@ end
 
 function App.keychord_pressed(chord, key)
   -- ignore events for some time after window in focus (mostly alt-tab)
-  if App.getTime() < Last_focus_time + 0.01 then
+  if Current_time < Last_focus_time + 0.01 then
     return
   end
   --
@@ -192,7 +194,7 @@ end
 
 function App.textinput(t)
   -- ignore events for some time after window in focus (mostly alt-tab)
-  if App.getTime() < Last_focus_time + 0.01 then
+  if Current_time < Last_focus_time + 0.01 then
     return
   end
   --
@@ -207,7 +209,7 @@ end
 
 function App.keyreleased(chord, key)
   -- ignore events for some time after window in focus (mostly alt-tab)
-  if App.getTime() < Last_focus_time + 0.01 then
+  if Current_time < Last_focus_time + 0.01 then
     return
   end
   --
diff --git a/source_edit.lua b/source_edit.lua
index 4f55083..1d82596 100644
--- a/source_edit.lua
+++ b/source_edit.lua
@@ -189,7 +189,7 @@ end
 
 function edit.update(State, dt)
   Drawing.update(State, dt)
-  if State.next_save and State.next_save < App.getTime() then
+  if State.next_save and State.next_save < Current_time then
     save_to_disk(State)
     State.next_save = nil
   end
@@ -197,7 +197,7 @@ end
 
 function schedule_save(State)
   if State.next_save == nil then
-    State.next_save = App.getTime() + 3  -- short enough that you're likely to still remember what you did
+    State.next_save = Current_time + 3  -- short enough that you're likely to still remember what you did
   end
 end
 
diff --git a/source_tests.lua b/source_tests.lua
index 81bdb74..b6e5861 100644
--- a/source_tests.lua
+++ b/source_tests.lua
@@ -31,7 +31,7 @@ function test_show_log_browser_side()
   log_browser.parse(Log_browser_state)
   check(not Show_log_browser_side, 'F - test_show_log_browser_side/baseline')
   -- pressing ctrl+l shows log-browser side
-  App.wait_fake_time(0.1)
+  Current_time = Current_time + 0.1
   App.run_after_keychord('C-l')
   check(Show_log_browser_side, 'F - test_show_log_browser_side')
 end
@@ -56,7 +56,7 @@ function test_show_log_browser_side_doubles_window_width_if_possible()
   Text.redraw_all(Log_browser_state)
   log_browser.parse(Log_browser_state)
   -- display log browser
-  App.wait_fake_time(0.1)
+  Current_time = Current_time + 0.1
   App.run_after_keychord('C-l')
   -- window width is doubled
   check_eq(App.screen.width, 600, 'F - test_show_log_browser_side_doubles_window_width_if_possible/display:width')
@@ -87,7 +87,7 @@ function test_show_log_browser_side_resizes_both_sides_if_cannot_double_window_w
   Text.redraw_all(Log_browser_state)
   log_browser.parse(Log_browser_state)
   -- display log browser
-  App.wait_fake_time(0.1)
+  Current_time = Current_time + 0.1
   App.run_after_keychord('C-l')
   -- margins are now adjusted
   check_eq(Editor_state.left, Margin_left, 'F - test_show_log_browser_side_resizes_both_sides_if_cannot_double_window_width/edit:left')