Refactoring
This commit is contained in:
		| @@ -11,17 +11,12 @@ export class BalanceHeroResourcesAction extends ActionController { | ||||
|         const resources = grabResources().asList(); | ||||
|         const currentType = grabCurrentHeroResource(); | ||||
|  | ||||
|         console.log('RESOURCES', resources); | ||||
|         console.log('CURRENT TYPE', currentType); | ||||
|  | ||||
|         const sorted = resources.sort((x, y) => x.value - y.value); | ||||
|         const min = sorted[0]; | ||||
|         const max = sorted[sorted.length - 1]; | ||||
|         const delta = max.value - min.value; | ||||
|         const eps = max.value / 10; | ||||
|  | ||||
|         console.log('MIN', min, 'MAX', max, 'DELTA', delta, 'EPS', eps); | ||||
|  | ||||
|         const resType = delta > eps ? min.type : HeroAllResources; | ||||
|         if (resType !== currentType) { | ||||
|             changeHeroResource(resType); | ||||
|   | ||||
| @@ -18,9 +18,6 @@ export class GoToHeroVillageAction extends ActionController { | ||||
|         const villages = grabVillageList(); | ||||
|         const heroVillage = grabHeroVillage(); | ||||
|  | ||||
|         console.log('VILLAGES', villages); | ||||
|         console.log('HERO VILLAGE', heroVillage); | ||||
|  | ||||
|         for (let village of villages) { | ||||
|             if (village.name === heroVillage) { | ||||
|                 return village.id; | ||||
|   | ||||
| @@ -14,6 +14,11 @@ import Vue from 'vue'; | ||||
| import DashboardApp from './Components/DashboardApp.vue'; | ||||
| import { ResourcesToLevel } from '../Task/ResourcesToLevel'; | ||||
|  | ||||
| interface QuickAction { | ||||
|     label: string; | ||||
|     cb: () => void; | ||||
| } | ||||
|  | ||||
| export class Dashboard { | ||||
|     private readonly version: string; | ||||
|     private scheduler: Scheduler; | ||||
| @@ -32,7 +37,7 @@ export class Dashboard { | ||||
|         const villageId = grabActiveVillageId(); | ||||
|  | ||||
|         const scheduler = this.scheduler; | ||||
|         const quickActions: any[] = []; | ||||
|         const quickActions: QuickAction[] = []; | ||||
|  | ||||
|         const state = { | ||||
|             name: 'Dashboard', | ||||
| @@ -53,21 +58,6 @@ export class Dashboard { | ||||
|  | ||||
|         setInterval(() => state.refreshTasks(), 1000); | ||||
|  | ||||
|         const deposits = grabResourceDeposits(); | ||||
|         if (deposits.length) { | ||||
|             const sorted = deposits.sort((x, y) => x.level - y.level); | ||||
|             const minLevel = sorted[0].level; | ||||
|             for (let i = minLevel + 1; i < minLevel + 4; ++i) { | ||||
|                 quickActions.push({ | ||||
|                     label: `Ресурсы до уровня ${i}`, | ||||
|                     cb: () => { | ||||
|                         scheduler.scheduleTask(ResourcesToLevel.name, { villageId, level: i }); | ||||
|                         state.refreshTasks(); | ||||
|                     }, | ||||
|                 }); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         const tasks = this.scheduler.getTaskItems(); | ||||
|         const buildingsInQueue = tasks | ||||
|             .filter(t => t.name === UpgradeBuildingTask.name && t.args.villageId === villageId) | ||||
| @@ -76,7 +66,7 @@ export class Dashboard { | ||||
|         if (p.pathname === '/dorf1.php') { | ||||
|             showResourceSlotIds(buildingsInQueue); | ||||
|             onResourceSlotCtrlClick(buildId => this.onResourceSlotCtrlClick(villageId, buildId, state)); | ||||
|             console.log(grabResourceDeposits()); | ||||
|             quickActions.push(...this.createDepositsQuickActions(state, villageId)); | ||||
|         } | ||||
|  | ||||
|         if (p.pathname === '/dorf2.php') { | ||||
| @@ -100,6 +90,26 @@ export class Dashboard { | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     private createDepositsQuickActions(state, villageId) { | ||||
|         const deposits = grabResourceDeposits(); | ||||
|         if (deposits.length === 0) { | ||||
|             return []; | ||||
|         } | ||||
|         const quickActions: QuickAction[] = []; | ||||
|         const sorted = deposits.sort((x, y) => x.level - y.level); | ||||
|         const minLevel = sorted[0].level; | ||||
|         for (let i = minLevel + 1; i < minLevel + 4; ++i) { | ||||
|             quickActions.push({ | ||||
|                 label: `Ресурсы до уровня ${i}`, | ||||
|                 cb: () => { | ||||
|                     this.scheduler.scheduleTask(ResourcesToLevel.name, { villageId, level: i }); | ||||
|                     state.refreshTasks(); | ||||
|                 }, | ||||
|             }); | ||||
|         } | ||||
|         return quickActions; | ||||
|     } | ||||
|  | ||||
|     private onResourceSlotCtrlClick(villageId: number, buildId: number, state) { | ||||
|         this.scheduler.scheduleTask(UpgradeBuildingTask.name, { villageId, buildId }); | ||||
|         state.refreshTasks(); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user