Fixing bugs in recursive object deletion and dependency.

This commit is contained in:
Adsooi 2022-10-18 22:40:49 +02:00
parent fcf5ef9539
commit 64d1419452
Signed by: Ad5001
GPG key ID: 7251B1AF90B960F9
7 changed files with 12 additions and 8 deletions

View file

@ -249,7 +249,11 @@ ApplicationWindow {
// Importing objects
Objects.currentObjects = {}
Objects.currentObjectsByName = {}
Object.keys(Objects.currentObjectsByName).forEach(key => {
delete Objects.currentObjectsByName[key];
// Required to keep the same reference for the copy of the object used in expression variable detection.
// Another way would be to change the reference as well, but I feel like the code would be less clean.
})
for(let objType in data['objects']) {
if(Object.keys(Objects.types).indexOf(objType) > -1) {
Objects.currentObjects[objType] = []

View file

@ -96,7 +96,7 @@ ScrollView {
posPicker: positionPicker
onChanged: {
//obj = Objects.currentObjects[objType][index]
obj = Objects.currentObjects[objType][index]
objectListList.update()
}

View file

@ -110,7 +110,6 @@ Item {
MouseArea {
anchors.fill: parent
onClicked: {
console.log(obj.type)
objEditor.obj = Objects.currentObjects[obj.type][index]
objEditor.objType = obj.type
objEditor.objIndex = index
@ -211,9 +210,9 @@ Item {
Deletes an object and it's dependencies recursively.
*/
function deleteRecursively(object) {
console.log(object.name, object.requiredBy.length)
for(let toRemove of object.requiredBy)
deleteRecursively(toRemove)
object.requiredBy = []
history.addToHistory(new HistoryLib.DeleteObject(
object.name, object.type, object.export()
))

View file

@ -1836,9 +1836,9 @@ var optionNameMap = {
'not': 'logical',
'?': 'conditional',
':': 'conditional',
'=': 'assignment',
//'=': 'assignment', // Disable assignment
'[': 'array',
'()=': 'fndef'
//'()=': 'fndef' // Diable function definition
};
function getOptionName(op) {

View file

@ -45,6 +45,7 @@ class CreateNewObject extends C.Action {
redo() {
Objects.createNewRegisteredObject(this.targetType, this.targetProperties)
Objects.currentObjectsByName[this.targetName].update()
}
export() {

View file

@ -47,8 +47,8 @@ function deleteObject(objName) {
*/
let obj = currentObjectsByName[objName]
currentObjects[obj.type].splice(currentObjects[obj.type].indexOf(obj),1)
delete currentObjectsByName[objName]
obj.delete()
delete currentObjectsByName[objName]
}
function getObjectsName(objType) {

View file

@ -200,7 +200,7 @@ class DrawableObject {
if(properties[property] == 'Expression' && this[property] != null) {
// Expressions with dependencies
for(let objName of this[property].requiredObjects()) {
if(objName in C.currentObjectsByName && !this.requires.includes(objName)) {
if(objName in C.currentObjectsByName && !this.requires.includes(C.currentObjectsByName[objName])) {
this.requires.push(C.currentObjectsByName[objName])
C.currentObjectsByName[objName].requiredBy.push(this)
}