Skip to content

Instantly share code, notes, and snippets.

@tmathmeyer
Last active October 19, 2017 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmathmeyer/b3b282fb9f3f4fa2c0600304d2558dab to your computer and use it in GitHub Desktop.
Save tmathmeyer/b3b282fb9f3f4fa2c0600304d2558dab to your computer and use it in GitHub Desktop.
show ratios on trimps buildings
oldCanAffordBuilding = canAffordBuilding
newCanAffordBuilding = function(what, take, buildCostString, isEquipment, updatingLabel, forceAmt, autoPerc) {
result = oldCanAffordBuilding(what, take, buildCostString, isEquipment, updatingLabel, forceAmt, autoPerc)
if(typeof(result) === "boolean"){
return result
}
gamething = game['buildings'][what]
if (gamething == null) {
return result
}
if (gamething.increase == null) {
return result
}
increase = gamething.increase.by
newresult = ''
number = /([e\.0-9]*)(.*)/
reg = /<span class="(green|red|orange)">(food|wood|gems|metal|fragments|helium):&nbsp;([e\.0-9]*[K|M|B|T]*)(.*?)<\/span>/g
var m;
while(m=reg.exec(result)) {
parse_amount = m[3].match(number)
cost_per = (Number(parse_amount[1]) / increase).toFixed(2)
string_per = '(cost per: '+cost_per+parse_amount[2]+')'
newspan = '<span class="'+m[1]+'">'+m[2]+':&nbsp;'+m[3]+string_per+m[4]+'</span><br/>'
newresult += newspan
}
newresult = newresult.slice(0, -5);
return newresult
}
canAffordBuilding = newCanAffordBuilding
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment