Particle Editor Demo
import Felgo 3.0
import QtQuick 2.2
import "ArrayStorage.js" as ArrayStorage
import "ArrayStorage.js" as ArrayStorage2
Column {
id: column
width: innerSpace
anchors.horizontalCenter: parent.horizontalCenter
spacing: 6
property variant particleFiles: []
property variant particleFilesDataStorage: []
property variant editableType
property bool dataStorageLocation: false
onEditableTypeChanged: {
scene.itemEditor.currentEditableType = editableType
}
onDataStorageLocationChanged: {
scene.itemEditor.dataStorageLocation = dataStorageLocation
}
Column {
id: customParticles
width: parent.width
anchors.horizontalCenter: parent.horizontalCenter
spacing: 6
Rectangle {
visible: false
}
Item {
width: parent.width
height: customParticlesText.height
Text {
id: customParticlesText
text: "Custom Particles"
color: "white"
}
Text {
id: browseButton
anchors.left: customParticlesText.right
anchors.leftMargin: 10
text: "[...]"
color: "white"
visible: false
}
MouseArea {
anchors.fill: parent
onClicked: {
nativeUtils.openUrl(getDataStorageUrl(getInternalStorageLocation()))
}
}
}
}
Rectangle {
width: parent.width
height: 2
visible: false
}
Rectangle {
width: parent.width
height: 2
color: "white"
opacity: 0.75
}
Rectangle {
width: parent.width
height: 2
visible: false
}
function fillListWithFiles() {
var i = 0
var j = 0
var stringList = fileUtils.listFiles(Qt.resolvedUrl("particles/"),["*.json"])
var files = []
for(i = 0; i < stringList.length; i++){
files[i] = stringList[i]
}
particleFiles = files
stringList = fileUtils.listFiles(getDataStorageUrl(getInternalStorageLocation()), ["*.json"])
files = []
for(i = 0; i < stringList.length; i++){
files[i] = stringList[i]
}
particleFilesDataStorage = files
var currentArray = ArrayStorage.getArray()
var isAlreadyInArray = false
for(i = 0; i<particleFilesDataStorage.length; ++i) {
for(j = 0; j<currentArray.length; ++j) {
if(currentArray[j].text === ut.cropPath(particleFilesDataStorage[i], true)) {
isAlreadyInArray = true
}
}
if(!isAlreadyInArray) {
ArrayStorage.push(addButtonModel(particleFilesDataStorage[i], true))
}
isAlreadyInArray = false
}
if(currentArray.length && (system.isPlatform(System.Mac) || system.isPlatform(System.Linux) || system.isPlatform(System.Windows))) {
browseButton.visible = true
}
currentArray = ArrayStorage2.getArray()
isAlreadyInArray = false
for(i = 0; i<particleFiles.length; ++i) {
for(j = 0; j<currentArray.length; ++j) {
if(currentArray[j].text === ut.cropPath(particleFiles[i], true)) {
isAlreadyInArray = true
}
}
if(!isAlreadyInArray) {
ArrayStorage2.push(addButtonModel(particleFiles[i], false))
}
isAlreadyInArray = false
}
}
Utils {
id: ut
}
function addButtonModel(particleName, isDataStorageLocation) {
var component = Qt.createComponent("ParticleButton.qml");
if (component.status === Component.Ready) {
var buttonObject = component.createObject(isDataStorageLocation ? customParticles : column, {"text" : ut.cropPath(particleName, true),
"width": column.width,
"dataStorageLocation": isDataStorageLocation
});
if (buttonObject === null) {
console.debug("[ParticleButton] ERROR: creating repeater object failed!")
return 0
} else {
return buttonObject
}
} else if(component.status === Component.Error) {
console.log("[ParticleButton] ERROR: loading repeater object failed:", component.errorString())
return 0