From a0cd84e04ddf68055b5eeca49b2db47a57885441 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Davy=20H=C3=A9lard?= Date: Mon, 8 Jan 2024 20:21:23 +0100 Subject: [PATCH 1/2] [Object picking tools] Fix crashes of pick first, pick last and pick Nth and deprecate them. - These conditions don't work for groups and would likely break in future releases of GDevelop. --- extensions/community/ObjectPickingTools.json | 110 ++++++++++++------- 1 file changed, 72 insertions(+), 38 deletions(-) diff --git a/extensions/community/ObjectPickingTools.json b/extensions/community/ObjectPickingTools.json index dddc0d4bb..d70214e46 100644 --- a/extensions/community/ObjectPickingTools.json +++ b/extensions/community/ObjectPickingTools.json @@ -8,7 +8,7 @@ "name": "ObjectPickingTools", "previewIconUrl": "https://resources.gdevelop-app.com/assets/Icons/selection-ellipse-arrow-inside.svg", "shortDescription": "Adds various object picking related tools.", - "version": "2.0.0", + "version": "2.1.0", "description": [ "Adds various actions and conditions for advanced object selection. Includes picking objects with the highest or lowest zOrder, an object variable, and the ability to unpick all objects.", "", @@ -163,11 +163,11 @@ "objectGroups": [] }, { - "description": "Pick object instances that have the lowest zOrder.", - "fullName": "Pick objects with lowest zOrder", + "description": "Pick object instances that have the lowest Z-order.", + "fullName": "Pick objects with lowest Z-order", "functionType": "Condition", "name": "PickLowestZCondition", - "sentence": "Pick _PARAM1_ with the lowest zOrder", + "sentence": "Pick _PARAM1_ with the lowest Z-order", "events": [ { "type": "BuiltinCommonInstructions::JsCode", @@ -296,11 +296,11 @@ "objectGroups": [] }, { - "description": "Pick object instances that have the highest zOrder.", - "fullName": "Pick objects with highest zOrder", + "description": "Pick object instances that have the highest Z-order.", + "fullName": "Pick objects with highest Z-order", "functionType": "Condition", "name": "PickHighestZCondition", - "sentence": "Pick _PARAM1_ with the highest zOrder", + "sentence": "Pick _PARAM1_ with the highest Z-order", "events": [ { "type": "BuiltinCommonInstructions::JsCode", @@ -368,10 +368,10 @@ }, { "description": "Pick object instances that have the lowest value of an object variable.", - "fullName": "Pick objects with lowest value of an object variable", + "fullName": "Pick objects with lowest variable value", "functionType": "Action", "name": "PickLowestVariableValueAction", - "sentence": "Pick _PARAM1_ with the lowest value of object variable _PARAM2_", + "sentence": "Pick _PARAM1_ with the lowest value of variable _PARAM2_", "events": [ { "type": "BuiltinCommonInstructions::JsCode", @@ -438,10 +438,10 @@ }, { "description": "Pick object instances that have the lowest value of an object variable.", - "fullName": "Pick objects with lowest value of an object variable", + "fullName": "Pick objects with lowest variable value", "functionType": "Condition", "name": "PickLowestVariableValueCondition", - "sentence": "Pick _PARAM1_ with the lowest value of object variable _PARAM2_", + "sentence": "Pick _PARAM1_ with the lowest value of variable _PARAM2_", "events": [ { "type": "BuiltinCommonInstructions::JsCode", @@ -517,10 +517,10 @@ }, { "description": "Pick object instances that have the highest value of an object variable.", - "fullName": "Pick objects with highest value of an object variable", + "fullName": "Pick objects with highest variable value", "functionType": "Action", "name": "PickHighestVariableValueAction", - "sentence": "Pick _PARAM1_ with the highest value of object variable _PARAM2_", + "sentence": "Pick _PARAM1_ with the highest value of variable _PARAM2_", "events": [ { "type": "BuiltinCommonInstructions::JsCode", @@ -587,10 +587,10 @@ }, { "description": "Pick object instances that have the highest value of an object variable.", - "fullName": "Pick objects with highest value of an object variable", + "fullName": "Pick objects with highest variable value", "functionType": "Condition", "name": "PickHighestVariableValueCondition", - "sentence": "Pick _PARAM1_ with the highest value of object variable _PARAM2_", + "sentence": "Pick _PARAM1_ with the highest value of variable _PARAM2_", "events": [ { "type": "BuiltinCommonInstructions::JsCode", @@ -666,9 +666,10 @@ }, { "description": "Picks the first instance out of a list of objects.", - "fullName": "Pick the first object", + "fullName": "Pick the first object (deprecated)", "functionType": "Action", "name": "PickFirstAction", + "private": true, "sentence": "Pick the first _PARAM1_", "events": [ { @@ -678,7 +679,11 @@ "\r", "for (const listName in lists) {\r", " const list = lists[listName];\r", - " list.length = 1;\r", + " // TODO The 1st object in the list won't necessarily be the oldest one.\r", + " // For instance, a collision condition that uses a spatial structure may change the order.\r", + " if (list.length > 1) {\r", + " list.length = 1;\r", + " }\r", "}\r", "" ], @@ -698,9 +703,10 @@ }, { "description": "Picks the first instance out of a list of objects.", - "fullName": "Pick the first object", + "fullName": "Pick the first object (deprecated)", "functionType": "Condition", "name": "PickFirstCondition", + "private": true, "sentence": "Pick the first _PARAM1_", "events": [ { @@ -710,7 +716,11 @@ "\r", "for (const listName in lists) {\r", " const list = lists[listName];\r", - " list.length = 1;\r", + " // TODO The 1st object in the list won't necessarily be the oldest one.\r", + " // For instance, a collision condition that uses a spatial structure may change the order.\r", + " if (list.length > 1) {\r", + " list.length = 1;\r", + " }\r", "}\r", "" ], @@ -744,9 +754,10 @@ }, { "description": "Picks the last instance out of a list of objects.", - "fullName": "Pick the last object", + "fullName": "Pick the last object (deprecated)", "functionType": "Action", "name": "PickLastAction", + "private": true, "sentence": "Pick the last _PARAM1_", "events": [ { @@ -756,8 +767,12 @@ "\r", "for (const listName in lists) {\r", " const list = lists[listName];\r", - " list[0] = list[list.length - 1];\r", - " list.length = 1;\r", + " // TODO The last object in the list won't necessarily be the newest one.\r", + " // For instance, a collision condition that uses a spatial structure may change the order.\r", + " if (list.length > 1) {\r", + " list[0] = list[list.length - 1];\r", + " list.length = 1;\r", + " }\r", "}\r", "" ], @@ -777,9 +792,10 @@ }, { "description": "Picks the last instance out of a list of objects.", - "fullName": "Pick the last object", + "fullName": "Pick the last object (deprecated)", "functionType": "Condition", "name": "PickLastCondition", + "private": true, "sentence": "Pick the last _PARAM1_", "events": [ { @@ -789,14 +805,18 @@ "\r", "for (const listName in lists) {\r", " const list = lists[listName];\r", - " list[0] = list[list.length - 1];\r", - " list.length = 1;\r", + " // TODO The last object in the list won't necessarily be the newest one.\r", + " // For instance, a collision condition that uses a spatial structure may change the order.\r", + " if (list.length > 1) {\r", + " list[0] = list[list.length - 1];\r", + " list.length = 1;\r", + " }\r", "}\r", "" ], "parameterObjects": "", "useStrict": true, - "eventsSheetExpanded": false + "eventsSheetExpanded": true }, { "type": "BuiltinCommonInstructions::Standard", @@ -824,28 +844,35 @@ }, { "description": "Picks the Nth instance out of a list of objects.", - "fullName": "Pick the Nth object", + "fullName": "Pick the Nth object (deprecated)", "functionType": "Action", "name": "PickNthAction", + "private": true, "sentence": "Pick the _PARAM2_th _PARAM1_", "events": [ { "type": "BuiltinCommonInstructions::JsCode", "inlineCode": [ "const lists = eventsFunctionContext.getObjectsLists(\"object\").items;\r", - "const n = eventsFunctionContext.getObjectsLists(\"n\");\r", + "const n = eventsFunctionContext.getArgument(\"n\");\r", "\r", "for (const listName in lists) {\r", " const list = lists[listName];\r", - " if (n >= list.length) continue;\r", - " list[0] = list[n];\r", - " list.length = 1;\r", + " // TODO Objects from the list won't necessarily be the order they were created.\r", + " // For instance, a collision condition that uses a spatial structure may change the order.\r", + " if (n < list.length) {\r", + " list[0] = list[n];\r", + " list.length = 1;\r", + " }\r", + " else {\r", + " list.length = 0;\r", + " }\r", "}\r", "" ], "parameterObjects": "", "useStrict": true, - "eventsSheetExpanded": false + "eventsSheetExpanded": true } ], "parameters": [ @@ -864,28 +891,35 @@ }, { "description": "Picks the Nth instance out of a list of objects.", - "fullName": "Pick the Nth object", + "fullName": "Pick the Nth object (deprecated)", "functionType": "Condition", "name": "PickNthCondition", + "private": true, "sentence": "Pick the _PARAM2_th _PARAM1_", "events": [ { "type": "BuiltinCommonInstructions::JsCode", "inlineCode": [ "const lists = eventsFunctionContext.getObjectsLists(\"object\").items;\r", - "const n = eventsFunctionContext.getObjectsLists(\"n\");\r", + "const n = eventsFunctionContext.getArgument(\"n\");\r", "\r", "for (const listName in lists) {\r", " const list = lists[listName];\r", - " if (n >= list.length) continue;\r", - " list[0] = list[n];\r", - " list.length = 1;\r", + " // TODO Objects from the list won't necessarily be the order they were created.\r", + " // For instance, a collision condition that uses a spatial structure may change the order.\r", + " if (n < list.length) {\r", + " list[0] = list[n];\r", + " list.length = 1;\r", + " }\r", + " else {\r", + " list.length = 0;\r", + " }\r", "}\r", "" ], "parameterObjects": "", "useStrict": true, - "eventsSheetExpanded": false + "eventsSheetExpanded": true }, { "type": "BuiltinCommonInstructions::Standard", From bf64af4a96371834dc4bc738f311f41489d91c71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Davy=20H=C3=A9lard?= Date: Mon, 8 Jan 2024 20:22:29 +0100 Subject: [PATCH 2/2] Promote back the extension to the reviewed list. --- extensions/{community => reviewed}/ObjectPickingTools.json | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename extensions/{community => reviewed}/ObjectPickingTools.json (100%) diff --git a/extensions/community/ObjectPickingTools.json b/extensions/reviewed/ObjectPickingTools.json similarity index 100% rename from extensions/community/ObjectPickingTools.json rename to extensions/reviewed/ObjectPickingTools.json