Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A monitor for A Dark Room (doublespeakgames/adarkroom)
// ==UserScript==
// @name Dark Monitor
// @namespace https://gist.github.com/Zbee/0df652f096b670ec13a6
// @version 0.3.5
// @description A monitor for A Dark Room (doublespeakgames/adarkroom)
// @author Zbee
// @match http://adarkroom.doublespeakgames.com/
// @grant none
// ==/UserScript==
//--------------------------------------------------------------------------------------------//
//Modules
//Stores
// @description Checks store levels
// @depends-on null
// @default on
// @added 2015-06-15
// @finished 2016-08-30
// @modified null
// @author zbee
//Advice
// @description Gives advice on keeping store levels steady
// @depends-on Stores
// @default on
// @added 2016-08-30
// @finished null
// @modified null
// @author zbee
//--------------------------------------------------------------------------------------------//
//Change Log
//0.3.5
//Basics for advice module
//0.3
//Changed over to object orientation
//Added stores to be tracked
//0.2
//Finalized stores to display
//0.1
//Initial monitor
//--------------------------------------------------------------------------------------------//
//Table of Contents
//(type) : (name) : (description) : (module, if any)
//DarkMonitor
//////Monitor
//////////array : allStores : all stores to be tracked : stores
//////////func : checkStores : background function for stores function : stores
//////////func : stores : checks change for each store : stores
//////Compute
//////////obj : storeModifiers : villager jobs and their affects on stores : advice
//////////func : modifierAmounts : check amounts of each villager job : advice
//////////func : advice : checks each store change and suggests ways to level them out : advice
//////Display
//////////func : setup : setups up for displaying date :
//////////obj : monitor : jQuery object of display div :
//////////func : advice : display advice from compute method container : advice
//////Controller
//////////func : stores : starts stores module : stores
//////////func : advice : starts advice module : advice
//////////func : start : starts modules based on options :
//--------------------------------------------------------------------------------------------//
$("#location_outside").click(function () { $("#monitor").show(); });
$("#location_room, #location_path").click(function () { $("#monitor").hide(); });
var DarkMonitor = DarkMonitor || {};
//--------------------------------------------------------------------------------------------//
DarkMonitor.Monitor = {
allStores: [
["bait", 0], ["coal", 0], ["cured-meat", 0], ["fur", 0], ["iron", 0], ["leather", 0],
["meat", 0], ["steel", 0], ["wood", 0], ["scales", 0], ["cloth", 0], ["teeth", 0]
],
checkStore: function(store) {
var income = 0;
store = "#row_" + store;
//Skip non-set stores
if ($(store).length === 0) return 0;
//Track source for each store
$(store + " .tooltip .row_val").each(function () {
income += parseInt($(this).html().split(" ")[0]);
});
//Set up to display sources
var incomeTxt = income > 0 ? "+" + income : income;
//???
var curText = $(store + " > .row_key").html().split(" ").length > 1 ?
$(store + " > .row_key").html().split(" ")[1] :
$(store + " > .row_key").html().split(" ")[0];
//Display the sources for the store
$(store + " > .row_key").html("(" + incomeTxt + ") " + curText);
return income;
},
stores: function () {
console.log("DM.Monitor.stores");
//Ask for an update on each store
DarkMonitor.Monitor.allStores.forEach(function(element, index) {
DarkMonitor.Monitor.allStores[index][1] = DarkMonitor.Monitor.checkStore(element[0]);
});
}
};
//--------------------------------------------------------------------------------------------//
DarkMonitor.Compute = {
storeModifiers: {
"wood": [
{"from": "gatherer", "change": 1, "rate": 10, "limit": 0, "amount": 0},
{"from": "builder", "change": 2, "rate": 10, "limit": 1, "amount": 0}
],
"meat":[
{"from": "hunter", "change": 0.5, "rate": 10, "limit": 0, "amount": 0}
]
},
modifierAmounts: function () {
},
advice: function () {
console.log("DM.Compute.advice");
advice = {"notification": "", "monitor": ""};
DarkMonitor.Monitor.allStores.forEach(function(store) {
var storeQuantity = store[1];
store = store[0];
if (storeQuantity < 0) {
advice.notification = store + " is being lost.";
modifier = DarkMonitor.Compute.storeModifiers[store];
modifier = modifier[Math.floor(Math.random() * modifier.length)];
advice.monitor = "add " + (Math.abs(storeQuantity) / modifier.change) + " " + modifier.from;
}
});
return advice;
}
};
//--------------------------------------------------------------------------------------------//
DarkMonitor.Display = {
setup: function () {
console.log("DM.Display.setup");
$("body").prepend("<div id='monitor' style='float:left;display:none;'></div>");
},
monitor: $("#monitor"),
advice: function (advice) {
console.log("DM.Display.advice");
DarkMonitor.Display.monitor.append(advice.monitor);
$("#monitor").html(advice.monitor);
//Display notification if not shown last
if (advice.notification != $("#notifications .notification:first-of-type").text())
$("#notifications").prepend("<div class='notification'>" + advice.notification + "</div>");
}
};
//--------------------------------------------------------------------------------------------//
DarkMonitor.Controller = {
stores: function () {
console.log("DM.Controller.stores");
window.setInterval(function(){
DarkMonitor.Monitor.stores();
}, 500); //Half second
},
advice: function () {
console.log("DM.Controller.advice");
window.setInterval(function(){
var advice = DarkMonitor.Compute.advice();
DarkMonitor.Display.advice(advice);
}, 5000); //5 seconds
},
start: function (opts) {
console.log("DM.Controller.start");
DarkMonitor.Display.setup();
if (opts.stores === true) DarkMonitor.Controller.stores();
if (opts.advice === true) DarkMonitor.Controller.advice();
}
};
//--------------------------------------------------------------------------------------------//
DarkMonitor.Controller.start({
stores: true,
advice: true
});
@zbee

This comment has been minimized.

Copy link
Owner Author

commented Jun 15, 2015

Features:

  • Show income for different resources
  • Suggest ways to stabilize / optimize incomes
  • Grey out or in some way denote things that cannot be afforded
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.