mirror of
https://github.com/doublespeakgames/adarkroom.git
synced 2026-05-28 00:01:54 +08:00
Hyper-proof cooldown state
Kept the distinction between "argument" time and script time. I called the latter "time" instead of "milliseconds" because, well, it's just tenth of seconds. Residual timeout is always stored in "nominal" time, not adjusted by hyper. I.e. if a button has a nominal timeout of 60 seconds and half cooldown had expired on reload, residual is stored as 300. In cooldown, Engine.setInterval makes the time flow with double speed
This commit is contained in:
committed by
Blake Grotewold
parent
a923c1c0bd
commit
65d7cfd784
+46
-13
@@ -24,6 +24,9 @@ var Button = {
|
||||
|
||||
el.append($("<div>").addClass('cooldown'));
|
||||
|
||||
// waiting for expiry of residual cooldown detected in state
|
||||
Button.cooldown(el, 'state');
|
||||
|
||||
if(options.cost) {
|
||||
var ttPos = options.ttPos ? options.ttPos : "bottom right";
|
||||
var costTooltip = $('<div>').addClass('tooltip ' + ttPos);
|
||||
@@ -43,6 +46,8 @@ var Button = {
|
||||
return el;
|
||||
},
|
||||
|
||||
saveCooldown: true,
|
||||
|
||||
setDisabled: function(btn, disabled) {
|
||||
if(btn) {
|
||||
if(!disabled && !btn.data('onCooldown')) {
|
||||
@@ -61,29 +66,57 @@ var Button = {
|
||||
return false;
|
||||
},
|
||||
|
||||
cooldown: function(btn) {
|
||||
cooldown: function(btn, option) {
|
||||
var cd = btn.data("cooldown");
|
||||
var id = 'cooldown.'+ btn.attr('id');
|
||||
if(cd > 0) {
|
||||
milliseconds = cd * 1000;
|
||||
if (Engine.options.doubleTime){
|
||||
milliseconds /= 2;
|
||||
// param "start" takes value from cooldown time if not specified
|
||||
var start, left;
|
||||
switch(option){
|
||||
// a switch will allow for several uses of cooldown function
|
||||
case 'state':
|
||||
if(!$SM.get(id)){
|
||||
return;
|
||||
}
|
||||
start = Math.min($SM.get(id), cd);
|
||||
left = (start / cd).toFixed(4);
|
||||
break;
|
||||
default:
|
||||
start = cd;
|
||||
left = 1;
|
||||
}
|
||||
|
||||
$('div.cooldown', btn).stop(true, true).width("100%").animate({width: '0%'}, milliseconds, 'linear', function() {
|
||||
var b = $(this).closest('.button');
|
||||
b.data('onCooldown', false);
|
||||
if(!b.data('disabled')) {
|
||||
b.removeClass('disabled');
|
||||
}
|
||||
Button.clearCooldown(btn);
|
||||
if(Button.saveCooldown){
|
||||
$SM.set(id,start);
|
||||
// residual value is measured in seconds
|
||||
// saves program performance
|
||||
btn.data('countdown', Engine.setInterval(function(){
|
||||
$SM.set(id, $SM.get(id, true) - 0.5, true);
|
||||
},500));
|
||||
}
|
||||
var time = start;
|
||||
if (Engine.options.doubleTime){
|
||||
time /= 2;
|
||||
}
|
||||
$('div.cooldown', btn).width(left * 100 +"%").animate({width: '0%'}, time * 1000, 'linear', function() {
|
||||
Button.clearCooldown(btn, true);
|
||||
});
|
||||
btn.addClass('disabled');
|
||||
btn.data('onCooldown', true);
|
||||
}
|
||||
},
|
||||
|
||||
clearCooldown: function(btn) {
|
||||
$('div.cooldown', btn).stop(true, true);
|
||||
clearCooldown: function(btn, ended) {
|
||||
var ended = ended || false;
|
||||
if(!ended){
|
||||
$('div.cooldown', btn).stop(true, true);
|
||||
}
|
||||
btn.data('onCooldown', false);
|
||||
if(btn.data('countdown')){
|
||||
window.clearInterval(btn.data('countdown'));
|
||||
$SM.remove('cooldown.'+ btn.attr('id'));
|
||||
btn.removeData('countdown');
|
||||
}
|
||||
if(!btn.data('disabled')) {
|
||||
btn.removeClass('disabled');
|
||||
}
|
||||
|
||||
@@ -955,6 +955,7 @@ var Events = {
|
||||
Engine.event('game event', 'event');
|
||||
Engine.keyLock = true;
|
||||
Engine.tabNavigation = false;
|
||||
Button.saveCooldown = false;
|
||||
Events.eventStack.unshift(event);
|
||||
event.eventPanel = $('<div>').attr('id', 'event').addClass('eventPanel').css('opacity', '0');
|
||||
if(options != null && options.width != null) {
|
||||
@@ -988,6 +989,7 @@ var Events = {
|
||||
Engine.log(Events.eventStack.length + ' events remaining');
|
||||
Engine.keyLock = false;
|
||||
Engine.tabNavigation = true;
|
||||
Button.saveCooldown = true;
|
||||
if (Events.BLINK_INTERVAL) {
|
||||
Events.stopTitleBlink();
|
||||
}
|
||||
|
||||
@@ -171,6 +171,8 @@ var Outside = {
|
||||
cooldown: Outside._GATHER_DELAY,
|
||||
width: '80px'
|
||||
}).appendTo('div#outsidePanel');
|
||||
|
||||
Outside.updateTrapButton();
|
||||
},
|
||||
|
||||
getMaxPopulation: function() {
|
||||
|
||||
@@ -28,17 +28,18 @@ var StateManager = {
|
||||
|
||||
//create categories
|
||||
var cats = [
|
||||
'features', //big features like buildings, location availability, unlocks, etc
|
||||
'stores', //little stuff, items, weapons, etc
|
||||
'character', //this is for player's character stats such as perks
|
||||
'features', // big features like buildings, location availability, unlocks, etc
|
||||
'stores', // little stuff, items, weapons, etc
|
||||
'character', // this is for player's character stats such as perks
|
||||
'income',
|
||||
'timers',
|
||||
'game', //mostly location related: fire temp, workers, population, world map, etc
|
||||
'playStats', //anything play related: play time, loads, etc
|
||||
'game', // mostly location related: fire temp, workers, population, world map, etc
|
||||
'playStats', // anything play related: play time, loads, etc
|
||||
'previous', // prestige, score, trophies (in future), achievements (again, not yet), etc
|
||||
'outfit', // used to temporarily store the items to be taken on the path
|
||||
'outfit', // used to temporarily store the items to be taken on the path
|
||||
'config',
|
||||
'wait' // mysterious wanderers are coming back
|
||||
'wait', // mysterious wanderers are coming back
|
||||
'cooldown' // residual values for cooldown buttons
|
||||
];
|
||||
|
||||
for(var which in cats) {
|
||||
|
||||
+3
-3
@@ -890,10 +890,8 @@ var World = {
|
||||
}
|
||||
World.state = null;
|
||||
|
||||
// Clear the embark cooldown
|
||||
var btn = Button.clearCooldown($('#embarkButton'));
|
||||
if(Path.outfit['cured meat'] > 0) {
|
||||
Button.setDisabled(btn, false);
|
||||
Button.setDisabled($('#embarkButton'), false);
|
||||
}
|
||||
|
||||
for(var k in Path.outfit) {
|
||||
@@ -959,6 +957,8 @@ var World = {
|
||||
|
||||
onArrival: function() {
|
||||
Engine.tabNavigation = false;
|
||||
// Clear the embark cooldown
|
||||
Button.clearCooldown($('#embarkButton'));
|
||||
Engine.keyLock = false;
|
||||
// Explore in a temporary world-state. We'll commit the changes if you return home safe.
|
||||
World.state = $.extend(true, {}, $SM.get('game.world'));
|
||||
|
||||
Reference in New Issue
Block a user