MCPcopy
hub / github.com/4ian/GDevelop / Event

Class Event

Extensions/P2P/B_p2ptools.ts:63–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

61 * @category Other extensions > P2P
62 */
63 export class Event implements IEvent {
64 private readonly data: IEventData[] = [];
65 public dataloss = false;
66
67 /**
68 * Returns true if the event is triggered.
69 */
70 isTriggered() {
71 return this.data.length > 0;
72 }
73
74 /**
75 * Add new data, to be called with the event data each time the event is triggered.
76 */
77 pushData(newData: IEventData) {
78 if (this.dataloss && this.data.length > 0) this.data[0] = newData;
79 else this.data.push(newData);
80 }
81
82 /**
83 * Delete the last event data, to be called when it is sure the event was processed thoroughly.
84 */
85 popData() {
86 this.data.shift();
87 }
88
89 /**
90 * Get the data sent with the last event triggering.
91 */
92 getData() {
93 return this.data.length === 0 ? '' : this.data[0].data;
94 }
95
96 /**
97 * Get the sender of the last event triggering.
98 */
99 getSender() {
100 return this.data.length === 0 ? '' : this.data[0].sender;
101 }
102 }
103
104 /**
105 * The optional peer ID. Only used if explicitly overridden.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected