Auto build warehouse, granary and crop fields

This commit is contained in:
2020-07-01 18:06:11 +03:00
parent 7653c7b6e7
commit effc1b1626
14 changed files with 252 additions and 54 deletions

View File

@@ -1,5 +1,5 @@
import { elClassId, getNumber } from '../utils';
import { ResourceSlot } from '../Game';
import { BuildingSlot, ResourceSlot } from '../Game';
import { numberToResourceType } from '../Core/ResourceType';
interface SlotElement {
@@ -90,3 +90,22 @@ function makeResourceSlot(slot: SlotElement): ResourceSlot {
export function grabResourceSlots(): Array<ResourceSlot> {
return slotElements('buildingSlot').map(makeResourceSlot);
}
function makeBuildingSlot(slot: SlotElement): BuildingSlot {
const $el = jQuery(slot.el);
const classes = $el.attr('class');
const $parent = $el.closest('.buildingSlot');
const parentClasses = $parent.attr('class');
return {
buildId: getNumber(elClassId(classes, 'aid')),
buildTypeId: getNumber(elClassId(parentClasses, 'g')),
level: getNumber(elClassId(classes, 'level')),
isReady: !$el.hasClass('notNow'),
isUnderConstruction: $el.hasClass('underConstruction'),
isMaxLevel: $el.hasClass('maxLevel'),
};
}
export function grabBuildingSlots(): Array<BuildingSlot> {
return slotElements('aid').map(makeBuildingSlot);
}