Skip to content

Unify variable instructions and handle local variables #6459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 145 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
145 commits
Select commit Hold shift + click to select a range
737c497
Start to add a "variable" parameter type
D8H Jan 8, 2024
c4915fa
Forbid undeclared variables in "variable" parameter.
D8H Mar 15, 2024
460770e
Add declarations for all variable instructions.
D8H Mar 15, 2024
ca227ef
Unify variable conditions.
D8H Mar 15, 2024
c92eb17
Fix parameter icon.
D8H Mar 25, 2024
c45eef1
Rename new variable instructions.
D8H Mar 25, 2024
e6ec599
Unify object variable instructions.
D8H Mar 25, 2024
fa22e1b
Use a boolean operator for toggle.
D8H Mar 26, 2024
0c2158c
Add the extra parameter in boolean condition.
D8H Mar 26, 2024
9d464fe
Unify toggle for object variable action.
D8H Mar 27, 2024
c9d73a2
Add new instructions for object variables.
D8H Mar 27, 2024
a5946ec
Add red on undeclared object variables in the instruction editor.
D8H Mar 27, 2024
dac0853
Add a refactor to choose the right variable instruction when its type…
D8H Mar 28, 2024
17777f6
Fix tests.
D8H Mar 28, 2024
2dc6b5d
Documentation
D8H Mar 29, 2024
eb9bef0
Handle child-variables.
D8H Mar 29, 2024
bc8535b
Allow to choose the type for undeclared child-variables.
D8H Apr 2, 2024
913373e
Hide the drop-down list if there is any error.
D8H Apr 3, 2024
283d8a3
Fix variable type in autocompletion tests.
D8H Apr 3, 2024
faaaac4
Fix a crash when the object doesn't exist.
D8H Apr 3, 2024
4352e3d
Fix instruction list identifiers.
D8H Apr 3, 2024
276ac41
Actually fix identifiers.
D8H Apr 3, 2024
4a69e59
Add red on undeclared object variables.
D8H Apr 3, 2024
d9e5e26
Fix tests.
D8H Apr 3, 2024
d956433
Make variable existence check more explicit.
D8H Apr 3, 2024
d4d35ee
Revert some unused changes.
D8H Apr 3, 2024
1b9a17e
Fix variable dialog switch.
D8H Apr 3, 2024
4b6d5d0
Fix object variable autocompletion.
D8H Apr 3, 2024
3637551
Fix a sentence.
D8H Apr 4, 2024
15f405b
Better show deprecated instructions.
D8H Apr 4, 2024
1c66b8b
Unify "Push" action.
D8H Apr 4, 2024
605b392
Unify "Push" actions of objects.
D8H Apr 4, 2024
8ec16c9
Autocomplete parameters with the last selected variable in the editor.
D8H Apr 5, 2024
47bdf73
Use the type of the previous child to push in an array.
D8H Apr 5, 2024
2f253d8
Hide global variable with the same name as a scene variable in autoco…
D8H Apr 5, 2024
57ce230
Add icons for scope and type.
D8H Apr 8, 2024
69e3fde
Hide variable expressions.
D8H Apr 8, 2024
1901c0d
Replace "string" by "text".
D8H Apr 8, 2024
75ed38b
Use tabs to switch between global and scene variable editors.
D8H Apr 9, 2024
08fd7f0
Use SVG icons for variable parameters in the event sheet.
D8H Apr 9, 2024
330189f
Fix rebase.
D8H Apr 9, 2024
ee7f6ef
Add variables on events.
D8H Apr 10, 2024
7f46a76
Pass a projectScopedContainers to the EventSheet.
D8H Apr 10, 2024
1cd8999
Pass a projectScopedContainers to the parameter fields.
D8H Apr 11, 2024
d512d90
Remove useless call to EventsFunctionExtractorDialog.
D8H Apr 11, 2024
2c5d683
Add local variables to the context.
D8H Apr 15, 2024
5a37190
Dumb inline variable declaration rendering.
D8H Apr 15, 2024
8fa1141
Handle local variable refactoring.
D8H Apr 16, 2024
215169c
Fix icon size.
D8H Apr 16, 2024
a865dee
Fix event selection rectangle.
D8H Apr 16, 2024
c6928ae
Code generation.
D8H Apr 17, 2024
0abb21d
Code generation for async actions.
D8H Apr 18, 2024
222c6ef
Review changes.
D8H Apr 18, 2024
29f296a
Open the dialog when a local variable is added and select it.
D8H Apr 18, 2024
5c1626c
Fix flow
D8H Apr 18, 2024
d7f66d9
Better handle translation and remove colors.
D8H Apr 18, 2024
fe68e44
Use the code namespace.
D8H Apr 18, 2024
f8c99d2
Fix the context copy when adding local variables to keep everything.
D8H Apr 18, 2024
56107ab
Fix id issue.
D8H Apr 18, 2024
f529ba0
Fix pre-selection from variable name with brackets.
D8H Apr 19, 2024
aa89468
Fix the shortcut.
D8H Apr 19, 2024
ab9340e
Add component for variable dialogs.
D8H Apr 19, 2024
778c7fc
Fix structure child insertion.
D8H Apr 22, 2024
83cbace
Fix some tests.
D8H Apr 22, 2024
a621cef
Revert a fix to handle variable name collision as it makes a regressi…
D8H Apr 22, 2024
519413f
Fix some other tests.
D8H Apr 22, 2024
be7b2a2
Fix some tests again.
D8H Apr 22, 2024
33209cb
Duplicate some tests.
D8H Apr 22, 2024
48b42b2
Add tests on some variable actions and conditions.
D8H Apr 23, 2024
23e63e6
Add some test with async.
D8H Apr 23, 2024
68d0ec4
Add some tests on object variable actions and conditions.
D8H Apr 23, 2024
e721739
Add some tests with async and local variables.
D8H Apr 24, 2024
bcf26fa
Add tests on push actions.
D8H Apr 24, 2024
f7a0e56
Various typo
D8H Apr 24, 2024
74283a8
Clarify some comments.
D8H Apr 24, 2024
7642a4b
Move some code to Core.
D8H Apr 25, 2024
2facabc
Fix tests.
D8H Apr 25, 2024
f0e65b9
Test variable declaration validation.
D8H Apr 25, 2024
b07bcf6
Rename a file to make git better detect a renaming.
D8H Apr 26, 2024
9f1a8ad
Various review changes.
D8H Apr 28, 2024
cb16eb3
Add css class for local variables.
D8H Apr 28, 2024
02358ae
Clarify some code.
D8H Apr 28, 2024
3ed0782
Encapsulate some code.
D8H Apr 28, 2024
62baa43
Create local variables by index.
D8H Apr 28, 2024
2fc3355
Fix undeclared variable list in the dialog with 2 tabs.
D8H Apr 29, 2024
72733af
Remove unused property for selection.
D8H Apr 29, 2024
3726bc7
Rename ProjectScopedContainers to ProjectScopedContainersAccessor.
D8H Apr 29, 2024
6b39c26
Some review changes.
D8H Apr 29, 2024
a734f1c
Factorize ExpressionVariableParentFinder and ExpressionVariableTypeFi…
D8H May 1, 2024
50b89cd
Clearer context.
D8H May 2, 2024
73eb5b3
Avoid to use a pointer.
D8H May 2, 2024
56264ce
Fix the refactor of the variable instruction type when a child type i…
D8H May 2, 2024
97d4cb2
Fix the refactor of object variable instruction type.
D8H May 3, 2024
4072999
Don't fallback on scene variables.
D8H May 3, 2024
2f14a3e
Remove useless defines.
D8H May 3, 2024
2cfdcc7
Format
D8H May 3, 2024
83f3452
Fix missing context in the expression builder.
D8H May 3, 2024
5d51554
Keep VariableChildCount compatibility.
D8H May 3, 2024
43e56ef
Fix local variables.
D8H May 3, 2024
552a818
Remove some useless code.
D8H May 6, 2024
2ef3e93
Factorize ProjectScopedContainers creation for extensions.
D8H May 6, 2024
5448576
Remove useless parameter.
D8H May 6, 2024
c2aa314
Fix scroll to edited instruction.
D8H May 7, 2024
1597610
Fix variable type check to return Unknown when there are brackets.
D8H May 7, 2024
bc42367
Handle literal bracket accessors to find type or give autocompletion.
D8H May 7, 2024
212eb1d
Fail attempt to fix the event height refresh after adding local varia…
D8H May 7, 2024
ec9a1dd
Fix variable autocompletion tests using expressions in brackets
4ian May 8, 2024
9e53bea
Fix flow.
D8H May 8, 2024
3090bdc
Fix typo in attribute name and format.
D8H May 10, 2024
9891ba2
Add some tests on structure instructions.
D8H May 10, 2024
762d2e4
Use only 1 object container for functions.
D8H May 8, 2024
43788be
Pass the extension.
D8H May 8, 2024
2febd58
Fix event worker inheritance.
D8H May 8, 2024
37b21e6
Allow to use extension variables in the editor.
D8H May 8, 2024
b629715
Generate code for global and scene variables of extensions.
D8H May 9, 2024
4ff4dfd
Generate code for local variables of extensions.
D8H May 9, 2024
7d640f4
Fix tests.
D8H May 10, 2024
8483a38
Duplicate tests for functions.
D8H May 10, 2024
2381229
Fix types.
D8H May 10, 2024
dae7911
Add a test on the instruction switching.
D8H May 10, 2024
01c70f5
Some review changes.
D8H May 13, 2024
5f60d8d
Use the function context for extension variables.
D8H May 14, 2024
91dd933
Add usedExtensionsWithVariablesData in a new instance.
D8H May 14, 2024
bf4927c
Some other review changes.
D8H May 14, 2024
2758697
Review changes: remove useless code.
D8H May 14, 2024
fc0c7bc
Fix file case in generate-types script.
D8H May 20, 2024
92b38d3
Remove ExpressionParserDiagnostic.
D8H May 15, 2024
f815aa5
Make expression error type more precise.
D8H May 15, 2024
96961a0
Add a report on the project.
D8H May 16, 2024
fa0402d
Add a dialog.
D8H May 16, 2024
2495ff2
Better title formatting.
D8H May 17, 2024
4264062
Use a Table.
D8H May 17, 2024
6d58c93
Show missing behaviors.
D8H May 17, 2024
8e3df70
Add a setting.
D8H May 17, 2024
3de7ae5
Update types.
D8H May 17, 2024
da9a207
Format
D8H May 17, 2024
c850d1e
Filter empty names.
D8H May 17, 2024
a106d0f
Remove some types.
D8H May 17, 2024
721a9ca
Declare missing constructor.
D8H May 17, 2024
aa341fb
Fix file case in generate-types script.
D8H May 20, 2024
8d6e0b3
Use a pointer for the setter too.
D8H May 20, 2024
7289c62
Fix test.
D8H May 20, 2024
0fff0fd
Fix a crash when using a custom object.
D8H May 20, 2024
2a5ec24
Fix false positive on ActivateBehavior.
D8H May 20, 2024
573f327
Comment back debug.
D8H May 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Core/GDCore/Events/Builtin/StandardEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ using namespace std;

namespace gd {

StandardEvent::StandardEvent() : BaseEvent() {}
StandardEvent::StandardEvent()
: BaseEvent(), variables(gd::VariablesContainer::SourceType::Local) {}

StandardEvent::~StandardEvent(){};

Expand Down Expand Up @@ -57,6 +58,9 @@ void StandardEvent::SerializeTo(SerializerElement& element) const {
if (!events.IsEmpty())
gd::EventsListSerialization::SerializeEventsTo(events,
element.AddChild("events"));
if (HasVariables()) {
variables.SerializeTo(element.AddChild("variables"));
}
}

void StandardEvent::UnserializeFrom(gd::Project& project,
Expand All @@ -71,6 +75,11 @@ void StandardEvent::UnserializeFrom(gd::Project& project,
gd::EventsListSerialization::UnserializeEventsFrom(
project, events, element.GetChild("events", 0, "Events"));
}

variables.Clear();
if (element.HasChild("variables")) {
variables.UnserializeFrom(element.GetChild("variables"));
}
}

} // namespace gd
14 changes: 8 additions & 6 deletions Core/GDCore/Events/Builtin/StandardEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
* reserved. This project is released under the MIT License.
*/

#if defined(GD_IDE_ONLY)
#ifndef GDCORE_STANDARDEVENT_H
#define GDCORE_STANDARDEVENT_H
#pragma once

#include "GDCore/Events/Event.h"
#include "GDCore/Events/EventsList.h"
#include "GDCore/Events/Instruction.h"
#include "GDCore/Events/InstructionsList.h"
#include "GDCore/Project/VariablesContainer.h"
namespace gd {
class Instruction;
class Project;
Expand All @@ -33,6 +33,10 @@ class GD_CORE_API StandardEvent : public gd::BaseEvent {
virtual const gd::EventsList& GetSubEvents() const { return events; };
virtual gd::EventsList& GetSubEvents() { return events; };

virtual bool CanHaveVariables() const { return true; }
virtual const gd::VariablesContainer& GetVariables() const { return variables; };
virtual gd::VariablesContainer& GetVariables() { return variables; };

const gd::InstructionsList& GetConditions() const { return conditions; };
gd::InstructionsList& GetConditions() { return conditions; };

Expand All @@ -53,9 +57,7 @@ class GD_CORE_API StandardEvent : public gd::BaseEvent {
gd::InstructionsList conditions;
gd::InstructionsList actions;
EventsList events;
VariablesContainer variables;
};

} // namespace gd

#endif // GDCORE_STANDARDEVENT_H
#endif
115 changes: 115 additions & 0 deletions Core/GDCore/Events/CodeGeneration/DiagnosticReport.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* GDevelop Core
* Copyright 2008-present Florian Rival ([email protected]). All rights
* reserved. This project is released under the MIT License.
*/
#pragma once

#include <memory>
#include <vector>

#include "GDCore/String.h"
#include "GDCore/Tools/MakeUnique.h"

namespace gd {

/**
* \brief
*/
class GD_CORE_API ProjectDiagnostic {
public:
enum ErrorType {
UndeclaredVariable,
MissingBehavior
};

ProjectDiagnostic(ErrorType type_, const gd::String &message_,
const gd::String &actualValue_,
const gd::String &expectedValue_, const gd::String &objectName_)
: type(type_), message(message_), actualValue(actualValue_), expectedValue(expectedValue_),
objectName(objectName_){};
virtual ~ProjectDiagnostic(){};

ErrorType GetType() const { return type; };
const gd::String &GetMessage() const { return message; }
const gd::String &GetObjectName() const { return objectName; }
const gd::String &GetActualValue() const { return actualValue; }
const gd::String &GetExpectedValue() const { return expectedValue; }

private:
ErrorType type;
gd::String message;
gd::String objectName;
gd::String actualValue;
gd::String expectedValue;
};

/**
* \brief
*/
class GD_CORE_API DiagnosticReport {
public:
DiagnosticReport(){};
virtual ~DiagnosticReport(){};

void Add(const gd::ProjectDiagnostic &projectDiagnostic) {
projectDiagnostics.push_back(
gd::make_unique<gd::ProjectDiagnostic>(projectDiagnostic));
};

const ProjectDiagnostic &Get(std::size_t index) const {
return *projectDiagnostics[index].get();
};

std::size_t Count() const { return projectDiagnostics.size(); };

const gd::String &GetSceneName() const { return sceneName; }

void SetSceneName(const gd::String &sceneName_) {
sceneName = sceneName_;
}

private:
std::vector<std::unique_ptr<gd::ProjectDiagnostic>> projectDiagnostics;
gd::String sceneName;
};

/**
* \brief
*/
class GD_CORE_API WholeProjectDiagnosticReport {
public:
WholeProjectDiagnosticReport(){};
virtual ~WholeProjectDiagnosticReport(){};

const DiagnosticReport &Get(std::size_t index) const {
return *diagnosticReports[index].get();
};

void Clear() {
diagnosticReports.clear();
};

DiagnosticReport& AddNewDiagnosticReportForScene(const gd::String &sceneName) {
auto diagnosticReport = gd::make_unique<gd::DiagnosticReport>();
diagnosticReport->SetSceneName(sceneName);
diagnosticReports.push_back(std::move(diagnosticReport));
return *diagnosticReports[diagnosticReports.size() - 1].get();
};

std::size_t Count() const { return diagnosticReports.size(); };

bool HasAnyIssue() {
for (auto& diagnosticReport : diagnosticReports) {
if (diagnosticReport->Count() > 0) {
return true;
}
}
return false;
}

private:
std::vector<std::unique_ptr<gd::DiagnosticReport>> diagnosticReports;
};

} // namespace gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Copyright 2008-2016 Florian Rival ([email protected]). All rights
* reserved. This project is released under the MIT License.
*/
#ifndef EVENTSCODEGENERATIONCONTEXT_H
#define EVENTSCODEGENERATIONCONTEXT_H
#pragma once

#include <map>
#include <memory>
#include <set>
Expand Down Expand Up @@ -325,4 +325,3 @@ class GD_CORE_API EventsCodeGenerationContext {
};

} // namespace gd
#endif // EVENTSCODEGENERATIONCONTEXT_H
Loading
Loading