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 // Importing objects
Objects.currentObjects = {} 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']) { for(let objType in data['objects']) {
if(Object.keys(Objects.types).indexOf(objType) > -1) { if(Object.keys(Objects.types).indexOf(objType) > -1) {
Objects.currentObjects[objType] = [] Objects.currentObjects[objType] = []

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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