Skip to content
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

Events based behaviors 🚀 #1049

Merged
merged 45 commits into from May 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
338f062
Refactor EventsFunctionsExtension to use EventsFunctionsContainer/Ser…
4ian Apr 25, 2019
bf8d1a6
Remove dead code from gd::Layout
4ian Apr 25, 2019
13bc2a5
Remove more dead code
4ian Apr 25, 2019
7925e75
[WIP] Add EventsBasedBehavior
4ian Apr 25, 2019
9bbc5e4
[WIP] Add support for EventsBasedBehavior in newIDE
4ian Apr 26, 2019
2353815
[WIP] Add code generation for EventsBasedBehavior
4ian Apr 26, 2019
7b69d41
Remove useless GetCustomCodeInMain and related methods
4ian Apr 29, 2019
73121d5
[WIP] Add code generation for EventsBasedBehavior (2)
4ian Apr 29, 2019
433dc76
Separate Behavior into BehaviorContent and Behavior, and add RuntimeB…
4ian Apr 30, 2019
6dba9d9
Improve EventsBasedBehavior edition in IDE
4ian May 3, 2019
3161f64
Rename ownerRemovedFromScene to onOwnerRemovedFromScene
4ian May 6, 2019
6332230
Add basic test game for EventsBasedBehavior
4ian May 6, 2019
2d31e91
Add support for EventsBasedBehavior object type
4ian May 6, 2019
9e89f51
Ensure behavior type is displayed in selector even if unknown
4ian May 7, 2019
e670563
Add tests for WholeProjectRefactorer and events based functions/exten…
4ian May 7, 2019
4b85f23
Prepare the new refactorings in WholeProjectRefactorer for behaviors
4ian May 7, 2019
b96fda0
Run Prettier
4ian May 8, 2019
32dd269
Add automatic refactoring of project when an events based behavior is…
4ian May 8, 2019
3073b9f
Fix typos
4ian May 9, 2019
89ac323
Add support for automatic refactoring when events function (including…
4ian May 10, 2019
ccb18a0
Fix opening of behavior function from events sheet and prevent using …
4ian May 10, 2019
58db3be
Add more tests for WholeProjectRefactorer
4ian May 10, 2019
99238a0
Only allow changing behavior's object type if actually possible
4ian May 10, 2019
6315857
Fix copy/cut/paste for Events Functions/Behaviors Extensions
4ian May 10, 2019
a97486b
Remove CopyOf prefix when pasting things in ProjectManager
4ian May 10, 2019
7769c02
Fix flow
4ian May 10, 2019
1778aa1
Add copy/cut/paste for events functions
4ian May 12, 2019
6496095
Add help links for events based behaviors
4ian May 15, 2019
7d144f1
Add missing translation tags
4ian May 15, 2019
2d850b0
[WIP] Add ExtensionsSearch to NewBehaviorDialog
4ian May 16, 2019
327be15
Rework EventsFunctionsExtensionsLoader to use context
4ian May 17, 2019
c7ba85c
Display extension full header in ExtensionInstallDialog and handle er…
4ian May 17, 2019
1494a47
Add button to search extensions in ProjectManager
4ian May 17, 2019
b7e8507
Remove some TODOs and add messages if too much extensions to display
4ian May 17, 2019
a985751
Add button to explain how to create new behaviors
4ian May 17, 2019
4e23c46
Remove warnings from .vscode/c_cpp_properties.json
4ian May 17, 2019
c9a90b2
Add support for short description and tags in EventsFunctionsExtension
4ian May 18, 2019
457940a
Add import/export to file for events functions extensions
4ian May 18, 2019
fdfe7b3
Allow to replace an extension when importing one
4ian May 18, 2019
60bb4ad
Remove warnings from .vscode/c_cpp_properties.json (2)
4ian May 18, 2019
2bccc31
Remove useless TODO
4ian May 18, 2019
eeeafff
Add tags in ExtensionsSearch
4ian May 18, 2019
0be7ee8
Fix SetReturnString argument type
4ian May 19, 2019
8d0ba97
Add author to EventsFunctionsExtension
4ian May 19, 2019
7fe3fa1
Fix search/tags in ExtensionsSearch
4ian May 19, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 1 addition & 4 deletions .vscode/c_cpp_properties.json
Expand Up @@ -4,15 +4,13 @@
"name": "Mac",
"includePath": [
"${workspaceRoot}",
"${workspaceRoot}/IDE",
"${workspaceRoot}/GDCpp",
"${workspaceRoot}/GDJS",
"${workspaceRoot}/Extensions",
"${workspaceRoot}/Core",
"${workspaceRoot}/ExtLibs/SFML/include",
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1",
"/usr/local/include",
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/include",
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include",
"/usr/include",
"${workspaceRoot}"
Expand All @@ -28,7 +26,6 @@
"path": [
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1",
"/usr/local/include",
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/include",
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include",
"/usr/include",
"${workspaceRoot}"
Expand Down Expand Up @@ -108,4 +105,4 @@
}
],
"version": 4
}
}
3 changes: 2 additions & 1 deletion .vscode/settings.json
Expand Up @@ -79,7 +79,8 @@
"mutex": "cpp",
"__hash": "cpp",
"__debug": "cpp",
"__threading_support": "cpp"
"__threading_support": "cpp",
"any": "cpp"
},
"files.exclude": {
"Binaries/*build*": true,
Expand Down
Expand Up @@ -537,6 +537,7 @@ gd::String EventsCodeGenerator::GenerateActionCode(
action.GetParameters().size() < 2
? ""
: action.GetParameter(1).GetPlainString());

if (MetadataProvider::HasBehaviorAction(
platform, behaviorType, action.GetType()) &&
instrInfos.parameters.size() >= 2) {
Expand Down
11 changes: 0 additions & 11 deletions Core/GDCore/Events/CodeGeneration/EventsCodeGenerator.h
Expand Up @@ -239,11 +239,6 @@ class GD_CORE_API EventsCodeGenerator {
customCodeOutsideMain += code;
};

/**
* \brief Add some code before events in the main function.
*/
void AddCustomCodeInMain(gd::String code) { customCodeInMain += code; };

/** \brief Get the set containing the include files.
*/
const std::set<gd::String>& GetIncludeFiles() const { return includeFiles; }
Expand All @@ -254,10 +249,6 @@ class GD_CORE_API EventsCodeGenerator {
return customCodeOutsideMain;
}

/** \brief Get the custom code to be inserted inside main function.
*/
const gd::String& GetCustomCodeInMain() const { return customCodeInMain; }

/** \brief Get the custom declaration to be inserted after includes.
*/
const std::set<gd::String>& GetCustomGlobalDeclaration() const {
Expand Down Expand Up @@ -734,8 +725,6 @@ class GD_CORE_API EventsCodeGenerator {
///< can share the same list.
gd::String customCodeOutsideMain; ///< Custom code inserted before events (
///< and not in events function )
gd::String customCodeInMain; ///< Custom code inserted before events ( in
///< main function )
std::set<gd::String>
customGlobalDeclarations; ///< Custom global C++ declarations inserted
///< after includes
Expand Down
3 changes: 0 additions & 3 deletions Core/GDCore/Events/Event.h
Expand Up @@ -266,9 +266,6 @@ class GD_CORE_API BaseEvent {
float percentDuringLastSession; ///< Total time used by the event during the
///< last run. Used for profiling.

protected:
mutable unsigned int renderedHeight;

private:
bool folded; ///< True if the subevents should be hidden in the events editor
bool disabled; ///< True if the event is disabled and must not be executed
Expand Down
11 changes: 2 additions & 9 deletions Core/GDCore/Events/Instruction.cpp
Expand Up @@ -16,22 +16,15 @@ namespace gd {
gd::Expression Instruction::badExpression("");

Instruction::Instruction(gd::String type_)
: renderedHeightNeedUpdate(true),
renderedHeight(0),
selected(false),
type(type_),
: type(type_),
inverted(false) {
// ctor
parameters.reserve(8);
}

Instruction::Instruction(gd::String type_,
const std::vector<gd::Expression>& parameters_,
bool inverted_)
: renderedHeightNeedUpdate(true),
renderedHeight(0),
selected(false),
type(type_),
: type(type_),
inverted(inverted_),
parameters(parameters_) {
parameters.reserve(8);
Expand Down
16 changes: 1 addition & 15 deletions Core/GDCore/Events/Instruction.h
Expand Up @@ -17,7 +17,7 @@ namespace gd {
* action.
*
* An instruction has a type, which define what it does, and some parameters. It
* can also be set as inverted ( when the instruction is a condition ) and it
* can also be set as inverted (when the instruction is a condition) and it
* can have sub instructions. This class does nothing particular except storing
* these data.
*
Expand Down Expand Up @@ -131,20 +131,6 @@ class GD_CORE_API Instruction {
*/
inline gd::InstructionsList& GetSubInstructions() { return subInstructions; };

/** \name Rendering
* Members related to the instruction rendering in an event editor.
*/
///@{

mutable bool
renderedHeightNeedUpdate; ///< True if the instruction height may have
///< changed and must be computed again.
mutable unsigned int renderedHeight; ///< Height of the instruction rendered
///< in an event editor.
mutable bool selected; ///< True if selected in an event editor.

///@}

private:
gd::String type; ///< Instruction type
bool inverted; ///< True if the instruction if inverted. Only applicable for
Expand Down
2 changes: 1 addition & 1 deletion Core/GDCore/Extensions/Builtin/AdvancedExtension.cpp
Expand Up @@ -56,7 +56,7 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsAdvancedExtension(
_("Functions"),
"res/function24.png",
"res/function16.png")
.AddParameter("expression", "The text to be returned")
.AddParameter("string", "The text to be returned")
.MarkAsAdvanced();

extension
Expand Down
52 changes: 51 additions & 1 deletion Core/GDCore/Extensions/Metadata/BehaviorMetadata.cpp
Expand Up @@ -4,8 +4,8 @@
* reserved. This project is released under the MIT License.
*/
#include "BehaviorMetadata.h"
#include <algorithm>
#include <iostream>
#include "GDCore/Extensions/PlatformExtension.h"
#include "GDCore/Extensions/Metadata/ExpressionMetadata.h"
#include "GDCore/Extensions/Metadata/InstructionMetadata.h"
#include "GDCore/Project/Behavior.h"
Expand Down Expand Up @@ -88,6 +88,52 @@ gd::InstructionMetadata& BehaviorMetadata::AddAction(
#endif
}

gd::InstructionMetadata& BehaviorMetadata::AddScopedCondition(
const gd::String& name,
const gd::String& fullname,
const gd::String& description,
const gd::String& sentence,
const gd::String& group,
const gd::String& icon,
const gd::String& smallicon) {
#if defined(GD_IDE_ONLY)
gd::String nameWithNamespace = GetName() +gd::PlatformExtension::GetNamespaceSeparator() + name;
conditionsInfos[nameWithNamespace] = InstructionMetadata(extensionNamespace,
nameWithNamespace,
fullname,
description,
sentence,
group,
icon,
smallicon)
.SetHelpPath(GetHelpPath());
return conditionsInfos[nameWithNamespace];
#endif
}

gd::InstructionMetadata& BehaviorMetadata::AddScopedAction(
const gd::String& name,
const gd::String& fullname,
const gd::String& description,
const gd::String& sentence,
const gd::String& group,
const gd::String& icon,
const gd::String& smallicon) {
#if defined(GD_IDE_ONLY)
gd::String nameWithNamespace = GetName() + gd::PlatformExtension::GetNamespaceSeparator() + name;
actionsInfos[nameWithNamespace] = InstructionMetadata(extensionNamespace,
nameWithNamespace,
fullname,
description,
sentence,
group,
icon,
smallicon)
.SetHelpPath(GetHelpPath());
return actionsInfos[nameWithNamespace];
#endif
}

gd::ExpressionMetadata& BehaviorMetadata::AddExpression(
const gd::String& name,
const gd::String& fullname,
Expand Down Expand Up @@ -162,4 +208,8 @@ BehaviorMetadata& BehaviorMetadata::AddIncludeFile(
return *this;
}

const gd::String& BehaviorMetadata::GetName() const {
return instance->GetTypeName();
}

} // namespace gd
73 changes: 60 additions & 13 deletions Core/GDCore/Extensions/Metadata/BehaviorMetadata.h
Expand Up @@ -19,11 +19,7 @@ class ExpressionMetadata;
namespace gd {

/**
* \brief Contains user-friendly information about a behavior type
*
* Implementations may derive from this class so as to provide more complete
* metadata if needed. ( For example, GDevelop C++ Platform is shared pointers
* to objects that will be cloned so as to create the behaviors... )
* \brief Contains user-friendly information about a behavior type.
*
* \ingroup Events
*/
Expand All @@ -44,7 +40,8 @@ class GD_CORE_API BehaviorMetadata {
virtual ~BehaviorMetadata(){};

/**
* Declare a new condition as being part of the extension.
* Declare a new condition as being part of the behavior.
* \deprecated Prefer using `AddScopedCondition`.
*/
gd::InstructionMetadata& AddCondition(const gd::String& name_,
const gd::String& fullname_,
Expand All @@ -55,7 +52,8 @@ class GD_CORE_API BehaviorMetadata {
const gd::String& smallicon_);

/**
* Declare a new action as being part of the extension.
* Declare a new action as being part of the behavior.
* \deprecated Prefer using `AddScopedAction`.
*/
gd::InstructionMetadata& AddAction(const gd::String& name_,
const gd::String& fullname_,
Expand All @@ -64,6 +62,28 @@ class GD_CORE_API BehaviorMetadata {
const gd::String& group_,
const gd::String& icon_,
const gd::String& smallicon_);

/**
* Declare a new condition as being part of the behavior.
*/
gd::InstructionMetadata& AddScopedCondition(const gd::String& name_,
const gd::String& fullname_,
const gd::String& description_,
const gd::String& sentence_,
const gd::String& group_,
const gd::String& icon_,
const gd::String& smallicon_);

/**
* Declare a new action as being part of the behavior.
*/
gd::InstructionMetadata& AddScopedAction(const gd::String& name_,
const gd::String& fullname_,
const gd::String& description_,
const gd::String& sentence_,
const gd::String& group_,
const gd::String& icon_,
const gd::String& smallicon_);
/**
* Declare a new action as being part of the extension.
*/
Expand Down Expand Up @@ -102,29 +122,54 @@ class GD_CORE_API BehaviorMetadata {
/**
* Get the help path of the behavior, relative to the documentation root.
*/
const gd::String &GetHelpPath() const { return helpPath; }
const gd::String& GetHelpPath() const { return helpPath; }

/**
* Set the help path of the behavior, relative to the documentation root.
*
*
* The behavior instructions will have this help path set by
* default, unless you call SetHelpPath on them.
*/
BehaviorMetadata &SetHelpPath(const gd::String &path) {
BehaviorMetadata& SetHelpPath(const gd::String& path) {
helpPath = path;
return *this;
}

const gd::String& GetName() const;
#if defined(GD_IDE_ONLY)
const gd::String& GetFullName() const { return fullname; }
const gd::String& GetDefaultName() const { return defaultName; }
const gd::String& GetDescription() const { return description; }
const gd::String& GetGroup() const { return group; }
const gd::String& GetIconFilename() const { return iconFilename; }

/**
* \brief Set the type of the object that this behavior can be used on.
*/
BehaviorMetadata& SetObjectType(const gd::String& objectType_) {
objectType = objectType_;
return *this;
}

/**
* \brief Get the type of the object that this behavior can be used on.
*
* \note An empty string means the base object, so any object.
*/
const gd::String& GetObjectType() const { return objectType; }
#endif
std::shared_ptr<gd::Behavior> Get() const { return instance; }
std::shared_ptr<gd::BehaviorsSharedData> GetSharedDataInstance() const {
return sharedDatasInstance;

/**
* \brief Return the associated gd::Behavior, handling behavior contents.
*/
gd::Behavior& Get() const { return *instance; }

/**
* \brief Return the associated gd::BehaviorsSharedData, handling behavior
* shared data, if any (nullptr if none).
*/
gd::BehaviorsSharedData* GetSharedDataInstance() const {
return sharedDatasInstance.get();
}

#if defined(GD_IDE_ONLY)
Expand All @@ -145,8 +190,10 @@ class GD_CORE_API BehaviorMetadata {
gd::String description;
gd::String group;
gd::String iconFilename;
gd::String objectType;
#endif

// TODO: Nitpicking: convert these to std::unique_ptr to clarify ownership.
std::shared_ptr<gd::Behavior> instance;
std::shared_ptr<gd::BehaviorsSharedData> sharedDatasInstance;
};
Expand Down