Add building queue time grabber
This commit is contained in:
parent
8001510f0a
commit
db16c54137
@ -2,22 +2,19 @@ import { ActionController, registerAction } from './ActionController';
|
|||||||
import { Args } from '../Common';
|
import { Args } from '../Common';
|
||||||
import { Task } from '../Storage/TaskQueue';
|
import { Task } from '../Storage/TaskQueue';
|
||||||
import { BuildingQueueFullError } from '../Errors';
|
import { BuildingQueueFullError } from '../Errors';
|
||||||
import { grabActiveVillageId } from '../Page/VillageBlock';
|
import { grabActiveVillageId, grabBuildingQueueInfo } from '../Page/VillageBlock';
|
||||||
|
|
||||||
@registerAction
|
@registerAction
|
||||||
export class CheckBuildingRemainingTimeAction extends ActionController {
|
export class CheckBuildingRemainingTimeAction extends ActionController {
|
||||||
async run(args: Args, task: Task): Promise<any> {
|
async run(args: Args, task: Task): Promise<any> {
|
||||||
const timer = jQuery('.buildDuration .timer');
|
const info = grabBuildingQueueInfo();
|
||||||
if (timer.length === 1) {
|
if (info.seconds > 0) {
|
||||||
const remainingSeconds = Number(timer.attr('value'));
|
throw new BuildingQueueFullError(
|
||||||
if (remainingSeconds > 0) {
|
task.id,
|
||||||
throw new BuildingQueueFullError(
|
grabActiveVillageId(),
|
||||||
task.id,
|
info.seconds + 1,
|
||||||
grabActiveVillageId(),
|
'Building queue is full'
|
||||||
remainingSeconds + 1,
|
);
|
||||||
'Building queue is full'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,6 +71,7 @@ export class ControlPanel {
|
|||||||
const resources = state.getResources();
|
const resources = state.getResources();
|
||||||
const storage = state.getResourceStorage();
|
const storage = state.getResourceStorage();
|
||||||
const performance = state.getResourcesPerformance();
|
const performance = state.getResourcesPerformance();
|
||||||
|
const buildQueueInfo = state.getBuildingQueueInfo();
|
||||||
return {
|
return {
|
||||||
id: village.id,
|
id: village.id,
|
||||||
name: village.name,
|
name: village.name,
|
||||||
@ -86,6 +87,7 @@ export class ControlPanel {
|
|||||||
crop_hour: performance.crop,
|
crop_hour: performance.crop,
|
||||||
warehouse: storage.warehouse,
|
warehouse: storage.warehouse,
|
||||||
granary: storage.granary,
|
granary: storage.granary,
|
||||||
|
buildRemainingSeconds: buildQueueInfo.seconds,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
for (let village of this.villages) {
|
for (let village of this.villages) {
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
<td class="right" v-text="village.granary"></td>
|
<td class="right" v-text="village.granary"></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="performance-line">
|
<tr class="performance-line">
|
||||||
<td></td>
|
<td class="right small" v-text="secondsToTime(village.buildRemainingSeconds)"></td>
|
||||||
<td class="right small">+{{ village.lumber_hour }}</td>
|
<td class="right small">+{{ village.lumber_hour }}</td>
|
||||||
<td class="right small">+{{ village.clay_hour }}</td>
|
<td class="right small">+{{ village.clay_hour }}</td>
|
||||||
<td class="right small">+{{ village.iron_hour }}</td>
|
<td class="right small">+{{ village.iron_hour }}</td>
|
||||||
@ -108,6 +108,12 @@ export default {
|
|||||||
const minutes = Math.round((value - hours) * 60);
|
const minutes = Math.round((value - hours) * 60);
|
||||||
return `${hours}:${String(minutes).padStart(2, '0')}`;
|
return `${hours}:${String(minutes).padStart(2, '0')}`;
|
||||||
},
|
},
|
||||||
|
secondsToTime(value) {
|
||||||
|
const hours = Math.floor(value / 3600);
|
||||||
|
const minutes = Math.floor((value % 3600) / 60);
|
||||||
|
const seconds = value % 60;
|
||||||
|
return `${hours}:${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@ -90,6 +90,13 @@ export class Village {
|
|||||||
|
|
||||||
export type VillageList = Array<Village>;
|
export type VillageList = Array<Village>;
|
||||||
|
|
||||||
|
export class BuildingQueueInfo {
|
||||||
|
readonly seconds: number;
|
||||||
|
constructor(seconds: number) {
|
||||||
|
this.seconds = seconds;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export type HeroAllResourcesType = 'all';
|
export type HeroAllResourcesType = 'all';
|
||||||
export const HeroAllResources: HeroAllResourcesType = 'all';
|
export const HeroAllResources: HeroAllResourcesType = 'all';
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Coordinates, Resources, Village, VillageList } from '../Game';
|
import { BuildingQueueInfo, Coordinates, Resources, Village, VillageList } from '../Game';
|
||||||
import { GrabError } from '../Errors';
|
import { GrabError } from '../Errors';
|
||||||
import { getNumber, parseLocation } from '../utils';
|
import { getNumber, parseLocation } from '../utils';
|
||||||
|
|
||||||
@ -59,3 +59,14 @@ export function grabResourcesPerformance(): Resources {
|
|||||||
getNumber($nums.get(3).innerText)
|
getNumber($nums.get(3).innerText)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function grabBuildingQueueInfo(): BuildingQueueInfo {
|
||||||
|
const timer = jQuery('.buildDuration .timer');
|
||||||
|
if (timer.length !== 1) {
|
||||||
|
throw new GrabError();
|
||||||
|
}
|
||||||
|
|
||||||
|
const remainingSeconds = getNumber(timer.attr('value'));
|
||||||
|
|
||||||
|
return new BuildingQueueInfo(remainingSeconds);
|
||||||
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { StateGrabber } from './StateGrabber';
|
import { StateGrabber } from './StateGrabber';
|
||||||
import { ResourceGrabber } from './ResourceGrabber';
|
import { ResourceGrabber } from './ResourceGrabber';
|
||||||
import { ResourcePerformanceGrabber } from './ResourcePerformanceGrabber';
|
import { VillageOverviewPageGrabber } from './VillageOverviewPageGrabber';
|
||||||
|
|
||||||
export class StateGrabberManager {
|
export class StateGrabberManager {
|
||||||
private readonly grabbers: Array<StateGrabber> = [];
|
private readonly grabbers: Array<StateGrabber> = [];
|
||||||
@ -8,7 +8,7 @@ export class StateGrabberManager {
|
|||||||
constructor() {
|
constructor() {
|
||||||
this.grabbers = [];
|
this.grabbers = [];
|
||||||
this.grabbers.push(new ResourceGrabber());
|
this.grabbers.push(new ResourceGrabber());
|
||||||
this.grabbers.push(new ResourcePerformanceGrabber());
|
this.grabbers.push(new VillageOverviewPageGrabber());
|
||||||
}
|
}
|
||||||
|
|
||||||
grab() {
|
grab() {
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { StateGrabber } from './StateGrabber';
|
import { StateGrabber } from './StateGrabber';
|
||||||
import { grabActiveVillageId, grabResourcesPerformance } from '../Page/VillageBlock';
|
import { grabActiveVillageId, grabBuildingQueueInfo, grabResourcesPerformance } from '../Page/VillageBlock';
|
||||||
import { VillageState } from './VillageState';
|
import { VillageState } from './VillageState';
|
||||||
import { parseLocation } from '../utils';
|
import { parseLocation } from '../utils';
|
||||||
|
|
||||||
export class ResourcePerformanceGrabber extends StateGrabber {
|
export class VillageOverviewPageGrabber extends StateGrabber {
|
||||||
grab(): void {
|
grab(): void {
|
||||||
const p = parseLocation();
|
const p = parseLocation();
|
||||||
if (p.pathname !== '/dorf1.php') {
|
if (p.pathname !== '/dorf1.php') {
|
||||||
@ -13,5 +13,6 @@ export class ResourcePerformanceGrabber extends StateGrabber {
|
|||||||
const villageId = grabActiveVillageId();
|
const villageId = grabActiveVillageId();
|
||||||
const state = new VillageState(villageId);
|
const state = new VillageState(villageId);
|
||||||
state.storeResourcesPerformance(grabResourcesPerformance());
|
state.storeResourcesPerformance(grabResourcesPerformance());
|
||||||
|
state.storeBuildingQueueInfo(grabBuildingQueueInfo());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,9 +1,10 @@
|
|||||||
import { DataStorage } from '../Storage/DataStorage';
|
import { DataStorage } from '../Storage/DataStorage';
|
||||||
import { Resources, ResourceStorage } from '../Game';
|
import { BuildingQueueInfo, Resources, ResourceStorage } from '../Game';
|
||||||
|
|
||||||
const RESOURCES_KEY = 'res';
|
const RESOURCES_KEY = 'res';
|
||||||
const CAPACITY_KEY = 'cap';
|
const CAPACITY_KEY = 'cap';
|
||||||
const PERFORMANCE_KEY = 'perf';
|
const PERFORMANCE_KEY = 'perf';
|
||||||
|
const BUILDING_QUEUE_KEY = 'bq';
|
||||||
|
|
||||||
export class VillageState {
|
export class VillageState {
|
||||||
private storage: DataStorage;
|
private storage: DataStorage;
|
||||||
@ -40,4 +41,14 @@ export class VillageState {
|
|||||||
let res = new Resources(0, 0, 0, 0);
|
let res = new Resources(0, 0, 0, 0);
|
||||||
return Object.assign(res, plain) as Resources;
|
return Object.assign(res, plain) as Resources;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
storeBuildingQueueInfo(info: BuildingQueueInfo): void {
|
||||||
|
this.storage.set(BUILDING_QUEUE_KEY, info);
|
||||||
|
}
|
||||||
|
|
||||||
|
getBuildingQueueInfo(): BuildingQueueInfo {
|
||||||
|
let plain = this.storage.get(BUILDING_QUEUE_KEY);
|
||||||
|
let res = new BuildingQueueInfo(0);
|
||||||
|
return Object.assign(res, plain) as BuildingQueueInfo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user