starting to load/save

[?]
May 15, 2022, 9:00 PM
YKRF5V3ZZQIQ3UGAFYTQT5PUQVHCP2VHFDX77EY2C3X543HUDYKQC

Dependencies

  • [2] SNDZOK6Q slightly less strange now that we have the same two ways to move points as any other operation
  • [3] JCSLDGAH beginnings of support for multiple shapes
  • [4] 2C7CTIQY make space for multiple kinds of width
  • [5] IZZVOCLB confirm that we have access to all of the love API
  • [6] 2KRK3OBV don't rely on defaults
  • [7] OTIBCAUJ love2d scaffold
  • [8] GCUARQ2G bugfix: clipping in line and manhattan mode
  • [*] FMQ74DP3 new mode: circle

Change contents

  • edit in main.lua at line 51
    [3.21]
    [3.47]
    filename = nil
  • replacement in main.lua at line 54
    [3.48][3.48:69]()
    function love.load()
    [3.48]
    [3.69]
    function love.load(arg)
    if #arg > 0 then
    filename = arg[1]
    lines = load_from_disk(filename)
    end
  • replacement in main.lua at line 168
    [2.301][2.301:318](),[2.318][3.1626:1650](),[3.1626][3.1626:1650]()
    return
    end
    if lines.current then
    [2.301]
    [3.1650]
    elseif lines.current then
  • edit in main.lua at line 221
    [3.2109]
    [3.2109]
    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 then
    while true do
    local line = infile:read()
    if line == nil then break end
    if line == '```lines' then -- inflexible with whitespace since these files are always autogenerated
    table.insert(result, load_drawing(infile))
    else
    table.insert(result, line)
    end
    end
    end
    return result
    end
    function save_to_disk(lines, filename)
    local outfile = io.open(filename, 'w')
    for _,line in ipairs(lines) do
    if type(line) == 'table' then
    store_drawing(outfile, line)
    else
    outfile:write(line..'\n')
    end
    end
    end
    json = require 'json'
    function load_drawing(infile)
    local drawing = {h=256/2, points={}, shapes={}, pending={}}
    while true do
    local line = infile:read()
    assert(line)
    if line == '```' then break end
    local shape = json.decode(line)
    if shape.mode == 'line' then
    shape.p1 = insert_point(drawing.points, shape.p1.x, shape.p1.y)
    shape.p2 = insert_point(drawing.points, shape.p2.x, shape.p2.y)
    end
    table.insert(drawing.shapes, shape)
    end
    return drawing
    end
    function store_drawing(outfile, drawing)
    outfile:write('```lines\n')
    for _,shape in ipairs(drawing.shapes) do
    if shape.mode == 'line' then
    local line = json.encode({mode=shape.mode, p1=drawing.points[shape.p1], p2=drawing.points[shape.p2]})
    outfile:write(line..'\n')
    end
    end
    outfile:write('```\n')
    end