Add resource performance values

This commit is contained in:
Anton Vakhrushev 2020-04-17 22:00:47 +03:00
parent 1ce79092bd
commit 8ef3c60d46
8 changed files with 174 additions and 42 deletions

View File

@ -16,7 +16,7 @@ export default {
},
computed: {
villageName() {
let village = this.shared.village;
let village = this.shared.activeVillage;
return village ? village.name : 'Unknown';
},
},

View File

@ -24,9 +24,9 @@ export default {
data() {
return {
shared: this.$root.$data,
activeVillage: this.$root.$data.activeVillage,
};
},
computed: {},
methods: {
formatDate(ts) {
const d = new Date(ts * 1000);
@ -34,7 +34,7 @@ export default {
},
isThisVillageTask(task) {
const taskVillageId = (task.args || {}).villageId;
const currentVillageId = (this.shared.village || {}).id;
const currentVillageId = this.activeVillage.id;
return taskVillageId !== undefined && taskVillageId === currentVillageId;
},
onRemove(taskId) {

View File

@ -1,21 +1,55 @@
<template>
<section>
<table class="village-table">
<tr v-for="village in shared.villages" :key="village.id">
<td :class="{ active: village.active }">{{ village.id }} - {{ village.name }}</td>
<td>Д: {{ resources(village.id).lumber }}</td>
<td>Г: {{ resources(village.id).clay }}</td>
<td>Ж: {{ resources(village.id).iron }}</td>
<td>З: {{ resources(village.id).crop }}</td>
<td>
<a
v-if="village.id !== activeVillageId"
:href="path('/build.php', { newdid: activeVillageId, gid: 17, t: 5, x: village.crd.x, y: village.crd.y })"
:title="'Отправить ресурсы в ' + village.name"
>РЕС</a
>
</td>
</tr>
<thead>
<tr>
<th></th>
<th class="right">Дерево</th>
<th class="right">Глина</th>
<th class="right">Железо</th>
<th class="right">Зерно</th>
<th class="right">Склад</th>
<th class="right">Амбар</th>
</tr>
</thead>
<tbody>
<template v-for="village in shared.villages">
<tr class="top-line">
<td :class="{ active: village.active }" :title="village.id">{{ village.name }}</td>
<td class="right" v-text="village.lumber"></td>
<td class="right" v-text="village.clay"></td>
<td class="right" v-text="village.iron"></td>
<td class="right" v-text="village.crop"></td>
<td class="right">
<a :href="warehousePath(village)" v-text="village.warehouse"></a>
</td>
<td class="right" v-text="village.granary"></td>
</tr>
<tr>
<td></td>
<td class="right small">+{{ village.lumber_hour }}</td>
<td class="right small">+{{ village.clay_hour }}</td>
<td class="right small">+{{ village.iron_hour }}</td>
<td class="right small">+{{ village.crop_hour }}</td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td class="right" colspan="6">
<a
class="village-quick-link"
v-for="v in shared.villages"
v-if="v.id !== village.id"
:href="marketPath(village, v)"
:title="'Отправить ресурсы из ' + village.name + ' в ' + v.name"
>->{{ v.name }}</a
>
<a class="village-quick-link" :href="quartersPath(village)">Казармы</a>
</td>
</tr>
</template>
</tbody>
</table>
</section>
</template>
@ -27,20 +61,22 @@ export default {
data() {
return {
shared: this.$root.$data,
activeVillage: this.$root.$data.activeVillage,
};
},
computed: {
activeVillageId() {
return this.shared.village.id;
},
},
methods: {
resources(id) {
return this.shared.getVillageResources(id);
},
path(name, args) {
return path(name, args);
},
marketPath(fromVillage, toVillage) {
return path('/build.php', { newdid: fromVillage.id, gid: 17, t: 5, x: toVillage.crd.x, y: toVillage.crd.y });
},
warehousePath(village) {
return path('/build.php', { newdid: village.id, gid: 10 });
},
quartersPath(village) {
return path('/build.php', { newdid: village.id, gid: 19 });
},
},
};
</script>
@ -52,11 +88,30 @@ export default {
}
.village-table td {
border-top: 1px solid #ddd;
padding: 4px;
}
.village-table td.active {
font-weight: bold;
}
.top-line td {
border-top: 1px solid #ddd;
}
.right {
text-align: right;
}
.small {
font-size: 90%;
}
.village-quick-link {
display: inline-block;
}
.village-quick-link + .village-quick-link {
margin-left: 0.4em;
}
</style>

View File

@ -3,7 +3,7 @@ import { getNumber, uniqId, waitForLoad } from '../utils';
import { Scheduler } from '../Scheduler';
import { BuildPage } from '../Page/BuildPage';
import { UpgradeBuildingTask } from '../Task/UpgradeBuildingTask';
import { grabActiveVillage, grabActiveVillageId, grabVillageList } from '../Page/VillageBlock';
import { grabActiveVillageId, grabVillageList } from '../Page/VillageBlock';
import {
grabResourceDeposits,
onResourceSlotCtrlClick,
@ -14,7 +14,6 @@ import Vue from 'vue';
import DashboardApp from './Components/DashboardApp.vue';
import { ResourcesToLevel } from '../Task/ResourcesToLevel';
import { Logger } from '../Logger';
import { Resources } from '../Game';
import { VillageState } from '../State/VillageState';
import { StateGrabberManager } from '../State/StateGrabberManager';
@ -51,10 +50,10 @@ export class Dashboard {
const state = {
name: 'Dashboard',
village: grabActiveVillage(),
villages: grabVillageList(),
version: this.version,
taskList: this.scheduler.getTaskItems(),
activeVillage: {},
villages: [],
taskList: [],
quickActions: quickActions,
refreshTasks() {
@ -66,13 +65,42 @@ export class Dashboard {
this.taskList = scheduler.getTaskItems();
},
getVillageResources(villageId): Resources {
const state = new VillageState(villageId);
return state.getResources();
refreshVillages() {
this.villages = grabVillageList().map(village => {
const state = new VillageState(village.id);
const resources = state.getResources();
const storage = state.getResourceStorage();
const performance = state.getResourcesPerformance();
return {
id: village.id,
name: village.name,
crd: village.crd,
active: village.active,
lumber: resources.lumber,
clay: resources.clay,
iron: resources.iron,
crop: resources.crop,
lumber_hour: performance.lumber,
clay_hour: performance.clay,
iron_hour: performance.iron,
crop_hour: performance.crop,
warehouse: storage.warehouse,
granary: storage.granary,
};
});
for (let village of this.villages) {
if (village.active) {
this.activeVillage = village;
}
}
},
};
setInterval(() => state.refreshTasks(), 1000);
state.refreshTasks();
setInterval(() => state.refreshTasks(), 2000);
state.refreshVillages();
setInterval(() => state.refreshVillages(), 5000);
const tasks = this.scheduler.getTaskItems();
const buildingsInQueue = tasks

View File

@ -1,4 +1,4 @@
import { Coordinates, Village, VillageList } from '../Game';
import { Coordinates, Resources, Village, VillageList } from '../Game';
import { GrabError } from '../Errors';
import * as URLParse from 'url-parse';
import { getNumber } from '../utils';
@ -56,3 +56,19 @@ function grabVillageInfo($el): Village {
);
return new Village(id, name, active, new Coordinates(x, y));
}
export function grabResourcesPerformance(): Resources {
const $el = jQuery('#production');
if ($el.length !== 1) {
throw new GrabError();
}
const $nums = $el.find('td.num');
return new Resources(
getNumber($nums.get(0).innerText),
getNumber($nums.get(1).innerText),
getNumber($nums.get(2).innerText),
getNumber($nums.get(3).innerText)
);
}

View File

@ -0,0 +1,17 @@
import * as URLParse from 'url-parse';
import { StateGrabber } from './StateGrabber';
import { grabActiveVillageId, grabResourcesPerformance } from '../Page/VillageBlock';
import { VillageState } from './VillageState';
export class ResourcePerformanceGrabber extends StateGrabber {
grab(): void {
const p = new URLParse(window.location.href, true);
if (p.pathname !== '/dorf1.php') {
return;
}
const villageId = grabActiveVillageId();
const state = new VillageState(villageId);
state.storeResourcesPerformance(grabResourcesPerformance());
}
}

View File

@ -1,12 +1,14 @@
import { StateGrabber } from './StateGrabber';
import { ResourceGrabber } from './ResourceGrabber';
import { ResourcePerformanceGrabber } from './ResourcePerformanceGrabber';
export class StateGrabberManager {
private grabbers: Array<StateGrabber> = [];
private readonly grabbers: Array<StateGrabber> = [];
constructor() {
this.grabbers = [];
this.grabbers.push(new ResourceGrabber());
this.grabbers.push(new ResourcePerformanceGrabber());
}
grab() {

View File

@ -1,6 +1,10 @@
import { DataStorage } from '../Storage/DataStorage';
import { Resources, ResourceStorage } from '../Game';
const RESOURCES_KEY = 'res';
const CAPACITY_KEY = 'cap';
const PERFORMANCE_KEY = 'perf';
export class VillageState {
private storage: DataStorage;
constructor(villageId: number) {
@ -8,22 +12,32 @@ export class VillageState {
}
storeResources(resources: Resources) {
this.storage.set('res', resources);
this.storage.set(RESOURCES_KEY, resources);
}
getResources(): Resources {
let plain = this.storage.get('res');
let plain = this.storage.get(RESOURCES_KEY);
let res = new Resources(0, 0, 0, 0);
return Object.assign(res, plain) as Resources;
}
storeResourceStorage(storage: ResourceStorage) {
this.storage.set('cap', storage);
this.storage.set(CAPACITY_KEY, storage);
}
getResourceStorage(): ResourceStorage {
let plain = this.storage.get('res');
let plain = this.storage.get(CAPACITY_KEY);
let res = new ResourceStorage(0, 0);
return Object.assign(res, plain) as ResourceStorage;
}
storeResourcesPerformance(resources: Resources) {
this.storage.set(PERFORMANCE_KEY, resources);
}
getResourcesPerformance(): Resources {
let plain = this.storage.get(PERFORMANCE_KEY);
let res = new Resources(0, 0, 0, 0);
return Object.assign(res, plain) as Resources;
}
}