diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2023-10-09 20:00:36 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2023-10-09 20:05:19 -0700 |
commit | 6e391d7875158a9351eae9976067671a0ef5ad0e (patch) | |
tree | 96115be8b30089090a26ce48750b1cb3a7f23dfe | |
parent | bd6f7d48e76182218877564e8ca672e657f4ef56 (diff) | |
download | view.love-6e391d7875158a9351eae9976067671a0ef5ad0e.tar.gz |
start supporting LÖVE v12
To do this I need some support for multiple versions. And I need an 'error' mode to go with existing 'run' and 'source' modes (`Current_app`). Most errors will automatically transition to 'source' editor mode, but some errors aren't really actionable in the editor. For those we'll use 'error' mode. The app doesn't yet work with LÖVE v12. There are some unit tests failing because of differences in font rendering.
-rw-r--r-- | app.lua | 1 | ||||
-rw-r--r-- | conf.lua | 3 | ||||
-rw-r--r-- | main.lua | 36 |
3 files changed, 36 insertions, 4 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 39c44a2..ecc261e 100644 --- a/main.lua +++ b/main.lua @@ -71,6 +71,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() @@ -136,7 +153,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() @@ -167,6 +189,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 @@ -202,6 +230,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 @@ -217,6 +246,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 @@ -232,6 +262,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 @@ -243,6 +274,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 @@ -253,6 +285,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 @@ -263,6 +296,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() |