GDevelop JS Platform
Platform for developing HTML5/Javascript based games with GDevelop
BehaviorCodeGenerator.h
1 /*
2  * GDevelop JS Platform
3  * Copyright 2008-2016 Florian Rival ([email protected]). All rights
4  * reserved. This project is released under the MIT License.
5  */
6 #pragma once
7 
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <vector>
12 
13 #include "GDCore/Project/Project.h"
14 #include "GDCore/Project/EventsBasedBehavior.h"
15 
16 namespace gd {
17 class NamedPropertyDescriptor;
18 class EventsBasedBehavior;
19 }
20 
21 namespace gdjs {
22 
30  public:
31  BehaviorCodeGenerator(gd::Project& project_) : project(project_){};
32 
38  const gd::EventsFunctionsExtension& eventsFunctionsExtension,
39  const gd::EventsBasedBehavior& eventsBasedBehavior,
40  const gd::String& codeNamespace,
41  const std::map<gd::String, gd::String>& behaviorMethodMangledNames,
42  std::set<gd::String>& includeFiles,
43  bool compilationForRuntime = false);
44 
49  static gd::String GetBehaviorPropertyGetterName(
50  const gd::String& propertyName) {
51  return "_get" + propertyName;
52  }
53 
58  static gd::String GetBehaviorPropertySetterName(
59  const gd::String& propertyName) {
60  return "_set" + propertyName;
61  }
62 
68  const gd::String& propertyName) {
69  return "_toggle" + propertyName;
70  }
71 
76  static gd::String GetBehaviorSharedPropertyGetterName(
77  const gd::String& propertyName);
78 
83  static gd::String GetBehaviorSharedPropertySetterName(
84  const gd::String& propertyName);
85 
91  const gd::String& propertyName);
92 
93  private:
98  static gd::String GetBehaviorSharedPropertyGetterInternalName(
99  const gd::String& propertyName);
100 
105  static gd::String GetBehaviorSharedPropertySetterInternalName(
106  const gd::String& propertyName);
107 
112  static gd::String GetBehaviorSharedPropertyToggleFunctionInternalName(
113  const gd::String& propertyName);
114 
115  gd::String GenerateRuntimeBehaviorTemplateCode(
116  const gd::String& extensionName,
117  const gd::EventsBasedBehavior& eventsBasedBehavior,
118  const gd::String& codeNamespace,
119  std::function<gd::String()> generateInitializePropertiesCode,
120  std::function<gd::String()> generatePropertiesCode,
121  std::function<gd::String()> generateInitializeSharedPropertiesCode,
122  std::function<gd::String()> generateSharedPropertiesCode,
123  std::function<gd::String()> generateMethodsCode,
124  std::function<gd::String()> generateUpdateFromBehaviorDataCode,
125  std::function<gd::String()> generateGetNetworkSyncDataCode,
126  std::function<gd::String()> generateUpdateFromNetworkSyncDataCode);
127 
128  gd::String GenerateRuntimeBehaviorPropertyTemplateCode(
129  const gd::EventsBasedBehavior& eventsBasedBehavior,
130  const gd::NamedPropertyDescriptor& property);
131 
132  gd::String GenerateToggleBooleanPropertyTemplateCode(
133  const gd::String& toggleName,
134  const gd::String& getterName,
135  const gd::String& setterName);
136 
137  gd::String GenerateInitializePropertyFromDataCode(
138  const gd::NamedPropertyDescriptor& property);
139 
140  gd::String GenerateInitializePropertyFromDefaultValueCode(
141  const gd::NamedPropertyDescriptor& property);
142 
143  gd::String GenerateRuntimeBehaviorSharedPropertyTemplateCode(
144  const gd::EventsBasedBehavior& eventsBasedBehavior,
145  const gd::NamedPropertyDescriptor& property);
146 
147  gd::String GenerateInitializeSharedPropertyFromDataCode(
148  const gd::NamedPropertyDescriptor& property);
149 
150  gd::String GenerateInitializeSharedPropertyFromDefaultValueCode(
151  const gd::NamedPropertyDescriptor& property);
152 
153  gd::String GeneratePropertyValueCode(const gd::PropertyDescriptor& property);
154 
155  gd::String GenerateUpdatePropertyFromBehaviorDataCode(
156  const gd::EventsBasedBehavior& eventsBasedBehavior,
157  const gd::NamedPropertyDescriptor& property);
158 
159  gd::String GenerateGetPropertyNetworkSyncDataCode(
160  const gd::EventsBasedBehavior& eventsBasedBehavior,
161  const gd::NamedPropertyDescriptor& property);
162 
163  gd::String GenerateUpdatePropertyFromNetworkSyncDataCode(
164  const gd::EventsBasedBehavior& eventsBasedBehavior,
165  const gd::NamedPropertyDescriptor& property);
166 
167  gd::String GenerateBehaviorOnDestroyToDeprecatedOnOwnerRemovedFromScene(
168  const gd::EventsBasedBehavior& eventsBasedBehavior,
169  const gd::String& codeNamespace);
170 
171  gd::String GenerateDefaultDoStepPreEventsFunctionCode(
172  const gd::EventsBasedBehavior& eventsBasedBehavior,
173  const gd::String& codeNamespace);
174 
175  gd::String GenerateDoStepPreEventsPreludeCode();
176 
177  gd::Project& project;
178 
179  static gd::String doStepPreEventsFunctionName;
180 };
181 
182 } // namespace gdjs
The class being responsible for generating JavaScript code for EventsBasedBehavior.
Definition: BehaviorCodeGenerator.h:29
static gd::String GetBehaviorPropertyToggleFunctionName(const gd::String &propertyName)
Generate the name of the method to toggle the value of the boolean property of a behavior.
Definition: BehaviorCodeGenerator.h:67
static gd::String GetBehaviorPropertySetterName(const gd::String &propertyName)
Generate the name of the method to set the value of the property of a behavior.
Definition: BehaviorCodeGenerator.h:58
gd::String GenerateRuntimeBehaviorCompleteCode(const gd::EventsFunctionsExtension &eventsFunctionsExtension, const gd::EventsBasedBehavior &eventsBasedBehavior, const gd::String &codeNamespace, const std::map< gd::String, gd::String > &behaviorMethodMangledNames, std::set< gd::String > &includeFiles, bool compilationForRuntime=false)
Generate the complete JS class (gdjs.RuntimeBehavior) for the behavior.
Definition: BehaviorCodeGenerator.cpp:17
static gd::String GetBehaviorSharedPropertyGetterName(const gd::String &propertyName)
Generate the name of the method to get the value of the shared property of a behavior.
Definition: BehaviorCodeGenerator.cpp:474
static gd::String GetBehaviorSharedPropertySetterName(const gd::String &propertyName)
Generate the name of the method to set the value of the shared property of a behavior.
Definition: BehaviorCodeGenerator.cpp:480
static gd::String GetBehaviorPropertyGetterName(const gd::String &propertyName)
Generate the name of the method to get the value of the property of a behavior.
Definition: BehaviorCodeGenerator.h:49
static gd::String GetBehaviorSharedPropertyToggleFunctionName(const gd::String &propertyName)
Generate the name of the method to toggle the value of the boolean shared property of a behavior.
Definition: BehaviorCodeGenerator.cpp:486