Android Question can you convert this JS code to B4x please

trvip

Member
or can you show how it can be converted
it is a class.

class Line::
function Line(data) { // data=points x and y, color and layer
    //Define Properties         
    this.type = "Line";
    this.family = "Geometry";
    this.minPoints = 2;
    this.showPreview = true;
    this.helper_geometry = false;
    this.points = [];
    this.lineWidth = 2;
    this.colour = "BYLAYER";
    this.layer = "0";
    this.alpha = 1.0

    if (data) {

        //console.log(data.points, data.colour, data.layer)

        var startPoint = new Point(data.points[data.points.length - 2].x, data.points[data.points.length - 2].y);
        var endPoint = new Point(data.points[data.points.length - 1].x, data.points[data.points.length - 1].y);

        this.points.push(startPoint);
        this.points.push(endPoint);

        if (data.colour) {
            this.colour = data.colour;
        }

        if (data.layer) {
            this.layer = data.layer;
        }
    }
}

Line.prototype.prompt = function (inputArray) {
    var num = inputArray.length;
    var expectedType = [];
    var reset = false;
    var action = false;
    var validInput = true
    var prompt = [];
    
    expectedType[0] = ["undefined"];
    prompt[0] = "Pick start point:";
 
    expectedType[1] = ["object"];   
    prompt[1] = "Pick another point or press ESC to quit:";

    expectedType[2] = ["object","number"];   
    prompt[2] = prompt[1];

    expectedType[3] = ["object","number"];   
    prompt[3] = prompt[1];

    validInput = expectedType[num].includes(typeof inputArray[num-1])
            
    if(!validInput || num > this.minPoints){
        inputArray.pop()
    }
    
    if (inputArray.length === this.minPoints){
        action = true;
        //reset = true
    }

    return [prompt[inputArray.length], reset, action, validInput]
}

thx
 
Top