I'm starting to feel better after replacing 1 line with 20 and 2 new bits of global state. I'm now handling two scenarios more explicitly:
If I change Current_app within key_press, the corresponding text_input and key_release events go to the new app. If it's an editor it might insert the key, which is undesirable. Putting such handlers in key_release now feels overly clever, particularly since it took me forever to realize why I was getting stuck in an infinite loop.
Both 'run' and 'source' can hit the version check, so we need to be able to transition from the 'error' app to either. Which necessitates yet another global bit of state: Next_app.
3XQROLSKN5GIROYOSBN2OW2DSG34PKDU4BGYV7DL6F3V5RNSHATQC
7SICLTEDRE23UDA5RMYFRSODTYBDWAJCX3BSYLDHVAPMTMVGDZCAC
Z2VZTIXYXUZXF4ZUVG54IOIRSMBGUZJZ2RTBPYOJC7NWBOUFU6YAC
APX2PY6GAMJSUH7SFSMBFOQJBSAWLLOCKH4L4ZQP2VLHNEXJPREAC
OTIBCAUJ3KDQJLVDN3A536DLZGNRYMGJLORZVR3WLCGXGO6UGO6AC
YGCT2D2ORMLTBHANLGHZV3EBGGHD7ZK55UAM7HF2AVSHDXAAKK5QC
LF7BWEG4DKQI7NMXMZC4LC2BE5PB42HK5PD6OYBNIDMAZBJASOKQC
KKMFQDR43ZWVCDRHQLWWX3FCWCFA3ZSXYOBRJNPHUQZR2XPKWULAC
AVTNUQYRBW7IX2YQ3KDLVQ23RGW3BAKTAE7P73ASBYNKOHMQMH5AC
2CK5QI7WA7M4IVSACFGOJYAIDKRUTZVMMPSFWEJTUNMWTN7AX4NAC
3QQZ7W4EJ7G4HQM5IYWXICMAHVRGERY4X6AOC6LOV5NSZ4OBICSAC
6VJTQKW7YJ7E3WRNSTFYULUDHHTYAE4JELX4J55LO75X4FDM3JZAC
IM6GSGVZTVICWIBWRCUXLIMXT3XE3H5LKJ3AITUA4AB3FTW5AJUAC
FJIGUGECGBLEKXGERZ6GE3CZYGSFEBCKSAUYSS7PFLHXDAKAFNKQC
3QNOKBFMKBGXBVJIRHR2444JRRMBTABHE4674NR3DT67RRM2X6GAC
BJ5X5O4ACBBJ56LRBBSTCW6IBQP4HAEOOOPNH3SKTA4F66YTOIDAC
-- Another weird bit for a class of corner cases. E.g.:
-- * I press ctrl+e, switch Current_app. I don't want the new app to receive
-- text_input and key_release events.
-- If I try to avoid text_input events by switching modes on key_release, I
-- hit a new problem:
-- * I press ctrl+e, am running an untested version, Current_app goes to
-- 'error', and immediately rolls back out of 'error' in the key_release
-- event.
-- Skip_rest_of_key_events is ugly, but feels cleaner than creating yet
-- another possible value for Current_app.
Skip_rest_of_key_events = nil
-- Where to go from 'error' app.
Next_app = nil
end
end
function App.love_version_check()
if Unsupported_version then
Current_app = 'error'
Error_message = ("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])
print(Error_message)
-- continue initializing everything; hopefully we won't have errors during initialization
function check_love_version()
if array.find(Supported_versions, Version) == nil then
Next_app = Current_app
Current_app = 'error'
Error_message = ("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
* run with an untested version. Error message pops up. Press a key. Text editor comes up, and doesn't receive the key. Press ctrl+e. Source editor opens up. Press ctrl+e. Text editor returns.
* run with an untested version. Error message pops up. Press a key. Text editor comes up, and doesn't receive the key. Press ctrl+e. Error pops up. Press a key. Source editor opens up. Press ctrl+e. Error pops up. Press a key. Text editor returns.