feat: refactor event API to use unique event names and remove NextEventId
This commit is contained in:
+1
-13
@@ -1,18 +1,6 @@
|
||||
/** 事件创建函数 @type {function(string,string):boolean} */
|
||||
const CallEvent = ll.import("GMLIB_API", "callCustomEvent");
|
||||
|
||||
/** 事件ID @type {number} */
|
||||
let NextEventId = 0;
|
||||
|
||||
/**
|
||||
* 获取事件ID标识名
|
||||
* @returns {string} 事件ID标识名
|
||||
*/
|
||||
function getNextEventId() {
|
||||
NextEventId++;
|
||||
return "GMLIB_Event_" + NextEventId;
|
||||
}
|
||||
|
||||
/** 事件类 */
|
||||
class Event {
|
||||
constructor() {
|
||||
@@ -26,7 +14,7 @@ class Event {
|
||||
* @returns {boolean} 是否创建成功
|
||||
*/
|
||||
static listen(event, callback) {
|
||||
let eventId = getNextEventId();
|
||||
let eventId = "GMLIB_Event_" + Math.random().toString(16).slice(2);
|
||||
ll.export(callback, event, eventId);
|
||||
let result = CallEvent(event, eventId);
|
||||
if (!result) {
|
||||
|
||||
Reference in New Issue
Block a user