Skip to content

Commit

Permalink
Remove an error about object name collision in object variable fields (
Browse files Browse the repository at this point in the history
  • Loading branch information
D8H authored Jul 4, 2024
1 parent b516037 commit f628119
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 2 deletions.
23 changes: 23 additions & 0 deletions Core/tests/ExpressionParser2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ TEST_CASE("ExpressionParser2", "[common][events]") {
mySpriteObject.GetVariables().InsertNew("MyVariable3");
mySpriteObject.GetVariables().InsertNew("MyNumberVariable").SetValue(123);
mySpriteObject.GetVariables().InsertNew("MyStringVariable").SetString("Test");
// A variable with the same name as the object.
mySpriteObject.GetVariables().InsertNew("MySpriteObject");
auto &mySpriteObject2 = layout1.InsertNewObject(project, "MyExtension::Sprite", "MySpriteObject2", 1);
mySpriteObject2.GetVariables().InsertNew("MyVariable", 0);
mySpriteObject2.GetVariables().InsertNew("MyVariable2", 1);
Expand Down Expand Up @@ -1685,6 +1687,27 @@ TEST_CASE("ExpressionParser2", "[common][events]") {
}
}

SECTION("Variable with the same name as an object") {
auto node = parser.ParseExpression("MySpriteObject.MySpriteObject");
REQUIRE(node != nullptr);

gd::ExpressionValidator validator(platform, projectScopedContainers,
"number|string");
node->Visit(validator);
REQUIRE(validator.GetFatalErrors().size() == 0);
REQUIRE(validator.GetAllErrors().size() == 0);
}

SECTION("Variable with the same name as an object (with child-variables)") {
auto node = parser.ParseExpression("MySpriteObject.MySpriteObject.MyChild.MyChild");
REQUIRE(node != nullptr);

gd::ExpressionValidator validator(platform, projectScopedContainers, "number|string");
node->Visit(validator);
REQUIRE(validator.GetFatalErrors().size() == 0);
REQUIRE(validator.GetAllErrors().size() == 0);
}

SECTION("Invalid object variables (1 level, non existing object)") {
{
auto node =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export default React.forwardRef<ParameterFieldProps, ParameterFieldInterface>(
forceDeclaration
project={project}
instruction={instruction}
isObjectVariable={false}
variablesContainers={variablesContainers}
enumerateVariables={enumerateGlobalAndSceneVariables}
parameterMetadata={props.parameterMetadata}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default React.forwardRef<ParameterFieldProps, ParameterFieldInterface>(
return (
<React.Fragment>
<VariableField
isObjectVariable={false}
variablesContainers={variablesContainers}
enumerateVariables={enumerateGlobaleVariables}
parameterMetadata={props.parameterMetadata}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export default React.forwardRef<ParameterFieldProps, ParameterFieldInterface>(
}
project={project}
instruction={instruction}
isObjectVariable={true}
variablesContainers={variablesContainers}
enumerateVariables={enumerateObjectVariables}
parameterMetadata={props.parameterMetadata}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default React.forwardRef<ParameterFieldProps, ParameterFieldInterface>(
return (
<React.Fragment>
<VariableField
isObjectVariable={false}
variablesContainers={variablesContainers}
enumerateVariables={enumerateSceneVariables}
parameterMetadata={props.parameterMetadata}
Expand Down
9 changes: 7 additions & 2 deletions newIDE/app/src/EventsSheet/ParameterFields/VariableField.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export type VariableDialogOpeningProps = {

type Props = {
...ParameterFieldProps,
isObjectVariable: boolean,
variablesContainers: Array<gdVariablesContainer>,
enumerateVariables: () => Array<EnumeratedVariable>,
forceDeclaration?: boolean,
Expand Down Expand Up @@ -94,7 +95,8 @@ export const getRootVariableName = (name: string): string => {
export const quicklyAnalyzeVariableName = (
name: string,
variablesContainers?: Array<gdVariablesContainer>,
projectScopedContainersAccessor?: ProjectScopedContainersAccessor
projectScopedContainersAccessor?: ProjectScopedContainersAccessor,
isObjectVariable: boolean = false
): VariableNameQuickAnalyzeResult => {
if (!name) return VariableNameQuickAnalyzeResults.OK;

Expand All @@ -121,6 +123,7 @@ export const quicklyAnalyzeVariableName = (

const rootVariableName = getRootVariableName(name);
if (
!isObjectVariable &&
projectScopedContainersAccessor &&
projectScopedContainersAccessor
.get()
Expand Down Expand Up @@ -196,6 +199,7 @@ export default React.forwardRef<Props, VariableFieldInterface>(
onApply,
id,
onInstructionTypeChanged,
isObjectVariable,
} = props;

const field = React.useRef<?SemiControlledAutoCompleteInterface>(null);
Expand Down Expand Up @@ -286,7 +290,8 @@ export default React.forwardRef<Props, VariableFieldInterface>(
const quicklyAnalysisResult = quicklyAnalyzeVariableName(
value,
variablesContainers,
projectScopedContainersAccessor
projectScopedContainersAccessor,
isObjectVariable
);

const errorText =
Expand Down

0 comments on commit f628119

Please sign in to comment.