GDevelop JS Platform
Platform for developing HTML5/Javascript based games with GDevelop
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
gdjs::EventsCodeGenerator Class Reference

The class being responsible for generating JavaScript code from events. More...

#include <EventsCodeGenerator.h>

Inherits gd::EventsCodeGenerator.

Public Member Functions

virtual gd::String GenerateEventsListCode (gd::EventsList &events, gd::EventsCodeGenerationContext &context) override
 Generate code for executing an event list. More...
 
virtual gd::String GenerateConditionsListCode (gd::InstructionsList &conditions, gd::EventsCodeGenerationContext &context) override
 
virtual gd::String GenerateBooleanFullName (const gd::String &boolName, const gd::EventsCodeGenerationContext &context) override
 Generate the full name for accessing to a boolean variable used for conditions.
 
virtual gd::String GenerateUpperScopeBooleanFullName (const gd::String &boolName, const gd::EventsCodeGenerationContext &context) override
 Generate the full name for accessing to a boolean variable used for conditions.
 
virtual gd::String GenerateBooleanInitializationToFalse (const gd::String &boolName, const gd::EventsCodeGenerationContext &context) override
 Set a boolean to false.
 
virtual gd::String GetObjectListName (const gd::String &name, const gd::EventsCodeGenerationContext &context) override
 Get the full name for accessing to a list of objects.
 
virtual gd::String GetCodeNamespaceAccessor () override
 Get the namespace to be used to store code generated objects/values/functions, with the extra "dot" at the end to be used to access to a property/member. More...
 
virtual gd::String GetCodeNamespace () override
 Get the namespace to be used to store code generated objects/values/functions. More...
 
void SetCodeNamespace (const gd::String &codeNamespace_)
 Specify the code namespace to use, useful for functions as it is not autogenerated. More...
 
virtual gd::String GeneratePropertySetterWithoutCasting (const gd::PropertiesContainer &propertiesContainer, const gd::NamedPropertyDescriptor &property, const gd::String &operandCode) override
 

Static Public Member Functions

static gd::String GenerateLayoutCode (const gd::Project &project, const gd::Layout &scene, const gd::String &codeNamespace, std::set< gd::String > &includeFiles, gd::DiagnosticReport &diagnosticReport, bool compilationForRuntime=false)
 
static gd::String GenerateEventsFunctionCode (gd::Project &project, const gd::EventsFunctionsExtension &eventsFunctionsExtension, const gd::EventsFunction &eventsFunction, const gd::String &codeNamespace, std::set< gd::String > &includeFiles, bool compilationForRuntime=false)
 
static gd::String GenerateBehaviorEventsFunctionCode (gd::Project &project, const gd::EventsFunctionsExtension &eventsFunctionsExtension, const gd::EventsBasedBehavior &eventsBasedBehavior, const gd::EventsFunction &eventsFunction, const gd::String &codeNamespace, const gd::String &fullyQualifiedFunctionName, const gd::String &onceTriggersVariable, const gd::String &preludeCode, std::set< gd::String > &includeFiles, bool compilationForRuntime=false)
 
static gd::String GenerateObjectEventsFunctionCode (gd::Project &project, const gd::EventsFunctionsExtension &eventsFunctionsExtension, const gd::EventsBasedObject &eventsBasedObject, const gd::EventsFunction &eventsFunction, const gd::String &codeNamespace, const gd::String &fullyQualifiedFunctionName, const gd::String &onceTriggersVariable, const gd::String &preludeCode, const gd::String &endingCode, std::set< gd::String > &includeFiles, bool compilationForRuntime=false)
 

Protected Member Functions

virtual gd::String GenerateParameterCodes (const gd::Expression &parameter, const gd::ParameterMetadata &metadata, gd::EventsCodeGenerationContext &context, const gd::String &lastObjectName, std::vector< std::pair< gd::String, gd::String > > *supplementaryParametersTypes) override
 
virtual gd::String GenerateObjectFunctionCall (gd::String objectListName, const gd::ObjectMetadata &objMetadata, const gd::ExpressionCodeGenerationInformation &codeInfo, gd::String parametersStr, gd::String defaultOutput, gd::EventsCodeGenerationContext &context) override
 
virtual gd::String GenerateObjectBehaviorFunctionCall (gd::String objectListName, gd::String behaviorName, const gd::BehaviorMetadata &autoInfo, const gd::ExpressionCodeGenerationInformation &codeInfo, gd::String parametersStr, gd::String defaultOutput, gd::EventsCodeGenerationContext &context) override
 
virtual gd::String GenerateFreeCondition (const std::vector< gd::String > &arguments, const gd::InstructionMetadata &instrInfos, const gd::String &returnBoolean, bool conditionInverted, gd::EventsCodeGenerationContext &context) override
 
virtual gd::String GenerateObjectCondition (const gd::String &objectName, const gd::ObjectMetadata &objInfo, const std::vector< gd::String > &arguments, const gd::InstructionMetadata &instrInfos, const gd::String &returnBoolean, bool conditionInverted, gd::EventsCodeGenerationContext &context) override
 
virtual gd::String GenerateBehaviorCondition (const gd::String &objectName, const gd::String &behaviorName, const gd::BehaviorMetadata &autoInfo, const std::vector< gd::String > &arguments, const gd::InstructionMetadata &instrInfos, const gd::String &returnBoolean, bool conditionInverted, gd::EventsCodeGenerationContext &context) override
 
virtual gd::String GenerateObjectAction (const gd::String &objectName, const gd::ObjectMetadata &objInfo, const gd::String &functionCallName, const std::vector< gd::String > &arguments, const gd::InstructionMetadata &instrInfos, gd::EventsCodeGenerationContext &context, const gd::String &optionalAsyncCallbackName="") override
 
virtual gd::String GenerateBehaviorAction (const gd::String &objectName, const gd::String &behaviorName, const gd::BehaviorMetadata &autoInfo, const gd::String &functionCallName, const std::vector< gd::String > &arguments, const gd::InstructionMetadata &instrInfos, gd::EventsCodeGenerationContext &context, const gd::String &optionalAsyncCallbackName="") override
 
virtual gd::String GenerateGetBehaviorNameCode (const gd::String &behaviorName) override
 
virtual gd::String GenerateGetVariable (const gd::String &variableName, const VariableScope &scope, gd::EventsCodeGenerationContext &context, const gd::String &objectName, bool hasChild) override
 
virtual gd::String GenerateVariableAccessor (gd::String childName) override
 
virtual gd::String GenerateVariableBracketAccessor (gd::String expressionCode) override
 
virtual gd::String GenerateBadVariable () override
 
virtual gd::String GeneratePropertyGetter (const gd::PropertiesContainer &propertiesContainer, const gd::NamedPropertyDescriptor &property, const gd::String &type, gd::EventsCodeGenerationContext &context) override
 
virtual gd::String GeneratePropertyGetterWithoutCasting (const gd::PropertiesContainer &propertiesContainer, const gd::NamedPropertyDescriptor &property) override
 
virtual gd::String GenerateParameterGetter (const gd::ParameterMetadata &parameter, const gd::String &type, gd::EventsCodeGenerationContext &context) override
 
virtual gd::String GenerateParameterGetterWithoutCasting (const gd::ParameterMetadata &parameter) override
 
virtual gd::String GenerateBadObject () override
 
virtual gd::String GenerateObject (const gd::String &objectName, const gd::String &type, gd::EventsCodeGenerationContext &context) override
 
virtual gd::String GenerateNegatedPredicate (const gd::String &predicate) const override
 
virtual gd::String GenerateObjectsDeclarationCode (gd::EventsCodeGenerationContext &context) override
 
virtual gd::String GenerateAllInstancesGetterCode (const gd::String &objectName, gd::EventsCodeGenerationContext &context)
 
virtual gd::String GenerateProfilerSectionBegin (const gd::String &section) override
 
virtual gd::String GenerateProfilerSectionEnd (const gd::String &section) override
 
virtual gd::String GenerateRelationalOperation (const gd::String &relationalOperator, const gd::String &lhs, const gd::String &rhs) override
 

Detailed Description

The class being responsible for generating JavaScript code from events.

See also gd::EventsCodeGenerator.

Member Function Documentation

◆ GenerateBehaviorEventsFunctionCode()

gd::String gdjs::EventsCodeGenerator::GenerateBehaviorEventsFunctionCode ( gd::Project &  project,
const gd::EventsFunctionsExtension &  eventsFunctionsExtension,
const gd::EventsBasedBehavior &  eventsBasedBehavior,
const gd::EventsFunction &  eventsFunction,
const gd::String &  codeNamespace,
const gd::String &  fullyQualifiedFunctionName,
const gd::String &  onceTriggersVariable,
const gd::String &  preludeCode,
std::set< gd::String > &  includeFiles,
bool  compilationForRuntime = false 
)
static

Generate JavaScript for executing events of a events based behavior function.

Parameters
projectProject used.
eventsFunctionThe events function to be compiled.
codeNamespaceWhere to store the context used by the function.
fullyQualifiedFunctionNameThe function name with its namespace.
onceTriggersVariableThe code to access the variable holding OnceTriggers.
preludeCodeThe code to run just before the events generated code.
includeFilesWill be filled with the necessary include files.
compilationForRuntimeSet this to true if the code is generated for runtime.
Returns
JavaScript code

◆ GenerateConditionsListCode()

gd::String gdjs::EventsCodeGenerator::GenerateConditionsListCode ( gd::InstructionsList &  conditions,
gd::EventsCodeGenerationContext &  context 
)
overridevirtual

Generate code for executing a condition list

Parameters
gameGame used
sceneScene used
conditionsstd::vector of conditions
contextContext used for generation
Returns
JS code.

◆ GenerateEventsFunctionCode()

gd::String gdjs::EventsCodeGenerator::GenerateEventsFunctionCode ( gd::Project &  project,
const gd::EventsFunctionsExtension &  eventsFunctionsExtension,
const gd::EventsFunction &  eventsFunction,
const gd::String &  codeNamespace,
std::set< gd::String > &  includeFiles,
bool  compilationForRuntime = false 
)
static

Generate JavaScript for executing events of an events based function.

Parameters
projectProject used.
eventsFunctionsExtensionThe container of the compiled event function.
eventsFunctionThe events function to be compiled.
codeNamespaceWhere to store the context used by the function.
includeFilesWill be filled with the necessary include files.
compilationForRuntimeSet this to true if the code is generated for runtime.
Returns
JavaScript code

◆ GenerateEventsListCode()

gd::String gdjs::EventsCodeGenerator::GenerateEventsListCode ( gd::EventsList &  events,
gd::EventsCodeGenerationContext &  context 
)
overridevirtual

Generate code for executing an event list.

Note
To reduce the stress on JS engines, the code is generated inside a separate JS function (see gd::EventsCodeGenerator::AddCustomCodeOutsideMain). This method will return the code to call this separate function.
Parameters
eventsstd::vector of events
contextContext used for generation
Returns
Code

◆ GenerateLayoutCode()

gd::String gdjs::EventsCodeGenerator::GenerateLayoutCode ( const gd::Project &  project,
const gd::Layout &  scene,
const gd::String &  codeNamespace,
std::set< gd::String > &  includeFiles,
gd::DiagnosticReport &  diagnosticReport,
bool  compilationForRuntime = false 
)
static

Generate JavaScript for executing events of a scene

Parameters
projectProject the scene belongs to.
sceneThe scene to generate the code for.
includeFilesWill be filled with the necessary include files.
compilationForRuntimeSet this to true if the code is generated for runtime.
Returns
JavaScript code

◆ GenerateObjectEventsFunctionCode()

gd::String gdjs::EventsCodeGenerator::GenerateObjectEventsFunctionCode ( gd::Project &  project,
const gd::EventsFunctionsExtension &  eventsFunctionsExtension,
const gd::EventsBasedObject &  eventsBasedObject,
const gd::EventsFunction &  eventsFunction,
const gd::String &  codeNamespace,
const gd::String &  fullyQualifiedFunctionName,
const gd::String &  onceTriggersVariable,
const gd::String &  preludeCode,
const gd::String &  endingCode,
std::set< gd::String > &  includeFiles,
bool  compilationForRuntime = false 
)
static

Generate JavaScript for executing events of a events based object function.

Parameters
projectProject used.
eventsBasedObjectThe object that contains the function to be compiled.
eventsFunctionThe events function to be compiled.
codeNamespaceWhere to store the context used by the function.
fullyQualifiedFunctionNameThe function name with its namespace.
onceTriggersVariableThe code to access the variable holding OnceTriggers.
preludeCodeThe code to run right before the events generated code.
endingCodeThe code to run right after the events generated code.
includeFilesWill be filled with the necessary include files.
compilationForRuntimeSet this to true if the code is generated for runtime.
Returns
JavaScript code

◆ GetCodeNamespace()

virtual gd::String gdjs::EventsCodeGenerator::GetCodeNamespace ( )
inlineoverridevirtual

Get the namespace to be used to store code generated objects/values/functions.

Example: "gdjs.something"

◆ GetCodeNamespaceAccessor()

virtual gd::String gdjs::EventsCodeGenerator::GetCodeNamespaceAccessor ( )
inlineoverridevirtual

Get the namespace to be used to store code generated objects/values/functions, with the extra "dot" at the end to be used to access to a property/member.

Example: "gdjs.something."

◆ SetCodeNamespace()

void gdjs::EventsCodeGenerator::SetCodeNamespace ( const gd::String &  codeNamespace_)
inline

Specify the code namespace to use, useful for functions as it is not autogenerated.

Example: "gdjs.something"


The documentation for this class was generated from the following files: