Skip to content

Commit

Permalink
Fix GDevelop.js tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
D8H committed Nov 3, 2024
1 parent 48a3ac4 commit f676bd5
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions GDJS/GDJS/Extensions/Builtin/VariablesExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ VariablesExtension::VariablesExtension() {
GetAllConditions()["NumberVariable"].SetCustomCodeGenerator(
[](gd::Instruction &instruction, gd::EventsCodeGenerator &codeGenerator,
gd::EventsCodeGenerationContext &context) {
const auto &variableName = instruction.GetParameters()[0].GetPlainString();
gd::String getterCode =
gd::ExpressionCodeGenerator::GenerateExpressionCode(
codeGenerator, context, "variable",
instruction.GetParameters()[0].GetPlainString());
variableName);
gd::String op = instruction.GetParameters()[1].GetPlainString();
gd::String expressionCode =
gd::ExpressionCodeGenerator::GenerateExpressionCode(
Expand All @@ -40,6 +41,17 @@ VariablesExtension::VariablesExtension() {
codeGenerator.GenerateUpperScopeBooleanFullName("isConditionTrue",
context);

const auto variablesContainersList =
codeGenerator.GetProjectScopedContainers().GetVariablesContainersList();
const auto& variablesContainer =
variablesContainersList.GetVariablesContainerFromVariableName(
variableName);
const auto sourceType = variablesContainer.GetSourceType();
if (sourceType != gd::VariablesContainer::SourceType::Properties &&
sourceType != gd::VariablesContainer::SourceType::Parameters) {
getterCode += ".getAsNumber()";
}

return resultingBoolean + " = " +
gd::String(instruction.IsInverted() ? "!" : "") + "(" +
codeGenerator.GenerateRelationalOperation(op, getterCode,
Expand All @@ -49,6 +61,7 @@ VariablesExtension::VariablesExtension() {
GetAllConditions()["StringVariable"].SetCustomCodeGenerator(
[](gd::Instruction &instruction, gd::EventsCodeGenerator &codeGenerator,
gd::EventsCodeGenerationContext &context) {
const auto &variableName = instruction.GetParameters()[0].GetPlainString();
gd::String getterCode =
gd::ExpressionCodeGenerator::GenerateExpressionCode(
codeGenerator, context, "variable",
Expand All @@ -59,6 +72,17 @@ VariablesExtension::VariablesExtension() {
codeGenerator, context, "string",
instruction.GetParameters()[2].GetPlainString());

const auto variablesContainersList =
codeGenerator.GetProjectScopedContainers().GetVariablesContainersList();
const auto& variablesContainer =
variablesContainersList.GetVariablesContainerFromVariableName(
variableName);
const auto sourceType = variablesContainer.GetSourceType();
if (sourceType != gd::VariablesContainer::SourceType::Properties &&
sourceType != gd::VariablesContainer::SourceType::Parameters) {
getterCode += ".getAsString()";
}

gd::String resultingBoolean =
codeGenerator.GenerateUpperScopeBooleanFullName("isConditionTrue",
context);
Expand All @@ -72,12 +96,24 @@ VariablesExtension::VariablesExtension() {
GetAllConditions()["BooleanVariable"].SetCustomCodeGenerator(
[](gd::Instruction &instruction, gd::EventsCodeGenerator &codeGenerator,
gd::EventsCodeGenerationContext &context) {
const auto &variableName = instruction.GetParameters()[0].GetPlainString();
gd::String getterCode =
gd::ExpressionCodeGenerator::GenerateExpressionCode(
codeGenerator, context, "variable",
instruction.GetParameters()[0].GetPlainString());
bool isOperandTrue =
instruction.GetParameters()[1].GetPlainString() == "True";
instruction.GetParameters()[1].GetPlainString() != "False";

const auto variablesContainersList =
codeGenerator.GetProjectScopedContainers().GetVariablesContainersList();
const auto& variablesContainer =
variablesContainersList.GetVariablesContainerFromVariableName(
variableName);
const auto sourceType = variablesContainer.GetSourceType();
if (sourceType != gd::VariablesContainer::SourceType::Properties &&
sourceType != gd::VariablesContainer::SourceType::Parameters) {
getterCode += ".getAsBoolean()";
}

gd::String resultingBoolean =
codeGenerator.GenerateUpperScopeBooleanFullName("isConditionTrue",
Expand Down

0 comments on commit f676bd5

Please sign in to comment.