mirror of
https://github.com/doublespeakgames/adarkroom.git
synced 2026-06-25 22:02:30 +08:00
Add missing Hyper Mode pieces
Some code was missing from the Hyper Mode feature addition. This completes the use of `Engine.setTimeout` and adds doubleTime check in button cooldowns. Closes #374
This commit is contained in:
+17
-12
@@ -7,12 +7,12 @@ var Button = {
|
|||||||
if(typeof options.click == 'function') {
|
if(typeof options.click == 'function') {
|
||||||
this.data_handler = options.click;
|
this.data_handler = options.click;
|
||||||
}
|
}
|
||||||
|
|
||||||
var el = $('<div>')
|
var el = $('<div>')
|
||||||
.attr('id', typeof(options.id) != 'undefined' ? options.id : "BTN_" + Engine.getGuid())
|
.attr('id', typeof(options.id) != 'undefined' ? options.id : "BTN_" + Engine.getGuid())
|
||||||
.addClass('button')
|
.addClass('button')
|
||||||
.text(typeof(options.text) != 'undefined' ? options.text : "button")
|
.text(typeof(options.text) != 'undefined' ? options.text : "button")
|
||||||
.click(function() {
|
.click(function() {
|
||||||
if(!$(this).hasClass('disabled')) {
|
if(!$(this).hasClass('disabled')) {
|
||||||
Button.cooldown($(this));
|
Button.cooldown($(this));
|
||||||
$(this).data("handler")($(this));
|
$(this).data("handler")($(this));
|
||||||
@@ -21,9 +21,9 @@ var Button = {
|
|||||||
.data("handler", typeof options.click == 'function' ? options.click : function() { Engine.log("click"); })
|
.data("handler", typeof options.click == 'function' ? options.click : function() { Engine.log("click"); })
|
||||||
.data("remaining", 0)
|
.data("remaining", 0)
|
||||||
.data("cooldown", typeof options.cooldown == 'number' ? options.cooldown : 0);
|
.data("cooldown", typeof options.cooldown == 'number' ? options.cooldown : 0);
|
||||||
|
|
||||||
el.append($("<div>").addClass('cooldown'));
|
el.append($("<div>").addClass('cooldown'));
|
||||||
|
|
||||||
if(options.cost) {
|
if(options.cost) {
|
||||||
var ttPos = options.ttPos ? options.ttPos : "bottom right";
|
var ttPos = options.ttPos ? options.ttPos : "bottom right";
|
||||||
var costTooltip = $('<div>').addClass('tooltip ' + ttPos);
|
var costTooltip = $('<div>').addClass('tooltip ' + ttPos);
|
||||||
@@ -35,14 +35,14 @@ var Button = {
|
|||||||
costTooltip.appendTo(el);
|
costTooltip.appendTo(el);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(options.width) {
|
if(options.width) {
|
||||||
el.css('width', options.width);
|
el.css('width', options.width);
|
||||||
}
|
}
|
||||||
|
|
||||||
return el;
|
return el;
|
||||||
},
|
},
|
||||||
|
|
||||||
setDisabled: function(btn, disabled) {
|
setDisabled: function(btn, disabled) {
|
||||||
if(btn) {
|
if(btn) {
|
||||||
if(!disabled && !btn.data('onCooldown')) {
|
if(!disabled && !btn.data('onCooldown')) {
|
||||||
@@ -53,18 +53,23 @@ var Button = {
|
|||||||
btn.data('disabled', disabled);
|
btn.data('disabled', disabled);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
isDisabled: function(btn) {
|
isDisabled: function(btn) {
|
||||||
if(btn) {
|
if(btn) {
|
||||||
return btn.data('disabled') === true;
|
return btn.data('disabled') === true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
cooldown: function(btn) {
|
cooldown: function(btn) {
|
||||||
var cd = btn.data("cooldown");
|
var cd = btn.data("cooldown");
|
||||||
if(cd > 0) {
|
if(cd > 0) {
|
||||||
$('div.cooldown', btn).stop(true, true).width("100%").animate({width: '0%'}, cd * 1000, 'linear', function() {
|
milliseconds = cd * 1000;
|
||||||
|
if (Engine.options.doubleTime){
|
||||||
|
milliseconds /= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
$('div.cooldown', btn).stop(true, true).width("100%").animate({width: '0%'}, milliseconds, 'linear', function() {
|
||||||
var b = $(this).closest('.button');
|
var b = $(this).closest('.button');
|
||||||
b.data('onCooldown', false);
|
b.data('onCooldown', false);
|
||||||
if(!b.data('disabled')) {
|
if(!b.data('disabled')) {
|
||||||
@@ -75,7 +80,7 @@ var Button = {
|
|||||||
btn.data('onCooldown', true);
|
btn.data('onCooldown', true);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
clearCooldown: function(btn) {
|
clearCooldown: function(btn) {
|
||||||
$('div.cooldown', btn).stop(true, true);
|
$('div.cooldown', btn).stop(true, true);
|
||||||
btn.data('onCooldown', false);
|
btn.data('onCooldown', false);
|
||||||
@@ -83,4 +88,4 @@ var Button = {
|
|||||||
btn.removeClass('disabled');
|
btn.removeClass('disabled');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
+2
-2
@@ -121,7 +121,7 @@
|
|||||||
onChoose: function () {
|
onChoose: function () {
|
||||||
DropboxConnector.log('Save to slot ' + n + ' initiated');
|
DropboxConnector.log('Save to slot ' + n + ' initiated');
|
||||||
// timeout prevents error due to fade out animation of the previous event
|
// timeout prevents error due to fade out animation of the previous event
|
||||||
window.setTimeout(function () {
|
Engine.setTimeout(function () {
|
||||||
DropboxConnector.log('Save to slot ' + n);
|
DropboxConnector.log('Save to slot ' + n);
|
||||||
DropboxConnector.saveGameToDropbox(n, DropboxConnector.savedtoDropboxEvent);
|
DropboxConnector.saveGameToDropbox(n, DropboxConnector.savedtoDropboxEvent);
|
||||||
}, 1000);
|
}, 1000);
|
||||||
@@ -150,7 +150,7 @@
|
|||||||
onChoose: function () {
|
onChoose: function () {
|
||||||
DropboxConnector.log('Load from slot ' + n + ' initiated');
|
DropboxConnector.log('Load from slot ' + n + ' initiated');
|
||||||
// timeout prevents error due to fade out animation of the previous event
|
// timeout prevents error due to fade out animation of the previous event
|
||||||
window.setTimeout(function () {
|
Engine.setTimeout(function () {
|
||||||
DropboxConnector.log('Load from slot ' + n);
|
DropboxConnector.log('Load from slot ' + n);
|
||||||
DropboxConnector.loadGameFromDropbox(n);
|
DropboxConnector.loadGameFromDropbox(n);
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|||||||
@@ -371,7 +371,7 @@ var StateManager = {
|
|||||||
if(changed){
|
if(changed){
|
||||||
$SM.fireUpdate('income', true);
|
$SM.fireUpdate('income', true);
|
||||||
}
|
}
|
||||||
Engine._incomeTimeout = setTimeout($SM.collectIncome, 1000);
|
Engine._incomeTimeout = Engine.setTimeout($SM.collectIncome, 1000);
|
||||||
},
|
},
|
||||||
|
|
||||||
//Thieves
|
//Thieves
|
||||||
|
|||||||
Reference in New Issue
Block a user