Update prettier and reformat code
This commit is contained in:
parent
ecaa98b69c
commit
60078e94b2
15
package-lock.json
generated
15
package-lock.json
generated
@ -410,6 +410,15 @@
|
|||||||
"prettier": "^1.18.2",
|
"prettier": "^1.18.2",
|
||||||
"source-map": "~0.6.1",
|
"source-map": "~0.6.1",
|
||||||
"vue-template-es2015-compiler": "^1.9.0"
|
"vue-template-es2015-compiler": "^1.9.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"prettier": {
|
||||||
|
"version": "1.19.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz",
|
||||||
|
"integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==",
|
||||||
|
"dev": true,
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@webassemblyjs/ast": {
|
"@webassemblyjs/ast": {
|
||||||
@ -4107,9 +4116,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"prettier": {
|
"prettier": {
|
||||||
"version": "1.19.1",
|
"version": "2.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz",
|
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.1.2.tgz",
|
||||||
"integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==",
|
"integrity": "sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"process": {
|
"process": {
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
"mocha": "^7.2.0",
|
"mocha": "^7.2.0",
|
||||||
"mocha-junit-reporter": "^1.23.3",
|
"mocha-junit-reporter": "^1.23.3",
|
||||||
"nyc": "^15.1.0",
|
"nyc": "^15.1.0",
|
||||||
"prettier": "^1.19.1",
|
"prettier": "^2.1.2",
|
||||||
"raw-loader": "^4.0.2",
|
"raw-loader": "^4.0.2",
|
||||||
"sass": "^1.27.0",
|
"sass": "^1.27.0",
|
||||||
"sass-loader": "^8.0.2",
|
"sass-loader": "^8.0.2",
|
||||||
|
@ -113,12 +113,12 @@ export class ControlPanel {
|
|||||||
this.villageFactory
|
this.villageFactory
|
||||||
.createTaskCollection(villageId)
|
.createTaskCollection(villageId)
|
||||||
.getTasks()
|
.getTasks()
|
||||||
.filter(t => t.name === UpgradeBuildingTask.name)
|
.filter((t) => t.name === UpgradeBuildingTask.name)
|
||||||
.map(t => t.args.buildId || 0);
|
.map((t) => t.args.buildId || 0);
|
||||||
|
|
||||||
if (p.pathname === '/dorf1.php') {
|
if (p.pathname === '/dorf1.php') {
|
||||||
showResourceSlotIds(getBuildingsInQueue());
|
showResourceSlotIds(getBuildingsInQueue());
|
||||||
onResourceSlotCtrlClick(buildId => {
|
onResourceSlotCtrlClick((buildId) => {
|
||||||
this.onSlotCtrlClick(villageId, buildId);
|
this.onSlotCtrlClick(villageId, buildId);
|
||||||
showResourceSlotIds(getBuildingsInQueue());
|
showResourceSlotIds(getBuildingsInQueue());
|
||||||
});
|
});
|
||||||
@ -126,7 +126,7 @@ export class ControlPanel {
|
|||||||
|
|
||||||
if (p.pathname === '/dorf2.php') {
|
if (p.pathname === '/dorf2.php') {
|
||||||
showBuildingSlotIds(getBuildingsInQueue());
|
showBuildingSlotIds(getBuildingsInQueue());
|
||||||
onBuildingSlotCtrlClick(buildId => {
|
onBuildingSlotCtrlClick((buildId) => {
|
||||||
this.onSlotCtrlClick(villageId, buildId);
|
this.onSlotCtrlClick(villageId, buildId);
|
||||||
showBuildingSlotIds(getBuildingsInQueue());
|
showBuildingSlotIds(getBuildingsInQueue());
|
||||||
});
|
});
|
||||||
@ -151,7 +151,7 @@ export class ControlPanel {
|
|||||||
el: `#${appId}`,
|
el: `#${appId}`,
|
||||||
data: gameState,
|
data: gameState,
|
||||||
store: createStore(villageFactory),
|
store: createStore(villageFactory),
|
||||||
render: h => h(DashboardApp),
|
render: (h) => h(DashboardApp),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,8 +36,8 @@ export default {
|
|||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapState({
|
...mapState({
|
||||||
isLogsVisible: state => state.views.logs,
|
isLogsVisible: (state) => state.views.logs,
|
||||||
isVillageEditorVisible: state => state.views.villageEditor,
|
isVillageEditorVisible: (state) => state.views.villageEditor,
|
||||||
}),
|
}),
|
||||||
isSecondaryDashboardVisible() {
|
isSecondaryDashboardVisible() {
|
||||||
return this.isLogsVisible || this.isVillageEditorVisible;
|
return this.isLogsVisible || this.isVillageEditorVisible;
|
||||||
|
@ -43,7 +43,7 @@ export function createStore(villageFactory: VillageFactory) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
reverseLogs: state => {
|
reverseLogs: (state) => {
|
||||||
return state.logs.slice().reverse();
|
return state.logs.slice().reverse();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -27,7 +27,7 @@ import { mapState } from 'vuex';
|
|||||||
export default {
|
export default {
|
||||||
computed: {
|
computed: {
|
||||||
...mapState({
|
...mapState({
|
||||||
villageName: state => state.villageSettings.villageName,
|
villageName: (state) => state.villageSettings.villageName,
|
||||||
}),
|
}),
|
||||||
sendResourcesThreshold: {
|
sendResourcesThreshold: {
|
||||||
get() {
|
get() {
|
||||||
|
@ -44,9 +44,7 @@ export class SendOnAdventureAction extends BaseAction {
|
|||||||
private checkConfig(adventure: Adventure, health: number) {
|
private checkConfig(adventure: Adventure, health: number) {
|
||||||
for (let conf of CONFIG) {
|
for (let conf of CONFIG) {
|
||||||
if (adventure.level === conf.level && health >= conf.health) {
|
if (adventure.level === conf.level && health >= conf.health) {
|
||||||
return jQuery(adventure.el)
|
return jQuery(adventure.el).find('td.goTo .gotoAdventure').trigger('click');
|
||||||
.find('td.goTo .gotoAdventure')
|
|
||||||
.trigger('click');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -55,11 +53,7 @@ export class SendOnAdventureAction extends BaseAction {
|
|||||||
const adventures: Array<Adventure> = [];
|
const adventures: Array<Adventure> = [];
|
||||||
|
|
||||||
jQuery('tr[id^=adventure]').each((index, el) => {
|
jQuery('tr[id^=adventure]').each((index, el) => {
|
||||||
const imgClass =
|
const imgClass = jQuery(el).find('.difficulty img').attr('class')?.toString() || '';
|
||||||
jQuery(el)
|
|
||||||
.find('.difficulty img')
|
|
||||||
.attr('class')
|
|
||||||
?.toString() || '';
|
|
||||||
const level = Number(trimPrefix(imgClass, 'adventureDifficulty'));
|
const level = Number(trimPrefix(imgClass, 'adventureDifficulty'));
|
||||||
if (!isNaN(level)) {
|
if (!isNaN(level)) {
|
||||||
adventures.push({ el, level: level });
|
adventures.push({ el, level: level });
|
||||||
|
@ -22,7 +22,7 @@ export class UpgradeResourceToLevelAction extends BaseAction {
|
|||||||
const requiredLevel = getNumber(args.level);
|
const requiredLevel = getNumber(args.level);
|
||||||
|
|
||||||
const notUpgraded = deposits.filter(
|
const notUpgraded = deposits.filter(
|
||||||
dep => !dep.isUnderConstruction && requiredLevel > dep.level
|
(dep) => !dep.isUnderConstruction && requiredLevel > dep.level
|
||||||
);
|
);
|
||||||
|
|
||||||
if (notUpgraded.length === 0) {
|
if (notUpgraded.length === 0) {
|
||||||
@ -59,7 +59,7 @@ export class UpgradeResourceToLevelAction extends BaseAction {
|
|||||||
return (
|
return (
|
||||||
undefined ===
|
undefined ===
|
||||||
tasks.find(
|
tasks.find(
|
||||||
task =>
|
(task) =>
|
||||||
task.name === UpgradeBuildingTask.name &&
|
task.name === UpgradeBuildingTask.name &&
|
||||||
task.args.villageId === villageId &&
|
task.args.villageId === villageId &&
|
||||||
task.args.buildId === dep.buildId
|
task.args.buildId === dep.buildId
|
||||||
|
@ -12,7 +12,7 @@ export class UpdateResourceContractsTask extends BaseTask {
|
|||||||
const villages = this.factory.getAllVillages();
|
const villages = this.factory.getAllVillages();
|
||||||
|
|
||||||
const tasks = villages
|
const tasks = villages
|
||||||
.map(v => this.factory.createTaskCollection(v.id).getTasks())
|
.map((v) => this.factory.createTaskCollection(v.id).getTasks())
|
||||||
.reduce((acc, tasks) => acc.concat(tasks), []);
|
.reduce((acc, tasks) => acc.concat(tasks), []);
|
||||||
|
|
||||||
const paths = uniqPaths([
|
const paths = uniqPaths([
|
||||||
@ -20,7 +20,7 @@ export class UpdateResourceContractsTask extends BaseTask {
|
|||||||
...this.walkImprovementTask(tasks),
|
...this.walkImprovementTask(tasks),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return paths.map(p => ({
|
return paths.map((p) => ({
|
||||||
name: GoToPageAction.name,
|
name: GoToPageAction.name,
|
||||||
args: { path: path(p.name, p.query) },
|
args: { path: path(p.name, p.query) },
|
||||||
}));
|
}));
|
||||||
@ -28,8 +28,10 @@ export class UpdateResourceContractsTask extends BaseTask {
|
|||||||
|
|
||||||
private walkUpgradeTasks(tasks: ImmutableTaskList): PathList {
|
private walkUpgradeTasks(tasks: ImmutableTaskList): PathList {
|
||||||
return tasks
|
return tasks
|
||||||
.filter(t => t.name === UpgradeBuildingTask.name && t.args.villageId && t.args.buildId)
|
.filter(
|
||||||
.map(t => ({
|
(t) => t.name === UpgradeBuildingTask.name && t.args.villageId && t.args.buildId
|
||||||
|
)
|
||||||
|
.map((t) => ({
|
||||||
name: '/build.php',
|
name: '/build.php',
|
||||||
query: { newdid: t.args.villageId, id: t.args.buildId },
|
query: { newdid: t.args.villageId, id: t.args.buildId },
|
||||||
}));
|
}));
|
||||||
@ -37,8 +39,10 @@ export class UpdateResourceContractsTask extends BaseTask {
|
|||||||
|
|
||||||
private walkImprovementTask(tasks: ImmutableTaskList): PathList {
|
private walkImprovementTask(tasks: ImmutableTaskList): PathList {
|
||||||
return tasks
|
return tasks
|
||||||
.filter(t => t.name === ForgeImprovementTask.name && t.args.villageId && t.args.buildId)
|
.filter(
|
||||||
.map(t => ({
|
(t) => t.name === ForgeImprovementTask.name && t.args.villageId && t.args.buildId
|
||||||
|
)
|
||||||
|
.map((t) => ({
|
||||||
name: '/build.php',
|
name: '/build.php',
|
||||||
query: { newdid: t.args.villageId, id: t.args.buildId },
|
query: { newdid: t.args.villageId, id: t.args.buildId },
|
||||||
}));
|
}));
|
||||||
|
@ -55,7 +55,7 @@ export function createTaskHandler(
|
|||||||
/**
|
/**
|
||||||
* List on non intersected task queue predicates.
|
* List on non intersected task queue predicates.
|
||||||
*/
|
*/
|
||||||
const TASK_TYPE_PREDICATES: Array<TaskNamePredicate> = OrderedProductionQueues.map(queue => {
|
const TASK_TYPE_PREDICATES: Array<TaskNamePredicate> = OrderedProductionQueues.map((queue) => {
|
||||||
return (taskName: string) => getProductionQueue(taskName) === queue;
|
return (taskName: string) => getProductionQueue(taskName) === queue;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import * as URLParse from 'url-parse';
|
import * as URLParse from 'url-parse';
|
||||||
|
|
||||||
export async function waitForLoad() {
|
export async function waitForLoad() {
|
||||||
return new Promise(resolve => jQuery(resolve));
|
return new Promise((resolve) => jQuery(resolve));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parseLocation(location?: string | undefined) {
|
export function parseLocation(location?: string | undefined) {
|
||||||
|
@ -7,7 +7,7 @@ export function elClassId(classes: string | undefined, prefix: string): number |
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
let result: number | undefined = undefined;
|
let result: number | undefined = undefined;
|
||||||
classes.split(/\s/).forEach(part => {
|
classes.split(/\s/).forEach((part) => {
|
||||||
const match = part.match(new RegExp(prefix + '(\\d+)'));
|
const match = part.match(new RegExp(prefix + '(\\d+)'));
|
||||||
if (match) {
|
if (match) {
|
||||||
result = toNumber(match[1]);
|
result = toNumber(match[1]);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { around, randomInRange } from './Random';
|
import { around, randomInRange } from './Random';
|
||||||
|
|
||||||
export function sleep(ms: number) {
|
export function sleep(ms: number) {
|
||||||
return new Promise(resolve => setTimeout(resolve, ms));
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function sleepMicro() {
|
export async function sleepMicro() {
|
||||||
|
@ -26,7 +26,7 @@ export function createBuildButton(
|
|||||||
const resElement = $el.find('.resourceWrapper .resource');
|
const resElement = $el.find('.resourceWrapper .resource');
|
||||||
const resources = grabResourcesFromList(resElement);
|
const resources = grabResourcesFromList(resElement);
|
||||||
$el.append(`<div style="padding: 8px"><a id="${btnId}" href="#">Построить</a></div>`);
|
$el.append(`<div style="padding: 8px"><a id="${btnId}" href="#">Построить</a></div>`);
|
||||||
jQuery(`#${btnId}`).on('click', evt => {
|
jQuery(`#${btnId}`).on('click', (evt) => {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
onClickHandler(buildTypeId, resources);
|
onClickHandler(buildTypeId, resources);
|
||||||
});
|
});
|
||||||
@ -50,17 +50,14 @@ export function createUpgradeButton(onClickHandler: (resources: Resources) => vo
|
|||||||
const btn = `<div style="padding: 8px"><a id="${id}" href="#">В очередь</a></div>`;
|
const btn = `<div style="padding: 8px"><a id="${id}" href="#">В очередь</a></div>`;
|
||||||
upgradeContainer.append(btn);
|
upgradeContainer.append(btn);
|
||||||
const resources = grabContractResources();
|
const resources = grabContractResources();
|
||||||
jQuery(`#${id}`).on('click', evt => {
|
jQuery(`#${id}`).on('click', (evt) => {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
onClickHandler(resources);
|
onClickHandler(resources);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function grabResourcesFromList($els: JQuery) {
|
export function grabResourcesFromList($els: JQuery) {
|
||||||
const getText = (n: number) =>
|
const getText = (n: number) => jQuery($els.get(n)).find('.value').text();
|
||||||
jQuery($els.get(n))
|
|
||||||
.find('.value')
|
|
||||||
.text();
|
|
||||||
const grab = (n: number) => getNumber(getText(n));
|
const grab = (n: number) => getNumber(getText(n));
|
||||||
return new Resources(grab(0), grab(1), grab(2), grab(3));
|
return new Resources(grab(0), grab(1), grab(2), grab(3));
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ function createResearchButton($researchBlockEl: JQuery, onClickHandler: Research
|
|||||||
<a id="${id}" href="#">Исследовать</a>
|
<a id="${id}" href="#">Исследовать</a>
|
||||||
</div>`);
|
</div>`);
|
||||||
|
|
||||||
jQuery(`#${id}`).on('click', evt => {
|
jQuery(`#${id}`).on('click', (evt) => {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
onClickHandler(resources, unitId);
|
onClickHandler(resources, unitId);
|
||||||
});
|
});
|
||||||
|
@ -45,7 +45,7 @@ function createCelebrationButton(
|
|||||||
<a id="${id}" href="#">Праздновать</a>
|
<a id="${id}" href="#">Праздновать</a>
|
||||||
</div>`);
|
</div>`);
|
||||||
|
|
||||||
jQuery(`#${id}`).on('click', evt => {
|
jQuery(`#${id}`).on('click', (evt) => {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
onClickHandler(resources, idx);
|
onClickHandler(resources, idx);
|
||||||
});
|
});
|
||||||
|
@ -23,7 +23,7 @@ export function createTrainTroopButtons(
|
|||||||
);
|
);
|
||||||
const resElement = $el.find('.resourceWrapper .resource');
|
const resElement = $el.find('.resourceWrapper .resource');
|
||||||
const resources = grabResourcesFromList(resElement);
|
const resources = grabResourcesFromList(resElement);
|
||||||
jQuery(`#${id}`).on('click', evt => {
|
jQuery(`#${id}`).on('click', (evt) => {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
const input = $el.find(`input[name="t${troopId}"]`);
|
const input = $el.find(`input[name="t${troopId}"]`);
|
||||||
const count = getNumber(input.val());
|
const count = getNumber(input.val());
|
||||||
|
@ -46,7 +46,7 @@ export class BuildingPageController {
|
|||||||
this.logger.info('BUILD PAGE DETECTED', 'ID', this.attributes.buildId, this.attributes);
|
this.logger.info('BUILD PAGE DETECTED', 'ID', this.attributes.buildId, this.attributes);
|
||||||
|
|
||||||
if (buildTypeId) {
|
if (buildTypeId) {
|
||||||
createUpgradeButton(res => this.onScheduleUpgradeBuilding(res));
|
createUpgradeButton((res) => this.onScheduleUpgradeBuilding(res));
|
||||||
} else {
|
} else {
|
||||||
createBuildButton((buildTypeId, res) => this.onScheduleBuildBuilding(buildTypeId, res));
|
createBuildButton((buildTypeId, res) => this.onScheduleBuildBuilding(buildTypeId, res));
|
||||||
}
|
}
|
||||||
@ -126,7 +126,7 @@ export class BuildingPageController {
|
|||||||
|
|
||||||
private onSendResources(coordinates: Coordinates) {
|
private onSendResources(coordinates: Coordinates) {
|
||||||
const villageId = grabActiveVillageId();
|
const villageId = grabActiveVillageId();
|
||||||
const targetVillage = grabVillageList().find(v => v.crd.eq(coordinates));
|
const targetVillage = grabVillageList().find((v) => v.crd.eq(coordinates));
|
||||||
this.scheduler.scheduleTask(SendResourcesTask.name, {
|
this.scheduler.scheduleTask(SendResourcesTask.name, {
|
||||||
villageId: villageId,
|
villageId: villageId,
|
||||||
targetVillageId: targetVillage?.id,
|
targetVillageId: targetVillage?.id,
|
||||||
|
@ -18,8 +18,8 @@ function slotElements(prefix: string): Array<SlotElement> {
|
|||||||
|
|
||||||
function showSlotIds(prefix: string, buildingIds: Array<number>): void {
|
function showSlotIds(prefix: string, buildingIds: Array<number>): void {
|
||||||
const slots = slotElements(prefix);
|
const slots = slotElements(prefix);
|
||||||
slots.forEach(slot => {
|
slots.forEach((slot) => {
|
||||||
const upCount = buildingIds.filter(id => id === slot.buildId).length;
|
const upCount = buildingIds.filter((id) => id === slot.buildId).length;
|
||||||
const $slotEl = jQuery(slot.el);
|
const $slotEl = jQuery(slot.el);
|
||||||
const $labelEl = $slotEl.find('.labelLayer');
|
const $labelEl = $slotEl.find('.labelLayer');
|
||||||
const oldLabel = $labelEl.data('oldLabel') || $labelEl.text();
|
const oldLabel = $labelEl.data('oldLabel') || $labelEl.text();
|
||||||
@ -53,10 +53,10 @@ export function showBuildingSlotIds(buildingIds: number[]): void {
|
|||||||
|
|
||||||
function onSlotCtrlClick(prefix: string, onClickHandler: (buildId: number) => void): void {
|
function onSlotCtrlClick(prefix: string, onClickHandler: (buildId: number) => void): void {
|
||||||
const slots = slotElements(prefix);
|
const slots = slotElements(prefix);
|
||||||
slots.forEach(slot => {
|
slots.forEach((slot) => {
|
||||||
jQuery(slot.el)
|
jQuery(slot.el)
|
||||||
.find('.labelLayer')
|
.find('.labelLayer')
|
||||||
.on('click', evt => {
|
.on('click', (evt) => {
|
||||||
if (evt.ctrlKey) {
|
if (evt.ctrlKey) {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
evt.stopPropagation();
|
evt.stopPropagation();
|
||||||
|
@ -47,7 +47,7 @@ export class ActionQueue {
|
|||||||
|
|
||||||
const items = serialized as Array<{ [key: string]: any }>;
|
const items = serialized as Array<{ [key: string]: any }>;
|
||||||
|
|
||||||
return items.map(i => {
|
return items.map((i) => {
|
||||||
const command = { name: '', args: {} };
|
const command = { name: '', args: {} };
|
||||||
return Object.assign(command, i);
|
return Object.assign(command, i);
|
||||||
});
|
});
|
||||||
|
@ -24,7 +24,7 @@ export class DataStorageTaskProvider implements TaskProvider {
|
|||||||
|
|
||||||
const storedItems = serialized as Array<{ [key: string]: any }>;
|
const storedItems = serialized as Array<{ [key: string]: any }>;
|
||||||
|
|
||||||
return storedItems.map(i => {
|
return storedItems.map((i) => {
|
||||||
const task = new Task(uniqTaskId(), 0, '', {});
|
const task = new Task(uniqTaskId(), 0, '', {});
|
||||||
return Object.assign(task, i);
|
return Object.assign(task, i);
|
||||||
});
|
});
|
||||||
|
@ -19,7 +19,7 @@ export class TaskQueue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get(ts: number): Task | undefined {
|
get(ts: number): Task | undefined {
|
||||||
const readyItems = this.getItems().filter(t => t.ts <= ts);
|
const readyItems = this.getItems().filter((t) => t.ts <= ts);
|
||||||
if (readyItems.length === 0) {
|
if (readyItems.length === 0) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
@ -27,7 +27,7 @@ export class TaskQueue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
findById(taskId: TaskId): Task | undefined {
|
findById(taskId: TaskId): Task | undefined {
|
||||||
const [matched, _] = this.split(t => t.id === taskId);
|
const [matched, _] = this.split((t) => t.id === taskId);
|
||||||
return matched.shift();
|
return matched.shift();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ export class TaskQueue {
|
|||||||
private split(predicate: (t: Task) => boolean): [TaskList, TaskList] {
|
private split(predicate: (t: Task) => boolean): [TaskList, TaskList] {
|
||||||
const matched: TaskList = [];
|
const matched: TaskList = [];
|
||||||
const other: TaskList = [];
|
const other: TaskList = [];
|
||||||
this.getItems().forEach(t => {
|
this.getItems().forEach((t) => {
|
||||||
if (predicate(t)) {
|
if (predicate(t)) {
|
||||||
matched.push(t);
|
matched.push(t);
|
||||||
} else {
|
} else {
|
||||||
|
@ -141,10 +141,10 @@ export class Scheduler {
|
|||||||
let alreadyHasTask;
|
let alreadyHasTask;
|
||||||
if (args.villageId) {
|
if (args.villageId) {
|
||||||
alreadyHasTask = this.taskQueue.has(
|
alreadyHasTask = this.taskQueue.has(
|
||||||
t => t.name === name && t.args.villageId === args.villageId
|
(t) => t.name === name && t.args.villageId === args.villageId
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
alreadyHasTask = this.taskQueue.has(t => t.name === name);
|
alreadyHasTask = this.taskQueue.has((t) => t.name === name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!alreadyHasTask) {
|
if (!alreadyHasTask) {
|
||||||
@ -153,7 +153,7 @@ export class Scheduler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
removeTask(taskId: TaskId) {
|
removeTask(taskId: TaskId) {
|
||||||
this.taskQueue.remove(t => t.id === taskId);
|
this.taskQueue.remove((t) => t.id === taskId);
|
||||||
this.actionQueue.clear();
|
this.actionQueue.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,7 +168,7 @@ export class Scheduler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
postponeTask(taskId: TaskId, seconds: number) {
|
postponeTask(taskId: TaskId, seconds: number) {
|
||||||
const task = this.taskQueue.seeItems().find(t => t.id === taskId);
|
const task = this.taskQueue.seeItems().find((t) => t.id === taskId);
|
||||||
if (!task) {
|
if (!task) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -179,7 +179,7 @@ export class Scheduler {
|
|||||||
this.removeTask(taskId);
|
this.removeTask(taskId);
|
||||||
} else {
|
} else {
|
||||||
const modifyTime = withTime(timestamp() + seconds);
|
const modifyTime = withTime(timestamp() + seconds);
|
||||||
this.taskQueue.modify(t => t.id === taskId, modifyTime);
|
this.taskQueue.modify((t) => t.id === taskId, modifyTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,10 +42,7 @@ export class Statistics {
|
|||||||
|
|
||||||
private getTopStatKeys(stat: ActionStatistics) {
|
private getTopStatKeys(stat: ActionStatistics) {
|
||||||
const keys = Object.keys(stat);
|
const keys = Object.keys(stat);
|
||||||
return keys
|
return keys.sort().reverse().slice(0, KEEP_RECORD_COUNT);
|
||||||
.sort()
|
|
||||||
.reverse()
|
|
||||||
.slice(0, KEEP_RECORD_COUNT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getActionStatistics(): ActionStatistics {
|
getActionStatistics(): ActionStatistics {
|
||||||
|
@ -6,7 +6,7 @@ const NAMESPACE = 'travian:v1';
|
|||||||
const storage = localStorage;
|
const storage = localStorage;
|
||||||
|
|
||||||
function join(...parts: Array<string>) {
|
function join(...parts: Array<string>) {
|
||||||
return parts.map(p => p.replace(/[:]+$/g, '').replace(/^[:]+/g, '')).join(':');
|
return parts.map((p) => p.replace(/[:]+$/g, '').replace(/^[:]+/g, '')).join(':');
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DataStorage {
|
export class DataStorage {
|
||||||
|
@ -19,7 +19,7 @@ export function createMapper<T>(options: ObjectMapperOptions<T>): ObjectMapper<T
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (factory) {
|
if (factory) {
|
||||||
return plain => {
|
return (plain) => {
|
||||||
let item = factory();
|
let item = factory();
|
||||||
if (typeof plain === 'object' && typeof item === 'object') {
|
if (typeof plain === 'object' && typeof item === 'object') {
|
||||||
return Object.assign(item, plain) as T;
|
return Object.assign(item, plain) as T;
|
||||||
|
@ -74,7 +74,7 @@ export class VillageStorage {
|
|||||||
storeIncomingMerchants(merchants: ReadonlyArray<IncomingMerchant>): void {
|
storeIncomingMerchants(merchants: ReadonlyArray<IncomingMerchant>): void {
|
||||||
this.storage.set(
|
this.storage.set(
|
||||||
INCOMING_MERCHANTS_KEY,
|
INCOMING_MERCHANTS_KEY,
|
||||||
merchants.map(m => ({ ...m.resources, ts: m.ts }))
|
merchants.map((m) => ({ ...m.resources, ts: m.ts }))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,9 +6,7 @@ const ID = uniqId();
|
|||||||
|
|
||||||
export class TaskQueueRenderer {
|
export class TaskQueueRenderer {
|
||||||
render(tasks: ImmutableTaskList) {
|
render(tasks: ImmutableTaskList) {
|
||||||
const ul = jQuery('<ul></ul>')
|
const ul = jQuery('<ul></ul>').attr({ id: ID }).css({
|
||||||
.attr({ id: ID })
|
|
||||||
.css({
|
|
||||||
'position': 'absolute',
|
'position': 'absolute',
|
||||||
'background-color': 'white',
|
'background-color': 'white',
|
||||||
'left': 0,
|
'left': 0,
|
||||||
@ -17,7 +15,7 @@ export class TaskQueueRenderer {
|
|||||||
'z-index': '9999',
|
'z-index': '9999',
|
||||||
'padding': '8px 6px',
|
'padding': '8px 6px',
|
||||||
});
|
});
|
||||||
tasks.forEach(task => {
|
tasks.forEach((task) => {
|
||||||
ul.append(
|
ul.append(
|
||||||
jQuery('<li></li>').text(formatDate(task.ts) + ' ' + task.name + ' ' + task.id)
|
jQuery('<li></li>').text(formatDate(task.ts) + ' ' + task.name + ' ' + task.id)
|
||||||
);
|
);
|
||||||
|
@ -171,19 +171,21 @@ export class VillageController {
|
|||||||
const resourceSlots = this.storage.getResourceSlots();
|
const resourceSlots = this.storage.getResourceSlots();
|
||||||
const tasks = this.taskCollection.getTasks();
|
const tasks = this.taskCollection.getTasks();
|
||||||
|
|
||||||
const cropSlots = resourceSlots.filter(s => s.type === ResourceType.Crop && !s.isMaxLevel);
|
const cropSlots = resourceSlots.filter(
|
||||||
|
(s) => s.type === ResourceType.Crop && !s.isMaxLevel
|
||||||
|
);
|
||||||
if (cropSlots.length === 0) {
|
if (cropSlots.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check, if crop field is building now
|
// Check, if crop field is building now
|
||||||
const underContraction = cropSlots.find(s => s.isUnderConstruction);
|
const underContraction = cropSlots.find((s) => s.isUnderConstruction);
|
||||||
if (underContraction !== undefined) {
|
if (underContraction !== undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check, if we already have crop task in queue
|
// Check, if we already have crop task in queue
|
||||||
const cropBuildIds = cropSlots.map(s => s.buildId);
|
const cropBuildIds = cropSlots.map((s) => s.buildId);
|
||||||
for (let buildId of cropBuildIds) {
|
for (let buildId of cropBuildIds) {
|
||||||
const upgradeTask = tasks.find(
|
const upgradeTask = tasks.find(
|
||||||
isBuildingPlanned(UpgradeBuildingTask.name, buildId, undefined)
|
isBuildingPlanned(UpgradeBuildingTask.name, buildId, undefined)
|
||||||
@ -207,11 +209,11 @@ export class VillageController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private planWarehouseBuilding(): void {
|
private planWarehouseBuilding(): void {
|
||||||
this.planStorageBuilding(WAREHOUSE_ID, t => !t.isEnoughWarehouseCapacity);
|
this.planStorageBuilding(WAREHOUSE_ID, (t) => !t.isEnoughWarehouseCapacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
private planGranaryBuilding(): void {
|
private planGranaryBuilding(): void {
|
||||||
this.planStorageBuilding(GARNER_ID, t => !t.isEnoughGranaryCapacity);
|
this.planStorageBuilding(GARNER_ID, (t) => !t.isEnoughGranaryCapacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
private planStorageBuilding(
|
private planStorageBuilding(
|
||||||
@ -221,14 +223,14 @@ export class VillageController {
|
|||||||
const buildingSlots = this.storage.getBuildingSlots();
|
const buildingSlots = this.storage.getBuildingSlots();
|
||||||
|
|
||||||
const storageSlots = buildingSlots.filter(
|
const storageSlots = buildingSlots.filter(
|
||||||
s => s.buildTypeId === buildTypeId && !s.isMaxLevel
|
(s) => s.buildTypeId === buildTypeId && !s.isMaxLevel
|
||||||
);
|
);
|
||||||
if (storageSlots.length === 0) {
|
if (storageSlots.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check, if storage is building now
|
// Check, if storage is building now
|
||||||
const underConstruction = storageSlots.find(s => s.isUnderConstruction);
|
const underConstruction = storageSlots.find((s) => s.isUnderConstruction);
|
||||||
if (underConstruction !== undefined) {
|
if (underConstruction !== undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -236,7 +238,7 @@ export class VillageController {
|
|||||||
const tasks = this.state.tasks;
|
const tasks = this.state.tasks;
|
||||||
|
|
||||||
// Check, if we have storage is in building queue
|
// Check, if we have storage is in building queue
|
||||||
const storageBuildIds = storageSlots.map(s => s.buildId);
|
const storageBuildIds = storageSlots.map((s) => s.buildId);
|
||||||
for (let buildId of storageBuildIds) {
|
for (let buildId of storageBuildIds) {
|
||||||
const upgradeTask = tasks.find(
|
const upgradeTask = tasks.find(
|
||||||
isBuildingPlanned(UpgradeBuildingTask.name, buildId, buildTypeId)
|
isBuildingPlanned(UpgradeBuildingTask.name, buildId, buildTypeId)
|
||||||
|
@ -13,7 +13,7 @@ export class VillageRepository implements VillageRepositoryInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get(villageId: number): Village {
|
get(villageId: number): Village {
|
||||||
const village = this.all().find(vlg => vlg.id === villageId);
|
const village = this.all().find((vlg) => vlg.id === villageId);
|
||||||
if (!village) {
|
if (!village) {
|
||||||
throw new VillageNotFound('Active village not found');
|
throw new VillageNotFound('Active village not found');
|
||||||
}
|
}
|
||||||
@ -21,7 +21,7 @@ export class VillageRepository implements VillageRepositoryInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getByCrd(crd: Coordinates): Village {
|
getByCrd(crd: Coordinates): Village {
|
||||||
const village = this.all().find(vlg => vlg.crd.eq(crd));
|
const village = this.all().find((vlg) => vlg.crd.eq(crd));
|
||||||
if (!village) {
|
if (!village) {
|
||||||
throw new VillageNotFound('Village not found');
|
throw new VillageNotFound('Village not found');
|
||||||
}
|
}
|
||||||
@ -29,7 +29,7 @@ export class VillageRepository implements VillageRepositoryInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getActive(): Village {
|
getActive(): Village {
|
||||||
const village = this.all().find(vlg => vlg.active);
|
const village = this.all().find((vlg) => vlg.active);
|
||||||
if (!village) {
|
if (!village) {
|
||||||
throw new VillageNotFound('Active village not found');
|
throw new VillageNotFound('Active village not found');
|
||||||
}
|
}
|
||||||
|
@ -220,7 +220,7 @@ function createTaskQueueStates(
|
|||||||
storage: VillageStorage
|
storage: VillageStorage
|
||||||
) {
|
) {
|
||||||
let result: Array<VillageProductionQueueState> = [];
|
let result: Array<VillageProductionQueueState> = [];
|
||||||
const possibleTasks = tasks.filter(task => task.canBeBuilt);
|
const possibleTasks = tasks.filter((task) => task.canBeBuilt);
|
||||||
for (let taskQueueInfo of getGroupedByQueueTasks(possibleTasks, storage)) {
|
for (let taskQueueInfo of getGroupedByQueueTasks(possibleTasks, storage)) {
|
||||||
result.push(createProductionQueueState(taskQueueInfo, warehouse));
|
result.push(createProductionQueueState(taskQueueInfo, warehouse));
|
||||||
}
|
}
|
||||||
@ -230,12 +230,14 @@ function createTaskQueueStates(
|
|||||||
function getReadyForProductionTask(
|
function getReadyForProductionTask(
|
||||||
queues: ReadonlyArray<VillageProductionQueueState>
|
queues: ReadonlyArray<VillageProductionQueueState>
|
||||||
): TaskState | undefined {
|
): TaskState | undefined {
|
||||||
const firstReadyQueue = queues.find(queue => queue.isWaiting);
|
const firstReadyQueue = queues.find((queue) => queue.isWaiting);
|
||||||
if (!firstReadyQueue) {
|
if (!firstReadyQueue) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
return firstReadyQueue.tasks.find(task => task.name === TrainTroopTask.name || task.canBeBuilt);
|
return firstReadyQueue.tasks.find(
|
||||||
|
(task) => task.name === TrainTroopTask.name || task.canBeBuilt
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTaskResources(task: TaskCore | undefined): Resources {
|
function getTaskResources(task: TaskCore | undefined): Resources {
|
||||||
@ -284,7 +286,7 @@ function createVillageOwnState(
|
|||||||
const storageState = makeStorageState(resources, storageResources, performance);
|
const storageState = makeStorageState(resources, storageResources, performance);
|
||||||
const tasks = taskCollection
|
const tasks = taskCollection
|
||||||
.getTasks()
|
.getTasks()
|
||||||
.map(t => makeTaskState(t, storageState.optimumFullness));
|
.map((t) => makeTaskState(t, storageState.optimumFullness));
|
||||||
const queues = createTaskQueueStates(storageState, tasks, storage);
|
const queues = createTaskQueueStates(storageState, tasks, storage);
|
||||||
const firstReadyTask = getReadyForProductionTask(queues);
|
const firstReadyTask = getReadyForProductionTask(queues);
|
||||||
const requiredResources = getTaskResources(firstReadyTask);
|
const requiredResources = getTaskResources(firstReadyTask);
|
||||||
@ -323,7 +325,7 @@ function createVillageState(
|
|||||||
state: VillageOwnState,
|
state: VillageOwnState,
|
||||||
ownStates: VillageOwnStateDictionary
|
ownStates: VillageOwnStateDictionary
|
||||||
): VillageState {
|
): VillageState {
|
||||||
const villageIds = Object.keys(ownStates).map(k => +k);
|
const villageIds = Object.keys(ownStates).map((k) => +k);
|
||||||
const commitments = villageIds.reduce((memo, shipmentVillageId) => {
|
const commitments = villageIds.reduce((memo, shipmentVillageId) => {
|
||||||
const shipmentVillageState = ownStates[shipmentVillageId];
|
const shipmentVillageState = ownStates[shipmentVillageId];
|
||||||
const shipmentVillageRequired = shipmentVillageState.required;
|
const shipmentVillageRequired = shipmentVillageState.required;
|
||||||
@ -342,7 +344,7 @@ function getVillageStates(
|
|||||||
taskCollectionFactory: VillageTaskCollectionFactory
|
taskCollectionFactory: VillageTaskCollectionFactory
|
||||||
): Array<VillageState> {
|
): Array<VillageState> {
|
||||||
const ownStates = createVillageOwnStates(villages, storageFactory, taskCollectionFactory);
|
const ownStates = createVillageOwnStates(villages, storageFactory, taskCollectionFactory);
|
||||||
return villages.map(village => createVillageState(ownStates[village.id], ownStates));
|
return villages.map((village) => createVillageState(ownStates[village.id], ownStates));
|
||||||
}
|
}
|
||||||
|
|
||||||
interface VillageStorageFactory {
|
interface VillageStorageFactory {
|
||||||
@ -382,7 +384,7 @@ export class VillageStateFactory {
|
|||||||
this.storageFactory,
|
this.storageFactory,
|
||||||
this.taskCollectionFactory
|
this.taskCollectionFactory
|
||||||
);
|
);
|
||||||
const needle = states.find(s => s.id === villageId);
|
const needle = states.find((s) => s.id === villageId);
|
||||||
if (!needle) {
|
if (!needle) {
|
||||||
throw new VillageNotFound(`Village ${villageId} not found`);
|
throw new VillageNotFound(`Village ${villageId} not found`);
|
||||||
}
|
}
|
||||||
|
@ -24,13 +24,13 @@ export class VillageTaskCollection {
|
|||||||
|
|
||||||
private modifyTasks(predicate: (t: Task) => boolean, modifier: (t: Task) => Task): void {
|
private modifyTasks(predicate: (t: Task) => boolean, modifier: (t: Task) => Task): void {
|
||||||
const tasks = this.getTasks();
|
const tasks = this.getTasks();
|
||||||
const modified = tasks.map(t => (predicate(t) ? modifier(t) : t));
|
const modified = tasks.map((t) => (predicate(t) ? modifier(t) : t));
|
||||||
this.storage.storeTaskList(modified);
|
this.storage.storeTaskList(modified);
|
||||||
}
|
}
|
||||||
|
|
||||||
private removeTasks(predicate: (t: Task) => boolean): void {
|
private removeTasks(predicate: (t: Task) => boolean): void {
|
||||||
const tasks = this.getTasks();
|
const tasks = this.getTasks();
|
||||||
const remaining = tasks.filter(t => !predicate(t));
|
const remaining = tasks.filter((t) => !predicate(t));
|
||||||
this.storage.storeTaskList(remaining);
|
this.storage.storeTaskList(remaining);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,12 +55,12 @@ export class VillageTaskCollection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
removeTask(taskId: TaskId) {
|
removeTask(taskId: TaskId) {
|
||||||
this.removeTasks(t => t.id === taskId);
|
this.removeTasks((t) => t.id === taskId);
|
||||||
}
|
}
|
||||||
|
|
||||||
upTask(taskId: TaskId): void {
|
upTask(taskId: TaskId): void {
|
||||||
const tasks = this.storage.getTasks();
|
const tasks = this.storage.getTasks();
|
||||||
const index = tasks.findIndex(t => t.id === taskId);
|
const index = tasks.findIndex((t) => t.id === taskId);
|
||||||
if (index < 0 || index === 0) {
|
if (index < 0 || index === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -71,7 +71,7 @@ export class VillageTaskCollection {
|
|||||||
|
|
||||||
downTask(taskId: TaskId) {
|
downTask(taskId: TaskId) {
|
||||||
const tasks = this.storage.getTasks();
|
const tasks = this.storage.getTasks();
|
||||||
const index = tasks.findIndex(t => t.id === taskId);
|
const index = tasks.findIndex((t) => t.id === taskId);
|
||||||
if (index < 0 || index === tasks.length - 1) {
|
if (index < 0 || index === tasks.length - 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -82,7 +82,7 @@ export class VillageTaskCollection {
|
|||||||
|
|
||||||
postponeTask(taskId: TaskId, seconds: number) {
|
postponeTask(taskId: TaskId, seconds: number) {
|
||||||
const modifyTime = withTime(timestamp() + seconds);
|
const modifyTime = withTime(timestamp() + seconds);
|
||||||
this.modifyTasks(task => task.id === taskId, modifyTime);
|
this.modifyTasks((task) => task.id === taskId, modifyTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateResourcesInTasks(resources: Resources, attr: ContractAttributes): void {
|
updateResourcesInTasks(resources: Resources, attr: ContractAttributes): void {
|
||||||
|
@ -27,7 +27,7 @@ describe('Task Queue', function() {
|
|||||||
new Task('id2', 2, 'task2', {}),
|
new Task('id2', 2, 'task2', {}),
|
||||||
]);
|
]);
|
||||||
const queue = new TaskQueue(provider, new NullLogger());
|
const queue = new TaskQueue(provider, new NullLogger());
|
||||||
queue.remove(t => t.id === 'id1');
|
queue.remove((t) => t.id === 'id1');
|
||||||
const tasks = provider.getTasks();
|
const tasks = provider.getTasks();
|
||||||
expect(tasks).to.have.lengthOf(1);
|
expect(tasks).to.have.lengthOf(1);
|
||||||
expect(tasks[0].ts).to.be.equals(2);
|
expect(tasks[0].ts).to.be.equals(2);
|
||||||
@ -41,8 +41,8 @@ describe('Task Queue', function() {
|
|||||||
]);
|
]);
|
||||||
const queue = new TaskQueue(provider, new NullLogger());
|
const queue = new TaskQueue(provider, new NullLogger());
|
||||||
queue.modify(
|
queue.modify(
|
||||||
t => t.ts < 4,
|
(t) => t.ts < 4,
|
||||||
t => new Task(t.id, 10, t.name, t.args)
|
(t) => new Task(t.id, 10, t.name, t.args)
|
||||||
);
|
);
|
||||||
const tasks = provider.getTasks();
|
const tasks = provider.getTasks();
|
||||||
expect(4).is.equals(tasks[0].ts);
|
expect(4).is.equals(tasks[0].ts);
|
||||||
|
Loading…
Reference in New Issue
Block a user