Created
September 16, 2018 22:41
-
-
Save Jorger/5e2a6d08f5e057af090faa0449a01944 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const readDataLevels = data => { | |
const dataWord = []; | |
const splitdata = data.split(";"); | |
for (let value of splitdata) { | |
const splitWorld = value.split("#"); | |
const splitDimensionColors = splitWorld[0].split(","); | |
const pipesValue = splitWorld[1]; | |
//Partir los valores que se necesitan... | |
//Guardar los valores de inicio... | |
const limitPoints = { s: [], e: [] }; | |
//Guardar los valores de finalización... | |
//Tener en cuenta los valores dobles (6 y 7)... | |
const coordinatesPipes = []; | |
let contColor = 0; | |
let contPipe = 0; | |
for (let i = 0; i < pipesValue.length / 4; i++) { | |
const valueData = pipesValue.substr(4 * i, 4).split(""); | |
let colorPipe = ""; | |
if (+valueData[2] === 1 || +valueData[2] === 2) { | |
const colorPosition = splitDimensionColors[contColor + 1]; | |
if (colorPosition.indexOf("-") >= 0) { | |
//Es un color combinado... | |
const splitColors = colorPosition.split("-"); | |
colorPipe = colors[+splitColors[0] - 1]; | |
for (let c = 1; c < splitColors.length; c++) { | |
colorPipe = rgbToHex( | |
colorMixer( | |
hexToRgb(colorPipe), | |
hexToRgb(colors[+splitColors[c] - 1]) | |
) | |
); | |
} | |
} else { | |
colorPipe = colors[+colorPosition - 1]; | |
} | |
contColor++; | |
limitPoints[+valueData[2] === 1 ? "s" : "e"].push(contPipe); | |
} | |
//Se adiciona el color de la figura y el valor para el movimiento de la misma (ángulo inicial)... | |
valueData.push(colorPipe, valueData[3]); | |
//Validar los valores especiales (cruceta (6) y doble curva (7))... | |
if (+valueData[2] === 6 || +valueData[2] === 7) { | |
const originalData = +valueData[2]; | |
const originalAngle = +valueData[3]; | |
//Se cambia la figura por su valor correspondiente... | |
valueData[2] = originalData === 6 ? 5 : 4; | |
//Se hace una copia del array para el opuesto... | |
const cloneValue = [...valueData]; | |
//Establece el valor del opuesto en base al original... | |
cloneValue[3] = | |
originalData === 6 ? +!originalAngle : [2, 3, 0, 1][originalAngle]; | |
coordinatesPipes.push( | |
serializeData(valueData), | |
serializeData(cloneValue) | |
); | |
contPipe++; | |
} else { | |
coordinatesPipes.push(serializeData(valueData)); | |
} | |
contPipe++; | |
} | |
dataWord.push([ | |
+splitDimensionColors[0], | |
coordinatesPipes, | |
limitPoints.s, | |
limitPoints.e | |
]); | |
} | |
return dataWord; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment