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