| | |
| | | */ |
| | | demoEndedCallback: null |
| | | }, |
| | | callbacks: { |
| | | /** |
| | | * a callback in the game code to set the expected player volume. |
| | | * The callback takes a float parameter with a value between 0.0 and 1.0 |
| | | */ |
| | | setPlayerVolume: null, |
| | | /** |
| | | * a callback to set the fullscreen |
| | | */ |
| | | setPlayerFullscreen: null |
| | | }, |
| | | /** |
| | | * Attempts to call into the app to inform it that the volume should be adjusted |
| | | * @param volume the float volume (between 0.0 and 1.0) |
| | | * @return bool.. true if the callback was successful.. false if no callback registered |
| | | */ |
| | | setPlayerVolume: function(volume) { |
| | | if (HUMBLE_API.callbacks.setPlayerVolume == null) return false; |
| | | var cb = HUMBLE_API.callbacks.setPlayerVolume[0], |
| | | data = HUMBLE_API.callbacks.setPlayerVolume[1]; |
| | | if (volume > 1.0) volume = 1.0; |
| | | if (volume < 0.0) volume = 0.0; |
| | | Runtime.dynCall('vdi', cb, [volume, data]); |
| | | return true; |
| | | }, |
| | | /** |
| | | * Attempts to call into the app to inform it that it should change to or from fullscreen mode |
| | | * @param fullscreen A bool of either true or false |
| | | * @return bool.. true if the callback was successful.. false if no callback registered |
| | | */ |
| | | setPlayerFullscreen: function(fullscreen) { |
| | | if (HUMBLE_API.callbacks.setPlayerFullscreen == null) return false; |
| | | var cb = HUMBLE_API.callbacks.setPlayerFullscreen[0], |
| | | data = HUMBLE_API.callbacks.setPlayerFullscreen[1]; |
| | | Runtime.dynCall('vii', cb, [fullscreen ? 1 : 0, data]); |
| | | return true; |
| | | }, |
| | | /** |
| | | * allows configuring the HUMBLE_API simply call this method in a preRun to initialize.. |
| | | * any option is accepted and will be added to the configuration hash. |
| | |
| | | if (HUMBLE_API.options.demoEndedCallback) { |
| | | return HUMBLE_API.options.demoEndedCallback.call(HUMBLE_API); |
| | | } |
| | | } |
| | | }, |
| | | humble_set_callback__deps: ['$HUMBLE_API'], |
| | | humble_set_callback: function(type, cb, data) { |
| | | var key = null; |
| | | switch(type) { |
| | | case 1: key = 'setPlayerVolume'; break; |
| | | case 2: key = 'setPlayerFullscreen'; break; |
| | | } |
| | | if (key == null) { |
| | | return 0; |
| | | } |
| | | if (cb == 0) { |
| | | HUMBLE_API.callbacks[key] = null; |
| | | } else { |
| | | HUMBLE_API.callbacks[key] = [cb, data]; |
| | | } |
| | | return 1; |
| | | }, |
| | | }; |
| | | |
| | | mergeInto(LibraryManager.library, LibraryHUMBLE); |