From e654ec32a0cfa89b541947f6ac14c883d73d260d Mon Sep 17 00:00:00 2001 From: Florian Rival Date: Wed, 20 May 2015 23:43:00 +1200 Subject: [PATCH] [WIP] Converting the bindings to WebIDL --- .gitignore | 5 +- Bindings/Bindings.idl | 96 ++++ Bindings/ProjectHelper.h | 48 ++ Bindings/Wrapper.cpp | 33 ++ Bindings/glue.cpp | 302 +++++++++++ Bindings/glue.js | 508 ++++++++++++++++++ Bindings/postjs.js | 57 ++ {WebIDE => Bindings}/prejs.js | 0 CMakeLists.txt | 27 +- Gruntfile.js | 4 +- Readme.md | 30 +- .../Bindings/Extensions/TextObject/Embind.cpp | 42 -- .../Extensions/TiledSpriteObject/Embind.cpp | 33 -- WebIDE/Bindings/GDCore/Embind.cpp | 448 --------------- WebIDE/Bindings/GDCore/Embind2.cpp | 507 ----------------- WebIDE/Bindings/GDCore/Embind3.cpp | 119 ---- WebIDE/Bindings/GDCore/Embind4.cpp | 110 ---- WebIDE/Bindings/GDJS/Embind.cpp | 51 -- WebIDE/main.cpp | 2 +- WebIDE/postjs.js | 2 - package.json | 6 +- test/libGD_Core.js | 6 + 22 files changed, 1093 insertions(+), 1343 deletions(-) create mode 100644 Bindings/Bindings.idl create mode 100644 Bindings/ProjectHelper.h create mode 100644 Bindings/Wrapper.cpp create mode 100644 Bindings/glue.cpp create mode 100644 Bindings/glue.js create mode 100644 Bindings/postjs.js rename {WebIDE => Bindings}/prejs.js (100%) delete mode 100644 WebIDE/Bindings/Extensions/TextObject/Embind.cpp delete mode 100644 WebIDE/Bindings/Extensions/TiledSpriteObject/Embind.cpp delete mode 100644 WebIDE/Bindings/GDCore/Embind.cpp delete mode 100644 WebIDE/Bindings/GDCore/Embind2.cpp delete mode 100644 WebIDE/Bindings/GDCore/Embind3.cpp delete mode 100644 WebIDE/Bindings/GDCore/Embind4.cpp delete mode 100644 WebIDE/Bindings/GDJS/Embind.cpp delete mode 100644 WebIDE/postjs.js diff --git a/.gitignore b/.gitignore index 30bc162..c18eda0 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -/node_modules \ No newline at end of file +/node_modules +Bindings/parser.out +Bindings/WebIDLGrammar.pkl +.cpp.old diff --git a/Bindings/Bindings.idl b/Bindings/Bindings.idl new file mode 100644 index 0000000..71d67b4 --- /dev/null +++ b/Bindings/Bindings.idl @@ -0,0 +1,96 @@ +/** + * IDL file for GDevelop classes bindings. + * + * Notes: + * + * WRAPPED_* functions are declared as such to allow the Wrapper.cpp + * file to use a macro to do special work on it. + * These functions are renamed in the final .js file (so that + * `WRAPPED_set` become `set` for example). + */ + +interface ProjectHelper { + [Ref] Project STATIC_CreateNewGDJSProject(); + void STATIC_InitializePlatforms(); +}; + +interface VectorString { + void push_back([Const] DOMString str); + void resize(long size); + long size(); + [Const, Ref] DOMString at(long index); + void WRAPPED_set(long index, [Const, Ref] DOMString str); + void clear(); +}; + +interface Project { + void Project(); + void SetName([Const] DOMString name); + [Const, Ref] DOMString GetName(); + void SetAuthor([Const] DOMString name); + [Const, Ref] DOMString GetAuthor(); + void SetProjectFile([Const] DOMString file); + [Const, Ref] DOMString GetProjectFile(); + void SetDefaultWidth(long width); + long GetMainWindowDefaultWidth(); + void SetDefaultHeight(long height); + long GetMainWindowDefaultHeight(); + long GetMaximumFPS(); + void SetMaximumFPS(long fps); + long GetMinimumFPS(); + void SetMinimumFPS(long fps); + [Const, Ref] VectorString GetUsedExtensions(); + + boolean HasLayoutNamed([Const] DOMString name); + [Ref] Layout InsertNewLayout([Const] DOMString name, long position); + [Ref] Layout GetLayout([Const] DOMString name); +}; + +interface Layout { + void Layout(); + + void SetName([Const] DOMString name); + [Const, Ref] DOMString GetName(); +}; + + + +interface InitialInstance { + void InitialInstance(); + + void SetObjectName([Const] DOMString name); + [Const, Ref] DOMString GetObjectName(); + + float GetX(); + void SetX(float x); + float GetY(); + void SetY(float y); + float GetAngle(); + void SetAngle(float angle); + long GetZOrder(); + void SetZOrder(long zOrder); + [Const, Ref] DOMString GetLayer(); + void SetLayer([Const] DOMString layer); +}; + +interface InitialInstancesContainer { + void InitialInstancesContainer(); + + long GetInstancesCount(); + + void IterateOverInstances([Ref] InitialInstanceFunctor func); + void IterateOverInstancesWithZOrdering([Ref] InitialInstanceFunctor func, DOMString layer); + void RemoveAllInstancesOnLayer(DOMString layer); + boolean SomeInstancesAreOnLayer(DOMString layer); + + [Ref] InitialInstance InsertNewInitialInstance(); +}; + +interface InitialInstanceFunctor {}; +interface InitialInstanceJSFunctorWrapper {}; +[JSImplementation="InitialInstanceJSFunctorWrapper"] +interface InitialInstanceJSFunctor { + void InitialInstanceJSFunctor(); + + void invoke(InitialInstance instance); +}; diff --git a/Bindings/ProjectHelper.h b/Bindings/ProjectHelper.h new file mode 100644 index 0000000..2ec1152 --- /dev/null +++ b/Bindings/ProjectHelper.h @@ -0,0 +1,48 @@ +#include "GDCore/PlatformDefinition/Project.h" +#include "GDCore/PlatformDefinition/Layout.h" +#include "GDCore/PlatformDefinition/Project.h" +#include "GDCore/PlatformDefinition/Platform.h" +#include "GDCore/IDE/PlatformManager.h" +#include "GDCore/TinyXml/tinyxml.h" +#include "GDCpp/CppPlatform.h" +#include "GDCore/PlatformDefinition/Platform.h" +#include "GDCore/PlatformDefinition/Platform.h" +#include "GDJS/JsPlatform.h" +#include "GDCore/PlatformDefinition/InitialInstancesContainer.h" + +using namespace gdjs; +using namespace gd; + +/** + * \brief A class providing helper functions related to projects. + */ +class ProjectHelper { +public: + static gd::Project & CreateNewGDJSProject() + { + Project * project = new Project; + project->AddPlatform(JsPlatform::Get()); + + return *project; + } + + /** + * \brief Initialize the JS platform. + */ + static void InitializePlatforms() + { + static bool initialized = false; + if (initialized) { + std::cout << "ERROR: You're calling initializePlatforms again, but initialization was already done!" << std::endl; + return; + } + + initialized = true; + std::cout << "Initializing GDJS platform" << std::endl; + { + std::shared_ptr platform(&JsPlatform::Get()); + gd::PlatformManager::Get()->AddPlatform(platform); + } + std::cout << "Platform initialization ended." << std::endl; + } +}; diff --git a/Bindings/Wrapper.cpp b/Bindings/Wrapper.cpp new file mode 100644 index 0000000..df787df --- /dev/null +++ b/Bindings/Wrapper.cpp @@ -0,0 +1,33 @@ +#include +#include +#include +#include +#include +#include "ProjectHelper.h" + +class InitialInstanceJSFunctorWrapper : public gd::InitialInstanceFunctor { +public: + InitialInstanceJSFunctorWrapper() {}; + + virtual void operator()(gd::InitialInstance * instance) { + invoke(instance); + }; + + virtual void invoke(gd::InitialInstance * instance) { + }; +}; + +//Declares typedef for std::vector +typedef std::vector VectorString; + +//Customize some functions implementation thanks to WRAPPED_* macros +//The original names will be reconstructed in the js file (see postjs.js) +#define WRAPPED_set(a, b) at(a) = b +#define STATIC_CreateNewGDJSProject CreateNewGDJSProject +#define STATIC_InitializePlatforms InitializePlatforms + +// We don't use prefix in .idl file to workaround a webidl_binder.py bug +// that can't find in its list of interfaces a class which has a prefix. +using namespace gd; +using namespace std; +#include "glue.cpp" diff --git a/Bindings/glue.cpp b/Bindings/glue.cpp new file mode 100644 index 0000000..bb4acb1 --- /dev/null +++ b/Bindings/glue.cpp @@ -0,0 +1,302 @@ + +#include + +class InitialInstanceJSFunctor : public InitialInstanceJSFunctorWrapper { +public: + void invoke(InitialInstance* arg0) { + EM_ASM_INT({ + var self = Module['getCache'](Module['InitialInstanceJSFunctor'])[$0]; + if (!self.hasOwnProperty('invoke')) throw 'a JSImplementation must implement all functions, you forgot InitialInstanceJSFunctor::invoke.'; + self.invoke($1); + }, (int)this, (int)arg0); + } + void __destroy__() { + EM_ASM_INT({ + var self = Module['getCache'](Module['InitialInstanceJSFunctor'])[$0]; + if (!self.hasOwnProperty('__destroy__')) throw 'a JSImplementation must implement all functions, you forgot InitialInstanceJSFunctor::__destroy__.'; + self.__destroy__(); + }, (int)this); + } +}; + +extern "C" { + +// Not using size_t for array indices as the values used by the javascript code are signed. +void array_bounds_check(const int array_size, const int array_idx) { + if (array_idx < 0 || array_idx >= array_size) { + EM_ASM_INT({ + throw 'Array index ' + $0 + ' out of bounds: [0,' + $1 + ')'; + }, array_idx, array_size); + } +} + +// InitialInstancesContainer + +InitialInstancesContainer* EMSCRIPTEN_KEEPALIVE emscripten_bind_InitialInstancesContainer_InitialInstancesContainer_0() { + return new InitialInstancesContainer(); +} + +int EMSCRIPTEN_KEEPALIVE emscripten_bind_InitialInstancesContainer_GetInstancesCount_0(InitialInstancesContainer* self) { + return self->GetInstancesCount(); +} + +void EMSCRIPTEN_KEEPALIVE emscripten_bind_InitialInstancesContainer_IterateOverInstances_1(InitialInstancesContainer* self, InitialInstanceFunctor* arg0) { + self->IterateOverInstances(*arg0); +} + +void EMSCRIPTEN_KEEPALIVE emscripten_bind_InitialInstancesContainer_IterateOverInstancesWithZOrdering_2(InitialInstancesContainer* self, InitialInstanceFunctor* arg0, char* arg1) { + self->IterateOverInstancesWithZOrdering(*arg0, arg1); +} + +void EMSCRIPTEN_KEEPALIVE emscripten_bind_InitialInstancesContainer_RemoveAllInstancesOnLayer_1(InitialInstancesContainer* self, char* arg0) { + self->RemoveAllInstancesOnLayer(arg0); +} + +bool EMSCRIPTEN_KEEPALIVE emscripten_bind_InitialInstancesContainer_SomeInstancesAreOnLayer_1(InitialInstancesContainer* self, char* arg0) { + return self->SomeInstancesAreOnLayer(arg0); +} + +InitialInstance* EMSCRIPTEN_KEEPALIVE emscripten_bind_InitialInstancesContainer_InsertNewInitialInstance_0(InitialInstancesContainer* self) { + return &self->InsertNewInitialInstance(); +} + +void EMSCRIPTEN_KEEPALIVE emscripten_bind_InitialInstancesContainer___destroy___0(InitialInstancesContainer* self) { + delete self; +} + +// VectorString + +void EMSCRIPTEN_KEEPALIVE emscripten_bind_VectorString_push_back_1(VectorString* self, char* arg0) { + self->push_back(arg0); +} + +void EMSCRIPTEN_KEEPALIVE emscripten_bind_VectorString_resize_1(VectorString* self, int arg0) { + self->resize(arg0); +} + +int EMSCRIPTEN_KEEPALIVE emscripten_bind_VectorString_size_0(VectorString* self) { + return self->size(); +} + +const char* EMSCRIPTEN_KEEPALIVE emscripten_bind_VectorString_at_1(VectorString* self, int arg0) { + return self->at(arg0).c_str(); +} + +void EMSCRIPTEN_KEEPALIVE emscripten_bind_VectorString_WRAPPED_set_2(VectorString* self, int arg0, char* arg1) { + self->WRAPPED_set(arg0, *arg1); +} + +void EMSCRIPTEN_KEEPALIVE emscripten_bind_VectorString_clear_0(VectorString* self) { + self->clear(); +} + +void EMSCRIPTEN_KEEPALIVE emscripten_bind_VectorString___destroy___0(VectorString* self) { + delete self; +} + +// Layout + +Layout* EMSCRIPTEN_KEEPALIVE emscripten_bind_Layout_Layout_0() { + return new Layout(); +} + +void EMSCRIPTEN_KEEPALIVE emscripten_bind_Layout_SetName_1(Layout* self, char* arg0) { + self->SetName(arg0); +} + +const char* EMSCRIPTEN_KEEPALIVE emscripten_bind_Layout_GetName_0(Layout* self) { + return self->GetName().c_str(); +} + +void EMSCRIPTEN_KEEPALIVE emscripten_bind_Layout___destroy___0(Layout* self) { + delete self; +} + +// InitialInstanceFunctor + +void EMSCRIPTEN_KEEPALIVE emscripten_bind_InitialInstanceFunctor___destroy___0(InitialInstanceFunctor* self) { + delete self; +} + +// InitialInstance + +InitialInstance* EMSCRIPTEN_KEEPALIVE emscripten_bind_InitialInstance_InitialInstance_0() { + return new InitialInstance(); +} + +void EMSCRIPTEN_KEEPALIVE emscripten_bind_InitialInstance_SetObjectName_1(InitialInstance* self, char* arg0) { + self->SetObjectName(arg0); +} + +const char* EMSCRIPTEN_KEEPALIVE emscripten_bind_InitialInstance_GetObjectName_0(InitialInstance* self) { + return self->GetObjectName().c_str(); +} + +float EMSCRIPTEN_KEEPALIVE emscripten_bind_InitialInstance_GetX_0(InitialInstance* self) { + return self->GetX(); +} + +void EMSCRIPTEN_KEEPALIVE emscripten_bind_InitialInstance_SetX_1(InitialInstance* self, float arg0) { + self->SetX(arg0); +} + +float EMSCRIPTEN_KEEPALIVE emscripten_bind_InitialInstance_GetY_0(InitialInstance* self) { + return self->GetY(); +} + +void EMSCRIPTEN_KEEPALIVE emscripten_bind_InitialInstance_SetY_1(InitialInstance* self, float arg0) { + self->SetY(arg0); +} + +float EMSCRIPTEN_KEEPALIVE emscripten_bind_InitialInstance_GetAngle_0(InitialInstance* self) { + return self->GetAngle(); +} + +void EMSCRIPTEN_KEEPALIVE emscripten_bind_InitialInstance_SetAngle_1(InitialInstance* self, float arg0) { + self->SetAngle(arg0); +} + +int EMSCRIPTEN_KEEPALIVE emscripten_bind_InitialInstance_GetZOrder_0(InitialInstance* self) { + return self->GetZOrder(); +} + +void EMSCRIPTEN_KEEPALIVE emscripten_bind_InitialInstance_SetZOrder_1(InitialInstance* self, int arg0) { + self->SetZOrder(arg0); +} + +const char* EMSCRIPTEN_KEEPALIVE emscripten_bind_InitialInstance_GetLayer_0(InitialInstance* self) { + return self->GetLayer().c_str(); +} + +void EMSCRIPTEN_KEEPALIVE emscripten_bind_InitialInstance_SetLayer_1(InitialInstance* self, char* arg0) { + self->SetLayer(arg0); +} + +void EMSCRIPTEN_KEEPALIVE emscripten_bind_InitialInstance___destroy___0(InitialInstance* self) { + delete self; +} + +// InitialInstanceJSFunctorWrapper + +void EMSCRIPTEN_KEEPALIVE emscripten_bind_InitialInstanceJSFunctorWrapper___destroy___0(InitialInstanceJSFunctorWrapper* self) { + delete self; +} + +// InitialInstanceJSFunctor + +InitialInstanceJSFunctor* EMSCRIPTEN_KEEPALIVE emscripten_bind_InitialInstanceJSFunctor_InitialInstanceJSFunctor_0() { + return new InitialInstanceJSFunctor(); +} + +void EMSCRIPTEN_KEEPALIVE emscripten_bind_InitialInstanceJSFunctor_invoke_1(InitialInstanceJSFunctor* self, InitialInstance* arg0) { + self->invoke(arg0); +} + +void EMSCRIPTEN_KEEPALIVE emscripten_bind_InitialInstanceJSFunctor___destroy___0(InitialInstanceJSFunctor* self) { + delete self; +} + +// Project + +Project* EMSCRIPTEN_KEEPALIVE emscripten_bind_Project_Project_0() { + return new Project(); +} + +void EMSCRIPTEN_KEEPALIVE emscripten_bind_Project_SetName_1(Project* self, char* arg0) { + self->SetName(arg0); +} + +const char* EMSCRIPTEN_KEEPALIVE emscripten_bind_Project_GetName_0(Project* self) { + return self->GetName().c_str(); +} + +void EMSCRIPTEN_KEEPALIVE emscripten_bind_Project_SetAuthor_1(Project* self, char* arg0) { + self->SetAuthor(arg0); +} + +const char* EMSCRIPTEN_KEEPALIVE emscripten_bind_Project_GetAuthor_0(Project* self) { + return self->GetAuthor().c_str(); +} + +void EMSCRIPTEN_KEEPALIVE emscripten_bind_Project_SetProjectFile_1(Project* self, char* arg0) { + self->SetProjectFile(arg0); +} + +const char* EMSCRIPTEN_KEEPALIVE emscripten_bind_Project_GetProjectFile_0(Project* self) { + return self->GetProjectFile().c_str(); +} + +void EMSCRIPTEN_KEEPALIVE emscripten_bind_Project_SetDefaultWidth_1(Project* self, int arg0) { + self->SetDefaultWidth(arg0); +} + +int EMSCRIPTEN_KEEPALIVE emscripten_bind_Project_GetMainWindowDefaultWidth_0(Project* self) { + return self->GetMainWindowDefaultWidth(); +} + +void EMSCRIPTEN_KEEPALIVE emscripten_bind_Project_SetDefaultHeight_1(Project* self, int arg0) { + self->SetDefaultHeight(arg0); +} + +int EMSCRIPTEN_KEEPALIVE emscripten_bind_Project_GetMainWindowDefaultHeight_0(Project* self) { + return self->GetMainWindowDefaultHeight(); +} + +int EMSCRIPTEN_KEEPALIVE emscripten_bind_Project_GetMaximumFPS_0(Project* self) { + return self->GetMaximumFPS(); +} + +void EMSCRIPTEN_KEEPALIVE emscripten_bind_Project_SetMaximumFPS_1(Project* self, int arg0) { + self->SetMaximumFPS(arg0); +} + +int EMSCRIPTEN_KEEPALIVE emscripten_bind_Project_GetMinimumFPS_0(Project* self) { + return self->GetMinimumFPS(); +} + +void EMSCRIPTEN_KEEPALIVE emscripten_bind_Project_SetMinimumFPS_1(Project* self, int arg0) { + self->SetMinimumFPS(arg0); +} + +const VectorString* EMSCRIPTEN_KEEPALIVE emscripten_bind_Project_GetUsedExtensions_0(Project* self) { + return &self->GetUsedExtensions(); +} + +bool EMSCRIPTEN_KEEPALIVE emscripten_bind_Project_HasLayoutNamed_1(Project* self, char* arg0) { + return self->HasLayoutNamed(arg0); +} + +Layout* EMSCRIPTEN_KEEPALIVE emscripten_bind_Project_InsertNewLayout_2(Project* self, char* arg0, int arg1) { + return &self->InsertNewLayout(arg0, arg1); +} + +Layout* EMSCRIPTEN_KEEPALIVE emscripten_bind_Project_GetLayout_1(Project* self, char* arg0) { + return &self->GetLayout(arg0); +} + +void EMSCRIPTEN_KEEPALIVE emscripten_bind_Project___destroy___0(Project* self) { + delete self; +} + +// ProjectHelper + +Project* EMSCRIPTEN_KEEPALIVE emscripten_bind_ProjectHelper_STATIC_CreateNewGDJSProject_0(ProjectHelper* self) { + return &self->STATIC_CreateNewGDJSProject(); +} + +void EMSCRIPTEN_KEEPALIVE emscripten_bind_ProjectHelper_STATIC_InitializePlatforms_0(ProjectHelper* self) { + self->STATIC_InitializePlatforms(); +} + +void EMSCRIPTEN_KEEPALIVE emscripten_bind_ProjectHelper___destroy___0(ProjectHelper* self) { + delete self; +} + +// VoidPtr + +void EMSCRIPTEN_KEEPALIVE emscripten_bind_VoidPtr___destroy___0(void** self) { + delete self; +} + +} + diff --git a/Bindings/glue.js b/Bindings/glue.js new file mode 100644 index 0000000..9e761d1 --- /dev/null +++ b/Bindings/glue.js @@ -0,0 +1,508 @@ + +// Bindings utilities + +function WrapperObject() { +} +WrapperObject.prototype = Object.create(WrapperObject.prototype); +WrapperObject.prototype.constructor = WrapperObject; +WrapperObject.prototype.__class__ = WrapperObject; +WrapperObject.__cache__ = {}; +Module['WrapperObject'] = WrapperObject; + +function getCache(__class__) { + return (__class__ || WrapperObject).__cache__; +} +Module['getCache'] = getCache; + +function wrapPointer(ptr, __class__) { + var cache = getCache(__class__); + var ret = cache[ptr]; + if (ret) return ret; + ret = Object.create((__class__ || WrapperObject).prototype); + ret.ptr = ptr; + return cache[ptr] = ret; +} +Module['wrapPointer'] = wrapPointer; + +function castObject(obj, __class__) { + return wrapPointer(obj.ptr, __class__); +} +Module['castObject'] = castObject; + +Module['NULL'] = wrapPointer(0); + +function destroy(obj) { + if (!obj['__destroy__']) throw 'Error: Cannot destroy object. (Did you create it yourself?)'; + obj['__destroy__'](); + // Remove from cache, so the object can be GC'd and refs added onto it released + delete getCache(obj.__class__)[obj.ptr]; +} +Module['destroy'] = destroy; + +function compare(obj1, obj2) { + return obj1.ptr === obj2.ptr; +} +Module['compare'] = compare; + +function getPointer(obj) { + return obj.ptr; +} +Module['getPointer'] = getPointer; + +function getClass(obj) { + return obj.__class__; +} +Module['getClass'] = getClass; + +// Converts a value into a C-style string. +var ensureString = (function() { + var stringCache = {}; + function ensureString(value) { + if (typeof value == 'string') { + var cachedVal = stringCache[value]; + if (cachedVal) return cachedVal; + var ret = allocate(intArrayFromString(value), 'i8', ALLOC_STACK); + stringCache[value] = ret; + return ret; + } + return value; + } + return ensureString; +})(); + + +// InitialInstancesContainer +function InitialInstancesContainer() { + this.ptr = _emscripten_bind_InitialInstancesContainer_InitialInstancesContainer_0(); + getCache(InitialInstancesContainer)[this.ptr] = this; +};; +InitialInstancesContainer.prototype = Object.create(WrapperObject.prototype); +InitialInstancesContainer.prototype.constructor = InitialInstancesContainer; +InitialInstancesContainer.prototype.__class__ = InitialInstancesContainer; +InitialInstancesContainer.__cache__ = {}; +Module['InitialInstancesContainer'] = InitialInstancesContainer; + +InitialInstancesContainer.prototype['GetInstancesCount'] = function() { + var self = this.ptr; + return _emscripten_bind_InitialInstancesContainer_GetInstancesCount_0(self); +};; + +InitialInstancesContainer.prototype['IterateOverInstances'] = function(arg0) { + var self = this.ptr; + if (arg0 && typeof arg0 === 'object') arg0 = arg0.ptr; + else arg0 = ensureString(arg0); + _emscripten_bind_InitialInstancesContainer_IterateOverInstances_1(self, arg0); +};; + +InitialInstancesContainer.prototype['IterateOverInstancesWithZOrdering'] = function(arg0, arg1) { + var self = this.ptr; + if (arg0 && typeof arg0 === 'object') arg0 = arg0.ptr; + else arg0 = ensureString(arg0); + if (arg1 && typeof arg1 === 'object') arg1 = arg1.ptr; + else arg1 = ensureString(arg1); + _emscripten_bind_InitialInstancesContainer_IterateOverInstancesWithZOrdering_2(self, arg0, arg1); +};; + +InitialInstancesContainer.prototype['RemoveAllInstancesOnLayer'] = function(arg0) { + var self = this.ptr; + if (arg0 && typeof arg0 === 'object') arg0 = arg0.ptr; + else arg0 = ensureString(arg0); + _emscripten_bind_InitialInstancesContainer_RemoveAllInstancesOnLayer_1(self, arg0); +};; + +InitialInstancesContainer.prototype['SomeInstancesAreOnLayer'] = function(arg0) { + var self = this.ptr; + if (arg0 && typeof arg0 === 'object') arg0 = arg0.ptr; + else arg0 = ensureString(arg0); + return _emscripten_bind_InitialInstancesContainer_SomeInstancesAreOnLayer_1(self, arg0); +};; + +InitialInstancesContainer.prototype['InsertNewInitialInstance'] = function() { + var self = this.ptr; + return wrapPointer(_emscripten_bind_InitialInstancesContainer_InsertNewInitialInstance_0(self), InitialInstance); +};; + + InitialInstancesContainer.prototype['__destroy__'] = function() { + var self = this.ptr; + _emscripten_bind_InitialInstancesContainer___destroy___0(self); +}; +// VectorString +function VectorString() { throw "cannot construct a VectorString, no constructor in IDL" } +VectorString.prototype = Object.create(WrapperObject.prototype); +VectorString.prototype.constructor = VectorString; +VectorString.prototype.__class__ = VectorString; +VectorString.__cache__ = {}; +Module['VectorString'] = VectorString; + +VectorString.prototype['push_back'] = function(arg0) { + var self = this.ptr; + if (arg0 && typeof arg0 === 'object') arg0 = arg0.ptr; + else arg0 = ensureString(arg0); + _emscripten_bind_VectorString_push_back_1(self, arg0); +};; + +VectorString.prototype['resize'] = function(arg0) { + var self = this.ptr; + if (arg0 && typeof arg0 === 'object') arg0 = arg0.ptr; + else arg0 = ensureString(arg0); + _emscripten_bind_VectorString_resize_1(self, arg0); +};; + +VectorString.prototype['size'] = function() { + var self = this.ptr; + return _emscripten_bind_VectorString_size_0(self); +};; + +VectorString.prototype['at'] = function(arg0) { + var self = this.ptr; + if (arg0 && typeof arg0 === 'object') arg0 = arg0.ptr; + else arg0 = ensureString(arg0); + return Pointer_stringify(_emscripten_bind_VectorString_at_1(self, arg0)); +};; + +VectorString.prototype['WRAPPED_set'] = function(arg0, arg1) { + var self = this.ptr; + if (arg0 && typeof arg0 === 'object') arg0 = arg0.ptr; + else arg0 = ensureString(arg0); + if (arg1 && typeof arg1 === 'object') arg1 = arg1.ptr; + else arg1 = ensureString(arg1); + _emscripten_bind_VectorString_WRAPPED_set_2(self, arg0, arg1); +};; + +VectorString.prototype['clear'] = function() { + var self = this.ptr; + _emscripten_bind_VectorString_clear_0(self); +};; + + VectorString.prototype['__destroy__'] = function() { + var self = this.ptr; + _emscripten_bind_VectorString___destroy___0(self); +}; +// Layout +function Layout() { + this.ptr = _emscripten_bind_Layout_Layout_0(); + getCache(Layout)[this.ptr] = this; +};; +Layout.prototype = Object.create(WrapperObject.prototype); +Layout.prototype.constructor = Layout; +Layout.prototype.__class__ = Layout; +Layout.__cache__ = {}; +Module['Layout'] = Layout; + +Layout.prototype['SetName'] = function(arg0) { + var self = this.ptr; + if (arg0 && typeof arg0 === 'object') arg0 = arg0.ptr; + else arg0 = ensureString(arg0); + _emscripten_bind_Layout_SetName_1(self, arg0); +};; + +Layout.prototype['GetName'] = function() { + var self = this.ptr; + return Pointer_stringify(_emscripten_bind_Layout_GetName_0(self)); +};; + + Layout.prototype['__destroy__'] = function() { + var self = this.ptr; + _emscripten_bind_Layout___destroy___0(self); +}; +// InitialInstanceFunctor +function InitialInstanceFunctor() { throw "cannot construct a InitialInstanceFunctor, no constructor in IDL" } +InitialInstanceFunctor.prototype = Object.create(WrapperObject.prototype); +InitialInstanceFunctor.prototype.constructor = InitialInstanceFunctor; +InitialInstanceFunctor.prototype.__class__ = InitialInstanceFunctor; +InitialInstanceFunctor.__cache__ = {}; +Module['InitialInstanceFunctor'] = InitialInstanceFunctor; + + InitialInstanceFunctor.prototype['__destroy__'] = function() { + var self = this.ptr; + _emscripten_bind_InitialInstanceFunctor___destroy___0(self); +}; +// InitialInstance +function InitialInstance() { + this.ptr = _emscripten_bind_InitialInstance_InitialInstance_0(); + getCache(InitialInstance)[this.ptr] = this; +};; +InitialInstance.prototype = Object.create(WrapperObject.prototype); +InitialInstance.prototype.constructor = InitialInstance; +InitialInstance.prototype.__class__ = InitialInstance; +InitialInstance.__cache__ = {}; +Module['InitialInstance'] = InitialInstance; + +InitialInstance.prototype['SetObjectName'] = function(arg0) { + var self = this.ptr; + if (arg0 && typeof arg0 === 'object') arg0 = arg0.ptr; + else arg0 = ensureString(arg0); + _emscripten_bind_InitialInstance_SetObjectName_1(self, arg0); +};; + +InitialInstance.prototype['GetObjectName'] = function() { + var self = this.ptr; + return Pointer_stringify(_emscripten_bind_InitialInstance_GetObjectName_0(self)); +};; + +InitialInstance.prototype['GetX'] = function() { + var self = this.ptr; + return _emscripten_bind_InitialInstance_GetX_0(self); +};; + +InitialInstance.prototype['SetX'] = function(arg0) { + var self = this.ptr; + if (arg0 && typeof arg0 === 'object') arg0 = arg0.ptr; + else arg0 = ensureString(arg0); + _emscripten_bind_InitialInstance_SetX_1(self, arg0); +};; + +InitialInstance.prototype['GetY'] = function() { + var self = this.ptr; + return _emscripten_bind_InitialInstance_GetY_0(self); +};; + +InitialInstance.prototype['SetY'] = function(arg0) { + var self = this.ptr; + if (arg0 && typeof arg0 === 'object') arg0 = arg0.ptr; + else arg0 = ensureString(arg0); + _emscripten_bind_InitialInstance_SetY_1(self, arg0); +};; + +InitialInstance.prototype['GetAngle'] = function() { + var self = this.ptr; + return _emscripten_bind_InitialInstance_GetAngle_0(self); +};; + +InitialInstance.prototype['SetAngle'] = function(arg0) { + var self = this.ptr; + if (arg0 && typeof arg0 === 'object') arg0 = arg0.ptr; + else arg0 = ensureString(arg0); + _emscripten_bind_InitialInstance_SetAngle_1(self, arg0); +};; + +InitialInstance.prototype['GetZOrder'] = function() { + var self = this.ptr; + return _emscripten_bind_InitialInstance_GetZOrder_0(self); +};; + +InitialInstance.prototype['SetZOrder'] = function(arg0) { + var self = this.ptr; + if (arg0 && typeof arg0 === 'object') arg0 = arg0.ptr; + else arg0 = ensureString(arg0); + _emscripten_bind_InitialInstance_SetZOrder_1(self, arg0); +};; + +InitialInstance.prototype['GetLayer'] = function() { + var self = this.ptr; + return Pointer_stringify(_emscripten_bind_InitialInstance_GetLayer_0(self)); +};; + +InitialInstance.prototype['SetLayer'] = function(arg0) { + var self = this.ptr; + if (arg0 && typeof arg0 === 'object') arg0 = arg0.ptr; + else arg0 = ensureString(arg0); + _emscripten_bind_InitialInstance_SetLayer_1(self, arg0); +};; + + InitialInstance.prototype['__destroy__'] = function() { + var self = this.ptr; + _emscripten_bind_InitialInstance___destroy___0(self); +}; +// InitialInstanceJSFunctorWrapper +function InitialInstanceJSFunctorWrapper() { throw "cannot construct a InitialInstanceJSFunctorWrapper, no constructor in IDL" } +InitialInstanceJSFunctorWrapper.prototype = Object.create(WrapperObject.prototype); +InitialInstanceJSFunctorWrapper.prototype.constructor = InitialInstanceJSFunctorWrapper; +InitialInstanceJSFunctorWrapper.prototype.__class__ = InitialInstanceJSFunctorWrapper; +InitialInstanceJSFunctorWrapper.__cache__ = {}; +Module['InitialInstanceJSFunctorWrapper'] = InitialInstanceJSFunctorWrapper; + + InitialInstanceJSFunctorWrapper.prototype['__destroy__'] = function() { + var self = this.ptr; + _emscripten_bind_InitialInstanceJSFunctorWrapper___destroy___0(self); +}; +// InitialInstanceJSFunctor +function InitialInstanceJSFunctor() { + this.ptr = _emscripten_bind_InitialInstanceJSFunctor_InitialInstanceJSFunctor_0(); + getCache(InitialInstanceJSFunctor)[this.ptr] = this; +};; +InitialInstanceJSFunctor.prototype = Object.create(InitialInstanceJSFunctorWrapper.prototype); +InitialInstanceJSFunctor.prototype.constructor = InitialInstanceJSFunctor; +InitialInstanceJSFunctor.prototype.__class__ = InitialInstanceJSFunctor; +InitialInstanceJSFunctor.__cache__ = {}; +Module['InitialInstanceJSFunctor'] = InitialInstanceJSFunctor; + +InitialInstanceJSFunctor.prototype['invoke'] = function(arg0) { + var self = this.ptr; + if (arg0 && typeof arg0 === 'object') arg0 = arg0.ptr; + else arg0 = ensureString(arg0); + _emscripten_bind_InitialInstanceJSFunctor_invoke_1(self, arg0); +};; + + InitialInstanceJSFunctor.prototype['__destroy__'] = function() { + var self = this.ptr; + _emscripten_bind_InitialInstanceJSFunctor___destroy___0(self); +}; +// Project +function Project() { + this.ptr = _emscripten_bind_Project_Project_0(); + getCache(Project)[this.ptr] = this; +};; +Project.prototype = Object.create(WrapperObject.prototype); +Project.prototype.constructor = Project; +Project.prototype.__class__ = Project; +Project.__cache__ = {}; +Module['Project'] = Project; + +Project.prototype['SetName'] = function(arg0) { + var self = this.ptr; + if (arg0 && typeof arg0 === 'object') arg0 = arg0.ptr; + else arg0 = ensureString(arg0); + _emscripten_bind_Project_SetName_1(self, arg0); +};; + +Project.prototype['GetName'] = function() { + var self = this.ptr; + return Pointer_stringify(_emscripten_bind_Project_GetName_0(self)); +};; + +Project.prototype['SetAuthor'] = function(arg0) { + var self = this.ptr; + if (arg0 && typeof arg0 === 'object') arg0 = arg0.ptr; + else arg0 = ensureString(arg0); + _emscripten_bind_Project_SetAuthor_1(self, arg0); +};; + +Project.prototype['GetAuthor'] = function() { + var self = this.ptr; + return Pointer_stringify(_emscripten_bind_Project_GetAuthor_0(self)); +};; + +Project.prototype['SetProjectFile'] = function(arg0) { + var self = this.ptr; + if (arg0 && typeof arg0 === 'object') arg0 = arg0.ptr; + else arg0 = ensureString(arg0); + _emscripten_bind_Project_SetProjectFile_1(self, arg0); +};; + +Project.prototype['GetProjectFile'] = function() { + var self = this.ptr; + return Pointer_stringify(_emscripten_bind_Project_GetProjectFile_0(self)); +};; + +Project.prototype['SetDefaultWidth'] = function(arg0) { + var self = this.ptr; + if (arg0 && typeof arg0 === 'object') arg0 = arg0.ptr; + else arg0 = ensureString(arg0); + _emscripten_bind_Project_SetDefaultWidth_1(self, arg0); +};; + +Project.prototype['GetMainWindowDefaultWidth'] = function() { + var self = this.ptr; + return _emscripten_bind_Project_GetMainWindowDefaultWidth_0(self); +};; + +Project.prototype['SetDefaultHeight'] = function(arg0) { + var self = this.ptr; + if (arg0 && typeof arg0 === 'object') arg0 = arg0.ptr; + else arg0 = ensureString(arg0); + _emscripten_bind_Project_SetDefaultHeight_1(self, arg0); +};; + +Project.prototype['GetMainWindowDefaultHeight'] = function() { + var self = this.ptr; + return _emscripten_bind_Project_GetMainWindowDefaultHeight_0(self); +};; + +Project.prototype['GetMaximumFPS'] = function() { + var self = this.ptr; + return _emscripten_bind_Project_GetMaximumFPS_0(self); +};; + +Project.prototype['SetMaximumFPS'] = function(arg0) { + var self = this.ptr; + if (arg0 && typeof arg0 === 'object') arg0 = arg0.ptr; + else arg0 = ensureString(arg0); + _emscripten_bind_Project_SetMaximumFPS_1(self, arg0); +};; + +Project.prototype['GetMinimumFPS'] = function() { + var self = this.ptr; + return _emscripten_bind_Project_GetMinimumFPS_0(self); +};; + +Project.prototype['SetMinimumFPS'] = function(arg0) { + var self = this.ptr; + if (arg0 && typeof arg0 === 'object') arg0 = arg0.ptr; + else arg0 = ensureString(arg0); + _emscripten_bind_Project_SetMinimumFPS_1(self, arg0); +};; + +Project.prototype['GetUsedExtensions'] = function() { + var self = this.ptr; + return wrapPointer(_emscripten_bind_Project_GetUsedExtensions_0(self), VectorString); +};; + +Project.prototype['HasLayoutNamed'] = function(arg0) { + var self = this.ptr; + if (arg0 && typeof arg0 === 'object') arg0 = arg0.ptr; + else arg0 = ensureString(arg0); + return _emscripten_bind_Project_HasLayoutNamed_1(self, arg0); +};; + +Project.prototype['InsertNewLayout'] = function(arg0, arg1) { + var self = this.ptr; + if (arg0 && typeof arg0 === 'object') arg0 = arg0.ptr; + else arg0 = ensureString(arg0); + if (arg1 && typeof arg1 === 'object') arg1 = arg1.ptr; + else arg1 = ensureString(arg1); + return wrapPointer(_emscripten_bind_Project_InsertNewLayout_2(self, arg0, arg1), Layout); +};; + +Project.prototype['GetLayout'] = function(arg0) { + var self = this.ptr; + if (arg0 && typeof arg0 === 'object') arg0 = arg0.ptr; + else arg0 = ensureString(arg0); + return wrapPointer(_emscripten_bind_Project_GetLayout_1(self, arg0), Layout); +};; + + Project.prototype['__destroy__'] = function() { + var self = this.ptr; + _emscripten_bind_Project___destroy___0(self); +}; +// ProjectHelper +function ProjectHelper() { throw "cannot construct a ProjectHelper, no constructor in IDL" } +ProjectHelper.prototype = Object.create(WrapperObject.prototype); +ProjectHelper.prototype.constructor = ProjectHelper; +ProjectHelper.prototype.__class__ = ProjectHelper; +ProjectHelper.__cache__ = {}; +Module['ProjectHelper'] = ProjectHelper; + +ProjectHelper.prototype['STATIC_CreateNewGDJSProject'] = function() { + var self = this.ptr; + return wrapPointer(_emscripten_bind_ProjectHelper_STATIC_CreateNewGDJSProject_0(self), Project); +};; + +ProjectHelper.prototype['STATIC_InitializePlatforms'] = function() { + var self = this.ptr; + _emscripten_bind_ProjectHelper_STATIC_InitializePlatforms_0(self); +};; + + ProjectHelper.prototype['__destroy__'] = function() { + var self = this.ptr; + _emscripten_bind_ProjectHelper___destroy___0(self); +}; +// VoidPtr +function VoidPtr() { throw "cannot construct a VoidPtr, no constructor in IDL" } +VoidPtr.prototype = Object.create(WrapperObject.prototype); +VoidPtr.prototype.constructor = VoidPtr; +VoidPtr.prototype.__class__ = VoidPtr; +VoidPtr.__cache__ = {}; +Module['VoidPtr'] = VoidPtr; + + VoidPtr.prototype['__destroy__'] = function() { + var self = this.ptr; + _emscripten_bind_VoidPtr___destroy___0(self); +}; +(function() { + function setupEnums() { + + } + if (Module['calledRun']) setupEnums(); + else addOnPreMain(setupEnums); +})(); diff --git a/Bindings/postjs.js b/Bindings/postjs.js new file mode 100644 index 0000000..2e0ee93 --- /dev/null +++ b/Bindings/postjs.js @@ -0,0 +1,57 @@ +Module = Module || {}; +var gd = Module; + +// Make sure that the naming convention for methods of GDevelop +// classes is camelCase (instead of CamelCase) and rename methods +// starting by WRAPPED_. +(function(gd) { + function uncapitalizeFirstLetter(method) { + return method.charAt(0).toLowerCase() + method.slice(1); + } + + function removePrefix(method, prefix) { + if (method.indexOf(prefix) !== 0) + return method; + + return method.replace(prefix, ""); + } + + function adaptClassMethods(object) { + var proto = object.prototype; + for (var method in proto) { + if (method && proto.hasOwnProperty(method)) { + var newName = method; + var addToObject = false; + + //Detect static methods + if (method.indexOf("STATIC_") == 0) { + newName = removePrefix(newName, "STATIC_"); + addToObject = true; + } + + //Normalize method name + newName = removePrefix(uncapitalizeFirstLetter(newName), "WRAPPED_"); + if (newName !== method) { + proto[newName] = proto[method]; + delete proto[method]; + } + + if (addToObject) { + object[newName] = proto[newName]; + } + } + } + } + + for(var gdClass in gd) { + if (gd.hasOwnProperty(gdClass)) { + if (typeof gd[gdClass] !== "function") continue; + if (!gd[gdClass].prototype) continue; + if (!gd[gdClass].prototype.hasOwnProperty("__class__")) continue; + + adaptClassMethods(gd[gdClass]); + } + } + + gd.initializePlatforms = gd.ProjectHelper.prototype.initializePlatforms; +})(gd); diff --git a/WebIDE/prejs.js b/Bindings/prejs.js similarity index 100% rename from WebIDE/prejs.js rename to Bindings/prejs.js diff --git a/CMakeLists.txt b/CMakeLists.txt index add675f..ce911c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,36 +11,26 @@ ENDIF() if(NOT EMSCRIPTEN) error("You're trying to compile the WebIDE without emscripten.") endif() -SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-warn-absolute-paths --bind" ) +SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-warn-absolute-paths" ) SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --memory-init-file 0" ) #Less efficient, but output a single JS file -SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s ASSERTIONS=2" ) #Debug +SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s ASSERTIONS=2 -s SAFE_HEAP=1" ) #Debug #Common directories: ### -set(GD_base_dir ${CMAKE_CURRENT_SOURCE_DIR}/..) -set(GDCORE_include_dir ${GD_base_dir}/Core) -set(GDCORE_lib_dir ${GD_base_dir}/Binaries/Output/${CMAKE_BUILD_TYPE}_${CMAKE_SYSTEM_NAME}) set(GDCpp_include_dir ${GD_base_dir}/GDCpp) set(GDCpp_lib_dir ${GD_base_dir}/Binaries/Output/${CMAKE_BUILD_TYPE}_${CMAKE_SYSTEM_NAME}) set(GDJS_include_dir ${GD_base_dir}/GDJS) set(GDJS_lib_dir ${GD_base_dir}/Binaries/Output/${CMAKE_BUILD_TYPE}_${CMAKE_SYSTEM_NAME}/JsPlatform) +set(GDCpp_include_dir ${GDCpp_include_dir} PARENT_SCOPE) #Expose GDCpp directories to extensions for includes. +set(GDCpp_lib_dir ${GDCpp_lib_dir} PARENT_SCOPE) + #Dependencies on external libraries: ### -include_directories(${boost_include_dir}) include_directories(${sfml_include_dir}) include_directories(${GDCORE_include_dir}) include_directories(${GDCpp_include_dir}) include_directories(${GDJS_include_dir}) -IF(NOT TARGET GDCore) #Ensure that the build will work even when GDCore is not in the target list. -link_directories(${GDCORE_lib_dir}) -ENDIF() -IF(NOT TARGET GDCpp) #Ensure that the build will work even when GDCpp is not in the target list. -link_directories(${GDCpp_lib_dir}) -ENDIF() -IF(NOT TARGET GDJS) #Ensure that the build will work even when GDJS is not in the target list. -link_directories(${GDJS_lib_dir}) -ENDIF() #Defines ### @@ -68,16 +58,11 @@ add_definitions( -DGD_EXTENSION_API= ) #The target ### include_directories(.) -file( - GLOB_RECURSE - source_files - WebIDE/* -) add_library( GD SHARED - ${source_files} + "Bindings/Wrapper.cpp" ) set_target_properties(GD PROPERTIES SUFFIX ".raw.js") set(LIBRARY_OUTPUT_PATH ${GD_base_dir}/Binaries/Output/WebIDE/${CMAKE_BUILD_TYPE}) diff --git a/Gruntfile.js b/Gruntfile.js index 8741605..57f9bdd 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -14,7 +14,7 @@ module.exports = function(grunt) { separator: ';', }, dist: { - src: ['WebIDE/prejs.js', buildDirectory+'libGD.raw.js', 'WebIDE/postjs.js'], + src: ['Bindings/prejs.js', buildDirectory+'libGD.raw.js', 'Bindings/glue.js', 'Bindings/postjs.js'], dest: buildDirectory+'libGD.js', }, }, @@ -51,4 +51,4 @@ module.exports = function(grunt) { grunt.loadNpmTasks('grunt-contrib-compress'); grunt.registerTask('build', [ 'clean', 'concat', 'compress' ]); grunt.registerTask('test', ['mochacli']); -}; \ No newline at end of file +}; diff --git a/Readme.md b/Readme.md index ef3ff8e..9b20861 100644 --- a/Readme.md +++ b/Readme.md @@ -1,18 +1,38 @@ libGD.js ======== -This is a port of some parts of GDevelop to Javascript using Emscripten. +This is a port of some parts of [GDevelop] to Javascript using [Emscripten]. + +GDevelop is a full featured, cross-platform, open-source game creator software requiring no programming skills. Download it on [the official website](http://compilgames.net) and check its [GitHub page](https://github.com/4ian/GD). How to build ------------ -* Put this repository into a folder called WebIDE at the root of the GDevelop repository. -* Launch CMake, choose the emscripten toolchain, and the root of the GD repository for the sources. -* Go to the folder where the makefile was generated and launch the compilation. +* Clone [GDevelop repository](https://github.com/4ian/GD) + + git clone https://github.com/4ian/GD.git + +* Put libGD.js into a folder called `WebIDE` at the root of the GDevelop repository. +* Launch [CMake](http://www.cmake.org/), choose the Emscripten toolchain, and the root of the GDevelop repository for the sources. For example: + + cd /path/to/GD + mkdir embuild && cd embuild + cmake .. -DCMAKE_TOOLCHAIN_FILE=/path/to/emsdk/emscripten/1.30.0/cmake/Modules/Platform/Emscripten.cmake -You may need to do: +* Patch SFML (TODO) +* TODO: try tweak options if error +* Launch compilation: + + make + +## Building for old versions of emscripten + +With old versions of emscripten, you may need to do: set EMCC_FAST_COMPILER=0 //on Windows export EMCC_FAST_COMPILER=0 //on Linux before starting the compilation. + +[GDevelop]: https://github.com/4ian/GD +[Emscripten]: https://github.com/kripken/emscripten diff --git a/WebIDE/Bindings/Extensions/TextObject/Embind.cpp b/WebIDE/Bindings/Extensions/TextObject/Embind.cpp deleted file mode 100644 index 9276ae9..0000000 --- a/WebIDE/Bindings/Extensions/TextObject/Embind.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/** - -GDevelop - Text Object Extension -Copyright (c) 2008-2014 Florian Rival (Florian.Rival@gmail.com) -This project is released under the MIT License. -*/ - -/* - * When cross-compiling using emscripten, this file exposes the extension API - * to javascript. - */ -#if defined(EMSCRIPTEN) -#include -#include "GDCore/PlatformDefinition/Layout.h" -#include "GDCore/PlatformDefinition/Project.h" -#include "GDCore/PlatformDefinition/Platform.h" -#include "../../../../../Extensions/TextObject/TextObject.h" - -using namespace emscripten; - -EMSCRIPTEN_BINDINGS(gd_TextObject) { - class_ >("TextObject") - .constructor() - .function("setString", &TextObject::SetString) - .function("getString", &TextObject::GetString) - .function("setCharacterSize", &TextObject::SetCharacterSize) - .function("getCharacterSize", &TextObject::GetCharacterSize) - .function("setFontFilename", &TextObject::SetFontFilename) - .function("getFontFilename", &TextObject::GetFontFilename) - .function("isBold", &TextObject::IsBold) - .function("setBold", &TextObject::SetBold) - .function("isItalic", &TextObject::IsItalic) - .function("setItalic", &TextObject::SetItalic) - .function("isUnderlined", &TextObject::IsUnderlined) - .function("setUnderlined", &TextObject::SetUnderlined) - .function("setColor", &TextObject::SetColor) - .function("getColorR", &TextObject::GetColorR) - .function("getColorG", &TextObject::GetColorG) - .function("getColorB", &TextObject::GetColorB) - ; -} -#endif diff --git a/WebIDE/Bindings/Extensions/TiledSpriteObject/Embind.cpp b/WebIDE/Bindings/Extensions/TiledSpriteObject/Embind.cpp deleted file mode 100644 index 20ad9a6..0000000 --- a/WebIDE/Bindings/Extensions/TiledSpriteObject/Embind.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/** - -GDevelop - Tiled Sprite Extension -Copyright (c) 2012 Victor Levasseur (victorlevasseur01@orange.fr) -Copyright (c) 2014 Florian Rival (Florian.Rival@gmail.com) -This project is released under the MIT License. -*/ - -/* - * When cross-compiling using emscripten, this file exposes the extension API - * to javascript. - */ -#if defined(EMSCRIPTEN) -#include -#include "GDCore/PlatformDefinition/Layout.h" -#include "GDCore/PlatformDefinition/Project.h" -#include "GDCore/PlatformDefinition/Platform.h" -#include "../../../../../Extensions/TiledSpriteObject/TiledSpriteObject.h" - -using namespace emscripten; - -EMSCRIPTEN_BINDINGS(gd_TiledSpriteObject) { - class_ >("TiledSpriteObject") - .constructor() - .function("setTexture", &TiledSpriteObject::SetTexture) - .function("getTexture", &TiledSpriteObject::GetTexture) - .function("setWidth", &TiledSpriteObject::SetWidth) - .function("setHeight", &TiledSpriteObject::SetHeight) - .function("getWidth", &TiledSpriteObject::GetWidth) - .function("getHeight", &TiledSpriteObject::GetHeight) - ; -} -#endif diff --git a/WebIDE/Bindings/GDCore/Embind.cpp b/WebIDE/Bindings/GDCore/Embind.cpp deleted file mode 100644 index 0707b6b..0000000 --- a/WebIDE/Bindings/GDCore/Embind.cpp +++ /dev/null @@ -1,448 +0,0 @@ -/* - * GDevelop Core - * Copyright 2008-2014 Florian Rival (Florian.Rival@gmail.com). All rights reserved. - * This project is released under the MIT License. - */ - -/* - * When cross-compiling using emscripten, this file exposes the GDCore API - * to javascript. - * - * The javascript API of GDCore is the same as the C++ one except that: - * - functions begins lowercase ("getLayout"), - * - not all methods or classes are available. - */ -#if defined(EMSCRIPTEN) -#include "Embind.h" -#include -#include "GDCore/IDE/Dialogs/ObjectListDialogsHelper.h" -#include "GDCore/IDE/Dialogs/PropertyDescriptor.h" -#include "GDCore/IDE/ArbitraryResourceWorker.h" -#include "GDCore/PlatformDefinition/Layout.h" -#include "GDCore/PlatformDefinition/Project.h" -#include "GDCore/PlatformDefinition/Platform.h" -#include "GDCore/PlatformDefinition/VariablesContainer.h" -#include "GDCore/PlatformDefinition/Object.h" -#include "GDCore/PlatformDefinition/Automatism.h" -#include "GDCore/Serialization/Serializer.h" -#include "GDCore/Events/Event.h" -#include "GDCore/Events/EventsList.h" -#include - -using namespace emscripten; -using namespace gd; - -EMSCRIPTEN_BINDINGS(gd_Platform) { - class_("Platform") - .constructor<>() - .function("getName", &Platform::GetName) - .function("getFullName", &Platform::GetFullName) - .function("getSubtitle", &Platform::GetSubtitle) - .function("getDescription", &Platform::GetDescription) - .function("getAllPlatformExtensions", &Platform::GetAllPlatformExtensions) - .function("isExtensionLoaded", &Platform::IsExtensionLoaded) - .function("createObject", &Platform::CreateObject); - ; -} - -namespace gd { //Workaround for emscripten not supporting methods returning a reference (objects are returned by copy in JS). -const std::string & PairStringVariable_GetFirst(std::pair & p) { return p.first; } -gd::Variable * PairStringVariable_GetSecond(std::pair & p) { return &p.second; } -Variable * Variable_GetChild(Variable & v, const std::string & name) { return &v.GetChild(name); } -} - -EMSCRIPTEN_BINDINGS(gd_Variable) { - class_< std::pair >("PairStringVariable") - .constructor<>() - .function("getString", PairStringVariable_GetFirst, allow_raw_pointers()) - .function("getName", PairStringVariable_GetFirst, allow_raw_pointers()) - .function("getVariable", PairStringVariable_GetSecond, allow_raw_pointers()) - ; - - class_("Variable") - .constructor<>() - .function("getString", &Variable::GetString) - .function("setString", &Variable::SetString) - .function("getValue", &Variable::GetValue) - .function("setValue", &Variable::SetValue) - .function("hasChild", &Variable::HasChild) - .function("getChild", &Variable_GetChild, allow_raw_pointers()) - .function("removeChild", &Variable::RemoveChild) - .function("getAllChildren", &Variable::GetAllChildren) - .function("isNumber", &Variable::IsNumber) - .function("isStructure", &Variable::IsStructure) - ; -} - -namespace gd { //Workaround for emscripten not supporting methods returning a reference (objects are returned by copy in JS). -Variable * VariablesContainer_Get(VariablesContainer & v, const std::string & name) { return &v.Get(name); } -std::pair * VariablesContainer_GetAt(VariablesContainer & v, unsigned int pos) { return &v.Get(pos); } -Variable * VariablesContainer_Insert(VariablesContainer & v, const std::string & name, const Variable & variable, unsigned int position) { return &v.Insert(name, variable, position); } -Variable * VariablesContainer_InsertNew(VariablesContainer & v, const std::string & name, unsigned int position) { return &v.InsertNew(name, position); } -} - -EMSCRIPTEN_BINDINGS(gd_VariablesContainer) { - class_("VariablesContainer") - .constructor<>() - .function("has", &VariablesContainer::Has) - .function("get", &VariablesContainer_Get, allow_raw_pointers()) - .function("getAt", &VariablesContainer_GetAt, allow_raw_pointers()) - .function("insert", &VariablesContainer_Insert, allow_raw_pointers()) - .function("insertNew", &VariablesContainer_InsertNew, allow_raw_pointers()) - .function("remove", &VariablesContainer::Remove) - .function("rename", &VariablesContainer::Rename) - .function("swap", &VariablesContainer::Swap) - .function("getPosition", &VariablesContainer::GetPosition) //TODO: Rename in getIndexOf? - .function("count", &VariablesContainer::Count) - .function("clear", &VariablesContainer::Clear) - ; -} - -namespace gd { //Workaround for emscripten not supporting methods returning a reference (objects are returned by copy in JS). -gd::Layout * Project_GetLayout(gd::Project & project, const std::string & name) { return &project.GetLayout(name); } -gd::Layout * Project_GetLayoutAt(gd::Project & project, unsigned int i) { return &project.GetLayout(i); } -gd::VariablesContainer * Project_GetVariables(gd::Project & project) { return &project.GetVariables(); } -gd::ResourcesManager * Project_GetResourcesManager(gd::Project & project) { return &project.GetResourcesManager(); } -gd::Layout * Project_InsertNewLayout(gd::Project & project, const std::string & name, unsigned int pos) { return &project.InsertNewLayout(name, pos); } -std::vector < std::string > * Project_GetUsedExtensions(gd::Project & project) { return &project.GetUsedExtensions(); } -} - -EMSCRIPTEN_BINDINGS(gd_Project) { - class_ >("Project") - .constructor<>() - .function("getName", &Project::GetName) - .function("setName", &Project::SetName) - .function("getAuthor", &Project::GetAuthor) - .function("setAuthor", &Project::SetAuthor) - .function("getProjectFile", &Project::GetProjectFile) - .function("setProjectFile", &Project::SetProjectFile) - .function("getMainWindowDefaultWidth", &Project::GetMainWindowDefaultWidth) - .function("setDefaultWidth", &Project::SetDefaultWidth) - .function("getMainWindowDefaultHeight", &Project::GetMainWindowDefaultHeight) - .function("setDefaultHeight", &Project::SetDefaultHeight) - .function("getMaximumFPS", &Project::GetMaximumFPS) - .function("setMaximumFPS", &Project::SetMaximumFPS) - .function("getMinimumFPS", &Project::GetMinimumFPS) - .function("setMinimumFPS", &Project::SetMinimumFPS) - - .function("addPlatform", &Project::AddPlatform) - .function("getCurrentPlatform", &Project::GetCurrentPlatform) - .function("getUsedExtensions", &Project_GetUsedExtensions, allow_raw_pointers()) - .function("createObject", &Project::CreateObject) - .function("createEvent", &Project::CreateEvent) - - .function("hasLayoutNamed", &Project::HasLayoutNamed) - .function("getLayout", gd::Project_GetLayout, allow_raw_pointers()) - .function("getLayoutAt", gd::Project_GetLayoutAt, allow_raw_pointers()) - .function("getLayoutsCount", &gd::Project::GetLayoutsCount) - .function("insertNewLayout", &Project_InsertNewLayout, allow_raw_pointers()) - .function("removeLayout", &Project::RemoveLayout) - .function("getFirstLayout", &Project::GetFirstLayout).function("setFirstLayout", &Project::SetFirstLayout) - - .function("getVariables", &Project_GetVariables, allow_raw_pointers()) - .function("getResourcesManager", &Project_GetResourcesManager, allow_raw_pointers()) - .function("exposeResources", &Project::ExposeResources) - - .class_function("validateObjectName", &Project::ValidateObjectName) - - .function("isDirty", &Project::IsDirty).function("setDirty", &Project::SetDirty) - .function("serializeTo", &Project::SerializeTo).function("unserializeFrom", &Project::UnserializeFrom) - //Properties, for convenience only: - .property("name", &Project::GetName, &Project::SetName) - .property("author", &Project::GetAuthor, &Project::SetAuthor) - .property("width", &Project::GetMainWindowDefaultWidth, &Project::SetDefaultWidth) - .property("height", &Project::GetMainWindowDefaultHeight, &Project::SetDefaultHeight) - .property("maximumFPS", &Project::GetMaximumFPS, &Project::SetMaximumFPS) - .property("minimumFPS", &Project::GetMinimumFPS, &Project::SetMinimumFPS) - //.property("dirty", &Project::IsDirty, &Project::SetDirty) - ; -} - -EMSCRIPTEN_BINDINGS(gd_Automatism) { - class_("Automatism") - .constructor<>() - .function("clone", &Automatism::Clone, allow_raw_pointers()) - .function("getName", &Automatism::GetName) - .function("setName", &Automatism::SetName) - .function("getTypeName", &Automatism::GetTypeName) - .function("getProperties", &Automatism::GetProperties) - .function("updateProperty", &Automatism::UpdateProperty) - ; - - function("getAutomatismsOfObject", gd::GetAutomatismsOfObject); - function("getTypeOfAutomatism", gd::GetTypeOfAutomatism); -} - - -namespace gd { //Workaround for emscripten not supporting methods returning a reference (objects are returned by copy in JS). -gd::VariablesContainer * Object_GetVariables(gd::Object & o) { return &o.GetVariables(); } -gd::Automatism * Object_GetAutomatism(gd::Object & o, const std::string & name) { return &o.GetAutomatism(name); } -} - -EMSCRIPTEN_BINDINGS(gd_Object) { - class_("Object") - .constructor() - .function("clone", &Object::Clone, allow_raw_pointers()) - .function("getType", &Object::GetType) - .function("setType", &Object::SetType) - .function("getName", &Object::GetName) - .function("setName", &Object::SetName) - .function("getVariables", &Object_GetVariables, allow_raw_pointers()) - .function("getAllAutomatismNames", &Object::GetAllAutomatismNames) - .function("hasAutomatismNamed", &Object::HasAutomatismNamed) - .function("addNewAutomatism", &Object::AddNewAutomatism, allow_raw_pointers()) - .function("getAutomatism", &Object_GetAutomatism, allow_raw_pointers()) - .function("removeAutomatism", &Object::RemoveAutomatism) - .function("renameAutomatism", &Object::RenameAutomatism) - .function("serializeTo", &Object::SerializeTo) - .function("unserializeFrom", &Object::UnserializeFrom) - //Properties, for convenience only: - .property("name", &Object::GetName, &Object::SetName) - ; -} -EMSCRIPTEN_BINDINGS(gd_ObjectGroup) { - class_("ObjectGroup") - .constructor<>() - .function("getName", &ObjectGroup::GetName).function("setName", &ObjectGroup::SetName) - .function("addObject", &ObjectGroup::AddObject) - .function("removeObject", &ObjectGroup::RemoveObject) - .function("find", &ObjectGroup::Find) - //Properties, for convenience only: - .property("name", &ObjectGroup::GetName, &ObjectGroup::SetName) - ; -} - - -namespace gd { //Workaround for emscripten not supporting methods returning a reference (objects are returned by copy in JS). -gd::InitialInstancesContainer * Layout_GetInitialInstances(gd::Layout & l) { return &l.GetInitialInstances(); } -gd::VariablesContainer * Layout_GetVariables(gd::Layout & l) { return &l.GetVariables(); } -gd::Layer * Layout_GetLayer(gd::Layout & l, const std::string & name) { return &l.GetLayer(name); } -gd::Layer * Layout_GetLayerAt(gd::Layout & l, unsigned int i) { return &l.GetLayer(i); } -gd::EventsList * Layout_GetEvents(gd::Layout & l) { return &l.GetEvents(); } -gd::Object * ClassWithObjects_GetObject(gd::ClassWithObjects & c, const std::string & name) { return &c.GetObject(name); } -gd::Object * ClassWithObjects_GetObjectAt(gd::ClassWithObjects & c, unsigned int id) { return &c.GetObject(id); } -gd::Object * ClassWithObjects_InsertNewObject(gd::ClassWithObjects & c, gd::Project & p, const std::string & o, const std::string & n, unsigned int pos) { return &c.InsertNewObject(p, o, n, pos); } -gd::Object * ClassWithObjects_InsertObject(gd::ClassWithObjects & c, const gd::Object & o, unsigned int p) { return &c.InsertObject(o, p); } -} - -EMSCRIPTEN_BINDINGS(gd_Layout) { - class_("ClassWithObjects") - .constructor<>() - .function("insertNewObject", &ClassWithObjects_InsertNewObject, allow_raw_pointers()) - .function("insertObject", &ClassWithObjects_InsertObject, allow_raw_pointers()) - .function("hasObjectNamed", &ClassWithObjects::HasObjectNamed) - .function("getObject", &ClassWithObjects_GetObject, allow_raw_pointers()) - .function("getObjectAt", &ClassWithObjects_GetObjectAt, allow_raw_pointers()) - .function("getObjectPosition", &ClassWithObjects::GetObjectPosition) - .function("removeObject", &ClassWithObjects::RemoveObject) - .function("swapObjects", &ClassWithObjects::SwapObjects) - .function("getObjectsCount", &ClassWithObjects::GetObjectsCount) - ; - - class_ >("Layout") - .constructor<>() - .function("getName", &Layout::GetName).function("setName", &Layout::SetName) - .function("setBackgroundColor", &Layout::SetBackgroundColor) - .function("getBackgroundColorRed", &Layout::GetBackgroundColorRed) - .function("getBackgroundColorGreen", &Layout::GetBackgroundColorGreen) - .function("getBackgroundColorBlue", &Layout::GetBackgroundColorBlue) - .function("getWindowDefaultTitle", &Layout::GetWindowDefaultTitle).function("setWindowDefaultTitle", &Layout::SetWindowDefaultTitle) - - .function("getInitialInstances", &Layout_GetInitialInstances, allow_raw_pointers()) - .function("getVariables", &Layout_GetVariables, allow_raw_pointers()) - .function("getEvents", &Layout_GetEvents, allow_raw_pointers()) - - .function("insertNewLayer", &Layout::InsertNewLayer) - .function("insertLayer", &Layout::InsertLayer) - .function("getLayer", &Layout_GetLayer, allow_raw_pointers()) - .function("getLayerAt", &Layout_GetLayerAt, allow_raw_pointers()) - .function("hasLayerNamed", &Layout::HasLayerNamed) - .function("removeLayer", &Layout::RemoveLayer) - .function("getLayersCount", &Layout::GetLayersCount) - //Properties, for convenience only: - .property("name", &Layout::GetName, &Layout::SetName) - ; -} - -EMSCRIPTEN_BINDINGS(gd_Layer) { - class_("Layer") - .constructor<>() - .function("getName", &Layer::GetName).function("setName", &Layer::SetName) - .function("getVisibility", &Layer::GetVisibility).function("setVisibility", &Layer::SetVisibility) - //Properties, for convenience only: - .property("name", &Layer::GetName, &Layer::SetName) - .property("visibility", &Layer::GetVisibility, &Layer::SetVisibility) - ; -} - -namespace gd { //Workaround for emscripten not supporting methods returning a reference (objects are returned by copy in JS). -gd::Resource * ResourcesManager_GetResource(gd::ResourcesManager & r, const std::string & n) { return &r.GetResource(n); } -} - -EMSCRIPTEN_BINDINGS(gd_ResourcesManager) { - class_("ResourcesManager") - .constructor<>() - .function("getAllResourcesList", &ResourcesManager::GetAllResourcesList) - .function("hasResource", &ResourcesManager::HasResource) - .function("getResource", &ResourcesManager_GetResource, allow_raw_pointers()) - .function("addResource", select_overload(&ResourcesManager::AddResource)) - .function("removeResource", &ResourcesManager::RemoveResource) - .function("renameResource", &ResourcesManager::RenameResource) - .function("moveResourceUpInList", &ResourcesManager::MoveResourceUpInList) - .function("moveResourceDownInList", &ResourcesManager::MoveResourceDownInList) - ; -} - - -EMSCRIPTEN_BINDINGS(gd_Resource) { - class_("Resource") - .constructor<>() - .function("clone", &Resource::Clone, allow_raw_pointers()) - .function("getName", &Resource::GetName) - .function("setName", &Resource::SetName) - .function("getKind", &Resource::GetKind) - .function("setKind", &Resource::SetKind) - .function("isUserAdded", &Resource::IsUserAdded) - .function("setUserAdded", &Resource::SetUserAdded) - .function("useFile", &Resource::UseFile) - .function("getFile", &Resource::GetFile) - .function("setFile", &Resource::SetFile) - .function("getAbsoluteFile", &Resource::GetAbsoluteFile) - .function("serializeTo", &Resource::SerializeTo) - .function("unserializeFrom", &Resource::UnserializeFrom) - //Properties, for convenience only: - .property("name", &Resource::GetName, &Resource::SetName) - .property("kind", &Resource::GetKind, &Resource::SetKind) - ; -} - -namespace gd { //Workaround for emscripten not supporting methods returning a reference (objects are returned by copy in JS). -ImageResource * AsImageResource(gd::Resource * r) { return static_cast(r); } -} - -EMSCRIPTEN_BINDINGS(gd_ImageResource) { - class_ >("ImageResource") - .constructor<>() - ; - - function("asImageResource", &AsImageResource, allow_raw_pointers()); -} - -namespace gd { //Workaround for emscripten not supporting methods returning a reference (objects are returned by copy in JS). -gd::VariablesContainer * InitialInstance_GetVariables(gd::InitialInstance & i) { return &i.GetVariables(); } -} - -EMSCRIPTEN_BINDINGS(gd_InitialInstance) { - class_("InitialInstance") - .constructor<>() - .function("clone", &InitialInstance::Clone, allow_raw_pointers()) - .function("getObjectName", &InitialInstance::GetObjectName).function("setObjectName", &InitialInstance::SetObjectName) - .function("getX", &InitialInstance::GetX).function("setX", &InitialInstance::SetX) - .function("getY", &InitialInstance::GetY).function("setY", &InitialInstance::SetY) - .function("getAngle", &InitialInstance::GetAngle).function("setAngle", &InitialInstance::SetAngle) - .function("getZOrder", &InitialInstance::GetZOrder).function("setZOrder", &InitialInstance::SetZOrder) - .function("getLayer", &InitialInstance::GetLayer).function("setLayer", &InitialInstance::SetLayer) - .function("hasCustomSize", &InitialInstance::HasCustomSize).function("setHasCustomSize", &InitialInstance::SetHasCustomSize) - .function("getCustomWidth", &InitialInstance::GetCustomWidth).function("setCustomWidth", &InitialInstance::SetCustomWidth) - .function("getCustomHeight", &InitialInstance::GetCustomHeight).function("setCustomHeight", &InitialInstance::SetCustomHeight) - .function("isLocked", &InitialInstance::IsLocked).function("setLocked", &InitialInstance::SetLocked) - .function("getCustomProperties", &InitialInstance::GetCustomProperties) - .function("updateCustomProperty", &InitialInstance::UpdateCustomProperty) - .function("getVariables", &InitialInstance_GetVariables, allow_raw_pointers()) - //Properties, for convenience only: - .property("objectName", &InitialInstance::GetObjectName, &InitialInstance::SetObjectName) - .property("x", &InitialInstance::GetX, &InitialInstance::SetX) - .property("y", &InitialInstance::GetY, &InitialInstance::SetY) - .property("angle", &InitialInstance::GetAngle, &InitialInstance::SetAngle) - .property("zOrder", &InitialInstance::GetZOrder, &InitialInstance::SetZOrder) - .property("layer", &InitialInstance::GetLayer, &InitialInstance::SetLayer) - .property("customWidth", &InitialInstance::GetCustomWidth, &InitialInstance::SetCustomWidth) - .property("customHeight", &InitialInstance::GetCustomHeight, &InitialInstance::SetCustomHeight) - //.property("locked", &InitialInstance::IsLocked, &InitialInstance::SetLocked) - ; -} - -namespace gd { //Workaround for emscripten not supporting methods returning a reference (objects are returned by copy in JS). -gd::InitialInstance * InitialInstancesContainer_InsertInitialInstance(gd::InitialInstancesContainer & c, const InitialInstance & instance) { return &c.InsertInitialInstance(instance); } -gd::InitialInstance * InitialInstancesContainer_InsertNewInitialInstance(gd::InitialInstancesContainer & c) { return &c.InsertNewInitialInstance(); } - -struct InitialInstanceFunctorWrapper : public wrapper { - EMSCRIPTEN_WRAPPER(InitialInstanceFunctorWrapper); - void operator()(InitialInstance * instance) { - return call("invoke", instance); - } -}; - -} - -EMSCRIPTEN_BINDINGS(gd_InitialInstancesContainer) { - class_("InitialInstanceFunctor") - .function("invoke", &InitialInstanceFunctor::operator(), allow_raw_pointers()) - .allow_subclass("InitialInstanceFunctorWrapper") - ; - - class_ >("HighestZOrderFinder") - .constructor<>() - .function("invoke", &HighestZOrderFinder::operator(), allow_raw_pointers()) - .function("getHighestZOrder", &HighestZOrderFinder::GetHighestZOrder) - .function("getLowestZOrder", &HighestZOrderFinder::GetLowestZOrder) - .function("restrictSearchToLayer", &HighestZOrderFinder::RestrictSearchToLayer) - ; - - class_("InitialInstancesContainer") - .constructor<>() - .function("create", &InitialInstancesContainer::Create) - .function("getInstancesCount", &InitialInstancesContainer::GetInstancesCount) - .function("iterateOverInstances", &InitialInstancesContainer::IterateOverInstances) - .function("iterateOverInstancesWithZOrdering", &InitialInstancesContainer::IterateOverInstancesWithZOrdering) - .function("insertInitialInstance", &InitialInstancesContainer_InsertInitialInstance, allow_raw_pointers()) - .function("insertNewInitialInstance", &InitialInstancesContainer_InsertNewInitialInstance, allow_raw_pointers()) - .function("removeInstance", &InitialInstancesContainer::RemoveInstance) - .function("removeAllInstancesOnLayer", &InitialInstancesContainer::RemoveAllInstancesOnLayer) - .function("moveInstancesToLayer", &InitialInstancesContainer::MoveInstancesToLayer) - .function("removeInitialInstancesOfObject", &InitialInstancesContainer::RemoveInitialInstancesOfObject) - .function("renameInstancesOfObject", &InitialInstancesContainer::RenameInstancesOfObject) - .function("someInstancesAreOnLayer", &InitialInstancesContainer::SomeInstancesAreOnLayer) - ; -} - -namespace gd { //Workaround for emscripten not supporting methods returning a reference (objects are returned by copy in JS). -PropertyDescriptor * PropertyDescriptor_SetValue(PropertyDescriptor &p, const std::string & v) { return &p.SetValue(v); } -PropertyDescriptor * PropertyDescriptor_SetType(PropertyDescriptor &p, const std::string & v) { return &p.SetType(v); } -PropertyDescriptor * PropertyDescriptor_AddExtraInfo(PropertyDescriptor &p, const std::string & v) { return &p.AddExtraInfo(v); } -} - -EMSCRIPTEN_BINDINGS(gd_PropertyDescriptor) { - class_("PropertyDescriptor") - .constructor() - .function("setValue", &PropertyDescriptor_SetValue, allow_raw_pointers()) - .function("getValue", &PropertyDescriptor::GetValue) - .function("setType", &PropertyDescriptor_SetType, allow_raw_pointers()) - .function("getType", &PropertyDescriptor::GetType) - .function("addExtraInfo", &PropertyDescriptor_AddExtraInfo, allow_raw_pointers()) - .function("getExtraInfo", &PropertyDescriptor::GetExtraInfo) - ; -} - -EMSCRIPTEN_BINDINGS(gd_Serializer) { - class_("SerializerElement") - .constructor<>() - ; - - class_("Serializer") - .class_function("toJSON", &Serializer::ToJSON) - .class_function("fromJSON", &Serializer::FromJSON) - ; -} - -EMSCRIPTEN_BINDINGS(gd_ObjectListDialogsHelper) { - class_("ObjectListDialogsHelper") - .constructor() - .function("setSearchText", &ObjectListDialogsHelper::SetSearchText) - .function("setAllowedObjectType", &ObjectListDialogsHelper::SetAllowedObjectType) - .function("setGroupsAllowed", &ObjectListDialogsHelper::SetGroupsAllowed) - .function("getMatchingObjects", &ObjectListDialogsHelper::GetMatchingObjects) - ; -} - -#endif diff --git a/WebIDE/Bindings/GDCore/Embind2.cpp b/WebIDE/Bindings/GDCore/Embind2.cpp deleted file mode 100644 index 5b2ec69..0000000 --- a/WebIDE/Bindings/GDCore/Embind2.cpp +++ /dev/null @@ -1,507 +0,0 @@ -/* - * GDevelop Core - * Copyright 2008-2014 Florian Rival (Florian.Rival@gmail.com). All rights reserved. - * This project is released under the MIT License. - */ - -/* - * The rest of the API exposed using embind. - * See Embind.cpp for more information - */ -#if defined(EMSCRIPTEN) -#include -#include -#include -#include "GDCore/PlatformDefinition/Platform.h" -#include "GDCore/PlatformDefinition/Layout.h" -#include "GDCore/PlatformDefinition/Project.h" -#include "GDCore/PlatformDefinition/PlatformExtension.h" -#include "GDCore/IDE/ArbitraryResourceWorker.h" -#include "GDCore/IDE/AbstractFileSystem.h" -#include "GDCore/IDE/ProjectResourcesAdder.h" -#include "GDCore/IDE/EventsRefactorer.h" -#include "GDCore/IDE/ArbitraryEventsWorker.h" -#include "GDCore/IDE/EventsParametersLister.h" -#include "GDCore/IDE/MetadataProvider.h" -#include "GDCore/IDE/InstructionSentenceFormatter.h" -#include "GDCore/Events/Instruction.h" -#include "GDCore/Events/Event.h" -#include "GDCore/Events/Builtin/StandardEvent.h" -#include "GDCore/Events/Builtin/CommentEvent.h" -#include "GDCore/Events/Builtin/ForEachEvent.h" -#include "GDCore/Events/Builtin/WhileEvent.h" -#include "GDCore/Events/Builtin/GroupEvent.h" -#include "GDCore/Events/Builtin/RepeatEvent.h" -#include "GDCore/Events/EventsCodeGenerator.h" -#include "GDCore/Events/InstructionMetadata.h" -#include "GDCore/Events/ExpressionMetadata.h" -#include "GDCore/Events/ObjectMetadata.h" -#include "GDCore/Events/AutomatismMetadata.h" -#include "GDCore/Events/EventsList.h" -#include "GDCore/Serialization/Serializer.h" - -using namespace emscripten; -using namespace gd; - -namespace gd { //Workaround for emscripten to directly use gd::PlatformExtension instead of shared pointers. -PlatformExtension * VectorPlatformExtension_Get(std::vector > & v, unsigned int i) { return v[i].get(); }; -unsigned int VectorPlatformExtension_Size(const std::vector > & v) { return v.size(); }; - -ObjectMetadata * PlatformExtension_GetObjectMetadata(PlatformExtension & e, const std::string & objectType) { return &e.GetObjectMetadata(objectType); }; -AutomatismMetadata * PlatformExtension_GetAutomatismMetadata(PlatformExtension & e, const std::string & autoType) { return &e.GetAutomatismMetadata(autoType); }; -std::map * PlatformExtension_GetAllEvents(PlatformExtension & e) { return &e.GetAllEvents();}; -std::map * PlatformExtension_GetAllActions(PlatformExtension & e) { return &e.GetAllActions();}; -std::map * PlatformExtension_GetAllConditions(PlatformExtension & e) { return &e.GetAllConditions();}; -std::map * PlatformExtension_GetAllExpressions(PlatformExtension & e) { return &e.GetAllExpressions();}; -std::map * PlatformExtension_GetAllStrExpressions(PlatformExtension & e) { return &e.GetAllStrExpressions();}; -std::map * PlatformExtension_GetAllActionsForObject(PlatformExtension & e, std::string objectType) { return &e.GetAllActionsForObject(objectType);}; -std::map * PlatformExtension_GetAllConditionsForObject(PlatformExtension & e, std::string objectType) { return &e.GetAllConditionsForObject(objectType);}; -std::map * PlatformExtension_GetAllExpressionsForObject(PlatformExtension & e, std::string objectType) { return &e.GetAllExpressionsForObject(objectType);}; -std::map * PlatformExtension_GetAllStrExpressionsForObject(PlatformExtension & e, std::string objectType) { return &e.GetAllStrExpressionsForObject(objectType);}; -std::map * PlatformExtension_GetAllActionsForAutomatism(PlatformExtension & e, std::string autoType) { return &e.GetAllActionsForAutomatism(autoType);}; -std::map * PlatformExtension_GetAllConditionsForAutomatism(PlatformExtension & e, std::string autoType) { return &e.GetAllConditionsForAutomatism(autoType);}; -std::map * PlatformExtension_GetAllExpressionsForAutomatism(PlatformExtension & e, std::string autoType) { return &e.GetAllExpressionsForAutomatism(autoType);}; -std::map * PlatformExtension_GetAllStrExpressionsForAutomatism(PlatformExtension & e, std::string autoType) { return &e.GetAllStrExpressionsForAutomatism(autoType);}; -} - -EMSCRIPTEN_BINDINGS(gd_PlatformExtension) { - class_ > >("VectorPlatformExtension") - .function("size", &VectorPlatformExtension_Size) - .function("get", &VectorPlatformExtension_Get, allow_raw_pointers()) - ; - - class_("PlatformExtension") - //Information about the extension: - .function("getFullName", &PlatformExtension::GetFullName) - .function("getName", &PlatformExtension::GetName) - .function("getDescription", &PlatformExtension::GetDescription) - .function("getAuthor", &PlatformExtension::GetAuthor) - .function("getLicense", &PlatformExtension::GetLicense) - .function("isBuiltin", &PlatformExtension::IsBuiltin) - .function("getNameSpace", &PlatformExtension::GetNameSpace) - //Accessing what's inside the extension: - .function("getExtensionObjectsTypes", &PlatformExtension::GetExtensionObjectsTypes) - .function("getAutomatismsTypes", &PlatformExtension::GetAutomatismsTypes) - .function("getObjectMetadata", &PlatformExtension_GetObjectMetadata, allow_raw_pointers()) - .function("getAutomatismMetadata", &PlatformExtension_GetAutomatismMetadata, allow_raw_pointers()) - //Actions, conditions and events: - .function("getAllEvents", &PlatformExtension_GetAllEvents, allow_raw_pointers()) - .function("getAllActions", &PlatformExtension_GetAllActions, allow_raw_pointers()) - .function("getAllConditions", &PlatformExtension_GetAllConditions, allow_raw_pointers()) - .function("getAllExpressions", &PlatformExtension_GetAllExpressions, allow_raw_pointers()) - .function("getAllStrExpressions", &PlatformExtension_GetAllStrExpressions, allow_raw_pointers()) - .function("getAllActionsForObject", &PlatformExtension_GetAllActionsForObject, allow_raw_pointers()) - .function("getAllConditionsForObject", &PlatformExtension_GetAllConditionsForObject, allow_raw_pointers()) - .function("getAllExpressionsForObject", &PlatformExtension_GetAllExpressionsForObject, allow_raw_pointers()) - .function("getAllStrExpressionsForObject", &PlatformExtension_GetAllStrExpressionsForObject, allow_raw_pointers()) - .function("getAllActionsForAutomatism", &PlatformExtension_GetAllActionsForAutomatism, allow_raw_pointers()) - .function("getAllConditionsForAutomatism", &PlatformExtension_GetAllConditionsForAutomatism, allow_raw_pointers()) - .function("getAllExpressionsForAutomatism", &PlatformExtension_GetAllExpressionsForAutomatism, allow_raw_pointers()) - .function("getAllStrExpressionsForAutomatism", &PlatformExtension_GetAllStrExpressionsForObject, allow_raw_pointers()) - ; -} - -namespace gd { //Workaround for emscripten to directly use strings instead of gd::Expression. -gd::Instruction Instruction_Clone(gd::Instruction & i) { gd::Instruction n = i; return n; }; -void Instruction_SetParameter(gd::Instruction & i, unsigned int nb, const std::string & val) { i.SetParameter(nb, val); }; -const std::string & Instruction_GetParameter(gd::Instruction & i, unsigned int nb) { return i.GetParameter(nb).GetPlainString(); }; -std::vector < Instruction > * Instruction_GetSubInstructions(gd::Instruction & i) { return &i.GetSubInstructions(); }; -void VectorInstruction_Remove(std::vector < Instruction > & v, unsigned int i) { v.erase(v.begin()+i); }; -} - -EMSCRIPTEN_BINDINGS(gd_Instruction) { - register_vector< Instruction >("VectorInstruction") - //"set, get, size, push_back" are already registered by register_vector - .function("remove", &VectorInstruction_Remove); - - class_("Instruction") - .constructor<>() - .function("clone", &Instruction_Clone) - .function("getType", &Instruction::GetType).function("setType", &Instruction::SetType) - .function("isInverted", &Instruction::IsInverted).function("setInverted", &Instruction::SetInverted) - .function("getParameter", &Instruction_GetParameter).function("setParameter", &Instruction_SetParameter) - .function("getParametersCount", &Instruction::GetParametersCount).function("setParametersCount", &Instruction::SetParametersCount) - .function("getSubInstructions", &Instruction_GetSubInstructions, allow_raw_pointers()) - //Properties, for convenience only: - .property("parametersCount", &Instruction::GetParametersCount, &Instruction::SetParametersCount) - ; -} - -namespace gd { //Workaround for emscripten not supporting methods returning a reference (objects are returned by copy in JS). -gd::EventsList * BaseEvent_GetSubEvents(BaseEvent & e) { return &e.GetSubEvents(); } -bool BaseEvent_IsFolded(BaseEvent & e) { return e.folded; } -void BaseEvent_SetFolded(BaseEvent & e, bool fold) { e.folded = fold; } -std::vector < gd::Instruction > * StandardEvent_GetConditions(StandardEvent & e) { return &e.GetConditions(); } -std::vector < gd::Instruction > * StandardEvent_GetActions(StandardEvent & e) { return &e.GetActions(); } -std::vector < gd::Instruction > * WhileEvent_GetConditions(WhileEvent & e) { return &e.GetConditions(); } -std::vector < gd::Instruction > * WhileEvent_GetActions(WhileEvent & e) { return &e.GetActions(); } -std::vector < gd::Instruction > * WhileEvent_GetWhileConditions(WhileEvent & e) { return &e.GetWhileConditions(); } -std::vector < gd::Instruction > * ForEachEvent_GetConditions(ForEachEvent & e) { return &e.GetConditions(); } -std::vector < gd::Instruction > * ForEachEvent_GetActions(ForEachEvent & e) { return &e.GetActions(); } -std::vector < gd::Instruction > * RepeatEvent_GetConditions(RepeatEvent & e) { return &e.GetConditions(); } -std::vector < gd::Instruction > * RepeatEvent_GetActions(RepeatEvent & e) { return &e.GetActions(); } -std::vector < std::string > * GroupEvent_GetCreationParameters(GroupEvent & e) { return &e.GetCreationParameters(); } -const std::string & CommentEvent_GetComment(CommentEvent & e) { return e.com1; } -void CommentEvent_SetComment(CommentEvent & e, const std::string & com) { e.com1 = com; } -gd::StandardEvent * AsStandardEvent(gd::BaseEvent * e) { return static_cast(e);} -gd::CommentEvent * AsCommentEvent(gd::BaseEvent * e) { return static_cast(e);} -gd::WhileEvent * AsWhileEvent(gd::BaseEvent * e) { return static_cast(e);} -gd::ForEachEvent * AsForEachEvent(gd::BaseEvent * e) { return static_cast(e);} -gd::RepeatEvent * AsRepeatEvent(gd::BaseEvent * e) { return static_cast(e);} -} - -EMSCRIPTEN_BINDINGS(gd_BaseEvent) { - class_("BaseEvent") - .constructor<>() - .smart_ptr< boost::shared_ptr >("BaseEventSPtr") - .function("clone", &BaseEvent::Clone, allow_raw_pointers()) - .function("getType", &BaseEvent::GetType).function("setType", &BaseEvent::SetType) - .function("isExecutable", &BaseEvent::IsExecutable) - .function("canHaveSubEvents", &BaseEvent::CanHaveSubEvents) - .function("hasSubEvents", &BaseEvent::HasSubEvents) - .function("getSubEvents", &BaseEvent_GetSubEvents, allow_raw_pointers()) - .function("isDisabled", &BaseEvent::IsDisabled) - .function("setDisabled", &BaseEvent::SetDisabled) - .function("isFolded", &BaseEvent_IsFolded) - .function("setFolded", &BaseEvent_SetFolded) - ; - - class_ >("StandardEvent") - .constructor<>() - .function("getConditions", &StandardEvent_GetConditions, allow_raw_pointers()) - .function("getActions", &StandardEvent_GetActions, allow_raw_pointers()) - ; - - class_ >("CommentEvent") - .constructor<>() - .function("getComment", &CommentEvent_GetComment) - .function("setComment", &CommentEvent_SetComment) - ; - - class_ >("GroupEvent") - .constructor<>() - .function("getName", &GroupEvent::GetName) - .function("setName", &GroupEvent::SetName) - .function("setBackgroundColor", &GroupEvent::SetBackgroundColor) - .function("getBackgroundColorR", &GroupEvent::GetBackgroundColorR) - .function("getBackgroundColorG", &GroupEvent::GetBackgroundColorG) - .function("getBackgroundColorB", &GroupEvent::GetBackgroundColorB) - .function("getSource", &GroupEvent::GetSource) - .function("setSource", &GroupEvent::SetSource) - .function("getCreationParameters", &GroupEvent_GetCreationParameters, allow_raw_pointers()) - .function("getCreationTimestamp", &GroupEvent::GetCreationTimestamp) - .function("setCreationTimestamp", &GroupEvent::SetCreationTimestamp) - ; - - class_ >("WhileEvent") - .constructor<>() - .function("getConditions", &WhileEvent_GetConditions, allow_raw_pointers()) - .function("getActions", &WhileEvent_GetActions, allow_raw_pointers()) - .function("getWhileConditions", &WhileEvent_GetWhileConditions, allow_raw_pointers()) - ; - - class_ >("ForEachEvent") - .constructor<>() - .function("getConditions", &ForEachEvent_GetConditions, allow_raw_pointers()) - .function("getActions", &ForEachEvent_GetActions, allow_raw_pointers()) - .function("getObjectsToPick", &ForEachEvent::GetObjectToPick) - .function("setObjectsToPick", &ForEachEvent::SetObjectToPick) - ; - - class_ >("RepeatEvent") - .constructor<>() - .function("getConditions", &RepeatEvent_GetConditions, allow_raw_pointers()) - .function("getActions", &RepeatEvent_GetActions, allow_raw_pointers()) - .function("getRepeatExpression", &RepeatEvent::GetRepeatExpression) - .function("setRepeatExpression", &RepeatEvent::SetRepeatExpression) - ; - - function("asStandardEvent", &AsStandardEvent, allow_raw_pointers()); - function("asCommentEvent", &AsCommentEvent, allow_raw_pointers()); - function("asForEachEvent", &AsForEachEvent, allow_raw_pointers()); - function("asWhileEvent", &AsWhileEvent, allow_raw_pointers()); - function("asRepeatEvent", &AsRepeatEvent, allow_raw_pointers()); -} - -namespace gd { //Workaround for emscripten not supporting methods returning a reference (objects are returned by copy in JS). -gd::BaseEvent * EventsList_GetEventAt(EventsList & l, size_t i) { return &l.GetEvent(i); } -gd::BaseEvent * EventsList_InsertEvent(EventsList & l, gd::BaseEvent & e, size_t pos) { return &l.InsertEvent(e, pos); } -gd::BaseEvent * EventsList_InsertNewEvent(EventsList & l, gd::Project & p, const std::string & t, size_t pos) { return &l.InsertNewEvent(p, t, pos); } -} - -EMSCRIPTEN_BINDINGS(gd_EventsList) { - class_("EventsList") - .constructor<>() - .function("insertEvent", &EventsList_InsertEvent, allow_raw_pointers()) - .function("insertNewEvent", &EventsList_InsertNewEvent, allow_raw_pointers()) - .function("insertEvents", &EventsList::InsertEvents) - .function("getEventAt", &EventsList_GetEventAt, allow_raw_pointers()) - .function("removeEventAt", select_overload(&EventsList::RemoveEvent)) - .function("removeEvent", select_overload(&EventsList::RemoveEvent)) - .function("getEventsCount", &EventsList::GetEventsCount) - .function("contains", &EventsList::Contains) - .function("isEmpty", &EventsList::IsEmpty) - .function("clear", &EventsList::Clear) - .function("serializeTo", &EventsList::SerializeTo) - .function("unserializeFrom", &EventsList::UnserializeFrom) - ; -} - -namespace gd { -gd::ParameterMetadata * InstructionMetadata_GetParameter(InstructionMetadata & im, unsigned int i) { return &im.parameters[i]; } -} - -EMSCRIPTEN_BINDINGS(gd_InstructionMetadata) { - class_("InstructionMetadata") - .function("getFullName", &InstructionMetadata::GetFullName) - .function("getDescription", &InstructionMetadata::GetDescription) - .function("getSentence", &InstructionMetadata::GetSentence) - .function("getGroup", &InstructionMetadata::GetGroup) - .function("getIconFilename", &InstructionMetadata::GetIconFilename) - .function("getSmallIconFilename", &InstructionMetadata::GetSmallIconFilename) - .function("canHaveSubInstructions", &InstructionMetadata::CanHaveSubInstructions) - .function("setCanHaveSubInstructions", &InstructionMetadata::SetCanHaveSubInstructions) - .function("getParameter", &InstructionMetadata_GetParameter, allow_raw_pointers()) - .function("getParametersCount", &InstructionMetadata::GetParametersCount) - .function("getUsageComplexity", &InstructionMetadata::GetUsageComplexity) - .function("isHidden", &InstructionMetadata::IsHidden) - ; -} - -namespace gd { -gd::ParameterMetadata * ExpressionMetadata_GetParameter(ExpressionMetadata & em, unsigned int i) { return &em.parameters[i]; } -size_t ExpressionMetadata_GetParametersCount(const ExpressionMetadata & em) { return em.parameters.size(); } -} - -EMSCRIPTEN_BINDINGS(gd_ExpressionMetadata) { - class_("ExpressionMetadata") - .function("getFullName", &ExpressionMetadata::GetFullName) - .function("getDescription", &ExpressionMetadata::GetDescription) - .function("getGroup", &ExpressionMetadata::GetGroup) - .function("getSmallIconFilename", &ExpressionMetadata::GetSmallIconFilename) - .function("isShown", &ExpressionMetadata::IsShown) - .function("getParameter", &ExpressionMetadata_GetParameter, allow_raw_pointers()) - .function("getParametersCount", &ExpressionMetadata_GetParametersCount) - ; -} - -EMSCRIPTEN_BINDINGS(gd_ParameterMetadata) { - class_("ParameterMetadata") - .function("getType", &ParameterMetadata::GetType) - .function("getExtraInfo", &ParameterMetadata::GetExtraInfo) - .function("isOptional", &ParameterMetadata::IsOptional) - .function("getDescription", &ParameterMetadata::GetDescription) - .function("isCodeOnly", &ParameterMetadata::IsCodeOnly) - .function("getDefaultValue", &ParameterMetadata::GetDefaultValue) - .class_function("isObject", &ParameterMetadata::IsObject) - ; -} - -EMSCRIPTEN_BINDINGS(gd_ObjectMetadata) { - class_("ObjectMetadata") - .function("getName", &ObjectMetadata::GetName) - .function("getFullName", &ObjectMetadata::GetFullName) - .function("getDescription", &ObjectMetadata::GetDescription) - .function("getIconFilename", &ObjectMetadata::GetIconFilename) - ; -} - -EMSCRIPTEN_BINDINGS(gd_AutomatismMetadata) { - class_("AutomatismMetadata") - .function("getFullName", &AutomatismMetadata::GetFullName) - .function("getDefaultName", &AutomatismMetadata::GetDefaultName) - .function("getDescription", &AutomatismMetadata::GetDescription) - .function("getGroup", &AutomatismMetadata::GetGroup) - .function("getIconFilename", &AutomatismMetadata::GetIconFilename) - ; -} - -EMSCRIPTEN_BINDINGS(gd_MetadataProvider) { - class_("MetadataProvider") - .class_function("getAutomatismMetadata", MetadataProvider::GetAutomatismMetadata) - .class_function("getObjectMetadata", MetadataProvider::GetObjectMetadata) - .class_function("getActionMetadata", MetadataProvider::GetActionMetadata) - .class_function("getConditionMetadata", MetadataProvider::GetConditionMetadata) - .class_function("getExpressionMetadata", MetadataProvider::GetExpressionMetadata) - .class_function("getObjectExpressionMetadata", MetadataProvider::GetObjectExpressionMetadata) - .class_function("getAutomatismExpressionMetadata", MetadataProvider::GetAutomatismExpressionMetadata) - .class_function("getStrExpressionMetadata", MetadataProvider::GetStrExpressionMetadata) - .class_function("getObjectStrExpressionMetadata", MetadataProvider::GetObjectStrExpressionMetadata) - .class_function("getAutomatismStrExpressionMetadata", MetadataProvider::GetAutomatismStrExpressionMetadata) - .class_function("hasCondition", MetadataProvider::HasCondition) - .class_function("hasAction", MetadataProvider::HasAction) - .class_function("hasObjectAction", MetadataProvider::HasObjectAction) - .class_function("hasObjectCondition", MetadataProvider::HasObjectCondition) - .class_function("hasAutomatismAction", MetadataProvider::HasAutomatismAction) - .class_function("hasAutomatismCondition", MetadataProvider::HasAutomatismCondition) - .class_function("hasExpression", MetadataProvider::HasExpression) - .class_function("hasObjectExpression", MetadataProvider::HasObjectExpression) - .class_function("hasAutomatismExpression", MetadataProvider::HasAutomatismExpression) - .class_function("hasStrExpression", MetadataProvider::HasStrExpression) - .class_function("hasObjectStrExpression", MetadataProvider::HasObjectStrExpression) - .class_function("hasAutomatismStrExpression", MetadataProvider::HasAutomatismStrExpression) - ; -} - -EMSCRIPTEN_BINDINGS(gd_InstructionSentenceFormatter) { - class_("InstructionSentenceFormatter") - .class_function("get", &InstructionSentenceFormatter::Get, allow_raw_pointers()) - .function("translate", &InstructionSentenceFormatter::Translate) - .function("getAsFormattedText", &InstructionSentenceFormatter::GetAsFormattedText) - .function("getFormattingFromType", &InstructionSentenceFormatter::GetFormattingFromType) - .function("labelFromType", &InstructionSentenceFormatter::LabelFromType) - .function("loadTypesFormattingFromConfig", &InstructionSentenceFormatter::LoadTypesFormattingFromConfig) - ; -} - -namespace gd { -unsigned int VectorPairStringTextFormatting_Size(std::vector< std::pair > & v) { return v.size(); } -const std::string & VectorPairStringTextFormatting_GetString(std::vector< std::pair > & v, unsigned int i) { return v[i].first; } -gd::TextFormatting * VectorPairStringTextFormatting_GetTextFormatting(std::vector< std::pair > & v, unsigned int i) { return &v[i].second; } -} - -EMSCRIPTEN_BINDINGS(gd_TextFormatting) { - class_("TextFormatting") - .constructor<>() - .function("isBold", &TextFormatting::IsBold) - .function("isItalic", &TextFormatting::IsItalic) - .function("getColorRed", &TextFormatting::GetColorRed) - .function("getColorGreen", &TextFormatting::GetColorGreen) - .function("getColorBlue", &TextFormatting::GetColorBlue) - ; - - class_< std::vector< std::pair > >("VectorPairStringTextFormatting") - .function("size", &VectorPairStringTextFormatting_Size, allow_raw_pointers()) - .function("getString", &VectorPairStringTextFormatting_GetString, allow_raw_pointers()) - .function("getTextFormatting", &VectorPairStringTextFormatting_GetTextFormatting, allow_raw_pointers()) - ; -} - -EMSCRIPTEN_BINDINGS(gd_EventsRefactorer) { - class_("EventsRefactorer") - .class_function("renameObjectInEvents", &EventsRefactorer::RenameObjectInEvents) - .class_function("removeObjectInEvents", &EventsRefactorer::RemoveObjectInEvents) - .class_function("replaceStringInEvents", &EventsRefactorer::ReplaceStringInEvents) - //TODO: SearchInEvents method. - ; -} - -EMSCRIPTEN_BINDINGS(gd_EventsCodeGenerator) { - class_("EventsCodeGenerator") - ; -} - -struct AbstractFileSystemWrapper : public wrapper { - EMSCRIPTEN_WRAPPER(AbstractFileSystemWrapper); - virtual void MkDir(const std::string & path) { - return call("mkDir", path); - } - virtual bool DirExists(const std::string & path) { - return call("dirExists", path); - } - virtual bool ClearDir(const std::string & path) { - return call("clearDir", path); - } - virtual std::string GetTempDir() { - return call("getTempDir"); - } - virtual std::string FileNameFrom(const std::string & file) { - return call("fileNameFrom", file); - } - virtual std::string DirNameFrom(const std::string & file) { - return call("dirNameFrom", file); - } - virtual bool MakeAbsolute(std::string & filename, const std::string & baseDirectory) { - filename = call("getAbsolute", filename, baseDirectory); - return true; - } - virtual bool MakeRelative(std::string & filename, const std::string & baseDirectory) { - filename = call("getRelative", filename, baseDirectory); - return true; - } - virtual bool IsAbsolute(const std::string & file) { - return call("isAbsolute", file); - } - virtual bool CopyFile(const std::string & file, const std::string & destination) { - return call("copyFile", file, destination); - } - virtual bool WriteToFile(const std::string & file, const std::string & content) { - return call("writeToFile", file, content); - } - virtual std::string ReadFile(const std::string & file) { - return call("readFile", file); - } - virtual std::vector ReadDir(const std::string & path, const std::string & ext) { - return call< std::vector >("readDir", path, ext); - } - virtual bool FileExists(const std::string & file) { - return call("fileExists", file); - } -}; - -namespace gd { -bool AbstractFileSystem_MakeAbsolute(AbstractFileSystem & fs, std::string * filename, - const std::string & baseDirectory) { return fs.MakeAbsolute(*filename, baseDirectory); } -bool AbstractFileSystem_MakeRelative(AbstractFileSystem & fs, std::string * filename, - const std::string & baseDirectory) { return fs.MakeRelative(*filename, baseDirectory); } -} - -EMSCRIPTEN_BINDINGS(gd_AbstractFileSystem) { - class_("AbstractFileSystem") - .function("mkDir", &AbstractFileSystem::MkDir) - .function("dirExists", &AbstractFileSystem::DirExists) - .function("clearDir", &AbstractFileSystem::ClearDir) - .function("getTempDir", &AbstractFileSystem::GetTempDir) - .function("fileNameFrom", &AbstractFileSystem::FileNameFrom) - .function("dirNameFrom", &AbstractFileSystem::DirNameFrom) - .function("makeAbsolute", &AbstractFileSystem_MakeAbsolute, allow_raw_pointers()) - .function("makeRelative", &AbstractFileSystem_MakeRelative, allow_raw_pointers()) - .function("isAbsolute", &AbstractFileSystem::IsAbsolute) - .function("copyFile", &AbstractFileSystem::CopyFile) - .function("writeToFile", &AbstractFileSystem::WriteToFile) - .function("readFile", &AbstractFileSystem::ReadFile) - .function("ReadDir", &AbstractFileSystem::ReadFile) - .function("fileExists", &AbstractFileSystem::FileExists) - .allow_subclass("AbstractFileSystemWrapper") - ; -} - -EMSCRIPTEN_BINDINGS(gd_ProjectResourcesAdder) { - class_("ProjectResourcesAdder") - .class_function("addAllMissingImages", &ProjectResourcesAdder::AddAllMissingImages) - .class_function("getAllUselessResources", &ProjectResourcesAdder::GetAllUselessResources) - .class_function("removeAllUselessResources", &ProjectResourcesAdder::RemoveAllUselessResources) - ; -} - -EMSCRIPTEN_BINDINGS(gd_ArbitraryEventsWorker) { - class_("ArbitraryEventsWorker") - .function("launch", &ArbitraryEventsWorker::Launch) - ; -} -EMSCRIPTEN_BINDINGS(gd_EventsParametersLister) { - class_ >("EventsParametersLister") - .constructor() - .function("getParametersAndTypes", &EventsParametersLister::GetParametersAndTypes) - ; -} - -struct ArbitraryResourceWorkerWrapper : public wrapper { - EMSCRIPTEN_WRAPPER(ArbitraryResourceWorkerWrapper); - virtual void ExposeImage(std::string & imageName) { - imageName = call("exposeImage", imageName); - } - virtual void ExposeShader(std::string & shaderName) { - shaderName = call("exposeShader", shaderName); - } - virtual void ExposeFile(std::string & resourceFileName) { - resourceFileName = call("exposeFile", resourceFileName); - } -}; - -EMSCRIPTEN_BINDINGS(gd_ArbitraryResourceWorker) { - class_("ArbitraryResourceWorker") - .allow_subclass("ArbitraryResourceWorkerWrapper") - ; -} -#endif diff --git a/WebIDE/Bindings/GDCore/Embind3.cpp b/WebIDE/Bindings/GDCore/Embind3.cpp deleted file mode 100644 index a298a89..0000000 --- a/WebIDE/Bindings/GDCore/Embind3.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/* - * GDevelop Core - * Copyright 2008-2014 Florian Rival (Florian.Rival@gmail.com). All rights reserved. - * This project is released under the MIT License. - */ - -/* - * When cross-compiling using emscripten, this file exposes the GDCore API - * to javascript. - * - * The javascript API of GDCore is the same as the C++ one except that: - * - functions begins lowercase ("getLayout"), - * - not all methods or classes are available. - */ -#if defined(EMSCRIPTEN) -#include "Embind.h" -#include -#include "GDCore/IDE/Dialogs/PropertyDescriptor.h" -#include "GDCore/PlatformDefinition/Layout.h" -#include "GDCore/PlatformDefinition/Project.h" -#include "GDCore/PlatformDefinition/Platform.h" -#include "GDCore/PlatformDefinition/VariablesContainer.h" -#include "GDCore/PlatformDefinition/Object.h" -#include "GDCore/PlatformDefinition/Automatism.h" -#include "GDCore/BuiltinExtensions/SpriteExtension/SpriteObject.h" -#include - -using namespace emscripten; -using namespace gd; - -namespace gd { -SpriteObject * AsSpriteObject(gd::Object * object) { return static_cast(object); } -gd::Animation * SpriteObject_GetAnimation(gd::SpriteObject & o, unsigned int i) { return &o.GetAnimation(i); } -gd::Direction * Animation_GetDirection(gd::Animation & a, unsigned int i) { return &a.GetDirection(i); } -gd::Sprite * Direction_GetSprite(gd::Direction & d, unsigned int i) { return &d.GetSprite(i); } -Point * Sprite_GetPoint(gd::Sprite & s, const std::string & name) { return &s.GetPoint(name); } -Point * Sprite_GetOrigin(gd::Sprite & s) { return &s.GetOrigin(); } -Point * Sprite_GetCenter(gd::Sprite & s) { return &s.GetCenter(); } -} - -EMSCRIPTEN_BINDINGS(gd_SpriteObject) { - class_("Point") - .constructor() - .function("setName", &Point::SetName) - .function("getName", &Point::GetName) - .function("setXY", &Point::SetXY) - .function("getX", &Point::GetX) - .function("setX", &Point::SetX) - .function("getY", &Point::GetY) - .function("setY", &Point::SetY) - ; - - class_("Sprite") - .constructor<>() - .function("setImageName", &Sprite::SetImageName) - .function("getImageName", select_overload(&Sprite::GetImageName)) - .function("addPoint", &Sprite::AddPoint) - .function("delPoint", &Sprite::DelPoint) - .function("getPoint", &Sprite_GetPoint, allow_raw_pointers()) - .function("hasPoint", &Sprite::HasPoint) - .function("getOrigin", &Sprite_GetOrigin, allow_raw_pointers()) - .function("getCenter", &Sprite_GetCenter, allow_raw_pointers()) - .function("isDefaultCenterPoint", &Sprite::IsDefaultCenterPoint) - .function("setDefaultCenterPoint", &Sprite::SetDefaultCenterPoint) - ; - - class_("Direction") - .constructor<>() - .function("addSprite", &Direction::AddSprite) - .function("getSprite", &Direction_GetSprite, allow_raw_pointers()) - .function("getSpritesCount", &Direction::GetSpritesCount) - .function("hasNoSprites", &Direction::HasNoSprites) - .function("removeSprite", &Direction::RemoveSprite) - .function("removeAllSprites", &Direction::RemoveAllSprites) - .function("isLooping", &Direction::IsLooping) - .function("setLoop", &Direction::SetLoop) - .function("getTimeBetweenFrames", &Direction::GetTimeBetweenFrames) - .function("setTimeBetweenFrames", &Direction::SetTimeBetweenFrames) - .function("swapSprites", &Direction::SwapSprites) - ; - - class_("Animation") - .constructor<>() - .function("setDirectionsCount", &Animation::SetDirectionsCount) - .function("getDirectionsCount", &Animation::GetDirectionsCount) - .function("getDirection", &Animation_GetDirection, allow_raw_pointers()) - .function("setDirection", &Animation::SetDirection) - .function("hasNoDirections", &Animation::HasNoDirections) - ; - - class_ >("SpriteObject") - .constructor() - .function("addAnimation", &SpriteObject::AddAnimation) - .function("getAnimation", &SpriteObject_GetAnimation, allow_raw_pointers()) - .function("getAnimationsCount", &SpriteObject::GetAnimationsCount) - .function("removeAnimation", &SpriteObject::RemoveAnimation) - .function("removeAllAnimations", &SpriteObject::RemoveAllAnimations) - .function("hasNoAnimations", &SpriteObject::HasNoAnimations) - .function("swapAnimations", &SpriteObject::SwapAnimations) - ; - - function("asSpriteObject", &AsSpriteObject, allow_raw_pointers()); -} - -namespace gd { //Workaround for emscripten not supporting methods returning a reference (objects are returned by copy in JS). -float Vector2f_GetX(const sf::Vector2f & v) { return v.x; } -float Vector2f_GetY(const sf::Vector2f & v) { return v.y; } -void Vector2f_SetX(sf::Vector2f & v, float x) { v.x = x; } -void Vector2f_SetY(sf::Vector2f & v, float y) { v.y = y; } -} - -EMSCRIPTEN_BINDINGS(sf_Vector2f) { - class_("Vector2f") - .constructor<>() - .property("x", &Vector2f_GetX, &Vector2f_SetX) - .property("y", &Vector2f_GetY, &Vector2f_SetY) - ; -} -#endif diff --git a/WebIDE/Bindings/GDCore/Embind4.cpp b/WebIDE/Bindings/GDCore/Embind4.cpp deleted file mode 100644 index c8e250c..0000000 --- a/WebIDE/Bindings/GDCore/Embind4.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* - * GDevelop Core - * Copyright 2008-2014 Florian Rival (Florian.Rival@gmail.com). All rights reserved. - * This project is released under the MIT License. - */ -#if defined(EMSCRIPTEN) -#include "Embind.h" -#include -#include "GDCore/IDE/Dialogs/PropertyDescriptor.h" -#include "GDCore/PlatformDefinition/Layout.h" -#include "GDCore/PlatformDefinition/Project.h" -#include "GDCore/PlatformDefinition/Platform.h" -#include "GDCore/PlatformDefinition/VariablesContainer.h" -#include "GDCore/PlatformDefinition/Object.h" -#include "GDCore/PlatformDefinition/Automatism.h" -#include "GDCore/Serialization/Serializer.h" -#include "GDCore/Events/Event.h" -#include "GDCore/Events/EventsList.h" -#include "GDCore/Events/InstructionMetadata.h" -#include "GDCore/Events/ExpressionMetadata.h" -#include "GDCore/Events/EventMetadata.h" -#include "GDCore/Events/ObjectMetadata.h" -#include "GDCore/Events/AutomatismMetadata.h" -#include - -using namespace emscripten; -using namespace gd; - -namespace gd -{ -namespace internal { - template - struct SetAccess { - static val has( - const SetType& s, - typename SetType::value_type value - ) { - return val(s.find(value) != s.end()); - } - }; -} - -/** - * Utility function used to expose a std::set to Embind. - */ -template -class_ > register_set(const char* name) { - typedef std::set SetType; - - return class_ >(name) - .template constructor<>() - //.function("insert", &SetType::insert) - .function("size", &SetType::size) - .function("has", &internal::SetAccess::has) - ; -} - -namespace internal { - template - struct MapKeys { - static std::vector keys( - const MapType& m - ) { - std::vector allKeys; - for(typename MapType::const_iterator it = m.begin(); it != m.end(); ++it) - allKeys.push_back(it->first); - - return allKeys; - } - }; -} - -/** - * Utility function used to expose extra functions for std::map. - */ -template -class_ > register_map_extra(class_ > theMap) { - typedef std::map MapType; - - return theMap - .function("keys", &internal::MapKeys::keys) - ; -} - -/** - * Utility function used to expose extra functions for std::vector. - */ -template -class_ > register_vector_extra(class_ > theVector) { - typedef std::vector VecType; - - void (VecType::*clear)() = &VecType::clear; - return theVector - .function("clear", clear) - ; -} -} - -EMSCRIPTEN_BINDINGS(gd_std_wrappers) { - register_vector_extra(register_vector("VectorString")); - register_set("SetString"); - register_map_extra(register_map("MapStringString")); - register_map_extra(register_map("MapStringEventMetadata")); - register_map_extra(register_map("MapStringInstructionMetadata")); - register_map_extra(register_map("MapStringExpressionMetadata")); - register_map_extra(register_map("MapStringPropertyDescriptor")); - -} - -#endif diff --git a/WebIDE/Bindings/GDJS/Embind.cpp b/WebIDE/Bindings/GDJS/Embind.cpp deleted file mode 100644 index 9aa9b7c..0000000 --- a/WebIDE/Bindings/GDJS/Embind.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * GDevelop JS Platform - * Copyright 2008-2014 Florian Rival (Florian.Rival@gmail.com). All rights reserved. - * This project is released under the MIT License. - */ - -/* - * When cross-compiling using emscripten, this file exposes the GDJS API - * to javascript. - */ -#if defined(EMSCRIPTEN) -#include -#include "GDCore/IDE/AbstractFileSystem.h" -#include "GDCore/PlatformDefinition/Layout.h" -#include "GDCore/PlatformDefinition/Project.h" -#include "GDCore/PlatformDefinition/Platform.h" -#include "GDJS/EventsCodeGenerator.h" -#include "GDJS/Exporter.h" -#include "GDJS/JsPlatform.h" - -using namespace emscripten; -using namespace gdjs; - -namespace gdjs { -JsPlatform * AsJSPlatform(gd::Platform & platform) { return static_cast(&platform); } -gd::Platform * AsPlatform(JsPlatform & platform) { return static_cast(&platform); } -} - -EMSCRIPTEN_BINDINGS(gdjs_JsPlatform) { - - class_>("JsPlatform") - .constructor<>() - .class_function("get", &JsPlatform::Get) - ; - - function("asPlatform", &gdjs::AsPlatform, allow_raw_pointers()); - function("asJSPlatform", &gdjs::AsJSPlatform, allow_raw_pointers()); -} - -EMSCRIPTEN_BINDINGS(gdjs_EventsCodeGenerator) { - function("GenerateSceneEventsCompleteCode", &EventsCodeGenerator::GenerateSceneEventsCompleteCode); -} - -EMSCRIPTEN_BINDINGS(gdjs_Exporter) { - class_("Exporter") - .constructor() - .function("exportLayoutForPreview", &Exporter::ExportLayoutForPreview) - .function("exportWholeProject", &Exporter::ExportWholeProject) - ; -} -#endif diff --git a/WebIDE/main.cpp b/WebIDE/main.cpp index 239e0b2..217eba4 100644 --- a/WebIDE/main.cpp +++ b/WebIDE/main.cpp @@ -31,7 +31,7 @@ namespace gd { initialized = true; std::cout << "Initializing GDJS platform" << std::endl; { - boost::shared_ptr platform(&JsPlatform::Get()); + std::shared_ptr platform(&JsPlatform::Get()); gd::PlatformManager::Get()->AddPlatform(platform); } std::cout << "Platform initialization ended." << std::endl; diff --git a/WebIDE/postjs.js b/WebIDE/postjs.js deleted file mode 100644 index c1bc7a2..0000000 --- a/WebIDE/postjs.js +++ /dev/null @@ -1,2 +0,0 @@ -Module = Module || {}; -var gd = Module; \ No newline at end of file diff --git a/package.json b/package.json index 59d1345..48891fb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,10 @@ { - "name": "gdevelop-web-ide", + "name": "libGD.js", "version": "0.0.1", + "author": "Florian Rival (http://florianrival.com)", + "description": "Core of GDevelop, the open-source game creator requiring no programming skills, ported to Javascript", + "keywords": ["GDevelop", "game", "creator", "events", "programming", "making", "port"], + "license": "MIT", "devDependencies": { "grunt": "latest", "mocha": "~1.18.2", diff --git a/test/libGD_Core.js b/test/libGD_Core.js index 1773a1f..860b21d 100644 --- a/test/libGD_Core.js +++ b/test/libGD_Core.js @@ -35,6 +35,12 @@ describe('libGD.js', function(){ expect(gd.Project.validateObjectName("ThisNameIsNot_Ok!")).to.be(false); }); + it("should have a list of extensions", function() { + expect(project.getUsedExtensions().size()).to.be.a("number"); + project.getUsedExtensions().clear(); + expect(project.getUsedExtensions().size()).to.be(0); + }); + after(function() { project.delete(); }); });