├── .gitignore
├── .idea
├── .name
└── jsLibraryMappings.xml
├── LICENSE
├── README.md
├── bin
├── flax-lite.min.js
└── flax.min.js
├── build.xml
├── graph.xmind
├── helloWorld
├── .cocos-project.json
├── flash
│ ├── flaxAnim.fla
│ └── flaxAnim.swf
├── index.html
├── main.js
├── project.json
├── res
│ ├── flaxAnim.plist
│ ├── flaxAnim.png
│ ├── logo.png
│ └── rotate.png
└── src
│ ├── HelloWorld.js
│ └── resource.js
├── logs
├── v1.8_cn.txt
└── v1.8_en.txt
└── src
└── flax
├── Flax.js
├── core
├── Animator.js
├── AssetsManager.js
├── Button.js
├── DebugDraw.js
├── FlaxLoader.js
├── FlaxSprite.js
├── Image.js
├── InputManager.js
├── Label.js
├── MovieClip.js
├── Physics.js
└── ProgressBar.js
├── game
├── Color.js
├── Gun.js
├── Gunner.js
├── LinkFinder.js
├── ObjectPool.js
├── Preloader.js
├── ScrollPane.js
├── ScrollingBG.js
├── SoundButton.js
├── TileMap.js
├── TiledImage.js
└── UserData.js
├── module
├── EnemyWaveModule.js
├── HealthModule.js
├── MoveModule.js
├── PhysicsModule.js
├── ScreenLayoutModule.js
└── TileMapModule.js
└── signal
├── Signal.js
├── SignalBinding.js
└── wrapper.js
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | .idea/encodings.xml
3 |
4 | .idea/Flax-js.iml
5 |
6 | .idea/misc.xml
7 |
8 | .idea/modules.xml
9 |
10 | .idea/scopes/scope_settings.xml
11 |
12 | .idea/vcs.xml
13 |
14 | .idea/workspace.xml
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | Flax-js
--------------------------------------------------------------------------------
/.idea/jsLibraryMappings.xml:
--------------------------------------------------------------------------------
1 |
2 |
IMPORTANT: Setting this property during a dispatch will only affect the next dispatch, if you want to stop the propagation of a signal use `halt()` instead.
62 | * @type boolean 63 | */ 64 | actived : true, 65 | 66 | /** 67 | * @param {Function} listener 68 | * @param {boolean} isOnce 69 | * @param {Object} [listenerContext] 70 | * @param {Number} [priority] 71 | * @return {SignalBinding} 72 | * @private 73 | */ 74 | _registerListener : function (listener, isOnce, listenerContext, priority) { 75 | 76 | var prevIndex = this._indexOfListener(listener, listenerContext), 77 | binding; 78 | 79 | if (prevIndex !== -1) { 80 | binding = this._bindings[prevIndex]; 81 | if (binding.isOnce() !== isOnce) { 82 | throw new Error('You cannot add'+ (isOnce? '' : 'Once') +'() then add'+ (!isOnce? '' : 'Once') +'() the same listener without removing the relationship first.'); 83 | } 84 | } else { 85 | binding = new SignalBinding(this, listener, isOnce, listenerContext, priority); 86 | this._addBinding(binding); 87 | } 88 | 89 | if(this.memorize && this._prevParams){ 90 | binding.execute(this._prevParams); 91 | } 92 | 93 | return binding; 94 | }, 95 | 96 | /** 97 | * @param {SignalBinding} binding 98 | * @private 99 | */ 100 | _addBinding : function (binding) { 101 | //simplified insertion sort 102 | var n = this._bindings.length; 103 | do { --n; } while (this._bindings[n] && binding._priority <= this._bindings[n]._priority); 104 | this._bindings.splice(n + 1, 0, binding); 105 | }, 106 | 107 | /** 108 | * @param {Function} listener 109 | * @param {Object} context 110 | * @return {number} 111 | * @private 112 | */ 113 | _indexOfListener : function (listener, context) { 114 | var n = this._bindings.length, 115 | cur; 116 | while (n--) { 117 | cur = this._bindings[n]; 118 | if (cur._listener === listener && cur.context === context) { 119 | return n; 120 | } 121 | } 122 | return -1; 123 | }, 124 | 125 | /** 126 | * Check if listener was attached to Signal. 127 | * @param {Function} listener 128 | * @param {Object} [context] 129 | * @return {boolean} if Signal has the specified listener. 130 | */ 131 | has : function (listener, context) { 132 | return this._indexOfListener(listener, context) !== -1; 133 | }, 134 | 135 | /** 136 | * Add a listener to the signal. 137 | * @param {Function} listener Signal handler function. 138 | * @param {Object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function). 139 | * @param {Number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0) 140 | * @return {SignalBinding} An Object representing the binding between the Signal and listener. 141 | */ 142 | add : function (listener, listenerContext, priority) { 143 | validateListener(listener, 'add'); 144 | return this._registerListener(listener, false, listenerContext, priority); 145 | }, 146 | 147 | /** 148 | * Add listener to the signal that should be removed after first execution (will be executed only once). 149 | * @param {Function} listener Signal handler function. 150 | * @param {Object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function). 151 | * @param {Number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0) 152 | * @return {SignalBinding} An Object representing the binding between the Signal and listener. 153 | */ 154 | addOnce : function (listener, listenerContext, priority) { 155 | validateListener(listener, 'addOnce'); 156 | return this._registerListener(listener, true, listenerContext, priority); 157 | }, 158 | 159 | /** 160 | * Remove a single listener from the dispatch queue. 161 | * @param {Function} listener Handler function that should be removed. 162 | * @param {Object} [context] Execution context (since you can add the same handler multiple times if executing in a different context). 163 | * @return {Function} Listener handler function. 164 | */ 165 | remove : function (listener, context) { 166 | validateListener(listener, 'remove'); 167 | 168 | var i = this._indexOfListener(listener, context); 169 | if (i !== -1) { 170 | this._bindings[i]._destroy(); //no reason to a SignalBinding exist if it isn't attached to a signal 171 | this._bindings.splice(i, 1); 172 | } 173 | return listener; 174 | }, 175 | 176 | /** 177 | * Remove all listeners from the Signal. 178 | */ 179 | removeAll : function () { 180 | var n = this._bindings.length; 181 | while (n--) { 182 | this._bindings[n]._destroy(); 183 | } 184 | this._bindings.length = 0; 185 | }, 186 | 187 | /** 188 | * @return {number} Number of listeners attached to the Signal. 189 | */ 190 | getNumListeners : function () { 191 | return this._bindings.length; 192 | }, 193 | 194 | /** 195 | * Stop propagation of the event, blocking the dispatch to next listeners on the queue. 196 | *IMPORTANT: should be called only during signal dispatch, calling it before/after dispatch won't affect signal broadcast.
197 | * @see Signal.prototype.disable 198 | */ 199 | halt : function () { 200 | this._shouldPropagate = false; 201 | }, 202 | 203 | /** 204 | * Dispatch/Broadcast Signal to all listeners added to the queue. 205 | * @param {...*} [params] Parameters that should be passed to each handler. 206 | */ 207 | dispatch : function (params) { 208 | if (! this.actived) { 209 | return; 210 | } 211 | 212 | var paramsArr = Array.prototype.slice.call(arguments), 213 | n = this._bindings.length, 214 | bindings; 215 | 216 | if (this.memorize) { 217 | this._prevParams = paramsArr; 218 | } 219 | if (! n) { 220 | //should come after memorize 221 | return; 222 | } 223 | 224 | bindings = this._bindings.slice(); //clone array in case add/remove items during dispatch 225 | this._shouldPropagate = true; //in case `halt` was called before dispatch or during the previous dispatch. 226 | 227 | //execute all callbacks until end of the list or until a callback returns `false` or stops propagation 228 | //reverse loop since listeners with higher priority will be added at the end of the list 229 | do { n--; } while (bindings[n] && this._shouldPropagate && bindings[n].execute(paramsArr) !== false); 230 | }, 231 | 232 | /** 233 | * Forget memorized arguments. 234 | * @see Signal.memorize 235 | */ 236 | forget : function(){ 237 | this._prevParams = null; 238 | }, 239 | 240 | /** 241 | * Remove all bindings from signal and destroy any reference to external objects (destroy Signal object). 242 | *IMPORTANT: calling any method on the signal instance after calling dispose will throw errors.
243 | */ 244 | dispose : function () { 245 | this.removeAll(); 246 | delete this._bindings; 247 | delete this._prevParams; 248 | }, 249 | 250 | /** 251 | * @return {string} String representation of the object. 252 | */ 253 | toString : function () { 254 | return '[Signal active:'+ this.actived +' numListeners:'+ this.getNumListeners() +']'; 255 | } 256 | 257 | }; 258 | 259 | 260 | // Namespace ----------------------------------------------------- 261 | //================================================================ 262 | 263 | /** 264 | * Signals namespace 265 | * @namespace 266 | * @name signals 267 | */ 268 | var signals = Signal; 269 | 270 | /** 271 | * Custom event broadcaster 272 | * @see Signal 273 | */ 274 | // alias for backwards compatibility (see #gh-44) 275 | signals.Signal = Signal; 276 | 277 | -------------------------------------------------------------------------------- /src/flax/signal/SignalBinding.js: -------------------------------------------------------------------------------- 1 | // SignalBinding ------------------------------------------------- 2 | //================================================================ 3 | 4 | /** 5 | * Object that represents a binding between a Signal and a listener function. 6 | *If binding was added using `Signal.addOnce()` it will be automatically removed from signal dispatch queue, this method is used internally for the signal dispatch.
74 | * @param {Array} [paramsArr] Array of parameters that should be passed to the listener 75 | * @return {*} Value returned by the listener. 76 | */ 77 | execute : function (paramsArr) { 78 | var handlerReturn, params; 79 | if (this.actived && !!this._listener) { 80 | params = this.params? this.params.concat(paramsArr) : paramsArr; 81 | handlerReturn = this._listener.apply(this.context, params); 82 | if (this._isOnce) { 83 | this.detach(); 84 | } 85 | } 86 | return handlerReturn; 87 | }, 88 | 89 | /** 90 | * Detach binding from signal. 91 | * - alias to: mySignal.remove(myBinding.getListener()); 92 | * @return {Function|null} Handler function bound to the signal or `null` if binding was previously detached. 93 | */ 94 | detach : function () { 95 | return this.isBound()? this._signal.remove(this._listener, this.context) : null; 96 | }, 97 | 98 | /** 99 | * @return {Boolean} `true` if binding is still bound to the signal and have a listener. 100 | */ 101 | isBound : function () { 102 | return (!!this._signal && !!this._listener); 103 | }, 104 | 105 | /** 106 | * @return {boolean} If SignalBinding will only be executed once. 107 | */ 108 | isOnce : function () { 109 | return this._isOnce; 110 | }, 111 | 112 | /** 113 | * @return {Function} Handler function bound to the signal. 114 | */ 115 | getListener : function () { 116 | return this._listener; 117 | }, 118 | 119 | /** 120 | * @return {Signal} Signal that listener is currently bound to. 121 | */ 122 | getSignal : function () { 123 | return this._signal; 124 | }, 125 | 126 | /** 127 | * Delete instance properties 128 | * @private 129 | */ 130 | _destroy : function () { 131 | delete this._signal; 132 | delete this._listener; 133 | delete this.context; 134 | }, 135 | 136 | /** 137 | * @return {string} String representation of the object. 138 | */ 139 | toString : function () { 140 | return '[SignalBinding isOnce:' + this._isOnce +', isBound:'+ this.isBound() +', actived:' + this.actived + ']'; 141 | } 142 | 143 | }; 144 | -------------------------------------------------------------------------------- /src/flax/signal/wrapper.js: -------------------------------------------------------------------------------- 1 | /*jslint onevar:true, undef:true, newcap:true, regexp:true, bitwise:true, maxerr:50, indent:4, white:false, nomen:false, plusplus:false */ 2 | /*global define:false, require:false, exports:false, module:false, signals:false */ 3 | 4 | //::LICENSE::// 5 | (function(global){ 6 | 7 | //::SIGNAL_BINDING_JS::// 8 | 9 | //::SIGNAL_JS::// 10 | 11 | //exports to multiple environments 12 | if(typeof define === 'function' && define.amd){ //AMD 13 | define(function () { return signals; }); 14 | } else if (typeof module !== 'undefined' && module.exports){ //node 15 | module.exports = signals; 16 | } else { //browser 17 | //use string because of Google closure compiler ADVANCED_MODE 18 | /*jslint sub:true */ 19 | global['signals'] = signals; 20 | } 21 | 22 | }(this)); 23 | --------------------------------------------------------------------------------