Skip to content

Commit

Permalink
[Object picking tools] Fix crashes of pick first, pick last and pick …
Browse files Browse the repository at this point in the history
…Nth and deprecate them (#1135)

- These conditions don't work for groups and would likely break in future releases of GDevelop.
  • Loading branch information
D8H authored Jan 8, 2024
1 parent 69e1f62 commit 89a384f
Showing 1 changed file with 72 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
"",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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": [
{
Expand All @@ -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",
""
],
Expand All @@ -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": [
{
Expand All @@ -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",
""
],
Expand Down Expand Up @@ -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": [
{
Expand All @@ -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",
""
],
Expand All @@ -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": [
{
Expand All @@ -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",
Expand Down Expand Up @@ -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": [
Expand All @@ -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",
Expand Down

0 comments on commit 89a384f

Please sign in to comment.