Skip to content

Commit 03ec15c

Browse files
committed
Added events generation
1 parent 06d3c99 commit 03ec15c

3 files changed

Lines changed: 49 additions & 1 deletion

File tree

src/FlowBridger.UnitTests/fullspecschema.spec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
version 1.0
22

3+
globaloption CsEventClass enabled
4+
35
# delegates
46
globaldelegate VoidDelegate
57
Int32Value int32

src/FlowBridger/EmbeddedScripts/Embedded.CSharp.Import.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,48 @@ function defineDelegate(method) {
187187
public delegate ${returnPassType} ${method.Name} ( ${parameters} );\n`;
188188
}
189189

190+
function defineEventClassProperties(event) {
191+
192+
}
193+
194+
function defineEventClass(event) {
195+
return `
196+
public class Event${event.Name} {
197+
198+
private static int m_iterator = 0;
199+
200+
private static ConcurrentDictionary<int, EventClick1> m_notCompletedEvents = new ConcurrentDictionary<int, EventClick1> ();
201+
202+
${defineEventClassProperties(event)}
203+
204+
public static Event${event.Name} CreateEvent () {
205+
var newEvent = new Event${event.Name} ();
206+
var index = Interlocked.Increment ( ref m_iterator );
207+
var completed = m_notCompletedEvents.TryAdd ( index, newEvent );
208+
if ( completed ) throw new Exception ( "Can't add new event to not completed list!" );
209+
210+
return newEvent;
211+
}
212+
213+
public static void CompleteEvent ( int index ) {
214+
if ( !m_notCompletedEvents.ContainsKey ( index ) ) return;
215+
216+
m_notCompletedEvents.TryRemove ( index, out var _ );
217+
}
218+
219+
}
220+
`;
221+
}
222+
223+
function defineEventClasses(events) {
224+
let result = ``;
225+
for (const event of events) {
226+
result += defineEventClass(event);
227+
}
228+
229+
return result;
230+
}
231+
190232
function defineFile(schema) {
191233
let result = "";
192234
result += defineImports();
@@ -206,6 +248,9 @@ function defineFile(schema) {
206248
result += defineMethod(globalMethod);
207249
}
208250

251+
var eventClasses = schema.GlobalOptions["CsEventClass"] === "enabled";
252+
if (eventClasses) defineEventClasses(schema.Events);
253+
209254
result += defineEndFile();
210255

211256
return result;

src/FlowBridger/Parsers/SchemaParser.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ public static SchemaModel ParseSchema ( string content ) {
263263

264264
var globalMethods = new List<MethodModel> ();
265265
var globalDelegates = new List<MethodModel> ();
266-
var globalEvents = new List<MethodModel> ();
266+
var globalEvents = new List<EventModel> ();
267267
var globalOptions = new Dictionary<string, string> ();
268268
var version = "";
269269

@@ -301,6 +301,7 @@ public static SchemaModel ParseSchema ( string content ) {
301301
GlobalMethods = globalMethods,
302302
GlobalOptions = globalOptions,
303303
GlobalDelegates = globalDelegates,
304+
Events = globalEvents
304305
};
305306
}
306307

0 commit comments

Comments
 (0)