@name Setpos Door
@inputs [D1 D2 D3 D4]:entity Button 
@outputs 
@persist OpenSpeed CloseSpeed OpenD1 OpenD2 OpenD3 OpenD4 Close OpenLimit 
@persist Tick Tock Num Num2 
@trigger 
interval(1000)

OpenSpeed = 5
OpenLimit = 55
CloseLimit = 0
Num = 30
Num2 = 30
CloseSpeed = 4

if (first()) {
    D1:setPos(entity():toWorld(vec(-1,17.793757438659,47.449996948242)))
    D2:setPos(entity():toWorld(vec(-1,5.931252479553,47.449996948242)))
    D3:setPos(entity():toWorld(vec(-1,5.931252479553,47.449996948242)))
    D4:setPos(entity():toWorld(vec(-1,17.793757438659,47.449996948242)))
}

if (Button) {
    Tick = 1
    
    timer("tick",100)
    
    if (clk("tick")) {
        if (OpenD4 < OpenLimit) {OpenD4 += OpenSpeed}
        if (OpenD4 >= OpenLimit-Num & OpenD3 < OpenLimit) {OpenD3 += OpenSpeed}
        if (OpenD4 >= OpenLimit-Num & OpenD3 >= OpenLimit-Num & OpenD2 < OpenLimit) {OpenD2 += OpenSpeed}
        if (OpenD4 >= OpenLimit-Num & OpenD3 >= OpenLimit-Num & OpenD2 >= OpenLimit-Num & OpenD1 < OpenLimit) {OpenD1 += OpenSpeed}
    }
    
    D1:setPos(entity():toWorld(vec(-1,OpenD1-17.793757438659,47.449996948242)))
    D2:setPos(entity():toWorld(vec(-1,OpenD2-5.931252479553,47.449996948242)))
    D3:setPos(entity():toWorld(vec(-1,OpenD3+5.931252479553,47.449996948242)))
    D4:setPos(entity():toWorld(vec(-1,OpenD4+17.793757438659,47.449996948242)))
}


if (!Button) {
    timer("tick",100)
    
    if (clk("tick")) {
        if (OpenD1 > CloseLimit) {OpenD1 -= CloseSpeed}
        if (OpenD1 <= CloseLimit+Num2 & OpenD2 > CloseLimit) {OpenD2 -= CloseSpeed}
        if (OpenD1 <= CloseLimit+Num2 & OpenD2 <= CloseLimit+Num2 & OpenD3 > CloseLimit) {OpenD3 -= CloseSpeed}
        if (OpenD1 <= CloseLimit+Num2 & OpenD2 <= CloseLimit+Num2 & OpenD3 <= CloseLimit+Num2 & OpenD4 > CloseLimit) {OpenD4 -= CloseSpeed}
    }
    
    D1:setPos(entity():toWorld(vec(-1,OpenD1-17.793757438659,47.449996948242)))
    D2:setPos(entity():toWorld(vec(-1,OpenD2-5.931252479553,47.449996948242)))
    D3:setPos(entity():toWorld(vec(-1,OpenD3+5.931252479553,47.449996948242)))
    D4:setPos(entity():toWorld(vec(-1,OpenD4+17.793757438659,47.449996948242)))
}

#print(D1:pos():z()-" | "-OpenD1)

#11.862504959106,94.899993896484,3
