Commit bc9e6cc7 authored by Jérémie Garcia's avatar Jérémie Garcia
Browse files

Multiplay new version

Uses the last selected elements for each sources
Initializitation with last trap for sources
parent 84a1ca50
......@@ -8,47 +8,75 @@ Traj.Manager = {
clipboardCurve : null, //temporary curve to paste
currentSource : 1, //the current selected source (apply to a selected source or set for the next one)
modifiedCurve : null,
NB_SOURCES : 8,
multiplay_indexes : [], //list of curve to play for each source indexes
//MULTIPLAY//
getPossibleTrajIndexesForSource : function (source_idx){
var traj_indexes = [];
var cpt = 0;
for (var i = 0; i < this.trajectories.length; i++) {
if(this.trajectories[i].sourceNumber === source_idx){
traj_indexes[cpt] = i;
cpt++;
}
}
return traj_indexes;
},
//this methods returns an array containeng the indexes of the curves for MultiPlay
getMultiPlayIndexes : function(active_index){
var indexes = [],
cpt =0,
multi = Traj.Manager.multiplay_indexes;
setTrajectories : function(traj_array){
this.trajectories = traj_array;
this.selectCurve(0);
Traj.View.repaintAll();
},
for (var i = 0; i < multi.length; i++) {
longestCurveIdxOfPlayedCurve : function(indexes) {
var maxTime = 0,
idx;
for (var k=0;k<indexes.length;k++) {
var time = this.trajectories[indexes[k]].lengthTime();
if (time>maxTime) {
maxTime = time;
idx = indexes[k];
if(multi[i] !== 'undefined'){
indexes[cpt] = multi[i];
cpt++;
}
}
return idx;
};
console.log("Get Multiplay create");
console.log(indexes);
return indexes;
},
getMultiPlayIndexes : function(){
var indexes = [],
source_pos = [],
pos = 0,
root = (Traj.Manager.hasSelectedCurve()) ? Traj.Manager.currentCurveIndex : 0;
//this methods update the multiplay indexes with the current curve
updateMultiPlayIndexes : function(source_nb, curve_index){
Traj.Manager.multiplay_indexes[(source_nb-1)] = curve_index;
},
for (var i = root; i < (Traj.Manager.trajectories.length + root); i++) {
var cpt = i % Traj.Manager.trajectories.length;
var src_nb = Traj.Manager.trajectories[cpt].sourceNumber;
createMultiPlayIndexes : function(){
if(typeof source_pos[src_nb]!=='undefined'){
indexes[source_pos[src_nb]] = cpt;
}else{
indexes[pos] = cpt;
source_pos[src_nb] = pos;
pos++;
var indexes = [];
//for each sources
for (var i = 0 ; i < Traj.Manager.NB_SOURCES; i++) {
var idx = 'undefined';
//for each curves we search for the last traj with the correct source number
for (var j = 0; j < Traj.Manager.trajectories.length; j++) {
var curve = Traj.Manager.trajectories[j];
//if correct, store the index
if((curve.sourceNumber - 1) === i){
idx = j;
}
}
indexes[i] = idx;
}
return indexes;
this.multiplay_indexes = indexes;
},
setTrajectories : function(traj_array){
this.trajectories = traj_array;
this.createMultiPlayIndexes();
this.selectCurve(0);
Traj.View.repaintAll();
},
processCreateNewCurve : function(x, y, z, t) {
......@@ -160,11 +188,9 @@ Traj.Manager = {
this.clipboardCurve = newCurve;
this.pasteInCurveAndAdapt(curve,firstPoint,lastPoint);
this.selectCurve(this.trajectories.length-1);
this.selectCurve(this.trajectories.length-1);
},
copyCurrentCurve : function(beginIdx,endIdx) {
if(Traj.Manager.hasCurveSelected())
......@@ -310,13 +336,13 @@ Traj.Manager = {
var nb = Traj.Manager.getCurrentCurve().sourceNumber;
Traj.Events.selectSourceButton(nb);
Traj.Manager.currentSource = nb;
Traj.Manager.updateMultiPlayIndexes(nb,index);
}
// change slider max value to curve max time, and time length, but not during drawing a new one (after)
if (Traj.Manager.trajectories[index] && index!=lastCurveIdx) {
Traj.Events.initSlider(false);
}
Traj.Session.saveTrajSession();
},
......@@ -480,7 +506,19 @@ Traj.Manager = {
Traj.View.traj_repaint();
Traj.View.dyn_repaint();
}
}
},
longestCurveIdxOfPlayedCurve : function(indexes) {
var maxTime = 0,
idx;
for (var k=0;k<indexes.length;k++) {
var time = this.trajectories[indexes[k]].lengthTime();
if (time>maxTime) {
maxTime = time;
idx = indexes[k];
}
}
return idx;
}
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment