Skip to content

Commit 58d7cac

Browse files
committed
Fixed generating classes in CS script
1 parent 03ec15c commit 58d7cac

File tree

3 files changed

+106
-20
lines changed

3 files changed

+106
-20
lines changed

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

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -188,35 +188,41 @@ function defineDelegate(method) {
188188
}
189189

190190
function defineEventClassProperties(event) {
191+
const lines = []
191192

193+
for (const method of event.Parameters) {
194+
lines.push(` public ${getInternalDataType(method.ParameterType)} ${method.Name} { get; set; }`);
195+
}
196+
197+
return lines.join('\n');
192198
}
193199

194200
function defineEventClass(event) {
195201
return `
196-
public class Event${event.Name} {
202+
public class Event${event.Name} {
197203
198-
private static int m_iterator = 0;
204+
private static int m_iterator = 0;
199205
200-
private static ConcurrentDictionary<int, EventClick1> m_notCompletedEvents = new ConcurrentDictionary<int, EventClick1> ();
206+
private static System.Collections.Concurrent.ConcurrentDictionary<int, Event${event.Name}> m_notCompletedEvents = new System.Collections.Concurrent.ConcurrentDictionary<int, Event${event.Name}> ();
201207
202-
${defineEventClassProperties(event)}
208+
${defineEventClassProperties(event)}
203209
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!" );
210+
public static Event${event.Name} CreateEvent () {
211+
var newEvent = new Event${event.Name} ();
212+
var index = Interlocked.Increment ( ref m_iterator );
213+
var completed = m_notCompletedEvents.TryAdd ( index, newEvent );
214+
if ( completed ) throw new Exception ( "Can't add new event to not completed list!" );
209215
210-
return newEvent;
211-
}
216+
return newEvent;
217+
}
212218
213-
public static void CompleteEvent ( int index ) {
214-
if ( !m_notCompletedEvents.ContainsKey ( index ) ) return;
219+
public static void CompleteEvent ( int index ) {
220+
if ( !m_notCompletedEvents.ContainsKey ( index ) ) return;
215221
216-
m_notCompletedEvents.TryRemove ( index, out var _ );
217-
}
222+
m_notCompletedEvents.TryRemove ( index, out var _ );
223+
}
218224
219-
}
225+
}
220226
`;
221227
}
222228

@@ -248,8 +254,10 @@ function defineFile(schema) {
248254
result += defineMethod(globalMethod);
249255
}
250256

251-
var eventClasses = schema.GlobalOptions["CsEventClass"] === "enabled";
252-
if (eventClasses) defineEventClasses(schema.Events);
257+
if (schema.GlobalOptions["CsEventClass"]) {
258+
var eventClasses = schema.GlobalOptions["CsEventClass"] === "enabled";
259+
if (eventClasses) result += defineEventClasses(schema.Events);
260+
}
253261

254262
result += defineEndFile();
255263

src/FlowBridgerTestLibrary/FlowBridger.cs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,5 +185,83 @@ public static void EventClick3CompleteGet ( int eventId ) {
185185

186186
public static partial void EventClick3CompleteGetInternal ( int eventId );
187187

188+
public class EventClick1 {
189+
190+
private static int m_iterator = 0;
191+
192+
private static System.Collections.Concurrent.ConcurrentDictionary<int, EventClick1> m_notCompletedEvents = new System.Collections.Concurrent.ConcurrentDictionary<int, EventClick1> ();
193+
194+
public int Order { get; set; }
195+
public string Name { get; set; }
196+
197+
public static EventClick1 CreateEvent () {
198+
var newEvent = new EventClick1 ();
199+
var index = Interlocked.Increment ( ref m_iterator );
200+
var completed = m_notCompletedEvents.TryAdd ( index, newEvent );
201+
if ( completed ) throw new Exception ( "Can't add new event to not completed list!" );
202+
203+
return newEvent;
204+
}
205+
206+
public static void CompleteEvent ( int index ) {
207+
if ( !m_notCompletedEvents.ContainsKey ( index ) ) return;
208+
209+
m_notCompletedEvents.TryRemove ( index, out var _ );
210+
}
211+
212+
}
213+
214+
public class EventClick2 {
215+
216+
private static int m_iterator = 0;
217+
218+
private static System.Collections.Concurrent.ConcurrentDictionary<int, EventClick2> m_notCompletedEvents = new System.Collections.Concurrent.ConcurrentDictionary<int, EventClick2> ();
219+
220+
public int Order { get; set; }
221+
public int Items { get; set; }
222+
223+
public static EventClick2 CreateEvent () {
224+
var newEvent = new EventClick2 ();
225+
var index = Interlocked.Increment ( ref m_iterator );
226+
var completed = m_notCompletedEvents.TryAdd ( index, newEvent );
227+
if ( completed ) throw new Exception ( "Can't add new event to not completed list!" );
228+
229+
return newEvent;
230+
}
231+
232+
public static void CompleteEvent ( int index ) {
233+
if ( !m_notCompletedEvents.ContainsKey ( index ) ) return;
234+
235+
m_notCompletedEvents.TryRemove ( index, out var _ );
236+
}
237+
238+
}
239+
240+
public class EventClick3 {
241+
242+
private static int m_iterator = 0;
243+
244+
private static System.Collections.Concurrent.ConcurrentDictionary<int, EventClick3> m_notCompletedEvents = new System.Collections.Concurrent.ConcurrentDictionary<int, EventClick3> ();
245+
246+
public int Order { get; set; }
247+
public int Items { get; set; }
248+
249+
public static EventClick3 CreateEvent () {
250+
var newEvent = new EventClick3 ();
251+
var index = Interlocked.Increment ( ref m_iterator );
252+
var completed = m_notCompletedEvents.TryAdd ( index, newEvent );
253+
if ( completed ) throw new Exception ( "Can't add new event to not completed list!" );
254+
255+
return newEvent;
256+
}
257+
258+
public static void CompleteEvent ( int index ) {
259+
if ( !m_notCompletedEvents.ContainsKey ( index ) ) return;
260+
261+
m_notCompletedEvents.TryRemove ( index, out var _ );
262+
}
263+
264+
}
265+
188266
}
189267
}

src/FlowBridgerTestLibrary/FlowBridgerExportsHelpers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static partial nint CallbackReturnMethodInternal () {
4949
delegate* unmanaged[Cdecl]< int, void > fp = &MyManagedCallback;
5050
return (nint) fp;
5151
}
52-
} catch(Exception e) {
52+
} catch ( Exception e ) {
5353
Console.WriteLine ( e.Message );
5454
return 0;
5555
}
@@ -72,7 +72,7 @@ public static partial void EventClick1CompleteSetInternal ( int eventId ) {
7272
}
7373

7474
public static partial int EventClick1GetOrderInternal ( int eventId ) {
75-
return 0;
75+
return 0;
7676
}
7777

7878
public static partial string EventClick1GetNameInternal ( int eventId ) {

0 commit comments

Comments
 (0)