Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Object picking tools] Fix crashes of pick first, pick last and pick Nth and deprecate them #1135

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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