-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathres.js
More file actions
25 lines (21 loc) · 825 Bytes
/
res.js
File metadata and controls
25 lines (21 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { Resources } from '/twcheese/src/Models/Resources.js';
/**
* @param {HTMLElement} resourcesContainer an element containing wood/stone/iron amounts
* @return {Resources}
*/
function scrapeResources(resourcesContainer) {
// remove grey periods used as thousands separators
let $res = $(resourcesContainer).clone();
$res.find('.grey').remove();
let resAmount = function(resIconCssClass) {
// note: sometimes, if the res amount is 0, the game excludes it (and its icon) instead of showing 0
let icon = $res.find('span.' + resIconCssClass).get(0);
return icon ? parseInt($(icon).parent().text()) : 0;
}
return new Resources(
resAmount('wood'),
resAmount('stone'),
resAmount('iron')
);
};
export { scrapeResources };