Display hero health

This commit is contained in:
Anton Vakhrushev 2020-10-15 10:26:07 +03:00
parent 901bea6b4e
commit 7d477ba35a
7 changed files with 58 additions and 14 deletions

View File

@ -86,7 +86,10 @@ export class Container {
this._grabberManager = this._grabberManager =
this._grabberManager || this._grabberManager ||
(() => { (() => {
return new GrabberManager(this.villageFactory); return new GrabberManager(
this.villageFactory,
new ConsoleLogger(GrabberManager.name)
);
})(); })();
return this._grabberManager; return this._grabberManager;
} }

View File

@ -23,6 +23,8 @@ import { timestamp } from './Helpers/Time';
import { notify, parseLocation, waitForLoad } from './Helpers/Browser'; import { notify, parseLocation, waitForLoad } from './Helpers/Browser';
import { Action } from './Queue/Action'; import { Action } from './Queue/Action';
import { Task } from './Queue/Task'; import { Task } from './Queue/Task';
import { HeroAttributes } from './Core/Hero';
import { HeroStorage } from './Storage/HeroStorage';
Vue.use(Vuex); Vue.use(Vuex);
@ -31,6 +33,7 @@ interface GameState {
version: string; version: string;
activeVillageState: VillageState | undefined; activeVillageState: VillageState | undefined;
villageStates: ReadonlyArray<VillageState>; villageStates: ReadonlyArray<VillageState>;
heroAttr: HeroAttributes;
taskList: ReadonlyArray<Task>; taskList: ReadonlyArray<Task>;
actionList: ReadonlyArray<Action>; actionList: ReadonlyArray<Action>;
pauseSeconds: number; pauseSeconds: number;
@ -64,17 +67,20 @@ export class ControlPanel {
const villageFactory = this.villageFactory; const villageFactory = this.villageFactory;
const executionState = new ExecutionStorage(); const executionState = new ExecutionStorage();
const heroStorage = new HeroStorage();
const state: GameState = { const state: GameState = {
name: 'Control', name: 'Control',
version: this.version, version: this.version,
activeVillageState: undefined, activeVillageState: undefined,
villageStates: [], villageStates: [],
heroAttr: HeroAttributes.default(),
taskList: [], taskList: [],
actionList: [], actionList: [],
pauseSeconds: 0, pauseSeconds: 0,
refresh() { refresh() {
this.heroAttr = heroStorage.getAttributes();
this.taskList = scheduler.getTaskItems(); this.taskList = scheduler.getTaskItems();
this.actionList = scheduler.getActionItems(); this.actionList = scheduler.getActionItems();
const { pauseTs } = executionState.getExecutionSettings(); const { pauseTs } = executionState.getExecutionSettings();

View File

@ -6,6 +6,10 @@ export class HeroAttributes {
constructor(health: number) { constructor(health: number) {
this.health = health; this.health = health;
} }
static default() {
return new HeroAttributes(0);
}
} }
export type HeroAllResourcesType = 'all'; export type HeroAllResourcesType = 'all';

View File

@ -1,8 +1,9 @@
<template> <template>
<main id="dashboard" v-on:keyup.76="toggleLogs"> <main id="dashboard" v-on:keyup.76="toggleLogs">
<section id="dashboard-primary"> <section id="dashboard-primary">
<hdr></hdr> <hdr />
<village-state-list /> <village-state-list />
<hero-view />
<hr class="separator" /> <hr class="separator" />
<task-list /> <task-list />
</section> </section>
@ -21,10 +22,12 @@ import LogList from './LogList';
import { mapState } from 'vuex'; import { mapState } from 'vuex';
import { Mutations } from './Store'; import { Mutations } from './Store';
import VillageEditor from './VillageEditor'; import VillageEditor from './VillageEditor';
import HeroView from './HeroView';
export default { export default {
components: { components: {
'village-editor': VillageEditor, 'village-editor': VillageEditor,
'hdr': Header, 'hdr': Header,
'hero-view': HeroView,
'task-list': TaskList, 'task-list': TaskList,
'village-state-list': VillageStateList, 'village-state-list': VillageStateList,
'log-list': LogList, 'log-list': LogList,

View File

@ -0,0 +1,26 @@
<template>
<table class="hero">
<tr>
<td>Герой</td>
<td>Здоровье</td>
<td v-text="shared.heroAttr.health"></td>
</tr>
</table>
</template>
<script>
export default {
data() {
return {
shared: this.$root.$data,
};
},
};
</script>
<style lang="scss" scoped>
@import 'style';
.hero {
@extend %table;
}
</style>

View File

@ -165,12 +165,8 @@ export class Executor {
} }
private runGrabbers() { private runGrabbers() {
try {
this.logger.info('Rug grabbers'); this.logger.info('Rug grabbers');
this.grabberManager.grab(); this.grabberManager.grab();
} catch (e) {
this.logger.warn('Grabbers fails with', e.message);
}
} }
} }

View File

@ -8,18 +8,24 @@ import { ForgePageGrabber } from './ForgePageGrabber';
import { GuildHallPageGrabber } from './GuildHallPageGrabber'; import { GuildHallPageGrabber } from './GuildHallPageGrabber';
import { VillageFactory } from '../Village/VillageFactory'; import { VillageFactory } from '../Village/VillageFactory';
import { VillageBuildingsPageGrabber } from './VillageBuildingsPageGrabber'; import { VillageBuildingsPageGrabber } from './VillageBuildingsPageGrabber';
import { GrabError } from '../Errors';
import { Logger } from '../Logger';
export class GrabberManager { export class GrabberManager {
private factory: VillageFactory; constructor(private readonly factory: VillageFactory, private readonly logger: Logger) {}
constructor(factory: VillageFactory) {
this.factory = factory;
}
grab() { grab() {
const grabbers = this.createGrabbers(); const grabbers = this.createGrabbers();
for (let grabber of grabbers) { for (let grabber of grabbers) {
try {
grabber.grab(); grabber.grab();
} catch (e) {
if (e instanceof GrabError) {
this.logger.warn('Grabbers fails with', e.message);
} else {
throw e;
}
}
} }
} }