DRY some code

[?]
May 18, 2022, 6:10 AM
3RGHOJ25MCTQ5CRQADFIVJ53QZWRSIQOFGXLFGKQ765QABJ5S54AC

Dependencies

  • [2] VHQCNMAR several more modules
  • [3] XNFTJHC4 split keyboard handling between Text and Drawing
  • [4] JCSLDGAH beginnings of support for multiple shapes
  • [5] ZD63LJ2T bugfix: keep the click to create a new drawing from creating a new shape in the drawing
  • [6] OTIBCAUJ love2d scaffold
  • [7] POT3XFCT rename
  • [8] EFMLTMZG bugfix: restrict strokes to the drawing they started in
  • [9] KCIM5UTV revert: back to freehand
  • [10] L5USRTY2 inline
  • [11] WDWXNW7V slightly strange way to move points
  • [12] MNWHXPBL more lightweight; select just the stroke at the mouse
  • [13] SNDZOK6Q slightly less strange now that we have the same two ways to move points as any other operation
  • [14] VVXVV2D2 change data model; text can now have metadata
  • [15] O2UFJ6G3 switch from freehand to just straight lines
  • [16] XX7G2FFJ intermingle freehand line drawings with text
  • [17] TRCAEE2A clip drawings inside the border
  • [18] JVRL5TWL store device-independent coordinates inside drawings
  • [19] MGOQ5XAV start uppercasing globals
  • [20] AVQ5MC5D finish uppercasing all globals
  • [*] BLWAYPKV extract a module

Change contents

  • edit in main.lua at line 129
    [3.446]
    [3.76]
    if Lines.current == nil then return end
    local drawing = Lines.current
    assert(drawing.mode == 'drawing')
    local x, y = love.mouse.getX(), love.mouse.getY()
  • replacement in main.lua at line 134
    [3.109][3.357:467](),[3.32][3.2:60](),[3.104][3.2:60](),[3.467][3.2:60](),[3.780][3.2:60](),[3.1463][3.2:60](),[3.60][2.174:288](),[2.288][3.1397:1450](),[3.350][3.1397:1450](),[3.1736][3.1397:1450](),[3.957][3.1397:1450](),[3.1450][2.289:425](),[2.425][3.3:56](),[3.471][3.3:56](),[3.56][2.426:500](),[2.500][3.114:210](),[3.114][3.114:210](),[3.210][3.1570:1584](),[3.471][3.1570:1584](),[3.1570][3.1570:1584](),[3.87][3.1647:1659](),[3.229][3.1647:1659](),[3.634][3.1647:1659](),[3.1068][3.1647:1659](),[3.1584][3.1647:1659](),[3.1647][3.1647:1659]()
    if Lines.current then
    if Lines.current.mode == 'drawing' then
    local drawing = Lines.current
    local x, y = love.mouse.getX(), love.mouse.getY()
    if y >= drawing.y and y < drawing.y + Drawing.pixels(drawing.h) and x >= 16 and x < 16+Drawing_width then
    if drawing.pending.mode == 'freehand' then
    table.insert(drawing.pending.points, {x=Drawing.coord(love.mouse.getX()-16), y=Drawing.coord(love.mouse.getY()-drawing.y)})
    elseif drawing.pending.mode == 'move' then
    local mx,my = Drawing.coord(x-16), Drawing.coord(y-drawing.y)
    drawing.pending.target_point.x = mx
    drawing.pending.target_point.y = my
    end
    end
    [3.109]
    [3.1659]
    if Drawing.in_drawing(drawing, x,y) then
    if drawing.pending.mode == 'freehand' then
    table.insert(drawing.pending.points, {x=Drawing.coord(love.mouse.getX()-16), y=Drawing.coord(love.mouse.getY()-drawing.y)})
    elseif drawing.pending.mode == 'move' then
    local mx,my = Drawing.coord(x-16), Drawing.coord(y-drawing.y)
    drawing.pending.target_point.x = mx
    drawing.pending.target_point.y = my
  • replacement in main.lua at line 144
    [2.546][3.468:502](),[3.1774][3.468:502](),[3.61][3.468:502](),[3.502][3.95:149](),[3.95][3.95:149](),[3.149][2.547:657]()
    local drawing = Lines.current
    local x, y = love.mouse.getX(), love.mouse.getY()
    if y >= drawing.y and y < drawing.y + Drawing.pixels(drawing.h) and x >= 16 and x < 16+Drawing_width then
    [2.546]
    [2.657]
    if Drawing.in_drawing(drawing, x, y) then
  • replacement in drawing.lua at line 289
    [2.19238][2.19238:19350]()
    if y >= drawing.y and y < drawing.y + Drawing.pixels(drawing.h) and x >= 16 and x < 16+Drawing_width then
    [2.19238]
    [2.19350]
    if Drawing.in_drawing(drawing, x,y) then
  • replacement in drawing.lua at line 301
    [2.19586][2.19586:19800]()
    if y >= drawing.y and y < drawing.y + Drawing.pixels(drawing.h) and x >= 16 and x < 16+Drawing_width then
    local mx,my = Drawing.coord(love.mouse.getX()-16), Drawing.coord(love.mouse.getY()-drawing.y)
    [2.19586]
    [2.19800]
    if Drawing.in_drawing(drawing, x,y) then
    local mx,my = Drawing.coord(x-16), Drawing.coord(y-drawing.y)
  • replacement in drawing.lua at line 318
    [2.20189][2.20189:20403]()
    if y >= drawing.y and y < drawing.y + Drawing.pixels(drawing.h) and x >= 16 and x < 16+Drawing_width then
    local mx,my = Drawing.coord(love.mouse.getX()-16), Drawing.coord(love.mouse.getY()-drawing.y)
    [2.20189]
    [2.20403]
    if Drawing.in_drawing(drawing, x,y) then
    local mx,my = Drawing.coord(x-16), Drawing.coord(y-drawing.y)
  • replacement in drawing.lua at line 335
    [2.20784][2.20784:20896]()
    if y >= drawing.y and y < drawing.y + Drawing.pixels(drawing.h) and x >= 16 and x < 16+Drawing_width then
    [2.20784]
    [2.20896]
    if Drawing.in_drawing(drawing, x,y) then