about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2023-10-09 20:55:24 -0700
committerKartik K. Agaram <vc@akkartik.com>2023-10-09 20:55:24 -0700
commitb84cbf6d21fccdad85cb7963dd4689a8b497e729 (patch)
treef1d940f9cde81e58abbcb6420743e993db9b3874
parent3aec915559514e8294f80447fcac9c4b34df9dc4 (diff)
parent69d86cae5ba5672e7020243d0f78f0ea6355fd8f (diff)
downloadtext.love-b84cbf6d21fccdad85cb7963dd4689a8b497e729.tar.gz
Merge lines.love
-rw-r--r--app.lua1
-rw-r--r--conf.lua3
-rw-r--r--main.lua36
-rw-r--r--source_text_tests.lua13
-rw-r--r--text_tests.lua13
5 files changed, 56 insertions, 10 deletions
diff --git a/app.lua b/app.lua
index 55b1b0d..5e3301f 100644
--- a/app.lua
+++ b/app.lua
@@ -8,6 +8,7 @@
 --     and a source editor, while giving each the illusion of complete
 --     control.
 function love.run()
+  App.version_check()
   App.snapshot_love()
   -- Tests always run at the start.
   App.run_tests_and_initialize()
diff --git a/conf.lua b/conf.lua
deleted file mode 100644
index de8758a..0000000
--- a/conf.lua
+++ /dev/null
@@ -1,3 +0,0 @@
-function love.conf(t)
-  t.version = '11.4'
-end
diff --git a/main.lua b/main.lua
index 6ff69d6..b515b8e 100644
--- a/main.lua
+++ b/main.lua
@@ -69,6 +69,23 @@ function App.load()
   end
 end
 
+function App.version_check()
+  -- available modes: run, error
+  Error_message = nil
+  Error_count = 0
+  -- we'll reuse error mode on load for an initial version check
+  local supported_versions = {'11.4', '12.0'}  -- put the recommended version first
+  local minor_version
+  Major_version, minor_version = love.getVersion()
+  Version = Major_version..'.'..minor_version
+  if array.find(supported_versions, Version) == nil then
+    Current_app = 'error'
+    Error_message = ("This app doesn't support version %s; please use version %s. Press any key to try it with this version anyway."):format(Version, supported_versions[1])
+    print(Error_message)
+    -- continue initializing everything; hopefully we won't have errors during initialization
+  end
+end
+
 function App.initialize_globals()
   if Current_app == 'run' then
     run.initialize_globals()
@@ -134,7 +151,12 @@ function App.focus(in_focus)
 end
 
 function App.draw()
-  if Current_app == 'run' then
+  if Current_app == 'error' then
+    love.graphics.setColor(0,0,1)
+    love.graphics.rectangle('fill', 0,0, App.screen.width, App.screen.height)
+    love.graphics.setColor(1,1,1)
+    love.graphics.printf(Error_message, 40,40, 600)
+  elseif Current_app == 'run' then
     run.draw()
   elseif Current_app == 'source' then
     source.draw()
@@ -165,6 +187,12 @@ function App.keychord_press(chord, key)
     return
   end
   --
+  if Current_app == 'error' then
+    if chord == 'C-c' then
+      love.system.setClipboardText(Error_message)
+    end
+    return
+  end
   if chord == 'C-e' then
     -- carefully save settings
     if Current_app == 'run' then
@@ -200,6 +228,7 @@ function App.keychord_press(chord, key)
 end
 
 function App.textinput(t)
+  if Current_app == 'error' then return end
   -- ignore events for some time after window in focus (mostly alt-tab)
   if Current_time < Last_focus_time + 0.01 then
     return
@@ -215,6 +244,7 @@ function App.textinput(t)
 end
 
 function App.keyreleased(key, scancode)
+  if Current_app == 'error' then return end
   -- ignore events for some time after window in focus (mostly alt-tab)
   if Current_time < Last_focus_time + 0.01 then
     return
@@ -230,6 +260,7 @@ function App.keyreleased(key, scancode)
 end
 
 function App.mousepressed(x,y, mouse_button)
+  if Current_app == 'error' then return end
 --?   print('mouse press', x,y)
   if Current_app == 'run' then
     if run.mouse_press then run.mouse_press(x,y, mouse_button) end
@@ -241,6 +272,7 @@ function App.mousepressed(x,y, mouse_button)
 end
 
 function App.mousereleased(x,y, mouse_button)
+  if Current_app == 'error' then return end
   if Current_app == 'run' then
     if run.mouse_release then run.mouse_release(x,y, mouse_button) end
   elseif Current_app == 'source' then
@@ -251,6 +283,7 @@ function App.mousereleased(x,y, mouse_button)
 end
 
 function App.wheelmoved(dx,dy)
+  if Current_app == 'error' then return end
   if Current_app == 'run' then
     if run.mouse_wheel_move then run.mouse_wheel_move(dx,dy) end
   elseif Current_app == 'source' then
@@ -261,6 +294,7 @@ function App.wheelmoved(dx,dy)
 end
 
 function love.quit()
+  if Current_app == 'error' then return end
   if Current_app == 'run' then
     local source_settings = Settings.source
     Settings = run.settings()
diff --git a/source_text_tests.lua b/source_text_tests.lua
index 2dc3adb..0b45232 100644
--- a/source_text_tests.lua
+++ b/source_text_tests.lua
@@ -1086,7 +1086,14 @@ function test_pagedown_can_start_from_middle_of_long_wrapping_line()
   y = y + Editor_state.line_height
   App.screen.check(y, 'jkl ', 'screen:2')
   y = y + Editor_state.line_height
-  App.screen.check(y, 'mn', 'screen:3')
+  if Version == '12.0' then
+    -- HACK: Maybe v12.0 uses a different font? Strange that it only causes
+    -- issues in a couple of places.
+    -- We'll need to rethink our tests if issues like this start to multiply.
+    App.screen.check(y, 'mno ', 'screen:3')
+  else
+    App.screen.check(y, 'mn', 'screen:3')
+  end
 end
 
 function test_pagedown_never_moves_up()
@@ -1796,10 +1803,10 @@ function test_position_cursor_on_recently_edited_wrapping_line()
   y = y + Editor_state.line_height
   App.screen.check(y, 'stu', 'baseline2/screen:3')
   -- try to move the cursor earlier in the third screen line by clicking the mouse
-  edit.run_after_mouse_release(Editor_state, Editor_state.left+8,Editor_state.top+Editor_state.line_height*2+5, 1)
+  edit.run_after_mouse_release(Editor_state, Editor_state.left+2,Editor_state.top+Editor_state.line_height*2+5, 1)
   -- cursor should move
   check_eq(Editor_state.cursor1.line, 1, 'cursor:line')
-  check_eq(Editor_state.cursor1.pos, 26, 'cursor:pos')
+  check_eq(Editor_state.cursor1.pos, 25, 'cursor:pos')
 end
 
 function test_backspace_can_scroll_up()
diff --git a/text_tests.lua b/text_tests.lua
index 86d602b..8c2dc3a 100644
--- a/text_tests.lua
+++ b/text_tests.lua
@@ -1061,7 +1061,14 @@ function test_pagedown_can_start_from_middle_of_long_wrapping_line()
   y = y + Editor_state.line_height
   App.screen.check(y, 'jkl ', 'screen:2')
   y = y + Editor_state.line_height
-  App.screen.check(y, 'mn', 'screen:3')
+  if Version == '12.0' then
+    -- HACK: Maybe v12.0 uses a different font? Strange that it only causes
+    -- issues in a couple of places.
+    -- We'll need to rethink our tests if issues like this start to multiply.
+    App.screen.check(y, 'mno ', 'screen:3')
+  else
+    App.screen.check(y, 'mn', 'screen:3')
+  end
 end
 
 function test_pagedown_never_moves_up()
@@ -1699,10 +1706,10 @@ function test_position_cursor_on_recently_edited_wrapping_line()
   y = y + Editor_state.line_height
   App.screen.check(y, 'stu', 'baseline2/screen:3')
   -- try to move the cursor earlier in the third screen line by clicking the mouse
-  edit.run_after_mouse_release(Editor_state, Editor_state.left+8,Editor_state.top+Editor_state.line_height*2+5, 1)
+  edit.run_after_mouse_release(Editor_state, Editor_state.left+2,Editor_state.top+Editor_state.line_height*2+5, 1)
   -- cursor should move
   check_eq(Editor_state.cursor1.line, 1, 'cursor:line')
-  check_eq(Editor_state.cursor1.pos, 26, 'cursor:pos')
+  check_eq(Editor_state.cursor1.pos, 25, 'cursor:pos')
 end
 
 function test_backspace_can_scroll_up()