/* Built at: Tue Aug 19 2014 00:16:15 GMT+0200 (CEST) */ /** * @namespace JawsJS core functions. * * Jaws, a HTML5 canvas/javascript 2D game development framework * * Homepage: http://jawsjs.com/ * Source: http://github.com/ippa/jaws/ * Documentation: http://jawsjs.com/docs/ * * Works with: Chrome 6.0+, Firefox 3.6+, 4+, IE 9+ * License: LGPL - http://www.gnu.org/licenses/lgpl.html * * Jaws uses the "module pattern". * Adds 1 global, jaws, so plays nice with all other JS libs. * * Formating guide: * jaws.oneFunction() * jaws.one_variable = 1 * new jaws.OneConstructor * * @property {int} mouse_x Mouse X position with respect to the canvas-element * @property {int} mouse_y Mouse Y position with respect to the canvas-element * @property {canvas} canvas The detected/created canvas-element used for the game * @property {context} context The detected/created canvas 2D-context, used for all draw-operations * @property {int} width Width of the canvas-element * @property {int} height Height of the canvas-element */ var jaws = (function(jaws) { var title; var log_tag; /* * Placeholders for constructors in extras-dir. We define the constructors here to be able to give ppl better error-msgs. * When the correct from extras-dir is included, these will be overwritten. * */ //jaws.Parallax = function() { throw("To use jaws.Parallax() you need to include src/extras/parallax.js") } //jaws.QuadTree = function() { throw("To use QuadTree() you need to include src/extras/quadtree.js") } //jaws.PixelMap = function() { throw("To use PixelMap() you need to include src/extras/pixel_map.js") } //jaws.TileMap = function() { throw("To use TileMap() you need to include src/extras/tile_map.js") } jaws.SpriteList = function() { throw("To use SpriteList() you need to include src/extras/sprite_list.js") } jaws.Audio = function() { throw("To use jaws.Audio() you need to include src/extras/audio.js") } /** * Returns or sets contents of title's innerHTML * @private * @param {type} value The new value to set the innerHTML of title * @returns {string} The innerHTML of title */ jaws.title = function(value) { if (!jaws.isString(value)) { jaws.log.error("jaws.title: Passed in value is not a String."); return; } if (value) { return (title.innerHTML = value); } return title.innerHTML; }; /** * Unpacks Jaws core-constructors into the global namespace. * If a global property is already taken, a warning will be written to jaws log. */ jaws.unpack = function() { var make_global = ["Sprite", "SpriteList", "Animation", "Viewport", "SpriteSheet", "Parallax", "TileMap", "pressed", "QuadTree"]; make_global.forEach(function(item) { if (window[item]) { jaws.log.warn("jaws.unpack: " + item + " already exists in global namespace."); } else { window[item] = jaws[item]; } }); }; /** * Writes messages to either log_tag (if set) or console.log (if available) * @param {string} msg The string to write * @param {boolean} append If messages should be appended or not */ jaws.log = function(msg, append) { if (!jaws.isString(msg)) { msg = JSON.stringify(msg); } if (jaws.log.on) { if (log_tag && jaws.log.use_log_element) { if (append) { log_tag.innerHTML += msg + ""; } else { log_tag.innerHTML = msg; } } if (console.log && jaws.log.use_console) { console.log("JawsJS: ", msg); } } }; /** * If logging should take place or not * @type {boolean} */ jaws.log.on = true; /** * If console.log should be used during log writing * @type {boolean} */ jaws.log.use_console = false; /** * If log_tag should be used during log writing * @type {boolean} */ jaws.log.use_log_element = true; /** * Write messages to console.warn (if it exists) or append current log * @param {string|object} msg String or object to record * @see jaws.log */ jaws.log.warn = function(msg) { if (console.warn && jaws.log.use_console && jaws.log.on) { console.warn(msg); } else { jaws.log("[WARNING]: " + JSON.stringify(msg), true); } }; /** * Write messages to console.error (if it exists) or append current log * @param {string|object} msg String or object to record * @see jaws.log */ jaws.log.error = function(msg) { if (console.error && jaws.log.use_console && jaws.log.on) { console.error(msg); } else { jaws.log("[ERROR]: " + JSON.stringify(msg), true); } }; /** * Write messages to console.info (if it exists) or append current log * @param {string|object} msg String or object to record * @see jaws.log */ jaws.log.info = function(msg) { if (console.info && jaws.log.use_console && jaws.log.on) { console.info(msg); } else { jaws.log("[INFO]: " + JSON.stringify(msg), true); } }; /** * Write messages to console.debug (if it exists) or append current log * @param {string|object} msg String or object to record * @see jaws.log */ jaws.log.debug = function(msg) { if (console.debug && jaws.log.use_console && jaws.log.on) { console.debug(msg); } else { jaws.log("[DEBUG]: " + JSON.stringify(msg), true); } }; /** * Clears the contents of log_tag element (if set) and console.log (if set) */ jaws.log.clear = function() { if (log_tag) { log_tag.innerHTML = ""; } if (console.clear) { console.clear(); } }; /** * Initalizes jaws{canvas, context, dom, width, height} * @private * @param {object} options Object-literal of constructor properties * @see jaws.url_parameters() */ jaws.init = function(options) { /* Find