streamline version checking and active keys
In ripping out the source editor I also removed the ability to recover from an unsupported version on a best-effort basis. Now the error message matches that scenario.
This commit is contained in:
parent
d780bb0175
commit
2082d49bcf
9
app.lua
9
app.lua
|
@ -1,19 +1,13 @@
|
|||
App = {}
|
||||
App.screen = {}
|
||||
|
||||
function App.love_version()
|
||||
local major_version, minor_version = love.getVersion()
|
||||
local version = major_version..'.'..minor_version
|
||||
return version, major_version
|
||||
end
|
||||
|
||||
function App.color(color)
|
||||
love.graphics.setColor(color.r, color.g, color.b, color.a)
|
||||
end
|
||||
|
||||
nativefs = require 'nativefs'
|
||||
|
||||
local Keys_down = {}
|
||||
Keys_down = {}
|
||||
for name in pairs(love.handlers) do
|
||||
-- love.keyboard.isDown doesn't work on Android, so emulate it using
|
||||
-- keypressed and keyreleased events
|
||||
|
@ -83,4 +77,3 @@ App.remove = nativefs.remove
|
|||
App.source_dir = love.filesystem.getSource()..'/' -- '/' should work even on Windows
|
||||
App.current_dir = nativefs.getWorkingDirectory()..'/'
|
||||
App.save_dir = love.filesystem.getSaveDirectory()..'/'
|
||||
App.key_down = function(key) return Keys_down[key] end
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
array = {}
|
||||
|
||||
function array.find(arr, elem)
|
||||
if type(elem) == 'function' then
|
||||
for i,x in ipairs(arr) do
|
||||
if elem(x) then
|
||||
return i
|
||||
end
|
||||
end
|
||||
else
|
||||
for i,x in ipairs(arr) do
|
||||
if x == elem then
|
||||
return i
|
||||
end
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function array.any(arr, f)
|
||||
for i,x in ipairs(arr) do
|
||||
local result = f(x)
|
||||
if result then
|
||||
return result
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
67
keychord.lua
67
keychord.lua
|
@ -8,53 +8,53 @@ function love.keypressed(key, scancode, isrepeat)
|
|||
return
|
||||
end
|
||||
-- include the modifier(s) when the non-modifer is pressed
|
||||
love.keychord_pressed(App.combine_modifiers(key), key)
|
||||
love.keychord_pressed(combine_modifiers(key), key)
|
||||
end
|
||||
|
||||
function App.combine_modifiers(key)
|
||||
function combine_modifiers(key)
|
||||
if love.keyboard.isModifierActive then -- waiting for LÖVE v12
|
||||
if key:match('^kp') then
|
||||
key = App.translate_numlock(key)
|
||||
key = translate_numlock(key)
|
||||
end
|
||||
end
|
||||
local result = ''
|
||||
if App.ctrl_down() then
|
||||
if ctrl_down() then
|
||||
result = result..'C-'
|
||||
end
|
||||
if App.alt_down() then
|
||||
if alt_down() then
|
||||
result = result..'M-'
|
||||
end
|
||||
if App.shift_down() then
|
||||
if shift_down() then
|
||||
result = result..'S-' -- don't try to use this with letters/digits
|
||||
end
|
||||
if App.cmd_down() then
|
||||
if cmd_down() then
|
||||
result = result..'s-'
|
||||
end
|
||||
result = result..key
|
||||
return result
|
||||
end
|
||||
|
||||
function App.any_modifier_down()
|
||||
return App.ctrl_down() or App.alt_down() or App.shift_down() or App.cmd_down()
|
||||
function any_modifier_down()
|
||||
return ctrl_down() or alt_down() or shift_down() or cmd_down()
|
||||
end
|
||||
|
||||
function App.ctrl_down()
|
||||
return App.key_down('lctrl') or App.key_down('rctrl')
|
||||
function ctrl_down()
|
||||
return Keys_down.lctrl or Keys_down.rctrl
|
||||
end
|
||||
|
||||
function App.alt_down()
|
||||
return App.key_down('lalt') or App.key_down('ralt')
|
||||
function alt_down()
|
||||
return Keys_down.lalt or Keys_down.ralt
|
||||
end
|
||||
|
||||
function App.shift_down()
|
||||
return App.key_down('lshift') or App.key_down('rshift')
|
||||
function shift_down()
|
||||
return Keys_down.lshift or Keys_down.rshift
|
||||
end
|
||||
|
||||
function App.cmd_down()
|
||||
return App.key_down('lgui') or App.key_down('rgui')
|
||||
function cmd_down()
|
||||
return Keys_down.lgui or Keys_down.rgui
|
||||
end
|
||||
|
||||
function App.is_cursor_movement(key)
|
||||
function is_cursor_movement(key)
|
||||
return array.find({'left', 'right', 'up', 'down', 'home', 'end', 'pageup', 'pagedown'}, key)
|
||||
end
|
||||
|
||||
|
@ -81,7 +81,7 @@ Numlock_on = {
|
|||
kpenter='enter',
|
||||
kpdel='delete',
|
||||
}
|
||||
function App.translate_numlock(key)
|
||||
function translate_numlock(key)
|
||||
if love.keyboard.isModifierActive('numlock') then
|
||||
return Numlock_on[key] or key
|
||||
else
|
||||
|
@ -89,32 +89,3 @@ function App.translate_numlock(key)
|
|||
end
|
||||
return key
|
||||
end
|
||||
|
||||
array = {}
|
||||
|
||||
function array.find(arr, elem)
|
||||
if type(elem) == 'function' then
|
||||
for i,x in ipairs(arr) do
|
||||
if elem(x) then
|
||||
return i
|
||||
end
|
||||
end
|
||||
else
|
||||
for i,x in ipairs(arr) do
|
||||
if x == elem then
|
||||
return i
|
||||
end
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function array.any(arr, f)
|
||||
for i,x in ipairs(arr) do
|
||||
local result = f(x)
|
||||
if result then
|
||||
return result
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
|
29
main.lua
29
main.lua
|
@ -5,12 +5,13 @@
|
|||
utf8 = require 'utf8'
|
||||
|
||||
json = require('json')
|
||||
|
||||
require('app')
|
||||
require('array')
|
||||
|
||||
require('keychord')
|
||||
require('button')
|
||||
|
||||
require('app')
|
||||
|
||||
require('icons')
|
||||
require('drawing')
|
||||
require('geom')
|
||||
|
@ -25,7 +26,7 @@ require('select')
|
|||
require('undo')
|
||||
|
||||
function love.load(arg)
|
||||
Version, Major_version = App.love_version()
|
||||
check_love_version()
|
||||
|
||||
if love.filesystem.getInfo('config') then
|
||||
Settings = json.decode(love.filesystem.read('config'))
|
||||
|
@ -39,13 +40,21 @@ function love.load(arg)
|
|||
love.graphics.setBackgroundColor(1,1,1)
|
||||
|
||||
run.initialize(arg)
|
||||
end
|
||||
|
||||
check_love_version()
|
||||
function check_love_version()
|
||||
local supported_versions = {'11.5', '11.4', '12.0'} -- put the recommended version first
|
||||
|
||||
local major_version, minor_version = love.getVersion()
|
||||
local version = major_version..'.'..minor_version
|
||||
|
||||
if array.find(supported_versions, version) == nil then
|
||||
error(
|
||||
("This app hasn't been tested with LÖVE version %s. Please add %s to `supported_versions` in main.lua to try it out, and switch to version %s if you run into issues."):format(version, version, supported_versions[1]))
|
||||
end
|
||||
end
|
||||
|
||||
function initialize_globals()
|
||||
Supported_versions = {'11.5', '11.4', '12.0'} -- put the recommended version first
|
||||
|
||||
run.initialize_globals()
|
||||
|
||||
-- for hysteresis in a few places
|
||||
|
@ -54,14 +63,6 @@ function initialize_globals()
|
|||
Last_resize_time = 0
|
||||
end
|
||||
|
||||
function check_love_version()
|
||||
if array.find(Supported_versions, Version) == nil then
|
||||
error(
|
||||
("This app hasn't been tested with LÖVE version %s; please switch to version %s if you run into issues. Press any key to continue."):format(Version, Supported_versions[1]))
|
||||
-- continue initializing everything; hopefully we won't have errors during initialization
|
||||
end
|
||||
end
|
||||
|
||||
function love.resize(w,h)
|
||||
if run.resize then run.resize(w,h) end
|
||||
Last_resize_time = Current_time
|
||||
|
|
4
text.lua
4
text.lua
|
@ -122,8 +122,8 @@ end
|
|||
|
||||
function Text.text_input(State, t)
|
||||
if love.mouse.isDown(1) then return end
|
||||
if App.any_modifier_down() then
|
||||
if App.key_down(t) then
|
||||
if any_modifier_down() then
|
||||
if Keys_down[t] then
|
||||
-- The modifiers didn't change the key. Handle it in keychord_pressed.
|
||||
return
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue