Skip to content

Commit 29cf8d3

Browse files
authored
[Reviewed] [Object stack] Add quality of life features (#937)
* Add an action to check an object at an exact height * Add an action to insert the content of a stack into another stack * Add an operator to the stack height condition
1 parent af8a84f commit 29cf8d3

File tree

1 file changed

+199
-13
lines changed

1 file changed

+199
-13
lines changed

extensions/reviewed/ObjectStack.json

Lines changed: 199 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"name": "ObjectStack",
99
"previewIconUrl": "https://resources.gdevelop-app.com/assets/Icons/Line Hero Pack/Master/SVG/Videogames/Videogames_cards_game_solitaire_poker_blackjack_casino.svg",
1010
"shortDescription": "An ordered list of objects and a shuffle action.",
11-
"version": "0.0.8",
11+
"version": "0.1.0",
1212
"description": [
1313
"It provides:",
1414
"* Actions to modify a stack of objects",
@@ -19,9 +19,10 @@
1919
"* Card games",
2020
"* Fair randomness (for instance, to create a stack of predetermined bonus and randomize the order they appear)",
2121
"",
22-
"2 examples use it:",
23-
"* A card system demonstration ([open the project online](https://editor.gdevelop.io/?project=example://card-system))",
24-
"* A Klondike solitaire ([open the project online](https://editor.gdevelop.io/?project=example://klondike-solitaire))"
22+
"3 examples use it:",
23+
"* a card system demonstration ([open the project online](https://editor.gdevelop.io/?project=example://card-system))",
24+
"* a Klondike solitaire ([open the project online](https://editor.gdevelop.io/?project=example://klondike-solitaire))",
25+
"* a Zuma-like ([open the project online](https://editor.gdevelop.io/?project=example://smoothy))"
2526
],
2627
"origin": {
2728
"identifier": "ObjectStack",
@@ -40,7 +41,7 @@
4041
"dependencies": [],
4142
"eventsFunctions": [
4243
{
43-
"description": "Check if the stack contains the object between a range.",
44+
"description": "Check if the stack contains the object between a range. The lower and upper bounds are included.",
4445
"fullName": "Contain between a range",
4546
"functionType": "Condition",
4647
"name": "ContainsBetween",
@@ -110,6 +111,74 @@
110111
],
111112
"objectGroups": []
112113
},
114+
{
115+
"description": "Check if the stack contains the object at a height.",
116+
"fullName": "Contain at",
117+
"functionType": "Condition",
118+
"name": "ContainsAt",
119+
"sentence": "_PARAM3_ is into the stack of _PARAM1_ at _PARAM4_ ",
120+
"events": [
121+
{
122+
"type": "BuiltinCommonInstructions::JsCode",
123+
"inlineCode": [
124+
"const stackBehaviorName = eventsFunctionContext.getBehaviorName(\"Behavior\");",
125+
"/** @type {Hashtable<gdjs.RuntimeObject[]>} */",
126+
"const stackObjectsLists = eventsFunctionContext.getObjectsLists(\"Object\");",
127+
"/** @type {Hashtable<gdjs.RuntimeObject[]>} */",
128+
"const elementObjectsLists = eventsFunctionContext.getObjectsLists(\"Element\");",
129+
"",
130+
"// This code is duplicated from ContainsBetween because the picking wouldn't pass from one function to the other.",
131+
"const lowerBound = Math.max(0, eventsFunctionContext.getArgument(\"Height\"));",
132+
"let upperBound = eventsFunctionContext.getArgument(\"Height\");",
133+
"",
134+
"eventsFunctionContext.returnValue = gdjs.evtTools.object.twoListsTest(",
135+
" (stackObject, element, stackBehaviorName) => {",
136+
" const behavior = stackObject.getBehavior(stackBehaviorName);",
137+
" /** @type {gdjs.RuntimeObject[]} */",
138+
" const stack = behavior.objectStack;",
139+
" let found = false;",
140+
" upperBound = Math.min(upperBound, stack.length - 1);",
141+
" for (let i = lowerBound; i <= upperBound && !found; i++) {",
142+
" found = stack[i] === element;",
143+
" }",
144+
" return found;",
145+
" },",
146+
" stackObjectsLists,",
147+
" elementObjectsLists,",
148+
" false,",
149+
" stackBehaviorName",
150+
");"
151+
],
152+
"parameterObjects": "Object",
153+
"useStrict": true,
154+
"eventsSheetExpanded": true
155+
}
156+
],
157+
"parameters": [
158+
{
159+
"description": "Stack",
160+
"name": "Object",
161+
"type": "objectList"
162+
},
163+
{
164+
"description": "Stack behavior",
165+
"name": "Behavior",
166+
"supplementaryInformation": "ObjectStack::ObjectStack",
167+
"type": "behavior"
168+
},
169+
{
170+
"description": "Element",
171+
"name": "Element",
172+
"type": "objectList"
173+
},
174+
{
175+
"description": "Height",
176+
"name": "Height",
177+
"type": "expression"
178+
}
179+
],
180+
"objectGroups": []
181+
},
113182
{
114183
"description": "Check if an object is on the stack top.",
115184
"fullName": "Stack top",
@@ -399,7 +468,7 @@
399468
"/** @type {Map<gdjs.RuntimeObject> */",
400469
"const objectSet = behavior.objectSet;",
401470
"if (height < 0 || height > stack.length) {",
402-
" log.error(`Tried to insert in the stack at ${height} where the stack is ${stack.length} height.`);",
471+
" console.error(`Tried to insert in the stack at ${height} where the stack is ${stack.length} height.`);",
403472
" return;",
404473
"}",
405474
"for (const element of elements) {",
@@ -548,7 +617,7 @@
548617
"fullName": "Move into the stack",
549618
"functionType": "Action",
550619
"name": "MoveInto",
551-
"sentence": "Move the object of the stack of _PARAM3_ from:_PARAM5_ to:_PARAM6_ into the stack of _PARAM0_ at height: _PARAM2_",
620+
"sentence": "Move the objects of the stack of _PARAM3_ from:_PARAM5_ to:_PARAM6_ into the stack of _PARAM0_ at height: _PARAM2_",
552621
"events": [
553622
{
554623
"type": "BuiltinCommonInstructions::JsCode",
@@ -572,7 +641,7 @@
572641
" /** @type {Map<gdjs.RuntimeObject> */",
573642
" const objectSet = behavior.objectSet;",
574643
" if (insertHeight < 0 || insertHeight > stack.length) {",
575-
" log.error(`Tried to insert in the stack at ${insertHeight} where the stack is ${stack.length} height.`);",
644+
" console.error(`Tried to insert in the stack at ${insertHeight} where the stack is ${stack.length} height.`);",
576645
" return;",
577646
" }",
578647
" upperBound = Math.min(upperBound, otherStack.length - 1);",
@@ -636,6 +705,121 @@
636705
],
637706
"objectGroups": []
638707
},
708+
{
709+
"description": "Move all the object from a stack into another.",
710+
"fullName": "Move all into the stack",
711+
"functionType": "Action",
712+
"name": "MoveAllInto",
713+
"sentence": "Move all the objects of the stack of _PARAM3_ into the stack of _PARAM0_ at height: _PARAM2_",
714+
"events": [
715+
{
716+
"type": "BuiltinCommonInstructions::Standard",
717+
"conditions": [],
718+
"actions": [
719+
{
720+
"type": {
721+
"value": "ObjectStack::ObjectStack::MoveInto"
722+
},
723+
"parameters": [
724+
"Object",
725+
"Behavior",
726+
"GetArgumentAsNumber(\"Height\")",
727+
"Stack",
728+
"StackBehavior",
729+
"0",
730+
"Stack.StackBehavior::Height() - 1",
731+
""
732+
]
733+
}
734+
]
735+
}
736+
],
737+
"parameters": [
738+
{
739+
"description": "Object",
740+
"name": "Object",
741+
"type": "object"
742+
},
743+
{
744+
"description": "Behavior",
745+
"name": "Behavior",
746+
"supplementaryInformation": "ObjectStack::ObjectStack",
747+
"type": "behavior"
748+
},
749+
{
750+
"description": "Height",
751+
"name": "Height",
752+
"type": "expression"
753+
},
754+
{
755+
"description": "Stack",
756+
"name": "Stack",
757+
"type": "objectList"
758+
},
759+
{
760+
"description": "Stack behavior",
761+
"name": "StackBehavior",
762+
"supplementaryInformation": "ObjectStack::ObjectStack",
763+
"type": "behavior"
764+
}
765+
],
766+
"objectGroups": []
767+
},
768+
{
769+
"description": "Move all the object from a stack into another one at the top.",
770+
"fullName": "Move all on top of the stack",
771+
"functionType": "Action",
772+
"name": "MoveAllOnTop",
773+
"sentence": "Move all the objects of the stack of _PARAM2_ on the top of the stack of _PARAM0_",
774+
"events": [
775+
{
776+
"type": "BuiltinCommonInstructions::Standard",
777+
"conditions": [],
778+
"actions": [
779+
{
780+
"type": {
781+
"value": "ObjectStack::ObjectStack::MoveInto"
782+
},
783+
"parameters": [
784+
"Object",
785+
"Behavior",
786+
"Object.Behavior::Height()",
787+
"Stack",
788+
"StackBehavior",
789+
"0",
790+
"Stack.StackBehavior::Height() - 1",
791+
""
792+
]
793+
}
794+
]
795+
}
796+
],
797+
"parameters": [
798+
{
799+
"description": "Object",
800+
"name": "Object",
801+
"type": "object"
802+
},
803+
{
804+
"description": "Behavior",
805+
"name": "Behavior",
806+
"supplementaryInformation": "ObjectStack::ObjectStack",
807+
"type": "behavior"
808+
},
809+
{
810+
"description": "Stack",
811+
"name": "Stack",
812+
"type": "objectList"
813+
},
814+
{
815+
"description": "Stack behavior",
816+
"name": "StackBehavior",
817+
"supplementaryInformation": "ObjectStack::ObjectStack",
818+
"type": "behavior"
819+
}
820+
],
821+
"objectGroups": []
822+
},
639823
{
640824
"description": "Shuffle the stack.",
641825
"fullName": "Shuffle",
@@ -729,11 +913,11 @@
729913
"objectGroups": []
730914
},
731915
{
732-
"description": "The number of objects in the stack.",
916+
"description": "the number of objects in the stack.",
733917
"fullName": "Stack height",
734-
"functionType": "Expression",
918+
"functionType": "ExpressionAndCondition",
735919
"name": "Height",
736-
"sentence": "",
920+
"sentence": "the number of objects in the stack",
737921
"events": [
738922
{
739923
"type": "BuiltinCommonInstructions::JsCode",
@@ -743,7 +927,8 @@
743927
"",
744928
"/** @type {gdjs.RuntimeObject[]} */",
745929
"const stack = behavior.objectStack;",
746-
"eventsFunctionContext.returnValue = stack.length;"
930+
"eventsFunctionContext.returnValue = stack.length;",
931+
""
747932
],
748933
"parameterObjects": "Object",
749934
"useStrict": true,
@@ -770,9 +955,10 @@
770955
},
771956
{
772957
"description": "Compare the number of objects in the stack.",
773-
"fullName": "Stack height",
958+
"fullName": "Stack height (deprecated)",
774959
"functionType": "Condition",
775960
"name": "CheckHeight",
961+
"private": true,
776962
"sentence": "_PARAM0_ has _PARAM2_ objects in its stack",
777963
"events": [
778964
{

0 commit comments

Comments
 (0)