Skip to content

Commit 68babee

Browse files
authored
[Reviewed] [Button] Simpler FSM (#740)
* Don't show in changelog
1 parent 4c5521b commit 68babee

File tree

2 files changed

+299
-309
lines changed

2 files changed

+299
-309
lines changed

extensions/community/SpriteToggleSwitch.json

Lines changed: 150 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"name": "SpriteToggleSwitch",
99
"previewIconUrl": "https://asset-resources.gdevelop.io/public-resources/Icons/Line Hero Pack/Master/SVG/Interface Elements/8d0cd8cd0c9318f4f6efde6ee6b4c192bd19306467f80c9970387a259300f895_Interface Elements_interface_ui_toggle_switch_on_off.svg",
1010
"shortDescription": "Toggle switch that users can click or touch.",
11-
"version": "1.1.0",
11+
"version": "1.1.1",
1212
"description": "Toggle switch that users can click or touch. The switch can be customized with sprites.",
1313
"tags": [
1414
"ui",
@@ -21,29 +21,7 @@
2121
"gqDaZjCfevOOxBYkK6zlhtZnXCg1"
2222
],
2323
"dependencies": [],
24-
"eventsFunctions": [
25-
{
26-
"fullName": "Any touch pressed",
27-
"functionType": "Condition",
28-
"name": "AnyTouchPressed",
29-
"private": true,
30-
"sentence": "Any touch is pressed",
31-
"events": [
32-
{
33-
"type": "BuiltinCommonInstructions::JsCode",
34-
"inlineCode": [
35-
"eventsFunctionContext.returnValue = runtimeScene.getGame().getInputManager()._touches.firstKey() !== null;",
36-
""
37-
],
38-
"parameterObjects": "",
39-
"useStrict": true,
40-
"eventsSheetExpanded": false
41-
}
42-
],
43-
"parameters": [],
44-
"objectGroups": []
45-
}
46-
],
24+
"eventsFunctions": [],
4725
"eventsBasedBehaviors": [
4826
{
4927
"description": "The finite state machine used internally by the switch object.",
@@ -735,73 +713,64 @@
735713
},
736714
{
737715
"type": {
738-
"inverted": true,
739-
"value": "SpriteToggleSwitch::ButtonFSM::PropertyTouchIsInside"
716+
"value": "SpriteToggleSwitch::ButtonFSM::PropertyState"
740717
},
741718
"parameters": [
742719
"Object",
743-
"Behavior"
720+
"Behavior",
721+
"=",
722+
"\"Hovered\""
744723
]
745724
}
746725
],
747-
"actions": [],
748-
"events": [
726+
"actions": [
749727
{
750-
"type": "BuiltinCommonInstructions::Standard",
751-
"conditions": [
752-
{
753-
"type": {
754-
"value": "SpriteToggleSwitch::ButtonFSM::PropertyState"
755-
},
756-
"parameters": [
757-
"Object",
758-
"Behavior",
759-
"=",
760-
"\"Hovered\""
761-
]
762-
}
763-
],
764-
"actions": [
765-
{
766-
"type": {
767-
"value": "SpriteToggleSwitch::ButtonFSM::SetPropertyState"
768-
},
769-
"parameters": [
770-
"Object",
771-
"Behavior",
772-
"=",
773-
"\"Idle\""
774-
]
775-
}
728+
"type": {
729+
"value": "SpriteToggleSwitch::ButtonFSM::SetPropertyState"
730+
},
731+
"parameters": [
732+
"Object",
733+
"Behavior",
734+
"=",
735+
"\"Idle\""
736+
]
737+
}
738+
]
739+
},
740+
{
741+
"type": "BuiltinCommonInstructions::Standard",
742+
"conditions": [
743+
{
744+
"type": {
745+
"value": "SpriteToggleSwitch::ButtonFSM::PropertyMouseIsInside"
746+
},
747+
"parameters": [
748+
"Object",
749+
"Behavior"
776750
]
777751
},
778752
{
779-
"type": "BuiltinCommonInstructions::Standard",
780-
"conditions": [
781-
{
782-
"type": {
783-
"value": "SpriteToggleSwitch::ButtonFSM::PropertyState"
784-
},
785-
"parameters": [
786-
"Object",
787-
"Behavior",
788-
"=",
789-
"\"PressedInside\""
790-
]
791-
}
792-
],
793-
"actions": [
794-
{
795-
"type": {
796-
"value": "SpriteToggleSwitch::ButtonFSM::SetPropertyState"
797-
},
798-
"parameters": [
799-
"Object",
800-
"Behavior",
801-
"=",
802-
"\"PressedOutside\""
803-
]
804-
}
753+
"type": {
754+
"value": "SpriteToggleSwitch::ButtonFSM::PropertyState"
755+
},
756+
"parameters": [
757+
"Object",
758+
"Behavior",
759+
"=",
760+
"\"Idle\""
761+
]
762+
}
763+
],
764+
"actions": [
765+
{
766+
"type": {
767+
"value": "SpriteToggleSwitch::ButtonFSM::SetPropertyState"
768+
},
769+
"parameters": [
770+
"Object",
771+
"Behavior",
772+
"=",
773+
"\"Hovered\""
805774
]
806775
}
807776
]
@@ -811,99 +780,74 @@
811780
"conditions": [
812781
{
813782
"type": {
814-
"value": "BuiltinCommonInstructions::Or"
783+
"inverted": true,
784+
"value": "SpriteToggleSwitch::ButtonFSM::PropertyTouchIsInside"
815785
},
816-
"parameters": [],
817-
"subInstructions": [
818-
{
819-
"type": {
820-
"value": "SpriteToggleSwitch::ButtonFSM::PropertyMouseIsInside"
821-
},
822-
"parameters": [
823-
"Object",
824-
"Behavior"
825-
]
826-
},
827-
{
828-
"type": {
829-
"value": "SpriteToggleSwitch::ButtonFSM::PropertyTouchIsInside"
830-
},
831-
"parameters": [
832-
"Object",
833-
"Behavior"
834-
]
835-
}
786+
"parameters": [
787+
"Object",
788+
"Behavior"
789+
]
790+
},
791+
{
792+
"type": {
793+
"value": "SpriteToggleSwitch::ButtonFSM::PropertyState"
794+
},
795+
"parameters": [
796+
"Object",
797+
"Behavior",
798+
"=",
799+
"\"PressedInside\""
836800
]
837801
}
838802
],
839-
"actions": [],
840-
"events": [
803+
"actions": [
841804
{
842-
"type": "BuiltinCommonInstructions::Standard",
843-
"conditions": [
844-
{
845-
"type": {
846-
"value": "SpriteToggleSwitch::ButtonFSM::PropertyState"
847-
},
848-
"parameters": [
849-
"Object",
850-
"Behavior",
851-
"=",
852-
"\"PressedOutside\""
853-
]
854-
}
855-
],
856-
"actions": [
857-
{
858-
"type": {
859-
"value": "SpriteToggleSwitch::ButtonFSM::SetPropertyState"
860-
},
861-
"parameters": [
862-
"Object",
863-
"Behavior",
864-
"=",
865-
"\"PressedInside\""
866-
]
867-
}
805+
"type": {
806+
"value": "SpriteToggleSwitch::ButtonFSM::SetPropertyState"
807+
},
808+
"parameters": [
809+
"Object",
810+
"Behavior",
811+
"=",
812+
"\"PressedOutside\""
813+
]
814+
}
815+
]
816+
},
817+
{
818+
"type": "BuiltinCommonInstructions::Standard",
819+
"conditions": [
820+
{
821+
"type": {
822+
"value": "SpriteToggleSwitch::ButtonFSM::PropertyTouchIsInside"
823+
},
824+
"parameters": [
825+
"Object",
826+
"Behavior"
868827
]
869828
},
870829
{
871-
"type": "BuiltinCommonInstructions::Standard",
872-
"conditions": [
873-
{
874-
"type": {
875-
"inverted": true,
876-
"value": "MouseButtonPressed"
877-
},
878-
"parameters": [
879-
"",
880-
"Left"
881-
]
882-
},
883-
{
884-
"type": {
885-
"value": "SpriteToggleSwitch::ButtonFSM::PropertyState"
886-
},
887-
"parameters": [
888-
"Object",
889-
"Behavior",
890-
"=",
891-
"\"Idle\""
892-
]
893-
}
894-
],
895-
"actions": [
896-
{
897-
"type": {
898-
"value": "SpriteToggleSwitch::ButtonFSM::SetPropertyState"
899-
},
900-
"parameters": [
901-
"Object",
902-
"Behavior",
903-
"=",
904-
"\"Hovered\""
905-
]
906-
}
830+
"type": {
831+
"value": "SpriteToggleSwitch::ButtonFSM::PropertyState"
832+
},
833+
"parameters": [
834+
"Object",
835+
"Behavior",
836+
"=",
837+
"\"PressedOutside\""
838+
]
839+
}
840+
],
841+
"actions": [
842+
{
843+
"type": {
844+
"value": "SpriteToggleSwitch::ButtonFSM::SetPropertyState"
845+
},
846+
"parameters": [
847+
"Object",
848+
"Behavior",
849+
"=",
850+
"\"PressedInside\""
907851
]
908852
}
909853
]
@@ -1361,6 +1305,46 @@
13611305
}
13621306
],
13631307
"objectGroups": []
1308+
},
1309+
{
1310+
"description": "the touch id that is using the button or 0 if none.",
1311+
"fullName": "Touch id",
1312+
"functionType": "ExpressionAndCondition",
1313+
"name": "TouchId",
1314+
"sentence": "the touch id",
1315+
"events": [
1316+
{
1317+
"type": "BuiltinCommonInstructions::Standard",
1318+
"conditions": [],
1319+
"actions": [
1320+
{
1321+
"type": {
1322+
"value": "SetReturnNumber"
1323+
},
1324+
"parameters": [
1325+
"Object.Behavior::PropertyTouchId()"
1326+
]
1327+
}
1328+
]
1329+
}
1330+
],
1331+
"expressionType": {
1332+
"type": "expression"
1333+
},
1334+
"parameters": [
1335+
{
1336+
"description": "Object",
1337+
"name": "Object",
1338+
"type": "object"
1339+
},
1340+
{
1341+
"description": "Behavior",
1342+
"name": "Behavior",
1343+
"supplementaryInformation": "SpriteToggleSwitch::ButtonFSM",
1344+
"type": "behavior"
1345+
}
1346+
],
1347+
"objectGroups": []
13641348
}
13651349
],
13661350
"propertyDescriptors": [

0 commit comments

Comments
 (0)