Compare commits

...

54 Commits

Author SHA1 Message Date
Davy Hélard
2a03c8902d Fix a lost of focus when a condition is pasted 2024-07-26 15:53:31 +02:00
D8H
2585ad5dca Avoid children variables to collapse in the editor after an undo (#6805) 2024-07-26 14:43:38 +02:00
D8H
a9108fa87b Add a tolerance parameter on the "linear velocity angle" condition (#6804) 2024-07-26 14:27:17 +02:00
D8H
cd3186d2d8 Fix duplicated "email" choice for text input type (#6803) 2024-07-26 12:22:36 +02:00
D8H
6a737f7d51 Fix particle emitter blending mode action (#6801) 2024-07-26 12:01:19 +02:00
github-actions[bot]
9211aa7a3b Update translations [skip ci] (#6799)
Co-authored-by: 4ian <1280130+4ian@users.noreply.github.com>
2024-07-26 11:41:23 +02:00
D8H
864ba181e9 Improve a comment (#6800)
Don't show in changelog
2024-07-26 11:22:52 +02:00
D8H
10fa3296a9 Fix text input disabled/read only actions, as well as a few other actions (#6797) 2024-07-26 11:04:25 +02:00
AlexandreS
2fb39b9dbe Add tooltips on tilemap painting icons (#6798)
Don't show in changelog
2024-07-26 10:00:27 +02:00
Clément Pasteau
6f43e896d6 Bump version to 5.4.206 (#6796) 2024-07-25 18:06:10 +02:00
github-actions[bot]
122df05f99 Update translations [skip ci] (#6795)
Co-authored-by: D8H <2611977+D8H@users.noreply.github.com>
2024-07-25 18:05:36 +02:00
D8H
b7a5122b07 Add a variable editor for object groups (#6781) 2024-07-25 17:21:05 +02:00
Clément Pasteau
eb9d680d95 Instantly update lobby when a player leaves mid-game (#6794)
* Prevents seeing a player who has disconnected still in the lobby
2024-07-25 16:05:47 +02:00
github-actions[bot]
354da42a9e Update translations [skip ci] (#6791)
Co-authored-by: AlexandreSi <32449369+AlexandreSi@users.noreply.github.com>
2024-07-25 14:22:52 +02:00
AlexandreS
aca37fdade Fix tile set identifier computation (#6792)
Don't show in changelog
Also adds expressions to get tileset dimensions
2024-07-25 12:39:33 +02:00
Clément Pasteau
bb6eb01153 New condition for multiplayer games to know if a player is connected (#6790) 2024-07-25 09:49:07 +02:00
github-actions[bot]
9fb086dcdf Update translations [skip ci] (#6787)
Co-authored-by: D8H <2611977+D8H@users.noreply.github.com>
2024-07-24 18:48:20 +02:00
D8H
7e60a0246e Fix custom object getDrawableX/Y (#6789)
- Don't show in changelog
2024-07-24 17:48:00 +02:00
D8H
3cb2da3de5 Add autocompletion for parameter fields in events-based object events (#6770)
- Don't show in changelog
2024-07-24 17:23:20 +02:00
AlexandreS
ef23470a00 Add new object: (Integrated) TileMap (#6782)
This PR adds a new TileMap object that can be configured directly in GDevelop.

Import an atlas image, configure the tile size and start painting in the editor!
You can also configure which tiles should have a hit box and use them as platforms.
2024-07-24 17:06:13 +02:00
Clément Pasteau
196ea5e480 Fix multiplayer notifications (#6788)
Do not show in changelog
2024-07-24 15:14:53 +02:00
Clément Pasteau
e732f1952c Fix typo (#6786)
Do not show in changelog
2024-07-23 17:23:19 +02:00
github-actions[bot]
f5f024cc42 Update translations [skip ci] (#6784)
Co-authored-by: ClementPasteau <4895034+ClementPasteau@users.noreply.github.com>
2024-07-23 17:16:20 +02:00
Clément Pasteau
6a3df62598 Improve lobbies connections (#6762)
* Lobby start is now more reliable, and wait for everyone to be connected to the host to start the game, rather than wait on a fixed countdown. This can speed up the start (as well as slow it down on slower connections.)
  * A timeout is still in place to start the game without the missing players if they couldn't connect

* Lobbies can now be joined after the game is started, if defined as such in the lobbies section of the game dashboard
  * new actions & conditions are available

* Slightly improve disconnection time in preview
2024-07-23 16:13:50 +02:00
D8H
75f049d911 Show the top of the 1st page when the asset store search changes (#6765) 2024-07-22 16:17:50 +02:00
D8H
4d0ac6f355 Add icons for scenes and scene events (#6785)
- Don't show in changelog
2024-07-22 15:22:36 +02:00
D8H
00a5c93b35 Automatically rename identifiers in event-based objects (#6769)
- Don't show in changelog
2024-07-22 15:14:03 +02:00
D8H
a90cc83967 Add a dialog to choose between 2D and 3D when creating a custom object (#6776) 2024-07-22 14:43:50 +02:00
Aurélien Vivet
87a5934df3 Update the AdMob extension to support Play Services v23 (#6780) 2024-07-22 13:42:09 +02:00
github-actions[bot]
d0245b8f1a Update translations [skip ci] (#6774)
Co-authored-by: D8H <2611977+D8H@users.noreply.github.com>
2024-07-22 12:54:05 +02:00
D8H
45d73df6fb Fix initialization of local array variables (#6777) 2024-07-22 11:07:47 +02:00
AlexandreS
7ac600e92d Fix svg attrs (#6783)
Don't show in changelog
2024-07-22 10:31:50 +02:00
Aurélien Vivet
7ba8d0133e Declare shortcut CTRL+D to duplicate in object list (#6273)
Add duplicate shortcuts to objects list.
- Also applies the same shortcuts to the objects groups list.

---------

Co-authored-by: osmaneTKT <72160458+osmaneTKT@users.noreply.github.com>
2024-07-18 09:53:06 +02:00
D8H
e9adaa94c5 Remove unused imports (#6778)
Do not show in changelog
2024-07-17 10:24:36 +02:00
D8H
35da31c5c5 Add icons on tabs (#6771) 2024-07-16 14:44:11 +02:00
Aurélien Vivet
e65492e1a1 Translate properly the messages about a new update. (#6775) 2024-07-15 15:38:28 +02:00
AlexandreS
44827ea372 Fix errors when reading source files for autocompletions in JS events (#6773) 2024-07-15 11:01:24 +02:00
github-actions[bot]
ab3ffe6785 Update translations [skip ci] (#6759)
Co-authored-by: D8H <2611977+D8H@users.noreply.github.com>
2024-07-12 16:09:59 +02:00
D8H
d83d049ac9 Fix GDJS type declarations and tests (#6768)
- Don't show in changelog
2024-07-11 14:37:10 +02:00
Aurélien Vivet
67a7bd7af2 Remove dead code (#6767)
Only show in developer changelog
2024-07-11 14:13:55 +02:00
D8H
6db5267878 Allow to drag and drop custom object properties (#6766) 2024-07-11 14:11:24 +02:00
Florian Rival
a51c223c9c Add experimental, work-in-progress visual editor for custom objects (aka "prefabs"/"templates") (#6699)
* Still to do: 
  * Properly handle effects (disable 3D effects) for layers
  * Handle hot reloading properly
  * Avoid duplicating the configuration of the custom object inside each object created from it. Instead, only store the modified values.
  * Add a "Extract as a custom object ("prefab")" when selecting instances in a scene.
  * Add a dialog to give choice between 2D or 3D object when creating one.
  * Make sure "behavior shared data" are properly handled (physics, pathfinding...)
  * Check if we need to give an expression to translate coordinates from the parent to the local custom object.
  * Ensure a deleted custom object does not break the editor

Co-authored-by: Davy Hélard <davy.helard@gmail.com>
2024-07-11 11:27:34 +02:00
Arthur Pacaud (arthuro555)
0a4e5a1012 Add an action (#6191) 2024-07-10 22:48:22 +02:00
D8H
acce714736 Fix raycast test. (#6763)
Do not show in changelog
2024-07-10 14:53:37 +02:00
Florian Rival
3c34a8806b Fix message asking to check Apple/Google account for subscription not always shown (#6761)
- This was the case when the app was opened from https://editor.gdevelop.io?initial-dialog=subscription
2024-07-09 16:42:01 +02:00
Florian Rival
1d4cb7bef0 Fix checkbox to disable ads not displayed properly after being changed (#6760)
* Also address some part of the game dashboard that could be outdated after changes
2024-07-09 16:41:44 +02:00
Clément Pasteau
7badacd24a Fix not building peerjs for web runtime (#6758) 2024-07-09 12:06:10 +02:00
github-actions[bot]
11ab92fc0e Update translations [skip ci] (#6752)
Co-authored-by: D8H <2611977+D8H@users.noreply.github.com>
2024-07-09 10:02:32 +02:00
D8H
ddb1e335bc Improve raycast precision when the distance is 0 (#6757) 2024-07-08 14:51:29 +02:00
Tristan Rhodes
8d035a774d Add Star History to bottom of README (#6749) [skip ci] 2024-07-07 21:25:33 +02:00
Aurélien Vivet
5b1e3565d3 Remove dead code (TinyXml) (#6754)
Only show in developer changelog
2024-07-05 17:45:57 +02:00
Tristan Rhodes
8c88038bfb Added new condition to check the zoom of a camera of a layer (#6747) 2024-07-04 14:05:35 +02:00
D8H
f62811974d Remove an error about object name collision in object variable fields (#6751) 2024-07-04 12:56:25 +02:00
Florian Rival
b516037d2b Fix opening an example from a link or command line argument (#6750)
* An example opened from a link (typically, from the website) will now properly ask for the location where to save it, and will handle leaderboards and multiplayer.
2024-07-04 11:28:58 +02:00
474 changed files with 18045 additions and 11706 deletions

3
.gitattributes vendored
View File

@@ -1,12 +1,11 @@
Core/GDCore/Serialization/rapidjson/rapidjson.h/* linguist-vendored
Core/GDCore/TinyXml/* linguist-vendored
Extensions/ParticleSystem/SPARK/* linguist-vendored
Extensions/PhysicsBehavior/Box2D/* linguist-vendored
Extensions/PhysicsBehavior/box2djs/* linguist-vendored
Extensions/Physics2Behavior/box2d.js linguist-vendored
Extensions/BBText/pixi-multistyle-text/* linguist-vendored
Extensions/P2P/A_peer.js linguist-vendored
Extensions/Multiplayer/peer.js linguist-vendored
Extensions/Shopify/shopify-buy.umd.polyfilled.min.js linguist-vendored
Extensions/TileMap/pako/* linguist-vendored
Extensions/TileMap/pixi-tilemap/* linguist-vendored
Extensions/TweenBehavior/shifty.js linguist-vendored

View File

@@ -58,99 +58,7 @@
* Common functions and tools for programming.
*/
/**
* \defgroup TinyXml Integrated TinyXml library
*
* See the full documentation of TinyXml [here](http://www.grinninglizard.com/tinyxmldocs/index.html).
*/
/**
* \defgroup SpriteObjectExtension Standard Sprite Object extension
* \ingroup BuiltinExtensions
*/
/**
* \class TiXmlAttribute
* \brief Part of the tinyxml library
* \ingroup TinyXml
*/
/**
* \class TiXmlAttributeSet
* \brief Part of the tinyxml library
* \ingroup TinyXml
*/
/**
* \class TiXmlBase
* \brief Part of the tinyxml library
* \ingroup TinyXml
*/
/**
* \class TiXmlComment
* \brief Part of the tinyxml library
* \ingroup TinyXml
*/
/**
* \class TiXmlCursor
* \brief Part of the tinyxml library
* \ingroup TinyXml
*/
/**
* \class TiXmlDeclaration
* \brief Part of the tinyxml library
* \ingroup TinyXml
*/
/**
* \class TiXmlDocument
* \brief Part of the tinyxml library
* \ingroup TinyXml
*/
/**
* \class TiXmlElement
* \brief Part of the tinyxml library
* \ingroup TinyXml
*/
/**
* \class TiXmlHandle
* \brief Part of the tinyxml library
* \ingroup TinyXml
*/
/**
* \class TiXmlNode
* \brief Part of the tinyxml library
* \ingroup TinyXml
*/
/**
* \class TiXmlOutStream
* \brief Part of the tinyxml library
* \ingroup TinyXml
*/
/**
* \class TiXmlParsingData
* \brief Part of the tinyxml library
* \ingroup TinyXml
*/
/**
* \class TiXmlPrinter
* \brief Part of the tinyxml library
* \ingroup TinyXml
*/
/**
* \class TiXmlString
* \brief Part of the tinyxml library
* \ingroup TinyXml
*/
/**
* \class TiXmlText
* \brief Part of the tinyxml library
* \ingroup TinyXml
*/
/**
* \class TiXmlUnknown
* \brief Part of the tinyxml library
* \ingroup TinyXml
*/
/**
* \class TiXmlVisitor
* \brief Part of the tinyxml library
* \ingroup TinyXml
*/
*/

View File

@@ -8,7 +8,6 @@
#include "GDCore/Events/Serialization.h"
#include "GDCore/Events/Tools/EventsCodeNameMangler.h"
#include "GDCore/Serialization/SerializerElement.h"
#include "GDCore/TinyXml/tinyxml.h"
using namespace std;

View File

@@ -10,7 +10,6 @@
#include "GDCore/Events/CodeGeneration/EventsCodeGenerator.h"
#include "GDCore/Events/Serialization.h"
#include "GDCore/Serialization/SerializerElement.h"
#include "GDCore/TinyXml/tinyxml.h"
using namespace std;

View File

@@ -15,6 +15,7 @@
#include "GDCore/Project/Layout.h"
#include "GDCore/Project/Object.h"
#include "GDCore/Project/Project.h"
#include "GDCore/Project/EventsFunctionsExtension.h"
#include "GDCore/IDE/ProjectBrowserHelper.h"
namespace gd {
@@ -47,6 +48,9 @@ void EffectsCodeGenerator::GenerateEffectsIncludeFiles(
// TODO Merge with UsedExtensionsFinder.
// TODO Factorize with the iteration on all effects for resource exposure.
// TODO Implement an ArbitraryEffectWorker and add a method in ProjectBrowserHelper
// See also gd::Project::ExposeResources for a method that traverse the whole
// project (this time for resources) and
// WholeProjectRefactorer::ExposeProjectEvents.
@@ -68,6 +72,27 @@ void EffectsCodeGenerator::GenerateEffectsIncludeFiles(
// Add objects effects
gd::ProjectBrowserHelper::ExposeProjectObjects(project, effectsCodeGenerator);
// Add event-based objects layouts effects
for (std::size_t s = 0; s < project.GetEventsFunctionsExtensionsCount();
s++) {
auto &eventsFunctionExtension = project.GetEventsFunctionsExtension(s);
auto &eventsBasedObjects = eventsFunctionExtension.GetEventsBasedObjects();
for (std::size_t objectIndex = 0;
objectIndex < eventsBasedObjects.GetCount(); ++objectIndex) {
auto &eventsBasedObject = eventsBasedObjects.Get(objectIndex);
auto &layers = eventsBasedObject.GetLayers();
for (std::size_t l = 0; l < layers.GetLayersCount(); ++l) {
auto &effects = layers.GetLayer(l).GetEffects();
for (std::size_t e = 0; e < effects.GetEffectsCount(); ++e) {
auto &effect = effects.GetEffect(e);
effectsCodeGenerator.AddEffectIncludeFiles(effect);
}
}
}
}
}
} // namespace gd

View File

@@ -1179,8 +1179,13 @@ gd::String EventsCodeGenerator::GenerateFreeAction(
// Generate call
gd::String call;
if (instrInfos.codeExtraInformation.type == "number" ||
instrInfos.codeExtraInformation.type == "string" ||
instrInfos.codeExtraInformation.type == "boolean") {
instrInfos.codeExtraInformation.type == "string" ||
// Boolean actions declared with addExpressionAndConditionAndAction uses
// MutatorAndOrAccessor even though they don't declare an operator parameter.
// Boolean operators are only used with SetMutators or SetCustomCodeGenerator.
(instrInfos.codeExtraInformation.type == "boolean" &&
instrInfos.codeExtraInformation.accessType ==
gd::InstructionMetadata::ExtraInformation::AccessType::Mutators)) {
if (instrInfos.codeExtraInformation.accessType ==
gd::InstructionMetadata::ExtraInformation::MutatorAndOrAccessor)
call = GenerateOperatorCall(

View File

@@ -18,7 +18,6 @@ class BaseEvent;
namespace gd {
class SerializerElement;
}
class TiXmlElement;
#undef CreateEvent

View File

@@ -327,6 +327,25 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsCameraExtension(
.AddParameter("expression", _("Camera number (default : 0)"), "", true)
.SetDefaultValue("0");
extension
.AddCondition(
"CameraZoom",
_("Camera zoom"),
_("Compare the zoom of a camera of a layer."),
_("Zoom of camera _PARAM2_ of layer _PARAM1_"),
"",
"res/conditions/camera24.png",
"res/conditions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"), "", true)
.SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "", true)
.SetDefaultValue("0")
.UseStandardRelationalOperatorParameters(
"number", gd::ParameterOptions::MakeNewOptions().SetDescription(
_("Zoom")))
.MarkAsAdvanced();
extension
.AddAction(
"FixCamera",

View File

@@ -64,9 +64,7 @@ void SpriteObject::ExposeResources(gd::ArbitraryResourceWorker& worker) {
std::map<gd::String, gd::PropertyDescriptor>
SpriteObject::GetInitialInstanceProperties(
const gd::InitialInstance& initialInstance,
gd::Project& project,
gd::Layout& scene) {
const gd::InitialInstance& initialInstance) {
std::map<gd::String, gd::PropertyDescriptor> properties;
properties["animation"] =
gd::PropertyDescriptor(
@@ -80,9 +78,7 @@ SpriteObject::GetInitialInstanceProperties(
bool SpriteObject::UpdateInitialInstanceProperty(
gd::InitialInstance& initialInstance,
const gd::String& name,
const gd::String& value,
gd::Project& project,
gd::Layout& scene) {
const gd::String& value) {
if (name == "animation") {
initialInstance.SetRawDoubleProperty(
"animation", std::max(0, value.empty() ? 0 : value.To<int>()));

View File

@@ -47,14 +47,10 @@ class GD_CORE_API SpriteObject : public gd::ObjectConfiguration {
bool UpdateProperty(const gd::String& name, const gd::String& value) override;
std::map<gd::String, gd::PropertyDescriptor> GetInitialInstanceProperties(
const gd::InitialInstance& position,
gd::Project& project,
gd::Layout& scene) override;
const gd::InitialInstance& position) override;
bool UpdateInitialInstanceProperty(gd::InitialInstance& position,
const gd::String& name,
const gd::String& value,
gd::Project& project,
gd::Layout& scene) override;
const gd::String& value) override;
/**
* \brief Return the animation configuration.

View File

@@ -96,11 +96,11 @@ std::shared_ptr<gd::PlatformExtension> Platform::GetExtension(
std::unique_ptr<gd::ObjectConfiguration> Platform::CreateObjectConfiguration(
gd::String type) const {
if (creationFunctionTable.find(type) == creationFunctionTable.end()) {
gd::LogWarning("Tried to create an object with an unknown type: " + type
gd::LogWarning("Tried to create an object configuration with an unknown type: " + type
+ " for platform " + GetName() + "!");
type = "";
if (creationFunctionTable.find("") == creationFunctionTable.end()) {
gd::LogError("Unable to create a Base object!");
gd::LogFatalError("Unable to create a base object configuration!");
return nullptr;
}
}

View File

@@ -296,7 +296,7 @@ class GD_CORE_API ExpressionObjectFinder : public ExpressionParser2NodeWorker {
};
bool EventsRefactorer::RenameObjectInActions(const gd::Platform& platform,
gd::ProjectScopedContainers& projectScopedContainers,
const gd::ProjectScopedContainers& projectScopedContainers,
gd::InstructionsList& actions,
gd::String oldName,
gd::String newName) {
@@ -347,7 +347,7 @@ bool EventsRefactorer::RenameObjectInActions(const gd::Platform& platform,
bool EventsRefactorer::RenameObjectInConditions(
const gd::Platform& platform,
gd::ProjectScopedContainers& projectScopedContainers,
const gd::ProjectScopedContainers& projectScopedContainers,
gd::InstructionsList& conditions,
gd::String oldName,
gd::String newName) {
@@ -399,7 +399,7 @@ bool EventsRefactorer::RenameObjectInConditions(
bool EventsRefactorer::RenameObjectInEventParameters(
const gd::Platform& platform,
gd::ProjectScopedContainers& projectScopedContainers,
const gd::ProjectScopedContainers& projectScopedContainers,
gd::Expression& expression,
gd::ParameterMetadata parameterMetadata,
gd::String oldName,
@@ -432,7 +432,7 @@ bool EventsRefactorer::RenameObjectInEventParameters(
}
void EventsRefactorer::RenameObjectInEvents(const gd::Platform& platform,
gd::ProjectScopedContainers& projectScopedContainers,
const gd::ProjectScopedContainers& projectScopedContainers,
gd::EventsList& events,
gd::String oldName,
gd::String newName) {
@@ -475,7 +475,7 @@ void EventsRefactorer::RenameObjectInEvents(const gd::Platform& platform,
}
bool EventsRefactorer::RemoveObjectInActions(const gd::Platform& platform,
gd::ProjectScopedContainers& projectScopedContainers,
const gd::ProjectScopedContainers& projectScopedContainers,
gd::InstructionsList& actions,
gd::String name) {
bool somethingModified = false;
@@ -532,7 +532,7 @@ bool EventsRefactorer::RemoveObjectInActions(const gd::Platform& platform,
bool EventsRefactorer::RemoveObjectInConditions(
const gd::Platform& platform,
gd::ProjectScopedContainers& projectScopedContainers,
const gd::ProjectScopedContainers& projectScopedContainers,
gd::InstructionsList& conditions,
gd::String name) {
bool somethingModified = false;

View File

@@ -3,8 +3,8 @@
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#ifndef GDCORE_EVENTSREFACTORER_H
#define GDCORE_EVENTSREFACTORER_H
#pragma once
#include <memory>
#include <vector>
@@ -81,7 +81,7 @@ class GD_CORE_API EventsRefactorer {
* events ).
*/
static void RenameObjectInEvents(const gd::Platform& platform,
gd::ProjectScopedContainers& projectScopedContainers,
const gd::ProjectScopedContainers& projectScopedContainers,
gd::EventsList& events,
gd::String oldName,
gd::String newName);
@@ -128,7 +128,7 @@ class GD_CORE_API EventsRefactorer {
* \return true if something was modified.
*/
static bool RenameObjectInActions(const gd::Platform& platform,
gd::ProjectScopedContainers& projectScopedContainers,
const gd::ProjectScopedContainers& projectScopedContainers,
gd::InstructionsList& instructions,
gd::String oldName,
gd::String newName);
@@ -140,7 +140,7 @@ class GD_CORE_API EventsRefactorer {
* \return true if something was modified.
*/
static bool RenameObjectInConditions(const gd::Platform& platform,
gd::ProjectScopedContainers& projectScopedContainers,
const gd::ProjectScopedContainers& projectScopedContainers,
gd::InstructionsList& instructions,
gd::String oldName,
gd::String newName);
@@ -153,7 +153,7 @@ class GD_CORE_API EventsRefactorer {
*/
static bool RenameObjectInEventParameters(
const gd::Platform& platform,
gd::ProjectScopedContainers& projectScopedContainers,
const gd::ProjectScopedContainers& projectScopedContainers,
gd::Expression& expression,
gd::ParameterMetadata parameterMetadata,
gd::String oldName,
@@ -165,7 +165,7 @@ class GD_CORE_API EventsRefactorer {
* \return true if something was modified.
*/
static bool RemoveObjectInConditions(const gd::Platform& platform,
gd::ProjectScopedContainers& projectScopedContainers,
const gd::ProjectScopedContainers& projectScopedContainers,
gd::InstructionsList& conditions,
gd::String name);
@@ -175,7 +175,7 @@ class GD_CORE_API EventsRefactorer {
* \return true if something was modified.
*/
static bool RemoveObjectInActions(const gd::Platform& platform,
gd::ProjectScopedContainers& projectScopedContainers,
const gd::ProjectScopedContainers& projectScopedContainers,
gd::InstructionsList& conditions,
gd::String name);
@@ -242,5 +242,3 @@ class GD_CORE_API EventsRefactorer {
};
} // namespace gd
#endif // GDCORE_EVENTSREFACTORER_H

View File

@@ -31,6 +31,8 @@
namespace gd {
VariablesContainer EventsVariableInstructionTypeSwitcher::nullVariablesContainer;
bool EventsVariableInstructionTypeSwitcher::DoVisitInstruction(gd::Instruction& instruction,
bool isCondition) {
const auto& metadata = isCondition
@@ -82,7 +84,8 @@ bool EventsVariableInstructionTypeSwitcher::DoVisitInstruction(gd::Instruction&
// Every occurrence of the variable or its children are checked.
// Ensuring that a child is actually the one with a type change would
// take more time.
if (variablesContainer == &targetVariablesContainer) {
if (variablesContainer == &targetVariablesContainer ||
lastObjectName == groupName) {
if (typeChangedVariableNames.find(variableName) !=
typeChangedVariableNames.end()) {
gd::VariableInstructionSwitcher::

View File

@@ -17,7 +17,7 @@
namespace gd {
class VariablesContainer;
class Platform;
} // namespace gd
} // namespace gd
namespace gd {
/**
@@ -33,21 +33,36 @@ class GD_CORE_API EventsVariableInstructionTypeSwitcher
public:
EventsVariableInstructionTypeSwitcher(
const gd::Platform &platform_,
const gd::VariablesContainer &targetVariablesContainer_,
const std::unordered_set<gd::String> &typeChangedVariableNames_)
const std::unordered_set<gd::String> &typeChangedVariableNames_,
const gd::VariablesContainer &targetVariablesContainer_)
: platform(platform_),
targetVariablesContainer(targetVariablesContainer_),
typeChangedVariableNames(typeChangedVariableNames_){};
typeChangedVariableNames(typeChangedVariableNames_),
targetVariablesContainer(targetVariablesContainer_), groupName(""){};
EventsVariableInstructionTypeSwitcher(
const gd::Platform &platform_,
const std::unordered_set<gd::String> &typeChangedVariableNames_,
const gd::String &groupName_)
: platform(platform_),
typeChangedVariableNames(typeChangedVariableNames_),
targetVariablesContainer(nullVariablesContainer),
groupName(groupName_){};
virtual ~EventsVariableInstructionTypeSwitcher();
private:
private:
bool DoVisitInstruction(gd::Instruction &instruction,
bool isCondition) override;
const gd::Platform &platform;
const gd::VariablesContainer &targetVariablesContainer;
gd::String objectName;
/**
* Groups don't have VariablesContainer, so `targetVariablesContainer` will be
* pointing to `nullVariablesContainer` and the group name is use instead to
* check which instruction to modify.
*/
const gd::String groupName;
const std::unordered_set<gd::String> &typeChangedVariableNames;
static VariablesContainer nullVariablesContainer;
};
} // namespace gd

View File

@@ -32,6 +32,8 @@
namespace gd {
VariablesContainer EventsVariableReplacer::nullVariablesContainer;
/**
* \brief Go through the nodes and rename variables,
* or signal if the instruction must be renamed if a removed variable is used.
@@ -44,22 +46,26 @@ class GD_CORE_API ExpressionVariableReplacer
ExpressionVariableReplacer(
const gd::Platform& platform_,
const gd::ProjectScopedContainers& projectScopedContainers_,
const gd::VariablesContainer& targetVariablesContainer_,
const VariablesRenamingChangesetNode& variablesRenamingChangesetRoot_,
const std::unordered_set<gd::String>& removedVariableNames_)
const std::unordered_set<gd::String>& removedVariableNames_,
const gd::VariablesContainer& targetVariablesContainer_,
const gd::String &groupName_,
const gd::String &forcedInitialObjectName)
: hasDoneRenaming(false),
removedVariableUsed(false),
platform(platform_),
projectScopedContainers(projectScopedContainers_),
forcedInitialVariablesContainer(nullptr),
targetVariablesContainer(targetVariablesContainer_),
forcedVariablesContainer(nullptr),
forcedObjectName(forcedInitialObjectName),
variablesRenamingChangesetRoot(variablesRenamingChangesetRoot_),
removedVariableNames(removedVariableNames_){};
removedVariableNames(removedVariableNames_),
targetVariablesContainer(targetVariablesContainer_),
targetGroupName(groupName_){};
virtual ~ExpressionVariableReplacer(){};
void SetForcedInitialVariablesContainer(
const gd::VariablesContainer* forcedInitialVariablesContainer_) {
forcedInitialVariablesContainer = forcedInitialVariablesContainer_;
forcedVariablesContainer = forcedInitialVariablesContainer_;
}
bool HasDoneRenaming() const { return hasDoneRenaming; }
@@ -82,12 +88,13 @@ class GD_CORE_API ExpressionVariableReplacer
// The node represents a variable or an object name on which a variable
// will be accessed.
if (forcedInitialVariablesContainer) {
if (forcedVariablesContainer) {
const gd::String oldVariableName = node.name;
PushVariablesRenamingChangesetRoot();
// A scope was forced. Honor it: it means this node represents a variable
// of the forced variables container.
if (forcedInitialVariablesContainer == &targetVariablesContainer) {
if (forcedVariablesContainer == &targetVariablesContainer ||
IsTargetingObjectGroup(forcedObjectName)) {
RenameOrRemoveVariableOfTargetVariableContainer(node.name);
}
@@ -150,7 +157,8 @@ class GD_CORE_API ExpressionVariableReplacer
// This is always true because MatchIdentifierWithName is used to get
// objectNameToUseForVariableAccessor.
if (objectsContainersList.HasObjectOrGroupVariablesContainer(
objectNameToUseForVariableAccessor, targetVariablesContainer)) {
objectNameToUseForVariableAccessor, targetVariablesContainer) ||
IsTargetingObjectGroup(objectNameToUseForVariableAccessor)) {
objectNameToUseForVariableAccessor = "";
// The node represents an object variable, and this object variables are
// the target. Do the replacement or removals:
@@ -197,10 +205,11 @@ class GD_CORE_API ExpressionVariableReplacer
// (and if it's a variable reference or a value does not have any importance
// here).
if (forcedInitialVariablesContainer) {
if (forcedVariablesContainer) {
// A scope was forced. Honor it: it means this node represents a variable
// of the forced variables container.
if (forcedInitialVariablesContainer == &targetVariablesContainer) {
if (forcedVariablesContainer == &targetVariablesContainer ||
IsTargetingObjectGroup(forcedObjectName)) {
renameVariableAndChild();
}
return;
@@ -213,7 +222,8 @@ class GD_CORE_API ExpressionVariableReplacer
[&]() {
// This represents an object.
if (objectsContainersList.HasObjectOrGroupVariablesContainer(
node.identifierName, targetVariablesContainer)) {
node.identifierName, targetVariablesContainer) ||
IsTargetingObjectGroup(node.identifierName)) {
// The node represents an object variable, and this object variables
// are the target. Do the replacement or removals:
PushVariablesRenamingChangesetRoot();
@@ -261,31 +271,33 @@ class GD_CORE_API ExpressionVariableReplacer
// force the "scope" at which starts the evalution of variables.
if (parameterMetadata && parameterMetadata->GetValueTypeMetadata()
.IsLegacyPreScopedVariable()) {
const gd::VariablesContainer* oldForcedInitialVariablesContainer =
forcedInitialVariablesContainer;
const gd::VariablesContainer *oldForcedVariablesContainer =
forcedVariablesContainer;
const gd::String &oldForcedObjectName = forcedObjectName;
forcedInitialVariablesContainer = nullptr;
forcedVariablesContainer = nullptr;
forcedObjectName = "";
if (parameterMetadata->GetType() == "globalvar") {
forcedInitialVariablesContainer =
forcedVariablesContainer =
projectScopedContainers.GetVariablesContainersList()
.GetTopMostVariablesContainer();
} else if (parameterMetadata->GetType() == "scenevar") {
forcedInitialVariablesContainer =
forcedVariablesContainer =
projectScopedContainers.GetVariablesContainersList()
.GetBottomMostVariablesContainer();
} else if (parameterMetadata->GetType() == "objectvar") {
auto objectName = gd::ExpressionVariableOwnerFinder::GetObjectName(
platform,
projectScopedContainers.GetObjectsContainersList(),
node.objectName,
*node.parameters[parameterIndex].get());
forcedInitialVariablesContainer =
platform, projectScopedContainers.GetObjectsContainersList(),
node.objectName, *node.parameters[parameterIndex].get());
forcedVariablesContainer =
projectScopedContainers.GetObjectsContainersList()
.GetObjectOrGroupVariablesContainer(objectName);
forcedObjectName = objectName;
}
node.parameters[parameterIndex]->Visit(*this);
forcedInitialVariablesContainer = oldForcedInitialVariablesContainer;
forcedVariablesContainer = oldForcedVariablesContainer;
forcedObjectName = oldForcedObjectName;
} else {
// For any other parameter, there is no special treatment being needed.
node.parameters[parameterIndex]->Visit(*this);
@@ -298,6 +310,10 @@ class GD_CORE_API ExpressionVariableReplacer
bool hasDoneRenaming;
bool removedVariableUsed;
bool IsTargetingObjectGroup(const gd::String &objectGroupName) {
return !targetGroupName.empty() && objectGroupName == targetGroupName;
}
bool RenameOrRemoveVariableOfTargetVariableContainer(
gd::String& variableName) {
const auto *currentVariablesRenamingChangesetNode =
@@ -382,10 +398,17 @@ class GD_CORE_API ExpressionVariableReplacer
// Scope:
const gd::Platform& platform;
const gd::ProjectScopedContainers& projectScopedContainers;
const gd::VariablesContainer* forcedInitialVariablesContainer;
const gd::VariablesContainer* forcedVariablesContainer;
gd::String forcedObjectName;
// Renaming or removing to do:
const gd::VariablesContainer& targetVariablesContainer;
/**
* Groups don't have VariablesContainer, so `targetVariablesContainer` will be
* pointing to `nullVariablesContainer` and the group name is use instead to
* check which variable accesses to modify in expressions.
*/
const gd::String& targetGroupName;
const VariablesRenamingChangesetNode &variablesRenamingChangesetRoot;
const std::unordered_set<gd::String>& removedVariableNames;
@@ -397,7 +420,7 @@ const gd::VariablesContainer*
EventsVariableReplacer::FindForcedVariablesContainerIfAny(
const gd::String& type, const gd::String& lastObjectName) {
// Handle legacy pre-scoped variable parameters: in this case, we
// force the "scope" at which starts the evalution of variables.
// force the "scope" at which starts the evaluation of variables.
if (type == "objectvar") {
return GetProjectScopedContainers()
.GetObjectsContainersList()
@@ -442,9 +465,11 @@ bool EventsVariableReplacer::DoVisitInstruction(gd::Instruction& instruction,
if (node) {
ExpressionVariableReplacer renamer(platform,
GetProjectScopedContainers(),
targetVariablesContainer,
variablesRenamingChangesetRoot,
removedVariableNames);
removedVariableNames,
targetVariablesContainer,
targetGroupName,
type == "objectvar" ? lastObjectName : "");
renamer.SetForcedInitialVariablesContainer(
FindForcedVariablesContainerIfAny(type, lastObjectName));
node->Visit(renamer);
@@ -474,9 +499,11 @@ bool EventsVariableReplacer::DoVisitEventExpression(
if (node) {
ExpressionVariableReplacer renamer(platform,
GetProjectScopedContainers(),
targetVariablesContainer,
variablesRenamingChangesetRoot,
removedVariableNames);
removedVariableNames,
targetVariablesContainer,
targetGroupName,
"");
renamer.SetForcedInitialVariablesContainer(
FindForcedVariablesContainerIfAny(type, ""));
node->Visit(renamer);

View File

@@ -35,13 +35,24 @@ class GD_CORE_API EventsVariableReplacer
public:
EventsVariableReplacer(
const gd::Platform &platform_,
const gd::VariablesContainer &targetVariablesContainer_,
const VariablesRenamingChangesetNode &variablesRenamingChangesetRoot_,
const std::unordered_set<gd::String> &removedVariableNames_)
const std::unordered_set<gd::String> &removedVariableNames_,
const gd::VariablesContainer &targetVariablesContainer_)
: platform(platform_),
targetVariablesContainer(targetVariablesContainer_),
variablesRenamingChangesetRoot(variablesRenamingChangesetRoot_),
removedVariableNames(removedVariableNames_) {};
removedVariableNames(removedVariableNames_),
targetVariablesContainer(targetVariablesContainer_),
targetGroupName("") {};
EventsVariableReplacer(
const gd::Platform &platform_,
const VariablesRenamingChangesetNode &variablesRenamingChangesetRoot_,
const std::unordered_set<gd::String> &removedVariableNames_,
const gd::String &targetGroupName_)
: platform(platform_),
variablesRenamingChangesetRoot(variablesRenamingChangesetRoot_),
removedVariableNames(removedVariableNames_),
targetVariablesContainer(nullVariablesContainer),
targetGroupName(targetGroupName_) {};
virtual ~EventsVariableReplacer();
private:
@@ -55,9 +66,16 @@ class GD_CORE_API EventsVariableReplacer
const gd::Platform &platform;
const gd::VariablesContainer &targetVariablesContainer;
gd::String objectName;
/**
* Groups don't have VariablesContainer, so `targetVariablesContainer` will be
* pointing to `nullVariablesContainer` and the group name is use instead to
* check which variable accesses to modify in expressions.
*/
const gd::String targetGroupName;
const VariablesRenamingChangesetNode &variablesRenamingChangesetRoot;
const std::unordered_set<gd::String> &removedVariableNames;
static VariablesContainer nullVariablesContainer;
};
} // namespace gd

View File

@@ -92,17 +92,30 @@ void EventsFunctionTools::ObjectEventsFunctionToObjectsContainer(
"its parameters).");
return;
}
if (eventsBasedObject.HasObjectNamed("Object")) {
if (eventsBasedObject.GetObjects().HasObjectNamed("Object")) {
gd::LogWarning("Child-objects can't be named Object because it's reserved"
"for the parent. ");
return;
}
// ...and its children.
auto &children = eventsBasedObject.GetObjects();
gd::EventsFunctionTools::CopyEventsBasedObjectChildrenToObjectsContainer(
eventsBasedObject, outputObjectsContainer);
}
void EventsFunctionTools::CopyEventsBasedObjectChildrenToObjectsContainer(
const gd::EventsBasedObject& eventsBasedObject,
gd::ObjectsContainer& outputObjectsContainer) {
auto &children = eventsBasedObject.GetObjects().GetObjects();
for (auto &childObject : children) {
auto child = childObject.get();
outputObjectsContainer.InsertObject(*child, children.size());
outputObjectsContainer.InsertObject(
*child, outputObjectsContainer.GetObjectsCount());
}
auto &childrenGroups = eventsBasedObject.GetObjects().GetObjectGroups();
for (size_t index = 0; index < childrenGroups.Count(); ++index) {
auto &childGroup = childrenGroups.Get(index);
outputObjectsContainer.GetObjectGroups().Insert(
childGroup, outputObjectsContainer.GetObjectGroups().Count());
}
}

View File

@@ -68,5 +68,9 @@ class GD_CORE_API EventsFunctionTools {
const gd::EventsBasedObject& eventsBasedObject,
const gd::EventsFunction& eventsFunction,
gd::ObjectsContainer& outputObjectsContainer);
static void CopyEventsBasedObjectChildrenToObjectsContainer(
const gd::EventsBasedObject &eventsBasedObject,
gd::ObjectsContainer &outputObjectsContainer);
};
} // namespace gd

View File

@@ -0,0 +1,185 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "GroupVariableHelper.h"
#include "GDCore/IDE/WholeProjectRefactorer.h"
#include "GDCore/Project/Object.h"
#include "GDCore/Project/ObjectGroup.h"
#include "GDCore/Project/ObjectsContainer.h"
#include "GDCore/Project/ObjectsContainersList.h"
#include "GDCore/Project/Variable.h"
#include "GDCore/Project/VariablesContainer.h"
#include "GDCore/String.h"
namespace gd {
void GroupVariableHelper::FillAnyVariableBetweenObjects(
gd::ObjectsContainer &globalObjectsContainer,
gd::ObjectsContainer &objectsContainer,
const gd::ObjectGroup &objectGroup) {
const auto &objectNames = objectGroup.GetAllObjectsNames();
for (const gd::String &sourceObjectName : objectNames) {
const bool hasObject = objectsContainer.HasObjectNamed(sourceObjectName);
if (!hasObject &&
!globalObjectsContainer.HasObjectNamed(sourceObjectName)) {
continue;
}
const auto &sourceObject =
hasObject ? objectsContainer.GetObject(sourceObjectName)
: globalObjectsContainer.GetObject(sourceObjectName);
const auto &sourceVariablesContainer = sourceObject.GetVariables();
for (const gd::String &destinationObjectName : objectNames) {
if (sourceObjectName == destinationObjectName) {
continue;
}
const bool hasObject =
objectsContainer.HasObjectNamed(destinationObjectName);
if (!hasObject &&
!globalObjectsContainer.HasObjectNamed(destinationObjectName)) {
continue;
}
auto &destinationObject =
hasObject ? objectsContainer.GetObject(destinationObjectName)
: globalObjectsContainer.GetObject(destinationObjectName);
auto &destinationVariablesContainer = destinationObject.GetVariables();
for (std::size_t sourceVariableIndex = 0;
sourceVariableIndex < sourceVariablesContainer.Count();
++sourceVariableIndex) {
auto &sourceVariable =
sourceVariablesContainer.Get(sourceVariableIndex);
const auto &variableName =
sourceVariablesContainer.GetNameAt(sourceVariableIndex);
if (!destinationVariablesContainer.Has(variableName)) {
destinationVariablesContainer.Insert(
variableName, sourceVariable,
destinationVariablesContainer.Count());
}
}
}
}
}
gd::VariablesContainer GroupVariableHelper::MergeVariableContainers(
const gd::ObjectsContainersList &objectsContainersList,
const gd::ObjectGroup &objectGroup) {
gd::VariablesContainer mergedVariablesContainer;
const auto &objectNames = objectGroup.GetAllObjectsNames();
std::size_t objectIndex = 0;
bool isFirstObjectFound = false;
for (; objectIndex < objectNames.size() && !isFirstObjectFound;
objectIndex++) {
const gd::String &objectName = objectNames[objectIndex];
if (!objectsContainersList.HasObjectOrGroupNamed(objectName)) {
continue;
}
isFirstObjectFound = true;
mergedVariablesContainer =
*objectsContainersList.GetObjectOrGroupVariablesContainer(objectName);
}
for (; objectIndex < objectNames.size(); objectIndex++) {
const gd::String &objectName = objectNames[objectIndex];
if (!objectsContainersList.HasObjectOrGroupNamed(objectName)) {
continue;
}
const auto &variablesContainer =
*objectsContainersList.GetObjectOrGroupVariablesContainer(objectName);
for (std::size_t variableIndex = 0;
variableIndex < mergedVariablesContainer.Count(); ++variableIndex) {
auto &mergedVariable = mergedVariablesContainer.Get(variableIndex);
const auto &variableName =
mergedVariablesContainer.GetNameAt(variableIndex);
if (variablesContainer.Has(variableName)) {
auto &variable = variablesContainer.Get(variableName);
if (mergedVariable.GetType() != variable.GetType()) {
mergedVariable.CastTo(gd::Variable::Type::MixedTypes);
} else if (mergedVariable != variable) {
mergedVariable.MarkAsMixedValues();
}
} else {
mergedVariablesContainer.Remove(variableName);
variableIndex--;
}
}
}
return mergedVariablesContainer;
}
void GroupVariableHelper::FillMissingGroupVariablesToObjects(
gd::ObjectsContainer &globalObjectsContainer,
gd::ObjectsContainer &objectsContainer, const gd::ObjectGroup &objectGroup,
const gd::SerializerElement &originalSerializedVariables) {
gd::VariablesContainer groupVariablesContainer;
groupVariablesContainer.UnserializeFrom(originalSerializedVariables);
// Add missing variables to objects added in the group.
for (const gd::String &objectName : objectGroup.GetAllObjectsNames()) {
const bool hasObject = objectsContainer.HasObjectNamed(objectName);
if (!hasObject && !globalObjectsContainer.HasObjectNamed(objectName)) {
continue;
}
auto &object = hasObject ? objectsContainer.GetObject(objectName)
: globalObjectsContainer.GetObject(objectName);
auto &variablesContainer = object.GetVariables();
for (std::size_t variableIndex = 0;
variableIndex < groupVariablesContainer.Count(); ++variableIndex) {
auto &groupVariable = groupVariablesContainer.Get(variableIndex);
const auto &variableName =
groupVariablesContainer.GetNameAt(variableIndex);
if (!variablesContainer.Has(variableName)) {
variablesContainer.Insert(variableName, groupVariable,
variablesContainer.Count());
}
}
}
};
// TODO Handle position changes for group variables.
// We could try to change the order of object variables in a way that the next
// call to MergeVariableContainers rebuild them in the same order.
void GroupVariableHelper::ApplyChangesToObjects(
gd::ObjectsContainer &globalObjectsContainer,
gd::ObjectsContainer &objectsContainer,
const gd::VariablesContainer &groupVariablesContainer,
const gd::ObjectGroup &objectGroup,
const gd::VariablesChangeset &changeset) {
for (const gd::String &objectName : objectGroup.GetAllObjectsNames()) {
const bool hasObject = objectsContainer.HasObjectNamed(objectName);
if (!hasObject && !globalObjectsContainer.HasObjectNamed(objectName)) {
continue;
}
auto &object = hasObject ? objectsContainer.GetObject(objectName)
: globalObjectsContainer.GetObject(objectName);
auto &variablesContainer = object.GetVariables();
for (const gd::String &variableName : changeset.removedVariableNames) {
variablesContainer.Remove(variableName);
}
for (const gd::String &variableName : changeset.addedVariableNames) {
variablesContainer.Insert(variableName,
groupVariablesContainer.Get(variableName),
variablesContainer.Count());
}
for (const auto &pair : changeset.oldToNewVariableNames) {
const gd::String &oldVariableName = pair.first;
const gd::String &newVariableName = pair.second;
variablesContainer.Rename(oldVariableName, newVariableName);
}
// Apply type and value changes
for (const gd::String &variableName : changeset.valueChangedVariableNames) {
size_t index = variablesContainer.GetPosition(variableName);
variablesContainer.Remove(variableName);
variablesContainer.Insert(
variableName, groupVariablesContainer.Get(variableName), index);
}
}
}
} // namespace gd

View File

@@ -0,0 +1,75 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#pragma once
#include "GDCore/Project/VariablesContainer.h"
namespace gd {
class ObjectsContainersList;
class ObjectsContainer;
class ObjectGroup;
class VariablesContainer;
struct VariablesChangeset;
} // namespace gd
namespace gd {
/**
* Help handling variables of group objects as a whole.
*
* This is used by the object group variable editor.
*/
class GD_CORE_API GroupVariableHelper {
public:
/**
* Copy every variable from every object of the group to the other objects
* if they don't have it already.
*
* In the editor, when an object group is created, users can choose between:
* - doing no change and only see variables that are already shared by any
* objects of the group
* - applying this function and see every variable
*/
static void
FillAnyVariableBetweenObjects(gd::ObjectsContainer &globalObjectsContainer,
gd::ObjectsContainer &objectsContainer,
const gd::ObjectGroup &objectGroup);
/**
* Build a variable container with the intersection of variables from the
* every objects of the given group.
*/
static gd::VariablesContainer MergeVariableContainers(
const gd::ObjectsContainersList &objectsContainersList,
const gd::ObjectGroup &objectGroup);
/**
* @brief Copy the variables of the group to all objects.
*
* Objects can be added during the group edition and may not necessarily have
* all the variables initially shared by the group.
*
* \see gd::GroupVariableHelper::MergeVariableContainers
*/
static void FillMissingGroupVariablesToObjects(
gd::ObjectsContainer &globalObjectsContainer,
gd::ObjectsContainer &objectsContainer,
const gd::ObjectGroup &objectGroup,
const gd::SerializerElement &originalSerializedVariables);
/**
* @brief Apply the changes done with the variables editor to the objects of
* the group.
*/
static void
ApplyChangesToObjects(gd::ObjectsContainer &globalObjectsContainers,
gd::ObjectsContainer &objectsContainers,
const gd::VariablesContainer &groupVariablesContainer,
const gd::ObjectGroup &objectGroup,
const gd::VariablesChangeset &changeset);
};
} // namespace gd

View File

@@ -0,0 +1,41 @@
/*
* GDevelop JS Platform
* Copyright 2008-2023 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "EventsBasedObjectDependencyFinder.h"
#include "GDCore/Project/EventsBasedObject.h"
#include "GDCore/Project/Object.h"
#include "GDCore/Project/Project.h"
namespace gd {
bool EventsBasedObjectDependencyFinder::IsDependentFromEventsBasedObject(
const gd::Project &project, const gd::EventsBasedObject &eventsBasedObject,
const gd::EventsBasedObject &dependency) {
return gd::EventsBasedObjectDependencyFinder::
IsDependentFromEventsBasedObject(project, eventsBasedObject, dependency,
0);
}
bool EventsBasedObjectDependencyFinder::IsDependentFromEventsBasedObject(
const gd::Project &project, const gd::EventsBasedObject &eventsBasedObject,
const gd::EventsBasedObject &dependency, int depth) {
if (&eventsBasedObject == &dependency) {
return true;
}
if (depth > 200) {
return false;
}
for (auto &object : eventsBasedObject.GetObjects().GetObjects()) {
const gd::String &objectType = object->GetType();
if (project.HasEventsBasedObject(objectType) &&
gd::EventsBasedObjectDependencyFinder::IsDependentFromEventsBasedObject(
project, project.GetEventsBasedObject(objectType), dependency,
depth + 1)) {
return true;
}
}
return false;
}
} // namespace gd

View File

@@ -0,0 +1,37 @@
/*
* GDevelop JS Platform
* Copyright 2008-2023 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#pragma once
#include "GDCore/String.h"
namespace gd {
class Project;
class EventsBasedObject;
} // namespace gd
namespace gd {
/**
* \brief Find resource usages in several parts of the project.
*
* \ingroup IDE
*/
class EventsBasedObjectDependencyFinder {
public:
static bool IsDependentFromEventsBasedObject(
const gd::Project &project,
const gd::EventsBasedObject &eventsBasedObject,
const gd::EventsBasedObject &dependency);
private:
static bool IsDependentFromEventsBasedObject(
const gd::Project &project,
const gd::EventsBasedObject &eventsBasedObject,
const gd::EventsBasedObject &dependency, int depth);
};
} // namespace gd

View File

@@ -250,7 +250,7 @@ void ProjectBrowserHelper::ExposeProjectObjects(
gd::Project &project, gd::ArbitraryObjectsWorker &worker) {
// Global objects
worker.Launch(project);
worker.Launch(project.GetObjects());
// Layout objects
for (size_t i = 0; i < project.GetLayoutsCount(); i++) {
@@ -265,7 +265,7 @@ void ProjectBrowserHelper::ExposeProjectObjects(
for (auto &&eventsBasedObjectUniquePtr :
eventsFunctionsExtension.GetEventsBasedObjects().GetInternalVector()) {
auto eventsBasedObject = eventsBasedObjectUniquePtr.get();
worker.Launch(*eventsBasedObject);
worker.Launch(eventsBasedObject->GetObjects());
}
}
};
@@ -275,7 +275,7 @@ void ProjectBrowserHelper::ExposeLayoutObjects(gd::Layout &layout,
// In the future, layouts may have children object containers.
// Layout objects
worker.Launch(layout);
worker.Launch(layout.GetObjects());
}
void ProjectBrowserHelper::ExposeProjectFunctions(

View File

@@ -17,7 +17,7 @@
namespace gd {
void GD_CORE_API ProjectStripper::StripProjectForExport(gd::Project &project) {
project.GetObjectGroups().Clear();
project.GetObjects().GetObjectGroups().Clear();
while (project.GetExternalEventsCount() > 0)
project.RemoveExternalEvents(project.GetExternalEvents(0).GetName());
@@ -26,7 +26,7 @@ void GD_CORE_API ProjectStripper::StripProjectForExport(gd::Project &project) {
wholeProjectBrowser.ExposeObjects(project, behaviorDefaultFlagClearer);
for (unsigned int i = 0; i < project.GetLayoutsCount(); ++i) {
project.GetLayout(i).GetObjectGroups().Clear();
project.GetLayout(i).GetObjects().GetObjectGroups().Clear();
project.GetLayout(i).GetEvents().Clear();
}

View File

@@ -76,7 +76,7 @@ void ResourceExposer::ExposeWholeProjectResources(gd::Project& project, gd::Arbi
void ResourceExposer::ExposeProjectResources(gd::Project& project, gd::ArbitraryResourceWorker& worker) {
// Expose global objects configuration resources
auto objectWorker = gd::GetResourceWorkerOnObjects(project, worker);
objectWorker.Launch(project);
objectWorker.Launch(project.GetObjects());
}
void ResourceExposer::ExposeLayoutResources(

View File

@@ -11,22 +11,23 @@
#include "GDCore/Extensions/Metadata/MetadataProvider.h"
#include "GDCore/Extensions/PlatformExtension.h"
#include "GDCore/IDE/DependenciesAnalyzer.h"
#include "GDCore/IDE/GroupVariableHelper.h"
#include "GDCore/IDE/EventBasedBehaviorBrowser.h"
#include "GDCore/IDE/Events/ArbitraryEventsWorker.h"
#include "GDCore/IDE/Events/BehaviorParametersFiller.h"
#include "GDCore/IDE/Events/BehaviorTypeRenamer.h"
#include "GDCore/IDE/Events/CustomObjectTypeRenamer.h"
#include "GDCore/IDE/Events/EventsBehaviorRenamer.h"
#include "GDCore/IDE/Events/EventsPropertyReplacer.h"
#include "GDCore/IDE/Events/EventsRefactorer.h"
#include "GDCore/IDE/Events/EventsVariableReplacer.h"
#include "GDCore/IDE/Events/EventsVariableInstructionTypeSwitcher.h"
#include "GDCore/IDE/Events/EventsVariableReplacer.h"
#include "GDCore/IDE/Events/ExpressionsParameterMover.h"
#include "GDCore/IDE/Events/ExpressionsRenamer.h"
#include "GDCore/IDE/Events/InstructionsParameterMover.h"
#include "GDCore/IDE/Events/InstructionsTypeRenamer.h"
#include "GDCore/IDE/Events/LinkEventTargetRenamer.h"
#include "GDCore/IDE/Events/ProjectElementRenamer.h"
#include "GDCore/IDE/Events/BehaviorParametersFiller.h"
#include "GDCore/IDE/EventsFunctionTools.h"
#include "GDCore/IDE/Project/ArbitraryBehaviorSharedDataWorker.h"
#include "GDCore/IDE/Project/ArbitraryEventBasedBehaviorsWorker.h"
@@ -86,10 +87,10 @@ WholeProjectRefactorer::GetAllObjectTypesUsingEventsBasedBehavior(
}
};
addTypesOfObjectsIn(project);
addTypesOfObjectsIn(project.GetObjects());
for (std::size_t s = 0; s < project.GetLayoutsCount(); s++) {
auto &layout = project.GetLayout(s);
addTypesOfObjectsIn(layout);
addTypesOfObjectsIn(layout.GetObjects());
}
return allTypes;
@@ -173,6 +174,7 @@ WholeProjectRefactorer::ComputeChangesetForVariablesContainer(
removedUuidAndNames.find(variable.GetPersistentUuid());
if (existingOldVariableUuidAndName == removedUuidAndNames.end()) {
// This is a new variable.
changeset.addedVariableNames.insert(variableName);
} else {
const gd::String &oldName = existingOldVariableUuidAndName->second;
@@ -182,9 +184,15 @@ WholeProjectRefactorer::ComputeChangesetForVariablesContainer(
}
const auto &oldVariable = oldVariablesContainer.Get(oldName);
if (gd::WholeProjectRefactorer::HasAnyVariableTypeChanged(oldVariable, variable)) {
if (gd::WholeProjectRefactorer::HasAnyVariableTypeChanged(oldVariable,
variable)) {
changeset.typeChangedVariableNames.insert(variableName);
}
if (oldVariable != variable
// Mixed values are never equals, but they must not override anything.
&& !variable.HasMixedValues()) {
changeset.valueChangedVariableNames.insert(variableName);
}
const auto &variablesRenamingChangesetNode =
gd::WholeProjectRefactorer::ComputeChangesetForVariable(oldVariable,
@@ -310,8 +318,8 @@ void WholeProjectRefactorer::ApplyRefactoringForVariablesContainer(
// Rename and remove variables
gd::EventsVariableReplacer eventsVariableReplacer(
project.GetCurrentPlatform(), variablesContainer,
changeset, changeset.removedVariableNames);
project.GetCurrentPlatform(), changeset, changeset.removedVariableNames,
variablesContainer);
gd::ProjectBrowserHelper::ExposeProjectEvents(project,
eventsVariableReplacer);
@@ -321,8 +329,83 @@ void WholeProjectRefactorer::ApplyRefactoringForVariablesContainer(
// Switch types of instructions
gd::EventsVariableInstructionTypeSwitcher
eventsVariableInstructionTypeSwitcher(project.GetCurrentPlatform(),
variablesContainer,
changeset.typeChangedVariableNames);
changeset.typeChangedVariableNames,
variablesContainer);
gd::ProjectBrowserHelper::ExposeProjectEvents(
project, eventsVariableInstructionTypeSwitcher);
}
void WholeProjectRefactorer::ApplyRefactoringForGroupVariablesContainer(
gd::Project &project, gd::ObjectsContainer &globalObjectsContainer,
gd::ObjectsContainer &objectsContainer,
const gd::VariablesContainer &groupVariablesContainer,
const gd::ObjectGroup &objectGroup,
const gd::VariablesChangeset &changeset,
const gd::SerializerElement &originalSerializedVariables) {
// While we support refactoring that would remove all references (actions, conditions...)
// it's both a bit dangerous for the user and we would need to show the user what
// will be removed before doing so. For now, just clear the removed variables so they don't
// trigger any refactoring.
std::unordered_set<gd::String> removedVariableNames;
// Rename variables in events for the objects of the group.
for (const gd::String &objectName : objectGroup.GetAllObjectsNames()) {
const bool hasObject = objectsContainer.HasObjectNamed(objectName);
if (!hasObject && !globalObjectsContainer.HasObjectNamed(objectName)) {
continue;
}
auto &object = hasObject ? objectsContainer.GetObject(objectName)
: globalObjectsContainer.GetObject(objectName);
auto &variablesContainer = object.GetVariables();
gd::EventsVariableReplacer eventsVariableReplacer(
project.GetCurrentPlatform(), changeset,
removedVariableNames, variablesContainer);
gd::ProjectBrowserHelper::ExposeProjectEvents(project,
eventsVariableReplacer);
}
// Rename variables in events for the group.
gd::EventsVariableReplacer eventsVariableReplacer(
project.GetCurrentPlatform(), changeset, removedVariableNames,
objectGroup.GetName());
gd::ProjectBrowserHelper::ExposeProjectEvents(project,
eventsVariableReplacer);
// Apply changes to objects.
gd::GroupVariableHelper::FillMissingGroupVariablesToObjects(
globalObjectsContainer,
objectsContainer,
objectGroup,
originalSerializedVariables);
gd::GroupVariableHelper::ApplyChangesToObjects(
globalObjectsContainer, objectsContainer, groupVariablesContainer,
objectGroup, changeset);
// Switch types of instructions for the group objects.
for (const gd::String &objectName : objectGroup.GetAllObjectsNames()) {
const bool hasObject = objectsContainer.HasObjectNamed(objectName);
if (!hasObject && !globalObjectsContainer.HasObjectNamed(objectName)) {
continue;
}
auto &object = hasObject ? objectsContainer.GetObject(objectName)
: globalObjectsContainer.GetObject(objectName);
auto &variablesContainer = object.GetVariables();
gd::EventsVariableInstructionTypeSwitcher
eventsVariableInstructionTypeSwitcher(
project.GetCurrentPlatform(), changeset.typeChangedVariableNames,
variablesContainer);
gd::ProjectBrowserHelper::ExposeProjectEvents(
project, eventsVariableInstructionTypeSwitcher);
}
// Switch types of instructions for the group.
gd::EventsVariableInstructionTypeSwitcher
eventsVariableInstructionTypeSwitcher(project.GetCurrentPlatform(),
changeset.typeChangedVariableNames,
objectGroup.GetName());
gd::ProjectBrowserHelper::ExposeProjectEvents(
project, eventsVariableInstructionTypeSwitcher);
}
@@ -849,7 +932,8 @@ void WholeProjectRefactorer::RenameEventsBasedBehaviorProperty(
oldPropertyName, newPropertyName);
gd::ProjectBrowserHelper::ExposeEventsBasedBehaviorEvents(
project, eventsFunctionsExtension, eventsBasedBehavior, behaviorRenamer);
project, eventsFunctionsExtension, eventsBasedBehavior,
behaviorRenamer);
} else {
// Properties that represent primitive values will be used through
// their related actions/conditions/expressions. Rename these.
@@ -919,7 +1003,8 @@ void WholeProjectRefactorer::RenameEventsBasedBehaviorSharedProperty(
oldPropertyName, newPropertyName);
gd::ProjectBrowserHelper::ExposeEventsBasedBehaviorEvents(
project, eventsFunctionsExtension, eventsBasedBehavior, behaviorRenamer);
project, eventsFunctionsExtension, eventsBasedBehavior,
behaviorRenamer);
} else {
// Properties that represent primitive values will be used through
// their related actions/conditions/expressions. Rename these.
@@ -1177,12 +1262,14 @@ WholeProjectRefactorer::FindInvalidRequiredBehaviorProperties(
};
// Find in global objects
findInvalidRequiredBehaviorPropertiesInObjects(project.GetObjects());
findInvalidRequiredBehaviorPropertiesInObjects(
project.GetObjects().GetObjects());
// Find in layout objects.
for (std::size_t i = 0; i < project.GetLayoutsCount(); ++i) {
const gd::Layout &layout = project.GetLayout(i);
findInvalidRequiredBehaviorPropertiesInObjects(layout.GetObjects());
findInvalidRequiredBehaviorPropertiesInObjects(
layout.GetObjects().GetObjects());
}
return invalidRequiredBehaviorProperties;
}
@@ -1516,15 +1603,15 @@ void WholeProjectRefactorer::DoRenameObject(
projectBrowser.ExposeFunctions(project, objectParameterRenamer);
}
void WholeProjectRefactorer::ObjectRemovedInLayout(
void WholeProjectRefactorer::ObjectRemovedInScene(
gd::Project &project, gd::Layout &layout, const gd::String &objectName) {
auto projectScopedContainers = gd::ProjectScopedContainers::
MakeNewProjectScopedContainersForProjectAndLayout(project, layout);
// Object groups can't have instances or be in other groups
for (std::size_t g = 0; g < layout.GetObjectGroups().size(); ++g) {
if (layout.GetObjectGroups()[g].Find(objectName))
layout.GetObjectGroups()[g].RemoveObject(objectName);
auto &groups = layout.GetObjects().GetObjectGroups();
for (std::size_t g = 0; g < groups.size(); ++g) {
if (groups[g].Find(objectName))
groups[g].RemoveObject(objectName);
}
layout.GetInitialInstances().RemoveInitialInstancesOfObject(objectName);
@@ -1538,7 +1625,7 @@ void WholeProjectRefactorer::ObjectRemovedInLayout(
}
}
void WholeProjectRefactorer::BehaviorsAddedToObjectInLayout(
void WholeProjectRefactorer::BehaviorsAddedToObjectInScene(
gd::Project &project, gd::Layout &layout, const gd::String &objectName) {
auto projectScopedContainers = gd::ProjectScopedContainers::
MakeNewProjectScopedContainersForProjectAndLayout(project, layout);
@@ -1548,7 +1635,7 @@ void WholeProjectRefactorer::BehaviorsAddedToObjectInLayout(
project, layout, behaviorParameterFiller);
}
void WholeProjectRefactorer::ObjectOrGroupRenamedInLayout(
void WholeProjectRefactorer::ObjectOrGroupRenamedInScene(
gd::Project &project, gd::Layout &layout, const gd::String &oldName,
const gd::String &newName, bool isObjectGroup) {
if (oldName == newName || newName.empty() || oldName.empty())
@@ -1562,11 +1649,12 @@ void WholeProjectRefactorer::ObjectOrGroupRenamedInLayout(
project.GetCurrentPlatform(), projectScopedContainers, layout.GetEvents(),
oldName, newName);
if (!isObjectGroup) { // Object groups can't have instances or be in other
// groups
// Object groups can't have instances or be in other groups
if (!isObjectGroup) {
auto &groups = layout.GetObjects().GetObjectGroups();
layout.GetInitialInstances().RenameInstancesOfObject(oldName, newName);
for (std::size_t g = 0; g < layout.GetObjectGroups().size(); ++g) {
layout.GetObjectGroups()[g].RenameObject(oldName, newName);
for (std::size_t g = 0; g < groups.size(); ++g) {
groups[g].RenameObject(oldName, newName);
}
}
@@ -1638,133 +1726,210 @@ void WholeProjectRefactorer::RenameExternalEvents(gd::Project &project,
linkEventTargetRenamer);
}
void WholeProjectRefactorer::RenameLayer(gd::Project &project,
gd::Layout &layout,
const gd::String &oldName,
const gd::String &newName) {
void WholeProjectRefactorer::RenameLayerInScene(gd::Project &project,
gd::Layout &scene,
const gd::String &oldName,
const gd::String &newName) {
if (oldName == newName || newName.empty() || oldName.empty())
return;
gd::ProjectElementRenamer projectElementRenamer(project.GetCurrentPlatform(),
"layer", oldName, newName);
gd::ProjectBrowserHelper::ExposeLayoutEventsAndExternalEvents(
project, layout, projectElementRenamer);
layout.GetInitialInstances().MoveInstancesToLayer(oldName, newName);
project, scene, projectElementRenamer);
scene.GetInitialInstances().MoveInstancesToLayer(oldName, newName);
std::vector<gd::String> externalLayoutsNames =
GetAssociatedExternalLayouts(project, layout);
GetAssociatedExternalLayouts(project, scene);
for (gd::String name : externalLayoutsNames) {
auto &externalLayout = project.GetExternalLayout(name);
externalLayout.GetInitialInstances().MoveInstancesToLayer(oldName, newName);
}
}
void WholeProjectRefactorer::RenameLayerEffect(gd::Project &project,
gd::Layout &layout,
gd::Layer &layer,
const gd::String &oldName,
const gd::String &newName) {
void WholeProjectRefactorer::RenameLayerInEventsBasedObject(
gd::Project &project,
gd::EventsFunctionsExtension &eventsFunctionsExtension,
gd::EventsBasedObject &eventsBasedObject, const gd::String &oldName,
const gd::String &newName) {
if (oldName == newName || newName.empty() || oldName.empty())
return;
gd::ProjectElementRenamer projectElementRenamer(project.GetCurrentPlatform(),
"layer", oldName, newName);
gd::ProjectBrowserHelper::ExposeEventsBasedObjectEvents(
project, eventsFunctionsExtension, eventsBasedObject,
projectElementRenamer);
eventsBasedObject.GetInitialInstances().MoveInstancesToLayer(oldName,
newName);
}
void WholeProjectRefactorer::RenameLayerEffectInScene(
gd::Project &project, gd::Layout &scene, gd::Layer &layer,
const gd::String &oldName, const gd::String &newName) {
if (oldName == newName || newName.empty() || oldName.empty())
return;
gd::ProjectElementRenamer projectElementRenamer(
project.GetCurrentPlatform(), "layerEffectName", oldName, newName);
projectElementRenamer.SetLayerConstraint(layer.GetName());
gd::ProjectBrowserHelper::ExposeLayoutEventsAndExternalEvents(
project, layout, projectElementRenamer);
project, scene, projectElementRenamer);
}
void WholeProjectRefactorer::RenameObjectAnimation(gd::Project &project,
gd::Layout &layout,
gd::Object &object,
const gd::String &oldName,
const gd::String &newName) {
void WholeProjectRefactorer::RenameLayerEffectInEventsBasedObject(
gd::Project &project,
gd::EventsFunctionsExtension &eventsFunctionsExtension,
gd::EventsBasedObject &eventsBasedObject, gd::Layer &layer,
const gd::String &oldName, const gd::String &newName) {
if (oldName == newName || newName.empty() || oldName.empty())
return;
gd::ProjectElementRenamer projectElementRenamer(
project.GetCurrentPlatform(), "layerEffectName", oldName, newName);
projectElementRenamer.SetLayerConstraint(layer.GetName());
gd::ProjectBrowserHelper::ExposeEventsBasedObjectEvents(
project, eventsFunctionsExtension, eventsBasedObject,
projectElementRenamer);
}
void WholeProjectRefactorer::RenameObjectAnimationInScene(
gd::Project &project, gd::Layout &scene, gd::Object &object,
const gd::String &oldName, const gd::String &newName) {
if (oldName == newName || newName.empty() || oldName.empty())
return;
gd::ProjectElementRenamer projectElementRenamer(
project.GetCurrentPlatform(), "objectAnimationName", oldName, newName);
projectElementRenamer.SetObjectConstraint(object.GetName());
gd::ProjectBrowserHelper::ExposeLayoutEventsAndExternalEvents(
project, layout, projectElementRenamer);
project, scene, projectElementRenamer);
}
void WholeProjectRefactorer::RenameObjectPoint(gd::Project &project,
gd::Layout &layout,
gd::Object &object,
const gd::String &oldName,
const gd::String &newName) {
void WholeProjectRefactorer::RenameObjectAnimationInEventsBasedObject(
gd::Project &project,
gd::EventsFunctionsExtension &eventsFunctionsExtension,
gd::EventsBasedObject &eventsBasedObject, gd::Object &object,
const gd::String &oldName, const gd::String &newName) {
if (oldName == newName || newName.empty() || oldName.empty())
return;
gd::ProjectElementRenamer projectElementRenamer(
project.GetCurrentPlatform(), "objectAnimationName", oldName, newName);
projectElementRenamer.SetObjectConstraint(object.GetName());
gd::ProjectBrowserHelper::ExposeEventsBasedObjectEvents(
project, eventsFunctionsExtension, eventsBasedObject,
projectElementRenamer);
}
void WholeProjectRefactorer::RenameObjectPointInScene(
gd::Project &project, gd::Layout &scene, gd::Object &object,
const gd::String &oldName, const gd::String &newName) {
if (oldName == newName || newName.empty() || oldName.empty())
return;
gd::ProjectElementRenamer projectElementRenamer(
project.GetCurrentPlatform(), "objectPointName", oldName, newName);
projectElementRenamer.SetObjectConstraint(object.GetName());
gd::ProjectBrowserHelper::ExposeLayoutEventsAndExternalEvents(
project, layout, projectElementRenamer);
project, scene, projectElementRenamer);
}
void WholeProjectRefactorer::RenameObjectEffect(gd::Project &project,
gd::Layout &layout,
gd::Object &object,
const gd::String &oldName,
const gd::String &newName) {
void WholeProjectRefactorer::RenameObjectPointInEventsBasedObject(
gd::Project &project,
gd::EventsFunctionsExtension &eventsFunctionsExtension,
gd::EventsBasedObject &eventsBasedObject, gd::Object &object,
const gd::String &oldName, const gd::String &newName) {
if (oldName == newName || newName.empty() || oldName.empty())
return;
gd::ProjectElementRenamer projectElementRenamer(
project.GetCurrentPlatform(), "objectPointName", oldName, newName);
projectElementRenamer.SetObjectConstraint(object.GetName());
gd::ProjectBrowserHelper::ExposeEventsBasedObjectEvents(
project, eventsFunctionsExtension, eventsBasedObject,
projectElementRenamer);
}
void WholeProjectRefactorer::RenameObjectEffectInScene(
gd::Project &project, gd::Layout &scene, gd::Object &object,
const gd::String &oldName, const gd::String &newName) {
if (oldName == newName || newName.empty() || oldName.empty())
return;
gd::ProjectElementRenamer projectElementRenamer(
project.GetCurrentPlatform(), "objectEffectName", oldName, newName);
projectElementRenamer.SetObjectConstraint(object.GetName());
gd::ProjectBrowserHelper::ExposeLayoutEventsAndExternalEvents(
project, layout, projectElementRenamer);
project, scene, projectElementRenamer);
}
void WholeProjectRefactorer::RenameObjectEffectInEventsBasedObject(
gd::Project &project,
gd::EventsFunctionsExtension &eventsFunctionsExtension,
gd::EventsBasedObject &eventsBasedObject, gd::Object &object,
const gd::String &oldName, const gd::String &newName) {
if (oldName == newName || newName.empty() || oldName.empty())
return;
gd::ProjectElementRenamer projectElementRenamer(
project.GetCurrentPlatform(), "objectEffectName", oldName, newName);
projectElementRenamer.SetObjectConstraint(object.GetName());
gd::ProjectBrowserHelper::ExposeEventsBasedObjectEvents(
project, eventsFunctionsExtension, eventsBasedObject,
projectElementRenamer);
}
void WholeProjectRefactorer::ObjectRemovedInEventsBasedObject(
gd::Project &project, gd::EventsBasedObject &eventsBasedObject,
gd::ObjectsContainer &globalObjectsContainer,
gd::ObjectsContainer &objectsContainer, const gd::String &objectName) {
const gd::String &objectName) {
for (auto &functionUniquePtr :
eventsBasedObject.GetEventsFunctions().GetInternalVector()) {
auto function = functionUniquePtr.get();
WholeProjectRefactorer::ObjectRemovedInEventsFunction(
project, *function, globalObjectsContainer, objectsContainer,
objectName);
WholeProjectRefactorer::ObjectRemovedInEventsFunction(project, *function,
objectName);
}
auto &groups = eventsBasedObject.GetObjects().GetObjectGroups();
for (std::size_t g = 0; g < groups.size(); ++g) {
if (groups[g].Find(objectName))
groups[g].RemoveObject(objectName);
}
eventsBasedObject.GetInitialInstances().RemoveInitialInstancesOfObject(
objectName);
}
void WholeProjectRefactorer::ObjectRemovedInEventsFunction(
gd::Project &project, gd::EventsFunction &eventsFunction,
gd::ObjectsContainer &globalObjectsContainer,
gd::ObjectsContainer &objectsContainer, const gd::String &objectName) {
const gd::String &objectName) {
for (std::size_t g = 0; g < eventsFunction.GetObjectGroups().size();
++g) {
for (std::size_t g = 0; g < eventsFunction.GetObjectGroups().size(); ++g) {
if (eventsFunction.GetObjectGroups()[g].Find(objectName))
eventsFunction.GetObjectGroups()[g].RemoveObject(objectName);
}
}
void WholeProjectRefactorer::ObjectOrGroupRenamedInEventsBasedObject(
gd::Project &project, gd::ObjectsContainer &globalObjectsContainer,
gd::Project &project,
const gd::ProjectScopedContainers &projectScopedContainers,
gd::EventsBasedObject &eventsBasedObject, const gd::String &oldName,
const gd::String &newName, bool isObjectGroup) {
for (auto &functionUniquePtr :
eventsBasedObject.GetEventsFunctions().GetInternalVector()) {
auto *function = functionUniquePtr.get();
WholeProjectRefactorer::ObjectOrGroupRenamedInEventsFunction(
project, *function, globalObjectsContainer, eventsBasedObject, oldName,
newName, isObjectGroup);
project, projectScopedContainers, *function, oldName, newName,
isObjectGroup);
}
// Object groups can't have instances or be in other groups
if (!isObjectGroup) {
eventsBasedObject.GetInitialInstances().RenameInstancesOfObject(oldName,
newName);
auto &groups = eventsBasedObject.GetObjects().GetObjectGroups();
for (std::size_t g = 0; g < groups.size(); ++g) {
groups[g].RenameObject(oldName, newName);
}
}
}
void WholeProjectRefactorer::ObjectOrGroupRenamedInEventsFunction(
gd::Project &project, gd::EventsFunction &eventsFunction,
gd::ObjectsContainer &globalObjectsContainer,
gd::ObjectsContainer &objectsContainer, const gd::String &oldName,
gd::Project &project,
const gd::ProjectScopedContainers &projectScopedContainers,
gd::EventsFunction &eventsFunction, const gd::String &oldName,
const gd::String &newName, bool isObjectGroup) {
// In theory we should pass a ProjectScopedContainers to this function so it
// does not have to construct one. In practice, this is ok because we only
// deal with objects.
auto projectScopedContainers =
gd::ProjectScopedContainers::MakeNewProjectScopedContainersFor(
globalObjectsContainer, objectsContainer);
gd::EventsRefactorer::RenameObjectInEvents(
project.GetCurrentPlatform(), projectScopedContainers,
eventsFunction.GetEvents(), oldName, newName);
@@ -1782,33 +1947,35 @@ void WholeProjectRefactorer::GlobalObjectOrGroupRenamed(
bool isObjectGroup) {
// Object groups can't be in other groups
if (!isObjectGroup) {
for (std::size_t g = 0; g < project.GetObjectGroups().size(); ++g) {
project.GetObjectGroups()[g].RenameObject(oldName, newName);
for (std::size_t g = 0; g < project.GetObjects().GetObjectGroups().size();
++g) {
project.GetObjects().GetObjectGroups()[g].RenameObject(oldName, newName);
}
}
for (std::size_t i = 0; i < project.GetLayoutsCount(); ++i) {
gd::Layout &layout = project.GetLayout(i);
if (layout.HasObjectNamed(oldName))
if (layout.GetObjects().HasObjectNamed(oldName))
continue;
ObjectOrGroupRenamedInLayout(project, layout, oldName, newName,
ObjectOrGroupRenamedInScene(project, layout, oldName, newName,
isObjectGroup);
}
}
void WholeProjectRefactorer::GlobalObjectRemoved(
gd::Project &project, const gd::String &objectName) {
for (std::size_t g = 0; g < project.GetObjectGroups().size(); ++g) {
project.GetObjectGroups()[g].RemoveObject(objectName);
void WholeProjectRefactorer::GlobalObjectRemoved(gd::Project &project,
const gd::String &objectName) {
auto &globalGroups = project.GetObjects().GetObjectGroups();
for (std::size_t g = 0; g < globalGroups.size(); ++g) {
globalGroups[g].RemoveObject(objectName);
}
for (std::size_t i = 0; i < project.GetLayoutsCount(); ++i) {
gd::Layout &layout = project.GetLayout(i);
if (layout.HasObjectNamed(objectName))
if (layout.GetObjects().HasObjectNamed(objectName))
continue;
ObjectRemovedInLayout(project, layout, objectName);
ObjectRemovedInScene(project, layout, objectName);
}
}
@@ -1816,41 +1983,40 @@ void WholeProjectRefactorer::BehaviorsAddedToGlobalObject(
gd::Project &project, const gd::String &objectName) {
for (std::size_t i = 0; i < project.GetLayoutsCount(); ++i) {
gd::Layout &layout = project.GetLayout(i);
if (layout.HasObjectNamed(objectName))
if (layout.GetObjects().HasObjectNamed(objectName))
continue;
BehaviorsAddedToObjectInLayout(project, layout, objectName);
BehaviorsAddedToObjectInScene(project, layout, objectName);
}
}
void WholeProjectRefactorer::RemoveLayer(gd::Project &project,
gd::Layout &layout,
const gd::String &layerName) {
void WholeProjectRefactorer::RemoveLayerInScene(gd::Project &project,
gd::Layout &scene,
const gd::String &layerName) {
if (layerName.empty())
return;
layout.GetInitialInstances().RemoveAllInstancesOnLayer(layerName);
scene.GetInitialInstances().RemoveAllInstancesOnLayer(layerName);
std::vector<gd::String> externalLayoutsNames =
GetAssociatedExternalLayouts(project, layout);
GetAssociatedExternalLayouts(project, scene);
for (gd::String name : externalLayoutsNames) {
auto &externalLayout = project.GetExternalLayout(name);
externalLayout.GetInitialInstances().RemoveAllInstancesOnLayer(layerName);
}
}
void WholeProjectRefactorer::MergeLayers(gd::Project &project,
gd::Layout &layout,
const gd::String &originLayerName,
const gd::String &targetLayerName) {
void WholeProjectRefactorer::MergeLayersInScene(
gd::Project &project, gd::Layout &scene, const gd::String &originLayerName,
const gd::String &targetLayerName) {
if (originLayerName == targetLayerName || originLayerName.empty())
return;
layout.GetInitialInstances().MoveInstancesToLayer(originLayerName,
targetLayerName);
scene.GetInitialInstances().MoveInstancesToLayer(originLayerName,
targetLayerName);
std::vector<gd::String> externalLayoutsNames =
GetAssociatedExternalLayouts(project, layout);
GetAssociatedExternalLayouts(project, scene);
for (gd::String name : externalLayoutsNames) {
auto &externalLayout = project.GetExternalLayout(name);
externalLayout.GetInitialInstances().MoveInstancesToLayer(originLayerName,
@@ -1858,6 +2024,24 @@ void WholeProjectRefactorer::MergeLayers(gd::Project &project,
}
}
void WholeProjectRefactorer::RemoveLayerInEventsBasedObject(
gd::EventsBasedObject &eventsBasedObject, const gd::String &layerName) {
if (layerName.empty())
return;
eventsBasedObject.GetInitialInstances().RemoveAllInstancesOnLayer(layerName);
}
void WholeProjectRefactorer::MergeLayersInEventsBasedObject(
gd::EventsBasedObject &eventsBasedObject, const gd::String &originLayerName,
const gd::String &targetLayerName) {
if (originLayerName == targetLayerName || originLayerName.empty())
return;
eventsBasedObject.GetInitialInstances().MoveInstancesToLayer(originLayerName,
targetLayerName);
}
size_t WholeProjectRefactorer::GetLayoutAndExternalLayoutLayerInstancesCount(
gd::Project &project, gd::Layout &layout, const gd::String &layerName) {
size_t count = layout.GetInitialInstances().GetLayerInstancesCount(layerName);

View File

@@ -19,6 +19,7 @@ class Project;
class Layout;
class Layer;
class Object;
class ObjectGroup;
class String;
class EventsFunctionsExtension;
class EventsFunction;
@@ -37,6 +38,7 @@ class BehaviorMetadata;
class UnfilledRequiredBehaviorPropertyProblem;
class ProjectBrowser;
class SerializerElement;
class ProjectScopedContainers;
struct VariablesRenamingChangesetNode;
} // namespace gd
@@ -57,6 +59,8 @@ struct VariablesChangeset : VariablesRenamingChangesetNode {
* would take more time than checking the instruction type is rightly set.
*/
std::unordered_set<gd::String> typeChangedVariableNames;
std::unordered_set<gd::String> valueChangedVariableNames;
std::unordered_set<gd::String> addedVariableNames;
bool HasRemovedVariables() { return !removedVariableNames.empty(); }
@@ -67,7 +71,7 @@ struct VariablesChangeset : VariablesRenamingChangesetNode {
* \brief Tool functions to do refactoring on the whole project after
* changes like deletion or renaming of an object.
*
* \TODO Ideally ObjectOrGroupRenamedInLayout, ObjectRemovedInLayout,
* \TODO Ideally ObjectOrGroupRenamedInScene, ObjectRemovedInScene,
* GlobalObjectOrGroupRenamed, GlobalObjectRemoved would be implemented
* using ExposeProjectEvents.
*/
@@ -90,6 +94,18 @@ class GD_CORE_API WholeProjectRefactorer {
const gd::VariablesChangeset &changeset,
const gd::SerializerElement &originalSerializedVariables);
/**
* \brief Refactor the project according to the changes (renaming or deletion)
* made to variables of a group.
*/
static void ApplyRefactoringForGroupVariablesContainer(
gd::Project &project, gd::ObjectsContainer &globalObjectsContainer,
gd::ObjectsContainer &objectsContainer,
const gd::VariablesContainer &groupVariablesContainer,
const gd::ObjectGroup &objectGroup,
const gd::VariablesChangeset &changeset,
const gd::SerializerElement &originalSerializedVariables);
/**
* \brief Refactor the project **before** an events function extension is
* renamed.
@@ -338,40 +354,91 @@ class GD_CORE_API WholeProjectRefactorer {
static void RenameExternalEvents(gd::Project &project,
const gd::String &oldName,
const gd::String &newName);
/**
* \brief Refactor the project after a layer is renamed.
*/
static void RenameLayer(gd::Project &project, gd::Layout &layout,
const gd::String &oldName, const gd::String &newName);
static void RenameLayerInScene(gd::Project &project, gd::Layout &scene,
const gd::String &oldName,
const gd::String &newName);
/**
* \brief Refactor the project after a layer is renamed.
*/
static void RenameLayerInEventsBasedObject(
gd::Project &project,
gd::EventsFunctionsExtension &eventsFunctionsExtension,
gd::EventsBasedObject &eventsBasedObject, const gd::String &oldName,
const gd::String &newName);
/**
* \brief Refactor the project after a layer effect is renamed.
*/
static void RenameLayerEffect(gd::Project &project, gd::Layout &layout,
gd::Layer &layer, const gd::String &oldName,
const gd::String &newName);
static void RenameLayerEffectInScene(gd::Project &project, gd::Layout &scene,
gd::Layer &layer,
const gd::String &oldName,
const gd::String &newName);
/**
* \brief Refactor the project after a layer effect is renamed.
*/
static void RenameLayerEffectInEventsBasedObject(
gd::Project &project,
gd::EventsFunctionsExtension &eventsFunctionsExtension,
gd::EventsBasedObject &eventsBasedObject, gd::Layer &layer,
const gd::String &oldName, const gd::String &newName);
/**
* \brief Refactor the project after an object animation is renamed.
*/
static void RenameObjectAnimation(gd::Project &project, gd::Layout &layout,
gd::Object &object,
const gd::String &oldName,
const gd::String &newName);
static void RenameObjectAnimationInScene(gd::Project &project,
gd::Layout &scene,
gd::Object &object,
const gd::String &oldName,
const gd::String &newName);
/**
* \brief Refactor the project after an object animation is renamed.
*/
static void RenameObjectAnimationInEventsBasedObject(
gd::Project &project,
gd::EventsFunctionsExtension &eventsFunctionsExtension,
gd::EventsBasedObject &eventsBasedObject, gd::Object &object,
const gd::String &oldName, const gd::String &newName);
/**
* \brief Refactor the project after an object point is renamed.
*/
static void RenameObjectPoint(gd::Project &project, gd::Layout &layout,
gd::Object &object, const gd::String &oldName,
const gd::String &newName);
static void RenameObjectPointInScene(gd::Project &project, gd::Layout &scene,
gd::Object &object,
const gd::String &oldName,
const gd::String &newName);
/**
* \brief Refactor the project after an object point is renamed.
*/
static void RenameObjectPointInEventsBasedObject(
gd::Project &project,
gd::EventsFunctionsExtension &eventsFunctionsExtension,
gd::EventsBasedObject &eventsBasedObject, gd::Object &object,
const gd::String &oldName, const gd::String &newName);
/**
* \brief Refactor the project after an object effect is renamed.
*/
static void RenameObjectEffect(gd::Project &project, gd::Layout &layout,
gd::Object &object, const gd::String &oldName,
const gd::String &newName);
static void RenameObjectEffectInScene(gd::Project &project, gd::Layout &scene,
gd::Object &object,
const gd::String &oldName,
const gd::String &newName);
/**
* \brief Refactor the project after an object effect is renamed.
*/
static void RenameObjectEffectInEventsBasedObject(
gd::Project &project,
gd::EventsFunctionsExtension &eventsFunctionsExtension,
gd::EventsBasedObject &eventsBasedObject, gd::Object &object,
const gd::String &oldName, const gd::String &newName);
/**
* \brief Refactor the project after an object is renamed in a layout
@@ -379,11 +446,11 @@ class GD_CORE_API WholeProjectRefactorer {
* This will update the layout, all external layouts associated with it
* and all external events associated with it.
*/
static void ObjectOrGroupRenamedInLayout(gd::Project& project,
gd::Layout& layout,
const gd::String& oldName,
const gd::String& newName,
bool isObjectGroup);
static void ObjectOrGroupRenamedInScene(gd::Project &project,
gd::Layout &scene,
const gd::String &oldName,
const gd::String &newName,
bool isObjectGroup);
/**
* \brief Refactor the project after an object is removed in a layout
@@ -391,9 +458,8 @@ class GD_CORE_API WholeProjectRefactorer {
* This will update the layout, all external layouts associated with it
* and all external events associated with it.
*/
static void ObjectRemovedInLayout(gd::Project& project,
gd::Layout& layout,
const gd::String& objectName);
static void ObjectRemovedInScene(gd::Project &project, gd::Layout &scene,
const gd::String &objectName);
/**
* \brief Refactor the project after behaviors are added to an object in a
@@ -403,9 +469,9 @@ class GD_CORE_API WholeProjectRefactorer {
* The refactor is actually applied to all objects because it allow to handle
* groups.
*/
static void BehaviorsAddedToObjectInLayout(gd::Project &project,
gd::Layout &layout,
const gd::String &objectName);
static void BehaviorsAddedToObjectInScene(gd::Project &project,
gd::Layout &layout,
const gd::String &objectName);
/**
* \brief Refactor the project after an object is removed in an events-based
@@ -416,8 +482,6 @@ class GD_CORE_API WholeProjectRefactorer {
static void ObjectRemovedInEventsBasedObject(
gd::Project& project,
gd::EventsBasedObject& eventsBasedObject,
gd::ObjectsContainer& globalObjectsContainer,
gd::ObjectsContainer& objectsContainer,
const gd::String& objectName);
/**
@@ -427,7 +491,7 @@ class GD_CORE_API WholeProjectRefactorer {
*/
static void ObjectOrGroupRenamedInEventsBasedObject(
gd::Project& project,
gd::ObjectsContainer& globalObjectsContainer,
const gd::ProjectScopedContainers &projectScopedContainers,
gd::EventsBasedObject& eventsBasedObject,
const gd::String& oldName,
const gd::String& newName,
@@ -440,9 +504,8 @@ class GD_CORE_API WholeProjectRefactorer {
*/
static void ObjectOrGroupRenamedInEventsFunction(
gd::Project& project,
const gd::ProjectScopedContainers &projectScopedContainers,
gd::EventsFunction& eventsFunction,
gd::ObjectsContainer& globalObjectsContainer,
gd::ObjectsContainer& objectsContainer,
const gd::String& oldName,
const gd::String& newName,
bool isObjectGroup);
@@ -455,8 +518,6 @@ class GD_CORE_API WholeProjectRefactorer {
static void ObjectRemovedInEventsFunction(
gd::Project& project,
gd::EventsFunction& eventsFunction,
gd::ObjectsContainer& globalObjectsContainer,
gd::ObjectsContainer& objectsContainer,
const gd::String& objectName);
/**
@@ -518,16 +579,31 @@ class GD_CORE_API WholeProjectRefactorer {
/**
* \brief Remove all the instances from one layer.
*/
static void RemoveLayer(gd::Project &project, gd::Layout &layout,
static void RemoveLayerInScene(gd::Project &project, gd::Layout &scene,
const gd::String &layerName);
/**
* \brief Move all the instances from one layer into another.
*/
static void MergeLayers(gd::Project &project, gd::Layout &layout,
static void MergeLayersInScene(gd::Project &project, gd::Layout &scene,
const gd::String &originLayerName,
const gd::String &targetLayerName);
/**
* \brief Remove all the instances from one layer.
*/
static void
RemoveLayerInEventsBasedObject(gd::EventsBasedObject &eventsBasedObject,
const gd::String &layerName);
/**
* \brief Move all the instances from one layer into another.
*/
static void
MergeLayersInEventsBasedObject(gd::EventsBasedObject &eventsBasedObject,
const gd::String &originLayerName,
const gd::String &targetLayerName);
/**
* \brief Return the number of instances on the layer named \a layerName and
* all its associated layouts.

View File

@@ -35,19 +35,26 @@ std::unique_ptr<gd::ObjectConfiguration> CustomObjectConfiguration::Clone() cons
return gd::make_unique<gd::CustomObjectConfiguration>(*this);
}
gd::ObjectConfiguration &CustomObjectConfiguration::GetChildObjectConfiguration(const gd::String &objectName) {
const gd::EventsBasedObject* CustomObjectConfiguration::GetEventsBasedObject() const {
if (!project->HasEventsBasedObject(GetType())) {
return nullptr;
}
return &project->GetEventsBasedObject(GetType());
}
gd::ObjectConfiguration &CustomObjectConfiguration::GetChildObjectConfiguration(const gd::String &objectName) {
const auto *eventsBasedObject = GetEventsBasedObject();
if (!eventsBasedObject) {
return badObjectConfiguration;
}
const auto &eventsBasedObject = project->GetEventsBasedObject(GetType());
if (!eventsBasedObject.HasObjectNamed(objectName)) {
if (!eventsBasedObject->GetObjects().HasObjectNamed(objectName)) {
gd::LogError("Tried to get the configuration of a child-object:" + objectName
+ " that doesn't exist in the event-based object: " + GetType());
return badObjectConfiguration;
}
auto &childObject = eventsBasedObject.GetObject(objectName);
auto &childObject = eventsBasedObject->GetObjects().GetObject(objectName);
auto configurationPosition = childObjectConfigurations.find(objectName);
if (configurationPosition == childObjectConfigurations.end()) {
childObjectConfigurations.insert(std::make_pair(
@@ -90,8 +97,7 @@ bool CustomObjectConfiguration::UpdateProperty(const gd::String& propertyName,
std::map<gd::String, gd::PropertyDescriptor>
CustomObjectConfiguration::GetInitialInstanceProperties(
const gd::InitialInstance &initialInstance, gd::Project &project,
gd::Layout &scene) {
const gd::InitialInstance &initialInstance) {
std::map<gd::String, gd::PropertyDescriptor> properties;
if (!animations.HasNoAnimations()) {
properties["animation"] =
@@ -105,7 +111,7 @@ CustomObjectConfiguration::GetInitialInstanceProperties(
bool CustomObjectConfiguration::UpdateInitialInstanceProperty(
gd::InitialInstance &initialInstance, const gd::String &name,
const gd::String &value, gd::Project &project, gd::Layout &scene) {
const gd::String &value) {
if (name == "animation") {
initialInstance.SetRawDoubleProperty(
"animation", std::max(0, value.empty() ? 0 : value.To<int>()));
@@ -129,6 +135,20 @@ void CustomObjectConfiguration::DoSerializeTo(SerializerElement& element) const
auto &childElement = childrenContentElement.AddChild(childName);
childConfiguration->SerializeTo(childElement);
}
const auto *eventsBasedObject = GetEventsBasedObject();
if (eventsBasedObject) {
eventsBasedObject->GetInitialInstances().SerializeTo(
element.AddChild("instances"));
eventsBasedObject->GetLayers().SerializeLayersTo(
element.AddChild("layers"));
element.SetIntAttribute("areaMinX", eventsBasedObject->GetAreaMinX());
element.SetIntAttribute("areaMinY", eventsBasedObject->GetAreaMinY());
element.SetIntAttribute("areaMinZ", eventsBasedObject->GetAreaMinZ());
element.SetIntAttribute("areaMaxX", eventsBasedObject->GetAreaMaxX());
element.SetIntAttribute("areaMaxY", eventsBasedObject->GetAreaMaxY());
element.SetIntAttribute("areaMaxZ", eventsBasedObject->GetAreaMaxZ());
}
}
void CustomObjectConfiguration::DoUnserializeFrom(Project& project,
const SerializerElement& element) {
@@ -198,7 +218,7 @@ void CustomObjectConfiguration::ExposeResources(gd::ArbitraryResourceWorker& wor
}
const auto &eventsBasedObject = project->GetEventsBasedObject(GetType());
for (auto& childObject : eventsBasedObject.GetObjects()) {
for (auto& childObject : eventsBasedObject.GetObjects().GetObjects()) {
auto &configuration = GetChildObjectConfiguration(childObject->GetName());
configuration.ExposeResources(worker);
}

View File

@@ -58,14 +58,10 @@ class CustomObjectConfiguration : public gd::ObjectConfiguration {
bool UpdateProperty(const gd::String& name, const gd::String& value) override;
std::map<gd::String, gd::PropertyDescriptor> GetInitialInstanceProperties(
const gd::InitialInstance& instance,
gd::Project& project,
gd::Layout& scene) override;
const gd::InitialInstance& instance) override;
bool UpdateInitialInstanceProperty(gd::InitialInstance& instance,
const gd::String& name,
const gd::String& value,
gd::Project& project,
gd::Layout& scene) override;
const gd::String& value) override;
void ExposeResources(gd::ArbitraryResourceWorker& worker) override;
@@ -86,6 +82,8 @@ protected:
void DoUnserializeFrom(Project& project, const SerializerElement& element) override;
private:
const gd::EventsBasedObject* GetEventsBasedObject() const;
const Project* project; ///< The project is used to get the
///< EventBasedObject from the fullType.
gd::SerializerElement objectContent;

View File

@@ -13,21 +13,19 @@ EventsBasedObject::EventsBasedObject()
: AbstractEventsBasedEntity(
"MyObject",
gd::EventsFunctionsContainer::FunctionOwner::Object),
ObjectsContainer(),
isRenderedIn3D(false),
isAnimatable(false),
isTextContainer(false) {
isTextContainer(false),
areaMinX(0),
areaMinY(0),
areaMinZ(0),
areaMaxX(64),
areaMaxY(64),
areaMaxZ(64) {
}
EventsBasedObject::~EventsBasedObject() {}
EventsBasedObject::EventsBasedObject(const gd::EventsBasedObject &_eventBasedObject)
: AbstractEventsBasedEntity(_eventBasedObject) {
// TODO Add a copy constructor in ObjectsContainer.
initialObjects = gd::Clone(_eventBasedObject.initialObjects);
objectGroups = _eventBasedObject.objectGroups;
}
void EventsBasedObject::SerializeTo(SerializerElement& element) const {
element.SetAttribute("defaultName", defaultName);
if (isRenderedIn3D) {
@@ -39,10 +37,20 @@ void EventsBasedObject::SerializeTo(SerializerElement& element) const {
if (isTextContainer) {
element.SetBoolAttribute("isTextContainer", true);
}
element.SetIntAttribute("areaMinX", areaMinX);
element.SetIntAttribute("areaMinY", areaMinY);
element.SetIntAttribute("areaMinZ", areaMinZ);
element.SetIntAttribute("areaMaxX", areaMaxX);
element.SetIntAttribute("areaMaxY", areaMaxY);
element.SetIntAttribute("areaMaxZ", areaMaxZ);
AbstractEventsBasedEntity::SerializeTo(element);
SerializeObjectsTo(element.AddChild("objects"));
SerializeFoldersTo(element.AddChild("objectsFolderStructure"));
objectsContainer.SerializeObjectsTo(element.AddChild("objects"));
objectsContainer.SerializeFoldersTo(element.AddChild("objectsFolderStructure"));
objectsContainer.GetObjectGroups().SerializeTo(element.AddChild("objectsGroups"));
layers.SerializeLayersTo(element.AddChild("layers"));
initialInstances.SerializeTo(element.AddChild("instances"));
}
void EventsBasedObject::UnserializeFrom(gd::Project& project,
@@ -51,13 +59,29 @@ void EventsBasedObject::UnserializeFrom(gd::Project& project,
isRenderedIn3D = element.GetBoolAttribute("is3D", false);
isAnimatable = element.GetBoolAttribute("isAnimatable", false);
isTextContainer = element.GetBoolAttribute("isTextContainer", false);
areaMinX = element.GetIntAttribute("areaMinX", 0);
areaMinY = element.GetIntAttribute("areaMinY", 0);
areaMinZ = element.GetIntAttribute("areaMinZ", 0);
areaMaxX = element.GetIntAttribute("areaMaxX", 64);
areaMaxY = element.GetIntAttribute("areaMaxY", 64);
areaMaxZ = element.GetIntAttribute("areaMaxZ", 64);
AbstractEventsBasedEntity::UnserializeFrom(project, element);
UnserializeObjectsFrom(project, element.GetChild("objects"));
objectsContainer.UnserializeObjectsFrom(project, element.GetChild("objects"));
if (element.HasChild("objectsFolderStructure")) {
UnserializeFoldersFrom(project, element.GetChild("objectsFolderStructure", 0));
objectsContainer.UnserializeFoldersFrom(project, element.GetChild("objectsFolderStructure", 0));
}
AddMissingObjectsInRootFolder();
objectsContainer.AddMissingObjectsInRootFolder();
objectsContainer.GetObjectGroups().UnserializeFrom(
element.GetChild("objectsGroups"));
if (element.HasChild("layers")) {
layers.UnserializeLayersFrom(element.GetChild("layers"));
} else {
layers.Reset();
}
initialInstances.UnserializeFrom(element.GetChild("instances"));
}
} // namespace gd

View File

@@ -3,12 +3,13 @@
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#ifndef GDCORE_EVENTSBASEDOBJECT_H
#define GDCORE_EVENTSBASEDOBJECT_H
#pragma once
#include <vector>
#include "GDCore/Project/AbstractEventsBasedEntity.h"
#include "GDCore/Project/ObjectsContainer.h"
#include "GDCore/Project/InitialInstancesContainer.h"
#include "GDCore/Project/LayersContainer.h"
#include "GDCore/String.h"
namespace gd {
class SerializerElement;
@@ -26,11 +27,10 @@ namespace gd {
*
* \ingroup PlatformDefinition
*/
class GD_CORE_API EventsBasedObject: public AbstractEventsBasedEntity, public ObjectsContainer {
class GD_CORE_API EventsBasedObject: public AbstractEventsBasedEntity {
public:
EventsBasedObject();
virtual ~EventsBasedObject();
EventsBasedObject(const gd::EventsBasedObject &_eventBasedObject);
/**
* \brief Return a pointer to a new EventsBasedObject constructed from
@@ -111,6 +111,164 @@ class GD_CORE_API EventsBasedObject: public AbstractEventsBasedEntity, public Ob
*/
bool IsTextContainer() const { return isTextContainer; }
/** \name Layers
*/
///@{
/**
* \brief Get the layers of the custom object.
*/
const gd::LayersContainer& GetLayers() const { return layers; }
/**
* \brief Get the layers of the custom object.
*/
gd::LayersContainer& GetLayers() { return layers; }
///@}
/** \name Child objects
*/
///@{
/**
* \brief Get the objects of the custom object.
*/
gd::ObjectsContainer& GetObjects() {
return objectsContainer;
}
/**
* \brief Get the objects of the custom object.
*/
const gd::ObjectsContainer& GetObjects() const {
return objectsContainer;
}
///@}
/** \name Instances
*/
///@{
/**
* \brief Get the instances of the custom object.
*/
gd::InitialInstancesContainer& GetInitialInstances() {
return initialInstances;
}
/**
* \brief Get the instances of the custom object.
*/
const gd::InitialInstancesContainer& GetInitialInstances() const {
return initialInstances;
}
/**
* \brief Get the left bound of the custom object.
*
* This is used only if there is any initial instances.
*
* \see EventsBasedObject::GetInitialInstances
*/
int GetAreaMinX() const {
return areaMinX;
}
/**
* \brief Set the left bound of the custom object.
*/
void SetAreaMinX(int areaMinX_) {
areaMinX = areaMinX_;
}
/**
* \brief Get the top bound of the custom object.
*
* This is used only if there is any initial instances.
*
* \see EventsBasedObject::GetInitialInstances
*/
int GetAreaMinY() const {
return areaMinY;
}
/**
* \brief Set the top bound of the custom object.
*/
void SetAreaMinY(int areaMinY_) {
areaMinY = areaMinY_;
}
/**
* \brief Get the min Z bound of the custom object.
*
* This is used only if there is any initial instances.
*
* \see EventsBasedObject::GetInitialInstances
*/
int GetAreaMinZ() const {
return areaMinZ;
}
/**
* \brief Set the min Z bound of the custom object.
*/
void SetAreaMinZ(int areaMinZ_) {
areaMinZ = areaMinZ_;
}
/**
* \brief Get the right bound of the custom object.
*
* This is used only if there is any initial instances.
*
* \see EventsBasedObject::GetInitialInstances
*/
int GetAreaMaxX() const {
return areaMaxX;
}
/**
* \brief Set the right bound of the custom object.
*/
void SetAreaMaxX(int areaMaxX_) {
areaMaxX = areaMaxX_;
}
/**
* \brief Get the bottom bound of the custom object.
*
* This is used only if there is any initial instances.
*
* \see EventsBasedObject::GetInitialInstances
*/
int GetAreaMaxY() const {
return areaMaxY;
}
/**
* \brief Set the bottom bound of the custom object.
*/
void SetAreaMaxY(int areaMaxY_) {
areaMaxY = areaMaxY_;
}
/**
* \brief Get the max Z bound of the custom object.
*
* This is used only if there is any initial instances.
*
* \see EventsBasedObject::GetInitialInstances
*/
int GetAreaMaxZ() const {
return areaMaxZ;
}
/**
* \brief Set the bottom bound of the custom object.
*/
void SetAreaMaxZ(int areaMaxZ_) {
areaMaxZ = areaMaxZ_;
}
///@}
void SerializeTo(SerializerElement& element) const override;
void UnserializeFrom(gd::Project& project,
@@ -121,8 +279,15 @@ class GD_CORE_API EventsBasedObject: public AbstractEventsBasedEntity, public Ob
bool isRenderedIn3D;
bool isAnimatable;
bool isTextContainer;
gd::InitialInstancesContainer initialInstances;
gd::LayersContainer layers;
gd::ObjectsContainer objectsContainer;
double areaMinX;
double areaMinY;
double areaMinZ;
double areaMaxX;
double areaMaxY;
double areaMaxZ;
};
} // namespace gd
#endif // GDCORE_EVENTSBASEDOBJECT_H

View File

@@ -154,7 +154,7 @@ void EventsFunctionsExtension::UnserializeExtensionDeclarationFrom(
for (size_t i = 0; i < dependenciesElement.GetChildrenCount(); ++i)
dependencies.push_back(
UnserializeDependencyFrom(dependenciesElement.GetChild(i)));
globalVariables.UnserializeFrom(element.GetChild("globalVariables"));
sceneVariables.UnserializeFrom(element.GetChild("sceneVariables"));
@@ -184,7 +184,11 @@ void EventsFunctionsExtension::UnserializeExtensionImplementationFrom(
UnserializeEventsFunctionsFrom(project, element.GetChild("eventsFunctions"));
eventsBasedBehaviors.UnserializeElementsFrom(
"eventsBasedBehavior", project, element.GetChild("eventsBasedBehaviors"));
eventsBasedObjects.UnserializeElementsFrom(
// It's important to load the objects without erasing them first as each object
// might reference other objects, and so need to know if a custom object exists
// in the project or not.
eventsBasedObjects.ProgressivelyUnserializeElementsFrom(
"eventsBasedObject", project, element.GetChild("eventsBasedObjects"));
}

View File

@@ -9,7 +9,6 @@
#include "GDCore/IDE/Dialogs/LayoutEditorCanvas/EditorSettings.h"
#include "GDCore/Project/InitialInstancesContainer.h"
#include "GDCore/Serialization/SerializerElement.h"
#include "GDCore/TinyXml/tinyxml.h"
namespace gd {

View File

@@ -8,6 +8,7 @@
#include "GDCore/Project/Layout.h"
#include "GDCore/Project/Object.h"
#include "GDCore/Project/ObjectsContainer.h"
#include "GDCore/Project/Project.h"
#include "GDCore/Project/PropertyDescriptor.h"
#include "GDCore/Serialization/SerializerElement.h"
@@ -153,33 +154,35 @@ InitialInstance& InitialInstance::ResetPersistentUuid() {
}
std::map<gd::String, gd::PropertyDescriptor>
InitialInstance::GetCustomProperties(gd::Project& project, gd::Layout& layout) {
InitialInstance::GetCustomProperties(
gd::ObjectsContainer &globalObjectsContainer,
gd::ObjectsContainer &objectsContainer) {
// Find an object
if (layout.HasObjectNamed(GetObjectName()))
return layout.GetObject(GetObjectName())
if (objectsContainer.HasObjectNamed(GetObjectName()))
return objectsContainer.GetObject(GetObjectName())
.GetConfiguration()
.GetInitialInstanceProperties(*this, project, layout);
else if (project.HasObjectNamed(GetObjectName()))
return project.GetObject(GetObjectName())
.GetInitialInstanceProperties(*this);
else if (globalObjectsContainer.HasObjectNamed(GetObjectName()))
return globalObjectsContainer.GetObject(GetObjectName())
.GetConfiguration()
.GetInitialInstanceProperties(*this, project, layout);
.GetInitialInstanceProperties(*this);
std::map<gd::String, gd::PropertyDescriptor> nothing;
return nothing;
}
bool InitialInstance::UpdateCustomProperty(const gd::String& name,
const gd::String& value,
gd::Project& project,
gd::Layout& layout) {
if (layout.HasObjectNamed(GetObjectName()))
return layout.GetObject(GetObjectName())
bool InitialInstance::UpdateCustomProperty(
const gd::String &name, const gd::String &value,
gd::ObjectsContainer &globalObjectsContainer,
gd::ObjectsContainer &objectsContainer) {
if (objectsContainer.HasObjectNamed(GetObjectName()))
return objectsContainer.GetObject(GetObjectName())
.GetConfiguration()
.UpdateInitialInstanceProperty(*this, name, value, project, layout);
else if (project.HasObjectNamed(GetObjectName()))
return project.GetObject(GetObjectName())
.UpdateInitialInstanceProperty(*this, name, value);
else if (globalObjectsContainer.HasObjectNamed(GetObjectName()))
return globalObjectsContainer.GetObject(GetObjectName())
.GetConfiguration()
.UpdateInitialInstanceProperty(*this, name, value, project, layout);
.UpdateInitialInstanceProperty(*this, name, value);
return false;
}

View File

@@ -4,8 +4,8 @@
* reserved. This project is released under the MIT License.
*/
#ifndef GDCORE_INITIALINSTANCE_H
#define GDCORE_INITIALINSTANCE_H
#pragma once
#include <map>
#include "GDCore/Project/VariablesContainer.h"
@@ -14,6 +14,7 @@ namespace gd {
class PropertyDescriptor;
class Project;
class Layout;
class ObjectsContainer;
} // namespace gd
namespace gd {
@@ -263,18 +264,18 @@ class GD_CORE_API InitialInstance {
* \note Common properties ( name, position... ) do not need to be
* inserted in this map
*/
std::map<gd::String, gd::PropertyDescriptor> GetCustomProperties(
gd::Project& project, gd::Layout& layout);
std::map<gd::String, gd::PropertyDescriptor>
GetCustomProperties(gd::ObjectsContainer &globalObjectsContainer,
gd::ObjectsContainer &objectsContainer);
/**
* \brief Update the property called \a name with the new \a value.
*
* \return false if the property could not be updated.
*/
bool UpdateCustomProperty(const gd::String& name,
const gd::String& value,
gd::Project& project,
gd::Layout& layout);
bool UpdateCustomProperty(const gd::String &name, const gd::String &value,
gd::ObjectsContainer &globalObjectsContainer,
gd::ObjectsContainer &objectsContainer);
/**
* \brief Get the value of a double property stored in the instance.
@@ -361,5 +362,3 @@ class GD_CORE_API InitialInstance {
};
} // namespace gd
#endif // GDCORE_INITIALINSTANCE_H

View File

@@ -294,17 +294,6 @@ class GD_CORE_API Layer {
static gd::Camera badCamera;
};
/**
* \brief Functor testing layer name
*
* \see gd::Layer
*/
struct LayerHasName : public std::binary_function<gd::Layer, gd::String, bool> {
bool operator()(const Layer& layer, const gd::String& name) const {
return layer.GetName() == name;
}
};
} // namespace gd
#endif // GDCORE_LAYER_H

View File

@@ -0,0 +1,138 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "LayersContainer.h"
#include <algorithm>
#include <vector>
#include "Layer.h"
#include "Layout.h"
using namespace std;
namespace gd {
gd::Layer LayersContainer::badLayer;
LayersContainer::LayersContainer() {
Reset();
}
void LayersContainer::Reset() {
layers.clear();
gd::Layer layer;
layer.SetCameraCount(1);
layers.push_back(layer);
}
gd::Layer& LayersContainer::GetLayer(const gd::String& name) {
std::vector<gd::Layer>::iterator layer =
find_if(layers.begin(), layers.end(), [&name](const gd::Layer& layer) {
return layer.GetName() == name;
});
if (layer != layers.end()) return *layer;
return badLayer;
}
const gd::Layer& LayersContainer::GetLayer(const gd::String& name) const {
std::vector<gd::Layer>::const_iterator layer =
find_if(layers.begin(), layers.end(), [&name](const gd::Layer& layer) {
return layer.GetName() == name;
});
if (layer != layers.end()) return *layer;
return badLayer;
}
gd::Layer& LayersContainer::GetLayer(std::size_t index) {
return layers[index];
}
const gd::Layer& LayersContainer::GetLayer(std::size_t index) const {
return layers[index];
}
std::size_t LayersContainer::GetLayersCount() const { return layers.size(); }
bool LayersContainer::HasLayerNamed(const gd::String& name) const {
return (
find_if(layers.begin(), layers.end(), [&name](const gd::Layer& layer) {
return layer.GetName() == name;
}) != layers.end());
}
std::size_t LayersContainer::GetLayerPosition(const gd::String& name) const {
for (std::size_t i = 0; i < layers.size(); ++i) {
if (layers[i].GetName() == name) return i;
}
return gd::String::npos;
}
void LayersContainer::InsertNewLayer(const gd::String& name,
std::size_t position) {
gd::Layer newLayer;
newLayer.SetName(name);
if (position < layers.size())
layers.insert(layers.begin() + position, newLayer);
else
layers.push_back(newLayer);
}
void LayersContainer::InsertLayer(const gd::Layer& layer,
std::size_t position) {
if (position < layers.size())
layers.insert(layers.begin() + position, layer);
else
layers.push_back(layer);
}
void LayersContainer::RemoveLayer(const gd::String& name) {
std::vector<gd::Layer>::iterator layer =
find_if(layers.begin(), layers.end(), [&name](const gd::Layer& layer) {
return layer.GetName() == name;
});
if (layer == layers.end()) return;
layers.erase(layer);
}
void LayersContainer::SwapLayers(std::size_t firstLayerIndex,
std::size_t secondLayerIndex) {
if (firstLayerIndex >= layers.size() || secondLayerIndex >= layers.size())
return;
std::iter_swap(layers.begin() + firstLayerIndex,
layers.begin() + secondLayerIndex);
}
void LayersContainer::MoveLayer(std::size_t oldIndex, std::size_t newIndex) {
if (oldIndex >= layers.size() || newIndex >= layers.size()) return;
auto layer = layers[oldIndex];
layers.erase(layers.begin() + oldIndex);
InsertLayer(layer, newIndex);
}
void LayersContainer::SerializeLayersTo(SerializerElement& element) const {
element.ConsiderAsArrayOf("layer");
for (std::size_t j = 0; j < GetLayersCount(); ++j)
GetLayer(j).SerializeTo(element.AddChild("layer"));
}
void LayersContainer::UnserializeLayersFrom(const SerializerElement& element) {
layers.clear();
element.ConsiderAsArrayOf("layer", "Layer");
for (std::size_t i = 0; i < element.GetChildrenCount(); ++i) {
gd::Layer layer;
layer.UnserializeFrom(element.GetChild(i));
layers.push_back(layer);
}
}
} // namespace gd

View File

@@ -0,0 +1,109 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#pragma once
#include <vector>
#include "GDCore/Project/Layer.h"
#include "GDCore/String.h"
namespace gd {
/**
* \brief Contains the layers for a scene or a custom object.
*
* \ingroup PlatformDefinition
*/
class GD_CORE_API LayersContainer {
public:
LayersContainer();
/**
* \brief Return true if the layer called "name" exists.
*/
bool HasLayerNamed(const gd::String& name) const;
/**
* \brief Return a reference to the layer called "name".
*/
Layer& GetLayer(const gd::String& name);
/**
* \brief Return a reference to the layer called "name".
*/
const Layer& GetLayer(const gd::String& name) const;
/**
* \brief Return a reference to the layer at position "index" in the layers
* list.
*/
Layer& GetLayer(std::size_t index);
/**
* \brief Return a reference to the layer at position "index" in the layers
* list.
*/
const Layer& GetLayer(std::size_t index) const;
/**
* \brief Return the position of the layer called "name" in the layers list.
*/
std::size_t GetLayerPosition(const gd::String& name) const;
/**
* The number of layers.
*/
std::size_t GetLayersCount() const;
/**
* Add a new empty the layer sheet called "name" at the specified
* position in the layers list.
*/
void InsertNewLayer(const gd::String& name, std::size_t position);
/**
* Add a new layer constructed from the layer passed as parameter.
*
* \param theLayer The layer that must be copied and inserted.
* \param position Insertion position.
*/
void InsertLayer(const Layer& theLayer, std::size_t position);
/**
* Delete the layer named "name".
*/
void RemoveLayer(const gd::String& name);
/**
* Swap the position of the specified layers.
*/
void SwapLayers(std::size_t firstLayerIndex, std::size_t secondLayerIndex);
/**
* Change the position of the specified layer.
*/
void MoveLayer(std::size_t oldIndex, std::size_t newIndex);
void Reset();
/**
* \brief Serialize the layers.
*/
void SerializeLayersTo(SerializerElement& element) const;
/**
* \brief Unserialize the layers.
*/
void UnserializeLayersFrom(const SerializerElement& element);
private:
static gd::Layer badLayer; ///< Null object, returned when GetLayer can not
///< find an appropriate layer.
std::vector<gd::Layer> layers; ///< Layers
};
} // namespace gd

View File

@@ -33,7 +33,6 @@ using namespace std;
namespace gd {
gd::Layer Layout::badLayer;
gd::BehaviorsSharedData Layout::badBehaviorSharedData("", "");
Layout::Layout(const Layout& other) { Init(other); }
@@ -53,12 +52,8 @@ Layout::Layout()
stopSoundsOnStartup(true),
standardSortMethod(true),
disableInputWhenNotFocused(true),
profiler(NULL),
variables(gd::VariablesContainer::SourceType::Scene)
{
gd::Layer layer;
layer.SetCameraCount(1);
initialLayers.push_back(layer);
}
void Layout::SetName(const gd::String& name_) {
@@ -100,91 +95,47 @@ Layout::GetAllBehaviorSharedData() const {
}
gd::Layer& Layout::GetLayer(const gd::String& name) {
std::vector<gd::Layer>::iterator layer =
find_if(initialLayers.begin(),
initialLayers.end(),
bind2nd(gd::LayerHasName(), name));
if (layer != initialLayers.end()) return *layer;
return badLayer;
return layers.GetLayer(name);
}
const gd::Layer& Layout::GetLayer(const gd::String& name) const {
std::vector<gd::Layer>::const_iterator layer =
find_if(initialLayers.begin(),
initialLayers.end(),
bind2nd(gd::LayerHasName(), name));
if (layer != initialLayers.end()) return *layer;
return badLayer;
return layers.GetLayer(name);
}
gd::Layer& Layout::GetLayer(std::size_t index) { return initialLayers[index]; }
gd::Layer& Layout::GetLayer(std::size_t index) { return layers.GetLayer(index); }
const gd::Layer& Layout::GetLayer(std::size_t index) const {
return initialLayers[index];
return layers.GetLayer(index);
}
std::size_t Layout::GetLayersCount() const { return initialLayers.size(); }
std::size_t Layout::GetLayersCount() const { return layers.GetLayersCount(); }
#if defined(GD_IDE_ONLY)
bool Layout::HasLayerNamed(const gd::String& name) const {
return (find_if(initialLayers.begin(),
initialLayers.end(),
bind2nd(gd::LayerHasName(), name)) != initialLayers.end());
return layers.HasLayerNamed(name);
}
std::size_t Layout::GetLayerPosition(const gd::String& name) const {
for (std::size_t i = 0; i < initialLayers.size(); ++i) {
if (initialLayers[i].GetName() == name) return i;
}
return gd::String::npos;
return layers.GetLayerPosition(name);
}
void Layout::InsertNewLayer(const gd::String& name, std::size_t position) {
gd::Layer newLayer;
newLayer.SetName(name);
if (position < initialLayers.size())
initialLayers.insert(initialLayers.begin() + position, newLayer);
else
initialLayers.push_back(newLayer);
layers.InsertNewLayer(name, position);
}
void Layout::InsertLayer(const gd::Layer& layer, std::size_t position) {
if (position < initialLayers.size())
initialLayers.insert(initialLayers.begin() + position, layer);
else
initialLayers.push_back(layer);
layers.InsertLayer(layer, position);
}
void Layout::RemoveLayer(const gd::String& name) {
std::vector<gd::Layer>::iterator layer =
find_if(initialLayers.begin(),
initialLayers.end(),
bind2nd(gd::LayerHasName(), name));
if (layer == initialLayers.end()) return;
initialLayers.erase(layer);
layers.RemoveLayer(name);
}
void Layout::SwapLayers(std::size_t firstLayerIndex,
std::size_t secondLayerIndex) {
if (firstLayerIndex >= initialLayers.size() ||
secondLayerIndex >= initialLayers.size())
return;
std::iter_swap(initialLayers.begin() + firstLayerIndex,
initialLayers.begin() + secondLayerIndex);
layers.SwapLayers(firstLayerIndex, secondLayerIndex);
}
void Layout::MoveLayer(std::size_t oldIndex, std::size_t newIndex) {
if (oldIndex >= initialLayers.size() || newIndex >= initialLayers.size())
return;
auto layer = initialLayers[oldIndex];
initialLayers.erase(initialLayers.begin() + oldIndex);
InsertLayer(layer, newIndex);
layers.MoveLayer(oldIndex, newIndex);
}
void Layout::UpdateBehaviorsSharedData(gd::Project& project) {
@@ -192,22 +143,23 @@ void Layout::UpdateBehaviorsSharedData(gd::Project& project) {
std::vector<gd::String> allBehaviorsNames;
// Search in objects for the type and the name of every behaviors.
for (std::size_t i = 0; i < initialObjects.size(); ++i) {
for (std::size_t i = 0; i < objectsContainer.GetObjectsCount(); ++i) {
std::vector<gd::String> objectBehaviors =
initialObjects[i]->GetAllBehaviorNames();
objectsContainer.GetObject(i).GetAllBehaviorNames();
for (unsigned int j = 0; j < objectBehaviors.size(); ++j) {
auto& behavior =
initialObjects[i]->GetBehavior(objectBehaviors[j]);
objectsContainer.GetObject(i).GetBehavior(objectBehaviors[j]);
allBehaviorsTypes.push_back(behavior.GetTypeName());
allBehaviorsNames.push_back(behavior.GetName());
}
}
for (std::size_t i = 0; i < project.GetObjectsCount(); ++i) {
auto &globalObjects = project.GetObjects();
for (std::size_t i = 0; i < globalObjects.GetObjectsCount(); ++i) {
std::vector<gd::String> objectBehaviors =
project.GetObject(i).GetAllBehaviorNames();
globalObjects.GetObject(i).GetAllBehaviorNames();
for (std::size_t j = 0; j < objectBehaviors.size(); ++j) {
auto& behavior =
project.GetObject(i).GetBehavior(objectBehaviors[j]);
globalObjects.GetObject(i).GetBehavior(objectBehaviors[j]);
allBehaviorsTypes.push_back(behavior.GetTypeName());
allBehaviorsNames.push_back(behavior.GetName());
}
@@ -291,15 +243,15 @@ void Layout::SerializeTo(SerializerElement& element) const {
editorSettings.SerializeTo(element.AddChild("uiSettings"));
GetObjectGroups().SerializeTo(element.AddChild("objectsGroups"));
objectsContainer.GetObjectGroups().SerializeTo(element.AddChild("objectsGroups"));
GetVariables().SerializeTo(element.AddChild("variables"));
GetInitialInstances().SerializeTo(element.AddChild("instances"));
SerializeObjectsTo(element.AddChild("objects"));
SerializeFoldersTo(element.AddChild("objectsFolderStructure"));
objectsContainer.SerializeObjectsTo(element.AddChild("objects"));
objectsContainer.SerializeFoldersTo(element.AddChild("objectsFolderStructure"));
gd::EventsListSerialization::SerializeEventsTo(events,
element.AddChild("events"));
SerializeLayersTo(element.AddChild("layers"));
layers.SerializeLayersTo(element.AddChild("layers"));
SerializerElement& behaviorDatasElement =
element.AddChild("behaviorsSharedData");
@@ -317,23 +269,6 @@ void Layout::SerializeTo(SerializerElement& element) const {
}
}
void Layout::SerializeLayersTo(SerializerElement& element) const {
element.ConsiderAsArrayOf("layer");
for (std::size_t j = 0; j < GetLayersCount(); ++j)
GetLayer(j).SerializeTo(element.AddChild("layer"));
}
#endif
void Layout::UnserializeLayersFrom(const SerializerElement& element) {
initialLayers.clear();
element.ConsiderAsArrayOf("layer", "Layer");
for (std::size_t i = 0; i < element.GetChildrenCount(); ++i) {
gd::Layer layer;
layer.UnserializeFrom(element.GetChild(i));
initialLayers.push_back(layer);
}
}
void Layout::UnserializeFrom(gd::Project& project,
const SerializerElement& element) {
SetBackgroundColor(element.GetIntAttribute("r"),
@@ -349,22 +284,22 @@ void Layout::UnserializeFrom(gd::Project& project,
editorSettings.UnserializeFrom(
element.GetChild("uiSettings", 0, "UISettings"));
GetObjectGroups().UnserializeFrom(
objectsContainer.GetObjectGroups().UnserializeFrom(
element.GetChild("objectsGroups", 0, "GroupesObjets"));
gd::EventsListSerialization::UnserializeEventsFrom(
project, GetEvents(), element.GetChild("events", 0, "Events"));
UnserializeObjectsFrom(project, element.GetChild("objects", 0, "Objets"));
objectsContainer.UnserializeObjectsFrom(project, element.GetChild("objects", 0, "Objets"));
if (element.HasChild("objectsFolderStructure")) {
UnserializeFoldersFrom(project, element.GetChild("objectsFolderStructure", 0));
objectsContainer.UnserializeFoldersFrom(project, element.GetChild("objectsFolderStructure", 0));
}
AddMissingObjectsInRootFolder();
objectsContainer.AddMissingObjectsInRootFolder();
initialInstances.UnserializeFrom(
element.GetChild("instances", 0, "Positions"));
variables.UnserializeFrom(element.GetChild("variables", 0, "Variables"));
UnserializeLayersFrom(element.GetChild("layers", 0, "Layers"));
layers.UnserializeLayersFrom(element.GetChild("layers", 0, "Layers"));
// Compatibility with GD <= 4
gd::String deprecatedTag1 = "automatismsSharedData";
@@ -416,10 +351,10 @@ void Layout::Init(const Layout& other) {
stopSoundsOnStartup = other.stopSoundsOnStartup;
disableInputWhenNotFocused = other.disableInputWhenNotFocused;
initialInstances = other.initialInstances;
initialLayers = other.initialLayers;
layers = other.layers;
variables = other.GetVariables();
initialObjects = gd::Clone(other.initialObjects);
objectsContainer = other.objectsContainer;
behaviorsSharedData.clear();
for (const auto& it : other.behaviorsSharedData) {
@@ -429,9 +364,6 @@ void Layout::Init(const Layout& other) {
events = other.events;
editorSettings = other.editorSettings;
objectGroups = other.objectGroups;
profiler = other.profiler;
}
std::vector<gd::String> GetHiddenLayers(const Layout& layout) {

View File

@@ -9,15 +9,17 @@
#include <map>
#include <memory>
#include <vector>
#include "GDCore/Events/EventsList.h"
#include "GDCore/IDE/Dialogs/LayoutEditorCanvas/EditorSettings.h"
#include "GDCore/Project/BehaviorsSharedData.h"
#include "GDCore/Project/InitialInstancesContainer.h"
#include "GDCore/Project/Layer.h"
#include "GDCore/Project/LayersContainer.h"
#include "GDCore/Project/ObjectGroupsContainer.h"
#include "GDCore/Project/ObjectsContainer.h"
#include "GDCore/Project/VariablesContainer.h"
#include "GDCore/String.h"
#include "GDCore/IDE/Dialogs/LayoutEditorCanvas/EditorSettings.h"
namespace gd {
class BaseEvent;
@@ -25,7 +27,6 @@ class Object;
class Project;
class InitialInstancesContainer;
} // namespace gd
class TiXmlElement;
class BaseProfiler;
#undef GetObject // Disable an annoying macro
@@ -36,7 +37,7 @@ namespace gd {
*
* \ingroup PlatformDefinition
*/
class GD_CORE_API Layout : public ObjectsContainer {
class GD_CORE_API Layout {
public:
Layout();
Layout(const Layout&);
@@ -104,6 +105,24 @@ class GD_CORE_API Layout : public ObjectsContainer {
///@}
/** \name Layout's objects
*/
///@{
/**
* \brief return the objects of the scene.
*/
gd::ObjectsContainer& GetObjects() {
return objectsContainer;
}
/**
* \brief Return the objects of the scene.
*/
const gd::ObjectsContainer& GetObjects() const {
return objectsContainer;
}
///@}
/** \name Layout's initial instances
* Members functions related to initial instances of objects created at the
* layout start up
@@ -147,103 +166,96 @@ class GD_CORE_API Layout : public ObjectsContainer {
///@{
/**
* Provide access to the gd::VariablesContainer member containing the layout
* variables \see gd::VariablesContainer
* \brief Get the variables of the scene.
*
* \see gd::VariablesContainer
*/
inline const gd::VariablesContainer& GetVariables() const {
return variables;
}
/**
* Provide access to the gd::VariablesContainer member containing the layout
* variables \see gd::VariablesContainer
* \brief Get the variables of the scene.
*
* \see gd::VariablesContainer
*/
inline gd::VariablesContainer& GetVariables() { return variables; }
///@}
/** \name Layout layers management
* Members functions related to layout layers management.
* TODO: This could be moved to a separate class
/** \name Layers
*/
///@{
/**
* \brief Return true if the layer called "name" exists.
* \brief Get the layers of the scene.
*/
const gd::LayersContainer& GetLayers() const { return layers; }
/**
* \brief Get the layers of the scene.
*/
gd::LayersContainer& GetLayers() { return layers; }
/**
* @deprecated
*/
bool HasLayerNamed(const gd::String& name) const;
/**
* \brief Return a reference to the layer called "name".
* @deprecated
*/
Layer& GetLayer(const gd::String& name);
/**
* \brief Return a reference to the layer called "name".
* @deprecated
*/
const Layer& GetLayer(const gd::String& name) const;
/**
* \brief Return a reference to the layer at position "index" in the layers
* list
* @deprecated
*/
Layer& GetLayer(std::size_t index);
/**
* \brief Return a reference to the layer at position "index" in the layers
* list
* @deprecated
*/
const Layer& GetLayer(std::size_t index) const;
/**
* \brief Return the position of the layer called "name" in the layers list
* @deprecated
*/
std::size_t GetLayerPosition(const gd::String& name) const;
/**
* Must return the number of layers.
* @deprecated
*/
std::size_t GetLayersCount() const;
/**
* Must add a new empty the layer sheet called "name" at the specified
* position in the layout list.
* @deprecated
*/
void InsertNewLayer(const gd::String& name, std::size_t position);
/**
* Must add a new the layer constructed from the layout passed as parameter.
* \note No pointer or reference must be kept on the layer passed as
* parameter. \param theLayer the layer that must be copied and inserted
* into the project \param position Insertion position. Even if the position
* is invalid, the layer must be inserted at the end of the layers list.
* @deprecated
*/
void InsertLayer(const Layer& theLayer, std::size_t position);
/**
* Must delete the layer named "name".
* @deprecated
*/
void RemoveLayer(const gd::String& name);
/**
* Swap the position of the specified layers.
* @deprecated
*/
void SwapLayers(std::size_t firstLayerIndex, std::size_t secondLayerIndex);
/**
* Change the position of the specified layer.
* @deprecated
*/
void MoveLayer(std::size_t oldIndex, std::size_t newIndex);
/**
* \brief Serialize the layers.
*/
void SerializeLayersTo(SerializerElement& element) const;
/**
* \brief Unserialize the layers.
*/
void UnserializeLayersFrom(const SerializerElement& element);
///@}
/**
@@ -275,7 +287,8 @@ class GD_CORE_API Layout : public ObjectsContainer {
/**
* \brief Get the shared data stored for a behavior
*/
gd::BehaviorsSharedData& GetBehaviorSharedData(const gd::String& behaviorName);
gd::BehaviorsSharedData& GetBehaviorSharedData(
const gd::String& behaviorName);
/**
* \brief Get a map of all shared data stored for behaviors
@@ -283,7 +296,6 @@ class GD_CORE_API Layout : public ObjectsContainer {
const std::map<gd::String, std::unique_ptr<gd::BehaviorsSharedData>>&
GetAllBehaviorSharedData() const;
/**
* Return the settings associated to the layout.
* \see gd::EditorSettings
@@ -296,9 +308,7 @@ class GD_CORE_API Layout : public ObjectsContainer {
* Return the settings associated to the layout.
* \see gd::EditorSettings
*/
gd::EditorSettings& GetAssociatedEditorSettings() {
return editorSettings;
}
gd::EditorSettings& GetAssociatedEditorSettings() { return editorSettings; }
/** \name Other properties
*/
@@ -339,12 +349,12 @@ class GD_CORE_API Layout : public ObjectsContainer {
* launched
*/
bool StopSoundsOnStartup() const { return stopSoundsOnStartup; }
///@}
///@}
/** \name Saving and loading
* Members functions related to saving and loading the object.
*/
///@{
/** \name Saving and loading
* Members functions related to saving and loading the object.
*/
///@{
/**
* \brief Serialize the layout.
*/
@@ -354,18 +364,7 @@ class GD_CORE_API Layout : public ObjectsContainer {
* \brief Unserialize the layout.
*/
void UnserializeFrom(gd::Project& project, const SerializerElement& element);
///@}
// TODO: GD C++ Platform specific code below
/**
* Get the profiler associated with the scene. Can be NULL.
*/
BaseProfiler* GetProfiler() const { return profiler; };
/**
* Set the profiler associated with the scene. Can be NULL.
*/
void SetProfiler(BaseProfiler* profiler_) { profiler = profiler_; };
///@}
private:
gd::String name; ///< Scene name
@@ -375,8 +374,9 @@ class GD_CORE_API Layout : public ObjectsContainer {
unsigned int backgroundColorB; ///< Background color Blue component
gd::String title; ///< Title displayed in the window
gd::VariablesContainer variables; ///< Variables list
gd::ObjectsContainer objectsContainer;
gd::InitialInstancesContainer initialInstances; ///< Initial instances
std::vector<gd::Layer> initialLayers; ///< Initial layers
gd::LayersContainer layers;
std::map<gd::String, std::unique_ptr<gd::BehaviorsSharedData>>
behaviorsSharedData; ///< Initial shared datas of behaviors
bool stopSoundsOnStartup; ///< True to make the scene stop all sounds at
@@ -385,20 +385,14 @@ class GD_CORE_API Layout : public ObjectsContainer {
bool disableInputWhenNotFocused; /// If set to true, the input must be
/// disabled when the window do not have the
/// focus.
static gd::Layer badLayer; ///< Null object, returned when GetLayer can not
///< find an appropriate layer.
static gd::BehaviorsSharedData
badBehaviorSharedData; ///< Null object, returned when
///< GetBehaviorSharedData can not find the
///< specified behavior shared data.
///< GetBehaviorSharedData can not find the
///< specified behavior shared data.
EventsList events; ///< Scene events
gd::EditorSettings editorSettings;
// TODO: GD C++ Platform specific code below
BaseProfiler* profiler; ///< Pointer to the profiler. Can be NULL.
/**
* Initialize from another layout. Used by copy-ctor and assign-op.
* Don't forget to update me if members were changed!
@@ -445,20 +439,24 @@ gd::String GD_CORE_API GetTypeOfObject(const ObjectsContainer& game,
bool searchInGroups = true);
/**
* \brief Check if an object or all objects of a group has a behavior.
* \deprecated Use gd::ObjectsContainersList::HasBehaviorInObjectOrGroup instead.
* \deprecated Use gd::ObjectsContainersList::HasBehaviorInObjectOrGroup
* instead.
*/
bool GD_CORE_API HasBehaviorInObjectOrGroup(const gd::ObjectsContainer &project,
const gd::ObjectsContainer &layout,
const gd::String &objectOrGroupName,
const gd::String &behaviorName,
bool GD_CORE_API HasBehaviorInObjectOrGroup(const gd::ObjectsContainer& project,
const gd::ObjectsContainer& layout,
const gd::String& objectOrGroupName,
const gd::String& behaviorName,
bool searchInGroups = true);
/**
* \brief Get the names of behavior of a given type if an object or all objects of a group has it.
* \brief Get the names of behavior of a given type if an object or all objects
* of a group has it.
*/
std::vector<gd::String> GD_CORE_API GetBehaviorNamesInObjectOrGroup(
const gd::ObjectsContainer &project, const gd::ObjectsContainer &layout,
const gd::String &objectOrGroupName, const gd::String &behaviorType,
bool searchInGroups);
std::vector<gd::String> GD_CORE_API
GetBehaviorNamesInObjectOrGroup(const gd::ObjectsContainer& project,
const gd::ObjectsContainer& layout,
const gd::String& objectOrGroupName,
const gd::String& behaviorType,
bool searchInGroups);
/**
* \brief Check if a behavior is a default one or doesn't exist in an object or
@@ -471,13 +469,15 @@ bool GD_CORE_API IsDefaultBehavior(const gd::ObjectsContainer& project,
bool searchInGroups = true);
/**
* \brief Get the type of a behavior if an object or all objects of a group has it.
* \brief Get the type of a behavior if an object or all objects of a group has
* it.
*/
gd::String GD_CORE_API GetTypeOfBehaviorInObjectOrGroup(const gd::ObjectsContainer &project,
const gd::ObjectsContainer &layout,
const gd::String &objectOrGroupName,
const gd::String &behaviorName,
bool searchInGroups = true);
gd::String GD_CORE_API
GetTypeOfBehaviorInObjectOrGroup(const gd::ObjectsContainer& project,
const gd::ObjectsContainer& layout,
const gd::String& objectOrGroupName,
const gd::String& behaviorName,
bool searchInGroups = true);
/**
* \brief Get a type from a behavior name
* @return Type of the behavior.

View File

@@ -25,9 +25,7 @@ std::map<gd::String, gd::PropertyDescriptor> ObjectConfiguration::GetProperties(
}
std::map<gd::String, gd::PropertyDescriptor>
ObjectConfiguration::GetInitialInstanceProperties(const gd::InitialInstance& instance,
gd::Project& project,
gd::Layout& layout) {
ObjectConfiguration::GetInitialInstanceProperties(const gd::InitialInstance& instance) {
std::map<gd::String, gd::PropertyDescriptor> nothing;
return nothing;
}

View File

@@ -114,9 +114,7 @@ class GD_CORE_API ObjectConfiguration {
* \see gd::InitialInstance
*/
virtual std::map<gd::String, gd::PropertyDescriptor>
GetInitialInstanceProperties(const gd::InitialInstance& instance,
gd::Project& project,
gd::Layout& layout);
GetInitialInstanceProperties(const gd::InitialInstance& instance);
/**
* \brief Called when the IDE wants to update a custom property of an initial
@@ -127,9 +125,7 @@ class GD_CORE_API ObjectConfiguration {
*/
virtual bool UpdateInitialInstanceProperty(gd::InitialInstance& instance,
const gd::String& name,
const gd::String& value,
gd::Project& project,
gd::Layout& layout) {
const gd::String& value) {
return false;
};
///@}

View File

@@ -7,6 +7,7 @@
#include <algorithm>
#include "GDCore/Tools/PolymorphicClone.h"
#include "GDCore/Extensions/Platform.h"
#include "GDCore/Project/Object.h"
#include "GDCore/Project/ObjectFolderOrObject.h"
@@ -21,6 +22,25 @@ ObjectsContainer::ObjectsContainer() {
ObjectsContainer::~ObjectsContainer() {}
ObjectsContainer::ObjectsContainer(const ObjectsContainer& other) {
Init(other);
}
ObjectsContainer& ObjectsContainer::operator=(
const ObjectsContainer& other) {
if (this != &other) Init(other);
return *this;
}
void ObjectsContainer::Init(const gd::ObjectsContainer& other) {
initialObjects = gd::Clone(other.initialObjects);
objectGroups = other.objectGroups;
// The objects folders are not copied.
// It's not an issue because the UI uses the serialization for duplication.
rootFolder = gd::make_unique<gd::ObjectFolderOrObject>("__ROOT");
}
void ObjectsContainer::SerializeObjectsTo(SerializerElement& element) const {
element.ConsiderAsArrayOf("object");
for (std::size_t j = 0; j < initialObjects.size(); j++) {

View File

@@ -40,6 +40,9 @@ class GD_CORE_API ObjectsContainer {
*/
ObjectsContainer();
virtual ~ObjectsContainer();
ObjectsContainer(const ObjectsContainer&);
ObjectsContainer& operator=(const ObjectsContainer& rhs);
/** \name Objects management
* Members functions related to objects management.
@@ -230,6 +233,12 @@ class GD_CORE_API ObjectsContainer {
private:
std::unique_ptr<gd::ObjectFolderOrObject> rootFolder;
/**
* Initialize from another variables container, copying elements. Used by
* copy-ctor and assign-op. Don't forget to update me if members were changed!
*/
void Init(const ObjectsContainer& other);
};
} // namespace gd

View File

@@ -22,8 +22,8 @@ ObjectsContainersList
ObjectsContainersList::MakeNewObjectsContainersListForProjectAndLayout(
const gd::Project& project, const gd::Layout& layout) {
ObjectsContainersList objectsContainersList;
objectsContainersList.Add(project);
objectsContainersList.Add(layout);
objectsContainersList.Add(project.GetObjects());
objectsContainersList.Add(layout.GetObjects());
return objectsContainersList;
}
@@ -31,7 +31,7 @@ ObjectsContainersList
ObjectsContainersList::MakeNewObjectsContainersListForProject(
const gd::Project& project) {
ObjectsContainersList objectsContainersList;
objectsContainersList.Add(project);
objectsContainersList.Add(project.GetObjects());
return objectsContainersList;
}

View File

@@ -34,7 +34,6 @@
#include "GDCore/Serialization/Serializer.h"
#include "GDCore/Serialization/SerializerElement.h"
#include "GDCore/String.h"
#include "GDCore/TinyXml/tinyxml.h"
#include "GDCore/Tools/Localization.h"
#include "GDCore/Tools/Log.h"
#include "GDCore/Tools/PolymorphicClone.h"
@@ -835,15 +834,15 @@ void Project::UnserializeFrom(const SerializerElement& element) {
*this, eventsFunctionsExtensionElement);
}
GetObjectGroups().UnserializeFrom(
objectsContainer.GetObjectGroups().UnserializeFrom(
element.GetChild("objectsGroups", 0, "ObjectGroups"));
resourcesManager.UnserializeFrom(
element.GetChild("resources", 0, "Resources"));
UnserializeObjectsFrom(*this, element.GetChild("objects", 0, "Objects"));
objectsContainer.UnserializeObjectsFrom(*this, element.GetChild("objects", 0, "Objects"));
if (element.HasChild("objectsFolderStructure")) {
UnserializeFoldersFrom(*this, element.GetChild("objectsFolderStructure", 0));
objectsContainer.UnserializeFoldersFrom(*this, element.GetChild("objectsFolderStructure", 0));
}
AddMissingObjectsInRootFolder();
objectsContainer.AddMissingObjectsInRootFolder();
GetVariables().UnserializeFrom(element.GetChild("variables", 0, "Variables"));
@@ -995,9 +994,9 @@ void Project::SerializeTo(SerializerElement& element) const {
std::cout << "ERROR: The project current platform is NULL.";
resourcesManager.SerializeTo(element.AddChild("resources"));
SerializeObjectsTo(element.AddChild("objects"));
SerializeFoldersTo(element.AddChild("objectsFolderStructure"));
GetObjectGroups().SerializeTo(element.AddChild("objectsGroups"));
objectsContainer.SerializeObjectsTo(element.AddChild("objects"));
objectsContainer.SerializeFoldersTo(element.AddChild("objectsFolderStructure"));
objectsContainer.GetObjectGroups().SerializeTo(element.AddChild("objectsGroups"));
GetVariables().SerializeTo(element.AddChild("variables"));
element.SetAttribute("firstLayout", firstLayout);
@@ -1164,7 +1163,6 @@ void Project::Init(const gd::Project& game) {
platformSpecificAssets = game.platformSpecificAssets;
loadingScreen = game.loadingScreen;
watermark = game.watermark;
objectGroups = game.objectGroups;
extensionProperties = game.extensionProperties;
@@ -1177,7 +1175,7 @@ void Project::Init(const gd::Project& game) {
resourcesManager = game.resourcesManager;
initialObjects = gd::Clone(game.initialObjects);
objectsContainer = game.objectsContainer;
scenes = gd::Clone(game.scenes);

View File

@@ -48,7 +48,7 @@ namespace gd {
*
* \ingroup PlatformDefinition
*/
class GD_CORE_API Project : public ObjectsContainer {
class GD_CORE_API Project {
public:
Project();
Project(const Project&);
@@ -984,6 +984,24 @@ class GD_CORE_API Project : public ObjectsContainer {
///@}
/** \name Global objects
*/
///@{
/**
* \brief return the objects of the project.
*/
gd::ObjectsContainer& GetObjects() {
return objectsContainer;
}
/**
* \brief Return the objects of the project.
*/
const gd::ObjectsContainer& GetObjects() const {
return objectsContainer;
}
///@}
/** \name Identifier names
*/
///@{
@@ -1090,6 +1108,7 @@ class GD_CORE_API Project : public ObjectsContainer {
///< startup.
std::vector<std::unique_ptr<gd::Layout> > scenes; ///< List of all scenes
gd::VariablesContainer variables; ///< Initial global variables
gd::ObjectsContainer objectsContainer;
std::vector<std::unique_ptr<gd::ExternalLayout> >
externalLayouts; ///< List of all externals layouts
std::vector<std::unique_ptr<gd::EventsFunctionsExtension> >

View File

@@ -6,6 +6,7 @@
#include "GDCore/Project/EventsBasedObject.h"
#include "GDCore/Project/ObjectsContainer.h"
#include "GDCore/Events/Event.h"
#include "GDCore/Extensions/PlatformExtension.h"
namespace gd {
@@ -101,6 +102,37 @@ ProjectScopedContainers::MakeNewProjectScopedContainersForObjectEventsFunction(
return projectScopedContainers;
}
ProjectScopedContainers
ProjectScopedContainers::MakeNewProjectScopedContainersForEventsBasedObject(
const gd::Project &project,
const gd::EventsFunctionsExtension &eventsFunctionsExtension,
const gd::EventsBasedObject &eventsBasedObject,
gd::ObjectsContainer &outputObjectsContainer) {
outputObjectsContainer.GetObjects().clear();
outputObjectsContainer.GetObjectGroups().Clear();
outputObjectsContainer.InsertNewObject(
project,
gd::PlatformExtension::GetObjectFullType(
eventsFunctionsExtension.GetName(), eventsBasedObject.GetName()),
"Object", outputObjectsContainer.GetObjectsCount());
gd::EventsFunctionTools::CopyEventsBasedObjectChildrenToObjectsContainer(
eventsBasedObject, outputObjectsContainer);
ProjectScopedContainers projectScopedContainers(
ObjectsContainersList::MakeNewObjectsContainersListForContainer(
outputObjectsContainer),
VariablesContainersList::
MakeNewVariablesContainersListForEventsFunctionsExtension(
eventsFunctionsExtension),
PropertiesContainersList::MakeNewEmptyPropertiesContainersList());
projectScopedContainers.AddPropertiesContainer(
eventsBasedObject.GetPropertyDescriptors());
return projectScopedContainers;
}
ProjectScopedContainers
ProjectScopedContainers::MakeNewProjectScopedContainersWithLocalVariables(
const ProjectScopedContainers &projectScopedContainers,

View File

@@ -111,6 +111,13 @@ class ProjectScopedContainers {
const gd::EventsFunction &eventsFunction,
gd::ObjectsContainer &parameterObjectsContainer);
static ProjectScopedContainers
MakeNewProjectScopedContainersForEventsBasedObject(
const gd::Project &project,
const gd::EventsFunctionsExtension &eventsFunctionsExtension,
const gd::EventsBasedObject &eventsBasedObject,
gd::ObjectsContainer &outputObjectsContainer);
static ProjectScopedContainers
MakeNewProjectScopedContainersWithLocalVariables(
const ProjectScopedContainers &projectScopedContainers,

View File

@@ -30,6 +30,8 @@ gd::String Variable::TypeAsString(Type t) {
return "structure";
case Type::Array:
return "array";
case Type::MixedTypes:
return "mixed";
default:
return "error-type";
}
@@ -46,6 +48,8 @@ Variable::Type Variable::StringAsType(const gd::String& str) {
return Type::Structure;
else if (str == "array")
return Type::Array;
else if (str == "mixed")
return Type::MixedTypes;
// Default to number
return Type::Number;
@@ -56,6 +60,7 @@ bool Variable::IsPrimitive(const Type type) {
}
void Variable::CastTo(const Type newType) {
hasMixedValues = false;
if (newType == Type::Number)
SetValue(GetValue());
else if (newType == Type::String)
@@ -85,6 +90,9 @@ void Variable::CastTo(const Type newType) {
type = Type::Array;
// Free now unused memory
children.clear();
} else if (newType == Type::MixedTypes) {
type = Type::MixedTypes;
hasMixedValues = true;
}
}
@@ -142,6 +150,7 @@ Variable& Variable::GetChild(const gd::String& name) {
if (it != children.end()) return *it->second;
type = Type::Structure;
hasMixedValues = false;
children[name] = std::make_shared<gd::Variable>();
return *children[name];
}
@@ -202,6 +211,7 @@ Variable& Variable::PushNew() {
const size_t count = GetChildrenCount();
auto& variable = GetAtIndex(count);
if (type == Type::Array && count > 0) {
hasMixedValues = false;
const auto childType = GetAtIndex(count - 1).type;
variable.type = childType;
if (childType == Type::Number) {
@@ -224,6 +234,7 @@ void Variable::RemoveAtIndex(const size_t index) {
bool Variable::InsertAtIndex(const gd::Variable& variable, const size_t index) {
if (type != Type::Array) return false;
hasMixedValues = false;
auto newVariable = std::make_shared<gd::Variable>(variable);
if (index < childrenArray.size()) {
childrenArray.insert(childrenArray.begin() + index, newVariable);
@@ -238,6 +249,7 @@ bool Variable::InsertChild(const gd::String& name,
if (type != Type::Structure || HasChild(name)) {
return false;
}
hasMixedValues = false;
children[name] = std::make_shared<gd::Variable>(variable);
return true;
};
@@ -270,6 +282,9 @@ void Variable::SerializeTo(SerializerElement& element) const {
child->SerializeTo(childrenElement.AddChild("variable"));
}
}
if (hasMixedValues) {
element.SetBoolAttribute("hasMixedValues", true);
}
}
void Variable::UnserializeFrom(const SerializerElement& element) {
@@ -313,6 +328,9 @@ void Variable::UnserializeFrom(const SerializerElement& element) {
PushNew().UnserializeFrom(childElement);
}
}
if (element.GetBoolAttribute("hasMixedValues", false)) {
MarkAsMixedValues();
}
}
Variable& Variable::ResetPersistentUuid() {
@@ -384,7 +402,8 @@ Variable::Variable(const Variable& other)
folded(other.folded),
boolVal(other.boolVal),
type(other.type),
persistentUuid(other.persistentUuid) {
persistentUuid(other.persistentUuid),
hasMixedValues(other.hasMixedValues) {
CopyChildren(other);
}
@@ -396,6 +415,7 @@ Variable& Variable::operator=(const Variable& other) {
boolVal = other.boolVal;
type = other.type;
persistentUuid = other.persistentUuid;
hasMixedValues = other.hasMixedValues;
CopyChildren(other);
}
@@ -411,4 +431,61 @@ void Variable::CopyChildren(const gd::Variable& other) {
childrenArray.push_back(std::make_shared<gd::Variable>(*child.get()));
}
}
bool Variable::operator==(const gd::Variable &variable) const {
if (type != variable.type || hasMixedValues || variable.hasMixedValues) {
return false;
}
if (type == Variable::Type::Number) {
return value == variable.value;
}
if (type == Variable::Type::String) {
return str == variable.str;
}
if (type == Variable::Type::Boolean) {
return boolVal == variable.boolVal;
}
if (type == Variable::Type::Structure) {
if (children.size() != variable.children.size()) {
return false;
}
for (auto &pair : children) {
const gd::String &name = pair.first;
const auto &child = pair.second;
auto it = variable.children.find(name);
if (it == children.end()) {
return false;
}
auto &otherChild = it->second;
if (*child != *otherChild) {
return false;
}
}
return true;
}
if (type == Variable::Type::Array) {
if (childrenArray.size() != variable.childrenArray.size()) {
return false;
}
for (int i = 0; i < childrenArray.size(); ++i) {
if (*childrenArray[i] != *variable.childrenArray[i]) {
return false;
}
}
return true;
}
// MixedTypes variables can't equal another variable.
return false;
}
bool Variable::operator!=(const gd::Variable &variable) const {
return !(*this == variable);
}
void Variable::MarkAsMixedValues() {
hasMixedValues = true;
ClearChildren();
}
} // namespace gd

View File

@@ -4,8 +4,8 @@
* reserved. This project is released under the MIT License.
*/
#ifndef GDCORE_VARIABLE_H
#define GDCORE_VARIABLE_H
#pragma once
#include <cmath>
#include <map>
#include <memory>
@@ -31,6 +31,8 @@ class GD_CORE_API Variable {
static gd::Variable badVariable;
enum Type {
Unknown,
/** Used when objects of a group have different types for a variable. */
MixedTypes,
// Primitive types
String,
@@ -50,7 +52,7 @@ class GD_CORE_API Variable {
/**
* \brief Default constructor creating a variable with 0 as value.
*/
Variable() : value(0), type(Type::Number){};
Variable() : value(0), type(Type::Number), hasMixedValues(false) {};
Variable(const Variable&);
virtual ~Variable(){};
@@ -87,6 +89,7 @@ class GD_CORE_API Variable {
void SetString(const gd::String& newStr) {
str = newStr;
type = Type::String;
hasMixedValues = false;
}
/**
@@ -102,6 +105,7 @@ class GD_CORE_API Variable {
// NaN values are not supported by GDevelop nor the serializer.
if (std::isnan(value)) value = 0.0;
type = Type::Number;
hasMixedValues = false;
}
/**
@@ -115,8 +119,23 @@ class GD_CORE_API Variable {
void SetBool(bool val) {
boolVal = val;
type = Type::Boolean;
hasMixedValues = false;
}
/**
* \brief Return true when objects of a group have different values for a
* variable.
*/
bool HasMixedValues() const {
return hasMixedValues;
}
/**
* \brief Return true when objects of a group have different values for a
* variable.
*/
void MarkAsMixedValues();
// Operators are overloaded to allow accessing to variable using a simple
// int-like semantic.
void operator=(double val) { SetValue(val); };
@@ -168,6 +187,9 @@ class GD_CORE_API Variable {
bool operator==(const bool val) const { return GetBool() == val; };
bool operator!=(const bool val) const { return GetBool() != val; };
bool operator==(const gd::Variable& variable) const;
bool operator!=(const gd::Variable& variable) const;
///@}
/** \name Collection types
@@ -376,6 +398,7 @@ class GD_CORE_API Variable {
mutable gd::String str;
mutable double value;
mutable bool boolVal;
mutable bool hasMixedValues;
mutable std::map<gd::String, std::shared_ptr<Variable>>
children; ///< Children, when the variable is considered as a structure.
mutable std::vector<std::shared_ptr<Variable>>
@@ -392,5 +415,3 @@ class GD_CORE_API Variable {
};
} // namespace gd
#endif // GDCORE_VARIABLE_H

View File

@@ -11,7 +11,6 @@
#include "GDCore/Project/Variable.h"
#include "GDCore/Serialization/SerializerElement.h"
#include "GDCore/String.h"
#include "GDCore/TinyXml/tinyxml.h"
#include "GDCore/Tools/UUID/UUID.h"
namespace gd {

View File

@@ -12,7 +12,6 @@
namespace gd {
class SerializerElement;
}
class TiXmlElement;
namespace gd {

View File

@@ -17,91 +17,11 @@
#include "rapidjson/document.h"
#include "rapidjson/prettywriter.h"
#include "rapidjson/rapidjson.h"
#if !defined(EMSCRIPTEN)
#include "GDCore/TinyXml/tinyxml.h"
#endif
using namespace rapidjson;
namespace gd {
#if !defined(EMSCRIPTEN)
void Serializer::ToXML(SerializerElement& element, TiXmlElement* xmlElement) {
if (!xmlElement) return;
if (element.IsValueUndefined()) {
const std::map<gd::String, SerializerValue>& attributes =
element.GetAllAttributes();
for (std::map<gd::String, SerializerValue>::const_iterator it =
attributes.begin();
it != attributes.end();
++it) {
const SerializerValue& attr = it->second;
if (attr.IsBoolean())
xmlElement->SetAttribute(it->first.c_str(),
attr.GetBool() ? "true" : "false");
else if (attr.IsString())
xmlElement->SetAttribute(it->first.c_str(), attr.GetString().c_str());
else if (attr.IsInt())
xmlElement->SetAttribute(it->first.c_str(), attr.GetInt());
else if (attr.IsDouble())
xmlElement->SetDoubleAttribute(it->first.c_str(), attr.GetDouble());
else
xmlElement->SetAttribute(it->first.c_str(), attr.GetString().c_str());
}
const std::vector<
std::pair<gd::String, std::shared_ptr<SerializerElement> > >& children =
element.GetAllChildren();
for (size_t i = 0; i < children.size(); ++i) {
if (children[i].second == std::shared_ptr<SerializerElement>()) continue;
TiXmlElement* xmlChild = new TiXmlElement(children[i].first.c_str());
xmlElement->LinkEndChild(xmlChild);
ToXML(*children[i].second, xmlChild);
}
} else {
TiXmlText* xmlValue = new TiXmlText(element.GetValue().GetString().c_str());
xmlElement->LinkEndChild(xmlValue);
}
}
void Serializer::FromXML(SerializerElement& element,
const TiXmlElement* xmlElement) {
if (!xmlElement) return;
const TiXmlAttribute* attr = xmlElement->FirstAttribute();
while (attr) {
if (attr->Name() != NULL) {
gd::String name = gd::String::FromUTF8(attr->Name()).ReplaceInvalid();
if (attr->Value())
element.SetAttribute(
name, gd::String::FromUTF8(attr->Value()).ReplaceInvalid());
}
attr = attr->Next();
}
const TiXmlElement* child = xmlElement->FirstChildElement();
while (child) {
if (child->Value()) {
gd::String name = gd::String::FromUTF8(child->Value()).ReplaceInvalid();
SerializerElement& childElement = element.AddChild(name);
FromXML(childElement, child);
}
child = child->NextSiblingElement();
}
if (xmlElement->GetText()) {
SerializerValue value;
value.Set(gd::String::FromUTF8(xmlElement->GetText()).ReplaceInvalid());
element.SetValue(value);
}
}
#endif
gd::String Serializer::ToEscapedXMLString(const gd::String& str) {
return str.FindAndReplace("&", "&amp;")
.FindAndReplace("'", "&apos;")

View File

@@ -8,7 +8,6 @@
#define GDCORE_SERIALIZER_H
#include <string>
#include "GDCore/Serialization/SerializerElement.h"
class TiXmlElement;
namespace gd {
@@ -22,11 +21,7 @@ class GD_CORE_API Serializer {
* Convert a gd::SerializerElement from/to XML.
*/
///@{
#if !defined(EMSCRIPTEN)
static void ToXML(SerializerElement& element, TiXmlElement* xmlElement);
static void FromXML(SerializerElement& element,
const TiXmlElement* xmlElement);
#endif
/**
* \brief Escape a string for inclusion in a XML tag
*/

View File

@@ -1,117 +0,0 @@
/*
www.sourceforge.net/projects/tinyxml
Original file by Yves Berquin.
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
/*
* THIS FILE WAS ALTERED BY Tyge L<>vset, 7. April 2005.
*/
#ifndef TIXML_USE_STL
#include "GDCore/TinyXml/tinystr.h"
// Error value for find primitive
const TiXmlString::size_type TiXmlString::npos = static_cast< TiXmlString::size_type >(-1);
// Null rep.
TiXmlString::Rep TiXmlString::nullrep_ = { 0, 0, { '\0' } };
void TiXmlString::reserve (size_type cap)
{
if (cap > capacity())
{
TiXmlString tmp;
tmp.init(length(), cap);
memcpy(tmp.start(), data(), length());
swap(tmp);
}
}
TiXmlString& TiXmlString::assign(const char* str, size_type len)
{
size_type cap = capacity();
if (len > cap || cap > 3*(len + 8))
{
TiXmlString tmp;
tmp.init(len);
memcpy(tmp.start(), str, len);
swap(tmp);
}
else
{
memmove(start(), str, len);
set_size(len);
}
return *this;
}
TiXmlString& TiXmlString::append(const char* str, size_type len)
{
size_type newsize = length() + len;
if (newsize > capacity())
{
reserve (newsize + capacity());
}
memmove(finish(), str, len);
set_size(newsize);
return *this;
}
TiXmlString operator + (const TiXmlString & a, const TiXmlString & b)
{
TiXmlString tmp;
tmp.reserve(a.length() + b.length());
tmp += a;
tmp += b;
return tmp;
}
TiXmlString operator + (const TiXmlString & a, const char* b)
{
TiXmlString tmp;
TiXmlString::size_type b_len = static_cast<TiXmlString::size_type>( strlen(b) );
tmp.reserve(a.length() + b_len);
tmp += a;
tmp.append(b, b_len);
return tmp;
}
TiXmlString operator + (const char* a, const TiXmlString & b)
{
TiXmlString tmp;
TiXmlString::size_type a_len = static_cast<TiXmlString::size_type>( strlen(a) );
tmp.reserve(a_len + b.length());
tmp.append(a, a_len);
tmp += b;
return tmp;
}
#endif // TIXML_USE_STL

View File

@@ -1,325 +0,0 @@
/*
www.sourceforge.net/projects/tinyxml
Original file by Yves Berquin.
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
/*
* THIS FILE WAS ALTERED BY Tyge Lovset, 7. April 2005.
*
* - completely rewritten. compact, clean, and fast implementation.
* - sizeof(TiXmlString) = pointer size (4 bytes on 32-bit systems)
* - fixed reserve() to work as per specification.
* - fixed buggy compares operator==(), operator<(), and operator>()
* - fixed operator+=() to take a const ref argument, following spec.
* - added "copy" constructor with length, and most compare operators.
* - added swap(), clear(), size(), capacity(), operator+().
*/
/**
* Changes by Florian Rival :
* Added GD_CORE_API to integrate TinyXml to GDevelop Library.
*/
#ifndef TIXML_USE_STL
#ifndef TIXML_STRING_INCLUDED
#define TIXML_STRING_INCLUDED
#include <assert.h>
#include <string.h>
/* The support for explicit isn't that universal, and it isn't really
required - it is used to check that the TiXmlString class isn't incorrectly
used. Be nice to old compilers and macro it here:
*/
#if defined(_MSC_VER) && (_MSC_VER >= 1200 )
// Microsoft visual studio, version 6 and higher.
#define TIXML_EXPLICIT explicit
#elif defined(__GNUC__) && (__GNUC__ >= 3 )
// GCC version 3 and higher.s
#define TIXML_EXPLICIT explicit
#else
#define TIXML_EXPLICIT
#endif
/*
TiXmlString is an emulation of a subset of the std::string template.
Its purpose is to allow compiling TinyXML on compilers with no or poor STL support.
Only the member functions relevant to the TinyXML project have been implemented.
The buffer allocation is made by a simplistic power of 2 like mechanism : if we increase
a string and there's no more room, we allocate a buffer twice as big as we need.
*/
class GD_CORE_API TiXmlString
{
public :
// The size type used
typedef size_t size_type;
// Error value for find primitive
static const size_type npos; // = -1;
// TiXmlString empty constructor
TiXmlString () : rep_(&nullrep_)
{
}
// TiXmlString copy constructor
TiXmlString ( const TiXmlString & copy) : rep_(0)
{
init(copy.length());
memcpy(start(), copy.data(), length());
}
// TiXmlString constructor, based on a string
TIXML_EXPLICIT TiXmlString ( const char * copy) : rep_(0)
{
init( static_cast<size_type>( strlen(copy) ));
memcpy(start(), copy, length());
}
// TiXmlString constructor, based on a string
TIXML_EXPLICIT TiXmlString ( const char * str, size_type len) : rep_(0)
{
init(len);
memcpy(start(), str, len);
}
// TiXmlString destructor
~TiXmlString ()
{
quit();
}
// = operator
TiXmlString& operator = (const char * copy)
{
return assign( copy, (size_type)strlen(copy));
}
// = operator
TiXmlString& operator = (const TiXmlString & copy)
{
return assign(copy.start(), copy.length());
}
// += operator. Maps to append
TiXmlString& operator += (const char * suffix)
{
return append(suffix, static_cast<size_type>( strlen(suffix) ));
}
// += operator. Maps to append
TiXmlString& operator += (char single)
{
return append(&single, 1);
}
// += operator. Maps to append
TiXmlString& operator += (const TiXmlString & suffix)
{
return append(suffix.data(), suffix.length());
}
// Convert a TiXmlString into a null-terminated char *
const char * c_str () const { return rep_->str; }
// Convert a TiXmlString into a char * (need not be null terminated).
const char * data () const { return rep_->str; }
// Return the length of a TiXmlString
size_type length () const { return rep_->size; }
// Alias for length()
size_type size () const { return rep_->size; }
// Checks if a TiXmlString is empty
bool empty () const { return rep_->size == 0; }
// Return capacity of string
size_type capacity () const { return rep_->capacity; }
// single char extraction
const char& at (size_type index) const
{
assert( index < length() );
return rep_->str[ index ];
}
// [] operator
char& operator [] (size_type index) const
{
assert( index < length() );
return rep_->str[ index ];
}
// find a char in a string. Return TiXmlString::npos if not found
size_type find (char lookup) const
{
return find(lookup, 0);
}
// find a char in a string from an offset. Return TiXmlString::npos if not found
size_type find (char tofind, size_type offset) const
{
if (offset >= length()) return npos;
for (const char* p = c_str() + offset; *p != '\0'; ++p)
{
if (*p == tofind) return static_cast< size_type >( p - c_str() );
}
return npos;
}
void clear ()
{
//Lee:
//The original was just too strange, though correct:
// TiXmlString().swap(*this);
//Instead use the quit & re-init:
quit();
init(0,0);
}
/* Function to reserve a big amount of data when we know we'll need it. Be aware that this
function DOES NOT clear the content of the TiXmlString if any exists.
*/
void reserve (size_type cap);
TiXmlString& assign (const char* str, size_type len);
TiXmlString& append (const char* str, size_type len);
void swap (TiXmlString& other)
{
Rep* r = rep_;
rep_ = other.rep_;
other.rep_ = r;
}
private:
void init(size_type sz) { init(sz, sz); }
void set_size(size_type sz) { rep_->str[ rep_->size = sz ] = '\0'; }
char* start() const { return rep_->str; }
char* finish() const { return rep_->str + rep_->size; }
struct Rep
{
size_type size, capacity;
char str[1];
};
void init(size_type sz, size_type cap)
{
if (cap)
{
// Lee: the original form:
// rep_ = static_cast<Rep*>(operator new(sizeof(Rep) + cap));
// doesn't work in some cases of new being overloaded. Switching
// to the normal allocation, although use an 'int' for systems
// that are overly picky about structure alignment.
const size_type bytesNeeded = sizeof(Rep) + cap;
const size_type intsNeeded = ( bytesNeeded + sizeof(int) - 1 ) / sizeof( int );
rep_ = reinterpret_cast<Rep*>( new int[ intsNeeded ] );
rep_->str[ rep_->size = sz ] = '\0';
rep_->capacity = cap;
}
else
{
rep_ = &nullrep_;
}
}
void quit()
{
if (rep_ != &nullrep_)
{
// The rep_ is really an array of ints. (see the allocator, above).
// Cast it back before delete, so the compiler won't incorrectly call destructors.
delete [] ( reinterpret_cast<int*>( rep_ ) );
}
}
Rep * rep_;
static Rep nullrep_;
} ;
inline bool operator == (const TiXmlString & a, const TiXmlString & b)
{
return ( a.length() == b.length() ) // optimization on some platforms
&& ( strcmp(a.c_str(), b.c_str()) == 0 ); // actual compare
}
inline bool operator < (const TiXmlString & a, const TiXmlString & b)
{
return strcmp(a.c_str(), b.c_str()) < 0;
}
inline bool operator != (const TiXmlString & a, const TiXmlString & b) { return !(a == b); }
inline bool operator > (const TiXmlString & a, const TiXmlString & b) { return b < a; }
inline bool operator <= (const TiXmlString & a, const TiXmlString & b) { return !(b < a); }
inline bool operator >= (const TiXmlString & a, const TiXmlString & b) { return !(a < b); }
inline bool operator == (const TiXmlString & a, const char* b) { return strcmp(a.c_str(), b) == 0; }
inline bool operator == (const char* a, const TiXmlString & b) { return b == a; }
inline bool operator != (const TiXmlString & a, const char* b) { return !(a == b); }
inline bool operator != (const char* a, const TiXmlString & b) { return !(b == a); }
TiXmlString operator + (const TiXmlString & a, const TiXmlString & b);
TiXmlString operator + (const TiXmlString & a, const char* b);
TiXmlString operator + (const char* a, const TiXmlString & b);
/*
TiXmlOutStream is an emulation of std::ostream. It is based on TiXmlString.
Only the operators that we need for TinyXML have been developped.
*/
class GD_CORE_API TiXmlOutStream : public TiXmlString
{
public :
// TiXmlOutStream << operator.
TiXmlOutStream & operator << (const TiXmlString & in)
{
*this += in;
return *this;
}
// TiXmlOutStream << operator.
TiXmlOutStream & operator << (const char * in)
{
*this += in;
return *this;
}
} ;
#endif // TIXML_STRING_INCLUDED
#endif // TIXML_USE_STL

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,54 +0,0 @@
/*
www.sourceforge.net/projects/tinyxml
Original code (2.0 and earlier )copyright (c) 2000-2006 Lee Thomason (www.grinninglizard.com)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#include "GDCore/TinyXml/tinyxml.h"
// The goal of the seperate error file is to make the first
// step towards localization. tinyxml (currently) only supports
// english error messages, but the could now be translated.
//
// It also cleans up the code a bit.
//
const char* TiXmlBase::errorString[ TIXML_ERROR_STRING_COUNT ] =
{
"No error",
"Error",
"Failed to open file",
"Memory allocation failed.",
"Error parsing Element.",
"Failed to read Element name",
"Error reading Element value.",
"Error reading Attributes.",
"Error: empty tag.",
"Error reading end tag.",
"Error parsing Unknown.",
"Error parsing Comment.",
"Error parsing Declaration.",
"Error document empty.",
"Error null (0) or unexpected EOF found in input stream.",
"Error parsing CDATA.",
"Error when TiXmlDocument added to document, because TiXmlDocument can only be at the root.",
};

File diff suppressed because it is too large Load Diff

View File

@@ -204,6 +204,10 @@ class SerializableWithNameList {
void UnserializeElementsFrom(const gd::String& elementName,
const SerializerElement& element);
void ProgressivelyUnserializeElementsFrom(const gd::String& elementName,
gd::Project& project,
const SerializerElement& element);
///@}
protected:

View File

@@ -127,6 +127,26 @@ void SerializableWithNameList<T>::SerializeElementsTo(
}
}
template <typename T>
void SerializableWithNameList<T>::ProgressivelyUnserializeElementsFrom(
const gd::String& elementName,
gd::Project& project,
const SerializerElement& serializerElement) {
serializerElement.ConsiderAsArrayOf(elementName);
for (std::size_t i = 0; i < serializerElement.GetChildrenCount(); ++i) {
T* newElement = nullptr;
if (elements.size() <= i) {
newElement = &InsertNew("", GetCount());
} else {
newElement = elements[i].get();
}
newElement->UnserializeFrom(project, serializerElement.GetChild(i));
}
while (elements.size() > serializerElement.GetChildrenCount()) {
elements.pop_back();
}
}
template <typename T>
void SerializableWithNameList<T>::UnserializeElementsFrom(
const gd::String& elementName,

View File

@@ -1,39 +0,0 @@
#include "GDCore/Tools/XmlLoader.h"
#include <cstdio>
namespace gd {
namespace {
FILE* GetFileHandle(const gd::String& filename, const gd::String& mode) {
#if defined(WINDOWS)
return _wfopen(filename.ToWide().c_str(), mode.ToWide().c_str());
#else
return fopen(filename.ToLocale().c_str(), mode.ToLocale().c_str());
#endif
}
} // namespace
bool GD_CORE_API LoadXmlFromFile(TiXmlDocument& doc,
const gd::String& filepath) {
FILE* xmlFile = GetFileHandle(filepath, "rb");
if (!xmlFile) return false;
bool res = doc.LoadFile(xmlFile);
fclose(xmlFile);
return res;
}
bool GD_CORE_API SaveXmlToFile(const TiXmlDocument& doc,
const gd::String& filepath) {
FILE* xmlFile = GetFileHandle(filepath, "wb");
if (!xmlFile) return false;
bool res = doc.SaveFile(xmlFile);
fclose(xmlFile);
return res;
}
} // namespace gd

View File

@@ -1,17 +0,0 @@
#ifndef GDCORE_XMLLOADER_H
#define GDCORE_XMLLOADER_H
#include "GDCore/String.h"
#include "GDCore/TinyXml/tinyxml.h"
namespace gd {
bool GD_CORE_API LoadXmlFromFile(TiXmlDocument& doc,
const gd::String& filepath);
bool GD_CORE_API SaveXmlToFile(const TiXmlDocument& doc,
const gd::String& filepath);
} // namespace gd
#endif

View File

@@ -705,7 +705,7 @@ EXCLUDE_PATTERNS =
# wildcard * is used, a substring. Examples: ANamespace, AClass,
# AClass::ANamespace, ANamespace::*Test
EXCLUDE_SYMBOLS = TiXml*
EXCLUDE_SYMBOLS =
# The EXAMPLE_PATH tag can be used to specify one or more files or
# directories that contain example code fragments that are included (see

View File

@@ -94,7 +94,7 @@ TEST_CASE("ArbitraryResourceWorker", "[common][resources]") {
spriteConfiguration.GetAnimations().AddAnimation(anim);
gd::Object obj("myObject", "", spriteConfiguration.Clone());
project.InsertObject(obj, 0);
project.GetObjects().InsertObject(obj, 0);
worker.files.clear();
worker.images.clear();
@@ -141,7 +141,7 @@ TEST_CASE("ArbitraryResourceWorker", "[common][resources]") {
spriteConfiguration.GetAnimations().AddAnimation(anim);
gd::Object obj("myObject", "", spriteConfiguration.Clone());
layout.InsertObject(obj, 0);
layout.GetObjects().InsertObject(obj, 0);
worker.files.clear();
worker.images.clear();
@@ -378,8 +378,9 @@ TEST_CASE("ArbitraryResourceWorker", "[common][resources]") {
auto& layout = project.InsertNewLayout("Scene", 0);
layout.InsertNewLayer("MyLayer", 0);
auto& layer = layout.GetLayer("MyLayer");
auto& object = layout.InsertNewObject(project, "MyExtension::Sprite", "MyObject", 0);
auto& effect = object.GetEffects().InsertNewEffect("MyEffect", 0);
auto &object = layout.GetObjects().InsertNewObject(
project, "MyExtension::Sprite", "MyObject", 0);
auto &effect = object.GetEffects().InsertNewEffect("MyEffect", 0);
effect.SetEffectType("MyExtension::EffectWithResource");
effect.SetStringParameter("texture", "res1");
@@ -440,7 +441,7 @@ TEST_CASE("ArbitraryResourceWorker", "[common][resources]") {
spriteConfiguration.GetAnimations().AddAnimation(anim);
gd::Object obj("myObject", "", spriteConfiguration.Clone());
layout.InsertObject(obj, 0);
layout.GetObjects().InsertObject(obj, 0);
worker.files.clear();
worker.images.clear();
@@ -894,8 +895,9 @@ TEST_CASE("ArbitraryResourceWorker", "[common][resources]") {
auto& layout = project.InsertNewLayout("Scene", 0);
layout.InsertNewLayer("MyLayer", 0);
auto& layer = layout.GetLayer("MyLayer");
auto& object = layout.InsertNewObject(project, "MyExtension::Sprite", "MyObject", 0);
auto& effect = object.GetEffects().InsertNewEffect("MyEffect", 0);
auto &object = layout.GetObjects().InsertNewObject(
project, "MyExtension::Sprite", "MyObject", 0);
auto &effect = object.GetEffects().InsertNewEffect("MyEffect", 0);
effect.SetEffectType("MyExtension::EffectWithResource");
effect.SetStringParameter("texture", "res1");

View File

@@ -52,7 +52,7 @@ void AddAnotherEventsBasedExtensionWithDependency(gd::Project &project) {
eventsBasedObject.SetFullName("My events based object");
eventsBasedObject.SetDescription("An events based object for test");
gd::Object &object = eventsBasedObject.InsertNewObject(
gd::Object &object = eventsBasedObject.GetObjects().InsertNewObject(
project, "MyExtension::Sprite", "MyObject", 0);
gd::Behavior *behavior =
object.AddNewBehavior(project, "MyEventsExtension::MyEventsBasedBehavior",
@@ -65,8 +65,8 @@ void SetupProject(gd::Project &project, gd::Platform &platform) {
AddEventsBasedExtension(project);
gd::Layout &layout = project.InsertNewLayout("Scene", 0);
gd::Object &object =
layout.InsertNewObject(project, "MyExtension::Sprite", "MyObject", 0);
gd::Object &object = layout.GetObjects().InsertNewObject(
project, "MyExtension::Sprite", "MyObject", 0);
gd::Behavior *behavior =
object.AddNewBehavior(project, "MyEventsExtension::MyEventsBasedBehavior",
"MyEventsBasedBehavior");
@@ -127,7 +127,8 @@ TEST_CASE("BehaviorSerialization", "[common]") {
gd::Platform platform;
gd::Project writtenProject;
SetupProject(writtenProject, platform);
CheckBehaviorProperty(writtenProject.GetLayout("Scene"));
CheckBehaviorProperty(
writtenProject.GetLayout("Scene").GetObjects());
SerializerElement projectElement;
writtenProject.SerializeTo(projectElement);
@@ -136,7 +137,7 @@ TEST_CASE("BehaviorSerialization", "[common]") {
gd::Project readProject;
readProject.AddPlatform(platform);
readProject.UnserializeFrom(projectElement);
CheckBehaviorProperty(readProject.GetLayout("Scene"));
CheckBehaviorProperty(readProject.GetLayout("Scene").GetObjects());
}
SECTION("Load a project with a property value on a custom behavior that no longer exists") {
@@ -158,7 +159,7 @@ TEST_CASE("BehaviorSerialization", "[common]") {
// Add the events-based behavior back
AddEventsBasedExtension(readProject);
CheckBehaviorProperty(readProject.GetLayout("Scene"));
CheckBehaviorProperty(readProject.GetLayout("Scene").GetObjects());
}
SECTION("Save and load a project with an event based extension dependency") {
@@ -203,7 +204,9 @@ TEST_CASE("BehaviorSerialization", "[common]") {
// extension.
REQUIRE(readProject.HasEventsBasedObject(
"MyOtherEventsExtension::MyEventsBasedObject"));
CheckBehaviorProperty(readProject.GetEventsBasedObject(
"MyOtherEventsExtension::MyEventsBasedObject"));
CheckBehaviorProperty(
readProject
.GetEventsBasedObject("MyOtherEventsExtension::MyEventsBasedObject")
.GetObjects());
}
}

View File

@@ -39,8 +39,8 @@ TEST_CASE("EventsBehaviorRenamer (expressions)", "[common]") {
auto projectScopedContainers =
gd::ProjectScopedContainers::MakeNewProjectScopedContainersForProjectAndLayout(project, layout1);
auto &object1 =
layout1.InsertNewObject(project, "MyExtension::Sprite", "Object1", 0);
auto &object1 = layout1.GetObjects().InsertNewObject(
project, "MyExtension::Sprite", "Object1", 0);
object1.AddNewBehavior(project, "MyExtension::MyBehavior", "MyBehavior");
object1.AddNewBehavior(project, "MyExtension::MyBehavior", "MyBehavior2");
@@ -80,8 +80,8 @@ TEST_CASE("EventsBehaviorRenamer (instructions)", "[common]") {
auto projectScopedContainers =
gd::ProjectScopedContainers::MakeNewProjectScopedContainersForProjectAndLayout(project, layout1);
auto &object1 =
layout1.InsertNewObject(project, "MyExtension::Sprite", "Object1", 0);
auto &object1 = layout1.GetObjects().InsertNewObject(
project, "MyExtension::Sprite", "Object1", 0);
object1.AddNewBehavior(project, "MyExtension::MyBehavior", "MyBehavior");
object1.AddNewBehavior(project, "MyExtension::MyBehavior", "MyBehavior2");

View File

@@ -63,7 +63,8 @@ TEST_CASE("Events-based extension", "[common]") {
SetupProjectWithDummyPlatform(project, platform);
auto &eventsExtension = SetupProjectWithEventsFunctionExtension(project);
auto &layout1 = project.InsertNewLayout("Layout1", 0);
auto &object = layout1.InsertNewObject(project, "MyExtension::Sprite", "Object1", 0);
auto &object = layout1.GetObjects().InsertNewObject(
project, "MyExtension::Sprite", "Object1", 0);
// Attach a behavior to an object.
auto *behavior = object.AddNewBehavior(project, "MyEventsExtension::MyEventsBasedBehavior", "MyEventsBasedBehavior");

View File

@@ -195,7 +195,8 @@ TEST_CASE("EventsIdentifiersFinder (object timers)", "[common]") {
DeclareTimerExtension(project, platform);
auto &layout = project.InsertNewLayout("Layout1", 0);
auto &object = layout.InsertNewObject(project, "", "MyObject", 0);
auto &object = layout.GetObjects().InsertNewObject(project, "",
"MyObject", 0);
layout.GetEvents().InsertEvent(UseObjectTimer("MyObject", "MyObjectTimer"));
auto identifierExpressions =
@@ -212,8 +213,10 @@ TEST_CASE("EventsIdentifiersFinder (object timers)", "[common]") {
DeclareTimerExtension(project, platform);
auto &layout = project.InsertNewLayout("Layout1", 0);
auto &object = layout.InsertNewObject(project, "", "MyObject", 0);
layout.GetEvents().InsertEvent(UseObjectTimerInExpression("MyObject", "MyObjectTimer"));
auto &object = layout.GetObjects().InsertNewObject(project, "",
"MyObject", 0);
layout.GetEvents().InsertEvent(
UseObjectTimerInExpression("MyObject", "MyObjectTimer"));
auto identifierExpressions =
gd::EventsIdentifiersFinder::FindAllIdentifierExpressions(
@@ -229,7 +232,8 @@ TEST_CASE("EventsIdentifiersFinder (object timers)", "[common]") {
DeclareTimerExtension(project, platform);
auto &layout = project.InsertNewLayout("Layout1", 0);
auto &object = layout.InsertNewObject(project, "", "MyObject", 0);
auto &object = layout.GetObjects().InsertNewObject(project, "",
"MyObject", 0);
auto &externalEvents = project.InsertNewExternalEvents("ExternalEvents", 0);
externalEvents.GetEvents().InsertEvent(
UseObjectTimer("MyObject", "MyObjectTimer"));
@@ -249,8 +253,10 @@ TEST_CASE("EventsIdentifiersFinder (object timers)", "[common]") {
DeclareTimerExtension(project, platform);
auto &layout = project.InsertNewLayout("Layout1", 0);
auto &object1 = layout.InsertNewObject(project, "", "MyObject1", 0);
auto &object2 = layout.InsertNewObject(project, "", "MyObject2", 0);
auto &object1 = layout.GetObjects().InsertNewObject(
project, "", "MyObject1", 0);
auto &object2 = layout.GetObjects().InsertNewObject(
project, "", "MyObject2", 0);
layout.GetEvents().InsertEvent(
UseObjectTimer("MyObject1", "MyObjectTimer1"));
layout.GetEvents().InsertEvent(
@@ -270,8 +276,10 @@ TEST_CASE("EventsIdentifiersFinder (object timers)", "[common]") {
DeclareTimerExtension(project, platform);
auto &layout = project.InsertNewLayout("Layout1", 0);
auto &object1 = layout.InsertNewObject(project, "", "MyObject1", 0);
auto &object2 = layout.InsertNewObject(project, "", "MyObject2", 0);
auto &object1 = layout.GetObjects().InsertNewObject(
project, "", "MyObject1", 0);
auto &object2 = layout.GetObjects().InsertNewObject(
project, "", "MyObject2", 0);
auto &externalEvents = project.InsertNewExternalEvents("ExternalEvents", 0);
externalEvents.GetEvents().InsertEvent(
UseObjectTimer("MyObject1", "MyObjectTimer1"));

View File

@@ -268,7 +268,8 @@ TEST_CASE("EventsVariablesFinder (FindAllObjectVariables)", "[common]") {
DeclareVariableExtension(project, platform);
auto &layout = project.InsertNewLayout("Layout1", 0);
auto &object = layout.InsertNewObject(project, "", "MyObject", 0);
auto &object = layout.GetObjects().InsertNewObject(project, "",
"MyObject", 0);
layout.GetEvents().InsertEvent(
UseObjectVariable("MyObject", "MyObjectVariable"));
@@ -285,7 +286,8 @@ TEST_CASE("EventsVariablesFinder (FindAllObjectVariables)", "[common]") {
DeclareVariableExtension(project, platform);
auto &layout = project.InsertNewLayout("Layout1", 0);
auto &object = layout.InsertNewObject(project, "", "MyObject", 0);
auto &object = layout.GetObjects().InsertNewObject(project, "",
"MyObject", 0);
layout.GetEvents().InsertEvent(
UseObjectVariableInExpression("MyObject", "MyObjectVariable"));
@@ -302,7 +304,8 @@ TEST_CASE("EventsVariablesFinder (FindAllObjectVariables)", "[common]") {
DeclareVariableExtension(project, platform);
auto &layout = project.InsertNewLayout("Layout1", 0);
auto &object = layout.InsertNewObject(project, "", "MyObject", 0);
auto &object = layout.GetObjects().InsertNewObject(project, "",
"MyObject", 0);
auto &externalEvents = project.InsertNewExternalEvents("ExternalEvents", 0);
externalEvents.GetEvents().InsertEvent(
UseObjectVariable("MyObject", "MyObjectVariable"));
@@ -321,8 +324,10 @@ TEST_CASE("EventsVariablesFinder (FindAllObjectVariables)", "[common]") {
DeclareVariableExtension(project, platform);
auto &layout = project.InsertNewLayout("Layout1", 0);
auto &object1 = layout.InsertNewObject(project, "", "MyObject1", 0);
auto &object2 = layout.InsertNewObject(project, "", "MyObject2", 0);
auto &object1 = layout.GetObjects().InsertNewObject(
project, "", "MyObject1", 0);
auto &object2 = layout.GetObjects().InsertNewObject(
project, "", "MyObject2", 0);
layout.GetEvents().InsertEvent(
UseObjectVariable("MyObject1", "MyObjectVariable1"));
layout.GetEvents().InsertEvent(
@@ -342,8 +347,10 @@ TEST_CASE("EventsVariablesFinder (FindAllObjectVariables)", "[common]") {
DeclareVariableExtension(project, platform);
auto &layout = project.InsertNewLayout("Layout1", 0);
auto &object1 = layout.InsertNewObject(project, "", "MyObject1", 0);
auto &object2 = layout.InsertNewObject(project, "", "MyObject2", 0);
auto &object1 = layout.GetObjects().InsertNewObject(
project, "", "MyObject1", 0);
auto &object2 = layout.GetObjects().InsertNewObject(
project, "", "MyObject2", 0);
auto &externalEvents = project.InsertNewExternalEvents("ExternalEvents", 0);
externalEvents.GetEvents().InsertEvent(
UseObjectVariable("MyObject1", "MyObjectVariable1"));

View File

@@ -46,31 +46,39 @@ TEST_CASE("ExpressionCodeGenerator", "[common][events]") {
variable.PushNew().SetString("3");
}
auto &mySpriteObject = layout1.InsertNewObject(project, "MyExtension::Sprite", "MySpriteObject", 0);
auto &mySpriteObject = layout1.GetObjects().InsertNewObject(
project, "MyExtension::Sprite", "MySpriteObject", 0);
mySpriteObject.GetVariables().InsertNew("MyNumberVariable").SetValue(123);
mySpriteObject.GetVariables().InsertNew("MyStringVariable").SetString("Test");
mySpriteObject.GetVariables().InsertNew("MyStructureVariable").GetChild("MyStringChild").SetString("Test");
layout1.InsertNewObject(
project, "MyExtension::Sprite", "MyOtherSpriteObject", 1);
layout1.InsertNewObject(project,
"MyExtension::FakeObjectWithDefaultBehavior",
"FakeObjectWithDefaultBehavior",
2);
mySpriteObject.GetVariables()
.InsertNew("MyStructureVariable")
.GetChild("MyStringChild")
.SetString("Test");
layout1.GetObjects().InsertNewObject(project, "MyExtension::Sprite",
"MyOtherSpriteObject", 1);
layout1.GetObjects().InsertNewObject(
project, "MyExtension::FakeObjectWithDefaultBehavior",
"FakeObjectWithDefaultBehavior", 2);
// Also insert a variable having the same name as an object:
layout1.InsertNewObject(project, "MyExtension::Sprite", "ObjectWithNameReused", 3);
layout1.GetVariables().InsertNew("ObjectWithNameReused", 3).GetChild("MyChild");
layout1.GetObjects().InsertNewObject(project, "MyExtension::Sprite",
"ObjectWithNameReused", 3);
layout1.GetVariables()
.InsertNew("ObjectWithNameReused", 3)
.GetChild("MyChild");
// Also insert a global variable having the same name as a scene variable:
layout1.GetVariables().InsertNew("SceneVariableWithNameReused", 4);
project.GetVariables().InsertNew("SceneVariableWithNameReused", 0);
auto &group = layout1.GetObjectGroups().InsertNew("AllObjects");
auto &group =
layout1.GetObjects().GetObjectGroups().InsertNew("AllObjects");
group.AddObject("MySpriteObject");
group.AddObject("MyOtherSpriteObject");
group.AddObject("FakeObjectWithDefaultBehavior");
auto &spriteGroup = layout1.GetObjectGroups().InsertNew("MySpriteObjects");
auto &spriteGroup = layout1.GetObjects().GetObjectGroups().InsertNew(
"MySpriteObjects");
spriteGroup.AddObject("MySpriteObject");
spriteGroup.AddObject("MyOtherSpriteObject");

View File

@@ -23,8 +23,8 @@ TEST_CASE("ExpressionCompletionFinder", "[common][events]") {
SetupProjectWithDummyPlatform(project, platform);
auto& layout1 = project.InsertNewLayout("Layout1", 0);
layout1.GetVariables().InsertNew("myVariable");
auto& object1 =
layout1.InsertNewObject(project, "MyExtension::Sprite", "MyObject", 0);
auto &object1 = layout1.GetObjects().InsertNewObject(
project, "MyExtension::Sprite", "MyObject", 0);
object1.GetVariables().InsertNew("myObjectVariable");
gd::ProjectScopedContainers projectScopedContainers =
@@ -55,8 +55,8 @@ TEST_CASE("ExpressionCompletionFinder", "[common][events]") {
SECTION("Object or expression completions when type is string") {
// clang-format off
std::vector<gd::String> expectedCompletions{
"{ 0, string, 2, no prefix, MyObject, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, with object configuration }",
"{ 3, no type, 2, no prefix, myVariable, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, no object configuration }",
"{ 0, string, 3, no prefix, MyObject, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, with object configuration }",
"{ 3, no type, 3, no prefix, myVariable, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, no object configuration }",
gd::ExpressionCompletionDescription::ForExpressionWithPrefix("string", "My", 0, 2).ToString()
};
// clang-format on
@@ -67,8 +67,8 @@ TEST_CASE("ExpressionCompletionFinder", "[common][events]") {
SECTION("Object or expression completions when type is number") {
// clang-format off
std::vector<gd::String> expectedCompletions{
"{ 0, number, 2, no prefix, MyObject, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, with object configuration }",
"{ 3, no type, 2, no prefix, myVariable, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, no object configuration }",
"{ 0, number, 3, no prefix, MyObject, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, with object configuration }",
"{ 3, no type, 3, no prefix, myVariable, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, no object configuration }",
gd::ExpressionCompletionDescription::ForExpressionWithPrefix("number", "My", 0, 2).ToString()
};
// clang-format on
@@ -79,8 +79,8 @@ TEST_CASE("ExpressionCompletionFinder", "[common][events]") {
SECTION("Object or expression completions when type is number|string") {
// clang-format off
std::vector<gd::String> expectedCompletions{
"{ 0, number|string, 2, no prefix, MyObject, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, with object configuration }",
"{ 3, no type, 2, no prefix, myVariable, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, no object configuration }",
"{ 0, number|string, 3, no prefix, MyObject, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, with object configuration }",
"{ 3, no type, 3, no prefix, myVariable, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, no object configuration }",
gd::ExpressionCompletionDescription::ForExpressionWithPrefix("number|string", "My", 0, 2).ToString()
};
// clang-format on
@@ -94,8 +94,8 @@ TEST_CASE("ExpressionCompletionFinder", "[common][events]") {
SECTION("Object or expression completions in a variable name") {
// clang-format off
std::vector<gd::String> expectedCompletions{
"{ 0, string, 2, no prefix, MyObject, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, with object configuration }",
"{ 3, no type, 2, no prefix, myVariable, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, no object configuration }",
"{ 0, string, 3, no prefix, MyObject, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, with object configuration }",
"{ 3, no type, 3, no prefix, myVariable, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, no object configuration }",
gd::ExpressionCompletionDescription::ForExpressionWithPrefix("string", "My", 0, 2).ToString()
};
// clang-format on
@@ -115,8 +115,8 @@ TEST_CASE("ExpressionCompletionFinder", "[common][events]") {
SECTION("Object or expression completions in a variable index") {
// clang-format off
std::vector<gd::String> expectedCompletions{
"{ 0, number, 2, no prefix, MyObject, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, with object configuration }",
"{ 3, no type, 2, no prefix, myVariable, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, no object configuration }",
"{ 0, number, 3, no prefix, MyObject, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, with object configuration }",
"{ 3, no type, 3, no prefix, myVariable, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, no object configuration }",
gd::ExpressionCompletionDescription::ForExpressionWithPrefix("number", "My", 0, 2).ToString()
};
// clang-format on
@@ -136,7 +136,7 @@ TEST_CASE("ExpressionCompletionFinder", "[common][events]") {
SECTION("Object when type is an object") {
// clang-format off
std::vector<gd::String> expectedCompletions{
"{ 0, object, 2, no prefix, MyObject, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, with object configuration }",
"{ 0, object, 3, no prefix, MyObject, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, with object configuration }",
};
// clang-format on
REQUIRE(getCompletionsFor("object", "My", 0) == expectedCompletions);
@@ -149,7 +149,7 @@ TEST_CASE("ExpressionCompletionFinder", "[common][events]") {
// result in different code generation):
// clang-format off
std::vector<gd::String> expectedCompletions{
"{ 0, objectPtr, 2, no prefix, MyObject, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, with object configuration }",
"{ 0, objectPtr, 3, no prefix, MyObject, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, with object configuration }",
};
// clang-format on
REQUIRE(getCompletionsFor("objectPtr", "My", 0) == expectedCompletions);
@@ -204,8 +204,8 @@ TEST_CASE("ExpressionCompletionFinder", "[common][events]") {
// clang-format off
std::vector<gd::String> expectedCompletions{
"{ 0, unknown, 2, no prefix, MyObject, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, with object configuration }",
"{ 3, no type, 2, no prefix, myVariable, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, no object configuration }",
"{ 0, unknown, 3, no prefix, MyObject, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, with object configuration }",
"{ 3, no type, 3, no prefix, myVariable, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, no object configuration }",
gd::ExpressionCompletionDescription::ForExpressionWithPrefix("unknown", "My", 9, 10).ToString()
};
// clang-format on
@@ -215,7 +215,7 @@ TEST_CASE("ExpressionCompletionFinder", "[common][events]") {
SECTION("Function with a Variable as argument") {
// clang-format off
std::vector<gd::String> expectedCompletions{
"{ 3, no type, 2, no prefix, myVariable, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, no object configuration }",
"{ 3, no type, 3, no prefix, myVariable, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, no object configuration }",
};
// clang-format on
REQUIRE(getCompletionsFor("number",
@@ -225,7 +225,7 @@ TEST_CASE("ExpressionCompletionFinder", "[common][events]") {
SECTION("Object function with a Variable as argument") {
// clang-format off
std::vector<gd::String> expectedCompletions{
"{ 3, no type, 2, no prefix, myObjectVariable, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, no object configuration }",
"{ 3, no type, 3, no prefix, myObjectVariable, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, no object configuration }",
};
// clang-format on
REQUIRE(getCompletionsFor("number",
@@ -254,7 +254,7 @@ TEST_CASE("ExpressionCompletionFinder", "[common][events]") {
SECTION("Test with string type") {
// clang-format off
std::vector<gd::String> expectedObjectCompletions{
"{ 0, string, 2, no prefix, MyObject, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, with object configuration }"
"{ 0, string, 3, no prefix, MyObject, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, with object configuration }"
};
std::vector<gd::String> expectedBehaviorOrFunctionCompletions{
gd::ExpressionCompletionDescription::ForBehaviorWithPrefix("Func", 9, 13, "MyObject").ToString(),
@@ -277,7 +277,7 @@ TEST_CASE("ExpressionCompletionFinder", "[common][events]") {
SECTION("Test with 'number|string' type") {
// clang-format off
std::vector<gd::String> expectedObjectCompletions{
"{ 0, number|string, 2, no prefix, MyObject, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, with object configuration }"
"{ 0, number|string, 3, no prefix, MyObject, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, with object configuration }"
};
std::vector<gd::String> expectedBehaviorOrFunctionCompletions{
gd::ExpressionCompletionDescription::ForBehaviorWithPrefix("Func", 9, 13, "MyObject").ToString(),
@@ -303,7 +303,7 @@ TEST_CASE("ExpressionCompletionFinder", "[common][events]") {
SECTION("Test 1") {
// clang-format off
std::vector<gd::String> expectedObjectCompletions{
"{ 0, string, 2, no prefix, MyObject, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, with object configuration }"
"{ 0, string, 3, no prefix, MyObject, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, with object configuration }"
};
std::vector<gd::String> expectedBehaviorOrFunctionCompletions{
gd::ExpressionCompletionDescription::ForBehaviorWithPrefix("Func", 9, 13, "MyObject").ToString(),
@@ -336,7 +336,7 @@ TEST_CASE("ExpressionCompletionFinder", "[common][events]") {
SECTION("Test 1") {
// clang-format off
std::vector<gd::String> expectedObjectCompletions{
"{ 0, string, 2, no prefix, MyObject, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, with object configuration }"
"{ 0, string, 3, no prefix, MyObject, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, with object configuration }"
};
std::vector<gd::String> expectedBehaviorCompletions{
gd::ExpressionCompletionDescription::ForBehaviorWithPrefix("MyBehavior", 9, 19, "MyObject").ToString()};
@@ -366,7 +366,7 @@ TEST_CASE("ExpressionCompletionFinder", "[common][events]") {
SECTION("Test 2") {
// clang-format off
std::vector<gd::String> expectedObjectCompletions{
"{ 0, string, 2, no prefix, MyObject, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, with object configuration }"
"{ 0, string, 3, no prefix, MyObject, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, with object configuration }"
};
std::vector<gd::String> expectedBehaviorCompletions{
gd::ExpressionCompletionDescription::ForBehaviorWithPrefix("MyBehavior", 9, 19, "MyObject").ToString()
@@ -396,7 +396,7 @@ TEST_CASE("ExpressionCompletionFinder", "[common][events]") {
SECTION("Test 1") {
// clang-format off
std::vector<gd::String> expectedObjectCompletions{
"{ 0, string, 2, no prefix, MyObject, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, with object configuration }"
"{ 0, string, 3, no prefix, MyObject, no object name, no behavior name, non-exact, not last parameter, no parameter metadata, with object configuration }"
};
std::vector<gd::String> expectedBehaviorCompletions{
gd::ExpressionCompletionDescription::ForBehaviorWithPrefix("MyBehavior", 9, 19, "MyObject").ToString()

View File

@@ -57,7 +57,8 @@ TEST_CASE("ExpressionNodeLocationFinder", "[common][events]") {
gd::Platform platform;
SetupProjectWithDummyPlatform(project, platform);
auto& layout1 = project.InsertNewLayout("Layout1", 0);
layout1.InsertNewObject(project, "MyExtension::Sprite", "MySpriteObject", 0);
layout1.GetObjects().InsertNewObject(project, "MyExtension::Sprite",
"MySpriteObject", 0);
gd::ExpressionParser2 parser;

View File

@@ -35,29 +35,36 @@ TEST_CASE("ExpressionParser2", "[common][events]") {
// Create an instance of BuiltinObject.
// This is not possible in practice.
auto &myObject = layout1.InsertNewObject(project, "", "MyObject", 0);
auto &myObject =
layout1.GetObjects().InsertNewObject(project, "", "MyObject", 0);
myObject.AddNewBehavior(project, "MyExtension::MyBehavior", "MyBehavior");
auto &myGroup = layout1.GetObjectGroups().InsertNew("MyGroup");
auto &myGroup =
layout1.GetObjects().GetObjectGroups().InsertNew("MyGroup");
myGroup.AddObject(myObject.GetName());
layout1.GetObjectGroups().InsertNew("EmptyGroup");
layout1.GetObjects().GetObjectGroups().InsertNew("EmptyGroup");
auto &mySpriteObject = layout1.InsertNewObject(project, "MyExtension::Sprite", "MySpriteObject", 1);
auto &mySpriteObject = layout1.GetObjects().InsertNewObject(
project, "MyExtension::Sprite", "MySpriteObject", 1);
mySpriteObject.GetVariables().InsertNew("MyVariable");
mySpriteObject.GetVariables().InsertNew("MyVariable2");
mySpriteObject.GetVariables().InsertNew("MyVariable3");
mySpriteObject.GetVariables().InsertNew("MyNumberVariable").SetValue(123);
mySpriteObject.GetVariables().InsertNew("MyStringVariable").SetString("Test");
auto &mySpriteObject2 = layout1.InsertNewObject(project, "MyExtension::Sprite", "MySpriteObject2", 1);
// A variable with the same name as the object.
mySpriteObject.GetVariables().InsertNew("MySpriteObject");
auto &mySpriteObject2 = layout1.GetObjects().InsertNewObject(
project, "MyExtension::Sprite", "MySpriteObject2", 1);
mySpriteObject2.GetVariables().InsertNew("MyVariable", 0);
mySpriteObject2.GetVariables().InsertNew("MyVariable2", 1);
layout1.InsertNewObject(project,
"MyExtension::FakeObjectWithDefaultBehavior",
"FakeObjectWithDefaultBehavior",
2);
layout1.GetObjects().InsertNewObject(
project, "MyExtension::FakeObjectWithDefaultBehavior",
"FakeObjectWithDefaultBehavior", 2);
auto &mySpriteGroup = layout1.GetObjectGroups().InsertNew("MySpriteObjects", 0);
auto &mySpriteGroup =
layout1.GetObjects().GetObjectGroups().InsertNew(
"MySpriteObjects", 0);
mySpriteGroup.AddObject("MySpriteObject");
mySpriteGroup.AddObject("MySpriteObject2");
@@ -1685,6 +1692,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 =

View File

@@ -20,7 +20,8 @@ TEST_CASE("ExpressionParser2 - Benchmarks", "[common][events]") {
gd::Platform platform;
SetupProjectWithDummyPlatform(project, platform);
auto &layout1 = project.InsertNewLayout("Layout1", 0);
layout1.InsertNewObject(project, "MyExtension::Sprite", "MySpriteObject", 0);
layout1.GetObjects().InsertNewObject(project, "MyExtension::Sprite",
"MySpriteObject", 0);
auto projectScopedContainers = gd::ProjectScopedContainers::MakeNewProjectScopedContainersForProjectAndLayout(project, layout1);

View File

@@ -19,7 +19,8 @@ TEST_CASE("ExpressionParser2 - Naughty strings", "[common][events]") {
gd::Platform platform;
SetupProjectWithDummyPlatform(project, platform);
auto &layout1 = project.InsertNewLayout("Layout1", 0);
layout1.InsertNewObject(project, "MyExtension::Sprite", "MySpriteObject", 0);
layout1.GetObjects().InsertNewObject(project, "MyExtension::Sprite",
"MySpriteObject", 0);
gd::ExpressionParser2 parser;

View File

@@ -18,7 +18,8 @@ TEST_CASE("ExpressionParser2NodePrinter", "[common][events]") {
gd::Platform platform;
SetupProjectWithDummyPlatform(project, platform);
auto &layout1 = project.InsertNewLayout("Layout1", 0);
layout1.InsertNewObject(project, "MyExtension::Sprite", "MySpriteObject", 0);
layout1.GetObjects().InsertNewObject(project, "MyExtension::Sprite",
"MySpriteObject", 0);
gd::ExpressionParser2 parser;

View File

@@ -25,13 +25,13 @@ TEST_CASE("Layout", "[common]") {
SetupProjectWithDummyPlatform(project, platform);
gd::Layout &layout = project.InsertNewLayout("Scene", 0);
gd::Object &object =
layout.InsertNewObject(project, "MyExtension::Sprite", "MyObject", 0);
gd::Object &object = layout.GetObjects().InsertNewObject(
project, "MyExtension::Sprite", "MyObject", 0);
object.AddNewBehavior(project, "MyExtension::MyBehavior", "MyBehavior");
REQUIRE(GetTypeOfBehaviorInObjectOrGroup(project, layout, "MyObject",
"MyBehavior", true) ==
"MyExtension::MyBehavior");
REQUIRE(GetTypeOfBehaviorInObjectOrGroup(
project.GetObjects(), layout.GetObjects(),
"MyObject", "MyBehavior", true) == "MyExtension::MyBehavior");
}
SECTION("Give an empty type for an object that doesn't have the behavior") {
@@ -40,11 +40,12 @@ TEST_CASE("Layout", "[common]") {
SetupProjectWithDummyPlatform(project, platform);
gd::Layout &layout = project.InsertNewLayout("Scene", 0);
gd::Object &object =
layout.InsertNewObject(project, "MyExtension::Sprite", "MyObject", 0);
gd::Object &object = layout.GetObjects().InsertNewObject(
project, "MyExtension::Sprite", "MyObject", 0);
REQUIRE(GetTypeOfBehaviorInObjectOrGroup(project, layout, "MyObject",
"MyBehavior", true) == "");
REQUIRE(GetTypeOfBehaviorInObjectOrGroup(
project.GetObjects(), layout.GetObjects(),
"MyObject", "MyBehavior", true) == "");
}
SECTION("Find the type of a behavior in a group") {
@@ -53,63 +54,70 @@ TEST_CASE("Layout", "[common]") {
SetupProjectWithDummyPlatform(project, platform);
gd::Layout &layout = project.InsertNewLayout("Scene", 0);
gd::Object &object1 =
layout.InsertNewObject(project, "MyExtension::Sprite", "MyObject1", 0);
gd::Object &object1 = layout.GetObjects().InsertNewObject(
project, "MyExtension::Sprite", "MyObject1", 0);
object1.AddNewBehavior(project, "MyExtension::MyBehavior", "MyBehavior");
gd::Object &object2 =
layout.InsertNewObject(project, "MyExtension::Sprite", "MyObject2", 0);
gd::Object &object2 = layout.GetObjects().InsertNewObject(
project, "MyExtension::Sprite", "MyObject2", 0);
object2.AddNewBehavior(project, "MyExtension::MyBehavior", "MyBehavior");
auto &group = layout.GetObjectGroups().InsertNew("MyGroup", 0);
auto &group =
layout.GetObjects().GetObjectGroups().InsertNew("MyGroup", 0);
group.AddObject(object1.GetName());
group.AddObject(object2.GetName());
REQUIRE(GetTypeOfBehaviorInObjectOrGroup(project, layout, "MyGroup",
"MyBehavior", true) ==
"MyExtension::MyBehavior");
REQUIRE(GetTypeOfBehaviorInObjectOrGroup(
project.GetObjects(), layout.GetObjects(),
"MyGroup", "MyBehavior", true) == "MyExtension::MyBehavior");
}
SECTION("Give an empty type for a group with an object missing the behavior") {
SECTION(
"Give an empty type for a group with an object missing the behavior") {
gd::Platform platform;
gd::Project project;
SetupProjectWithDummyPlatform(project, platform);
gd::Layout &layout = project.InsertNewLayout("Scene", 0);
gd::Object &object1 =
layout.InsertNewObject(project, "MyExtension::Sprite", "MyObject1", 0);
gd::Object &object1 = layout.GetObjects().InsertNewObject(
project, "MyExtension::Sprite", "MyObject1", 0);
object1.AddNewBehavior(project, "MyExtension::MyBehavior", "MyBehavior");
gd::Object &object2 =
layout.InsertNewObject(project, "MyExtension::Sprite", "MyObject2", 0);
gd::Object &object2 = layout.GetObjects().InsertNewObject(
project, "MyExtension::Sprite", "MyObject2", 0);
// object2 doesn't have the behavior.
auto &group = layout.GetObjectGroups().InsertNew("MyGroup", 0);
auto &group =
layout.GetObjects().GetObjectGroups().InsertNew("MyGroup", 0);
group.AddObject(object1.GetName());
group.AddObject(object2.GetName());
REQUIRE(GetTypeOfBehaviorInObjectOrGroup(project, layout, "MyGroup",
"MyBehavior", true) == "");
REQUIRE(GetTypeOfBehaviorInObjectOrGroup(
project.GetObjects(), layout.GetObjects(),
"MyGroup", "MyBehavior", true) == "");
}
SECTION("Give an empty type for a group with behaviors of same name but different types") {
SECTION("Give an empty type for a group with behaviors of same name but "
"different types") {
gd::Platform platform;
gd::Project project;
SetupProjectWithDummyPlatform(project, platform);
gd::Layout &layout = project.InsertNewLayout("Scene", 0);
gd::Object &object1 =
layout.InsertNewObject(project, "MyExtension::Sprite", "MyObject1", 0);
gd::Object &object1 = layout.GetObjects().InsertNewObject(
project, "MyExtension::Sprite", "MyObject1", 0);
object1.AddNewBehavior(project, "MyExtension::MyBehavior", "MyBehavior");
gd::Object &object2 =
layout.InsertNewObject(project, "MyExtension::Sprite", "MyObject2", 0);
gd::Object &object2 = layout.GetObjects().InsertNewObject(
project, "MyExtension::Sprite", "MyObject2", 0);
object2.AddNewBehavior(project, "MyExtension::MyOtherBehavior",
"MyBehavior");
auto &group = layout.GetObjectGroups().InsertNew("MyGroup", 0);
auto &group =
layout.GetObjects().GetObjectGroups().InsertNew("MyGroup", 0);
group.AddObject(object1.GetName());
group.AddObject(object2.GetName());
REQUIRE(GetTypeOfBehaviorInObjectOrGroup(project, layout, "MyGroup",
"MyBehavior", true) == "");
REQUIRE(GetTypeOfBehaviorInObjectOrGroup(
project.GetObjects(), layout.GetObjects(),
"MyGroup", "MyBehavior", true) == "");
}
SECTION("Give an empty type for an empty group") {
@@ -118,9 +126,11 @@ TEST_CASE("Layout", "[common]") {
SetupProjectWithDummyPlatform(project, platform);
gd::Layout &layout = project.InsertNewLayout("Scene", 0);
auto &group = layout.GetObjectGroups().InsertNew("MyGroup", 0);
auto &group =
layout.GetObjects().GetObjectGroups().InsertNew("MyGroup", 0);
REQUIRE(GetTypeOfBehaviorInObjectOrGroup(project, layout, "MyGroup",
"MyBehavior", true) == "");
REQUIRE(GetTypeOfBehaviorInObjectOrGroup(
project.GetObjects(), layout.GetObjects(),
"MyGroup", "MyBehavior", true) == "");
}
}

View File

@@ -36,7 +36,7 @@ TEST_CASE("Object", "[common]") {
SetupProjectWithDummyPlatform(project, platform);
gd::Layout &layout = project.InsertNewLayout("Scene", 0);
gd::Object &object = layout.InsertNewObject(
gd::Object &object = layout.GetObjects().InsertNewObject(
project, "MyExtension::FakeObjectWithDefaultBehavior", "MyObject", 0);
REQUIRE(object.HasBehaviorNamed("Effect"));

View File

@@ -43,8 +43,8 @@ TEST_CASE("ObjectAssetSerializer", "[common]") {
"MyEventsBasedObject", 0);
eventsBasedObject.SetFullName("My events based object");
eventsBasedObject.SetDescription("An events based object for test");
eventsBasedObject.InsertNewObject(project, "MyExtension::Sprite", "MyChild",
0);
eventsBasedObject.GetObjects().InsertNewObject(
project, "MyExtension::Sprite", "MyChild", 0);
auto &resourceManager = project.GetResourcesManager();
gd::ImageResource imageResource;
@@ -54,7 +54,7 @@ TEST_CASE("ObjectAssetSerializer", "[common]") {
resourceManager.AddResource(imageResource);
gd::Layout &layout = project.InsertNewLayout("Scene", 0);
gd::Object &object = layout.InsertNewObject(
gd::Object &object = layout.GetObjects().InsertNewObject(
project, "MyEventsExtension::MyEventsBasedObject", "MyObject", 0);
auto &configuration = object.GetConfiguration();
auto *customObjectConfiguration =

View File

@@ -43,8 +43,8 @@ gd::Object &SetupProjectWithSprite(gd::Project &project,
SetupProjectWithDummyPlatform(project, platform);
gd::Layout &layout = project.InsertNewLayout("Scene", 0);
gd::Object &object =
layout.InsertNewObject(project, "MyExtension::Sprite", "MyObject", 0);
gd::Object &object = layout.GetObjects().InsertNewObject(
project, "MyExtension::Sprite", "MyObject", 0);
SetupSpriteConfiguration(object.GetConfiguration());
return object;
@@ -98,7 +98,7 @@ void CheckSpriteConfiguration(gd::Object &object) {
void CheckSpriteConfiguration(gd::Project &project) {
auto &layout = project.GetLayout("Scene");
auto &object = layout.GetObject("MyObject");
auto &object = layout.GetObjects().GetObject("MyObject");
CheckSpriteConfiguration(object);
};
@@ -112,11 +112,11 @@ gd::Object &SetupProjectWithCustomObject(gd::Project &project,
"MyEventsBasedObject", 0);
eventsBasedObject.SetFullName("My events based object");
eventsBasedObject.SetDescription("An events based object for test");
eventsBasedObject.InsertNewObject(project, "MyExtension::Sprite", "MyChild",
0);
eventsBasedObject.GetObjects().InsertNewObject(
project, "MyExtension::Sprite", "MyChild", 0);
gd::Layout &layout = project.InsertNewLayout("Scene", 0);
gd::Object &object = layout.InsertNewObject(
gd::Object &object = layout.GetObjects().InsertNewObject(
project, "MyEventsExtension::MyEventsBasedObject", "MyObject", 0);
auto &configuration = object.GetConfiguration();
auto *customObjectConfiguration =
@@ -167,7 +167,7 @@ void CheckCustomObjectConfiguration(gd::Object &object) {
void CheckCustomObjectConfiguration(gd::Project &project) {
auto &layout = project.GetLayout("Scene");
auto &object = layout.GetObject("MyObject");
auto &object = layout.GetObjects().GetObject("MyObject");
CheckCustomObjectConfiguration(object);
};
} // namespace
@@ -232,7 +232,7 @@ TEST_CASE("ObjectSerialization", "[common]") {
SetupProjectWithDummyPlatform(project, platform);
gd::Layout &layout = project.InsertNewLayout("Scene", 0);
gd::Object &object = layout.InsertNewObject(
gd::Object &object = layout.GetObjects().InsertNewObject(
project, "MyExtension::FakeObjectWithDefaultBehavior", "MyObject", 0);
REQUIRE(object.HasBehaviorNamed("Effect"));

View File

@@ -91,4 +91,49 @@ TEST_CASE("Variable", "[common][variables]") {
"Hello second copied World");
REQUIRE(variable3.GetChild("Child2").GetValue() == 44);
}
SECTION("Can find identical number variables") {
gd::Variable variable;
variable.SetValue(123);
gd::Variable otherVariable;
otherVariable.SetValue(123);
REQUIRE(variable == otherVariable);
}
SECTION("Can find different number variables") {
gd::Variable variable;
variable.SetValue(123);
gd::Variable otherVariable;
otherVariable.SetValue(456);
REQUIRE(variable != otherVariable);
}
SECTION("Can find identical structure variables") {
gd::Variable variable;
variable.GetChild("MyChild").SetValue(123);
gd::Variable otherVariable;
otherVariable.GetChild("MyChild").SetValue(123);
REQUIRE(variable == otherVariable);
}
SECTION("Can find structure with different child value") {
gd::Variable variable;
variable.GetChild("MyChild").SetValue(123);
gd::Variable otherVariable;
otherVariable.GetChild("MyChild").SetValue(456);
REQUIRE(variable != otherVariable);
}
SECTION("Can find structure with different child name") {
gd::Variable variable;
variable.GetChild("MyChild").SetValue(123);
gd::Variable otherVariable;
otherVariable.GetChild("MyOtherChild").SetValue(123);
REQUIRE(variable != otherVariable);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1094,19 +1094,12 @@ module.exports = {
objectContent,
instance,
propertyName,
newValue,
project,
layout
newValue
) {
return false;
};
Cube3DObject.getInitialInstanceProperties = function (
content,
instance,
project,
layout
) {
Cube3DObject.getInitialInstanceProperties = function (content, instance) {
const instanceProperties = new gd.MapStringPropertyDescriptor();
return instanceProperties;
};
@@ -2115,7 +2108,6 @@ module.exports = {
constructor(
project,
layout,
instance,
associatedObjectConfiguration,
pixiContainer,
@@ -2123,7 +2115,6 @@ module.exports = {
) {
super(
project,
layout,
instance,
associatedObjectConfiguration,
pixiContainer,
@@ -2300,7 +2291,6 @@ module.exports = {
class RenderedCube3DObject3DInstance extends Rendered3DInstance {
constructor(
project,
layout,
instance,
associatedObjectConfiguration,
pixiContainer,
@@ -2309,7 +2299,6 @@ module.exports = {
) {
super(
project,
layout,
instance,
associatedObjectConfiguration,
pixiContainer,
@@ -2682,7 +2671,6 @@ module.exports = {
constructor(
project,
layout,
instance,
associatedObjectConfiguration,
pixiContainer,
@@ -2690,7 +2678,6 @@ module.exports = {
) {
super(
project,
layout,
instance,
associatedObjectConfiguration,
pixiContainer,
@@ -2945,7 +2932,6 @@ module.exports = {
constructor(
project,
layout,
instance,
associatedObjectConfiguration,
pixiContainer,
@@ -2954,7 +2940,6 @@ module.exports = {
) {
super(
project,
layout,
instance,
associatedObjectConfiguration,
pixiContainer,

View File

@@ -165,14 +165,13 @@ Model3DObjectConfiguration::GetProperties() const {
bool Model3DObjectConfiguration::UpdateInitialInstanceProperty(
gd::InitialInstance &instance, const gd::String &propertyName,
const gd::String &newValue, gd::Project &project, gd::Layout &layout) {
const gd::String &newValue) {
return false;
}
std::map<gd::String, gd::PropertyDescriptor>
Model3DObjectConfiguration::GetInitialInstanceProperties(
const gd::InitialInstance &instance, gd::Project &project,
gd::Layout &layout) {
const gd::InitialInstance &instance) {
std::map<gd::String, gd::PropertyDescriptor> instanceProperties;
return instanceProperties;
}

View File

@@ -75,15 +75,11 @@ public:
const gd::String &value) override;
virtual std::map<gd::String, gd::PropertyDescriptor>
GetInitialInstanceProperties(const gd::InitialInstance &instance,
gd::Project &project,
gd::Layout &layout) override;
GetInitialInstanceProperties(const gd::InitialInstance &instance) override;
virtual bool UpdateInitialInstanceProperty(gd::InitialInstance &instance,
const gd::String &name,
const gd::String &value,
gd::Project &project,
gd::Layout &layout) override;
const gd::String &value) override;
/** \name Animations
* Methods related to animations management

View File

@@ -38,7 +38,7 @@ module.exports = {
.setName('Consent Cordova plugin')
.setDependencyType('cordova')
.setExportName('cordova-plugin-consent')
.setVersion('2.4.0')
.setVersion('3.0.0-alpha.8')
.onlyIfOtherDependencyIsExported('AdMob Cordova plugin');
extension
@@ -58,7 +58,7 @@ module.exports = {
.setName('AdMob Cordova plugin')
.setDependencyType('cordova')
.setExportName('admob-plus-cordova')
.setVersion('1.28.0')
.setVersion('2.0.0-alpha.18')
.setExtraSetting(
'APP_ID_ANDROID',
new gd.PropertyDescriptor('AdMobAppIdAndroid').setType(
@@ -166,11 +166,11 @@ module.exports = {
)
.addParameter('string', _('Android app open ID'), '', false)
.setParameterLongDescription(
'Get it from your AdMob account. You can use `"ca-app-pub-3940256099942544/3419835294"` for loading a test app open.'
'Get it from your AdMob account. You can use `"ca-app-pub-3940256099942544/9257395921"` for loading a test app open.'
)
.addParameter('string', _('iOS app open ID'), '', false)
.setParameterLongDescription(
'Get it from your AdMob account. You can use `"ca-app-pub-3940256099942544/5662855259"` for loading a test app open.'
'Get it from your AdMob account. You can use `"ca-app-pub-3940256099942544/5575463023"` for loading a test app open.'
)
.addParameter(
'yesorno',

View File

@@ -7,8 +7,8 @@ namespace gdjs {
const testAdIds = {
appOpen: {
android: 'ca-app-pub-3940256099942544/3419835294',
ios: 'ca-app-pub-3940256099942544/5662855259',
android: 'ca-app-pub-3940256099942544/9257395921',
ios: 'ca-app-pub-3940256099942544/5575463023',
},
banner: {
android: 'ca-app-pub-3940256099942544/6300978111',
@@ -67,6 +67,7 @@ namespace gdjs {
// Admob does not initialize automatically, so we store a flag to know if it's initialized.
let admobStarted = false;
let isStarting = false;
let isUsingTestAds = false;
// Banner
@@ -115,9 +116,13 @@ namespace gdjs {
async () => {
// Obtain user consent ?
logger.info('Starting AdMob.');
isStarting = true;
await admob.start();
logger.info('AdMob successfully started.');
isStarting = false;
admobStarted = true;
},
false
@@ -126,15 +131,32 @@ namespace gdjs {
/**
* Helper to know if we are on mobile and admob is correctly initialized.
*/
const checkIfAdMobIsAvailable = () => {
const checkIfAdMobIsAvailable = async () => {
if (typeof cordova === 'undefined') {
logger.warn('We are not on mobile, AdMob will not be available.');
return false;
}
if (typeof admob === 'undefined' || !admobStarted) {
logger.warn('AdMob has not been configured or started properly.');
if (typeof admob === 'undefined') {
logger.warn('AdMob has not been configured properly.');
return false;
}
if (!admobStarted) {
if (isStarting) {
// Delay the call until AdMob is started, up to 5 seconds.
let time = 0;
while (!admobStarted && time < 5000) {
await new Promise((resolve) => setTimeout(resolve, 100));
time += 100;
}
}
if (!admobStarted) {
logger.warn('AdMob is not started.');
return false;
}
}
return true;
};
@@ -164,8 +186,10 @@ namespace gdjs {
* charging advertisers. If you click on too many ads without being in test mode, you risk your
* account being flagged for invalid activity.
*/
export const setTestMode = (enable: boolean) => {
if (!checkIfAdMobIsAvailable()) return;
export const setTestMode = async (enable: boolean) => {
if (!(await checkIfAdMobIsAvailable())) return;
logger.info('Setting AdMob test mode to:', enable);
isUsingTestAds = enable;
};
@@ -185,7 +209,7 @@ namespace gdjs {
displayLandscape,
displayWhenLoaded
) => {
if (!checkIfAdMobIsAvailable()) return;
if (!(await checkIfAdMobIsAvailable())) return;
// If an appOpen is already loading or showing, we don't stop it.
if (appOpenLoading || appOpenShowing) {
return;
@@ -242,7 +266,7 @@ namespace gdjs {
/** Show the loaded appOpen. */
export const showAppOpen = async () => {
if (!checkIfAdMobIsAvailable()) return;
if (!(await checkIfAdMobIsAvailable())) return;
if (!appOpen) {
logger.warn('App Open has not been set up, call loadAppOpen first.');
@@ -293,7 +317,7 @@ namespace gdjs {
* If a banner is already set up, it will be hidden and replaced by the new one.
*/
export const setupBanner = async (androidAdUnitId, iosAdUnitId, atTop) => {
if (!checkIfAdMobIsAvailable()) return;
if (!(await checkIfAdMobIsAvailable())) return;
const adUnitId = getAdUnitId(androidAdUnitId, iosAdUnitId, 'banner');
if (!adUnitId) return;
@@ -354,7 +378,7 @@ namespace gdjs {
/** Hide the banner shown on screen. */
export const hideBanner = async () => {
if (!checkIfAdMobIsAvailable()) return;
if (!(await checkIfAdMobIsAvailable())) return;
if (!banner || !bannerShowing) {
logger.warn('No banner is being shown.');
@@ -381,7 +405,7 @@ namespace gdjs {
iosAdUnitId,
displayWhenLoaded
) => {
if (!checkIfAdMobIsAvailable()) return;
if (!(await checkIfAdMobIsAvailable())) return;
// If an interstitial is already loading or showing, we don't stop it.
if (interstitialLoading || interstitialShowing) {
return;
@@ -440,7 +464,7 @@ namespace gdjs {
/** Show the loaded interstitial. */
export const showInterstitial = async () => {
if (!checkIfAdMobIsAvailable()) return;
if (!(await checkIfAdMobIsAvailable())) return;
if (!interstitial) {
logger.warn(
@@ -495,7 +519,7 @@ namespace gdjs {
iosAdUnitID,
displayWhenLoaded
) => {
if (!checkIfAdMobIsAvailable()) return;
if (!(await checkIfAdMobIsAvailable())) return;
if (rewardedInterstitialLoading || rewardedInterstitialShowing) {
return;
}
@@ -557,7 +581,7 @@ namespace gdjs {
/** Show the loaded reward interstitial. */
export const showRewardedInterstitial = async () => {
if (!checkIfAdMobIsAvailable()) return;
if (!(await checkIfAdMobIsAvailable())) return;
if (!rewardedInterstitial) {
logger.warn(
@@ -614,7 +638,7 @@ namespace gdjs {
iosAdUnitID,
displayWhenLoaded
) => {
if (!checkIfAdMobIsAvailable()) return;
if (!(await checkIfAdMobIsAvailable())) return;
if (rewardedVideoLoading || rewardedVideoShowing) {
return;
}
@@ -672,7 +696,7 @@ namespace gdjs {
/** Show the loaded reward video. */
export const showRewardedVideo = async () => {
if (!checkIfAdMobIsAvailable()) return;
if (!(await checkIfAdMobIsAvailable())) return;
if (!rewardedVideo) {
logger.warn('Video has not been set up, call loadRewardedVideo first.');

View File

@@ -132,18 +132,11 @@ module.exports = {
objectContent,
instance,
propertyName,
newValue,
project,
layout
newValue
) {
return false;
};
objectBBText.getInitialInstanceProperties = function (
content,
instance,
project,
layout
) {
objectBBText.getInitialInstanceProperties = function (content, instance) {
var instanceProperties = new gd.MapStringPropertyDescriptor();
return instanceProperties;
};
@@ -500,7 +493,6 @@ module.exports = {
class RenderedBBTextInstance extends RenderedInstance {
constructor(
project,
layout,
instance,
associatedObjectConfiguration,
pixiContainer,
@@ -508,7 +500,6 @@ module.exports = {
) {
super(
project,
layout,
instance,
associatedObjectConfiguration,
pixiContainer,

View File

@@ -134,17 +134,13 @@ module.exports = {
objectContent,
instance,
propertyName,
newValue,
project,
layout
newValue
) {
return false;
};
bitmapTextObject.getInitialInstanceProperties = function (
content,
instance,
project,
layout
instance
) {
var instanceProperties = new gd.MapStringPropertyDescriptor();
return instanceProperties;
@@ -641,7 +637,6 @@ module.exports = {
constructor(
project,
layout,
instance,
associatedObjectConfiguration,
pixiContainer,
@@ -649,7 +644,6 @@ module.exports = {
) {
super(
project,
layout,
instance,
associatedObjectConfiguration,
pixiContainer,

View File

@@ -349,9 +349,7 @@ module.exports = {
objectContent,
instance,
propertyName,
newValue,
project,
layout
newValue
) {
if (propertyName === 'My instance property') {
instance.setRawStringProperty('instanceprop1', newValue);
@@ -364,12 +362,7 @@ module.exports = {
return false;
};
dummyObject.getInitialInstanceProperties = function (
content,
instance,
project,
layout
) {
dummyObject.getInitialInstanceProperties = function (content, instance) {
var instanceProperties = new gd.MapStringPropertyDescriptor();
instanceProperties
@@ -475,7 +468,6 @@ module.exports = {
class RenderedDummyObjectInstance extends RenderedInstance {
constructor(
project,
layout,
instance,
associatedObjectConfiguration,
pixiContainer,
@@ -483,7 +475,6 @@ module.exports = {
) {
super(
project,
layout,
instance,
associatedObjectConfiguration,
pixiContainer,

View File

@@ -381,6 +381,28 @@ module.exports = {
.setFunctionName('gdjs.fileSystem.deleteFileAsync')
.setAsyncFunctionName('gdjs.fileSystem.deleteFileAsyncTask');
extension
.addAction(
'ReadDirectory',
_('Read a directory'),
_(
'Reads the contents of a directory (all files and sub-directories) and stores them in an array.'
),
_('Read the directory _PARAM0_ into _PARAM1_'),
_('Windows, Linux, MacOS/Asynchronous'),
'JsPlatform/Extensions/filesystem_delete_file32.png',
'JsPlatform/Extensions/filesystem_delete_file32.png'
)
.addParameter('string', _('Directory path'), '', false)
.addParameter('scenevar', _('Variable to store the result'), '', true)
.setParameterLongDescription(
'It is set to `"error"` if an error has occured, otherwise it is set to an array of all files and sub-directories present in the directory.'
)
.getCodeExtraInformation()
.setIncludeFile('Extensions/FileSystem/filesystemtools.js')
.setFunctionName('gdjs.fileSystem.readdir')
.setAsyncFunctionName('gdjs.fileSystem.readdirAsync');
extension
.addStrExpression(
'DesktopPath',

View File

@@ -662,6 +662,56 @@ namespace gdjs {
)
: (resultVar.setString('error'), new gdjs.ResolveTask());
/**
* Reads the contents of a directory.
* @param directoryPath Path to the directory.
* @param resultVar The variable where to store the result of the operation.
*/
export const readdir = function (
directoryPath: string,
resultVar: gdjs.Variable
) {
let result: string[] | string = 'error';
if (fs) {
try {
result = fs.readdirSync(directoryPath);
} catch (err) {
logger.error(
"Unable to read the directory: '" + directoryPath + "': ",
err
);
result = 'error';
}
}
resultVar.fromJSObject(result);
};
/**
* Read a directory's contents asynchronously.
* @param directoryPath Path to the directory
* @param resultVar The variable where to store the result of the operation
*/
export const readdirAsync = (
directoryPath: string,
resultVar: gdjs.Variable
) =>
asyncFs
? new gdjs.PromiseTask(
asyncFs
.readdir(directoryPath)
.then((results) => {
resultVar.fromJSObject(results);
})
.catch((err) => {
resultVar.setString('error');
logger.error(
"Unable to read the directory: '" + directoryPath + "': ",
err
);
})
)
: (resultVar.setString('error'), new gdjs.ResolveTask());
/**
* Check if the file or directory exists.
* @param filePath The path to the file or directory

View File

@@ -10,7 +10,6 @@ declare namespace PIXI {}
*/
class RenderedInstance {
_project: gd.Project;
_layout: gd.Layout;
_instance: gd.InitialInstance;
_associatedObjectConfiguration: gd.ObjectConfiguration;
_pixiContainer: PIXI.Container;
@@ -20,7 +19,6 @@ class RenderedInstance {
constructor(
project: gdProject,
layout: gdLayout,
instance: gdInitialInstance,
associatedObjectConfiguration: gdObjectConfiguration,
pixiContainer: PIXI.Container,
@@ -86,7 +84,6 @@ class RenderedInstance {
*/
class Rendered3DInstance {
_project: gdProject;
_layout: gdLayout;
_instance: gdInitialInstance;
_associatedObjectConfiguration: gdObjectConfiguration;
_pixiContainer: PIXI.Container;
@@ -98,7 +95,6 @@ class Rendered3DInstance {
constructor(
project: gdProject,
layout: gdLayout,
instance: gdInitialInstance,
associatedObjectConfiguration: gdObjectConfiguration,
pixiContainer: PIXI.Container,

View File

@@ -153,19 +153,12 @@ module.exports = {
objectContent,
instance,
propertyName,
newValue,
project,
layout
newValue
) {
return false;
};
lightObject.getInitialInstanceProperties = function (
content,
instance,
project,
layout
) {
lightObject.getInitialInstanceProperties = function (content, instance) {
const instanceProperties = new gd.MapStringPropertyDescriptor();
return instanceProperties;
@@ -247,7 +240,6 @@ module.exports = {
class RenderedLightObjectInstance extends RenderedInstance {
constructor(
project,
layout,
instance,
associatedObjectConfiguration,
pixiContainer,
@@ -255,7 +247,6 @@ module.exports = {
) {
super(
project,
layout,
instance,
associatedObjectConfiguration,
pixiContainer,

View File

@@ -417,7 +417,7 @@ module.exports = {
.addIncludeFile('Extensions/Multiplayer/messageManager.js')
.addIncludeFile('Extensions/Multiplayer/multiplayerVariablesManager.js')
.addIncludeFile('Extensions/Multiplayer/multiplayertools.js')
.setFunctionName('gdjs.multiplayerMessageManager.hasAnyPlayerLeft');
.setFunctionName('gdjs.multiplayerMessageManager.hasAnyPlayerJustLeft');
extension
.addCondition(
@@ -443,7 +443,108 @@ module.exports = {
.addIncludeFile('Extensions/Multiplayer/messageManager.js')
.addIncludeFile('Extensions/Multiplayer/multiplayerVariablesManager.js')
.addIncludeFile('Extensions/Multiplayer/multiplayertools.js')
.setFunctionName('gdjs.multiplayerMessageManager.hasPlayerLeft');
.setFunctionName('gdjs.multiplayerMessageManager.hasPlayerJustLeft');
extension
.addExpression(
'LastLeftPlayerNumber',
_('Last left player number'),
_('Returns the number of the player that has just left the lobby.'),
_('Lobbies'),
'JsPlatform/Extensions/multiplayer.svg'
)
.getCodeExtraInformation()
.setIncludeFile('Extensions/Multiplayer/peer.js')
.addIncludeFile('Extensions/Multiplayer/peerJsHelper.js')
.addIncludeFile(
'Extensions/PlayerAuthentication/playerauthenticationcomponents.js'
)
.addIncludeFile(
'Extensions/PlayerAuthentication/playerauthenticationtools.js'
)
.addIncludeFile('Extensions/Multiplayer/multiplayercomponents.js')
.addIncludeFile('Extensions/Multiplayer/messageManager.js')
.addIncludeFile('Extensions/Multiplayer/multiplayerVariablesManager.js')
.addIncludeFile('Extensions/Multiplayer/multiplayertools.js')
.setFunctionName(
'gdjs.multiplayerMessageManager.getLatestPlayerWhoJustLeft'
);
extension
.addCondition(
'HasAnyPlayerJoined',
_('Any player has joined'),
_('Check if any player has joined the lobby.'),
_('Any player has joined'),
_('Lobbies'),
'JsPlatform/Extensions/multiplayer.svg',
'JsPlatform/Extensions/multiplayer.svg'
)
.getCodeExtraInformation()
.setIncludeFile('Extensions/Multiplayer/peer.js')
.addIncludeFile('Extensions/Multiplayer/peerJsHelper.js')
.addIncludeFile(
'Extensions/PlayerAuthentication/playerauthenticationcomponents.js'
)
.addIncludeFile(
'Extensions/PlayerAuthentication/playerauthenticationtools.js'
)
.addIncludeFile('Extensions/Multiplayer/multiplayercomponents.js')
.addIncludeFile('Extensions/Multiplayer/messageManager.js')
.addIncludeFile('Extensions/Multiplayer/multiplayerVariablesManager.js')
.addIncludeFile('Extensions/Multiplayer/multiplayertools.js')
.setFunctionName('gdjs.multiplayerMessageManager.hasAnyPlayerJustJoined');
extension
.addCondition(
'HasPlayerJoined',
_('Player has joined'),
_('Check if the player has joined the lobby.'),
_('Player _PARAM0_ has joined'),
_('Lobbies'),
'JsPlatform/Extensions/multiplayer.svg',
'JsPlatform/Extensions/multiplayer.svg'
)
.getCodeExtraInformation()
.addParameter('number', _('Player number'), '', false)
.setIncludeFile('Extensions/Multiplayer/peer.js')
.addIncludeFile('Extensions/Multiplayer/peerJsHelper.js')
.addIncludeFile(
'Extensions/PlayerAuthentication/playerauthenticationcomponents.js'
)
.addIncludeFile(
'Extensions/PlayerAuthentication/playerauthenticationtools.js'
)
.addIncludeFile('Extensions/Multiplayer/multiplayercomponents.js')
.addIncludeFile('Extensions/Multiplayer/messageManager.js')
.addIncludeFile('Extensions/Multiplayer/multiplayerVariablesManager.js')
.addIncludeFile('Extensions/Multiplayer/multiplayertools.js')
.setFunctionName('gdjs.multiplayerMessageManager.hasPlayerJustJoined');
extension
.addExpression(
'LastJoinedPlayerNumber',
_('Last joined player number'),
_('Returns the number of the player that has just joined the lobby.'),
_('Lobbies'),
'JsPlatform/Extensions/multiplayer.svg'
)
.getCodeExtraInformation()
.setIncludeFile('Extensions/Multiplayer/peer.js')
.addIncludeFile('Extensions/Multiplayer/peerJsHelper.js')
.addIncludeFile(
'Extensions/PlayerAuthentication/playerauthenticationcomponents.js'
)
.addIncludeFile(
'Extensions/PlayerAuthentication/playerauthenticationtools.js'
)
.addIncludeFile('Extensions/Multiplayer/multiplayercomponents.js')
.addIncludeFile('Extensions/Multiplayer/messageManager.js')
.addIncludeFile('Extensions/Multiplayer/multiplayerVariablesManager.js')
.addIncludeFile('Extensions/Multiplayer/multiplayertools.js')
.setFunctionName(
'gdjs.multiplayerMessageManager.getLatestPlayerWhoJustJoined'
);
extension
.addStrExpression(
@@ -520,6 +621,37 @@ module.exports = {
.useStandardParameters('number', gd.ParameterOptions.makeNewOptions())
.setFunctionName('gdjs.multiplayer.getPlayersInLobbyCount');
extension
.addCondition(
'IsPlayerConnected',
_('Player is connected'),
_('Check if the specified player is connected to the lobby.'),
_('Player _PARAM0_ is connected'),
_('Lobbies'),
'JsPlatform/Extensions/multiplayer.svg',
'JsPlatform/Extensions/multiplayer.svg'
)
.addParameter(
'number',
_('The position of the player in the lobby (1, 2, ...)'),
'',
false
)
.setHelpPath('/all-features/multiplayer')
.getCodeExtraInformation()
.setIncludeFile('Extensions/Multiplayer/peer.js')
.addIncludeFile('Extensions/Multiplayer/peerJsHelper.js')
.addIncludeFile(
'Extensions/PlayerAuthentication/playerauthenticationcomponents.js'
)
.addIncludeFile(
'Extensions/PlayerAuthentication/playerauthenticationtools.js'
)
.addIncludeFile('Extensions/Multiplayer/messageManager.js')
.addIncludeFile('Extensions/Multiplayer/multiplayerVariablesManager.js')
.addIncludeFile('Extensions/Multiplayer/multiplayertools.js')
.setFunctionName('gdjs.multiplayer.isPlayerConnected');
extension
.addExpressionAndCondition(
'number',

Some files were not shown because too many files have changed in this diff Show More