From 0b62d100d22a8b636cdf7f1da171de78ba9de83a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Davy=20H=C3=A9lard?= Date: Wed, 21 Aug 2024 18:13:39 +0200 Subject: [PATCH] [Swipe gesture] Use extension variables --- extensions/reviewed/SwipeGesture.json | 370 +++++++++++++++----------- 1 file changed, 221 insertions(+), 149 deletions(-) diff --git a/extensions/reviewed/SwipeGesture.json b/extensions/reviewed/SwipeGesture.json index 9c74802f6..01a2f9af8 100644 --- a/extensions/reviewed/SwipeGesture.json +++ b/extensions/reviewed/SwipeGesture.json @@ -8,8 +8,29 @@ "name": "SwipeGesture", "previewIconUrl": "https://resources.gdevelop-app.com/assets/Icons/gesture-swipe-right.svg", "shortDescription": "Detect swipe gestures based on their distance and duration.", - "version": "1.0.0", - "description": "Use the \"Enable swipe detection\" action at the beginning of your scene.\n\nNote: This extension does NOT support multitouch.\n\nExpressions:\n\n- `StartX`, `StartY`: Position where the swipe started\n- `EndX`, `EndY`: Position where the swipe ended\n- `Distance`: Length of the swipe, in pixels\n- `DistanceX`, `DistanceY`: Distance the swipe moved in each axis\n- `Angle`: Direction the swipe moved towards. Range (-180, 180)\n- `Layer`: Layer used to detect swipe gestures\n\nConditions:\n\n- `Is swipe detection enabled`\n- `Is swipe in progress?` - A swipe starts when the mouse click or touch begins\n- `Has swipe just ended?` - When the mouse or touch is released, this condition is true for one frame \n- `Swipe moved in a direction (4-way movement)` - the direction value for 4 sides (UP, DOWN, LEFT, RIGHT). In this case, the “circle” is divided into 4 segments of 90 degrees\n- `Swipe moved in a direction (8-way movement)` - the direction value for 8 sides (UP, DOWN, LEFT, RIGHT, UP-LEFT, UP-RIGHT, DOWN-LEFT, DOWN-RIGHT). In this case, the “circle” is divided into 8 segments of 45 degrees.", + "version": "1.0.1", + "description": [ + "Use the \"Enable swipe detection\" action at the beginning of your scene.", + "", + "Note: This extension does NOT support multitouch.", + "", + "Expressions:", + "", + "- `StartX`, `StartY`: Position where the swipe started", + "- `EndX`, `EndY`: Position where the swipe ended", + "- `Distance`: Length of the swipe, in pixels", + "- `DistanceX`, `DistanceY`: Distance the swipe moved in each axis", + "- `Angle`: Direction the swipe moved towards. Range (-180, 180)", + "- `Layer`: Layer used to detect swipe gestures", + "", + "Conditions:", + "", + "- `Is swipe detection enabled`", + "- `Is swipe in progress?` - A swipe starts when the mouse click or touch begins", + "- `Has swipe just ended?` - When the mouse or touch is released, this condition is true for one frame ", + "- `Swipe moved in a direction (4-way movement)` - the direction value for 4 sides (UP, DOWN, LEFT, RIGHT). In this case, the “circle” is divided into 4 segments of 90 degrees", + "- `Swipe moved in a direction (8-way movement)` - the direction value for 8 sides (UP, DOWN, LEFT, RIGHT, UP-LEFT, UP-RIGHT, DOWN-LEFT, DOWN-RIGHT). In this case, the “circle” is divided into 8 segments of 45 degrees." + ], "origin": { "identifier": "SwipeGesture", "name": "gdevelop-extension-store" @@ -26,6 +47,81 @@ "gqDaZjCfevOOxBYkK6zlhtZnXCg1" ], "dependencies": [], + "globalVariables": [], + "sceneVariables": [ + { + "folded": true, + "name": "SwipeJustEnded", + "type": "boolean", + "value": false + }, + { + "folded": true, + "name": "EndPointX", + "type": "number", + "value": 0 + }, + { + "folded": true, + "name": "EndPointY", + "type": "number", + "value": 0 + }, + { + "folded": true, + "name": "SwipeInProgress", + "type": "boolean", + "value": false + }, + { + "folded": true, + "name": "StartPointX", + "type": "number", + "value": 0 + }, + { + "folded": true, + "name": "StartPointY", + "type": "number", + "value": 0 + }, + { + "folded": true, + "name": "Distance", + "type": "number", + "value": 0 + }, + { + "folded": true, + "name": "DistanceX", + "type": "number", + "value": 0 + }, + { + "folded": true, + "name": "DistanceY", + "type": "number", + "value": 0 + }, + { + "folded": true, + "name": "Angle", + "type": "number", + "value": 0 + }, + { + "folded": true, + "name": "Enabled", + "type": "boolean", + "value": false + }, + { + "folded": true, + "name": "Layer", + "type": "string", + "value": "" + } + ], "eventsFunctions": [ { "fullName": "", @@ -43,8 +139,7 @@ "textG": 0, "textR": 0 }, - "comment": "Reset \"swipe just ended\" detection", - "comment2": "" + "comment": "Reset \"swipe just ended\" detection" }, { "type": "BuiltinCommonInstructions::Standard", @@ -52,11 +147,12 @@ "actions": [ { "type": { - "value": "SetSceneVariableAsBoolean" + "value": "SetBooleanVariable" }, "parameters": [ - "__SwipeGesture.SwipeJustEnded", - "False" + "SwipeJustEnded", + "False", + "" ] } ] @@ -109,22 +205,22 @@ "actions": [ { "type": { - "value": "ModVarScene" + "value": "SetNumberVariable" }, "parameters": [ - "__SwipeGesture.EndPointX", + "EndPointX", "=", - "MouseX(VariableString(__SwipeGesture.Layer),0)" + "MouseX(Layer)" ] }, { "type": { - "value": "ModVarScene" + "value": "SetNumberVariable" }, "parameters": [ - "__SwipeGesture.EndPointY", + "EndPointY", "=", - "MouseY(VariableString(__SwipeGesture.Layer),0)" + "MouseY(Layer)" ] } ] @@ -156,19 +252,20 @@ }, { "type": { - "value": "SetSceneVariableAsBoolean" + "value": "SetBooleanVariable" }, "parameters": [ - "__SwipeGesture.SwipeInProgress", - "False" + "SwipeInProgress", + "False", + "" ] }, { "type": { - "value": "SetSceneVariableAsBoolean" + "value": "SetBooleanVariable" }, "parameters": [ - "__SwipeGesture.SwipeJustEnded", + "SwipeJustEnded", "True" ] } @@ -236,20 +333,20 @@ "actions": [ { "type": { - "value": "ModVarScene" + "value": "SetNumberVariable" }, "parameters": [ - "__SwipeGesture.EndPointX", + "EndPointX", "=", "0" ] }, { "type": { - "value": "ModVarScene" + "value": "SetNumberVariable" }, "parameters": [ - "__SwipeGesture.EndPointY", + "EndPointY", "=", "0" ] @@ -274,22 +371,22 @@ "actions": [ { "type": { - "value": "ModVarScene" + "value": "SetNumberVariable" }, "parameters": [ - "__SwipeGesture.StartPointX", + "StartPointX", "=", - "MouseX(VariableString(__SwipeGesture.Layer),0)" + "MouseX(Layer)" ] }, { "type": { - "value": "ModVarScene" + "value": "SetNumberVariable" }, "parameters": [ - "__SwipeGesture.StartPointY", + "StartPointY", "=", - "MouseY(VariableString(__SwipeGesture.Layer),0)" + "MouseY(Layer)" ] } ] @@ -330,10 +427,10 @@ }, { "type": { - "value": "SetSceneVariableAsBoolean" + "value": "SetBooleanVariable" }, "parameters": [ - "__SwipeGesture.SwipeInProgress", + "SwipeInProgress", "True" ] } @@ -386,44 +483,32 @@ "actions": [ { "type": { - "value": "ModVarScene" + "value": "SetNumberVariable" }, "parameters": [ - "__SwipeGesture.Distance", + "Distance", "=", - "DistanceBetweenPositions(Variable(__SwipeGesture.StartPointX), Variable(__SwipeGesture.StartPointY), MouseX(VariableString(__SwipeGesture.Layer),0), MouseY(VariableString(__SwipeGesture.Layer),0))" + "DistanceBetweenPositions(StartPointX, StartPointY, MouseX(Layer), MouseY(Layer))" ] - } - ] - }, - { - "type": "BuiltinCommonInstructions::Standard", - "conditions": [], - "actions": [ + }, { "type": { - "value": "ModVarScene" + "value": "SetNumberVariable" }, "parameters": [ - "__SwipeGesture.DistanceX", + "DistanceX", "=", - "abs(Variable(__SwipeGesture.StartPointX) - MouseX(VariableString(__SwipeGesture.Layer),0))" + "abs(StartPointX - MouseX(Layer))" ] - } - ] - }, - { - "type": "BuiltinCommonInstructions::Standard", - "conditions": [], - "actions": [ + }, { "type": { - "value": "ModVarScene" + "value": "SetNumberVariable" }, "parameters": [ - "__SwipeGesture.DistanceY", + "DistanceY", "=", - "abs(Variable(__SwipeGesture.StartPointY) - MouseY(VariableString(__SwipeGesture.Layer),0))" + "abs(StartPointY - MouseY(Layer))" ] } ] @@ -446,12 +531,12 @@ "actions": [ { "type": { - "value": "ModVarScene" + "value": "SetNumberVariable" }, "parameters": [ - "__SwipeGesture.Angle", + "Angle", "=", - "AngleBetweenPositions(Variable(__SwipeGesture.StartPointX), Variable(__SwipeGesture.StartPointY), MouseX(VariableString(__SwipeGesture.Layer),0), MouseY(VariableString(__SwipeGesture.Layer),0))" + "AngleBetweenPositions(StartPointX, StartPointY, MouseX(Layer), MouseY(Layer))" ] } ] @@ -491,19 +576,20 @@ "actions": [ { "type": { - "value": "SetSceneVariableAsBoolean" + "value": "SetBooleanVariable" }, "parameters": [ - "__SwipeGesture.Enabled", - "False" + "Enabled", + "False", + "" ] }, { "type": { - "value": "SetSceneVariableAsBoolean" + "value": "SetBooleanVariable" }, "parameters": [ - "__SwipeGesture.SwipeInProgress", + "SwipeInProgress", "False" ] }, @@ -533,10 +619,10 @@ "actions": [ { "type": { - "value": "SetSceneVariableAsBoolean" + "value": "SetBooleanVariable" }, "parameters": [ - "__SwipeGesture.Enabled", + "Enabled", "True" ] } @@ -578,8 +664,7 @@ "textG": 0, "textR": 0 }, - "comment": "Create a shape painter if one does not already exist", - "comment2": "" + "comment": "Create a shape painter if one does not already exist" }, { "type": "BuiltinCommonInstructions::Standard", @@ -606,7 +691,7 @@ "ShapePainterObject", "0", "0", - "VariableString(__SwipeGesture.Layer)" + "Layer" ] } ] @@ -623,13 +708,7 @@ "ShapePainterObject", "" ] - } - ] - }, - { - "type": "BuiltinCommonInstructions::Standard", - "conditions": [], - "actions": [ + }, { "type": { "value": "PrimitiveDrawing::UseRelativeCoordinates" @@ -666,25 +745,18 @@ ] } ], - "actions": [], - "events": [ + "actions": [ { - "type": "BuiltinCommonInstructions::Standard", - "conditions": [], - "actions": [ - { - "type": { - "value": "PrimitiveDrawing::LineV2" - }, - "parameters": [ - "ShapePainterObject", - "Variable(__SwipeGesture.StartPointX)", - "Variable(__SwipeGesture.StartPointY)", - "MouseX(VariableString(__SwipeGesture.Layer),0)", - "MouseY(VariableString(__SwipeGesture.Layer),0)", - "ShapePainterObject.OutlineSize()" - ] - } + "type": { + "value": "PrimitiveDrawing::LineV2" + }, + "parameters": [ + "ShapePainterObject", + "StartPointX", + "StartPointY", + "MouseX(Layer)", + "MouseY(Layer)", + "ShapePainterObject.OutlineSize()" ] } ] @@ -717,12 +789,12 @@ "actions": [ { "type": { - "value": "ModVarSceneTxt" + "value": "SetStringVariable" }, "parameters": [ - "__SwipeGesture.Layer", + "Layer", "=", - "GetArgumentAsString(\"Value\")" + "Value" ] } ] @@ -753,7 +825,7 @@ "value": "SetReturnString" }, "parameters": [ - "VariableString(__SwipeGesture.Layer)" + "Layer" ] } ] @@ -781,7 +853,7 @@ "value": "SetReturnNumber" }, "parameters": [ - "Variable(__SwipeGesture.Angle)" + "Angle" ] } ] @@ -809,7 +881,7 @@ "value": "SetReturnNumber" }, "parameters": [ - "Variable(__SwipeGesture.Distance)" + "Distance" ] } ] @@ -837,7 +909,7 @@ "value": "SetReturnNumber" }, "parameters": [ - "Variable(__SwipeGesture.DistanceX)" + "DistanceX" ] } ] @@ -865,7 +937,7 @@ "value": "SetReturnNumber" }, "parameters": [ - "Variable(__SwipeGesture.DistanceY)" + "DistanceY" ] } ] @@ -893,7 +965,7 @@ "value": "SetReturnNumber" }, "parameters": [ - "Variable(__SwipeGesture.StartPointX)" + "StartPointX" ] } ] @@ -921,7 +993,7 @@ "value": "SetReturnNumber" }, "parameters": [ - "Variable(__SwipeGesture.StartPointY)" + "StartPointY" ] } ] @@ -949,7 +1021,7 @@ "value": "SetReturnNumber" }, "parameters": [ - "Variable(__SwipeGesture.EndPointX)" + "EndPointX" ] } ] @@ -977,7 +1049,7 @@ "value": "SetReturnNumber" }, "parameters": [ - "Variable(__SwipeGesture.EndPointY)" + "EndPointY" ] } ] @@ -1029,10 +1101,10 @@ "conditions": [ { "type": { - "value": "SceneVariableAsBoolean" + "value": "BooleanVariable" }, "parameters": [ - "__SwipeGesture.SwipeInProgress", + "SwipeInProgress", "True" ] } @@ -1064,10 +1136,10 @@ "conditions": [ { "type": { - "value": "SceneVariableAsBoolean" + "value": "BooleanVariable" }, "parameters": [ - "__SwipeGesture.Enabled", + "Enabled", "True" ] } @@ -1099,10 +1171,10 @@ "conditions": [ { "type": { - "value": "SceneVariableAsBoolean" + "value": "BooleanVariable" }, "parameters": [ - "__SwipeGesture.SwipeJustEnded", + "SwipeJustEnded", "True" ] } @@ -1172,7 +1244,7 @@ "value": "BuiltinCommonInstructions::CompareStrings" }, "parameters": [ - "GetArgumentAsString(\"Direction\")", + "Direction", "=", "\"Up\"" ] @@ -1188,7 +1260,7 @@ "value": "BuiltinCommonInstructions::CompareNumbers" }, "parameters": [ - "SwipeGesture::Angle()", + "Angle", ">=", "-135" ] @@ -1198,7 +1270,7 @@ "value": "BuiltinCommonInstructions::CompareNumbers" }, "parameters": [ - "SwipeGesture::Angle()", + "Angle", "<", "-45" ] @@ -1237,7 +1309,7 @@ "value": "BuiltinCommonInstructions::CompareStrings" }, "parameters": [ - "GetArgumentAsString(\"Direction\")", + "Direction", "=", "\"Down\"" ] @@ -1253,7 +1325,7 @@ "value": "BuiltinCommonInstructions::CompareNumbers" }, "parameters": [ - "SwipeGesture::Angle()", + "Angle", ">=", "45" ] @@ -1263,7 +1335,7 @@ "value": "BuiltinCommonInstructions::CompareNumbers" }, "parameters": [ - "SwipeGesture::Angle()", + "Angle", "<", "135" ] @@ -1302,7 +1374,7 @@ "value": "BuiltinCommonInstructions::CompareStrings" }, "parameters": [ - "GetArgumentAsString(\"Direction\")", + "Direction", "=", "\"Left\"" ] @@ -1330,7 +1402,7 @@ "value": "BuiltinCommonInstructions::CompareNumbers" }, "parameters": [ - "SwipeGesture::Angle()", + "Angle", ">=", "-180" ] @@ -1340,7 +1412,7 @@ "value": "BuiltinCommonInstructions::CompareNumbers" }, "parameters": [ - "SwipeGesture::Angle()", + "Angle", "<", "-135" ] @@ -1358,7 +1430,7 @@ "value": "BuiltinCommonInstructions::CompareNumbers" }, "parameters": [ - "SwipeGesture::Angle()", + "Angle", ">=", "135" ] @@ -1368,7 +1440,7 @@ "value": "BuiltinCommonInstructions::CompareNumbers" }, "parameters": [ - "SwipeGesture::Angle()", + "Angle", "<", "180" ] @@ -1411,7 +1483,7 @@ "value": "BuiltinCommonInstructions::CompareStrings" }, "parameters": [ - "GetArgumentAsString(\"Direction\")", + "Direction", "=", "\"Right\"" ] @@ -1427,7 +1499,7 @@ "value": "BuiltinCommonInstructions::CompareNumbers" }, "parameters": [ - "SwipeGesture::Angle()", + "Angle", ">=", "-45" ] @@ -1437,7 +1509,7 @@ "value": "BuiltinCommonInstructions::CompareNumbers" }, "parameters": [ - "SwipeGesture::Angle()", + "Angle", "<", "45" ] @@ -1525,7 +1597,7 @@ "value": "BuiltinCommonInstructions::CompareStrings" }, "parameters": [ - "GetArgumentAsString(\"Direction\")", + "Direction", "=", "\"Up\"" ] @@ -1541,7 +1613,7 @@ "value": "BuiltinCommonInstructions::CompareNumbers" }, "parameters": [ - "SwipeGesture::Angle()", + "Angle", ">=", "-112.5" ] @@ -1551,7 +1623,7 @@ "value": "BuiltinCommonInstructions::CompareNumbers" }, "parameters": [ - "SwipeGesture::Angle()", + "Angle", "<", "-67.5" ] @@ -1590,7 +1662,7 @@ "value": "BuiltinCommonInstructions::CompareStrings" }, "parameters": [ - "GetArgumentAsString(\"Direction\")", + "Direction", "=", "\"Down\"" ] @@ -1606,7 +1678,7 @@ "value": "BuiltinCommonInstructions::CompareNumbers" }, "parameters": [ - "SwipeGesture::Angle()", + "Angle", ">=", "67.5" ] @@ -1616,7 +1688,7 @@ "value": "BuiltinCommonInstructions::CompareNumbers" }, "parameters": [ - "SwipeGesture::Angle()", + "Angle", "<", "112.5" ] @@ -1655,7 +1727,7 @@ "value": "BuiltinCommonInstructions::CompareStrings" }, "parameters": [ - "GetArgumentAsString(\"Direction\")", + "Direction", "=", "\"Left\"" ] @@ -1683,7 +1755,7 @@ "value": "BuiltinCommonInstructions::CompareNumbers" }, "parameters": [ - "SwipeGesture::Angle()", + "Angle", ">=", "-180" ] @@ -1693,7 +1765,7 @@ "value": "BuiltinCommonInstructions::CompareNumbers" }, "parameters": [ - "SwipeGesture::Angle()", + "Angle", "<", "-157.5" ] @@ -1711,7 +1783,7 @@ "value": "BuiltinCommonInstructions::CompareNumbers" }, "parameters": [ - "SwipeGesture::Angle()", + "Angle", ">=", "157.5" ] @@ -1721,7 +1793,7 @@ "value": "BuiltinCommonInstructions::CompareNumbers" }, "parameters": [ - "SwipeGesture::Angle()", + "Angle", "<", "180" ] @@ -1764,7 +1836,7 @@ "value": "BuiltinCommonInstructions::CompareStrings" }, "parameters": [ - "GetArgumentAsString(\"Direction\")", + "Direction", "=", "\"Right\"" ] @@ -1780,7 +1852,7 @@ "value": "BuiltinCommonInstructions::CompareNumbers" }, "parameters": [ - "SwipeGesture::Angle()", + "Angle", ">=", "-22.5" ] @@ -1790,7 +1862,7 @@ "value": "BuiltinCommonInstructions::CompareNumbers" }, "parameters": [ - "SwipeGesture::Angle()", + "Angle", "<", "22.5" ] @@ -1829,7 +1901,7 @@ "value": "BuiltinCommonInstructions::CompareStrings" }, "parameters": [ - "GetArgumentAsString(\"Direction\")", + "Direction", "=", "\"UpRight\"" ] @@ -1845,7 +1917,7 @@ "value": "BuiltinCommonInstructions::CompareNumbers" }, "parameters": [ - "SwipeGesture::Angle()", + "Angle", ">=", "-67.5" ] @@ -1855,7 +1927,7 @@ "value": "BuiltinCommonInstructions::CompareNumbers" }, "parameters": [ - "SwipeGesture::Angle()", + "Angle", "<", "-22.5" ] @@ -1894,7 +1966,7 @@ "value": "BuiltinCommonInstructions::CompareStrings" }, "parameters": [ - "GetArgumentAsString(\"Direction\")", + "Direction", "=", "\"UpLeft\"" ] @@ -1910,7 +1982,7 @@ "value": "BuiltinCommonInstructions::CompareNumbers" }, "parameters": [ - "SwipeGesture::Angle()", + "Angle", ">=", "-157.5" ] @@ -1920,7 +1992,7 @@ "value": "BuiltinCommonInstructions::CompareNumbers" }, "parameters": [ - "SwipeGesture::Angle()", + "Angle", "<", "-112.5" ] @@ -1959,7 +2031,7 @@ "value": "BuiltinCommonInstructions::CompareStrings" }, "parameters": [ - "GetArgumentAsString(\"Direction\")", + "Direction", "=", "\"DownLeft\"" ] @@ -1975,7 +2047,7 @@ "value": "BuiltinCommonInstructions::CompareNumbers" }, "parameters": [ - "SwipeGesture::Angle()", + "Angle", ">=", "112.5" ] @@ -1985,7 +2057,7 @@ "value": "BuiltinCommonInstructions::CompareNumbers" }, "parameters": [ - "SwipeGesture::Angle()", + "Angle", "<", "157.5" ] @@ -2024,7 +2096,7 @@ "value": "BuiltinCommonInstructions::CompareStrings" }, "parameters": [ - "GetArgumentAsString(\"Direction\")", + "Direction", "=", "\"DownRight\"" ] @@ -2040,7 +2112,7 @@ "value": "BuiltinCommonInstructions::CompareNumbers" }, "parameters": [ - "SwipeGesture::Angle()", + "Angle", ">=", "22.5" ] @@ -2050,7 +2122,7 @@ "value": "BuiltinCommonInstructions::CompareNumbers" }, "parameters": [ - "SwipeGesture::Angle()", + "Angle", "<", "67.5" ]