var selectSizeWithoutStatus = 8;
var selectSizeWithStatus = 6;
var numCommands = 0;
var thisCommand = 0;
var commandsList = new Array();
var tmrTick = null;
var tickCount = 0;
var sendNextGameTickerAfter = 0;
var verbButtonCount = 9;
var commandLog = null;
//JS
var is_asl_event=false;
function init() {
var smusic = getStorage("music");
if (smusic===null)
$("#soundMenu").modal({backdrop: 'static',keyboard: false});
else
init2(null);
}
function init2(sound) {
if (sound) {
setStorage("music","on");
music_on=true;
} else if (sound===false) {
setStorage("music","off");
music_on=false;
}
showStatusVisible(false);
$("#button-restart").button().click(function () {
$("#button-restart").removeClass("ui-state-focus ui-state-hover");
uiDoRestart();
});
$("#button-undo").button().click(function () {
$("#button-undo").removeClass("ui-state-focus ui-state-hover");
uiDoUndo();
});
$("#button-wait").button().click(function () {
$("#button-wait").removeClass("ui-state-focus ui-state-hover");
uiDoWait();
});
$("#button-options").button().click(function () {
$("#button-options").removeClass("ui-state-focus ui-state-hover");
$("#gameMore").hide();
$("#gameOptions").show();
});
$("#fontOptions").change(function () {
var newFont = $("#fontOptions option:selected").text();
$("#divOutput div span").css("font-family", newFont);
$("#fontSample").css("font-family", newFont);
currentFont = newFont;
set(GetObject("game"), "defaultfont", newFont);
saveGame();
});
$("#fontSize").change(function () {
var newFontSize = $("#fontSize option:selected").val();
$("#divOutput div span").css("font-size", newFontSize + "pt");
$("#fontSample").css("font-size", newFontSize + "pt");
currentFontSize = newFontSize;
set(GetObject("game"), "defaultfontsize", parseInt(newFontSize));
saveGame();
});
$(document).on("click", ".elementmenu", function (event) {
if (!$(this).hasClass("disabled")) {
event.preventDefault();
event.stopPropagation();
// TO DO
//$(this).jjmenu_popup();
bindMenuEl($(this));
//--
$(this).click();
//--
//$(this).blur();
return false;
}
});
$(document).on("click", ".exitlink", function () {
if (!$(this).hasClass("disabled")) {
sendCommand($(this).data("command"));
}
});
$(document).on("click", ".commandlink", function () {
var $this = $(this);
if (!$this.hasClass("disabled") && canSendCommand) {
if ($this.data("deactivateonclick")) {
$this.addClass("disabled");
$this.data("deactivated", true);
}
sendCommand($this.data("command"));
}
});
worldmodelInitialise();
if (!loadGame_()) {
worldModelBeginGame();
}
}
function extLink(url) {
window.open(url, "_system");
}
function showStatusVisible(visible) {
if (visible) {
$("#statusVars").show();
$("#statusLabel").show();
}
else {
$("#statusVars").hide();
$("#statusLabel").hide();
}
}
var beginningOfCurrentTurnScrollPosition = 0;
var scrollTimeout = null;
function scrollToEnd() {
if (scrollTimeout != null) {
clearTimeout(scrollTimeout);
}
scrollTimeout = setTimeout(function () {
scrollTimeout = null;
scrollToEndNow();
}, 200);
}
function scrollToEndNow() {
$('html, body').animate({ scrollTop: beginningOfCurrentTurnScrollPosition - 30 }, 200);
}
function updateLocation(text) {
}
var _waitMode = false;
var _pauseMode = false;
var _waitingForSoundToFinish = false;
var waitButtonId = 0;
function beginWait() {
if (runningWalkthrough) {
awaitingCallback = false;
waitCallback();
TryFinishTurn();
return;
}
_waitMode = true;
waitButtonId++;
addText("Continue...
");
$("#waitButton" + waitButtonId).click(function () {
_waitMode = false;
$(this).hide();
$("#divCommand").show();
beginningOfCurrentTurnScrollPosition = $("#gameContent").height();
window.setTimeout(function () {
awaitingCallback = false;
waitCallback();
TryFinishTurn();
}, 100);
});
$("#divCommand").hide();
}
function beginPause(ms) {
_pauseMode = true;
$("#divCommand").hide();
window.setTimeout(function () {
endPause()
}, ms);
}
function endPause() {
_pauseMode = false;
$("#divCommand").show();
window.setTimeout(function () {
// TO DO
//$("#fldUIMsg").val("endpause");
//$("#cmdSubmit").click();
}, 100);
}
function globalKey(e) {
if (_waitMode) {
endWait();
return;
}
}
function commandKey(e) {
switch (keyPressCode(e)) {
case 13:
runCommand();
return false;
case 38:
thisCommand--;
if (thisCommand == 0) thisCommand = numCommands;
$("#txtCommand").val(commandsList[thisCommand]);
break;
case 40:
thisCommand++;
if (thisCommand > numCommands) thisCommand = 1;
$("#txtCommand").val(commandsList[thisCommand]);
break;
case 27:
thisCommand = numCommands + 1;
$("#txtCommand").val("");
break;
}
}
function runCommand() {
var command = $("#txtCommand").val();
if (command.length > 0) {
numCommands++;
commandsList[numCommands] = command;
thisCommand = numCommands + 1;
sendCommand(command);
$("#txtCommand").val("");
}
}
function prepareCommand(command) {
// TO DO
//$("#fldUITickCount").val(getTickCountAndStopTimer());
//$("#fldUIMsg").val("command " + command);
}
function showQuestion(title) {
$("#msgboxCaption").html(title);
var msgboxOptions = {
modal: true,
autoOpen: false,
buttons: [
{
text: "Yes",
click: function () { msgboxSubmit("yes"); }
},
{
text: "No",
click: function () { msgboxSubmit("no"); }
}
],
closeOnEscape: false,
open: function (event, ui) { $(".ui-dialog-titlebar-close").hide(); } // suppresses "close" button
};
$("#msgbox").dialog(msgboxOptions);
$("#msgbox").dialog("open");
}
function msgboxSubmit(text) {
$("#msgbox").dialog("close");
window.setTimeout(function () {
// TO DO
//$("#fldUIMsg").val("msgbox " + text);
//$("#cmdSubmit").click();
}, 100);
}
var _menuSelection = "";
function showMenu(title, options, allowCancel) {
$("#dialogOptions").empty();
$.each(options, function (key, value) {
$("#dialogOptions").append(
$("").attr("value", key).text(value)
);
});
$("#dialogCaption").html(title);
var dialogOptions = {
modal: true,
autoOpen: false,
buttons: [{
text: "Select",
click: function () { dialogSelect(); }
}]
};
if (allowCancel) {
dialogOptions.buttons = dialogOptions.buttons.concat([{
text: "Cancel",
click: function () { dialogCancel(); }
}]);
dialogOptions.close = function (event, ui) { dialogClose(); };
}
else {
dialogOptions.closeOnEscape = false;
dialogOptions.open = function (event, ui) { $(".ui-dialog-titlebar-close").hide(); }; // suppresses "close" button
}
_menuSelection = "";
$("#dialog").dialog(dialogOptions);
$("#dialog").dialog("open");
}
function dialogSelect() {
_menuSelection = $("#dialogOptions").val();
if (_menuSelection.length > 0) {
$("#dialog").dialog("close");
window.setTimeout(function () {
SetMenuSelection(_menuSelection);
updateLists();
}, 100);
}
}
function dialogCancel() {
$("#dialog").dialog("close");
}
function dialogClose() {
if (_menuSelection.length == 0) {
dialogSendCancel();
}
}
function dialogSendCancel() {
window.setTimeout(function () {
// TO DO
//$("#fldUIMsg").val("choicecancel");
//$("#cmdSubmit").click();
}, 100);
}
function sessionTimeout() {
disableInterface();
}
function gameFinished() {
disableInterface();
}
function disableInterface() {
$("#divCommand").hide();
$("#gamePanesRunning").hide();
$("#gamePanesFinished").show();
}
function playWav(filename, sync, looped) {
}
function playMp3(filename, sync, looped) {
playAudio(filename, "mp3", sync, looped);
}
function playAudio(filename, format, sync, looped) {
//TODO: parameters
if (music_on) {
new Audio(filename).play();
}
}
function stopAudio() {
}
function finishSync() {
_waitingForSoundToFinish = false;
window.setTimeout(function () {
$("#divCommand").show();
$("#fldUIMsg").val("endwait");
$("#cmdSubmit").click();
}, 100);
}
function panesVisible(visible) {
if (visible) {
$("#gamePanes").show();
}
else {
$("#gamePanes").hide();
}
}
function uiShow(element) {
if (element == "") return;
$(element).show();
}
function uiHide(element) {
if (element == "") return;
$(element).hide();
}
var _compassDirs = ["northwest", "north", "northeast", "west", "east", "southwest", "south", "southeast", "up", "down", "in", "out"];
var lastPaneLinkId = 0;
function updateList(listName, listData) {
var listElement = "";
var emptyListLabel = "";
if (listName == "inventory") {
listElement = "#inventoryList";
emptyListLabel = "#inventoryEmpty";
}
if (listName == "placesobjects") {
listElement = "#objectsList";
emptyListLabel = "#placesObjectsEmpty";
}
$(listElement).empty();
$(listElement).show();
var listcount = 0;
var anyItem = false;
$.each(listData, function (key, value) {
var splitString = value.split(":");
var objectDisplayName = splitString[0];
var objectVerbs = splitString[1];
if (listName == "inventory" || $.inArray(objectDisplayName, _compassDirs) == -1) {
listcount++;
lastPaneLinkId++;
var paneLinkId = "paneLink" + lastPaneLinkId;
$(listElement).append(
"
" + objectDisplayName + ""
);
bindMenu(paneLinkId, objectVerbs, objectDisplayName, false);
anyItem = true;
}
});
$(listElement + " li:last-child").addClass('last-child')
if (listcount == 0) $(listElement).hide();
if (anyItem) {
$(emptyListLabel).hide();
}
else {
$(emptyListLabel).show();
}
}
function updateCompass(directions) {
updateDir(directions, "NW", _compassDirs[0]);
updateDir(directions, "N", _compassDirs[1]);
updateDir(directions, "NE", _compassDirs[2]);
updateDir(directions, "W", _compassDirs[3]);
updateDir(directions, "E", _compassDirs[4]);
updateDir(directions, "SW", _compassDirs[5]);
updateDir(directions, "S", _compassDirs[6]);
updateDir(directions, "SE", _compassDirs[7]);
updateDir(directions, "U", _compassDirs[8]);
updateDir(directions, "D", _compassDirs[9]);
updateDir(directions, "In", _compassDirs[10]);
updateDir(directions, "Out", _compassDirs[11]);
}
function updateDir(directions, label, dir) {
$("#cmdCompass" + label).attr("disabled", $.inArray(dir, directions) == -1);
}
function compassClick(direction) {
sendCommand(direction);
}
function sendCommand(text) {
if (!gameRunning) return;
//JS
if (e_start.cmds.length%50==0)
clearPast(150)
//--
if (awaitingInputCallback) {
awaitingInputCallback = false;
awaitingCallback = false;
//JS
if (e_start.record) {
listadd (e_start.cmds, "%"+text);
}
//--
getinputCallback(text);
TryFinishTurn();
return;
}
if (awaitingCallback) return;
beginningOfCurrentTurnScrollPosition = $("#gameContent").height();
if (_pauseMode || _waitingForSoundToFinish) return;
if (_waitMode) {
endWait();
return;
}
window.setTimeout(function () {
// TO DO - send tick count
//prepareCommand(text);
if (text.substring(0, 6) == "cheat ") {
runCheatCode(text.substring(6));
}
else {
sendCommandInternal(text);
}
}, 100);
}
function sendCommandInternal(command) {
var start = (new Date).getTime();
addToCommandLog(command);
HandleCommand(command);
var diff = (new Date).getTime() - start;
TryFinishTurn();
}
function addToCommandLog(command) {
if (commandLog == null) {
commandLog = new Array();
}
commandLog.push(command);
}
function runCheatCode(code) {
var walkthrough = window["object_main"];
if (walkthrough.steps.indexOf("label:" + code) > -1) {
runWalkthrough("main", 0, 0, code);
}
else {
sendCommandInternal("cheat " + code);
}
}
function generateSaveLog(fn) {
var gameElementArray = new Array();
gameElementArray.push(GetObject("game"));
generateSaveLogForArray(gameElementArray, fn);
generateSaveLogForArray(allObjects, fn);
generateSaveLogForArray(allExits, fn);
generateSaveLogForArray(allCommands, fn);
generateSaveLogForArray(allTurnScripts, fn);
generateSaveLogForArray(allTimers, fn);
thisTurnModifiedItems = new Array();
}
function generateSaveLogForArray(array, fn) {
for (var idx in array) {
var object = array[idx];
var attrs = object["__modified"];
if (attrs != undefined) {
for (var attrIdx in attrs) {
var attr = attrs[attrIdx];
fn(object, attr, object[attr]);
}
}
for (var attr in object) {
var value = object[attr];
if (typeof value === "object") {
for (var idx in thisTurnModifiedItems) {
var item = thisTurnModifiedItems[idx];
if (value === item) {
markAttributeModified(object, attr);
fn(object, attr, value);
break;
}
}
}
}
}
}
function saveGame() {
return;
if (!gameRunning) return;
if (awaitingCallback) return;
if (runningWalkthrough) return;
setTimeout(function () {
var start = (new Date).getTime();
saveGameInternal();
var diff = (new Date).getTime() - start;
}, 250);
}
function saveGameInternal() {
if (!gameRunning) return;
if (awaitingCallback) return;
if (!localStorage) return;
try {
localStorageTransactionId = localStorage.getItem("transaction");
if (localStorageTransactionId == undefined) {
localStorageTransactionId = 1;
}
else {
localStorageTransactionId = 3 - localStorageTransactionId;
}
localStorageSet("output", allOutput);
localStorageSet("output2", $("#divOutput").html());
localStorageSet("divCount", _divCount);
if (commandLog != null) {
localStorageSet("commandLog", commandLog.join(";"));
}
localStorageSet("nextObjectId", nextObjectId);
// Save all object creations
var createId = 0;
for (var idx in createdObjects) {
createId++;
localStorageSet("create" + createId, createdObjects[idx]);
}
localStorageSet("numCreates", createId);
// Save all object type additions
var addTypeId = 0;
for (var idx in addedTypes) {
addTypeId++;
localStorageSet("addtype" + addTypeId, addedTypes[idx]);
}
localStorageSet("numAddTypes", addTypeId);
// Save all object attribute changes
var changeId = 0;
generateSaveLog(function (object, attribute, value) {
var valueType = TypeOf(value);
if (object.name == "player" && StartsWith(attribute, "currentcommand")) return;
changeId++;
var key = "change" + changeId;
var storeValue = value;
switch (valueType) {
case "stringlist":
storeValue = value.length;
var count = 0;
for (var idx in value) {
localStorageSet(key + "_" + count, value[idx]);
count++;
}
break;
case "objectlist":
storeValue = value.length;
var count = 0;
for (var idx in value) {
localStorageSet(key + "_" + count, value[idx]._js_name);
count++;
}
break;
case "stringdictionary":
case "scriptdictionary":
var count = 0;
for (var dictKey in value) {
localStorageSet(key + "_k" + count, dictKey);
localStorageSet(key + "_v" + count, value[dictKey]);
count++;
}
storeValue = count;
break;
case "objectdictionary":
var count = 0;
for (var dictKey in value) {
localStorageSet(key + "_k" + count, dictKey);
localStorageSet(key + "_v" + count, value[dictKey]._js_name);
count++;
}
storeValue = count;
break;
case "object":
storeValue = value._js_name;
break;
case "null":
storeValue = "";
}
localStorageSet(key, object._js_name + "." + attribute + "=" + valueType + ":" + storeValue);
});
localStorageSet("numChanges", changeId);
// Save all object destroys
var destroyId = 0;
for (var idx in destroyedObjects) {
destroyId++;
localStorageSet("destroy" + destroyId, destroyedObjects[idx]);
}
localStorageSet("numDestroys", destroyId);
localStorage.setItem("transaction", localStorageTransactionId);
}
catch (err) {
reportError("Failed to save game: " + err);
}
}
function loadGame_() {
return false;
if (!localStorage) return false;
localStorageTransactionId = localStorage.getItem("transaction");
if (localStorageTransactionId == undefined) {
return false;
}
try {
nextObjectId = parseInt(localStorageGet("nextObjectId"));
// Load object creations
var commandLogList = localStorageGet("commandLog");
if (commandLogList != null) {
commandLog = commandLogList.split(";");
}
addToCommandLog("* loaded game");
var createCount = localStorageGet("numCreates");
for (var i = 1; i <= createCount; i++) {
var data = localStorageGet("create" + i);
var params = data.split(";");
// format is name;defaultTypeObject.name;objectType
switch (params[2]) {
case "object":
var array = allObjects;
break;
case "exit":
var array = allExits;
break;
case "timer":
break;
case "turnscript":
break;
default:
throw "Unhandled create object type " + params[2];
}
if (params[2] == "timer") {
createtimer(params[0]);
}
else if (params[2] == "turnscript") {
createturnscript(params[0]);
}
else {
createInternal(params[0], array, GetObject(params[1]), params[2]);
// TODO: Add to objectsNameMap
}
}
// Load object type additions
var addTypeCount = localStorageGet("numAddTypes");
for (var i = 1; i <= addTypeCount; i++) {
var data = localStorageGet("addtype" + i);
var params = data.split(";");
// format is object;type
addTypeToObject(window[params[0]], window[params[1]]);
}
// Load object attribute changes
var changeCount = localStorageGet("numChanges");
for (var i = 1; i <= changeCount; i++) {
var data = localStorageGet("change" + i);
var dotPos = data.indexOf(".");
var eqPos = data.indexOf("=");
var colonPos = data.indexOf(":");
var objectName = data.substring(0, dotPos);
var attrName = data.substring(dotPos + 1, eqPos);
var type = data.substring(eqPos + 1, colonPos);
var valueString = data.substring(colonPos + 1);
var object = window[objectName];
var value = valueString;
switch (type) {
case "script":
eval("_temp_assignfn=" + valueString);
value = _temp_assignfn;
break;
case "stringlist":
var count = parseInt(valueString);
value = new Array();
for (var listIdx = 0; listIdx < count; listIdx++) {
value.push(localStorageGet("change" + i + "_" + listIdx));
}
break;
case "objectlist":
var count = parseInt(valueString);
value = new Array();
for (var listIdx = 0; listIdx < count; listIdx++) {
value.push(window[localStorageGet("change" + i + "_" + listIdx)]);
}
break;
case "stringdictionary":
var count = parseInt(valueString);
value = new Object();
for (var listIdx = 0; listIdx < count; listIdx++) {
var dictKey = localStorageGet("change" + i + "_k" + listIdx);
var dictVal = localStorageGet("change" + i + "_v" + listIdx);
value[dictKey] = dictVal;
}
break;
case "objectdictionary":
var count = parseInt(valueString);
value = new Object();
for (var listIdx = 0; listIdx < count; listIdx++) {
var dictKey = localStorageGet("change" + i + "_k" + listIdx);
var dictVal = localStorageGet("change" + i + "_v" + listIdx);
value[dictKey] = window[dictVal];
}
break;
case "scriptdictionary":
var count = parseInt(valueString);
value = new Object();
for (var listIdx = 0; listIdx < count; listIdx++) {
var dictKey = localStorageGet("change" + i + "_k" + listIdx);
var dictVal = localStorageGet("change" + i + "_v" + listIdx);
eval("_temp_assignfn=" + dictVal);
value[dictKey] = _temp_assignfn;
}
break;
case "object":
value = window[valueString];
break;
case "null":
value = null;
break;
case "int":
value = parseInt(valueString);
break;
case "double":
value = parseFloat(valueString);
break;
case "boolean":
value = (valueString == "true");
}
set(object, attrName, value, false);
}
// Load object destroys
var destroyCount = localStorageGet("numDestroys");
for (var i = 1; i <= destroyCount; i++) {
var data = localStorageGet("destroy" + i);
destroy(data);
}
currentFont = GetObject("game").defaultfont;
$("#fontOptions").val(currentFont);
currentFontSize = GetObject("game").defaultfontsize.toString();
$("#fontSize").val(currentFontSize);
$("#fontSample").css("font-family", currentFont);
$("#fontSample").css("font-size", currentFontSize + "pt");
clearScreen();
_divCount = localStorageGet("divCount");
$("#divOutput").html(localStorageGet("output2"));
msg(localStorageGet("output"));
beginningOfCurrentTurnScrollPosition = $("#gameContent").height();
scrollToEnd();
updateLists();
return true;
}
catch (err) {
reportError("Failed to load game: " + err);
return false;
}
}
var localStorageTransactionId;
var lastRead;
function localStorageSet(key, value) {
localStorage.setItem("c" + localStorageTransactionId + key, value);
}
function localStorageGet(key) {
lastRead = key;
return localStorage.getItem("c" + localStorageTransactionId + key);
}
var currentWalkthroughSteps;
var runningWalkthrough = false;
var stepCount;
var walkthroughMaxSteps;
var walkthroughFinishCode;
function runWalkthrough(name, startStep, maxSteps, cheatCode) {
stepCount = 0;
walkthroughMaxSteps = maxSteps;
walkthroughFinishCode = cheatCode;
var walkthrough = getElement(name);
if (walkthrough) {
currentWalkthroughSteps = addWalkthroughSteps(walkthrough);
currentWalkthroughSteps.splice(0, startStep);
runningWalkthrough = true;
runWalkthroughSteps();
}
else {
msg("No walkthrough of that name");
}
}
function addWalkthroughSteps(walkthrough) {
var list = new Array();
if (walkthrough.parent != null) {
list = list.concat(addWalkthroughSteps(walkthrough.parent));
}
list = list.concat(walkthrough.steps);
return list;
}
var postStep = null;
function runWalkthroughSteps() {
if (currentWalkthroughSteps == null || currentWalkthroughSteps.length == 0 || (walkthroughMaxSteps > 0 && stepCount >= walkthroughMaxSteps)) {
runningWalkthrough = false;
saveGame();
return;
}
var step = currentWalkthroughSteps.splice(0, 1)[0];
if (step == "label:" + walkthroughFinishCode) {
runningWalkthrough = false;
saveGame();
return;
}
msg("");
if (StartsWith(step, "assert:")) {
}
else if (StartsWith(step, "label:")) {
// ignore
}
else {
stepCount++;
beginningOfCurrentTurnScrollPosition = $("#gameContent").height();
sendCommandInternal(step);
scrollToEndNow();
}
while (postStep) {
var fn = postStep;
postStep = null;
fn();
}
setTimeout(function () {
runWalkthroughSteps();
}, 100);
}
function updateStatus(text) {
if (text.length > 0) {
showStatusVisible(true);
$("#statusVars").html(text.replace(/\n/g, "
"));
}
else {
showStatusVisible(false);
}
}
function setBackground(col) {
$("#divOutput").css("background-color", col);
$("#gamePanel").css("background-color", col);
}
function ASLEvent(event, parameter) {
is_asl_event=true; // JS
var fn = window[event];
fn.apply(null, [parameter]);
is_asl_event=false; //JS
}
function disableMainScrollbar() {
$("#divOutput").css("overflow", "hidden");
}
function stopTimer() {
clearInterval(tmrTick);
}
function getTickCountAndStopTimer() {
stopTimer();
return tickCount;
}
function goUrl(href) {
window.open(href);
}
function setCompassDirections(directions) {
_compassDirs = directions;
$("#cmdCompassNW").attr("title", _compassDirs[0]);
$("#cmdCompassN").attr("title", _compassDirs[1]);
$("#cmdCompassNE").attr("title", _compassDirs[2]);
$("#cmdCompassW").attr("title", _compassDirs[3]);
$("#cmdCompassE").attr("title", _compassDirs[4]);
$("#cmdCompassSW").attr("title", _compassDirs[5]);
$("#cmdCompassS").attr("title", _compassDirs[6]);
$("#cmdCompassSE").attr("title", _compassDirs[7]);
$("#cmdCompassU").attr("title", _compassDirs[8]);
$("#cmdCompassD").attr("title", _compassDirs[9]);
$("#cmdCompassIn").attr("title", _compassDirs[10]);
$("#cmdCompassOut").attr("title", _compassDirs[11]);
}
function setInterfaceString(name, text) {
switch (name) {
case "InventoryLabel":
$("#inventoryLabel").html(text);
break;
case "PlacesObjectsLabel":
$("#placesObjectsLabel").html(text);
break;
case "CompassLabel":
$("#compassLabel").html(text);
break;
case "InButtonLabel":
$("#cmdCompassIn").attr("value", text);
break;
case "OutButtonLabel":
$("#cmdCompassOut").attr("value", text);
break;
case "EmptyListLabel":
break;
case "NothingSelectedLabel":
break;
}
}
function updateVerbButtons(list, verbsArray, idprefix) {
var selectedIndex = list.prop("selectedIndex");
var verbs = verbsArray[selectedIndex].split("/");
var count = 1;
$.each(verbs, function () {
var target = $("#" + idprefix + count);
target.attr("value", this);
target.show();
count++;
});
for (var i = count; i <= verbButtonCount; i++) {
var target = $("#" + idprefix + i);
target.hide();
}
}
var _currentDiv = null;
function setCommandBarStyle(style) {
var width = $("#txtCommand").width();
$("#txtCommand").attr("style", style);
//$("#txtCommand").width(width); //?????????????????????? JS
}
function addText(text) {
if (_currentDiv == null) {
createNewDiv("left");
}
_currentDiv.append(text);
scrollToEnd();
}
var _divCount = 0;
function createNewDiv(alignment) {
var classes = _outputSections.join(" ");
_divCount++;
$("", {
id: "divOutputAlign" + _divCount,
style: "text-align: " + alignment,
"class": classes
}).appendTo("#divOutput");
_currentDiv = $("#divOutputAlign" + _divCount);
}
function bindMenu(linkid, verbs, text, inline) {
var verbsList = verbs.split("/");
var options = [];
$.each(verbsList, function (key, value) {
options = options.concat({ title: value, action: { type: "fn", callback: "doMenuClick('" + value.toLowerCase() + " " + text.replace("'", "\\'") + "');" } });
});
$("#" + linkid).jjmenu("both", options, {}, { show: "fadeIn", speed: 100, xposition: "left", yposition: "auto", "orientation": "auto" });
}
function bindMenuEl(el) {
var verbs = el.data("verbs");
var text = el.html();
var elementId = el.data("elementid");
var id = el.attr("id");
bindMenu(id, verbs, text, false);
}
// added from desktop version:
function buildMenuOptions(verbs, text, elementId) {
var verbsList = verbs.split("/");
var options = [];
var metadata = new Object();
metadata[text] = elementId;
var metadataString = JSON.stringify(metadata);
$.each(verbsList, function (key, value) {
options = options.concat({
title: value,
action: {
callback: function (selectedValue) {
sendCommand(selectedValue.toLowerCase() + " " + text, metadataString);
}
}
});
});
return options;
}
function doMenuClick(command) {
$("div[id^=jjmenu]").remove();
sendCommand(command);
}
function updateObjectLinks(data) {
$(".elementmenu").each(function (index, e) {
var $e = $(e);
var verbs = data[$e.data("elementid")];
if (verbs) {
$e.removeClass("disabled");
$e.data("verbs", verbs);
// also set attribute so verbs are persisted to savegame
$e.attr("data-verbs", verbs);
bindMenuEl($e); // added by vourtram
} else {
$e.addClass("disabled");
}
});
}
function updateExitLinks(data) {
$(".exitlink").each(function (index, e) {
var $e = $(e);
var exitid = $e.data("elementid");
var available = $.inArray(exitid, data) > -1;
if (available) {
$e.removeClass("disabled");
} else {
$e.addClass("disabled");
}
});
}
function updateCommandLinks(data) {
$(".commandlink").each(function (index, e) {
var $e = $(e);
var exitid = $e.data("elementid");
var available = $.inArray(exitid, data) > -1;
if (available) {
$e.removeClass("disabled");
} else {
$e.addClass("disabled");
}
});
}
function disableAllCommandLinks() {
$(".commandlink").each(function (index, e) {
$(e).addClass("disabled");
});
}
function clearScreen() {
allOutput = "";
$("#divOutput").html("");
createNewDiv("left");
beginningOfCurrentTurnScrollPosition = 0;
}
function clearPast(keep) {
while ( $("#divOutput").children().length>keep) {
$("#divOutput").children().first().remove();
}
}
function keyPressCode(e) {
var keynum
if (window.event) {
keynum = e.keyCode
} else if (e.which) {
keynum = e.which
}
return keynum;
}
function AddYouTube(id) {
var embedHTML = "";
addText(embedHTML);
}
function AddVimeo(id) {
var embedHTML = "";
addText(embedHTML);
}
function SetMenuBackground(color) {
var css = getCSSRule("div.jj_menu_item");
if (css) {
css.style.backgroundColor = color;
}
}
function SetMenuForeground(color) {
var css = getCSSRule("div.jj_menu_item");
if (css) {
css.style.color = color;
}
}
function SetMenuHoverBackground(color) {
var css = getCSSRule("div.jj_menu_item_hover");
if (css) {
css.style.backgroundColor = color;
}
}
function SetMenuHoverForeground(color) {
var css = getCSSRule("div.jj_menu_item_hover");
if (css) {
css.style.color = color;
}
}
function SetMenuFontName(font) {
var css = getCSSRule("div.jjmenu");
if (css) {
css.style.fontFamily = font;
}
}
function SetMenuFontSize(size) {
// disabled
//var css = getCSSRule("div.jjmenu");
//if (css) {
// css.style.fontSize = size;
//}
}
function TurnOffHyperlinksUnderline() {
var css = getCSSRule("a.cmdlink");
if (css) {
css.style.textDecoration = "none";
}
}
var _outputSections = new Array();
function JsStartOutputSection(name) {
if ($.inArray(name, _outputSections) == -1) {
_outputSections.push(name);
createNewDiv("left");
}
}
function JsEndOutputSection(name) {
var index = $.inArray(name, _outputSections);
if (index != -1) {
_outputSections.splice(index, 1);
createNewDiv("left");
}
}
function JsHideOutputSection(name) {
EndOutputSection(name);
$("." + name + " a").attr("onclick", "");
setTimeout(function () {
$("." + name).hide(250, function () { $(this).remove(); });
}, 250);
}
function getCSSRule(ruleName, deleteFlag) {
ruleName = ruleName.toLowerCase();
if (document.styleSheets) {
for (var i = 0; i < document.styleSheets.length; i++) {
var styleSheet = document.styleSheets[i];
var ii = 0;
var cssRule = false;
try {
do {
if (styleSheet.cssRules) {
cssRule = styleSheet.cssRules[ii];
} else if (styleSheet.rules) {
cssRule = styleSheet.rules[ii];
}
if (cssRule) {
if (typeof cssRule.selectorText != "undefined") {
if (cssRule.selectorText.toLowerCase() == ruleName) {
if (deleteFlag == 'delete') {
if (styleSheet.cssRules) {
styleSheet.deleteRule(ii);
} else {
styleSheet.removeRule(ii);
}
return true;
} else {
return cssRule;
}
}
}
}
ii++;
} while (cssRule)
} catch(err) {
//security errors...
}
}
}
return false;
}
function killCSSRule(ruleName) {
return getCSSRule(ruleName, 'delete');
}
function addCSSRule(ruleName) {
if (document.styleSheets) {
if (!getCSSRule(ruleName)) {
if (document.styleSheets[0].addRule) {
document.styleSheets[0].addRule(ruleName, null, 0);
} else {
document.styleSheets[0].insertRule(ruleName + ' { }', 0);
}
}
}
return getCSSRule(ruleName);
}
function uiDoRestart() {
if (localStorage) {
//localStorage.clear(); //JS
}
window.location.reload();
}
function reportError(errorMessage) {
alert(errorMessage);
console.log(errorMessage);
}
// WORLDMODEL ===================================================================================================================
var webPlayer = true;
var tmrTick = null;
var awaitingCallback = false;
var gameRunning = true;
var gameActive = true;
function worldmodelInitialise() {
resolveObjectReferences();
GetObject("game").timeelapsed = 0;
for (var idx in allTimers) {
var timer = allTimers[idx];
if (timer.enabled) {
timer.trigger = timer.interval;
}
}
setObjectChildAttributes();
if (typeof InitInterface == 'function') {
InitInterface();
}
updateLists();
tmrTick = setInterval(function () {
timerTick();
}, 1000);
}
function worldModelBeginGame() {
StartGame();
TryRunOnReadyScripts();
updateLists();
}
function resolveObjectReferences() {
for (var item in objectReferences) {
var objData = objectReferences[item];
window[objData[0]][objData[1]] = window[objData[2]];
}
for (var item in objectListReferences) {
var objData = objectListReferences[item];
var parent = window[objData[0]];
var attribute = objData[1].replace(/ /g, "___SPACE___");
var itemValue = objData[2];
if (typeof parent[attribute] == "undefined") {
parent[attribute] = new Array();
}
parent[attribute].push(window[itemValue]);
}
for (var item in objectDictionaryReferences) {
var objData = objectDictionaryReferences[item];
var parent = window[objData[0]];
var attribute = objData[1].replace(/ /g, "___SPACE___");
var itemKey = objData[2];
var itemValue = objData[3];
if (typeof parent[attribute] == "undefined") {
parent[attribute] = new Object();
}
parent[attribute][itemKey] = window[itemValue];
}
}
function setObjectChildAttributes() {
for (var idx in allObjects) {
var obj = allObjects[idx];
if (obj.parent) {
addChildObject(obj.parent, obj);
}
}
}
function addChildObject(parent, child) {
if (!parent["_children"]) {
parent["_children"] = new Array();
}
parent["_children"].push(child);
}
function updateLists() {
setTimeout(function () {
updateListsInternal();
}, 1000);
}
function updateListsInternal() {
updateObjectsLists();
updateExitsList();
if (typeof UpdateStatusAttributes == "function") {
UpdateStatusAttributes();
}
}
function updateObjectsLists() {
updateObjectsList("GetPlacesObjectsList", "placesobjects");
updateObjectsList("ScopeInventory", "inventory");
}
function updateObjectsList(scope, listName) {
var listItems = window[scope]();
if (scope == "GetPlacesObjectsList") {
listItems = listItems.concat(ScopeExits());
}
var listData = new Array();
for (var item in listItems) {
var verbs = (listName == "inventory") ? listItems[item].inventoryverbs : listItems[item].displayverbs;
if (verbs != undefined) {
var verbsList = verbs.join("/");
}
else {
var verbsList = "";
}
listData.push(GetDisplayAlias(listItems[item]) + ":" + verbsList);
}
updateList(listName, listData);
}
function updateExitsList() {
var listItems = ScopeExits();
var listData = new Array();
for (var item in listItems) {
listData.push(listItems[item].alias);
}
updateCompass(listData);
}
function attributeChanged(object, attribute, runscript, oldParent) {
// TO DO: "Meta" field SortIndex - changed when object moves to a new parent, so it appears at the end of the list
// of children.
markAttributeModified(object, attribute);
if (runscript) {
var changedScript = "changed" + attribute;
if (typeof object[changedScript] == "function") {
object[changedScript](oldParent);
}
}
}
var nextObjectId = 0;
function getUniqueId() {
nextObjectId++;
return "dynid" + nextObjectId;
}
var transactions = new Array();
var currentTransaction;
function preAttributeChange(object, attribute, newValue) {
if (currentTransaction != undefined) {
// store the old value on the undo list
var oldValue = object[attribute];
var undoFunction;
if (attribute == "parent") {
undoFunction = function () {
newValue = object[attribute];
object[attribute] = oldValue;
objectMoved(object, newValue, oldValue);
};
}
else {
undoFunction = function () {
object[attribute] = oldValue;
};
}
currentTransaction.undolist.push(undoFunction);
}
var type = TypeOf(newValue);
// if value requires cloning first then return a clone
if (type == "stringdictionary" || type == "objectdictionary" || type == "scriptdictionary") {
var result = new Object();
for (key in newValue) {
result[key] = newValue[key];
}
return result;
}
else if (type == "objectlist" || type == "stringlist") {
var result = new Array();
for (idx in newValue) {
result.push(newValue[idx]);
}
return result;
}
return newValue;
}
function markAttributeModified(object, attribute) {
if (object["__modified"] == undefined) {
object["__modified"] = new Array();
}
if (object["__modified"].indexOf(attribute) == -1) {
object["__modified"].push(attribute);
}
}
var thisTurnModifiedItems = new Array();
function markModified(item) {
if (thisTurnModifiedItems.indexOf(item) == -1) {
thisTurnModifiedItems.push(item);
}
}
// Javascript magic to support function overloading
// from http://ejohn.org/blog/javascript-method-overloading/
// addMethod - By John Resig (MIT Licensed)
function addMethod(object, name, fn) {
var old = object[name];
object[name] = function () {
if (fn.length == arguments.length)
return fn.apply(this, arguments);
else if (typeof old == 'function')
return old.apply(this, arguments);
};
}
// Script commands
var objectTag = new XRegExp("\