Compare commits

...

1 Commits

Author SHA1 Message Date
Clément Pasteau
04c4e22bc8 Wip clearer and more array tools 2023-02-06 18:23:10 +01:00
2 changed files with 50 additions and 3 deletions

View File

@@ -164,7 +164,7 @@ BaseObjectExtension::BaseObjectExtension() {
objectConditions["CollisionPoint"]
.SetFunctionName("isCollidingWithPoint")
.SetIncludeFile("runtimeobject.js");
objectConditions["ObjectTimer"] // deprecated
objectConditions["ObjectTimer"] // deprecated
.SetFunctionName("timerElapsedTime")
.SetIncludeFile("runtimeobject.js");
objectConditions["CompareObjectTimer"]
@@ -247,6 +247,12 @@ BaseObjectExtension::BaseObjectExtension() {
"getXFromAngleAndDistance");
objectExpressions["YFromAngleAndDistance"].SetFunctionName(
"getYFromAngleAndDistance");
objectExpressions["ArrayVariableFirst"].SetFunctionName(
"getFirstVariableValue");
objectExpressions["ArrayVariableLast"].SetFunctionName(
"getLastVariableValue");
objectExpressions["ArrayVariableAt"].SetFunctionName(
"getVariableValueAtIndex");
GetAllActions()["Create"].SetFunctionName(
"gdjs.evtTools.object.createObjectOnScene");
@@ -254,9 +260,9 @@ BaseObjectExtension::BaseObjectExtension() {
"gdjs.evtTools.object.createObjectFromGroupOnScene");
GetAllExpressions()["Count"].SetFunctionName(
"gdjs.evtTools.object.pickedObjectsCount"); // Deprecated
"gdjs.evtTools.object.pickedObjectsCount"); // Deprecated
GetAllConditions()["NbObjet"].SetFunctionName(
"gdjs.evtTools.object.pickedObjectsCount"); // Deprecated
"gdjs.evtTools.object.pickedObjectsCount"); // Deprecated
GetAllExpressions()["SceneInstancesCount"].SetFunctionName(
"gdjs.evtTools.object.getSceneInstancesCount");
@@ -335,6 +341,9 @@ BaseObjectExtension::BaseObjectExtension() {
objectActions["ObjectVariableRemoveAt"]
.SetFunctionName("variableRemoveAt")
.SetIncludeFile("runtimeobject.js");
objectConditions["ObjectVariableLength"]
.SetFunctionName("getVariableLength")
.SetIncludeFile("runtimeobject.js");
GetAllActions()["MoveObjects"].codeExtraInformation.SetCustomCodeGenerator(
[](gd::Instruction &,

View File

@@ -940,6 +940,44 @@ namespace gdjs {
array.removeAtIndex(index);
};
/**
* Shortcut to return the size of an array or structure variable.
* @returns {number}
*/
getVariableLength = function (array: gdjs.Variable): number {
return array.getChildrenCount();
};
/**
* Shortcut to get the value of an array variable at a given index.
* @returns {string | number | boolean}
*/
getVariableValueAtIndex = function (array: gdjs.Variable, index: number) {
if (index < 0 || index >= array.getChildrenCount()) {
return 0;
}
return array.getAllChildrenArray()[index].getValue();
};
/**
* Shortcut to get the first value of an array variable.
* @returns {string | number | boolean}
*/
getFirstVariableValue = function (array: gdjs.Variable) {
return array.getAllChildrenArray()[0].getValue();
};
/**
* Shortcut to get the last value of an array variable.
* @returns {string | number | boolean}
*/
getLastVariableValue = function (array: gdjs.Variable) {
const children = array.getAllChildrenArray();
return children.length === 0
? 0
: children[children.length - 1].getValue();
};
/**
* Shortcut to test if a variable exists for the object.
* @param name The variable to be tested