From f69a6e629be4e7d21add409d659204c654791973 Mon Sep 17 00:00:00 2001 From: Anton Vakhrushev Date: Tue, 26 May 2020 22:29:41 +0300 Subject: [PATCH] Reformat code --- package.json | 8 +-- src/Action/FindSendResourcesPath.ts | 6 ++- src/Action/TrainTrooperAction.ts | 6 ++- src/Action/UpgradeResourceToLevel.ts | 14 ++++-- src/Core/GatheringTimings.ts | 13 ++++- src/Core/Resources.ts | 40 ++++++++++++--- src/DashboardView/Header.vue | 6 ++- src/DashboardView/Store.ts | 9 ++-- src/DashboardView/TaskList.vue | 26 ++++++++-- src/DashboardView/VillageStateList.vue | 18 +++++-- src/Executor.ts | 9 +++- src/Grabber/ForgePageGrabber.ts | 5 +- src/Grabber/GuildHallPageGrabber.ts | 5 +- src/Grabber/VillageOverviewPageGrabber.ts | 4 +- src/Page/BuildingPage/BuildingPage.ts | 4 +- src/Page/BuildingPage/GuildHallPage.ts | 6 ++- src/Page/BuildingPage/MarketPage.ts | 5 +- src/Page/BuildingPage/TrooperPage.ts | 4 +- src/Page/BuildingPageController.ts | 29 ++++++++--- src/Queue/TaskQueue.ts | 9 +++- src/ResourceTransfer.ts | 11 ++++- src/Scheduler.ts | 11 +++-- src/Storage/VillageStorage.ts | 4 +- src/Task/BuildBuildingTask.ts | 6 ++- src/Task/CelebrationTask.ts | 5 +- src/Task/ForgeImprovementTask.ts | 5 +- src/Task/UpdateResourceContracts.ts | 5 +- src/TaskQueueRenderer.ts | 4 +- src/VillageFactory.ts | 6 ++- src/VillageState.ts | 59 ++++++++++++++++++----- src/VillageTaskCollection.ts | 11 +++-- tests/Queue/StatisticsTest.js.ts | 4 +- tests/Queue/TaskQueueTest.js.ts | 5 +- 33 files changed, 288 insertions(+), 74 deletions(-) diff --git a/package.json b/package.json index 22f2d3c..914bba4 100644 --- a/package.json +++ b/package.json @@ -15,10 +15,10 @@ "coverage": "nyc mocha", "build:dev": "webpack", "build": "webpack --env.production", - "format": "prettier --tab-width=4 --print-width 120 --single-quote --trailing-comma es5 --quote-props consistent --write '{src,tests}/**/*.{ts,js}'", - "format-check": "prettier --tab-width=4 --print-width 120 --single-quote --trailing-comma es5 --quote-props consistent --check '{src,tests}/**/*.{ts,js}'", - "format-vue": "prettier --tab-width=2 --print-width 120 --single-quote --trailing-comma es5 --quote-props consistent --write '{src,tests}/**/*.vue'", - "format-wp": "prettier --tab-width=4 --print-width 120 --single-quote --trailing-comma es5 --quote-props consistent --write 'webpack.config.js'" + "format": "prettier --tab-width=4 --print-width 100 --single-quote --trailing-comma es5 --quote-props consistent --write '{src,tests}/**/*.{ts,js}'", + "format-check": "prettier --tab-width=4 --print-width 100 --single-quote --trailing-comma es5 --quote-props consistent --check '{src,tests}/**/*.{ts,js}'", + "format-vue": "prettier --tab-width=2 --print-width 100 --single-quote --trailing-comma es5 --quote-props consistent --write '{src,tests}/**/*.vue'", + "format-wp": "prettier --tab-width=4 --print-width 100 --single-quote --trailing-comma es5 --quote-props consistent --write 'webpack.config.js'" }, "devDependencies": { "@types/chai": "^4.2.11", diff --git a/src/Action/FindSendResourcesPath.ts b/src/Action/FindSendResourcesPath.ts index 6428437..f0f895a 100644 --- a/src/Action/FindSendResourcesPath.ts +++ b/src/Action/FindSendResourcesPath.ts @@ -40,7 +40,11 @@ export class FindSendResourcesPath extends ActionController { const storage = new ResourceTransferStorage(); storage.storeReport(bestReport); - const marketPath = path('/build.php', { newdid: bestReport.fromVillageId, gid: MARKET_ID, t: 5 }); + const marketPath = path('/build.php', { + newdid: bestReport.fromVillageId, + gid: MARKET_ID, + t: 5, + }); window.location.assign(marketPath); } } diff --git a/src/Action/TrainTrooperAction.ts b/src/Action/TrainTrooperAction.ts index f2fc8d7..e186265 100644 --- a/src/Action/TrainTrooperAction.ts +++ b/src/Action/TrainTrooperAction.ts @@ -3,7 +3,11 @@ import { taskError, TryLaterError } from '../Errors'; import { aroundMinutes, randomInRange } from '../utils'; import { Args } from '../Queue/Args'; import { Task } from '../Queue/TaskProvider'; -import { clickTrainButton, fillTrainCount, getAvailableCount } from '../Page/BuildingPage/TrooperPage'; +import { + clickTrainButton, + fillTrainCount, + getAvailableCount, +} from '../Page/BuildingPage/TrooperPage'; import { TrainTroopTask } from '../Task/TrainTroopTask'; import { Resources } from '../Core/Resources'; diff --git a/src/Action/UpgradeResourceToLevel.ts b/src/Action/UpgradeResourceToLevel.ts index 09aa7e0..32c8195 100644 --- a/src/Action/UpgradeResourceToLevel.ts +++ b/src/Action/UpgradeResourceToLevel.ts @@ -19,7 +19,9 @@ export class UpgradeResourceToLevel extends ActionController { const requiredLevel = getNumber(args.level); - const notUpgraded = deposits.filter(dep => !dep.underConstruction && requiredLevel > dep.level); + const notUpgraded = deposits.filter( + dep => !dep.underConstruction && requiredLevel > dep.level + ); if (notUpgraded.length === 0) { this.scheduler.removeTask(task.id); @@ -34,11 +36,17 @@ export class UpgradeResourceToLevel extends ActionController { const secondNotUpgraded = notUpgraded.shift(); if (firstNotUpgraded && this.isTaskNotInQueue(villageId, firstNotUpgraded)) { - this.scheduler.scheduleTask(UpgradeBuildingTask.name, { villageId, buildId: firstNotUpgraded.buildId }); + this.scheduler.scheduleTask(UpgradeBuildingTask.name, { + villageId, + buildId: firstNotUpgraded.buildId, + }); } if (secondNotUpgraded && this.isTaskNotInQueue(villageId, secondNotUpgraded)) { - this.scheduler.scheduleTask(UpgradeBuildingTask.name, { villageId, buildId: secondNotUpgraded.buildId }); + this.scheduler.scheduleTask(UpgradeBuildingTask.name, { + villageId, + buildId: secondNotUpgraded.buildId, + }); } throw new TryLaterError(aroundMinutes(10), 'Sleep for next round'); diff --git a/src/Core/GatheringTimings.ts b/src/Core/GatheringTimings.ts index d7d5885..4125548 100644 --- a/src/Core/GatheringTimings.ts +++ b/src/Core/GatheringTimings.ts @@ -53,7 +53,12 @@ export class GatheringTimings { return new GatheringTimings(factory(lumber), factory(clay), factory(iron), factory(crop)); } - constructor(lumber: GatheringTime, clay: GatheringTime, iron: GatheringTime, crop: GatheringTime) { + constructor( + lumber: GatheringTime, + clay: GatheringTime, + iron: GatheringTime, + crop: GatheringTime + ) { this.lumber = lumber; this.clay = clay; this.iron = iron; @@ -97,7 +102,11 @@ function calcGatheringTime(val: number, desired: number, speed: number): Gatheri return GatheringTime.makeCounting((diff / speed) * 3600); } -export function calcGatheringTimings(resources: Resources, desired: Resources, speed: Resources): GatheringTimings { +export function calcGatheringTimings( + resources: Resources, + desired: Resources, + speed: Resources +): GatheringTimings { return new GatheringTimings( calcGatheringTime(resources.lumber, desired.lumber, speed.lumber), calcGatheringTime(resources.clay, desired.clay, speed.clay), diff --git a/src/Core/Resources.ts b/src/Core/Resources.ts index 4a3fcd3..3463e07 100644 --- a/src/Core/Resources.ts +++ b/src/Core/Resources.ts @@ -26,7 +26,12 @@ export class Resources implements ResourcesInterface { } static fromStorage(storage: ResourceStorage): Resources { - return new Resources(storage.warehouse, storage.warehouse, storage.warehouse, storage.granary); + return new Resources( + storage.warehouse, + storage.warehouse, + storage.warehouse, + storage.granary + ); } static zero(): Resources { @@ -86,16 +91,29 @@ export class Resources implements ResourcesInterface { } anyLower(other: ResourcesInterface): boolean { - return this.lumber < other.lumber || this.clay < other.clay || this.iron < other.iron || this.crop < other.crop; + return ( + this.lumber < other.lumber || + this.clay < other.clay || + this.iron < other.iron || + this.crop < other.crop + ); } allGreater(other: ResourcesInterface): boolean { - return this.lumber > other.lumber && this.clay > other.clay && this.iron > other.iron && this.crop > other.crop; + return ( + this.lumber > other.lumber && + this.clay > other.clay && + this.iron > other.iron && + this.crop > other.crop + ); } allGreaterOrEqual(other: ResourcesInterface): boolean { return ( - this.lumber >= other.lumber && this.clay >= other.clay && this.iron >= other.iron && this.crop >= other.crop + this.lumber >= other.lumber && + this.clay >= other.clay && + this.iron >= other.iron && + this.crop >= other.crop ); } @@ -136,7 +154,12 @@ export class Resources implements ResourcesInterface { return (Math.floor(v / multiplier) + 1) * multiplier; }; - return new Resources(upper(this.lumber), upper(this.clay), upper(this.iron), upper(this.crop)); + return new Resources( + upper(this.lumber), + upper(this.clay), + upper(this.iron), + upper(this.crop) + ); } downTo(multiplier: number): Resources { @@ -151,6 +174,11 @@ export class Resources implements ResourcesInterface { return part * multiplier; }; - return new Resources(lower(this.lumber), lower(this.clay), lower(this.iron), lower(this.crop)); + return new Resources( + lower(this.lumber), + lower(this.clay), + lower(this.iron), + lower(this.crop) + ); } } diff --git a/src/DashboardView/Header.vue b/src/DashboardView/Header.vue index 06cac6b..45202f4 100644 --- a/src/DashboardView/Header.vue +++ b/src/DashboardView/Header.vue @@ -6,7 +6,11 @@

- pause + pause + logs

diff --git a/src/DashboardView/Store.ts b/src/DashboardView/Store.ts index cccf914..ed6726a 100644 --- a/src/DashboardView/Store.ts +++ b/src/DashboardView/Store.ts @@ -57,7 +57,8 @@ export function createStore(villageFactory: VillageFactory) { state.logs = logs; }, [Mutations.ToggleVillageEditor](state, visible?: any) { - state.views.villageEditor = visible === undefined ? !state.views.villageEditor : !!visible; + state.views.villageEditor = + visible === undefined ? !state.views.villageEditor : !!visible; }, [Mutations.SetVillageSettings](state, settings) { state.villageSettings = settings; @@ -90,9 +91,11 @@ export function createStore(villageFactory: VillageFactory) { const villageName = state.villageSettings.villageName; const newSettings: VillageSettings = { sendResourcesThreshold: - state.villageSettings.sendResourcesThreshold || VillageSettingsDefaults.sendResourcesThreshold, + state.villageSettings.sendResourcesThreshold || + VillageSettingsDefaults.sendResourcesThreshold, sendResourcesTimeout: - state.villageSettings.sendResourcesTimeout || VillageSettingsDefaults.sendResourcesTimeout, + state.villageSettings.sendResourcesTimeout || + VillageSettingsDefaults.sendResourcesTimeout, sendResourcesMultiplier: state.villageSettings.sendResourcesMultiplier || VillageSettingsDefaults.sendResourcesMultiplier, diff --git a/src/DashboardView/TaskList.vue b/src/DashboardView/TaskList.vue index a4a79bb..6d4c52d 100644 --- a/src/DashboardView/TaskList.vue +++ b/src/DashboardView/TaskList.vue @@ -9,14 +9,32 @@

- - + + - +
- × + ×
diff --git a/src/DashboardView/VillageStateList.vue b/src/DashboardView/VillageStateList.vue index 95b72de..1c5084e 100644 --- a/src/DashboardView/VillageStateList.vue +++ b/src/DashboardView/VillageStateList.vue @@ -15,7 +15,11 @@