close #5 the data knows where it is, and the file doesn't
This commit is contained in:
+11
-4
@@ -20,16 +20,23 @@ local load_json = function(file_name)
|
|||||||
assert(file, error_message)
|
assert(file, error_message)
|
||||||
local result = json.decode(file:read("*all"))
|
local result = json.decode(file:read("*all"))
|
||||||
file:close()
|
file:close()
|
||||||
|
|
||||||
|
result._loaded_file_location = file_name
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
local save_json = function(file_name, data)
|
local save_json = function(data)
|
||||||
|
local file_name = data._loaded_file_location
|
||||||
|
data._loaded_file_location = nil
|
||||||
|
|
||||||
local file, error_message = io.open(file_name, "w")
|
local file, error_message = io.open(file_name, "w")
|
||||||
assert(file, error_message)
|
assert(file, error_message)
|
||||||
file:write(json.encode(data, { indent = true, }))
|
file:write(json.encode(data, { indent = true, }))
|
||||||
file:write("\n")
|
file:write("\n")
|
||||||
file:close()
|
file:close()
|
||||||
debug("Saved.")
|
debug("Saved.")
|
||||||
|
|
||||||
|
data._loaded_file_location = file_name
|
||||||
end
|
end
|
||||||
|
|
||||||
local get_random_order = function(array)
|
local get_random_order = function(array)
|
||||||
@@ -429,7 +436,7 @@ local launch = function(file_name)
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
save_json(file_name, data)
|
save_json(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
local selected_books = get_books_by_preset(data, "launch")
|
local selected_books = get_books_by_preset(data, "launch")
|
||||||
@@ -470,11 +477,11 @@ local main = function(data, selected_books)
|
|||||||
-- no? these are completely separate modes, there should be quick add, update progress, rank mode, add pages mode, etc
|
-- no? these are completely separate modes, there should be quick add, update progress, rank mode, add pages mode, etc
|
||||||
end
|
end
|
||||||
|
|
||||||
save_json(default_file, data) -- this assumes it is equivalent with how launch() is called
|
save_json(data)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local data, selected_books = launch(default_file) -- the file name doesn't make it to main :\
|
local data, selected_books = launch(default_file)
|
||||||
while true do
|
while true do
|
||||||
main(data, selected_books)
|
main(data, selected_books)
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user