#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "../../Extensions/PanelSpriteObject/PanelSpriteObject.h" #include "../../Extensions/ParticleSystem/ParticleEmitterObject.h" #include "../../Extensions/PrimitiveDrawing/ShapePainterObject.h" #include "../../Extensions/SkeletonObject/SkeletonObject.h" #include "../../Extensions/TextEntryObject/TextEntryObject.h" #include "../../Extensions/TextObject/TextObject.h" #include "../../Extensions/TiledSpriteObject/TiledSpriteObject.h" #include "BehaviorJsImplementation.h" #include "BehaviorSharedDataJsImplementation.h" #include "ObjectJsImplementation.h" #include "ProjectHelper.h" /** * \brief Manual binding of gd::ArbitraryResourceWorker to allow overriding * methods that are using std::string */ class ArbitraryResourceWorkerJS : public ArbitraryResourceWorker { public: void ExposeImage(gd::String &arg0) { arg0 = (const char *)EM_ASM_INT( { var self = Module['getCache'](Module['ArbitraryResourceWorkerJS'])[$0]; if (!self.hasOwnProperty('exposeImage')) throw 'a JSImplementation must implement all functions, you forgot ArbitraryResourceWorkerJS::exposeImage.'; return ensureString(self.exposeImage(UTF8ToString($1))); }, (int)this, arg0.c_str()); } void ExposeShader(gd::String &arg0) { arg0 = (const char *)EM_ASM_INT( { var self = Module['getCache'](Module['ArbitraryResourceWorkerJS'])[$0]; if (!self.hasOwnProperty('exposeShader')) throw 'a JSImplementation must implement all functions, you forgot ArbitraryResourceWorkerJS::exposeShader.'; return ensureString(self.exposeShader(UTF8ToString($1))); }, (int)this, arg0.c_str()); } void ExposeFile(gd::String &arg0) { arg0 = (const char *)EM_ASM_INT( { var self = Module['getCache'](Module['ArbitraryResourceWorkerJS'])[$0]; if (!self.hasOwnProperty('exposeFile')) throw 'a JSImplementation must implement all functions, you forgot ArbitraryResourceWorkerJS::exposeFile.'; return ensureString(self.exposeFile(UTF8ToString($1))); }, (int)this, arg0.c_str()); } }; /** * \brief Manual binding of gd::AbstractFileSystem to allow overriding methods * that are using std::string */ class AbstractFileSystemJS : public AbstractFileSystem { public: virtual void MkDir(const gd::String &path) { EM_ASM_INT( { var self = Module['getCache'](Module['AbstractFileSystemJS'])[$0]; if (!self.hasOwnProperty('mkDir')) throw 'a JSImplementation must implement all functions, you forgot AbstractFileSystemJS::mkDir.'; self.mkDir(UTF8ToString($1)); }, (int)this, path.c_str()); } virtual bool DirExists(const gd::String &path) { return EM_ASM_INT( { var self = Module['getCache'](Module['AbstractFileSystemJS'])[$0]; if (!self.hasOwnProperty('dirExists')) throw 'a JSImplementation must implement all functions, you forgot AbstractFileSystemJS::dirExists.'; return self.dirExists(UTF8ToString($1)); }, (int)this, path.c_str()); } virtual bool FileExists(const gd::String &path) { return EM_ASM_INT( { var self = Module['getCache'](Module['AbstractFileSystemJS'])[$0]; if (!self.hasOwnProperty('fileExists')) throw 'a JSImplementation must implement all functions, you forgot AbstractFileSystemJS::fileExists.'; return self.fileExists(UTF8ToString($1)); }, (int)this, path.c_str()); } virtual gd::String FileNameFrom(const gd::String &file) { return (const char *)EM_ASM_INT( { var self = Module['getCache'](Module['AbstractFileSystemJS'])[$0]; if (!self.hasOwnProperty('fileNameFrom')) throw 'a JSImplementation must implement all functions, you forgot AbstractFileSystemJS::fileNameFrom.'; return ensureString(self.fileNameFrom(UTF8ToString($1))); }, (int)this, file.c_str()); } virtual gd::String DirNameFrom(const gd::String &file) { return (const char *)EM_ASM_INT( { var self = Module['getCache'](Module['AbstractFileSystemJS'])[$0]; if (!self.hasOwnProperty('dirNameFrom')) throw 'a JSImplementation must implement all functions, you forgot AbstractFileSystemJS::dirNameFrom.'; return ensureString(self.dirNameFrom(UTF8ToString($1))); }, (int)this, file.c_str()); } virtual bool MakeAbsolute(gd::String &filename, const gd::String &baseDirectory) { filename = (const char *)EM_ASM_INT( { var self = Module['getCache'](Module['AbstractFileSystemJS'])[$0]; if (!self.hasOwnProperty('makeAbsolute')) throw 'a JSImplementation must implement all functions, you forgot AbstractFileSystemJS::makeAbsolute.'; return ensureString( self.makeAbsolute(UTF8ToString($1), UTF8ToString($2))); }, (int)this, filename.c_str(), baseDirectory.c_str()); return true; } virtual bool MakeRelative(gd::String &filename, const gd::String &baseDirectory) { filename = (const char *)EM_ASM_INT( { var self = Module['getCache'](Module['AbstractFileSystemJS'])[$0]; if (!self.hasOwnProperty('makeRelative')) throw 'a JSImplementation must implement all functions, you forgot AbstractFileSystemJS::makeRelative.'; return ensureString( self.makeRelative(UTF8ToString($1), UTF8ToString($2))); }, (int)this, filename.c_str(), baseDirectory.c_str()); return true; } virtual bool IsAbsolute(const gd::String &filename) { return (bool)EM_ASM_INT( { var self = Module['getCache'](Module['AbstractFileSystemJS'])[$0]; if (!self.hasOwnProperty('isAbsolute')) throw 'a JSImplementation must implement all functions, you forgot AbstractFileSystemJS::isAbsolute.'; return self.isAbsolute(UTF8ToString($1)); }, (int)this, filename.c_str()); }; virtual bool CopyFile(const gd::String &file, const gd::String &destination) { return (bool)EM_ASM_INT( { var self = Module['getCache'](Module['AbstractFileSystemJS'])[$0]; if (!self.hasOwnProperty('copyFile')) throw 'a JSImplementation must implement all functions, you forgot AbstractFileSystemJS::copyFile.'; return self.copyFile(UTF8ToString($1), UTF8ToString($2)); }, (int)this, file.c_str(), destination.c_str()); } virtual bool ClearDir(const gd::String &directory) { return (bool)EM_ASM_INT( { var self = Module['getCache'](Module['AbstractFileSystemJS'])[$0]; if (!self.hasOwnProperty('clearDir')) throw 'a JSImplementation must implement all functions, you forgot AbstractFileSystemJS::clearDir.'; return self.clearDir(UTF8ToString($1)); }, (int)this, directory.c_str()); } virtual bool WriteToFile(const gd::String &file, const gd::String &content) { return (bool)EM_ASM_INT( { var self = Module['getCache'](Module['AbstractFileSystemJS'])[$0]; if (!self.hasOwnProperty('writeToFile')) throw 'a JSImplementation must implement all functions, you forgot AbstractFileSystemJS::writeToFile.'; return self.writeToFile(UTF8ToString($1), UTF8ToString($2)); }, (int)this, file.c_str(), content.c_str()); } virtual gd::String ReadFile(const gd::String &file) { return (const char *)EM_ASM_INT( { var self = Module['getCache'](Module['AbstractFileSystemJS'])[$0]; if (!self.hasOwnProperty('readFile')) throw 'a JSImplementation must implement all functions, you forgot AbstractFileSystemJS::readFile.'; return ensureString(self.readFile(UTF8ToString($1))); }, (int)this, file.c_str()); } virtual gd::String GetTempDir() { return (const char *)EM_ASM_INT( { var self = Module['getCache'](Module['AbstractFileSystemJS'])[$0]; if (!self.hasOwnProperty('getTempDir')) throw 'a JSImplementation must implement all functions, you forgot AbstractFileSystemJS::getTempDir.'; return ensureString(self.getTempDir()); }, (int)this); } virtual std::vector ReadDir(const gd::String &path, const gd::String &extension = "") { std::vector directories = *(std::vector *)EM_ASM_INT( { var self = Module['getCache'](Module['AbstractFileSystemJS'])[$0]; if (!self.hasOwnProperty('readDir')) throw 'a JSImplementation must implement all functions, you forgot AbstractFileSystemJS::readDir.'; return self.readDir(UTF8ToString($1), UTF8ToString($2)).ptr; }, (int)this, path.c_str(), extension.c_str()); return directories; } AbstractFileSystemJS(){}; virtual ~AbstractFileSystemJS(){}; }; class InitialInstanceJSFunctorWrapper : public gd::InitialInstanceFunctor { public: InitialInstanceJSFunctorWrapper(){}; virtual void operator()(gd::InitialInstance &instance) { invoke(&instance); }; virtual void invoke(gd::InitialInstance *instance){}; }; // Implement some std::vector<*> erase methods as free functions as there is no // easy way to properly expose the erase method :'( void removeFromVectorPolygon2d(std::vector &vec, size_t pos) { vec.erase(vec.begin() + pos); } void removeFromVectorVector2f(std::vector &vec, size_t pos) { vec.erase(vec.begin() + pos); } void removeFromVectorParameterMetadata(std::vector &vec, size_t pos) { vec.erase(vec.begin() + pos); } // Implement a conversion from std::set to std::vector // as there is no easy way to properly expose iterators :/ std::vector toNewVectorString(const std::set &set) { std::vector output(set.begin(), set.end()); return output; } // Declares typedef for std::vector and templatized types typedef std::vector VectorString; typedef std::vector> VectorPlatformExtension; typedef std::pair PairStringVariable; typedef std::pair PairStringTextFormatting; typedef std::vector> VectorPairStringTextFormatting; typedef std::vector VectorObjectGroup; typedef std::map MapStringString; typedef std::map MapStringBoolean; typedef std::map MapStringDouble; typedef std::map MapStringExpressionMetadata; typedef std::map MapStringInstructionMetadata; typedef std::map MapStringEventMetadata; typedef std::map MapStringVariable; typedef std::map MapStringPropertyDescriptor; typedef std::set SetString; typedef std::vector VectorPoint; typedef std::vector VectorPolygon2d; typedef std::vector VectorVector2f; typedef std::vector VectorEventsSearchResult; typedef std::vector VectorParameterMetadata; typedef std::vector VectorDependencyMetadata; typedef std::vector VectorEventsFunction; typedef gd::Object gdObject; // To avoid clashing javascript Object in glue.js typedef ParticleEmitterObject::RendererType ParticleEmitterObject_RendererType; typedef EventsFunction::FunctionType EventsFunction_FunctionType; typedef std::unique_ptr UniquePtrObject; typedef std::unique_ptr UniquePtrExpressionNode; typedef std::vector VectorExpressionParserDiagnostic; typedef gd::SerializableWithNameList EventsBasedBehaviorsList; typedef gd::SerializableWithNameList NamedPropertyDescriptorsList; typedef ExpressionCompletionDescription::CompletionKind ExpressionCompletionDescription_CompletionKind; typedef std::vector VectorExpressionCompletionDescription; typedef std::map> MapExtensionProperties; typedef ExtensionAndMetadata ExtensionAndBehaviorMetadata; typedef ExtensionAndMetadata ExtensionAndObjectMetadata; typedef ExtensionAndMetadata ExtensionAndEffectMetadata; typedef ExtensionAndMetadata ExtensionAndInstructionMetadata; typedef ExtensionAndMetadata ExtensionAndInstructionMetadata; typedef ExtensionAndMetadata ExtensionAndExpressionMetadata; typedef ExtensionAndMetadata ExtensionAndExpressionMetadata; typedef ExtensionAndMetadata ExtensionAndExpressionMetadata; typedef ExtensionAndMetadata ExtensionAndExpressionMetadata; typedef ExtensionAndMetadata ExtensionAndExpressionMetadata; typedef ExtensionAndMetadata ExtensionAndExpressionMetadata; // 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 WRAPPED_GetString(i) at(i).first #define WRAPPED_GetComment() com1 #define WRAPPED_SetComment(str) com1 = str #define WRAPPED_GetTextFormatting(i) at(i).second #define WRAPPED_GetName() first #define WRAPPED_GetVariable() second #define WRAPPED_SetBool(v) SetValue(v) #define WRAPPED_SetString(v) SetValue(gd::String(v)) #define WRAPPED_SetInt(v) SetValue(v) #define WRAPPED_SetDouble(v) SetValue(v) #define WRAPPED_SetChild(name, child) GetChild(name) = child // Wrappers to avoid dealing with shared_ptr in the methods interface: #define WRAPPED_AddBehavior(name, \ fullname, \ defaultName, \ description, \ group, \ icon24x24, \ className, \ instance, \ sharedDatasInstance) \ AddBehavior(name, \ fullname, \ defaultName, \ description, \ group, \ icon24x24, \ className, \ std::shared_ptr(instance), \ std::shared_ptr(sharedDatasInstance)) #define WRAPPED_AddObject(name, fullname, description, icon24x24, instance) \ AddObject(name, \ fullname, \ description, \ icon24x24, \ std::shared_ptr(instance)) #define WRAPPED_at(a) at(a).get() #define MAP_getOrCreate(key) operator[](key) #define MAP_get(key) find(key)->second #define MAP_set(key, value) [key] = value #define MAP_has(key) find(key) != self->end() #define STATIC_CreateNewGDJSProject CreateNewGDJSProject #define STATIC_InitializePlatforms InitializePlatforms #define STATIC_ValidateName ValidateName #define STATIC_ToJSON ToJSON #define STATIC_FromJSON(x) FromJSON(gd::String(x)) #define STATIC_IsObject IsObject #define STATIC_IsBehavior IsBehavior #define STATIC_Get Get #define STATIC_AddAllMissing AddAllMissing #define STATIC_GetAllUseless GetAllUseless #define STATIC_RemoveAllUseless RemoveAllUseless #define STATIC_GetExtensionAndBehaviorMetadata GetExtensionAndBehaviorMetadata #define STATIC_GetExtensionAndObjectMetadata GetExtensionAndObjectMetadata #define STATIC_GetExtensionAndEffectMetadata GetExtensionAndEffectMetadata #define STATIC_GetExtensionAndActionMetadata GetExtensionAndActionMetadata #define STATIC_GetExtensionAndConditionMetadata GetExtensionAndConditionMetadata #define STATIC_GetExtensionAndExpressionMetadata \ GetExtensionAndExpressionMetadata #define STATIC_GetExtensionAndObjectExpressionMetadata \ GetExtensionAndObjectExpressionMetadata #define STATIC_GetExtensionAndBehaviorExpressionMetadata \ GetExtensionAndBehaviorExpressionMetadata #define STATIC_GetExtensionAndStrExpressionMetadata \ GetExtensionAndStrExpressionMetadata #define STATIC_GetExtensionAndObjectStrExpressionMetadata \ GetExtensionAndObjectStrExpressionMetadata #define STATIC_GetExtensionAndBehaviorStrExpressionMetadata \ GetExtensionAndBehaviorStrExpressionMetadata #define STATIC_HasCondition HasCondition #define STATIC_HasAction HasAction #define STATIC_HasObjectAction HasObjectAction #define STATIC_HasObjectCondition HasObjectCondition #define STATIC_HasBehaviorAction HasBehaviorAction #define STATIC_HasBehaviorCondition HasBehaviorCondition #define STATIC_HasExpression HasExpression #define STATIC_HasObjectExpression HasObjectExpression #define STATIC_HasBehaviorExpression HasBehaviorExpression #define STATIC_HasStrExpression HasStrExpression #define STATIC_HasObjectStrExpression HasObjectStrExpression #define STATIC_HasBehaviorStrExpression HasBehaviorStrExpression #define STATIC_RenameObjectInEvents RenameObjectInEvents #define STATIC_RemoveObjectInEvents RemoveObjectInEvents #define STATIC_ReplaceStringInEvents ReplaceStringInEvents #define STATIC_ExposeProjectEvents ExposeProjectEvents #define STATIC_GetBehaviorMetadata GetBehaviorMetadata #define STATIC_GetObjectMetadata GetObjectMetadata #define STATIC_GetEffectMetadata GetEffectMetadata #define STATIC_GetActionMetadata GetActionMetadata #define STATIC_GetConditionMetadata GetConditionMetadata #define STATIC_GetExpressionMetadata GetExpressionMetadata #define STATIC_GetObjectExpressionMetadata GetObjectExpressionMetadata #define STATIC_GetBehaviorExpressionMetadata GetBehaviorExpressionMetadata #define STATIC_GetStrExpressionMetadata GetStrExpressionMetadata #define STATIC_GetObjectStrExpressionMetadata GetObjectStrExpressionMetadata #define STATIC_GetBehaviorStrExpressionMetadata GetBehaviorStrExpressionMetadata #define STATIC_Major Major #define STATIC_Minor Minor #define STATIC_Build Build #define STATIC_Revision Revision #define STATIC_FullString FullString #define STATIC_Status Status #define STATIC_Year Year #define STATIC_Month Month #define STATIC_Date Date #define STATIC_ObjectOrGroupRenamedInLayout ObjectOrGroupRenamedInLayout #define STATIC_ObjectOrGroupRemovedInLayout ObjectOrGroupRemovedInLayout #define STATIC_ObjectOrGroupRemovedInEventsFunction \ ObjectOrGroupRemovedInEventsFunction #define STATIC_ObjectOrGroupRenamedInEventsFunction \ ObjectOrGroupRenamedInEventsFunction #define STATIC_GlobalObjectOrGroupRenamed GlobalObjectOrGroupRenamed #define STATIC_GlobalObjectOrGroupRemoved GlobalObjectOrGroupRemoved #define STATIC_GetAllObjectTypesUsingEventsBasedBehavior \ GetAllObjectTypesUsingEventsBasedBehavior #define STATIC_EnsureBehaviorEventsFunctionsProperParameters \ EnsureBehaviorEventsFunctionsProperParameters #define STATIC_CreateRectangle CreateRectangle #define STATIC_SanityCheckBehaviorProperty SanityCheckBehaviorProperty #define STATIC_SanityCheckObjectProperty SanityCheckObjectProperty #define STATIC_SanityCheckObjectInitialInstanceProperty \ SanityCheckObjectInitialInstanceProperty #define STATIC_SanityCheckBehaviorsSharedDataProperty \ SanityCheckBehaviorsSharedDataProperty #define STATIC_SearchInEvents SearchInEvents #define STATIC_UnfoldWhenContaining UnfoldWhenContaining #define STATIC_EventsFunctionToObjectsContainer EventsFunctionToObjectsContainer #define STATIC_ParametersToObjectsContainer ParametersToObjectsContainer #define STATIC_GetObjectParameterIndexFor GetObjectParameterIndexFor #define STATIC_GetNamespaceSeparator GetNamespaceSeparator #define STATIC_RenameEventsFunctionsExtension RenameEventsFunctionsExtension #define STATIC_RenameEventsFunction RenameEventsFunction #define STATIC_RenameBehaviorEventsFunction RenameBehaviorEventsFunction #define STATIC_MoveEventsFunctionParameter MoveEventsFunctionParameter #define STATIC_MoveBehaviorEventsFunctionParameter \ MoveBehaviorEventsFunctionParameter #define STATIC_RenameBehaviorProperty RenameBehaviorProperty #define STATIC_RenameEventsBasedBehavior RenameEventsBasedBehavior #define STATIC_GetBehaviorPropertyGetterName GetBehaviorPropertyGetterName #define STATIC_GetBehaviorPropertySetterName GetBehaviorPropertySetterName #define STATIC_GetPropertyActionName GetPropertyActionName #define STATIC_GetPropertyConditionName GetPropertyConditionName #define STATIC_GetPropertyExpressionName GetPropertyExpressionName #define STATIC_CopyAllResourcesTo CopyAllResourcesTo #define STATIC_IsExtensionLifecycleEventsFunction \ IsExtensionLifecycleEventsFunction #define STATIC_GetCompletionDescriptionsFor GetCompletionDescriptionsFor // We postfix some methods with "At" as Javascript does not support overloading #define GetLayoutAt GetLayout #define GetExternalEventsAt GetExternalEvents #define GetExternalLayoutAt GetExternalLayout #define GetEventsFunctionsExtensionAt GetEventsFunctionsExtension #define GetLayerAt GetLayer #define GetObjectAt GetObject #define GetAt Get #define GetEventAt GetEvent #define RemoveEventAt RemoveEvent #define RemoveAt Remove #define GetEventsFunctionAt GetEventsFunction #define GetEffectAt GetEffect // 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"