diff --git a/game/begin.coffee b/game/begin.coffee index 565776d..b810ac0 100644 --- a/game/begin.coffee +++ b/game/begin.coffee @@ -4,9 +4,7 @@ obj = require('../../lib/obj.coffee') dialogue = require('../../lib/dialogue.coffee') oneOf = require('../../lib/oneOf.coffee') require('../../lib/interface.coffee') -languages = require('../../lib/localize.coffee') undum = require('../../lib/undum.js') -undum.language = languages undum.game.id = "your-game-id-here" undum.game.version = "1.0" diff --git a/lib/interface.coffee b/lib/interface.coffee index 2c8a1be..db3a2de 100644 --- a/lib/interface.coffee +++ b/lib/interface.coffee @@ -11,7 +11,6 @@ $(document).ready(() -> event.preventDefault() ) $("#load").on("click", "a", (event) -> - event.preventDefault() window.location.reload() ) ) diff --git a/lib/localize.coffee b/lib/localize.coffee index 945bc89..be3694d 100644 --- a/lib/localize.coffee +++ b/lib/localize.coffee @@ -36,7 +36,7 @@ languageCodes = Object.keys(languages) localize = (languageCode, message) -> for thisCode in languageCodes - localized = languages[languageCode] + localized = languages[languageCode][message] if localized return localized return message diff --git a/lib/undum.js b/lib/undum.js index 864369b..29cd26b 100644 --- a/lib/undum.js +++ b/lib/undum.js @@ -5,7 +5,8 @@ // Version: 3.2.0-oreolek // --------------------------------------------------------------------------- -var Random = require('./random.js') +var Random = require('./random.js'); +var languages = require('./localize.coffee'); // --------------------------------------------------------------------------- // Infrastructure implementations @@ -55,13 +56,6 @@ var hasLocalStorage = function() { return hasStorage; }; -var isMobileDevice = function() { - /* User agent detection is unreliable and evil. If your screen is less - than 700 pixels wide, we'll give you the mobile interface. This may be - less than ideal with Retina displays, however, so FIXME? */ - return $("html").width() <= 700; -}; - // Assertion var AssertionError = function(message) { @@ -1108,9 +1102,6 @@ var character = null; /* Tracks whether we're in interactive mode or batch mode. */ var interactive = true; -/* Tracks whether we're mobile or not. */ -var mobile = isMobileDevice(); - /* The system time when the game was initialized. */ var startTime; @@ -1330,7 +1321,6 @@ var endOutputTransaction = function () { newTop, newBottom, newHeight, optionHeight = 0; if ($new.length === 0) return; /* Somehow, there's nothing new. */ - if (isMobileDevice()) return; newTop = $new.first().offset().top, newBottom = $new.last().offset().top + $new.last().height(), @@ -1394,7 +1384,6 @@ var processLink = function(code) { endOutputTransaction(); // We're able to save, if we weren't already. - $("#save").attr('disabled', false); $("#save").removeClass('disabled'); }; @@ -1483,15 +1472,11 @@ var doTransitionTo = function(newSituationId) { return $(this).attr("href").match(/[?&]transient[=&]?/); })); if (interactive) { - if (mobile) { - contentToHide.fadeOut(2000); - } else { - contentToHide. + contentToHide. animate({opacity: 0}, 350). slideUp(500, function() { $(this).remove(); }); - } } else { contentToHide.remove(); } @@ -1551,11 +1536,10 @@ var augmentLinks = function(content) { /* no longer has to be the end-all be-all repository of game state. */ var doErase = function(force) { var saveId = getSaveId(); - if (localStorage[saveId]) { + if (localStorage.getItem(saveId)) { if (force || confirm("erase_message".l())) { - delete localStorage[saveId]; + localStorage.removeItem(saveId); window.location.reload(); - } } }; @@ -1617,13 +1601,11 @@ var saveGame = function() { progress.saveTime = now - startTime; // Save the game. - localStorage[getSaveId()] = JSON.stringify(progress); + localStorage.setItem(getSaveId(), JSON.stringify(progress)); // Switch the button highlights. - $("#erase").attr('disabled', false); $("#erase").removeClass('disabled'); $("#load").removeClass('disabled'); - $("#save").attr('disabled', true); $("#save").addClass('disabled'); }; @@ -1675,42 +1657,21 @@ var begin = function () { }); var save = $("#save").click(saveGame); - var storedCharacter = localStorage[getSaveId()]; - console.log(storedCharacter) + var storedCharacter = localStorage.getItem(getSaveId()); if (storedCharacter) { try { loadGame(JSON.parse(storedCharacter)); - save.attr('disabled', true); - erase.attr("disabled", false); + save.addClass('disabled') + erase.removeClass('disabled') } catch(err) { doErase(true); } } else { - save.attr('disabled', true); - erase.attr("disabled", true); startGame(); } } else { - $(".buttons").html("

"+"no_local_storage".l()+"

"); startGame(); } - - // Display the "click to begin" message. (We do this in code - // so that, if Javascript is off, it doesn't happen.) - $(".click_message").show(); - - // Show the game when we click on the title. - $("#title").one('click', function() { - $("#content_wrapper, #legal").fadeIn(500); - $("#tools_wrapper").fadeIn(2000); - $("#title").css("cursor", "default"); - $("#title .click_message").fadeOut(250); - if (mobile) { - $("#toolbar").slideDown(500); - $("#menu").show(); - } - }); - // Any point that an option list appears, its options are its // first links. $("body").on('click', "ul.options li, #menu li", function(event) { @@ -1720,98 +1681,6 @@ var begin = function () { $(link.get(0)).click(); } }); - - // Switch between the two UIs as we resize. - var resize = function() { - // Work out if we're mobile or not. - var wasMobile = mobile; - mobile = isMobileDevice(); - - if (wasMobile != mobile) { - var showing = !$(".click_message").is(":visible"); - if (mobile) { - var menu = $("#menu"); - if (showing) { - $("#toolbar").show(); - menu.show(); - } - menu.css('top', -menu.height()-52); - // Go to the story view. - $("#character_panel, #info_panel").hide(); - } else { - // Use the full width version - $("#toolbar").hide(); - $("#menu").hide(); - if (showing) { - // Display the side bars - $("#tools_wrapper").show(); - } - $("#character_panel, #info_panel").show(); - } - $("#title").show(); - if (showing) $("#content_wrapper").show(); - } - }; - $(window).bind('resize', resize); - resize(); - - // Handle display of the menu and resizing: used on mobile - // devices and an small screens. - initMenu(); -}; - -var initMenu = function() { - var menu = $("#menu"); - - var menuVisible = false; - var open = function() { - menu.animate({top:48}, 500); - menuVisible = true; - }; - var close = function() { - menu.animate({top:-menu.height()-52}, 250); - menuVisible = false; - }; - menu.css('top', -menu.height()-52); - - // Slide up and down on clicks from the main button. - $("#menu-button").click(function(event) { - event.preventDefault(); - event.stopPropagation(); - if (menuVisible) { - close(); - } else { - open(); - } - return false; - }); - - // Register for clicks on the individual menu items: show the - // relevant item. - $("#menu a").click(function(event) { - event.preventDefault(); - event.stopPropagation(); - var target = $($(this).attr('href')); - if (!target.is(":visible")) { - // Fade out those we don't want. - $("#menu a").each(function() { - var href = $(this).attr('href'); - if (href != target) { - $(href).fadeOut(250); - } - }); - // Fade in our target - setTimeout(function() { - target.fadeIn(500); - if (target.is('#content_wrapper') && $('.new').length) { - /* Put the newest content into view if possible */ - window.scrollTo(0, $('.new').first().offset().top - 500); - } - }, 250); - } - close(); - return false; - }); }; /* Export our API. */ @@ -1833,6 +1702,8 @@ module.exports = { game: game, begin: begin, + language: languages, + processClick: processClick, // you need this if you want to have some additional link blocks isInteractive: function() { return interactive; },