mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-25 01:05:12 +03:00
Waypoint OOP migration 1.0
This commit is contained in:
parent
ef5c999428
commit
525943baf1
4 changed files with 531 additions and 100 deletions
|
@ -1,4 +1,7 @@
|
|||
'use strict';
|
||||
//import { MWNP.WPTYPE, MWNP.WPTYPE.REV } from '/js/mission_control_module.mjs';
|
||||
//const { MWNP } = require('./js/mission_control_module.mjs')
|
||||
|
||||
|
||||
let WaypointCollection = function () {
|
||||
|
||||
|
@ -6,7 +9,9 @@ let WaypointCollection = function () {
|
|||
data = [],
|
||||
maxWaypoints = 0,
|
||||
isValidMission = 0,
|
||||
countBusyPoints = 0
|
||||
countBusyPoints = 0,
|
||||
version = 0,
|
||||
center = {}
|
||||
|
||||
self.getMaxWaypoints = function () {
|
||||
return maxWaypoints;
|
||||
|
@ -31,6 +36,30 @@ let WaypointCollection = function () {
|
|||
self.setCountBusyPoints = function (data) {
|
||||
countBusyPoints = data;
|
||||
};
|
||||
|
||||
self.getVersion = function () {
|
||||
return version;
|
||||
};
|
||||
|
||||
self.setVersion = function (data) {
|
||||
version = data;
|
||||
};
|
||||
|
||||
self.getCenter = function () {
|
||||
return center;
|
||||
};
|
||||
|
||||
self.setCenterZoom = function (data) {
|
||||
center.zoom = data;
|
||||
};
|
||||
|
||||
self.setCenterLon = function (data) {
|
||||
center.lon = data;
|
||||
};
|
||||
|
||||
self.setCenterLat = function (data) {
|
||||
center.lat = data;
|
||||
};
|
||||
|
||||
self.put = function (element) {
|
||||
data.push(element);
|
||||
|
@ -39,6 +68,10 @@ let WaypointCollection = function () {
|
|||
self.get = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
self.isEmpty = function () {
|
||||
return data == [];
|
||||
};
|
||||
|
||||
self.flush = function () {
|
||||
data = [];
|
||||
|
@ -56,6 +89,41 @@ let WaypointCollection = function () {
|
|||
}
|
||||
};
|
||||
|
||||
self.updateWaypoint = function(newWaypoint) {
|
||||
if (newWaypoint.isUsed()) {
|
||||
data[newWaypoint.getNumber()] = newWaypoint;
|
||||
}
|
||||
};
|
||||
|
||||
self.dropWaypoint = function(newWaypoint) {
|
||||
self.getWaypoint(newWaypoint.getNumber()).setUsed(false);
|
||||
var tmpData = [];
|
||||
let idx = 0;
|
||||
data.forEach(function (element) {
|
||||
if (element.isUsed()) {
|
||||
element.setNumber(idx)
|
||||
tmpData.push(element);
|
||||
idx++;
|
||||
}
|
||||
});
|
||||
|
||||
data = tmpData;
|
||||
|
||||
};
|
||||
|
||||
self.insertWaypoint = function (newWaypoint, indexId) {
|
||||
data.forEach(function (wp) {
|
||||
if (wp.getNumber() >= indexId) {
|
||||
wp.setNumber(wp.getNumber()+1);
|
||||
}
|
||||
if (wp.getAction() == MWNP.WPTYPE.JUMP && wp.getP1()>=indexId) {
|
||||
wp.setP1(wp.getP1()+1);
|
||||
}
|
||||
});
|
||||
data.splice(indexId, 0, newWaypoint);
|
||||
};
|
||||
|
||||
|
||||
self.drop = function (waypointId) {
|
||||
self.getWaypoint(waypointId).setUsed(false);
|
||||
var tmpData = [];
|
||||
|
@ -70,6 +138,44 @@ let WaypointCollection = function () {
|
|||
|
||||
data = tmpData;
|
||||
};
|
||||
|
||||
self.update = function (bMWPfile=false) {
|
||||
let oldWPNumber = 0;
|
||||
let idx = 0;
|
||||
data.forEach(function (element) {
|
||||
if (element.isUsed()) {
|
||||
if (bMWPfile) {
|
||||
element.setNumber(element.getNumber()-1);
|
||||
if (element.getAction() == MWNP.WPTYPE.JUMP) {
|
||||
element.setP1(element.getP1()-1);
|
||||
}
|
||||
}
|
||||
if ([MWNP.WPTYPE.JUMP,MWNP.WPTYPE.SET_HEAD,MWNP.WPTYPE.RTH].includes(element.getAction())) {
|
||||
element.setAttachedId(oldWPNumber);
|
||||
element.setAttached(true);
|
||||
}
|
||||
else {
|
||||
oldWPNumber = element.getNumber();
|
||||
element.setLayerNumber(idx);
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
self.getAttachedList = function () {
|
||||
let tmpData = [];
|
||||
data.forEach(function (element) {
|
||||
if (element.isAttached()) {
|
||||
tmpData.push(element);
|
||||
}
|
||||
});
|
||||
|
||||
return tmpData;
|
||||
}
|
||||
|
||||
|
||||
return self;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue