-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventscontext.js
83 lines (74 loc) · 2.18 KB
/
eventscontext.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* GDevelop JS Platform
* Copyright 2013-2015 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
*/
/**
* EventsContext contains specific tools and data structures used
* by events generated code only.
*
* @namespace gdjs
* @class EventsContext
* @constructor
*/
gdjs.EventsContext = function()
{
if (this._eventsObjectsMap !== undefined) this._eventsObjectsMap.clear();
else this._eventsObjectsMap = new Hashtable();
this._onceTriggers = {};
this._lastFrameOnceTrigger = {};
};
/**
* To be called when events begin so that "Trigger once" conditions
* are properly handled.
* @method startNewFrame
*/
gdjs.EventsContext.prototype.startNewFrame = function() {
this.clearObject(this._lastFrameOnceTrigger);
for (var k in this._onceTriggers) {
if (this._onceTriggers.hasOwnProperty(k)) {
this._lastFrameOnceTrigger[k] = this._onceTriggers[k];
delete this._onceTriggers[k];
}
}
};
/**
* Used by "Trigger once" conditions: Return true only if
* this method was not called with the same identifier during the last frame.
* @param triggerId The identifier of the "Trigger once" condition.
* @method triggerOnce
*/
gdjs.EventsContext.prototype.triggerOnce = function(triggerId) {
this._onceTriggers[triggerId] = true;
return !this._lastFrameOnceTrigger.hasOwnProperty(triggerId);
};
gdjs.EventsContext.prototype.clearObject = function(obj) {
for (var k in obj) {
if (obj.hasOwnProperty(k)) {
delete obj[k];
}
}
};
/**
* Clear the map containing objects lists.
* @method clearEventsObjectsMap
*/
gdjs.EventsContext.prototype.clearEventsObjectsMap = function() {
this._eventsObjectsMap.clear();
return this;
};
/**
* Add an objects list to the objects lists map.
* @method addObjectsToEventsMap
*/
gdjs.EventsContext.prototype.addObjectsToEventsMap = function(name, objectList) {
this._eventsObjectsMap.put(name, objectList);
return this;
};
/**
* Return the objects lists map.
* @method getEventsObjectsMap
*/
gdjs.EventsContext.prototype.getEventsObjectsMap = function() {
return this._eventsObjectsMap.clone();
};