This is much easier to explain, and it also avoids errors like forgetting to delete the save dir after editing sources in source dir.
One drawback: there's a little more risk of accidental data loss, either
because of bugs here or programmer mistakes. To mitigate this risk, put
your apps in a git repo and periodically git commit
.
2NQZJUPTOHIMDTSB2V53KQ5HLKKUUHQEKVB4XEHVFXOSI7UUGCJAC
FD6GKGZEDU7GYQPOKM4DT4GHASYBUUFVMUJRKWYBPJQK74ZN544QC
55UFMP6UMLX5EK5HRM7V4UIL57U7OZXIL75SGS2E74OQBRQ3UBSQC
TFRXO4PWML632XVMXGALPHGYYXI6AM32K6JIZFABAINI6G45TRWQC
BSDXVB3HU5Y5FZ244FU2F577RTM6SWEHAZX3IELBVUP52CRFVDSAC
LRDM35CEK3OHXOTB7TEFJRL7P6PQWO5ZG3F2BVA7DIDFHBPJQ7KAC
EZHO4TSWIYYUE73S6XQWIEF3HA3H7MKCNJOT27NTWTVSPVS2SL5QC
IJQP7HJKG5EMEVCPOL7ARC3B7WT55OPCH4MLKD6435XRDPFNX3XQC
3LU2TYSWNQ54STN7EBBIRYM5NR4XWPX2SUV337G7NJCUPXIG67GQC
GACNGS44Q6373XVGENKVG7H3ZO57MN3ZK6JL2TWE5YKIN67BK6VQC
FFFJ54GJ3A2HNKZEHO7RHUZ2YWT67EK4B3Y2YJVYCEUANGY6BQQAC
FS2ITYYHBLFT66YUC3ENPFYI2HOYHOVEPQIN7NQR6KF5MEK4NKZAC
D4FEFHQCSILZFQ5VLWNXAIRZNUMCDNGJSM4UJ6T6FDMMIWYRYILQC
print('new edits will go to ' .. love.filesystem.getSaveDirectory())
-- if necessary, copy files from repo to save dir
if io.open(love.filesystem.getSaveDirectory()..'/0000-freewheeling-start') == nil then
print('copying all definitions from repo to save dir')
for _,filename in ipairs(love.filesystem.getDirectoryItems('')) do
local numeric_prefix, root = filename:match('^(%d+)-(.+)')
if numeric_prefix then
local buf = love.filesystem.read(filename)
print('copying', filename)
love.filesystem.write(filename, buf)
end
end
end
-- list files to load in save dir
-- (ignore the repo because we might have deleted definitions)
if io.open(love.filesystem.getSaveDirectory()..'/'..filename) then
local numeric_prefix, root = filename:match('^(%d+)-(.+)')
if numeric_prefix and not numeric_prefix:match('^0+$') then
Live.filename[root] = filename
table.insert(Live.filenames_to_load, filename)
Live.final_prefix = math.max(Live.final_prefix, tonumber(numeric_prefix))
end
local numeric_prefix, root = filename:match('^(%d+)-(.+)')
if numeric_prefix and tonumber(numeric_prefix) > 0 then -- skip 0000
Live.filename[root] = filename
table.insert(Live.filenames_to_load, filename)
Live.final_prefix = math.max(Live.final_prefix, tonumber(numeric_prefix))
love.filesystem.write(filename, buf)
-- try to write to source dir
local status, err = App.write_file(App.source_dir..filename, buf)
if err then
-- not possible; perhaps it's a .love file
-- try to write to save dir
local status, err2 = App.write_file(App.save_dir..filename, buf)
if err2 then
-- throw an error
live.send_to_driver('ERROR '..tostring(err..'\n\n'..err2))
return
end
end
To publish your changes:
* delete all files with a numeric prefix from the repo, and then
* move all files with a numeric prefix from the [save directory](https://love2d.org/wiki/love.filesystem.getSaveDirectory)
to the repo.
If you run a .love file, your changes will go into the [save directory](https://love2d.org/wiki/love.filesystem.getSaveDirectory).
If you unzip the .love file into a new directory and run the directory
instead, your changes will go straight into the same directory.