mirror of
https://github.com/doublespeakgames/adarkroom.git
synced 2026-05-30 17:21:53 +08:00
+85
-85
@@ -1,86 +1,86 @@
|
||||
var Button = {
|
||||
Button: function(options) {
|
||||
if(typeof options.cooldown == 'number') {
|
||||
this.data_cooldown = options.cooldown;
|
||||
}
|
||||
this.data_remaining = 0;
|
||||
if(typeof options.click == 'function') {
|
||||
this.data_handler = options.click;
|
||||
}
|
||||
|
||||
var el = $('<div>')
|
||||
.attr('id', typeof(options.id) != 'undefined' ? options.id : "BTN_" + Engine.getGuid())
|
||||
.addClass('button')
|
||||
.text(typeof(options.text) != 'undefined' ? options.text : "button")
|
||||
.click(function() {
|
||||
if(!$(this).hasClass('disabled')) {
|
||||
Button.cooldown($(this));
|
||||
$(this).data("handler")($(this));
|
||||
}
|
||||
})
|
||||
.data("handler", typeof options.click == 'function' ? options.click : function() { Engine.log("click"); })
|
||||
.data("remaining", 0)
|
||||
.data("cooldown", typeof options.cooldown == 'number' ? options.cooldown : 0);
|
||||
|
||||
el.append($("<div>").addClass('cooldown'));
|
||||
|
||||
if(options.cost) {
|
||||
var ttPos = options.ttPos ? options.ttPos : "bottom right";
|
||||
var costTooltip = $('<div>').addClass('tooltip ' + ttPos);
|
||||
for(var k in options.cost) {
|
||||
$("<div>").addClass('row_key').text(_(k)).appendTo(costTooltip);
|
||||
$("<div>").addClass('row_val').text(options.cost[k]).appendTo(costTooltip);
|
||||
}
|
||||
if(costTooltip.children().length > 0) {
|
||||
costTooltip.appendTo(el);
|
||||
}
|
||||
}
|
||||
|
||||
if(options.width) {
|
||||
el.css('width', options.width);
|
||||
}
|
||||
|
||||
return el;
|
||||
},
|
||||
|
||||
setDisabled: function(btn, disabled) {
|
||||
if(btn) {
|
||||
if(!disabled && !btn.data('onCooldown')) {
|
||||
btn.removeClass('disabled');
|
||||
} else if(disabled) {
|
||||
btn.addClass('disabled');
|
||||
}
|
||||
btn.data('disabled', disabled);
|
||||
}
|
||||
},
|
||||
|
||||
isDisabled: function(btn) {
|
||||
if(btn) {
|
||||
return btn.data('disabled') === true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
cooldown: function(btn) {
|
||||
var cd = btn.data("cooldown");
|
||||
if(cd > 0) {
|
||||
$('div.cooldown', btn).stop(true, true).width("100%").animate({width: '0%'}, cd * 1000, 'linear', function() {
|
||||
var b = $(this).closest('.button');
|
||||
b.data('onCooldown', false);
|
||||
if(!b.data('disabled')) {
|
||||
b.removeClass('disabled');
|
||||
}
|
||||
});
|
||||
btn.addClass('disabled');
|
||||
btn.data('onCooldown', true);
|
||||
}
|
||||
},
|
||||
|
||||
clearCooldown: function(btn) {
|
||||
$('div.cooldown', btn).stop(true, true);
|
||||
btn.data('onCooldown', false);
|
||||
if(!btn.data('disabled')) {
|
||||
btn.removeClass('disabled');
|
||||
}
|
||||
}
|
||||
var Button = {
|
||||
Button: function(options) {
|
||||
if(typeof options.cooldown == 'number') {
|
||||
this.data_cooldown = options.cooldown;
|
||||
}
|
||||
this.data_remaining = 0;
|
||||
if(typeof options.click == 'function') {
|
||||
this.data_handler = options.click;
|
||||
}
|
||||
|
||||
var el = $('<div>')
|
||||
.attr('id', typeof(options.id) != 'undefined' ? options.id : "BTN_" + Engine.getGuid())
|
||||
.addClass('button')
|
||||
.text(typeof(options.text) != 'undefined' ? options.text : "button")
|
||||
.click(function() {
|
||||
if(!$(this).hasClass('disabled')) {
|
||||
Button.cooldown($(this));
|
||||
$(this).data("handler")($(this));
|
||||
}
|
||||
})
|
||||
.data("handler", typeof options.click == 'function' ? options.click : function() { Engine.log("click"); })
|
||||
.data("remaining", 0)
|
||||
.data("cooldown", typeof options.cooldown == 'number' ? options.cooldown : 0);
|
||||
|
||||
el.append($("<div>").addClass('cooldown'));
|
||||
|
||||
if(options.cost) {
|
||||
var ttPos = options.ttPos ? options.ttPos : "bottom right";
|
||||
var costTooltip = $('<div>').addClass('tooltip ' + ttPos);
|
||||
for(var k in options.cost) {
|
||||
$("<div>").addClass('row_key').text(_(k)).appendTo(costTooltip);
|
||||
$("<div>").addClass('row_val').text(options.cost[k]).appendTo(costTooltip);
|
||||
}
|
||||
if(costTooltip.children().length > 0) {
|
||||
costTooltip.appendTo(el);
|
||||
}
|
||||
}
|
||||
|
||||
if(options.width) {
|
||||
el.css('width', options.width);
|
||||
}
|
||||
|
||||
return el;
|
||||
},
|
||||
|
||||
setDisabled: function(btn, disabled) {
|
||||
if(btn) {
|
||||
if(!disabled && !btn.data('onCooldown')) {
|
||||
btn.removeClass('disabled');
|
||||
} else if(disabled) {
|
||||
btn.addClass('disabled');
|
||||
}
|
||||
btn.data('disabled', disabled);
|
||||
}
|
||||
},
|
||||
|
||||
isDisabled: function(btn) {
|
||||
if(btn) {
|
||||
return btn.data('disabled') === true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
cooldown: function(btn) {
|
||||
var cd = btn.data("cooldown");
|
||||
if(cd > 0) {
|
||||
$('div.cooldown', btn).stop(true, true).width("100%").animate({width: '0%'}, cd * 1000, 'linear', function() {
|
||||
var b = $(this).closest('.button');
|
||||
b.data('onCooldown', false);
|
||||
if(!b.data('disabled')) {
|
||||
b.removeClass('disabled');
|
||||
}
|
||||
});
|
||||
btn.addClass('disabled');
|
||||
btn.data('onCooldown', true);
|
||||
}
|
||||
},
|
||||
|
||||
clearCooldown: function(btn) {
|
||||
$('div.cooldown', btn).stop(true, true);
|
||||
btn.data('onCooldown', false);
|
||||
if(!btn.data('disabled')) {
|
||||
btn.removeClass('disabled');
|
||||
}
|
||||
}
|
||||
};
|
||||
+361
-361
@@ -1,362 +1,362 @@
|
||||
(function (Engine, Events, Dropbox, $) {
|
||||
|
||||
/**
|
||||
* Module that enables a save of the gamestate to the dropbox datastore
|
||||
* @see https://www.dropbox.com/developers/datastore
|
||||
*
|
||||
* The dropbox datastore (dbds) connector lets you save your data to your own dropbox datastore
|
||||
* without jamming files to it.
|
||||
*
|
||||
* This connector uses the game engines own base64 encoder.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
if (!Engine) { return false; } // Game Engine not available
|
||||
if (!Dropbox) { return false; } // Dropbox Connector not available
|
||||
|
||||
var DropboxConnector = {
|
||||
|
||||
options: {
|
||||
log: false,
|
||||
key: 'q7vyvfsakyfmp3o',
|
||||
table: 'adarkroom'
|
||||
},
|
||||
|
||||
client: false,
|
||||
table: false,
|
||||
dropboxAccount: false,
|
||||
savegameKey: false,
|
||||
savegames: {0: null, 1: null, 2: null, 3: null, 4: null},
|
||||
|
||||
init: function (options) {
|
||||
this.options = $.extend(
|
||||
this.options,
|
||||
options
|
||||
);
|
||||
|
||||
this._log = this.options.log;
|
||||
|
||||
this.client = new Dropbox.Client({key: DropboxConnector.options.key});
|
||||
this.connectToDropbox(false);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
startDropbox: function () {
|
||||
if (!DropboxConnector.client || !DropboxConnector.table) {
|
||||
DropboxConnector.startDropboxConnectEvent();
|
||||
} else {
|
||||
DropboxConnector.startDropboxImportEvent();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* ******
|
||||
* Events
|
||||
* ******
|
||||
*/
|
||||
|
||||
startDropboxConnectEvent: function () {
|
||||
Events.startEvent({
|
||||
title: _('Dropbox connection'),
|
||||
scenes: {
|
||||
start: {
|
||||
text: [_('connect game to dropbox local storage')],
|
||||
buttons: {
|
||||
'connect': {
|
||||
text: _('connect'),
|
||||
nextScene: 'end',
|
||||
onChoose: function () {
|
||||
DropboxConnector.connectToDropbox(DropboxConnector.startDropboxImportEvent);
|
||||
}
|
||||
},
|
||||
'cancel': {
|
||||
text: _('cancel'),
|
||||
nextScene: 'end'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
startDropboxImportEvent: function () {
|
||||
Events.startEvent({
|
||||
title: _('Dropbox Export / Import'),
|
||||
scenes: {
|
||||
start: {
|
||||
text: [_('export or import save data to dropbox datastorage'),
|
||||
_('your are connected to dropbox with account / email ') + DropboxConnector.dropboxAccount],
|
||||
buttons: {
|
||||
'save': {
|
||||
text: _('save'),
|
||||
nextScene: {1: 'saveToSlot'}
|
||||
},
|
||||
'load': {
|
||||
text: _('load'),
|
||||
nextScene: {1: 'loadFromSlot'},
|
||||
onChoose: DropboxConnector.loadGamesFromDropbox
|
||||
},
|
||||
'signout': {
|
||||
text: _('signout'),
|
||||
nextScene: 'end',
|
||||
onChoose: DropboxConnector.signout
|
||||
},
|
||||
'cancel': {
|
||||
text: _('cancel'),
|
||||
nextScene: 'end'
|
||||
}
|
||||
}
|
||||
},
|
||||
saveToSlot: {
|
||||
text: [_('choose one slot to save to')],
|
||||
buttons: (function () {
|
||||
var buttons = {};
|
||||
|
||||
$.each(DropboxConnector.savegames, function (n, savegame) {
|
||||
buttons['savegame' + n] = {
|
||||
text: _('save to slot') + n + ' ' + (savegame ? DropboxConnector.prepareSaveDate(savegame.get('timestamp')) : 'empty'),
|
||||
nextScene: 'end',
|
||||
onChoose: function () {
|
||||
DropboxConnector.log('Save to slot ' + n + ' initiated');
|
||||
// timeout prevents error due to fade out animation of the previous event
|
||||
window.setTimeout(function () {
|
||||
DropboxConnector.log('Save to slot ' + n);
|
||||
DropboxConnector.saveGameToDropbox(n, DropboxConnector.savedtoDropboxEvent);
|
||||
}, 1000);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
buttons.cancel = {
|
||||
text: _('cancel'),
|
||||
nextScene: 'end'
|
||||
};
|
||||
|
||||
return buttons;
|
||||
}())
|
||||
},
|
||||
loadFromSlot: {
|
||||
text: [_('choose one slot to load from')],
|
||||
buttons: (function () {
|
||||
var buttons = {};
|
||||
|
||||
$.each(DropboxConnector.savegames, function (n, savegame) {
|
||||
if (savegame) {
|
||||
buttons['savegame' + n] = {
|
||||
text: _('load from slot') + n + ' ' + DropboxConnector.prepareSaveDate(savegame.get('timestamp')),
|
||||
nextScene: 'end',
|
||||
onChoose: function () {
|
||||
DropboxConnector.log('Load from slot ' + n + ' initiated');
|
||||
// timeout prevents error due to fade out animation of the previous event
|
||||
window.setTimeout(function () {
|
||||
DropboxConnector.log('Load from slot ' + n);
|
||||
DropboxConnector.loadGameFromDropbox(n);
|
||||
}, 1000);
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
buttons.cancel = {
|
||||
text: _('cancel'),
|
||||
nextScene: 'end'
|
||||
};
|
||||
|
||||
return buttons;
|
||||
}())
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
savedtoDropboxEvent: function (success) {
|
||||
Events.startEvent({
|
||||
title: _('Dropbox Export / Import'),
|
||||
scenes: {
|
||||
start: {
|
||||
text: success ? [_('successfully saved to dropbox datastorage')] :
|
||||
[_('error while saving to dropbox datastorage')],
|
||||
buttons: {
|
||||
'ok': {
|
||||
text: _('ok'),
|
||||
nextScene: 'end'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* ***************
|
||||
* functional code
|
||||
* ***************
|
||||
*/
|
||||
|
||||
/**
|
||||
* Initiate dropbox connection
|
||||
*
|
||||
* @param interactive
|
||||
* @param callback
|
||||
*/
|
||||
connectToDropbox: function (interactive, callback) {
|
||||
|
||||
DropboxConnector.log('start dropbox');
|
||||
|
||||
var client = this.client;
|
||||
|
||||
client.authenticate({interactive: interactive}, function (error) {
|
||||
if (error) {
|
||||
DropboxConnector.log('Dropbox Authentication error: ' + error);
|
||||
}
|
||||
});
|
||||
|
||||
if (client.isAuthenticated()) {
|
||||
|
||||
var datastoreManager = client.getDatastoreManager();
|
||||
datastoreManager.openDefaultDatastore(function (error, datastore) {
|
||||
if (error) {
|
||||
DropboxConnector.log('Error opening default datastore: ' + error);
|
||||
} else {
|
||||
DropboxConnector.table = datastore.getTable(DropboxConnector.options.table);
|
||||
DropboxConnector.loadGamesFromDropbox();
|
||||
|
||||
DropboxConnector.log(DropboxConnector.client.credentials());
|
||||
|
||||
DropboxConnector.client.getAccountInfo({}, function (error, info) {
|
||||
if (!error) {
|
||||
DropboxConnector.dropboxAccount = info.email;
|
||||
}
|
||||
});
|
||||
|
||||
DropboxConnector.log("Got savegames", DropboxConnector.savegames);
|
||||
|
||||
if (typeof callback === "function") {
|
||||
callback.call(DropboxConnector.table);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
DropboxConnector.log('Not connected to dropbox.');
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Requests your savegames fom dbds
|
||||
*
|
||||
* @returns {*}
|
||||
*/
|
||||
loadGamesFromDropbox: function () {
|
||||
var savegames = DropboxConnector.savegames;
|
||||
|
||||
$.each(savegames, function (n) {
|
||||
var results = DropboxConnector.table.query({savegameId: DropboxConnector.prepareSavegameID(n)});
|
||||
savegames[n] = results[0];
|
||||
});
|
||||
|
||||
return savegames;
|
||||
},
|
||||
|
||||
/**
|
||||
* Imports a gamestate of a given slotnumber to your game
|
||||
*
|
||||
* @param slotnumber
|
||||
*/
|
||||
loadGameFromDropbox: function (slotnumber) {
|
||||
|
||||
var table = DropboxConnector.table;
|
||||
var id = DropboxConnector.prepareSavegameID(slotnumber);
|
||||
var results = table.query({savegameId: id});
|
||||
var record = results[0];
|
||||
|
||||
if (record && record.get('gameState')) {
|
||||
Engine.import64(record.get('gameState'));
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Saves a gamestate to a given slot in dbds
|
||||
*
|
||||
* @param slotnumber
|
||||
* @param callback
|
||||
*/
|
||||
saveGameToDropbox: function (slotnumber, callback) {
|
||||
|
||||
var table = DropboxConnector.table;
|
||||
var record = null;
|
||||
var success = false;
|
||||
var id = DropboxConnector.prepareSavegameID(slotnumber);
|
||||
|
||||
var saveGame = {
|
||||
gameState: Engine.generateExport64(),
|
||||
timestamp: new Date().getTime()
|
||||
};
|
||||
|
||||
if (DropboxConnector.savegames[slotnumber]) { // slot aleady used -> overwrite
|
||||
record = DropboxConnector.savegames[slotnumber];
|
||||
try {
|
||||
record.update(saveGame);
|
||||
DropboxConnector.log("Updated savegame ", slotnumber);
|
||||
success = true;
|
||||
} catch (e) {
|
||||
success = false;
|
||||
}
|
||||
|
||||
} else {
|
||||
saveGame.savegameId = id;
|
||||
try {
|
||||
record = table.insert(saveGame);
|
||||
DropboxConnector.log("Inserted savegame ", record.getId());
|
||||
success = true;
|
||||
} catch (e) {
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
if (typeof callback === "function") {
|
||||
callback(success);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Terminates the connection to your db account
|
||||
*/
|
||||
signout: function () {
|
||||
DropboxConnector.client.signOut({}, function (error) {
|
||||
if (error) {
|
||||
alert('Error while logout from dropbox');
|
||||
} else {
|
||||
alert('Successfully signed out.');
|
||||
DropboxConnector.client = null;
|
||||
DropboxConnector.savegames = null;
|
||||
DropboxConnector.dropboxAccount = null;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* **************
|
||||
* Helper methods
|
||||
* **************
|
||||
*/
|
||||
|
||||
prepareSavegameID: function (slotnumber) {
|
||||
return 'adarkroom_savegame_' + slotnumber;
|
||||
},
|
||||
|
||||
prepareSaveDate: function (timestamp) {
|
||||
var date = new Date(timestamp);
|
||||
return date.toLocaleDateString() + ' ' + date.toLocaleTimeString();
|
||||
},
|
||||
|
||||
log: function () {
|
||||
if (this._log) {
|
||||
console.log(arguments);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Engine.Dropbox = DropboxConnector;
|
||||
|
||||
(function (Engine, Events, Dropbox, $) {
|
||||
|
||||
/**
|
||||
* Module that enables a save of the gamestate to the dropbox datastore
|
||||
* @see https://www.dropbox.com/developers/datastore
|
||||
*
|
||||
* The dropbox datastore (dbds) connector lets you save your data to your own dropbox datastore
|
||||
* without jamming files to it.
|
||||
*
|
||||
* This connector uses the game engines own base64 encoder.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
if (!Engine) { return false; } // Game Engine not available
|
||||
if (!Dropbox) { return false; } // Dropbox Connector not available
|
||||
|
||||
var DropboxConnector = {
|
||||
|
||||
options: {
|
||||
log: false,
|
||||
key: 'q7vyvfsakyfmp3o',
|
||||
table: 'adarkroom'
|
||||
},
|
||||
|
||||
client: false,
|
||||
table: false,
|
||||
dropboxAccount: false,
|
||||
savegameKey: false,
|
||||
savegames: {0: null, 1: null, 2: null, 3: null, 4: null},
|
||||
|
||||
init: function (options) {
|
||||
this.options = $.extend(
|
||||
this.options,
|
||||
options
|
||||
);
|
||||
|
||||
this._log = this.options.log;
|
||||
|
||||
this.client = new Dropbox.Client({key: DropboxConnector.options.key});
|
||||
this.connectToDropbox(false);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
startDropbox: function () {
|
||||
if (!DropboxConnector.client || !DropboxConnector.table) {
|
||||
DropboxConnector.startDropboxConnectEvent();
|
||||
} else {
|
||||
DropboxConnector.startDropboxImportEvent();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* ******
|
||||
* Events
|
||||
* ******
|
||||
*/
|
||||
|
||||
startDropboxConnectEvent: function () {
|
||||
Events.startEvent({
|
||||
title: _('Dropbox connection'),
|
||||
scenes: {
|
||||
start: {
|
||||
text: [_('connect game to dropbox local storage')],
|
||||
buttons: {
|
||||
'connect': {
|
||||
text: _('connect'),
|
||||
nextScene: 'end',
|
||||
onChoose: function () {
|
||||
DropboxConnector.connectToDropbox(DropboxConnector.startDropboxImportEvent);
|
||||
}
|
||||
},
|
||||
'cancel': {
|
||||
text: _('cancel'),
|
||||
nextScene: 'end'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
startDropboxImportEvent: function () {
|
||||
Events.startEvent({
|
||||
title: _('Dropbox Export / Import'),
|
||||
scenes: {
|
||||
start: {
|
||||
text: [_('export or import save data to dropbox datastorage'),
|
||||
_('your are connected to dropbox with account / email ') + DropboxConnector.dropboxAccount],
|
||||
buttons: {
|
||||
'save': {
|
||||
text: _('save'),
|
||||
nextScene: {1: 'saveToSlot'}
|
||||
},
|
||||
'load': {
|
||||
text: _('load'),
|
||||
nextScene: {1: 'loadFromSlot'},
|
||||
onChoose: DropboxConnector.loadGamesFromDropbox
|
||||
},
|
||||
'signout': {
|
||||
text: _('signout'),
|
||||
nextScene: 'end',
|
||||
onChoose: DropboxConnector.signout
|
||||
},
|
||||
'cancel': {
|
||||
text: _('cancel'),
|
||||
nextScene: 'end'
|
||||
}
|
||||
}
|
||||
},
|
||||
saveToSlot: {
|
||||
text: [_('choose one slot to save to')],
|
||||
buttons: (function () {
|
||||
var buttons = {};
|
||||
|
||||
$.each(DropboxConnector.savegames, function (n, savegame) {
|
||||
buttons['savegame' + n] = {
|
||||
text: _('save to slot') + n + ' ' + (savegame ? DropboxConnector.prepareSaveDate(savegame.get('timestamp')) : 'empty'),
|
||||
nextScene: 'end',
|
||||
onChoose: function () {
|
||||
DropboxConnector.log('Save to slot ' + n + ' initiated');
|
||||
// timeout prevents error due to fade out animation of the previous event
|
||||
window.setTimeout(function () {
|
||||
DropboxConnector.log('Save to slot ' + n);
|
||||
DropboxConnector.saveGameToDropbox(n, DropboxConnector.savedtoDropboxEvent);
|
||||
}, 1000);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
buttons.cancel = {
|
||||
text: _('cancel'),
|
||||
nextScene: 'end'
|
||||
};
|
||||
|
||||
return buttons;
|
||||
}())
|
||||
},
|
||||
loadFromSlot: {
|
||||
text: [_('choose one slot to load from')],
|
||||
buttons: (function () {
|
||||
var buttons = {};
|
||||
|
||||
$.each(DropboxConnector.savegames, function (n, savegame) {
|
||||
if (savegame) {
|
||||
buttons['savegame' + n] = {
|
||||
text: _('load from slot') + n + ' ' + DropboxConnector.prepareSaveDate(savegame.get('timestamp')),
|
||||
nextScene: 'end',
|
||||
onChoose: function () {
|
||||
DropboxConnector.log('Load from slot ' + n + ' initiated');
|
||||
// timeout prevents error due to fade out animation of the previous event
|
||||
window.setTimeout(function () {
|
||||
DropboxConnector.log('Load from slot ' + n);
|
||||
DropboxConnector.loadGameFromDropbox(n);
|
||||
}, 1000);
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
buttons.cancel = {
|
||||
text: _('cancel'),
|
||||
nextScene: 'end'
|
||||
};
|
||||
|
||||
return buttons;
|
||||
}())
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
savedtoDropboxEvent: function (success) {
|
||||
Events.startEvent({
|
||||
title: _('Dropbox Export / Import'),
|
||||
scenes: {
|
||||
start: {
|
||||
text: success ? [_('successfully saved to dropbox datastorage')] :
|
||||
[_('error while saving to dropbox datastorage')],
|
||||
buttons: {
|
||||
'ok': {
|
||||
text: _('ok'),
|
||||
nextScene: 'end'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* ***************
|
||||
* functional code
|
||||
* ***************
|
||||
*/
|
||||
|
||||
/**
|
||||
* Initiate dropbox connection
|
||||
*
|
||||
* @param interactive
|
||||
* @param callback
|
||||
*/
|
||||
connectToDropbox: function (interactive, callback) {
|
||||
|
||||
DropboxConnector.log('start dropbox');
|
||||
|
||||
var client = this.client;
|
||||
|
||||
client.authenticate({interactive: interactive}, function (error) {
|
||||
if (error) {
|
||||
DropboxConnector.log('Dropbox Authentication error: ' + error);
|
||||
}
|
||||
});
|
||||
|
||||
if (client.isAuthenticated()) {
|
||||
|
||||
var datastoreManager = client.getDatastoreManager();
|
||||
datastoreManager.openDefaultDatastore(function (error, datastore) {
|
||||
if (error) {
|
||||
DropboxConnector.log('Error opening default datastore: ' + error);
|
||||
} else {
|
||||
DropboxConnector.table = datastore.getTable(DropboxConnector.options.table);
|
||||
DropboxConnector.loadGamesFromDropbox();
|
||||
|
||||
DropboxConnector.log(DropboxConnector.client.credentials());
|
||||
|
||||
DropboxConnector.client.getAccountInfo({}, function (error, info) {
|
||||
if (!error) {
|
||||
DropboxConnector.dropboxAccount = info.email;
|
||||
}
|
||||
});
|
||||
|
||||
DropboxConnector.log("Got savegames", DropboxConnector.savegames);
|
||||
|
||||
if (typeof callback === "function") {
|
||||
callback.call(DropboxConnector.table);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
DropboxConnector.log('Not connected to dropbox.');
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Requests your savegames fom dbds
|
||||
*
|
||||
* @returns {*}
|
||||
*/
|
||||
loadGamesFromDropbox: function () {
|
||||
var savegames = DropboxConnector.savegames;
|
||||
|
||||
$.each(savegames, function (n) {
|
||||
var results = DropboxConnector.table.query({savegameId: DropboxConnector.prepareSavegameID(n)});
|
||||
savegames[n] = results[0];
|
||||
});
|
||||
|
||||
return savegames;
|
||||
},
|
||||
|
||||
/**
|
||||
* Imports a gamestate of a given slotnumber to your game
|
||||
*
|
||||
* @param slotnumber
|
||||
*/
|
||||
loadGameFromDropbox: function (slotnumber) {
|
||||
|
||||
var table = DropboxConnector.table;
|
||||
var id = DropboxConnector.prepareSavegameID(slotnumber);
|
||||
var results = table.query({savegameId: id});
|
||||
var record = results[0];
|
||||
|
||||
if (record && record.get('gameState')) {
|
||||
Engine.import64(record.get('gameState'));
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Saves a gamestate to a given slot in dbds
|
||||
*
|
||||
* @param slotnumber
|
||||
* @param callback
|
||||
*/
|
||||
saveGameToDropbox: function (slotnumber, callback) {
|
||||
|
||||
var table = DropboxConnector.table;
|
||||
var record = null;
|
||||
var success = false;
|
||||
var id = DropboxConnector.prepareSavegameID(slotnumber);
|
||||
|
||||
var saveGame = {
|
||||
gameState: Engine.generateExport64(),
|
||||
timestamp: new Date().getTime()
|
||||
};
|
||||
|
||||
if (DropboxConnector.savegames[slotnumber]) { // slot aleady used -> overwrite
|
||||
record = DropboxConnector.savegames[slotnumber];
|
||||
try {
|
||||
record.update(saveGame);
|
||||
DropboxConnector.log("Updated savegame ", slotnumber);
|
||||
success = true;
|
||||
} catch (e) {
|
||||
success = false;
|
||||
}
|
||||
|
||||
} else {
|
||||
saveGame.savegameId = id;
|
||||
try {
|
||||
record = table.insert(saveGame);
|
||||
DropboxConnector.log("Inserted savegame ", record.getId());
|
||||
success = true;
|
||||
} catch (e) {
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
if (typeof callback === "function") {
|
||||
callback(success);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Terminates the connection to your db account
|
||||
*/
|
||||
signout: function () {
|
||||
DropboxConnector.client.signOut({}, function (error) {
|
||||
if (error) {
|
||||
alert('Error while logout from dropbox');
|
||||
} else {
|
||||
alert('Successfully signed out.');
|
||||
DropboxConnector.client = null;
|
||||
DropboxConnector.savegames = null;
|
||||
DropboxConnector.dropboxAccount = null;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* **************
|
||||
* Helper methods
|
||||
* **************
|
||||
*/
|
||||
|
||||
prepareSavegameID: function (slotnumber) {
|
||||
return 'adarkroom_savegame_' + slotnumber;
|
||||
},
|
||||
|
||||
prepareSaveDate: function (timestamp) {
|
||||
var date = new Date(timestamp);
|
||||
return date.toLocaleDateString() + ' ' + date.toLocaleTimeString();
|
||||
},
|
||||
|
||||
log: function () {
|
||||
if (this._log) {
|
||||
console.log(arguments);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Engine.Dropbox = DropboxConnector;
|
||||
|
||||
})(Engine, Events, Dropbox, jQuery);
|
||||
+43
-4
@@ -605,30 +605,42 @@
|
||||
switch(e.which) {
|
||||
case 38: // Up
|
||||
case 87:
|
||||
if(Engine.activeModule == Outside || Engine.activeModule == Path) {
|
||||
Engine.activeModule.scrollSidebar('up');
|
||||
}
|
||||
Engine.log('up');
|
||||
break;
|
||||
case 40: // Down
|
||||
case 83:
|
||||
if (Engine.activeModule == Outside || Engine.activeModule == Path) {
|
||||
Engine.activeModule.scrollSidebar('down');
|
||||
}
|
||||
Engine.log('down');
|
||||
break;
|
||||
case 37: // Left
|
||||
case 65:
|
||||
if(Engine.activeModule == Ship && Path.tab)
|
||||
Engine.travelTo(Path);
|
||||
else if(Engine.activeModule == Path && Outside.tab)
|
||||
else if(Engine.activeModule == Path && Outside.tab){
|
||||
Engine.activeModule.scrollSidebar('left', true);
|
||||
Engine.travelTo(Outside);
|
||||
else if(Engine.activeModule == Outside && Room.tab)
|
||||
}else if(Engine.activeModule == Outside && Room.tab){
|
||||
Engine.activeModule.scrollSidebar('left', true);
|
||||
Engine.travelTo(Room);
|
||||
}
|
||||
Engine.log('left');
|
||||
break;
|
||||
case 39: // Right
|
||||
case 68:
|
||||
if(Engine.activeModule == Room && Outside.tab)
|
||||
Engine.travelTo(Outside);
|
||||
else if(Engine.activeModule == Outside && Path.tab)
|
||||
else if(Engine.activeModule == Outside && Path.tab){
|
||||
Engine.activeModule.scrollSidebar('right', true);
|
||||
Engine.travelTo(Path);
|
||||
else if(Engine.activeModule == Path && Ship.tab)
|
||||
}else if(Engine.activeModule == Path && Ship.tab){
|
||||
Engine.activeModule.scrollSidebar('right', true);
|
||||
Engine.travelTo(Ship);
|
||||
}
|
||||
Engine.log('right');
|
||||
break;
|
||||
}
|
||||
@@ -718,6 +730,33 @@
|
||||
|
||||
})();
|
||||
|
||||
function inView(dir, elem){
|
||||
|
||||
var scTop = $('#main').offset().top;
|
||||
var scBot = scTop + $('#main').height();
|
||||
|
||||
var elTop = elem.offset().top;
|
||||
var elBot = elTop + elem.height();
|
||||
|
||||
if( dir == 'up' ){
|
||||
// STOP MOVING IF BOTTOM OF ELEMENT IS VISIBLE IN SCREEN
|
||||
return ( elBot < scBot );
|
||||
}else if( dir == 'down' ){
|
||||
return ( elTop > scTop );
|
||||
}else{
|
||||
return ( ( elBot <= scBot ) && ( elTop >= scTop ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function scrollByX(elem, x){
|
||||
|
||||
var elTop = parseInt( elem.css('top'), 10 );
|
||||
elem.css( 'top', ( elTop + x ) + "px" );
|
||||
|
||||
}
|
||||
|
||||
|
||||
//create jQuery Callbacks() to handle object events
|
||||
$.Dispatch = function( id ) {
|
||||
var callbacks, topic = id && Engine.topics[ id ];
|
||||
|
||||
+400
-400
@@ -1,400 +1,400 @@
|
||||
/**
|
||||
* Events that can occur when wandering around the world
|
||||
**/
|
||||
Events.Encounters = [
|
||||
/* Tier 1 */
|
||||
{ /* Snarling Beast */
|
||||
title: _('A Snarling Beast'),
|
||||
isAvailable: function() {
|
||||
return World.getDistance() <= 10 && World.getTerrain() == World.TILE.FOREST;
|
||||
},
|
||||
scenes: {
|
||||
'start': {
|
||||
combat: true,
|
||||
enemy: 'snarling beast',
|
||||
enemyName: _('snarling beast'),
|
||||
deathMessage: _('the snarling beast is dead'),
|
||||
chara: 'B',
|
||||
damage: 1,
|
||||
hit: 0.8,
|
||||
attackDelay: 1,
|
||||
health: 5,
|
||||
loot: {
|
||||
'fur': {
|
||||
min: 1,
|
||||
max: 3,
|
||||
chance: 1
|
||||
},
|
||||
'meat': {
|
||||
min: 1,
|
||||
max: 3,
|
||||
chance: 1
|
||||
},
|
||||
'teeth': {
|
||||
min: 1,
|
||||
max: 3,
|
||||
chance: 0.8
|
||||
}
|
||||
},
|
||||
notification: _('a snarling beast leaps out of the underbrush')
|
||||
}
|
||||
}
|
||||
},
|
||||
{ /* Gaunt Man */
|
||||
title: _('A Gaunt Man'),
|
||||
isAvailable: function() {
|
||||
return World.getDistance() <= 10 && World.getTerrain() == World.TILE.BARRENS;
|
||||
},
|
||||
scenes: {
|
||||
'start': {
|
||||
combat: true,
|
||||
enemy: 'gaunt man',
|
||||
enemyName: _('gaunt man'),
|
||||
deathMessage: _('the gaunt man is dead'),
|
||||
chara: 'G',
|
||||
damage: 2,
|
||||
hit: 0.8,
|
||||
attackDelay: 2,
|
||||
health: 6,
|
||||
loot: {
|
||||
'cloth': {
|
||||
min: 1,
|
||||
max: 3,
|
||||
chance: 0.8
|
||||
},
|
||||
'teeth': {
|
||||
min: 1,
|
||||
max: 2,
|
||||
chance: 0.8
|
||||
},
|
||||
'leather': {
|
||||
min: 1,
|
||||
max: 2,
|
||||
chance: 0.5
|
||||
}
|
||||
},
|
||||
notification: _('a gaunt man approaches, a crazed look in his eye')
|
||||
}
|
||||
}
|
||||
},
|
||||
{ /* Strange Bird */
|
||||
title: _('A Strange Bird'),
|
||||
isAvailable: function() {
|
||||
return World.getDistance() <= 10 && World.getTerrain() == World.TILE.FIELD;
|
||||
},
|
||||
scenes: {
|
||||
'start': {
|
||||
combat: true,
|
||||
enemy: 'strange bird',
|
||||
enemyName: _('strange bird'),
|
||||
deathMessage: _('the strange bird is dead'),
|
||||
chara: 'B',
|
||||
damage: 3,
|
||||
hit: 0.8,
|
||||
attackDelay: 2,
|
||||
health: 4,
|
||||
loot: {
|
||||
'scales': {
|
||||
min: 1,
|
||||
max: 3,
|
||||
chance: 0.8
|
||||
},
|
||||
'teeth': {
|
||||
min: 1,
|
||||
max: 2,
|
||||
chance: 0.5
|
||||
},
|
||||
'meat': {
|
||||
min: 1,
|
||||
max: 3,
|
||||
chance: 0.8
|
||||
}
|
||||
},
|
||||
notification: _('a strange looking bird speeds across the plains')
|
||||
}
|
||||
}
|
||||
},
|
||||
/* Tier 2*/
|
||||
{ /* Shivering Man */
|
||||
title: _('A Shivering Man'),
|
||||
isAvailable: function() {
|
||||
return World.getDistance() > 10 && World.getDistance() <= 20 && World.getTerrain() == World.TILE.BARRENS;
|
||||
},
|
||||
scenes: {
|
||||
'start': {
|
||||
combat: true,
|
||||
enemy: 'shivering man',
|
||||
enemyName: _('shivering man'),
|
||||
deathMessage: _('the shivering man is dead'),
|
||||
chara: 'S',
|
||||
damage: 5,
|
||||
hit: 0.5,
|
||||
attackDelay: 1,
|
||||
health: 20,
|
||||
loot: {
|
||||
'cloth': {
|
||||
min: 1,
|
||||
max: 1,
|
||||
chance: 0.2
|
||||
},
|
||||
'teeth': {
|
||||
min: 1,
|
||||
max: 2,
|
||||
chance: 0.8
|
||||
},
|
||||
'leather': {
|
||||
min: 1,
|
||||
max: 1,
|
||||
chance: 0.2
|
||||
},
|
||||
'medicine': {
|
||||
min: 1,
|
||||
max: 3,
|
||||
chance: 0.7
|
||||
}
|
||||
},
|
||||
notification: _('a shivering man approaches and attacks with surprising strength')
|
||||
}
|
||||
}
|
||||
},
|
||||
{ /* Man-eater */
|
||||
title: _('A Man-Eater'),
|
||||
isAvailable: function() {
|
||||
return World.getDistance() > 10 && World.getDistance() <= 20 && World.getTerrain() == World.TILE.FOREST;
|
||||
},
|
||||
scenes: {
|
||||
'start': {
|
||||
combat: true,
|
||||
enemy: 'man-eater',
|
||||
enemyName: _('man-eater'),
|
||||
deathMessage: _('the man-eater is dead'),
|
||||
chara: 'E',
|
||||
damage: 3,
|
||||
hit: 0.8,
|
||||
attackDelay: 1,
|
||||
health: 25,
|
||||
loot: {
|
||||
'fur': {
|
||||
min: 5,
|
||||
max: 10,
|
||||
chance: 1
|
||||
},
|
||||
'meat': {
|
||||
min: 5,
|
||||
max: 10,
|
||||
chance: 1
|
||||
},
|
||||
'teeth': {
|
||||
min: 5,
|
||||
max: 10,
|
||||
chance: 0.8
|
||||
}
|
||||
},
|
||||
notification: _('a large creature attacks, claws freshly bloodied')
|
||||
}
|
||||
}
|
||||
},
|
||||
{ /* Scavenger */
|
||||
title: _('A Scavenger'),
|
||||
isAvailable: function() {
|
||||
return World.getDistance() > 10 && World.getDistance() <= 20 && World.getTerrain() == World.TILE.BARRENS;
|
||||
},
|
||||
scenes: {
|
||||
'start': {
|
||||
combat: true,
|
||||
enemy: 'scavenger',
|
||||
enemyName: _('scavenger'),
|
||||
deathMessage: _('the scavenger is dead'),
|
||||
chara: 'S',
|
||||
damage: 4,
|
||||
hit: 0.8,
|
||||
attackDelay: 2,
|
||||
health: 30,
|
||||
loot: {
|
||||
'cloth': {
|
||||
min: 5,
|
||||
max: 10,
|
||||
chance: 0.8
|
||||
},
|
||||
'leather': {
|
||||
min: 5,
|
||||
max: 10,
|
||||
chance: 0.8
|
||||
},
|
||||
'iron': {
|
||||
min: 1,
|
||||
max: 5,
|
||||
chance: 0.5
|
||||
},
|
||||
'medicine': {
|
||||
min: 1,
|
||||
max: 2,
|
||||
chance: 0.1
|
||||
}
|
||||
},
|
||||
notification: _('a scavenger draws close, hoping for an easy score')
|
||||
}
|
||||
}
|
||||
},
|
||||
{ /* Huge Lizard */
|
||||
title: _('A Huge Lizard'),
|
||||
isAvailable: function() {
|
||||
return World.getDistance() > 10 && World.getDistance() <= 20 && World.getTerrain() == World.TILE.FIELD;
|
||||
},
|
||||
scenes: {
|
||||
'start': {
|
||||
combat: true,
|
||||
enemy: 'lizard',
|
||||
enemyName: _('lizard'),
|
||||
deathMessage: _('the lizard is dead'),
|
||||
chara: 'L',
|
||||
damage: 5,
|
||||
hit: 0.8,
|
||||
attackDelay: 2,
|
||||
health: 20,
|
||||
loot: {
|
||||
'scales': {
|
||||
min: 5,
|
||||
max: 10,
|
||||
chance: 0.8
|
||||
},
|
||||
'teeth': {
|
||||
min: 5,
|
||||
max: 10,
|
||||
chance: 0.5
|
||||
},
|
||||
'meat': {
|
||||
min: 5,
|
||||
max: 10,
|
||||
chance: 0.8
|
||||
}
|
||||
},
|
||||
notification: _('the grass thrashes wildly as a huge lizard pushes through')
|
||||
}
|
||||
}
|
||||
},
|
||||
/* Tier 3*/
|
||||
{ /* Feral Terror */
|
||||
title: _('A Feral Terror'),
|
||||
isAvailable: function() {
|
||||
return World.getDistance() > 20 && World.getTerrain() == World.TILE.FOREST;
|
||||
},
|
||||
scenes: {
|
||||
'start': {
|
||||
combat: true,
|
||||
enemy: 'feral terror',
|
||||
enemyName: _('feral terror'),
|
||||
deathMessage: _('the feral terror is dead'),
|
||||
chara: 'F',
|
||||
damage: 6,
|
||||
hit: 0.8,
|
||||
attackDelay: 1,
|
||||
health: 45,
|
||||
loot: {
|
||||
'fur': {
|
||||
min: 5,
|
||||
max: 10,
|
||||
chance: 1
|
||||
},
|
||||
'meat': {
|
||||
min: 5,
|
||||
max: 10,
|
||||
chance: 1
|
||||
},
|
||||
'teeth': {
|
||||
min: 5,
|
||||
max: 10,
|
||||
chance: 0.8
|
||||
}
|
||||
},
|
||||
notification: _('a beast, wilder than imagining, erupts out of the foliage')
|
||||
}
|
||||
}
|
||||
},
|
||||
{ /* Soldier */
|
||||
title: _('A Soldier'),
|
||||
isAvailable: function() {
|
||||
return World.getDistance() > 20 && World.getTerrain() == World.TILE.BARRENS;
|
||||
},
|
||||
scenes: {
|
||||
'start': {
|
||||
combat: true,
|
||||
enemy: 'soldier',
|
||||
enemyName: _('soldier'),
|
||||
deathMessage: _('the soldier is dead'),
|
||||
ranged: true,
|
||||
chara: 'D',
|
||||
damage: 8,
|
||||
hit: 0.8,
|
||||
attackDelay: 2,
|
||||
health: 50,
|
||||
loot: {
|
||||
'cloth': {
|
||||
min: 5,
|
||||
max: 10,
|
||||
chance: 0.8
|
||||
},
|
||||
'bullets': {
|
||||
min: 1,
|
||||
max: 5,
|
||||
chance: 0.5
|
||||
},
|
||||
'rifle': {
|
||||
min: 1,
|
||||
max: 1,
|
||||
chance: 0.2
|
||||
},
|
||||
'medicine': {
|
||||
min: 1,
|
||||
max: 2,
|
||||
chance: 0.1
|
||||
}
|
||||
},
|
||||
notification: _('a soldier opens fire from across the desert')
|
||||
}
|
||||
}
|
||||
},
|
||||
{ /* Sniper */
|
||||
title: _('A Sniper'),
|
||||
isAvailable: function() {
|
||||
return World.getDistance() > 20 && World.getTerrain() == World.TILE.FIELD;
|
||||
},
|
||||
scenes: {
|
||||
'start': {
|
||||
combat: true,
|
||||
enemy: 'sniper',
|
||||
enemyName: _('sniper'),
|
||||
deathMessage: _('the sniper is dead'),
|
||||
chara: 'S',
|
||||
damage: 15,
|
||||
hit: 0.8,
|
||||
attackDelay: 4,
|
||||
health: 30,
|
||||
ranged: true,
|
||||
loot: {
|
||||
'cloth': {
|
||||
min: 5,
|
||||
max: 10,
|
||||
chance: 0.8
|
||||
},
|
||||
'bullets': {
|
||||
min: 1,
|
||||
max: 5,
|
||||
chance: 0.5
|
||||
},
|
||||
'rifle': {
|
||||
min: 1,
|
||||
max: 1,
|
||||
chance: 0.2
|
||||
},
|
||||
'medicine': {
|
||||
min: 1,
|
||||
max: 2,
|
||||
chance: 0.1
|
||||
}
|
||||
},
|
||||
notification: _('a shot rings out, from somewhere in the long grass')
|
||||
}
|
||||
}
|
||||
}
|
||||
];
|
||||
/**
|
||||
* Events that can occur when wandering around the world
|
||||
**/
|
||||
Events.Encounters = [
|
||||
/* Tier 1 */
|
||||
{ /* Snarling Beast */
|
||||
title: _('A Snarling Beast'),
|
||||
isAvailable: function() {
|
||||
return World.getDistance() <= 10 && World.getTerrain() == World.TILE.FOREST;
|
||||
},
|
||||
scenes: {
|
||||
'start': {
|
||||
combat: true,
|
||||
enemy: 'snarling beast',
|
||||
enemyName: _('snarling beast'),
|
||||
deathMessage: _('the snarling beast is dead'),
|
||||
chara: 'B',
|
||||
damage: 1,
|
||||
hit: 0.8,
|
||||
attackDelay: 1,
|
||||
health: 5,
|
||||
loot: {
|
||||
'fur': {
|
||||
min: 1,
|
||||
max: 3,
|
||||
chance: 1
|
||||
},
|
||||
'meat': {
|
||||
min: 1,
|
||||
max: 3,
|
||||
chance: 1
|
||||
},
|
||||
'teeth': {
|
||||
min: 1,
|
||||
max: 3,
|
||||
chance: 0.8
|
||||
}
|
||||
},
|
||||
notification: _('a snarling beast leaps out of the underbrush')
|
||||
}
|
||||
}
|
||||
},
|
||||
{ /* Gaunt Man */
|
||||
title: _('A Gaunt Man'),
|
||||
isAvailable: function() {
|
||||
return World.getDistance() <= 10 && World.getTerrain() == World.TILE.BARRENS;
|
||||
},
|
||||
scenes: {
|
||||
'start': {
|
||||
combat: true,
|
||||
enemy: 'gaunt man',
|
||||
enemyName: _('gaunt man'),
|
||||
deathMessage: _('the gaunt man is dead'),
|
||||
chara: 'G',
|
||||
damage: 2,
|
||||
hit: 0.8,
|
||||
attackDelay: 2,
|
||||
health: 6,
|
||||
loot: {
|
||||
'cloth': {
|
||||
min: 1,
|
||||
max: 3,
|
||||
chance: 0.8
|
||||
},
|
||||
'teeth': {
|
||||
min: 1,
|
||||
max: 2,
|
||||
chance: 0.8
|
||||
},
|
||||
'leather': {
|
||||
min: 1,
|
||||
max: 2,
|
||||
chance: 0.5
|
||||
}
|
||||
},
|
||||
notification: _('a gaunt man approaches, a crazed look in his eye')
|
||||
}
|
||||
}
|
||||
},
|
||||
{ /* Strange Bird */
|
||||
title: _('A Strange Bird'),
|
||||
isAvailable: function() {
|
||||
return World.getDistance() <= 10 && World.getTerrain() == World.TILE.FIELD;
|
||||
},
|
||||
scenes: {
|
||||
'start': {
|
||||
combat: true,
|
||||
enemy: 'strange bird',
|
||||
enemyName: _('strange bird'),
|
||||
deathMessage: _('the strange bird is dead'),
|
||||
chara: 'B',
|
||||
damage: 3,
|
||||
hit: 0.8,
|
||||
attackDelay: 2,
|
||||
health: 4,
|
||||
loot: {
|
||||
'scales': {
|
||||
min: 1,
|
||||
max: 3,
|
||||
chance: 0.8
|
||||
},
|
||||
'teeth': {
|
||||
min: 1,
|
||||
max: 2,
|
||||
chance: 0.5
|
||||
},
|
||||
'meat': {
|
||||
min: 1,
|
||||
max: 3,
|
||||
chance: 0.8
|
||||
}
|
||||
},
|
||||
notification: _('a strange looking bird speeds across the plains')
|
||||
}
|
||||
}
|
||||
},
|
||||
/* Tier 2*/
|
||||
{ /* Shivering Man */
|
||||
title: _('A Shivering Man'),
|
||||
isAvailable: function() {
|
||||
return World.getDistance() > 10 && World.getDistance() <= 20 && World.getTerrain() == World.TILE.BARRENS;
|
||||
},
|
||||
scenes: {
|
||||
'start': {
|
||||
combat: true,
|
||||
enemy: 'shivering man',
|
||||
enemyName: _('shivering man'),
|
||||
deathMessage: _('the shivering man is dead'),
|
||||
chara: 'S',
|
||||
damage: 5,
|
||||
hit: 0.5,
|
||||
attackDelay: 1,
|
||||
health: 20,
|
||||
loot: {
|
||||
'cloth': {
|
||||
min: 1,
|
||||
max: 1,
|
||||
chance: 0.2
|
||||
},
|
||||
'teeth': {
|
||||
min: 1,
|
||||
max: 2,
|
||||
chance: 0.8
|
||||
},
|
||||
'leather': {
|
||||
min: 1,
|
||||
max: 1,
|
||||
chance: 0.2
|
||||
},
|
||||
'medicine': {
|
||||
min: 1,
|
||||
max: 3,
|
||||
chance: 0.7
|
||||
}
|
||||
},
|
||||
notification: _('a shivering man approaches and attacks with surprising strength')
|
||||
}
|
||||
}
|
||||
},
|
||||
{ /* Man-eater */
|
||||
title: _('A Man-Eater'),
|
||||
isAvailable: function() {
|
||||
return World.getDistance() > 10 && World.getDistance() <= 20 && World.getTerrain() == World.TILE.FOREST;
|
||||
},
|
||||
scenes: {
|
||||
'start': {
|
||||
combat: true,
|
||||
enemy: 'man-eater',
|
||||
enemyName: _('man-eater'),
|
||||
deathMessage: _('the man-eater is dead'),
|
||||
chara: 'E',
|
||||
damage: 3,
|
||||
hit: 0.8,
|
||||
attackDelay: 1,
|
||||
health: 25,
|
||||
loot: {
|
||||
'fur': {
|
||||
min: 5,
|
||||
max: 10,
|
||||
chance: 1
|
||||
},
|
||||
'meat': {
|
||||
min: 5,
|
||||
max: 10,
|
||||
chance: 1
|
||||
},
|
||||
'teeth': {
|
||||
min: 5,
|
||||
max: 10,
|
||||
chance: 0.8
|
||||
}
|
||||
},
|
||||
notification: _('a large creature attacks, claws freshly bloodied')
|
||||
}
|
||||
}
|
||||
},
|
||||
{ /* Scavenger */
|
||||
title: _('A Scavenger'),
|
||||
isAvailable: function() {
|
||||
return World.getDistance() > 10 && World.getDistance() <= 20 && World.getTerrain() == World.TILE.BARRENS;
|
||||
},
|
||||
scenes: {
|
||||
'start': {
|
||||
combat: true,
|
||||
enemy: 'scavenger',
|
||||
enemyName: _('scavenger'),
|
||||
deathMessage: _('the scavenger is dead'),
|
||||
chara: 'S',
|
||||
damage: 4,
|
||||
hit: 0.8,
|
||||
attackDelay: 2,
|
||||
health: 30,
|
||||
loot: {
|
||||
'cloth': {
|
||||
min: 5,
|
||||
max: 10,
|
||||
chance: 0.8
|
||||
},
|
||||
'leather': {
|
||||
min: 5,
|
||||
max: 10,
|
||||
chance: 0.8
|
||||
},
|
||||
'iron': {
|
||||
min: 1,
|
||||
max: 5,
|
||||
chance: 0.5
|
||||
},
|
||||
'medicine': {
|
||||
min: 1,
|
||||
max: 2,
|
||||
chance: 0.1
|
||||
}
|
||||
},
|
||||
notification: _('a scavenger draws close, hoping for an easy score')
|
||||
}
|
||||
}
|
||||
},
|
||||
{ /* Huge Lizard */
|
||||
title: _('A Huge Lizard'),
|
||||
isAvailable: function() {
|
||||
return World.getDistance() > 10 && World.getDistance() <= 20 && World.getTerrain() == World.TILE.FIELD;
|
||||
},
|
||||
scenes: {
|
||||
'start': {
|
||||
combat: true,
|
||||
enemy: 'lizard',
|
||||
enemyName: _('lizard'),
|
||||
deathMessage: _('the lizard is dead'),
|
||||
chara: 'L',
|
||||
damage: 5,
|
||||
hit: 0.8,
|
||||
attackDelay: 2,
|
||||
health: 20,
|
||||
loot: {
|
||||
'scales': {
|
||||
min: 5,
|
||||
max: 10,
|
||||
chance: 0.8
|
||||
},
|
||||
'teeth': {
|
||||
min: 5,
|
||||
max: 10,
|
||||
chance: 0.5
|
||||
},
|
||||
'meat': {
|
||||
min: 5,
|
||||
max: 10,
|
||||
chance: 0.8
|
||||
}
|
||||
},
|
||||
notification: _('the grass thrashes wildly as a huge lizard pushes through')
|
||||
}
|
||||
}
|
||||
},
|
||||
/* Tier 3*/
|
||||
{ /* Feral Terror */
|
||||
title: _('A Feral Terror'),
|
||||
isAvailable: function() {
|
||||
return World.getDistance() > 20 && World.getTerrain() == World.TILE.FOREST;
|
||||
},
|
||||
scenes: {
|
||||
'start': {
|
||||
combat: true,
|
||||
enemy: 'feral terror',
|
||||
enemyName: _('feral terror'),
|
||||
deathMessage: _('the feral terror is dead'),
|
||||
chara: 'F',
|
||||
damage: 6,
|
||||
hit: 0.8,
|
||||
attackDelay: 1,
|
||||
health: 45,
|
||||
loot: {
|
||||
'fur': {
|
||||
min: 5,
|
||||
max: 10,
|
||||
chance: 1
|
||||
},
|
||||
'meat': {
|
||||
min: 5,
|
||||
max: 10,
|
||||
chance: 1
|
||||
},
|
||||
'teeth': {
|
||||
min: 5,
|
||||
max: 10,
|
||||
chance: 0.8
|
||||
}
|
||||
},
|
||||
notification: _('a beast, wilder than imagining, erupts out of the foliage')
|
||||
}
|
||||
}
|
||||
},
|
||||
{ /* Soldier */
|
||||
title: _('A Soldier'),
|
||||
isAvailable: function() {
|
||||
return World.getDistance() > 20 && World.getTerrain() == World.TILE.BARRENS;
|
||||
},
|
||||
scenes: {
|
||||
'start': {
|
||||
combat: true,
|
||||
enemy: 'soldier',
|
||||
enemyName: _('soldier'),
|
||||
deathMessage: _('the soldier is dead'),
|
||||
ranged: true,
|
||||
chara: 'D',
|
||||
damage: 8,
|
||||
hit: 0.8,
|
||||
attackDelay: 2,
|
||||
health: 50,
|
||||
loot: {
|
||||
'cloth': {
|
||||
min: 5,
|
||||
max: 10,
|
||||
chance: 0.8
|
||||
},
|
||||
'bullets': {
|
||||
min: 1,
|
||||
max: 5,
|
||||
chance: 0.5
|
||||
},
|
||||
'rifle': {
|
||||
min: 1,
|
||||
max: 1,
|
||||
chance: 0.2
|
||||
},
|
||||
'medicine': {
|
||||
min: 1,
|
||||
max: 2,
|
||||
chance: 0.1
|
||||
}
|
||||
},
|
||||
notification: _('a soldier opens fire from across the desert')
|
||||
}
|
||||
}
|
||||
},
|
||||
{ /* Sniper */
|
||||
title: _('A Sniper'),
|
||||
isAvailable: function() {
|
||||
return World.getDistance() > 20 && World.getTerrain() == World.TILE.FIELD;
|
||||
},
|
||||
scenes: {
|
||||
'start': {
|
||||
combat: true,
|
||||
enemy: 'sniper',
|
||||
enemyName: _('sniper'),
|
||||
deathMessage: _('the sniper is dead'),
|
||||
chara: 'S',
|
||||
damage: 15,
|
||||
hit: 0.8,
|
||||
attackDelay: 4,
|
||||
health: 30,
|
||||
ranged: true,
|
||||
loot: {
|
||||
'cloth': {
|
||||
min: 5,
|
||||
max: 10,
|
||||
chance: 0.8
|
||||
},
|
||||
'bullets': {
|
||||
min: 1,
|
||||
max: 5,
|
||||
chance: 0.5
|
||||
},
|
||||
'rifle': {
|
||||
min: 1,
|
||||
max: 1,
|
||||
chance: 0.2
|
||||
},
|
||||
'medicine': {
|
||||
min: 1,
|
||||
max: 2,
|
||||
chance: 0.1
|
||||
}
|
||||
},
|
||||
notification: _('a shot rings out, from somewhere in the long grass')
|
||||
}
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
+66
-66
@@ -1,66 +1,66 @@
|
||||
/**
|
||||
* Events that can occur when any module is active (Except World. It's special.)
|
||||
**/
|
||||
Events.Global = [
|
||||
{ /* The Thief */
|
||||
title: _('The Thief'),
|
||||
isAvailable: function() {
|
||||
return (Engine.activeModule == Room || Engine.activeModule == Outside) && $SM.get('game.thieves') == 1;
|
||||
},
|
||||
scenes: {
|
||||
'start': {
|
||||
text: [
|
||||
_('the villagers haul a filthy man out of the store room.'),
|
||||
_("say his folk have been skimming the supplies."),
|
||||
_('say he should be strung up as an example.')
|
||||
],
|
||||
notification: _('a thief is caught'),
|
||||
blink: true,
|
||||
buttons: {
|
||||
'kill': {
|
||||
text: _('hang him'),
|
||||
nextScene: {1: 'hang'}
|
||||
},
|
||||
'spare': {
|
||||
text: _('spare him'),
|
||||
nextScene: {1: 'spare'}
|
||||
}
|
||||
}
|
||||
},
|
||||
'hang': {
|
||||
text: [
|
||||
_('the villagers hang the thief high in front of the store room.'),
|
||||
_('the point is made. in the next few days, the missing supplies are returned.')
|
||||
],
|
||||
onLoad: function() {
|
||||
$SM.set('game.thieves', 2);
|
||||
$SM.remove('income.thieves');
|
||||
$SM.addM('stores', $SM.get('game.stolen'));
|
||||
},
|
||||
buttons: {
|
||||
'leave': {
|
||||
text: _('leave'),
|
||||
nextScene: 'end'
|
||||
}
|
||||
}
|
||||
},
|
||||
'spare': {
|
||||
text: [
|
||||
_("the man says he's grateful. says he won't come around any more."),
|
||||
_("shares what he knows about sneaking before he goes.")
|
||||
],
|
||||
onLoad: function() {
|
||||
$SM.set('game.thieves', 2);
|
||||
$SM.remove('income.thieves');
|
||||
$SM.addPerk('stealthy');
|
||||
},
|
||||
buttons: {
|
||||
'leave': {
|
||||
text: _('leave'),
|
||||
nextScene: 'end'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
];
|
||||
/**
|
||||
* Events that can occur when any module is active (Except World. It's special.)
|
||||
**/
|
||||
Events.Global = [
|
||||
{ /* The Thief */
|
||||
title: _('The Thief'),
|
||||
isAvailable: function() {
|
||||
return (Engine.activeModule == Room || Engine.activeModule == Outside) && $SM.get('game.thieves') == 1;
|
||||
},
|
||||
scenes: {
|
||||
'start': {
|
||||
text: [
|
||||
_('the villagers haul a filthy man out of the store room.'),
|
||||
_("say his folk have been skimming the supplies."),
|
||||
_('say he should be strung up as an example.')
|
||||
],
|
||||
notification: _('a thief is caught'),
|
||||
blink: true,
|
||||
buttons: {
|
||||
'kill': {
|
||||
text: _('hang him'),
|
||||
nextScene: {1: 'hang'}
|
||||
},
|
||||
'spare': {
|
||||
text: _('spare him'),
|
||||
nextScene: {1: 'spare'}
|
||||
}
|
||||
}
|
||||
},
|
||||
'hang': {
|
||||
text: [
|
||||
_('the villagers hang the thief high in front of the store room.'),
|
||||
_('the point is made. in the next few days, the missing supplies are returned.')
|
||||
],
|
||||
onLoad: function() {
|
||||
$SM.set('game.thieves', 2);
|
||||
$SM.remove('income.thieves');
|
||||
$SM.addM('stores', $SM.get('game.stolen'));
|
||||
},
|
||||
buttons: {
|
||||
'leave': {
|
||||
text: _('leave'),
|
||||
nextScene: 'end'
|
||||
}
|
||||
}
|
||||
},
|
||||
'spare': {
|
||||
text: [
|
||||
_("the man says he's grateful. says he won't come around any more."),
|
||||
_("shares what he knows about sneaking before he goes.")
|
||||
],
|
||||
onLoad: function() {
|
||||
$SM.set('game.thieves', 2);
|
||||
$SM.remove('income.thieves');
|
||||
$SM.addPerk('stealthy');
|
||||
},
|
||||
buttons: {
|
||||
'leave': {
|
||||
text: _('leave'),
|
||||
nextScene: 'end'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
+3574
-3574
File diff suppressed because it is too large
Load Diff
+27
-27
@@ -1,28 +1,28 @@
|
||||
/**
|
||||
* Module that takes care of header buttons
|
||||
*/
|
||||
var Header = {
|
||||
|
||||
init: function(options) {
|
||||
this.options = $.extend(
|
||||
this.options,
|
||||
options
|
||||
);
|
||||
},
|
||||
|
||||
options: {}, // Nothing for now
|
||||
|
||||
canTravel: function() {
|
||||
return $('div#header div.headerButton').length > 1;
|
||||
},
|
||||
|
||||
addLocation: function(text, id, module) {
|
||||
return $('<div>').attr('id', "location_" + id)
|
||||
.addClass('headerButton')
|
||||
.text(text).click(function() {
|
||||
if(Header.canTravel()) {
|
||||
Engine.travelTo(module);
|
||||
}
|
||||
}).appendTo($('div#header'));
|
||||
}
|
||||
/**
|
||||
* Module that takes care of header buttons
|
||||
*/
|
||||
var Header = {
|
||||
|
||||
init: function(options) {
|
||||
this.options = $.extend(
|
||||
this.options,
|
||||
options
|
||||
);
|
||||
},
|
||||
|
||||
options: {}, // Nothing for now
|
||||
|
||||
canTravel: function() {
|
||||
return $('div#header div.headerButton').length > 1;
|
||||
},
|
||||
|
||||
addLocation: function(text, id, module) {
|
||||
return $('<div>').attr('id', "location_" + id)
|
||||
.addClass('headerButton')
|
||||
.text(text).click(function() {
|
||||
if(Header.canTravel()) {
|
||||
Engine.travelTo(module);
|
||||
}
|
||||
}).appendTo($('div#header'));
|
||||
}
|
||||
};
|
||||
+34
-1
@@ -4,6 +4,7 @@
|
||||
var Outside = {
|
||||
name: _("Outside"),
|
||||
|
||||
_STORES_OFFSET: 0,
|
||||
_GATHER_DELAY: 60,
|
||||
_TRAPS_DELAY: 90,
|
||||
_POP_DELAY: [0.5, 3],
|
||||
@@ -439,7 +440,7 @@ var Outside = {
|
||||
this.setTitle();
|
||||
|
||||
if(!ignoreStores && Engine.activeModule === Outside && village.children().length > 1) {
|
||||
$('#storesContainer').css({top: village.height() + 26 + 'px'});
|
||||
$('#storesContainer').css({top: village.height() + 26 + Outside._STORES_OFFSET + 'px'});
|
||||
}
|
||||
},
|
||||
|
||||
@@ -610,6 +611,38 @@ var Outside = {
|
||||
Outside.updateVillage();
|
||||
Outside.updateWorkersView();
|
||||
Outside.updateVillageIncome();
|
||||
};
|
||||
},
|
||||
|
||||
scrollSidebar: function(direction, reset) {
|
||||
|
||||
if( typeof reset != "undefined" ){
|
||||
$('#village').css('top', '0px');
|
||||
$('#storesContainer').css('top', '224px');
|
||||
Outside._STORES_OFFSET = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
var momentum = 10;
|
||||
|
||||
// If they hit up, we scroll everything down
|
||||
if( direction == 'up' )
|
||||
momentum = momentum * -1;
|
||||
|
||||
/* Let's stop scrolling if the top or bottom bound is in the viewport, based on direction */
|
||||
if( direction == 'down' && inView( direction, $('#village') ) ){
|
||||
|
||||
return false;
|
||||
|
||||
}else if( direction == 'up' && inView( direction, $('#storesContainer') ) ){
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
scrollByX( $('#village'), momentum );
|
||||
scrollByX( $('#storesContainer'), momentum );
|
||||
Outside._STORES_OFFSET += momentum;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
+32
-2
@@ -1,7 +1,7 @@
|
||||
var Path = {
|
||||
|
||||
DEFAULT_BAG_SPACE: 10,
|
||||
|
||||
_STORES_OFFSET: 0,
|
||||
// Everything not in this list weighs 1
|
||||
Weight: {
|
||||
'bone spear': 2,
|
||||
@@ -116,7 +116,7 @@ var Path = {
|
||||
}
|
||||
|
||||
if(!ignoreStores && Engine.activeModule === Path) {
|
||||
$('#storesContainer').css({top: perks.height() + 26 + 'px'});
|
||||
$('#storesContainer').css({top: perks.height() + 26 + Path._STORES_OFFSET + 'px'});
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -312,6 +312,36 @@ var Path = {
|
||||
handleStateUpdates: function(e){
|
||||
if(e.category == 'character' && e.stateName.indexOf('character.perks') === 0 && Engine.activeModule == Path){
|
||||
Path.updatePerks();
|
||||
};
|
||||
},
|
||||
|
||||
scrollSidebar: function(direction, reset){
|
||||
|
||||
if( typeof reset != "undefined" ){
|
||||
$('#perks').css('top', '0px');
|
||||
$('#storesContainer').css('top', '206px');
|
||||
Path._STORES_OFFSET = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
var momentum = 10;
|
||||
|
||||
if( direction == 'up' )
|
||||
momentum = momentum * -1
|
||||
|
||||
if( direction == 'down' && inView( direction, $('#perks') ) ){
|
||||
|
||||
return false;
|
||||
|
||||
}else if( direction == 'up' && inView( direction, $('#storesContainer') ) ){
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
scrollByX( $('#perks'), momentum );
|
||||
scrollByX( $('#storesContainer'), momentum );
|
||||
Path._STORES_OFFSET += momentum;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
+173
-173
@@ -1,174 +1,174 @@
|
||||
/**
|
||||
* Module that registers the starship!
|
||||
*/
|
||||
var Ship = {
|
||||
LIFTOFF_COOLDOWN: 120,
|
||||
ALLOY_PER_HULL: 1,
|
||||
ALLOY_PER_THRUSTER: 1,
|
||||
BASE_HULL: 0,
|
||||
BASE_THRUSTERS: 1,
|
||||
|
||||
name: _("Ship"),
|
||||
init: function(options) {
|
||||
this.options = $.extend(
|
||||
this.options,
|
||||
options
|
||||
);
|
||||
|
||||
if(!$SM.get('features.location.spaceShip')) {
|
||||
$SM.set('features.location.spaceShip', true);
|
||||
$SM.setM('game.spaceShip', {
|
||||
hull: Ship.BASE_HULL,
|
||||
thrusters: Ship.BASE_THRUSTERS
|
||||
});
|
||||
}
|
||||
|
||||
// Create the Ship tab
|
||||
this.tab = Header.addLocation(_("An Old Starship"), "ship", Ship);
|
||||
|
||||
// Create the Ship panel
|
||||
this.panel = $('<div>').attr('id', "shipPanel")
|
||||
.addClass('location')
|
||||
.appendTo('div#locationSlider');
|
||||
|
||||
Engine.updateSlider();
|
||||
|
||||
// Draw the hull label
|
||||
var hullRow = $('<div>').attr('id', 'hullRow').appendTo('div#shipPanel');
|
||||
$('<div>').addClass('row_key').text(_('hull:')).appendTo(hullRow);
|
||||
$('<div>').addClass('row_val').text($SM.get('game.spaceShip.hull')).appendTo(hullRow);
|
||||
$('<div>').addClass('clear').appendTo(hullRow);
|
||||
|
||||
// Draw the thrusters label
|
||||
var engineRow = $('<div>').attr('id', 'engineRow').appendTo('div#shipPanel');
|
||||
$('<div>').addClass('row_key').text(_('engine:')).appendTo(engineRow);
|
||||
$('<div>').addClass('row_val').text($SM.get('game.spaceShip.thrusters')).appendTo(engineRow);
|
||||
$('<div>').addClass('clear').appendTo(engineRow);
|
||||
|
||||
// Draw the reinforce button
|
||||
new Button.Button({
|
||||
id: 'reinforceButton',
|
||||
text: _('reinforce hull'),
|
||||
click: Ship.reinforceHull,
|
||||
width: '100px',
|
||||
cost: {'alien alloy': Ship.ALLOY_PER_HULL}
|
||||
}).appendTo('div#shipPanel');
|
||||
|
||||
// Draw the engine button
|
||||
new Button.Button({
|
||||
id: 'engineButton',
|
||||
text: _('upgrade engine'),
|
||||
click: Ship.upgradeEngine,
|
||||
width: '100px',
|
||||
cost: {'alien alloy': Ship.ALLOY_PER_THRUSTER}
|
||||
}).appendTo('div#shipPanel');
|
||||
|
||||
// Draw the lift off button
|
||||
var b = new Button.Button({
|
||||
id: 'liftoffButton',
|
||||
text: _('lift off'),
|
||||
click: Ship.checkLiftOff,
|
||||
width: '100px',
|
||||
cooldown: Ship.LIFTOFF_COOLDOWN
|
||||
}).appendTo('div#shipPanel');
|
||||
|
||||
if($SM.get('game.spaceShip.hull') <= 0) {
|
||||
Button.setDisabled(b, true);
|
||||
}
|
||||
|
||||
// Init Space
|
||||
Space.init();
|
||||
|
||||
//subscribe to stateUpdates
|
||||
$.Dispatch('stateUpdate').subscribe(Ship.handleStateUpdates);
|
||||
},
|
||||
|
||||
options: {}, // Nothing for now
|
||||
|
||||
onArrival: function(transition_diff) {
|
||||
Ship.setTitle();
|
||||
if(!$SM.get('game.spaceShip.seenShip')) {
|
||||
Notifications.notify(Ship, _('somewhere above the debris cloud, the wanderer fleet hovers. been on this rock too long.'));
|
||||
$SM.set('game.spaceShip.seenShip', true);
|
||||
}
|
||||
|
||||
Engine.moveStoresView(null, transition_diff);
|
||||
},
|
||||
|
||||
setTitle: function() {
|
||||
if(Engine.activeModule == this) {
|
||||
document.title = "An Old Starship";
|
||||
}
|
||||
},
|
||||
|
||||
reinforceHull: function() {
|
||||
if($SM.get('stores["alien alloy"]', true) < Ship.ALLOY_PER_HULL) {
|
||||
Notifications.notify(Ship, _("not enough alien alloy"));
|
||||
return false;
|
||||
}
|
||||
$SM.add('stores["alien alloy"]', -Ship.ALLOY_PER_HULL);
|
||||
$SM.add('game.spaceShip.hull', 1);
|
||||
if($SM.get('game.spaceShip.hull') > 0) {
|
||||
Button.setDisabled($('#liftoffButton', Ship.panel), false);
|
||||
}
|
||||
$('#hullRow .row_val', Ship.panel).text($SM.get('game.spaceShip.hull'));
|
||||
},
|
||||
|
||||
upgradeEngine: function() {
|
||||
if($SM.get('stores["alien alloy"]', true) < Ship.ALLOY_PER_THRUSTER) {
|
||||
Notifications.notify(Ship, _("not enough alien alloy"));
|
||||
return false;
|
||||
}
|
||||
$SM.add('stores["alien alloy"]', -Ship.ALLOY_PER_THRUSTER);
|
||||
$SM.add('game.spaceShip.thrusters', 1);
|
||||
$('#engineRow .row_val', Ship.panel).text($SM.get('game.spaceShip.thrusters'));
|
||||
},
|
||||
|
||||
getMaxHull: function() {
|
||||
return $SM.get('game.spaceShip.hull');
|
||||
},
|
||||
|
||||
checkLiftOff: function() {
|
||||
if(!$SM.get('game.spaceShip.seenWarning')) {
|
||||
Events.startEvent({
|
||||
title: _('Ready to Leave?'),
|
||||
scenes: {
|
||||
'start': {
|
||||
text: [
|
||||
_("time to get out of this place. won't be coming back.")
|
||||
],
|
||||
buttons: {
|
||||
'fly': {
|
||||
text: _('lift off'),
|
||||
onChoose: function() {
|
||||
$SM.set('game.spaceShip.seenWarning', true);
|
||||
Ship.liftOff();
|
||||
},
|
||||
nextScene: 'end'
|
||||
},
|
||||
'wait': {
|
||||
text: _('linger'),
|
||||
onChoose: function() {
|
||||
Button.clearCooldown($('#liftoffButton'));
|
||||
},
|
||||
nextScene: 'end'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Ship.liftOff();
|
||||
}
|
||||
},
|
||||
|
||||
liftOff: function () {
|
||||
$('#outerSlider').animate({top: '700px'}, 300);
|
||||
Space.onArrival();
|
||||
Engine.activeModule = Space;
|
||||
},
|
||||
|
||||
handleStateUpdates: function(e){
|
||||
|
||||
}
|
||||
/**
|
||||
* Module that registers the starship!
|
||||
*/
|
||||
var Ship = {
|
||||
LIFTOFF_COOLDOWN: 120,
|
||||
ALLOY_PER_HULL: 1,
|
||||
ALLOY_PER_THRUSTER: 1,
|
||||
BASE_HULL: 0,
|
||||
BASE_THRUSTERS: 1,
|
||||
|
||||
name: _("Ship"),
|
||||
init: function(options) {
|
||||
this.options = $.extend(
|
||||
this.options,
|
||||
options
|
||||
);
|
||||
|
||||
if(!$SM.get('features.location.spaceShip')) {
|
||||
$SM.set('features.location.spaceShip', true);
|
||||
$SM.setM('game.spaceShip', {
|
||||
hull: Ship.BASE_HULL,
|
||||
thrusters: Ship.BASE_THRUSTERS
|
||||
});
|
||||
}
|
||||
|
||||
// Create the Ship tab
|
||||
this.tab = Header.addLocation(_("An Old Starship"), "ship", Ship);
|
||||
|
||||
// Create the Ship panel
|
||||
this.panel = $('<div>').attr('id', "shipPanel")
|
||||
.addClass('location')
|
||||
.appendTo('div#locationSlider');
|
||||
|
||||
Engine.updateSlider();
|
||||
|
||||
// Draw the hull label
|
||||
var hullRow = $('<div>').attr('id', 'hullRow').appendTo('div#shipPanel');
|
||||
$('<div>').addClass('row_key').text(_('hull:')).appendTo(hullRow);
|
||||
$('<div>').addClass('row_val').text($SM.get('game.spaceShip.hull')).appendTo(hullRow);
|
||||
$('<div>').addClass('clear').appendTo(hullRow);
|
||||
|
||||
// Draw the thrusters label
|
||||
var engineRow = $('<div>').attr('id', 'engineRow').appendTo('div#shipPanel');
|
||||
$('<div>').addClass('row_key').text(_('engine:')).appendTo(engineRow);
|
||||
$('<div>').addClass('row_val').text($SM.get('game.spaceShip.thrusters')).appendTo(engineRow);
|
||||
$('<div>').addClass('clear').appendTo(engineRow);
|
||||
|
||||
// Draw the reinforce button
|
||||
new Button.Button({
|
||||
id: 'reinforceButton',
|
||||
text: _('reinforce hull'),
|
||||
click: Ship.reinforceHull,
|
||||
width: '100px',
|
||||
cost: {'alien alloy': Ship.ALLOY_PER_HULL}
|
||||
}).appendTo('div#shipPanel');
|
||||
|
||||
// Draw the engine button
|
||||
new Button.Button({
|
||||
id: 'engineButton',
|
||||
text: _('upgrade engine'),
|
||||
click: Ship.upgradeEngine,
|
||||
width: '100px',
|
||||
cost: {'alien alloy': Ship.ALLOY_PER_THRUSTER}
|
||||
}).appendTo('div#shipPanel');
|
||||
|
||||
// Draw the lift off button
|
||||
var b = new Button.Button({
|
||||
id: 'liftoffButton',
|
||||
text: _('lift off'),
|
||||
click: Ship.checkLiftOff,
|
||||
width: '100px',
|
||||
cooldown: Ship.LIFTOFF_COOLDOWN
|
||||
}).appendTo('div#shipPanel');
|
||||
|
||||
if($SM.get('game.spaceShip.hull') <= 0) {
|
||||
Button.setDisabled(b, true);
|
||||
}
|
||||
|
||||
// Init Space
|
||||
Space.init();
|
||||
|
||||
//subscribe to stateUpdates
|
||||
$.Dispatch('stateUpdate').subscribe(Ship.handleStateUpdates);
|
||||
},
|
||||
|
||||
options: {}, // Nothing for now
|
||||
|
||||
onArrival: function(transition_diff) {
|
||||
Ship.setTitle();
|
||||
if(!$SM.get('game.spaceShip.seenShip')) {
|
||||
Notifications.notify(Ship, _('somewhere above the debris cloud, the wanderer fleet hovers. been on this rock too long.'));
|
||||
$SM.set('game.spaceShip.seenShip', true);
|
||||
}
|
||||
|
||||
Engine.moveStoresView(null, transition_diff);
|
||||
},
|
||||
|
||||
setTitle: function() {
|
||||
if(Engine.activeModule == this) {
|
||||
document.title = "An Old Starship";
|
||||
}
|
||||
},
|
||||
|
||||
reinforceHull: function() {
|
||||
if($SM.get('stores["alien alloy"]', true) < Ship.ALLOY_PER_HULL) {
|
||||
Notifications.notify(Ship, _("not enough alien alloy"));
|
||||
return false;
|
||||
}
|
||||
$SM.add('stores["alien alloy"]', -Ship.ALLOY_PER_HULL);
|
||||
$SM.add('game.spaceShip.hull', 1);
|
||||
if($SM.get('game.spaceShip.hull') > 0) {
|
||||
Button.setDisabled($('#liftoffButton', Ship.panel), false);
|
||||
}
|
||||
$('#hullRow .row_val', Ship.panel).text($SM.get('game.spaceShip.hull'));
|
||||
},
|
||||
|
||||
upgradeEngine: function() {
|
||||
if($SM.get('stores["alien alloy"]', true) < Ship.ALLOY_PER_THRUSTER) {
|
||||
Notifications.notify(Ship, _("not enough alien alloy"));
|
||||
return false;
|
||||
}
|
||||
$SM.add('stores["alien alloy"]', -Ship.ALLOY_PER_THRUSTER);
|
||||
$SM.add('game.spaceShip.thrusters', 1);
|
||||
$('#engineRow .row_val', Ship.panel).text($SM.get('game.spaceShip.thrusters'));
|
||||
},
|
||||
|
||||
getMaxHull: function() {
|
||||
return $SM.get('game.spaceShip.hull');
|
||||
},
|
||||
|
||||
checkLiftOff: function() {
|
||||
if(!$SM.get('game.spaceShip.seenWarning')) {
|
||||
Events.startEvent({
|
||||
title: _('Ready to Leave?'),
|
||||
scenes: {
|
||||
'start': {
|
||||
text: [
|
||||
_("time to get out of this place. won't be coming back.")
|
||||
],
|
||||
buttons: {
|
||||
'fly': {
|
||||
text: _('lift off'),
|
||||
onChoose: function() {
|
||||
$SM.set('game.spaceShip.seenWarning', true);
|
||||
Ship.liftOff();
|
||||
},
|
||||
nextScene: 'end'
|
||||
},
|
||||
'wait': {
|
||||
text: _('linger'),
|
||||
onChoose: function() {
|
||||
Button.clearCooldown($('#liftoffButton'));
|
||||
},
|
||||
nextScene: 'end'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Ship.liftOff();
|
||||
}
|
||||
},
|
||||
|
||||
liftOff: function () {
|
||||
$('#outerSlider').animate({top: '700px'}, 300);
|
||||
Space.onArrival();
|
||||
Engine.activeModule = Space;
|
||||
},
|
||||
|
||||
handleStateUpdates: function(e){
|
||||
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user