@name egpCreator
@inputs EGP:wirelink
@outputs String:string
@persist PosY PosX Index Editing Total Removed Removing ColorBef:vector
@persist Coloring Time Export:string Text:string
@trigger
runOnTick(1)
runOnChat(1)
PosY=EGP:egpCursor(owner()):y()
PosX=EGP:egpCursor(owner()):x()
LSi=owner():lastSaid():explode(" ")
LS=owner():lastSaid()
if(first()){Total=0 Removed=0 Time=0
    Export="@name egpCreator File
"
    Export=Export+"@inputs EGP:wirelink
"
}
   
if(chatClk()){
    if(LSi:string(1)=="!remove"){
        hideChat(1)
        if(LSi:string(2)){
            EGP:egpRemove(LSi:string(2):toNumber())
            Total=Total-1
            Export=Export+"
            EGP:egpRemove("+LSi:string(2):toNumber()+")"
            print("Removed index:"+LSi:string(2))
        } else {
            print("Syntax Error: Missing argument")
            print("Usage: !remove ID")
        }
    }
    if(LSi:string(1)=="!editPos"){
        hideChat(1)
        Editing=1
        Index=LSi:string(2):toNumber()
        print("Now editing position of index:"+Index)
    }
    if(LSi:string(1)=="!save"){
        hideChat(1)
        Editing=0
        Saved=round(EGP:egpPos(Index))
        Export = Export + "
        EGP:egpPos("+Index+",vec2("+PosX+","+PosY+"))"
        print("Position saved to "+Saved:toString())          
    }
   
    if(LSi:string(1)=="!find"){
        hideChat(1)
        Index=LSi:string(2):toNumber()
        ColorBef=EGP:egpColor(Index)
        Saved=round(EGP:egpPos(Index))
        Coloring=1
        print("You are now viewing the index:"+Index)
        print(Index+" position is "+Saved:toString())
        print(Index+" color is "+ColorBef)  
        print(Index+" is now RED to make easier to find")
        print("Its color will get back in a while")
             
    }
   
    if(LSi:string(1)=="!color"){
        hideChat(1)
        Index=LSi:string(2):toNumber()
        Color1=LSi:string(3):toNumber()
        Color2=LSi:string(4):toNumber()
        Color3=LSi:string(5):toNumber()
        EGP:egpColor(Index,vec(Color1,Color2,Color3))
        Export = Export + "
        EGP:egpColor("+Index+",vec("+Color1+","+Color2+","+Color3+"))"
        print("Changed color of index:"+Index+" to "+Color1+","+Color2+","+Color3)
    }
   
    if(LSi:string(1)=="!create"){
        if(LSi:string(2)=="box"){
            hideChat(1)
            Total=Total+1
            EGP:egpBox(Total,vec2(20,20),vec2(20,20))
            Export = Export + "
            EGP:egpBox("+Total+",vec2(20,20),vec2(20,20)) "
            print("Created a box")
        }
        if(LSi:string(2)=="rounded"){
            hideChat(1)
            Total=Total+1
            EGP:egpRoundedBox(Total,vec2(20,20),vec2(20,20))
            Export = Export + "
            EGP:egpRoundedBox("+Total+",vec2(20,20),vec2(20,20)) "
            print("Created a roundedBox")
        }
        if(LSi:string(2)=="circle"){
            hideChat(1)
            Total=Total+1
            EGP:egpCircle(Total,vec2(20,20),vec2(20,20))
            Export = Export + "
            EGP:egpCircle("+Total+",vec2(20,20),vec2(20,20)) "
            print("Created a circle")
        }  
    }
    if(LSi:string(1)=="!removeAll"){
        hideChat(1)
        Removing=1
    }
   
    if(LSi:string(1)=="!copy"){
        hideChat(1)
        Index=LSi:string(2):toNumber()
        Total=Total+1
        EGP:egpCopy(Total,Index)
        EGP:egpPos(Total,vec2(20,20))
        print("Copied index:"+Index+" to "+Total)
    }
   
    if(LSi:string(1)=="!size"){
        hideChat(1)
        Index=LSi:string(2):toNumber()
        Size1=LSi:string(3):toNumber()
        Size2=LSi:string(4):toNumber()
        if(Size2){
            EGP:egpSize(Index,vec2(Size1,Size2))
            Export = Export + "
            EGP:egpSize("+Index+",vec2("+Size1+","+Size2+"))"
            print("Changed size of index:"+Index+" to "+Size1+","+Size2)
        } else {
            EGP:egpSize(Index,Size1)
            Export = Export + "
            EGP:egpSize("+Index+","+Size1+")"
            print("Changed size of index:"+Index+" to "+Size1)
        }
    }
   
    if(LSi:string(1)=="!export"){
        hideChat(1)
        if(LSi:string(2)){
            E2updateFILENAME = LSi:string(2)
            E2updateCODE = Export
            if(fileCanWrite()) {
                fileWrite(">e2shared/" + E2updateFILENAME + ".txt",E2updateCODE)
                print("Created file "+E2updateFILENAME)
            }
        } else {
            print("Syntax Error: Missing argument")
            print("Usage: !export NAME")
        }
    }
   
    if(LSi:string(1)=="!text"){
        hideChat(1)
        Total=Total+1
        I=2
        Text = LSi:string(2)
        while(I<LSi:count()){
            I++
            Text=Text+" "+LSi:string(I)  
        }        
        EGP:egpText(Total,Text,vec2(20,20))
        Export=Export+ "
        Text = \""+Text+"\"
        EGP:egpText("+Total+",Text,vec2(20,20))"
        print("Created '"+Text+"' (text)")
    }
}
 
if(Editing==1){
    EGP:egpPos(Index,vec2(PosX,PosY))
}
if(Removing==1){
    while(Removed<=Total+1){
        Removed=Removed+1
        EGP:egpRemove(Removed)          
    }
    if(Removed>Total){
        print("Removed all the "+Total+" index")
        Removing=0
        Total=0
        Removed=0
        Export="@name egpCreator File
"
        Export=Export+"@inputs EGP:wirelink
"
    }
       
}
if(Coloring==1){
    if(Time==400){
        EGP:egpColor(Index,ColorBef)
        Time=0
        Coloring=0
        print(Index+" normal color is now back")
    } else {
        EGP:egpColor(Index,vec(255,0,0))
        Time=Time+1  
    }
}
