Add action "make task first in queue"
This commit is contained in:
parent
9ae499f18c
commit
cf2d3878f3
@ -14,7 +14,12 @@ import DashboardApp from './Dashboard/Dashboard.vue';
|
||||
import { createStore } from './Dashboard/Store';
|
||||
import { ConsoleLogger, Logger } from './Logger';
|
||||
import { DataStorage } from './Storage/DataStorage';
|
||||
import { getBuildingPageAttributes, isAdventurePage, isBuildingPage } from './Page/PageDetector';
|
||||
import {
|
||||
getBuildingPageAttributes,
|
||||
isAdventurePage,
|
||||
isBuildingPage,
|
||||
isTrapperPage,
|
||||
} from './Page/PageDetector';
|
||||
import { ExecutionStorage } from './Storage/ExecutionStorage';
|
||||
import { VillageState } from './Village/VillageState';
|
||||
import { VillageFactory } from './Village/VillageFactory';
|
||||
@ -26,6 +31,7 @@ import { Task } from './Queue/Task';
|
||||
import { HeroAttributes } from './Core/Hero';
|
||||
import { HeroStorage } from './Storage/HeroStorage';
|
||||
import { showAdventureDifficulty } from './Page/AdventurePage';
|
||||
import { getTrapStats } from './Page/BuildingPage/TrapperPage';
|
||||
|
||||
Vue.use(Vuex);
|
||||
|
||||
@ -153,6 +159,10 @@ export class ControlPanel {
|
||||
showAdventureDifficulty();
|
||||
}
|
||||
|
||||
if (isTrapperPage()) {
|
||||
console.log('TRAPS', getTrapStats());
|
||||
}
|
||||
|
||||
this.createControlPanel(state, villageFactory);
|
||||
}
|
||||
|
||||
|
@ -8,3 +8,4 @@ export const HORSE_STABLE_ID = 20;
|
||||
export const GUILD_HALL_ID = 24;
|
||||
export const EMBASSY_ID = 25;
|
||||
export const PALACE_ID = 26;
|
||||
export const TRAPPER_ID = 36;
|
||||
|
7
src/Core/Traps.ts
Normal file
7
src/Core/Traps.ts
Normal file
@ -0,0 +1,7 @@
|
||||
export interface TrapStat {
|
||||
overall: number;
|
||||
current: number;
|
||||
built: number;
|
||||
used: number;
|
||||
canBuiltNow: number;
|
||||
}
|
@ -24,6 +24,7 @@ export enum Actions {
|
||||
RemoveVillageTask = 'remove_village_task',
|
||||
UpVillageTask = 'up_village_task',
|
||||
DownVillageTask = 'down_village_task',
|
||||
MakeFirstVillageTask = 'make_first_village_task',
|
||||
}
|
||||
|
||||
export function createStore(villageFactory: VillageFactory) {
|
||||
@ -111,6 +112,10 @@ export function createStore(villageFactory: VillageFactory) {
|
||||
const controller = villageFactory.getById(villageId).controller();
|
||||
controller.removeTask(taskId);
|
||||
},
|
||||
[Actions.MakeFirstVillageTask]({}, { villageId, taskId }) {
|
||||
const controller = villageFactory.getById(villageId).controller();
|
||||
controller.makeFirst(taskId);
|
||||
},
|
||||
[Actions.UpVillageTask]({}, { villageId, taskId }) {
|
||||
const controller = villageFactory.getById(villageId).controller();
|
||||
controller.upTask(taskId);
|
||||
|
@ -3,6 +3,9 @@
|
||||
<tr v-for="task in tasks">
|
||||
<td class="col-name" v-text="taskLabel(task)" :title="task.name + ', ' + task.id"></td>
|
||||
<td class="col-actions">
|
||||
<a href="#" class="action" @click.prevent="makeFirstTask(task.id)" title="Сделать первой"
|
||||
>fst</a
|
||||
>
|
||||
<a href="#" class="action" @click.prevent="upTask(task.id)" title="Поднять задачу">up</a>
|
||||
<a href="#" class="action" @click.prevent="downTask(task.id)" title="Опустить задачу">dn</a>
|
||||
<a href="#" class="action" @click.prevent="removeTask(task.id)" title="Удалить задачу">x</a>
|
||||
@ -39,6 +42,9 @@ export default {
|
||||
}
|
||||
return taskStatus + task.name;
|
||||
},
|
||||
makeFirstTask(taskId) {
|
||||
this.$store.dispatch(Actions.MakeFirstVillageTask, { villageId: this.villageId, taskId });
|
||||
},
|
||||
upTask(taskId) {
|
||||
this.$store.dispatch(Actions.UpVillageTask, { villageId: this.villageId, taskId });
|
||||
},
|
||||
|
18
src/Page/BuildingPage/TrapperPage.ts
Normal file
18
src/Page/BuildingPage/TrapperPage.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { Resources } from '../../Core/Resources';
|
||||
import { GrabError } from '../../Errors';
|
||||
import { grabResourcesFromList } from './BuildingPage';
|
||||
import { elClassId, getNumber } from '../../Helpers/Convert';
|
||||
import { uniqId } from '../../Helpers/Identity';
|
||||
import { TrapStat } from '../../Core/Traps';
|
||||
|
||||
export function getTrapStats(): TrapStat {
|
||||
const $buildValue = jQuery('#build_value');
|
||||
const $trapsEl = jQuery('.traps');
|
||||
return {
|
||||
built: getNumber($trapsEl.find('b').get(0).innerText),
|
||||
canBuiltNow: 0,
|
||||
current: getNumber($buildValue.find('.currentLevel .number').text()),
|
||||
overall: getNumber($buildValue.find('.overall .number').text()),
|
||||
used: getNumber($trapsEl.find('b').get(1).innerText),
|
||||
};
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import { FORGE_ID, GUILD_HALL_ID, MARKET_ID } from '../Core/Buildings';
|
||||
import { FORGE_ID, GUILD_HALL_ID, MARKET_ID, TRAPPER_ID } from '../Core/Buildings';
|
||||
import { elClassId, getNumber } from '../Helpers/Convert';
|
||||
import { parseLocation } from '../Helpers/Browser';
|
||||
|
||||
@ -65,3 +65,11 @@ export function isGuildHallPage(): boolean {
|
||||
const { buildTypeId } = getBuildingPageAttributes();
|
||||
return buildTypeId === GUILD_HALL_ID;
|
||||
}
|
||||
|
||||
export function isTrapperPage(): boolean {
|
||||
if (!isBuildingPage()) {
|
||||
return false;
|
||||
}
|
||||
const { buildTypeId } = getBuildingPageAttributes();
|
||||
return buildTypeId === TRAPPER_ID;
|
||||
}
|
||||
|
@ -56,6 +56,10 @@ export class VillageController {
|
||||
this.taskCollection.upTask(taskId);
|
||||
}
|
||||
|
||||
makeFirst(taskId: TaskId) {
|
||||
this.taskCollection.makeFirst(taskId);
|
||||
}
|
||||
|
||||
downTask(taskId: TaskId) {
|
||||
this.taskCollection.downTask(taskId);
|
||||
}
|
||||
|
@ -52,6 +52,17 @@ export class VillageTaskCollection {
|
||||
this.removeTasks((t) => t.id === taskId);
|
||||
}
|
||||
|
||||
makeFirst(taskId: TaskId): void {
|
||||
const tasks = this.storage.getTasks();
|
||||
const index = tasks.findIndex((t) => t.id === taskId);
|
||||
if (index < 0 || index === 0) {
|
||||
return;
|
||||
}
|
||||
const movedTask = tasks.splice(index, 1)[0];
|
||||
tasks.unshift(movedTask);
|
||||
this.storage.storeTaskList(tasks);
|
||||
}
|
||||
|
||||
upTask(taskId: TaskId): void {
|
||||
const tasks = this.storage.getTasks();
|
||||
const index = tasks.findIndex((t) => t.id === taskId);
|
||||
|
Loading…
Reference in New Issue
Block a user