Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Compare projects

dave1707dave1707 Mod
edited June 7 in Code Sharing Posts: 10,055

I don’t know if anyone can use this or not, but I thought I would share it anyways. I had 2 projects, one where I made some changes to, but I didn’t remember what/why something was changed. I didn’t want to try comparing them on 2 different iPads, so I wrote this. It was easy to see what the differences were. The code of the 2 projects were listed side by side and scrollable.

To use, key in the names of the 2 projects you want to compare as name1 and name2. Run the code and use the size slider to vary the width of the text to fit half the screen. Scrolling the text on the left half of the screen will close the parameter window (or manually close it) and move both text areas up or down together. Scrolling the text on the right half will only scroll that side so you can resync the code as you move down comparing the code and seeing any differences.

PS. Make sure there’s a blank line at the end of the projects or the last line won’t be seen. Not sure how to fix that yet because the gmatch code needs to find a \n to get that line of text.

viewer.mode=OVERLAY

function setup()
    name1="Qwert"
    name2="Asdfg"

    parameter.integer("size",20,80,40,setup1)
    textMode(CORNER)
    fill(255)
    setup1()
end

function setup1()
    dy1,dy2=0,0
    tab1,tab2={},{}
    process1()
    process2()
end


function process1()    
    str=""
    l=listProjectTabs(name1)
    for a,b in pairs(l) do
        str=str..readProjectTab(name1..":"..b)
    end
    for b in string.gmatch(str,".-%\n") do
        b=string.gsub(b,"\n"," ")        
        c,st=0,1
        while c<#b do
            table.insert(tab1,string.sub(b,st,st+size-1))
            c=c+size
            st=st+size
        end
    end
end

function process2()   
    str=""
    l=listProjectTabs(name2)
    for a,b in pairs(l) do
        str=str..readProjectTab(name2..":"..b)
    end
    for b in string.gmatch(str,".-%\n") do
        b=string.gsub(b,"\n"," ") 
        c,st=0,1
        while c<#b do
            table.insert(tab2,string.sub(b,st,st+size-1))
            c=c+size
            st=st+size
        end
    end
end    

function draw()
    background(0)
    stroke(50)
    strokeWidth(12)
    for z=1,HEIGHT/20 do
        line(0,z*20,WIDTH,z*20)
    end
    stroke(255)
    strokeWidth(2)
    line(WIDTH/2,0,WIDTH/2,HEIGHT)
    for a,b in pairs(tab1) do
        text(b,0,HEIGHT-a*20+dy1-50)
    end
    for a,b in pairs(tab2) do
        text(b,WIDTH/2,HEIGHT-a*20+dy2-50)
    end    
end

function touched(t)
    if t.state==BEGAN then
        viewer.mode=FULLSCREEN
        end
    if t.x<WIDTH/2 then
        dy1=dy1+t.deltaY
        dy2=dy2+t.deltaY
    else
        dy2=dy2+t.deltaY
    end  
end
Sign In or Register to comment.