Village state refactoring
This commit is contained in:
parent
c5de5ca901
commit
b16a121d37
@ -24,7 +24,7 @@ export class BalanceHeroResourcesAction extends ActionController {
|
||||
thisVillageState.required.balance,
|
||||
thisVillageState.commitments,
|
||||
thisVillageState.totalRequired.balance,
|
||||
thisVillageState.resources.sub(thisVillageState.storage),
|
||||
thisVillageState.resources.sub(thisVillageState.storage.capacity),
|
||||
];
|
||||
|
||||
console.log('Requirements');
|
||||
|
@ -60,7 +60,7 @@ export class SendResourcesAction extends ActionController {
|
||||
}
|
||||
|
||||
private getRecipientRequirements(recipientState: VillageState): Resources {
|
||||
const maxPossibleToStore = recipientState.storage.sub(recipientState.performance);
|
||||
const maxPossibleToStore = recipientState.storage.capacity.sub(recipientState.performance);
|
||||
const currentResources = recipientState.resources;
|
||||
const incomingResources = recipientState.incomingResources;
|
||||
const requirementResources = recipientState.required.resources;
|
||||
|
@ -12,7 +12,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<template v-for="villageState in shared.villageStates">
|
||||
<template v-for="villageState in villageStates">
|
||||
<tr class="normal-line top-line">
|
||||
<td :class="{ active: villageState.village.active }" :title="villageState.id">
|
||||
{{ villageState.village.name }}
|
||||
@ -20,28 +20,28 @@
|
||||
<td class="right">
|
||||
<filling
|
||||
:value="villageState.resources.lumber"
|
||||
:max="villageState.storage.lumber"
|
||||
:max="villageState.storage.capacity.lumber"
|
||||
:speed="villageState.performance.lumber"
|
||||
></filling>
|
||||
</td>
|
||||
<td class="right">
|
||||
<filling
|
||||
:value="villageState.resources.clay"
|
||||
:max="villageState.storage.clay"
|
||||
:max="villageState.storage.capacity.clay"
|
||||
:speed="villageState.performance.clay"
|
||||
></filling>
|
||||
</td>
|
||||
<td class="right">
|
||||
<filling
|
||||
:value="villageState.resources.iron"
|
||||
:max="villageState.storage.iron"
|
||||
:max="villageState.storage.capacity.iron"
|
||||
:speed="villageState.performance.iron"
|
||||
></filling>
|
||||
</td>
|
||||
<td class="right">
|
||||
<filling
|
||||
:value="villageState.resources.crop"
|
||||
:max="villageState.storage.crop"
|
||||
:max="villageState.storage.capacity.crop"
|
||||
:speed="villageState.performance.crop"
|
||||
></filling>
|
||||
</td>
|
||||
@ -167,7 +167,7 @@
|
||||
<td></td>
|
||||
<td class="right" colspan="5">
|
||||
<a
|
||||
v-for="s in shared.villageStates"
|
||||
v-for="s in villageStates"
|
||||
v-if="s.id !== villageState.id"
|
||||
class="village-quick-link"
|
||||
:class="{ active: villageState.shipment.includes(s.id) }"
|
||||
@ -218,6 +218,7 @@ export default {
|
||||
data() {
|
||||
return {
|
||||
shared: this.$root.$data,
|
||||
villageStates: this.$root.$data.villageStates,
|
||||
activeVillageState: this.$root.$data.activeVillageState,
|
||||
};
|
||||
},
|
||||
@ -226,8 +227,8 @@ export default {
|
||||
return path(name, args);
|
||||
},
|
||||
storageTime(villageState) {
|
||||
const toZero = villageState.storageBalance.timeToZero;
|
||||
const toFull = villageState.storageBalance.timeToFull;
|
||||
const toZero = villageState.storage.timeToZero;
|
||||
const toFull = villageState.storage.timeToFull;
|
||||
return this.renderGatheringTime(toFull.never ? toZero : toFull);
|
||||
},
|
||||
marketPath(fromVillage, toVillage) {
|
||||
|
@ -6,9 +6,9 @@ import { calcGatheringTimings, GatheringTime } from './Core/GatheringTimings';
|
||||
import { VillageRepositoryInterface } from './VillageRepository';
|
||||
import { VillageNotFound } from './Errors';
|
||||
|
||||
interface StorageBalance {
|
||||
interface VillageStorageState {
|
||||
resources: Resources;
|
||||
storage: Resources;
|
||||
capacity: Resources;
|
||||
balance: Resources;
|
||||
performance: Resources;
|
||||
timeToZero: GatheringTime;
|
||||
@ -21,7 +21,7 @@ interface RequiredResources {
|
||||
*/
|
||||
resources: Resources;
|
||||
/**
|
||||
* Balance resources (current - required), may be negative
|
||||
* Balance resources (current - required, may be negative)
|
||||
*/
|
||||
balance: Resources;
|
||||
/**
|
||||
@ -44,9 +44,14 @@ interface VillageOwnState {
|
||||
*/
|
||||
resources: Resources;
|
||||
performance: Resources;
|
||||
storage: Resources;
|
||||
storageBalance: StorageBalance;
|
||||
storage: VillageStorageState;
|
||||
/**
|
||||
* Required resources for nearest task
|
||||
*/
|
||||
required: RequiredResources;
|
||||
/**
|
||||
* Required resources for all tasks
|
||||
*/
|
||||
totalRequired: RequiredResources;
|
||||
incomingResources: Resources;
|
||||
buildRemainingSeconds: number;
|
||||
@ -58,7 +63,7 @@ interface VillageOwnStateDictionary {
|
||||
|
||||
export interface VillageState extends VillageOwnState {
|
||||
/**
|
||||
* Resource commitments of this village to other
|
||||
* Resource commitments of this village to other (may be negative)
|
||||
*/
|
||||
commitments: Resources;
|
||||
/**
|
||||
@ -75,10 +80,10 @@ function calcResourceBalance(resources: Resources, current: Resources, performan
|
||||
};
|
||||
}
|
||||
|
||||
function calcStorageBalance(resources: Resources, storage: Resources, performance: Resources): StorageBalance {
|
||||
function calcStorageBalance(resources: Resources, storage: Resources, performance: Resources): VillageStorageState {
|
||||
return {
|
||||
resources,
|
||||
storage,
|
||||
capacity: storage,
|
||||
performance,
|
||||
balance: storage.sub(resources),
|
||||
timeToZero: timeToFastestResource(resources, Resources.zero(), performance),
|
||||
@ -114,8 +119,7 @@ function createVillageOwnState(village: Village, scheduler: Scheduler): VillageO
|
||||
village,
|
||||
resources,
|
||||
performance,
|
||||
storage: Resources.fromStorage(resourceStorage),
|
||||
storageBalance: calcStorageBalance(resources, Resources.fromStorage(resourceStorage), performance),
|
||||
storage: calcStorageBalance(resources, Resources.fromStorage(resourceStorage), performance),
|
||||
required: calcResourceBalance(requiredResources, resources, performance),
|
||||
totalRequired: calcResourceBalance(totalRequiredResources, resources, performance),
|
||||
buildRemainingSeconds: buildQueueInfo.seconds,
|
||||
|
Loading…
Reference in New Issue
Block a user