starting to load/save
[?]
May 15, 2022, 9:00 PM
YKRF5V3ZZQIQ3UGAFYTQT5PUQVHCP2VHFDX77EY2C3X543HUDYKQCDependencies
- [2]
SNDZOK6Qslightly less strange now that we have the same two ways to move points as any other operation - [3]
JCSLDGAHbeginnings of support for multiple shapes - [4]
2C7CTIQYmake space for multiple kinds of width - [5]
IZZVOCLBconfirm that we have access to all of the love API - [6]
2KRK3OBVdon't rely on defaults - [7]
OTIBCAUJlove2d scaffold - [8]
GCUARQ2Gbugfix: clipping in line and manhattan mode - [*]
FMQ74DP3new mode: circle
Change contents
- edit in main.lua at line 51
filename = nil - replacement in main.lua at line 54
function love.load()function love.load(arg)if #arg > 0 thenfilename = arg[1]lines = load_from_disk(filename)end - replacement in main.lua at line 168
returnendif lines.current thenelseif lines.current then - edit in main.lua at line 221
save_to_disk(lines, filename) - edit in main.lua at line 760[10.1482]
function load_from_disk(filename)local result = {}local infile = io.open(filename)if infile thenwhile true dolocal line = infile:read()if line == nil then break endif line == '```lines' then -- inflexible with whitespace since these files are always autogeneratedtable.insert(result, load_drawing(infile))elsetable.insert(result, line)endendendreturn resultendfunction save_to_disk(lines, filename)local outfile = io.open(filename, 'w')for _,line in ipairs(lines) doif type(line) == 'table' thenstore_drawing(outfile, line)elseoutfile:write(line..'\n')endendendjson = require 'json'function load_drawing(infile)local drawing = {h=256/2, points={}, shapes={}, pending={}}while true dolocal line = infile:read()assert(line)if line == '```' then break endlocal shape = json.decode(line)if shape.mode == 'line' thenshape.p1 = insert_point(drawing.points, shape.p1.x, shape.p1.y)shape.p2 = insert_point(drawing.points, shape.p2.x, shape.p2.y)endtable.insert(drawing.shapes, shape)endreturn drawingendfunction store_drawing(outfile, drawing)outfile:write('```lines\n')for _,shape in ipairs(drawing.shapes) doif shape.mode == 'line' thenlocal line = json.encode({mode=shape.mode, p1=drawing.points[shape.p1], p2=drawing.points[shape.p2]})outfile:write(line..'\n')endendoutfile:write('```\n')end