From 0c4867ccd914edef4da4a4b2394c991a9eea7aca Mon Sep 17 00:00:00 2001 From: Gregg Tavares Date: Sun, 16 Nov 2014 23:32:18 -0800 Subject: [PATCH] add setStats, log, and error to CommonUI --- docs/api-versions.md | 6 ++++ hft.hanson | 2 +- public/hft/0.x.x/scripts/commonui.js | 48 ++++++++++++++++++++++++++-- todo.md | 1 + 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/docs/api-versions.md b/docs/api-versions.md index 4582cf17..25be714b 100644 --- a/docs/api-versions.md +++ b/docs/api-versions.md @@ -263,4 +263,10 @@ the correct version handle this in CSS so we needed a way to check for a specific phone and change the CSS programatically. +* v1.6.0 + + * CommonUI.setStatus, CommonUI.log, CommonUI.error + + These work the same as the corresponding GameSupport functions + except for the controller. diff --git a/hft.hanson b/hft.hanson index f62ef3ab..2dbf07e1 100644 --- a/hft.hanson +++ b/hft.hanson @@ -37,7 +37,7 @@ game: "templates/0.x.x/game.gameview.html", }, }, - "1.5.0": { + "1.6.0": { templates: { controller: "templates/0.x.x/controller.index.html", game: "templates/0.x.x/game.gameview.html", diff --git a/public/hft/0.x.x/scripts/commonui.js b/public/hft/0.x.x/scripts/commonui.js index 2f59c17d..e7deb9f4 100644 --- a/public/hft/0.x.x/scripts/commonui.js +++ b/public/hft/0.x.x/scripts/commonui.js @@ -40,6 +40,7 @@ define([ './hft-splash', './hft-system', './misc/fullscreen', + './misc/logger', './misc/misc', './misc/playername', ], function( @@ -47,6 +48,7 @@ define([ HFTSplash, HFTSystem, FullScreen, + Logger, Misc, PlayerNameHandler) { @@ -54,6 +56,10 @@ define([ return document.getElementById(id); }; + var g = { + logger: new Logger.NullLogger(), + }; + /** * @typedef {Object} ControllerUI~Options * @property {callback?} function to call when controller @@ -62,6 +68,7 @@ define([ * disconncted from game. * @property {boolean?} debug True displays a status and debug * html element + * @property {number?} numConsoleLines number of lines to show for the debug console. * @memberOf module:CommonUI */ @@ -185,14 +192,51 @@ define([ }); if (options.debug) { - var statusNode = document.createTextNode(""); - $("hft-status").appendChild(statusNode); + g.statusNode = document.createTextNode(""); + $("hft-status").appendChild(g.statusNode); var debugCSS = Misc.findCSSStyleRule("#hft-debug"); debugCSS.style.display = "block"; + + g.logger = new Logger.HTMLLogger($("hft-console"), options.numConsoleLines); + } + }; + + /** + * Sets the content of the status element. Only visible of debug + * is true. + * @memberOf module:CommonUI + * @param {string} str value to set the status + */ + var setStatus = function(msg) { + if (g.statusNode) { + g.statusNode.nodeValue = msg; } }; + /** + * Logs a msg to the HTML based console that is only visible + * when debug = true. + * @memberOf module:CommonUI + * @param {string} str msg to add to log + */ + var log = function(str) { + g.logger.log(str); + }; + + /** + * Logs an error to the HTML based console that is only visible + * when debug = true. + * @memberOf module:CommonUI + * @param {string} str msg to add to log + */ + var error = function(str) { + g.logger.error(str); + }; + return { + log: log, + error: error, + setStatus: setStatus, setupStandardControllerUI: setupStandardControllerUI, }; }); diff --git a/todo.md b/todo.md index 2b05dd01..9e4c5c68 100644 --- a/todo.md +++ b/todo.md @@ -1,6 +1,7 @@ To Do ===== +* figure out err msg for un-added games. As it is controllers just get JS errors. * move tiled support to hft-tiled? * add tiled support to jumpjump * add glow processing to powpow?