bugfix: save modified files in save directory

scenario: open app from .love file, press ctrl+e

Before this change the source file showed up empty.
This commit is contained in:
Kartik K. Agaram 2022-09-05 12:39:28 -07:00
parent 5ab541f160
commit fdb35ce12b
1 changed files with 26 additions and 2 deletions

28
app.lua
View File

@ -383,8 +383,32 @@ function App.disable_tests()
App.newText = love.graphics.newText
App.screen.draw = love.graphics.draw
App.width = function(text) return text:getWidth() end
App.open_for_reading = function(filename) return io.open(filename, 'r') end
App.open_for_writing = function(filename) return io.open(filename, 'w') end
if Current_app == nil or Current_app == 'run' then
App.open_for_reading = function(filename) return io.open(filename, 'r') end
App.open_for_writing = function(filename) return io.open(filename, 'w') end
elseif Current_app == 'source' then
-- HACK: source editor requires a couple of different foundational definitions
App.open_for_reading =
function(filename)
local result = love.filesystem.newFile(filename)
local ok, err = result:open('r')
if ok then
return result
else
return ok, err
end
end
App.open_for_writing =
function(filename)
local result = love.filesystem.newFile(filename)
local ok, err = result:open('w')
if ok then
return result
else
return ok, err
end
end
end
App.getTime = love.timer.getTime
App.getClipboardText = love.system.getClipboardText
App.setClipboardText = love.system.setClipboardText