clean up some final bifold code

This commit is contained in:
Kartik K. Agaram 2023-04-01 20:39:39 -07:00
parent c87e4a3bab
commit 86517606a1
2 changed files with 3 additions and 19 deletions

View File

@ -1,7 +1,5 @@
-- primitives for saving to file and loading from file -- primitives for saving to file and loading from file
Fold = '\x1e' -- ASCII RS (record separator)
function file_exists(filename) function file_exists(filename)
local infile = App.open_for_reading(filename) local infile = App.open_for_reading(filename)
if infile then if infile then
@ -28,13 +26,7 @@ function load_from_file(infile)
if line == '```lines' then -- inflexible with whitespace since these files are always autogenerated if line == '```lines' then -- inflexible with whitespace since these files are always autogenerated
table.insert(result, load_drawing(infile_next_line)) table.insert(result, load_drawing(infile_next_line))
else else
local line_info = {mode='text'} table.insert(result, {mode='text', data=line})
if line:find(Fold) then
_, _, line_info.data, line_info.dataB = line:find('([^'..Fold..']*)'..Fold..'([^'..Fold..']*)')
else
line_info.data = line
end
table.insert(result, line_info)
end end
end end
end end
@ -54,10 +46,6 @@ function save_to_disk(State)
store_drawing(outfile, line) store_drawing(outfile, line)
else else
outfile:write(line.data) outfile:write(line.data)
if line.dataB and #line.dataB > 0 then
outfile:write(Fold)
outfile:write(line.dataB)
end
outfile:write('\n') outfile:write('\n')
end end
end end
@ -147,11 +135,7 @@ function load_array(a)
else else
--? print('inserting text') --? print('inserting text')
local line_info = {mode='text'} local line_info = {mode='text'}
if line:find(Fold) then line_info.data = line
_, _, line_info.data, line_info.dataB = line:find('([^'..Fold..']*)'..Fold..'([^'..Fold..']*)')
else
line_info.data = line
end
table.insert(result, line_info) table.insert(result, line_info)
end end
end end

View File

@ -61,7 +61,7 @@ function snapshot(State, s,e)
for i=s,e do for i=s,e do
local line = State.lines[i] local line = State.lines[i]
if line.mode == 'text' then if line.mode == 'text' then
table.insert(event.lines, {mode='text', data=line.data, dataB=line.dataB}) table.insert(event.lines, {mode='text', data=line.data})
elseif line.mode == 'drawing' then elseif line.mode == 'drawing' then
local points=deepcopy(line.points) local points=deepcopy(line.points)
--? print('copying', line.points, 'with', #line.points, 'points into', points) --? print('copying', line.points, 'with', #line.points, 'points into', points)