diff --git a/package-lock.json b/package-lock.json index 2e570b9..8d45699 100644 --- a/package-lock.json +++ b/package-lock.json @@ -410,6 +410,15 @@ "prettier": "^1.18.2", "source-map": "~0.6.1", "vue-template-es2015-compiler": "^1.9.0" + }, + "dependencies": { + "prettier": { + "version": "1.19.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz", + "integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==", + "dev": true, + "optional": true + } } }, "@webassemblyjs/ast": { @@ -4107,9 +4116,9 @@ "dev": true }, "prettier": { - "version": "1.19.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz", - "integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==", + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.1.2.tgz", + "integrity": "sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg==", "dev": true }, "process": { diff --git a/package.json b/package.json index ba4744c..4483da9 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "mocha": "^7.2.0", "mocha-junit-reporter": "^1.23.3", "nyc": "^15.1.0", - "prettier": "^1.19.1", + "prettier": "^2.1.2", "raw-loader": "^4.0.2", "sass": "^1.27.0", "sass-loader": "^8.0.2", diff --git a/src/ControlPanel.ts b/src/ControlPanel.ts index d19c866..31ae4fe 100644 --- a/src/ControlPanel.ts +++ b/src/ControlPanel.ts @@ -113,12 +113,12 @@ export class ControlPanel { this.villageFactory .createTaskCollection(villageId) .getTasks() - .filter(t => t.name === UpgradeBuildingTask.name) - .map(t => t.args.buildId || 0); + .filter((t) => t.name === UpgradeBuildingTask.name) + .map((t) => t.args.buildId || 0); if (p.pathname === '/dorf1.php') { showResourceSlotIds(getBuildingsInQueue()); - onResourceSlotCtrlClick(buildId => { + onResourceSlotCtrlClick((buildId) => { this.onSlotCtrlClick(villageId, buildId); showResourceSlotIds(getBuildingsInQueue()); }); @@ -126,7 +126,7 @@ export class ControlPanel { if (p.pathname === '/dorf2.php') { showBuildingSlotIds(getBuildingsInQueue()); - onBuildingSlotCtrlClick(buildId => { + onBuildingSlotCtrlClick((buildId) => { this.onSlotCtrlClick(villageId, buildId); showBuildingSlotIds(getBuildingsInQueue()); }); @@ -151,7 +151,7 @@ export class ControlPanel { el: `#${appId}`, data: gameState, store: createStore(villageFactory), - render: h => h(DashboardApp), + render: (h) => h(DashboardApp), }); } diff --git a/src/Dashboard/Dashboard.vue b/src/Dashboard/Dashboard.vue index af20096..60cbb2d 100644 --- a/src/Dashboard/Dashboard.vue +++ b/src/Dashboard/Dashboard.vue @@ -36,8 +36,8 @@ export default { }, computed: { ...mapState({ - isLogsVisible: state => state.views.logs, - isVillageEditorVisible: state => state.views.villageEditor, + isLogsVisible: (state) => state.views.logs, + isVillageEditorVisible: (state) => state.views.villageEditor, }), isSecondaryDashboardVisible() { return this.isLogsVisible || this.isVillageEditorVisible; diff --git a/src/Dashboard/Store.ts b/src/Dashboard/Store.ts index 3b0d174..43e7f97 100644 --- a/src/Dashboard/Store.ts +++ b/src/Dashboard/Store.ts @@ -43,7 +43,7 @@ export function createStore(villageFactory: VillageFactory) { }, }, getters: { - reverseLogs: state => { + reverseLogs: (state) => { return state.logs.slice().reverse(); }, }, diff --git a/src/Dashboard/VillageEditor.vue b/src/Dashboard/VillageEditor.vue index d4075f3..7f8d2ef 100644 --- a/src/Dashboard/VillageEditor.vue +++ b/src/Dashboard/VillageEditor.vue @@ -27,7 +27,7 @@ import { mapState } from 'vuex'; export default { computed: { ...mapState({ - villageName: state => state.villageSettings.villageName, + villageName: (state) => state.villageSettings.villageName, }), sendResourcesThreshold: { get() { diff --git a/src/Handler/Action/SendOnAdventureAction.ts b/src/Handler/Action/SendOnAdventureAction.ts index 45a75b1..b9bab64 100644 --- a/src/Handler/Action/SendOnAdventureAction.ts +++ b/src/Handler/Action/SendOnAdventureAction.ts @@ -44,9 +44,7 @@ export class SendOnAdventureAction extends BaseAction { private checkConfig(adventure: Adventure, health: number) { for (let conf of CONFIG) { if (adventure.level === conf.level && health >= conf.health) { - return jQuery(adventure.el) - .find('td.goTo .gotoAdventure') - .trigger('click'); + return jQuery(adventure.el).find('td.goTo .gotoAdventure').trigger('click'); } } } @@ -55,11 +53,7 @@ export class SendOnAdventureAction extends BaseAction { const adventures: Array = []; jQuery('tr[id^=adventure]').each((index, el) => { - const imgClass = - jQuery(el) - .find('.difficulty img') - .attr('class') - ?.toString() || ''; + const imgClass = jQuery(el).find('.difficulty img').attr('class')?.toString() || ''; const level = Number(trimPrefix(imgClass, 'adventureDifficulty')); if (!isNaN(level)) { adventures.push({ el, level: level }); diff --git a/src/Handler/Action/UpgradeResourceToLevelAction.ts b/src/Handler/Action/UpgradeResourceToLevelAction.ts index 9ed09f0..d2cc075 100644 --- a/src/Handler/Action/UpgradeResourceToLevelAction.ts +++ b/src/Handler/Action/UpgradeResourceToLevelAction.ts @@ -22,7 +22,7 @@ export class UpgradeResourceToLevelAction extends BaseAction { const requiredLevel = getNumber(args.level); const notUpgraded = deposits.filter( - dep => !dep.isUnderConstruction && requiredLevel > dep.level + (dep) => !dep.isUnderConstruction && requiredLevel > dep.level ); if (notUpgraded.length === 0) { @@ -59,7 +59,7 @@ export class UpgradeResourceToLevelAction extends BaseAction { return ( undefined === tasks.find( - task => + (task) => task.name === UpgradeBuildingTask.name && task.args.villageId === villageId && task.args.buildId === dep.buildId diff --git a/src/Handler/Task/UpdateResourceContractsTask.ts b/src/Handler/Task/UpdateResourceContractsTask.ts index 1f41147..851dbe5 100644 --- a/src/Handler/Task/UpdateResourceContractsTask.ts +++ b/src/Handler/Task/UpdateResourceContractsTask.ts @@ -12,7 +12,7 @@ export class UpdateResourceContractsTask extends BaseTask { const villages = this.factory.getAllVillages(); const tasks = villages - .map(v => this.factory.createTaskCollection(v.id).getTasks()) + .map((v) => this.factory.createTaskCollection(v.id).getTasks()) .reduce((acc, tasks) => acc.concat(tasks), []); const paths = uniqPaths([ @@ -20,7 +20,7 @@ export class UpdateResourceContractsTask extends BaseTask { ...this.walkImprovementTask(tasks), ]); - return paths.map(p => ({ + return paths.map((p) => ({ name: GoToPageAction.name, args: { path: path(p.name, p.query) }, })); @@ -28,8 +28,10 @@ export class UpdateResourceContractsTask extends BaseTask { private walkUpgradeTasks(tasks: ImmutableTaskList): PathList { return tasks - .filter(t => t.name === UpgradeBuildingTask.name && t.args.villageId && t.args.buildId) - .map(t => ({ + .filter( + (t) => t.name === UpgradeBuildingTask.name && t.args.villageId && t.args.buildId + ) + .map((t) => ({ name: '/build.php', query: { newdid: t.args.villageId, id: t.args.buildId }, })); @@ -37,8 +39,10 @@ export class UpdateResourceContractsTask extends BaseTask { private walkImprovementTask(tasks: ImmutableTaskList): PathList { return tasks - .filter(t => t.name === ForgeImprovementTask.name && t.args.villageId && t.args.buildId) - .map(t => ({ + .filter( + (t) => t.name === ForgeImprovementTask.name && t.args.villageId && t.args.buildId + ) + .map((t) => ({ name: '/build.php', query: { newdid: t.args.villageId, id: t.args.buildId }, })); diff --git a/src/Handler/TaskMap.ts b/src/Handler/TaskMap.ts index bcf7dfc..23f7022 100644 --- a/src/Handler/TaskMap.ts +++ b/src/Handler/TaskMap.ts @@ -23,7 +23,7 @@ interface TaskMap { const taskMap: TaskMap = {}; export function registerTask(options: TaskOptions = {}) { - return function(ctor: Function) { + return function (ctor: Function) { taskMap[ctor.name] = { ctor, queue: options.queue, @@ -55,7 +55,7 @@ export function createTaskHandler( /** * List on non intersected task queue predicates. */ -const TASK_TYPE_PREDICATES: Array = OrderedProductionQueues.map(queue => { +const TASK_TYPE_PREDICATES: Array = OrderedProductionQueues.map((queue) => { return (taskName: string) => getProductionQueue(taskName) === queue; }); diff --git a/src/Helpers/Browser.ts b/src/Helpers/Browser.ts index 0646481..5b44d5a 100644 --- a/src/Helpers/Browser.ts +++ b/src/Helpers/Browser.ts @@ -1,7 +1,7 @@ import * as URLParse from 'url-parse'; export async function waitForLoad() { - return new Promise(resolve => jQuery(resolve)); + return new Promise((resolve) => jQuery(resolve)); } export function parseLocation(location?: string | undefined) { diff --git a/src/Helpers/Convert.ts b/src/Helpers/Convert.ts index 369b077..4f22268 100644 --- a/src/Helpers/Convert.ts +++ b/src/Helpers/Convert.ts @@ -7,7 +7,7 @@ export function elClassId(classes: string | undefined, prefix: string): number | return undefined; } let result: number | undefined = undefined; - classes.split(/\s/).forEach(part => { + classes.split(/\s/).forEach((part) => { const match = part.match(new RegExp(prefix + '(\\d+)')); if (match) { result = toNumber(match[1]); diff --git a/src/Helpers/Time.ts b/src/Helpers/Time.ts index aa2960c..fcd321d 100644 --- a/src/Helpers/Time.ts +++ b/src/Helpers/Time.ts @@ -1,7 +1,7 @@ import { around, randomInRange } from './Random'; export function sleep(ms: number) { - return new Promise(resolve => setTimeout(resolve, ms)); + return new Promise((resolve) => setTimeout(resolve, ms)); } export async function sleepMicro() { diff --git a/src/Page/BuildingPage/BuildingPage.ts b/src/Page/BuildingPage/BuildingPage.ts index 71f0fd7..7dbe4cb 100644 --- a/src/Page/BuildingPage/BuildingPage.ts +++ b/src/Page/BuildingPage/BuildingPage.ts @@ -26,7 +26,7 @@ export function createBuildButton( const resElement = $el.find('.resourceWrapper .resource'); const resources = grabResourcesFromList(resElement); $el.append(`
Построить
`); - jQuery(`#${btnId}`).on('click', evt => { + jQuery(`#${btnId}`).on('click', (evt) => { evt.preventDefault(); onClickHandler(buildTypeId, resources); }); @@ -50,17 +50,14 @@ export function createUpgradeButton(onClickHandler: (resources: Resources) => vo const btn = `
В очередь
`; upgradeContainer.append(btn); const resources = grabContractResources(); - jQuery(`#${id}`).on('click', evt => { + jQuery(`#${id}`).on('click', (evt) => { evt.preventDefault(); onClickHandler(resources); }); } export function grabResourcesFromList($els: JQuery) { - const getText = (n: number) => - jQuery($els.get(n)) - .find('.value') - .text(); + const getText = (n: number) => jQuery($els.get(n)).find('.value').text(); const grab = (n: number) => getNumber(getText(n)); return new Resources(grab(0), grab(1), grab(2), grab(3)); } diff --git a/src/Page/BuildingPage/ForgePage.ts b/src/Page/BuildingPage/ForgePage.ts index aeab42c..07fb9de 100644 --- a/src/Page/BuildingPage/ForgePage.ts +++ b/src/Page/BuildingPage/ForgePage.ts @@ -22,7 +22,7 @@ function createResearchButton($researchBlockEl: JQuery, onClickHandler: Research Исследовать `); - jQuery(`#${id}`).on('click', evt => { + jQuery(`#${id}`).on('click', (evt) => { evt.preventDefault(); onClickHandler(resources, unitId); }); diff --git a/src/Page/BuildingPage/GuildHallPage.ts b/src/Page/BuildingPage/GuildHallPage.ts index 99e5540..98815d8 100644 --- a/src/Page/BuildingPage/GuildHallPage.ts +++ b/src/Page/BuildingPage/GuildHallPage.ts @@ -45,7 +45,7 @@ function createCelebrationButton( Праздновать `); - jQuery(`#${id}`).on('click', evt => { + jQuery(`#${id}`).on('click', (evt) => { evt.preventDefault(); onClickHandler(resources, idx); }); diff --git a/src/Page/BuildingPage/TrooperPage.ts b/src/Page/BuildingPage/TrooperPage.ts index d9efe7b..db90b73 100644 --- a/src/Page/BuildingPage/TrooperPage.ts +++ b/src/Page/BuildingPage/TrooperPage.ts @@ -23,7 +23,7 @@ export function createTrainTroopButtons( ); const resElement = $el.find('.resourceWrapper .resource'); const resources = grabResourcesFromList(resElement); - jQuery(`#${id}`).on('click', evt => { + jQuery(`#${id}`).on('click', (evt) => { evt.preventDefault(); const input = $el.find(`input[name="t${troopId}"]`); const count = getNumber(input.val()); diff --git a/src/Page/BuildingPageController.ts b/src/Page/BuildingPageController.ts index 78c9a30..afed5eb 100644 --- a/src/Page/BuildingPageController.ts +++ b/src/Page/BuildingPageController.ts @@ -46,7 +46,7 @@ export class BuildingPageController { this.logger.info('BUILD PAGE DETECTED', 'ID', this.attributes.buildId, this.attributes); if (buildTypeId) { - createUpgradeButton(res => this.onScheduleUpgradeBuilding(res)); + createUpgradeButton((res) => this.onScheduleUpgradeBuilding(res)); } else { createBuildButton((buildTypeId, res) => this.onScheduleBuildBuilding(buildTypeId, res)); } @@ -126,7 +126,7 @@ export class BuildingPageController { private onSendResources(coordinates: Coordinates) { const villageId = grabActiveVillageId(); - const targetVillage = grabVillageList().find(v => v.crd.eq(coordinates)); + const targetVillage = grabVillageList().find((v) => v.crd.eq(coordinates)); this.scheduler.scheduleTask(SendResourcesTask.name, { villageId: villageId, targetVillageId: targetVillage?.id, diff --git a/src/Page/SlotBlock.ts b/src/Page/SlotBlock.ts index d428af9..ddcff69 100644 --- a/src/Page/SlotBlock.ts +++ b/src/Page/SlotBlock.ts @@ -18,8 +18,8 @@ function slotElements(prefix: string): Array { function showSlotIds(prefix: string, buildingIds: Array): void { const slots = slotElements(prefix); - slots.forEach(slot => { - const upCount = buildingIds.filter(id => id === slot.buildId).length; + slots.forEach((slot) => { + const upCount = buildingIds.filter((id) => id === slot.buildId).length; const $slotEl = jQuery(slot.el); const $labelEl = $slotEl.find('.labelLayer'); const oldLabel = $labelEl.data('oldLabel') || $labelEl.text(); @@ -53,10 +53,10 @@ export function showBuildingSlotIds(buildingIds: number[]): void { function onSlotCtrlClick(prefix: string, onClickHandler: (buildId: number) => void): void { const slots = slotElements(prefix); - slots.forEach(slot => { + slots.forEach((slot) => { jQuery(slot.el) .find('.labelLayer') - .on('click', evt => { + .on('click', (evt) => { if (evt.ctrlKey) { evt.preventDefault(); evt.stopPropagation(); diff --git a/src/Queue/ActionQueue.ts b/src/Queue/ActionQueue.ts index aded18a..b879024 100644 --- a/src/Queue/ActionQueue.ts +++ b/src/Queue/ActionQueue.ts @@ -47,7 +47,7 @@ export class ActionQueue { const items = serialized as Array<{ [key: string]: any }>; - return items.map(i => { + return items.map((i) => { const command = { name: '', args: {} }; return Object.assign(command, i); }); diff --git a/src/Queue/TaskProvider/DataStorageTaskProvider.ts b/src/Queue/TaskProvider/DataStorageTaskProvider.ts index ac8bcc1..6130c84 100644 --- a/src/Queue/TaskProvider/DataStorageTaskProvider.ts +++ b/src/Queue/TaskProvider/DataStorageTaskProvider.ts @@ -24,7 +24,7 @@ export class DataStorageTaskProvider implements TaskProvider { const storedItems = serialized as Array<{ [key: string]: any }>; - return storedItems.map(i => { + return storedItems.map((i) => { const task = new Task(uniqTaskId(), 0, '', {}); return Object.assign(task, i); }); diff --git a/src/Queue/TaskQueue.ts b/src/Queue/TaskQueue.ts index e613ddf..971805d 100644 --- a/src/Queue/TaskQueue.ts +++ b/src/Queue/TaskQueue.ts @@ -19,7 +19,7 @@ export class TaskQueue { } get(ts: number): Task | undefined { - const readyItems = this.getItems().filter(t => t.ts <= ts); + const readyItems = this.getItems().filter((t) => t.ts <= ts); if (readyItems.length === 0) { return undefined; } @@ -27,7 +27,7 @@ export class TaskQueue { } findById(taskId: TaskId): Task | undefined { - const [matched, _] = this.split(t => t.id === taskId); + const [matched, _] = this.split((t) => t.id === taskId); return matched.shift(); } @@ -58,7 +58,7 @@ export class TaskQueue { private split(predicate: (t: Task) => boolean): [TaskList, TaskList] { const matched: TaskList = []; const other: TaskList = []; - this.getItems().forEach(t => { + this.getItems().forEach((t) => { if (predicate(t)) { matched.push(t); } else { diff --git a/src/Scheduler.ts b/src/Scheduler.ts index 179a219..6a554fb 100644 --- a/src/Scheduler.ts +++ b/src/Scheduler.ts @@ -141,10 +141,10 @@ export class Scheduler { let alreadyHasTask; if (args.villageId) { alreadyHasTask = this.taskQueue.has( - t => t.name === name && t.args.villageId === args.villageId + (t) => t.name === name && t.args.villageId === args.villageId ); } else { - alreadyHasTask = this.taskQueue.has(t => t.name === name); + alreadyHasTask = this.taskQueue.has((t) => t.name === name); } if (!alreadyHasTask) { @@ -153,7 +153,7 @@ export class Scheduler { } removeTask(taskId: TaskId) { - this.taskQueue.remove(t => t.id === taskId); + this.taskQueue.remove((t) => t.id === taskId); this.actionQueue.clear(); } @@ -168,7 +168,7 @@ export class Scheduler { } postponeTask(taskId: TaskId, seconds: number) { - const task = this.taskQueue.seeItems().find(t => t.id === taskId); + const task = this.taskQueue.seeItems().find((t) => t.id === taskId); if (!task) { return; } @@ -179,7 +179,7 @@ export class Scheduler { this.removeTask(taskId); } else { const modifyTime = withTime(timestamp() + seconds); - this.taskQueue.modify(t => t.id === taskId, modifyTime); + this.taskQueue.modify((t) => t.id === taskId, modifyTime); } } diff --git a/src/Statistics.ts b/src/Statistics.ts index a820189..f6a9a8d 100644 --- a/src/Statistics.ts +++ b/src/Statistics.ts @@ -42,10 +42,7 @@ export class Statistics { private getTopStatKeys(stat: ActionStatistics) { const keys = Object.keys(stat); - return keys - .sort() - .reverse() - .slice(0, KEEP_RECORD_COUNT); + return keys.sort().reverse().slice(0, KEEP_RECORD_COUNT); } getActionStatistics(): ActionStatistics { diff --git a/src/Storage/DataStorage.ts b/src/Storage/DataStorage.ts index be88daa..43ad566 100644 --- a/src/Storage/DataStorage.ts +++ b/src/Storage/DataStorage.ts @@ -6,7 +6,7 @@ const NAMESPACE = 'travian:v1'; const storage = localStorage; function join(...parts: Array) { - return parts.map(p => p.replace(/[:]+$/g, '').replace(/^[:]+/g, '')).join(':'); + return parts.map((p) => p.replace(/[:]+$/g, '').replace(/^[:]+/g, '')).join(':'); } export class DataStorage { diff --git a/src/Storage/Mapper.ts b/src/Storage/Mapper.ts index 8ca351d..6ffe844 100644 --- a/src/Storage/Mapper.ts +++ b/src/Storage/Mapper.ts @@ -19,7 +19,7 @@ export function createMapper(options: ObjectMapperOptions): ObjectMapper { + return (plain) => { let item = factory(); if (typeof plain === 'object' && typeof item === 'object') { return Object.assign(item, plain) as T; diff --git a/src/Storage/VillageStorage.ts b/src/Storage/VillageStorage.ts index 7b4e121..14e5b96 100644 --- a/src/Storage/VillageStorage.ts +++ b/src/Storage/VillageStorage.ts @@ -74,7 +74,7 @@ export class VillageStorage { storeIncomingMerchants(merchants: ReadonlyArray): void { this.storage.set( INCOMING_MERCHANTS_KEY, - merchants.map(m => ({ ...m.resources, ts: m.ts })) + merchants.map((m) => ({ ...m.resources, ts: m.ts })) ); } diff --git a/src/TaskQueueRenderer.ts b/src/TaskQueueRenderer.ts index bacb9a2..15afa42 100644 --- a/src/TaskQueueRenderer.ts +++ b/src/TaskQueueRenderer.ts @@ -6,18 +6,16 @@ const ID = uniqId(); export class TaskQueueRenderer { render(tasks: ImmutableTaskList) { - const ul = jQuery('
    ') - .attr({ id: ID }) - .css({ - 'position': 'absolute', - 'background-color': 'white', - 'left': 0, - 'top': '40px', - 'color': 'black', - 'z-index': '9999', - 'padding': '8px 6px', - }); - tasks.forEach(task => { + const ul = jQuery('
      ').attr({ id: ID }).css({ + 'position': 'absolute', + 'background-color': 'white', + 'left': 0, + 'top': '40px', + 'color': 'black', + 'z-index': '9999', + 'padding': '8px 6px', + }); + tasks.forEach((task) => { ul.append( jQuery('
    • ').text(formatDate(task.ts) + ' ' + task.name + ' ' + task.id) ); diff --git a/src/Village/VillageController.ts b/src/Village/VillageController.ts index 3129db8..e93a1e7 100644 --- a/src/Village/VillageController.ts +++ b/src/Village/VillageController.ts @@ -171,19 +171,21 @@ export class VillageController { const resourceSlots = this.storage.getResourceSlots(); const tasks = this.taskCollection.getTasks(); - const cropSlots = resourceSlots.filter(s => s.type === ResourceType.Crop && !s.isMaxLevel); + const cropSlots = resourceSlots.filter( + (s) => s.type === ResourceType.Crop && !s.isMaxLevel + ); if (cropSlots.length === 0) { return; } // Check, if crop field is building now - const underContraction = cropSlots.find(s => s.isUnderConstruction); + const underContraction = cropSlots.find((s) => s.isUnderConstruction); if (underContraction !== undefined) { return; } // Check, if we already have crop task in queue - const cropBuildIds = cropSlots.map(s => s.buildId); + const cropBuildIds = cropSlots.map((s) => s.buildId); for (let buildId of cropBuildIds) { const upgradeTask = tasks.find( isBuildingPlanned(UpgradeBuildingTask.name, buildId, undefined) @@ -207,11 +209,11 @@ export class VillageController { } private planWarehouseBuilding(): void { - this.planStorageBuilding(WAREHOUSE_ID, t => !t.isEnoughWarehouseCapacity); + this.planStorageBuilding(WAREHOUSE_ID, (t) => !t.isEnoughWarehouseCapacity); } private planGranaryBuilding(): void { - this.planStorageBuilding(GARNER_ID, t => !t.isEnoughGranaryCapacity); + this.planStorageBuilding(GARNER_ID, (t) => !t.isEnoughGranaryCapacity); } private planStorageBuilding( @@ -221,14 +223,14 @@ export class VillageController { const buildingSlots = this.storage.getBuildingSlots(); const storageSlots = buildingSlots.filter( - s => s.buildTypeId === buildTypeId && !s.isMaxLevel + (s) => s.buildTypeId === buildTypeId && !s.isMaxLevel ); if (storageSlots.length === 0) { return; } // Check, if storage is building now - const underConstruction = storageSlots.find(s => s.isUnderConstruction); + const underConstruction = storageSlots.find((s) => s.isUnderConstruction); if (underConstruction !== undefined) { return; } @@ -236,7 +238,7 @@ export class VillageController { const tasks = this.state.tasks; // Check, if we have storage is in building queue - const storageBuildIds = storageSlots.map(s => s.buildId); + const storageBuildIds = storageSlots.map((s) => s.buildId); for (let buildId of storageBuildIds) { const upgradeTask = tasks.find( isBuildingPlanned(UpgradeBuildingTask.name, buildId, buildTypeId) diff --git a/src/Village/VillageRepository.ts b/src/Village/VillageRepository.ts index 7fe5120..8d37f58 100644 --- a/src/Village/VillageRepository.ts +++ b/src/Village/VillageRepository.ts @@ -13,7 +13,7 @@ export class VillageRepository implements VillageRepositoryInterface { } get(villageId: number): Village { - const village = this.all().find(vlg => vlg.id === villageId); + const village = this.all().find((vlg) => vlg.id === villageId); if (!village) { throw new VillageNotFound('Active village not found'); } @@ -21,7 +21,7 @@ export class VillageRepository implements VillageRepositoryInterface { } getByCrd(crd: Coordinates): Village { - const village = this.all().find(vlg => vlg.crd.eq(crd)); + const village = this.all().find((vlg) => vlg.crd.eq(crd)); if (!village) { throw new VillageNotFound('Village not found'); } @@ -29,7 +29,7 @@ export class VillageRepository implements VillageRepositoryInterface { } getActive(): Village { - const village = this.all().find(vlg => vlg.active); + const village = this.all().find((vlg) => vlg.active); if (!village) { throw new VillageNotFound('Active village not found'); } diff --git a/src/Village/VillageState.ts b/src/Village/VillageState.ts index 014d210..8d423f2 100644 --- a/src/Village/VillageState.ts +++ b/src/Village/VillageState.ts @@ -220,7 +220,7 @@ function createTaskQueueStates( storage: VillageStorage ) { let result: Array = []; - const possibleTasks = tasks.filter(task => task.canBeBuilt); + const possibleTasks = tasks.filter((task) => task.canBeBuilt); for (let taskQueueInfo of getGroupedByQueueTasks(possibleTasks, storage)) { result.push(createProductionQueueState(taskQueueInfo, warehouse)); } @@ -230,12 +230,14 @@ function createTaskQueueStates( function getReadyForProductionTask( queues: ReadonlyArray ): TaskState | undefined { - const firstReadyQueue = queues.find(queue => queue.isWaiting); + const firstReadyQueue = queues.find((queue) => queue.isWaiting); if (!firstReadyQueue) { return undefined; } - return firstReadyQueue.tasks.find(task => task.name === TrainTroopTask.name || task.canBeBuilt); + return firstReadyQueue.tasks.find( + (task) => task.name === TrainTroopTask.name || task.canBeBuilt + ); } function getTaskResources(task: TaskCore | undefined): Resources { @@ -284,7 +286,7 @@ function createVillageOwnState( const storageState = makeStorageState(resources, storageResources, performance); const tasks = taskCollection .getTasks() - .map(t => makeTaskState(t, storageState.optimumFullness)); + .map((t) => makeTaskState(t, storageState.optimumFullness)); const queues = createTaskQueueStates(storageState, tasks, storage); const firstReadyTask = getReadyForProductionTask(queues); const requiredResources = getTaskResources(firstReadyTask); @@ -323,7 +325,7 @@ function createVillageState( state: VillageOwnState, ownStates: VillageOwnStateDictionary ): VillageState { - const villageIds = Object.keys(ownStates).map(k => +k); + const villageIds = Object.keys(ownStates).map((k) => +k); const commitments = villageIds.reduce((memo, shipmentVillageId) => { const shipmentVillageState = ownStates[shipmentVillageId]; const shipmentVillageRequired = shipmentVillageState.required; @@ -342,7 +344,7 @@ function getVillageStates( taskCollectionFactory: VillageTaskCollectionFactory ): Array { const ownStates = createVillageOwnStates(villages, storageFactory, taskCollectionFactory); - return villages.map(village => createVillageState(ownStates[village.id], ownStates)); + return villages.map((village) => createVillageState(ownStates[village.id], ownStates)); } interface VillageStorageFactory { @@ -382,7 +384,7 @@ export class VillageStateFactory { this.storageFactory, this.taskCollectionFactory ); - const needle = states.find(s => s.id === villageId); + const needle = states.find((s) => s.id === villageId); if (!needle) { throw new VillageNotFound(`Village ${villageId} not found`); } diff --git a/src/Village/VillageTaskCollection.ts b/src/Village/VillageTaskCollection.ts index bd04139..b3bc186 100644 --- a/src/Village/VillageTaskCollection.ts +++ b/src/Village/VillageTaskCollection.ts @@ -24,13 +24,13 @@ export class VillageTaskCollection { private modifyTasks(predicate: (t: Task) => boolean, modifier: (t: Task) => Task): void { const tasks = this.getTasks(); - const modified = tasks.map(t => (predicate(t) ? modifier(t) : t)); + const modified = tasks.map((t) => (predicate(t) ? modifier(t) : t)); this.storage.storeTaskList(modified); } private removeTasks(predicate: (t: Task) => boolean): void { const tasks = this.getTasks(); - const remaining = tasks.filter(t => !predicate(t)); + const remaining = tasks.filter((t) => !predicate(t)); this.storage.storeTaskList(remaining); } @@ -55,12 +55,12 @@ export class VillageTaskCollection { } removeTask(taskId: TaskId) { - this.removeTasks(t => t.id === taskId); + this.removeTasks((t) => t.id === taskId); } upTask(taskId: TaskId): void { const tasks = this.storage.getTasks(); - const index = tasks.findIndex(t => t.id === taskId); + const index = tasks.findIndex((t) => t.id === taskId); if (index < 0 || index === 0) { return; } @@ -71,7 +71,7 @@ export class VillageTaskCollection { downTask(taskId: TaskId) { const tasks = this.storage.getTasks(); - const index = tasks.findIndex(t => t.id === taskId); + const index = tasks.findIndex((t) => t.id === taskId); if (index < 0 || index === tasks.length - 1) { return; } @@ -82,7 +82,7 @@ export class VillageTaskCollection { postponeTask(taskId: TaskId, seconds: number) { const modifyTime = withTime(timestamp() + seconds); - this.modifyTasks(task => task.id === taskId, modifyTime); + this.modifyTasks((task) => task.id === taskId, modifyTime); } updateResourcesInTasks(resources: Resources, attr: ContractAttributes): void { diff --git a/tests/Core/GatheringTimingsTest.ts b/tests/Core/GatheringTimingsTest.ts index dca998b..83c3f21 100644 --- a/tests/Core/GatheringTimingsTest.ts +++ b/tests/Core/GatheringTimingsTest.ts @@ -4,23 +4,23 @@ import { expect } from 'chai'; import { Resources } from '../../src/Core/Resources'; import { calcGatheringTimings, GatheringTimings } from '../../src/Core/GatheringTimings'; -describe('Gathering timings', function() { - it('Can calc common from numbers', function() { +describe('Gathering timings', function () { + it('Can calc common from numbers', function () { const timings = GatheringTimings.create(10, 20, 15, 5); expect(20).to.equals(timings.slowest.seconds); }); - it('Can calc common with never', function() { + it('Can calc common with never', function () { const timings = GatheringTimings.create(10, 20, 'never', 5); expect(true).to.equals(timings.slowest.never); }); - it('Can calc common with all never', function() { + it('Can calc common with all never', function () { const timings = GatheringTimings.create('never', 'never', 'never', 'never'); expect(true).to.equals(timings.slowest.never); }); - it('Can calc timings', function() { + it('Can calc timings', function () { const resources = new Resources(10, 10, 10, 10); const desired = new Resources(60, 60, 60, 60); const speed = new Resources(5, 5, 5, 5); @@ -28,7 +28,7 @@ describe('Gathering timings', function() { expect(10 * 3600).to.equals(timings.slowest.seconds); }); - it('Can calc timings with different speed', function() { + it('Can calc timings with different speed', function () { const resources = new Resources(10, 10, 10, 10); const desired = new Resources(60, 60, 60, 60); const speed = new Resources(5, 10, 25, 5); @@ -40,7 +40,7 @@ describe('Gathering timings', function() { expect(10 * 3600).to.equals(timings.slowest.seconds); }); - it('Can calc timings with negative speed', function() { + it('Can calc timings with negative speed', function () { const resources = new Resources(10, 10, 10, 10); const desired = new Resources(60, 60, 60, 60); const speed = new Resources(5, 10, 25, -5); diff --git a/tests/Core/HeroBalanceTest.ts b/tests/Core/HeroBalanceTest.ts index 2a51a9d..b340a2e 100644 --- a/tests/Core/HeroBalanceTest.ts +++ b/tests/Core/HeroBalanceTest.ts @@ -5,14 +5,14 @@ import { calcHeroResource } from '../../src/Core/HeroBalance'; import { Resources } from '../../src/Core/Resources'; import { ResourceType } from '../../src/Core/ResourceType'; -describe('HeroBalance', function() { - it('Get resource for single requirement', function() { +describe('HeroBalance', function () { + it('Get resource for single requirement', function () { const req = new Resources(0, 0, -100, 0); const heroRes = calcHeroResource([req]); expect(heroRes).to.equals(ResourceType.Iron); }); - it('Get resource for second requirement', function() { + it('Get resource for second requirement', function () { const req1 = new Resources(0, 0, 100, 0); const req2 = new Resources(0, -200, 20, 0); const heroRes = calcHeroResource([req1, req2]); diff --git a/tests/Core/ResourcesTest.ts b/tests/Core/ResourcesTest.ts index e9d610e..298d621 100644 --- a/tests/Core/ResourcesTest.ts +++ b/tests/Core/ResourcesTest.ts @@ -3,45 +3,45 @@ import { expect } from 'chai'; import { Resources } from '../../src/Core/Resources'; -describe('Resources', function() { - it('Can compare with lt', function() { +describe('Resources', function () { + it('Can compare with lt', function () { const x = new Resources(0, 0, 0, 0); const y = new Resources(5, 5, 5, 5); expect(x.anyLower(y)).is.true; }); - it('Can compare with lt (mixed)', function() { + it('Can compare with lt (mixed)', function () { const x = new Resources(20, 20, 5, 20); const y = new Resources(10, 10, 10, 10); expect(x.anyLower(y)).is.true; }); - it('Can compare with gt', function() { + it('Can compare with gt', function () { const x = new Resources(5, 5, 5, 5); const y = new Resources(0, 0, 0, 0); expect(x.allGreater(y)).is.true; }); - it('Can compare with gt (mixed)', function() { + it('Can compare with gt (mixed)', function () { const x = new Resources(30, 30, 10, 30); const y = new Resources(20, 20, 20, 20); expect(x.allGreater(y)).is.false; }); - it('Can up to 1', function() { + it('Can up to 1', function () { const resources = new Resources(0, 4, 10, 18); const upped = resources.upTo(1); expect(upped.eq(resources)).is.true; }); - it('Can up to 10', function() { + it('Can up to 10', function () { const resources = new Resources(0, 4, 10, 18); const expected = new Resources(0, 10, 10, 20); const upped = resources.upTo(10); expect(upped.eq(expected)).is.true; }); - it('Can down to 10', function() { + it('Can down to 10', function () { const resources = new Resources(0, 4, 10, 18); const expected = new Resources(0, 0, 10, 10); const lowed = resources.downTo(10); diff --git a/tests/Helpers/ConvertTest.ts b/tests/Helpers/ConvertTest.ts index 5f62c9a..927031a 100644 --- a/tests/Helpers/ConvertTest.ts +++ b/tests/Helpers/ConvertTest.ts @@ -2,36 +2,36 @@ import { it, describe } from 'mocha'; import { expect } from 'chai'; import { elClassId, getNumber } from '../../src/Helpers/Convert'; -describe('Utils', function() { - describe('getNumber', function() { - it('Can parse positive number', function() { +describe('Utils', function () { + describe('getNumber', function () { + it('Can parse positive number', function () { const text = '123'; expect(getNumber(text)).to.be.equals(123); }); - it('Can parse positive number with noise', function() { + it('Can parse positive number with noise', function () { const text = ' 123 '; expect(getNumber(text)).to.be.equals(123); }); - it('Can parse negative number', function() { + it('Can parse negative number', function () { const text = '-‭146'; expect(getNumber(text)).to.be.equals(-146); }); - it('Can parse negative number with minus sign', function() { + it('Can parse negative number with minus sign', function () { const text = '\u2212132'; expect(getNumber(text)).to.be.equals(-132); }); }); - describe('elClassId', function() { - it('Can parse number with prefix', function() { + describe('elClassId', function () { + it('Can parse number with prefix', function () { const text = 'foo bar12 baz'; expect(elClassId(text, 'bar')).to.be.equals(12); }); - it('Can parse number from parts with same prefix', function() { + it('Can parse number from parts with same prefix', function () { const text = 'foo12 foobar'; expect(elClassId(text, 'foo')).to.be.equals(12); }); diff --git a/tests/Helpers/PathTest.ts b/tests/Helpers/PathTest.ts index 67e6506..9974cd2 100644 --- a/tests/Helpers/PathTest.ts +++ b/tests/Helpers/PathTest.ts @@ -2,28 +2,28 @@ import { it, describe } from 'mocha'; import { expect } from 'chai'; import { path, uniqPaths } from '../../src/Helpers/Path'; -describe('Path', function() { - it('Can build path with empty query', function() { +describe('Path', function () { + it('Can build path with empty query', function () { const p = path('/info.php'); expect(p).to.be.equals('/info.php'); }); - it('Can build path with query', function() { + it('Can build path with query', function () { const p = path('/info.php', { foo: 'bar' }); expect(p).to.be.equals('/info.php?foo=bar'); }); - it('Can build path with complex query', function() { + it('Can build path with complex query', function () { const p = path('/info.php', { a: 'x', b: 'y', c: 5 }); expect(p).to.be.equals('/info.php?a=x&b=y&c=5'); }); - it('Can build path with query (undefined part)', function() { + it('Can build path with query (undefined part)', function () { const p = path('/info.php', { foo: 'bar', foobar: undefined }); expect(p).to.be.equals('/info.php?foo=bar'); }); - it('Can keep uniq paths', function() { + it('Can keep uniq paths', function () { const p1 = { name: '/info.php', query: { a: 'b' } }; const p2 = { name: '/info.php', query: { a: 'b' } }; const up = uniqPaths([p1, p2]); diff --git a/tests/Queue/StatisticsTest.js.ts b/tests/Queue/StatisticsTest.js.ts index adc34c4..76bbbeb 100644 --- a/tests/Queue/StatisticsTest.js.ts +++ b/tests/Queue/StatisticsTest.js.ts @@ -15,15 +15,15 @@ class MemoryStatisticsStorage implements StatisticsStorageInterface { } } -describe('Statistics', function() { - it('Can save statistics item', function() { +describe('Statistics', function () { + it('Can save statistics item', function () { const storage = new MemoryStatisticsStorage(); const statistics = new Statistics(storage); statistics.incrementAction(1588408294); expect(Object.keys(statistics.getActionStatistics())).to.has.lengthOf(1); }); - it('Can trim statistics', function() { + it('Can trim statistics', function () { const storage = new MemoryStatisticsStorage(); const statistics = new Statistics(storage); const baseTime = 1588408294; diff --git a/tests/Queue/TaskQueueTest.js.ts b/tests/Queue/TaskQueueTest.js.ts index 87ec68f..8890b2d 100644 --- a/tests/Queue/TaskQueueTest.js.ts +++ b/tests/Queue/TaskQueueTest.js.ts @@ -6,34 +6,34 @@ import { NullLogger } from '../../src/Logger'; import { ArrayTaskProvider } from '../../src/Queue/TaskProvider/ArrayTaskProvider'; import { Task } from '../../src/Queue/Task'; -describe('Task Queue', function() { - it('Can get task from queue', function() { +describe('Task Queue', function () { + it('Can get task from queue', function () { const provider = new ArrayTaskProvider([new Task('1', 0, 'task', {})]); const queue = new TaskQueue(provider, new NullLogger()); const task = queue.get(1); expect(task).to.be.instanceOf(Task); }); - it("Don't get unready task from queue", function() { + it("Don't get unready task from queue", function () { const provider = new ArrayTaskProvider([new Task('1', 5, 'task', {})]); const queue = new TaskQueue(provider, new NullLogger()); const task = queue.get(1); expect(task).to.be.undefined; }); - it('Can remove task by id', function() { + it('Can remove task by id', function () { const provider = new ArrayTaskProvider([ new Task('id1', 1, 'task1', {}), new Task('id2', 2, 'task2', {}), ]); const queue = new TaskQueue(provider, new NullLogger()); - queue.remove(t => t.id === 'id1'); + queue.remove((t) => t.id === 'id1'); const tasks = provider.getTasks(); expect(tasks).to.have.lengthOf(1); expect(tasks[0].ts).to.be.equals(2); }); - it('Can modify tasks', function() { + it('Can modify tasks', function () { const provider = new ArrayTaskProvider([ new Task('1', 1, 'task1', {}), new Task('2', 3, 'task2', {}), @@ -41,8 +41,8 @@ describe('Task Queue', function() { ]); const queue = new TaskQueue(provider, new NullLogger()); queue.modify( - t => t.ts < 4, - t => new Task(t.id, 10, t.name, t.args) + (t) => t.ts < 4, + (t) => new Task(t.id, 10, t.name, t.args) ); const tasks = provider.getTasks(); expect(4).is.equals(tasks[0].ts);