Improve resource scan
Walk only unique paths
This commit is contained in:
parent
d350603c48
commit
789c5aba3e
30
package-lock.json
generated
30
package-lock.json
generated
@ -336,12 +336,6 @@
|
|||||||
"integrity": "sha512-KlPPdikagvL6ELjWsljbyDIPzNCeliYkqRpI+zea99vBBbCIA5JNshZAwQKTON139c87y9qvTFVgkFd14rtS4g==",
|
"integrity": "sha512-KlPPdikagvL6ELjWsljbyDIPzNCeliYkqRpI+zea99vBBbCIA5JNshZAwQKTON139c87y9qvTFVgkFd14rtS4g==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"@types/debounce": {
|
|
||||||
"version": "1.2.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/@types/debounce/-/debounce-1.2.0.tgz",
|
|
||||||
"integrity": "sha512-bWG5wapaWgbss9E238T0R6bfo5Fh3OkeoSt245CM7JJwVwpw6MEBCbIxLq5z8KzsE3uJhzcIuQkyiZmzV3M/Dw==",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"@types/jquery": {
|
"@types/jquery": {
|
||||||
"version": "3.3.34",
|
"version": "3.3.34",
|
||||||
"resolved": "https://registry.npmjs.org/@types/jquery/-/jquery-3.3.34.tgz",
|
"resolved": "https://registry.npmjs.org/@types/jquery/-/jquery-3.3.34.tgz",
|
||||||
@ -369,6 +363,12 @@
|
|||||||
"integrity": "sha512-7EJYyKTL7tFR8+gDbB6Wwz/arpGa0Mywk1TJbNzKzHtzbwVmY4HR9WqS5VV7dsBUKQmPNr192jHr/VpBluj/hg==",
|
"integrity": "sha512-7EJYyKTL7tFR8+gDbB6Wwz/arpGa0Mywk1TJbNzKzHtzbwVmY4HR9WqS5VV7dsBUKQmPNr192jHr/VpBluj/hg==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"@types/underscore": {
|
||||||
|
"version": "1.9.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/underscore/-/underscore-1.9.4.tgz",
|
||||||
|
"integrity": "sha512-CjHWEMECc2/UxOZh0kpiz3lEyX2Px3rQS9HzD20lxMvx571ivOBQKeLnqEjxUY0BMgp6WJWo/pQLRBwMW5v4WQ==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"@types/url-parse": {
|
"@types/url-parse": {
|
||||||
"version": "1.4.3",
|
"version": "1.4.3",
|
||||||
"resolved": "https://registry.npmjs.org/@types/url-parse/-/url-parse-1.4.3.tgz",
|
"resolved": "https://registry.npmjs.org/@types/url-parse/-/url-parse-1.4.3.tgz",
|
||||||
@ -2088,12 +2088,6 @@
|
|||||||
"integrity": "sha1-sgOOhG3DO6pXlhKNCAS0VbjB4h0=",
|
"integrity": "sha1-sgOOhG3DO6pXlhKNCAS0VbjB4h0=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"debounce": {
|
|
||||||
"version": "1.2.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/debounce/-/debounce-1.2.0.tgz",
|
|
||||||
"integrity": "sha512-mYtLl1xfZLi1m4RtQYlZgJUNQjl4ZxVnHzIR8nLLgi4q1YT8o/WM+MK/f8yfcc9s5Ir5zRaPZyZU6xs1Syoocg==",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"debug": {
|
"debug": {
|
||||||
"version": "3.2.6",
|
"version": "3.2.6",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz",
|
||||||
@ -4470,9 +4464,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"yargs-parser": {
|
"yargs-parser": {
|
||||||
"version": "18.1.1",
|
"version": "18.1.3",
|
||||||
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.3.tgz",
|
||||||
"integrity": "sha512-KRHEsOM16IX7XuLnMOqImcPNbLVXMNHYAoFc3BKR8Ortl5gzDbtXvvEoGx9imk5E+X1VeNKNlcHr8B8vi+7ipA==",
|
"integrity": "sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"camelcase": "^5.0.0",
|
"camelcase": "^5.0.0",
|
||||||
@ -6043,6 +6037,12 @@
|
|||||||
"integrity": "sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==",
|
"integrity": "sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"underscore": {
|
||||||
|
"version": "1.10.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.10.2.tgz",
|
||||||
|
"integrity": "sha512-N4P+Q/BuyuEKFJ43B9gYuOj4TQUHXX+j2FqguVOpjkssLUUrnJofCcBccJSCoeturDoZU6GorDTHSvUDlSQbTg==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"union-value": {
|
"union-value": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/union-value/-/union-value-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/union-value/-/union-value-1.0.1.tgz",
|
||||||
|
@ -23,15 +23,14 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/chai": "^4.2.11",
|
"@types/chai": "^4.2.11",
|
||||||
"@types/dateformat": "^3.0.1",
|
"@types/dateformat": "^3.0.1",
|
||||||
"@types/debounce": "^1.2.0",
|
|
||||||
"@types/jquery": "^3.3.34",
|
"@types/jquery": "^3.3.34",
|
||||||
"@types/mocha": "^7.0.2",
|
"@types/mocha": "^7.0.2",
|
||||||
"@types/node": "^13.9.4",
|
"@types/node": "^13.9.4",
|
||||||
|
"@types/underscore": "^1.9.4",
|
||||||
"@types/url-parse": "^1.4.3",
|
"@types/url-parse": "^1.4.3",
|
||||||
"chai": "^4.2.0",
|
"chai": "^4.2.0",
|
||||||
"css-loader": "^3.5.2",
|
"css-loader": "^3.5.2",
|
||||||
"dateformat": "^3.0.3",
|
"dateformat": "^3.0.3",
|
||||||
"debounce": "^1.2.0",
|
|
||||||
"jquery": "^3.4.1",
|
"jquery": "^3.4.1",
|
||||||
"mocha": "^7.1.1",
|
"mocha": "^7.1.1",
|
||||||
"mocha-junit-reporter": "^1.23.3",
|
"mocha-junit-reporter": "^1.23.3",
|
||||||
@ -42,6 +41,7 @@
|
|||||||
"ts-loader": "^6.2.2",
|
"ts-loader": "^6.2.2",
|
||||||
"ts-node": "^8.8.1",
|
"ts-node": "^8.8.1",
|
||||||
"typescript": "^3.8.3",
|
"typescript": "^3.8.3",
|
||||||
|
"underscore": "^1.10.2",
|
||||||
"url-parse": "^1.4.7",
|
"url-parse": "^1.4.7",
|
||||||
"vue": "^2.6.11",
|
"vue": "^2.6.11",
|
||||||
"vue-loader": "^15.9.1",
|
"vue-loader": "^15.9.1",
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import { ActionController, registerAction } from './ActionController';
|
import { ActionController, registerAction } from './ActionController';
|
||||||
import { grabVillageList } from '../Page/VillageBlock';
|
import { grabVillageList } from '../Page/VillageBlock';
|
||||||
import { grabHeroVillage } from '../Page/HeroPage';
|
import { grabHeroVillage } from '../Page/HeroPage';
|
||||||
import { path } from '../utils';
|
|
||||||
import { HeroStorage } from '../Storage/HeroStorage';
|
import { HeroStorage } from '../Storage/HeroStorage';
|
||||||
import { Args } from '../Queue/Args';
|
import { Args } from '../Queue/Args';
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../Queue/TaskProvider';
|
||||||
|
import { path } from '../Helpers/Path';
|
||||||
|
|
||||||
@registerAction
|
@registerAction
|
||||||
export class GoToHeroVillageAction extends ActionController {
|
export class GoToHeroVillageAction extends ActionController {
|
||||||
|
@ -16,11 +16,11 @@ import { ResourcesToLevel } from './Task/ResourcesToLevel';
|
|||||||
import { ConsoleLogger, Logger } from './Logger';
|
import { ConsoleLogger, Logger } from './Logger';
|
||||||
import { DataStorage } from './DataStorage';
|
import { DataStorage } from './DataStorage';
|
||||||
import { getBuildingPageAttributes, isBuildingPage } from './Page/PageDetectors';
|
import { getBuildingPageAttributes, isBuildingPage } from './Page/PageDetectors';
|
||||||
import { debounce } from 'debounce';
|
|
||||||
import { ExecutionStorage } from './Storage/ExecutionStorage';
|
import { ExecutionStorage } from './Storage/ExecutionStorage';
|
||||||
import { createVillageStates, VillageState } from './VillageState';
|
import { createVillageStates, VillageState } from './VillageState';
|
||||||
import { Task } from './Queue/TaskProvider';
|
import { Task } from './Queue/TaskProvider';
|
||||||
import { Action } from './Queue/ActionQueue';
|
import { Action } from './Queue/ActionQueue';
|
||||||
|
import * as _ from 'underscore';
|
||||||
|
|
||||||
interface QuickAction {
|
interface QuickAction {
|
||||||
label: string;
|
label: string;
|
||||||
@ -110,7 +110,7 @@ export class ControlPanel {
|
|||||||
}, 3000);
|
}, 3000);
|
||||||
|
|
||||||
DataStorage.onChange(
|
DataStorage.onChange(
|
||||||
debounce(() => {
|
_.debounce(() => {
|
||||||
state.refresh();
|
state.refresh();
|
||||||
}, 500)
|
}, 500)
|
||||||
);
|
);
|
||||||
|
@ -197,10 +197,10 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { path } from '../utils';
|
|
||||||
import ResourceBalance from './ResourceBalance';
|
import ResourceBalance from './ResourceBalance';
|
||||||
import VillageResource from './VillageResource';
|
import VillageResource from './VillageResource';
|
||||||
import { COLLECTION_POINT_ID, HORSE_STABLE_ID, MARKET_ID, QUARTERS_ID, WAREHOUSE_ID } from '../Core/Buildings';
|
import { COLLECTION_POINT_ID, HORSE_STABLE_ID, MARKET_ID, QUARTERS_ID, WAREHOUSE_ID } from '../Core/Buildings';
|
||||||
|
import { path } from '../Helpers/Path';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
|
34
src/Helpers/Path.ts
Normal file
34
src/Helpers/Path.ts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
export interface PathQuery {
|
||||||
|
[key: string]: string | number | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PathDefinition {
|
||||||
|
name: string;
|
||||||
|
query: PathQuery;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type PathList = Array<PathDefinition>;
|
||||||
|
|
||||||
|
export function path(base: string, query: PathQuery = {}): string {
|
||||||
|
let parts: string[] = [];
|
||||||
|
for (let name of Object.keys(query)) {
|
||||||
|
if (query[name] !== undefined) {
|
||||||
|
parts.push(`${name}=${query[name]}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return base + (parts.length ? '?' + parts.join('&') : '');
|
||||||
|
}
|
||||||
|
|
||||||
|
export function uniqPaths(paths: PathList): PathList {
|
||||||
|
const keys: { [k: string]: boolean | undefined } = {};
|
||||||
|
const result: PathList = [];
|
||||||
|
for (let path of paths) {
|
||||||
|
const pathKey = JSON.stringify(path);
|
||||||
|
if (keys[pathKey]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
keys[pathKey] = true;
|
||||||
|
result.push(path);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
@ -30,7 +30,7 @@ export function getBuildingPageAttributes(): BuildingPageAttributes {
|
|||||||
buildTypeId: getNumber(elClassId($buildEl.attr('class'), 'gid')),
|
buildTypeId: getNumber(elClassId($buildEl.attr('class'), 'gid')),
|
||||||
level: getNumber(elClassId($buildEl.attr('class'), 'level')),
|
level: getNumber(elClassId($buildEl.attr('class'), 'level')),
|
||||||
buildId: getNumber(p.query.id) || undefined,
|
buildId: getNumber(p.query.id) || undefined,
|
||||||
categoryId: getNumber(p.query.category, 1),
|
categoryId: getNumber(p.query.category) || 1,
|
||||||
sheetId: getNumber(p.query.s) || undefined,
|
sheetId: getNumber(p.query.s) || undefined,
|
||||||
tabId: getNumber(p.query.t) || undefined,
|
tabId: getNumber(p.query.t) || undefined,
|
||||||
};
|
};
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { ActionDefinition } from './TaskController';
|
import { ActionDefinition } from './TaskController';
|
||||||
import { grabVillageList } from '../Page/VillageBlock';
|
import { grabVillageList } from '../Page/VillageBlock';
|
||||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
import { GoToPageAction } from '../Action/GoToPageAction';
|
||||||
import { path } from '../utils';
|
|
||||||
import { MARKET_ID } from '../Core/Buildings';
|
import { MARKET_ID } from '../Core/Buildings';
|
||||||
|
import { path } from '../Helpers/Path';
|
||||||
|
|
||||||
export function scanAllVillagesBundle(): Array<ActionDefinition> {
|
export function scanAllVillagesBundle(): Array<ActionDefinition> {
|
||||||
const actions: Array<ActionDefinition> = [];
|
const actions: Array<ActionDefinition> = [];
|
||||||
|
@ -2,11 +2,11 @@ import { TaskController, registerTask } from './TaskController';
|
|||||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
import { GoToPageAction } from '../Action/GoToPageAction';
|
||||||
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
||||||
import { BalanceHeroResourcesAction } from '../Action/BalanceHeroResourcesAction';
|
import { BalanceHeroResourcesAction } from '../Action/BalanceHeroResourcesAction';
|
||||||
import { path } from '../utils';
|
|
||||||
import { GoToHeroVillageAction } from '../Action/GoToHeroVillageAction';
|
import { GoToHeroVillageAction } from '../Action/GoToHeroVillageAction';
|
||||||
import { Action } from '../Queue/ActionQueue';
|
import { Action } from '../Queue/ActionQueue';
|
||||||
import { Args } from '../Queue/Args';
|
import { Args } from '../Queue/Args';
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../Queue/TaskProvider';
|
||||||
|
import { path } from '../Helpers/Path';
|
||||||
|
|
||||||
@registerTask
|
@registerTask
|
||||||
export class BalanceHeroResourcesTask extends TaskController {
|
export class BalanceHeroResourcesTask extends TaskController {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { BuildBuildingAction } from '../Action/BuildBuildingAction';
|
import { BuildBuildingAction } from '../Action/BuildBuildingAction';
|
||||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
import { GoToPageAction } from '../Action/GoToPageAction';
|
||||||
import { path } from '../utils';
|
|
||||||
import { TaskController, registerTask, ActionDefinition } from './TaskController';
|
import { TaskController, registerTask, ActionDefinition } from './TaskController';
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../Queue/TaskProvider';
|
||||||
|
import { path } from '../Helpers/Path';
|
||||||
|
|
||||||
@registerTask
|
@registerTask
|
||||||
export class BuildBuildingTask extends TaskController {
|
export class BuildBuildingTask extends TaskController {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { TaskController, registerTask, ActionDefinition } from './TaskController';
|
import { TaskController, registerTask, ActionDefinition } from './TaskController';
|
||||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
import { GoToPageAction } from '../Action/GoToPageAction';
|
||||||
import { path } from '../utils';
|
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../Queue/TaskProvider';
|
||||||
import { ForgeImprovementAction } from '../Action/ForgeImprovementAction';
|
import { ForgeImprovementAction } from '../Action/ForgeImprovementAction';
|
||||||
|
import { path } from '../Helpers/Path';
|
||||||
|
|
||||||
@registerTask
|
@registerTask
|
||||||
export class ForgeImprovementTask extends TaskController {
|
export class ForgeImprovementTask extends TaskController {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { TaskController, registerTask, ActionDefinition } from './TaskController';
|
import { TaskController, registerTask, ActionDefinition } from './TaskController';
|
||||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
import { GoToPageAction } from '../Action/GoToPageAction';
|
||||||
import { path } from '../utils';
|
|
||||||
import { UpgradeResourceToLevel } from '../Action/UpgradeResourceToLevel';
|
import { UpgradeResourceToLevel } from '../Action/UpgradeResourceToLevel';
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../Queue/TaskProvider';
|
||||||
|
import { path } from '../Helpers/Path';
|
||||||
|
|
||||||
@registerTask
|
@registerTask
|
||||||
export class ResourcesToLevel extends TaskController {
|
export class ResourcesToLevel extends TaskController {
|
||||||
|
@ -3,10 +3,10 @@ import { GoToPageAction } from '../Action/GoToPageAction';
|
|||||||
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
||||||
import { SendOnAdventureAction } from '../Action/SendOnAdventureAction';
|
import { SendOnAdventureAction } from '../Action/SendOnAdventureAction';
|
||||||
import { ClickButtonAction } from '../Action/ClickButtonAction';
|
import { ClickButtonAction } from '../Action/ClickButtonAction';
|
||||||
import { path } from '../utils';
|
|
||||||
import { Action } from '../Queue/ActionQueue';
|
import { Action } from '../Queue/ActionQueue';
|
||||||
import { Args } from '../Queue/Args';
|
import { Args } from '../Queue/Args';
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../Queue/TaskProvider';
|
||||||
|
import { path } from '../Helpers/Path';
|
||||||
|
|
||||||
@registerTask
|
@registerTask
|
||||||
export class SendOnAdventureTask extends TaskController {
|
export class SendOnAdventureTask extends TaskController {
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import { TaskController, registerTask, ActionDefinition } from './TaskController';
|
import { TaskController, registerTask, ActionDefinition } from './TaskController';
|
||||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
import { GoToPageAction } from '../Action/GoToPageAction';
|
||||||
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
||||||
import { path } from '../utils';
|
|
||||||
import { SendResourcesAction } from '../Action/SendResourcesAction';
|
import { SendResourcesAction } from '../Action/SendResourcesAction';
|
||||||
import { ClickButtonAction } from '../Action/ClickButtonAction';
|
import { ClickButtonAction } from '../Action/ClickButtonAction';
|
||||||
import { scanAllVillagesBundle } from './ActionBundles';
|
import { scanAllVillagesBundle } from './ActionBundles';
|
||||||
import { Args } from '../Queue/Args';
|
import { Args } from '../Queue/Args';
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../Queue/TaskProvider';
|
||||||
|
import { path } from '../Helpers/Path';
|
||||||
|
|
||||||
@registerTask
|
@registerTask
|
||||||
export class SendResourcesTask extends TaskController {
|
export class SendResourcesTask extends TaskController {
|
||||||
|
@ -2,10 +2,10 @@ import { registerTask, TaskController } from './TaskController';
|
|||||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
import { GoToPageAction } from '../Action/GoToPageAction';
|
||||||
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
||||||
import { TrainTrooperAction } from '../Action/TrainTrooperAction';
|
import { TrainTrooperAction } from '../Action/TrainTrooperAction';
|
||||||
import { path } from '../utils';
|
|
||||||
import { Action } from '../Queue/ActionQueue';
|
import { Action } from '../Queue/ActionQueue';
|
||||||
import { Args } from '../Queue/Args';
|
import { Args } from '../Queue/Args';
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../Queue/TaskProvider';
|
||||||
|
import { path } from '../Helpers/Path';
|
||||||
|
|
||||||
@registerTask
|
@registerTask
|
||||||
export class TrainTroopTask extends TaskController {
|
export class TrainTroopTask extends TaskController {
|
||||||
|
@ -1,33 +1,36 @@
|
|||||||
import { TaskController, registerTask, ActionDefinition } from './TaskController';
|
import { TaskController, registerTask, ActionDefinition } from './TaskController';
|
||||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
import { GoToPageAction } from '../Action/GoToPageAction';
|
||||||
import { path } from '../utils';
|
|
||||||
import { UpgradeBuildingTask } from './UpgradeBuildingTask';
|
import { UpgradeBuildingTask } from './UpgradeBuildingTask';
|
||||||
import { ImmutableTaskList, Task } from '../Queue/TaskProvider';
|
import { ImmutableTaskList, Task } from '../Queue/TaskProvider';
|
||||||
import { ForgeImprovementTask } from './ForgeImprovementTask';
|
import { ForgeImprovementTask } from './ForgeImprovementTask';
|
||||||
|
import { path, PathList, uniqPaths } from '../Helpers/Path';
|
||||||
|
|
||||||
@registerTask
|
@registerTask
|
||||||
export class UpdateResourceContracts extends TaskController {
|
export class UpdateResourceContracts extends TaskController {
|
||||||
defineActions(task: Task): Array<ActionDefinition> {
|
defineActions(task: Task): Array<ActionDefinition> {
|
||||||
const tasks = this.scheduler.getTaskItems();
|
const tasks = this.scheduler.getTaskItems();
|
||||||
|
|
||||||
return [...this.walkUpgradeTasks(tasks), ...this.walkImprovementTask(tasks)];
|
const paths = [...this.walkUpgradeTasks(tasks), ...this.walkImprovementTask(tasks)];
|
||||||
|
const uniq = uniqPaths(paths);
|
||||||
|
|
||||||
|
return uniq.map(p => [GoToPageAction.name, { path: path(p.name, p.query) }]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private walkUpgradeTasks(tasks: ImmutableTaskList): Array<ActionDefinition> {
|
private walkUpgradeTasks(tasks: ImmutableTaskList): PathList {
|
||||||
return tasks
|
return tasks
|
||||||
.filter(t => t.name === UpgradeBuildingTask.name && t.args.villageId && t.args.buildId)
|
.filter(t => t.name === UpgradeBuildingTask.name && t.args.villageId && t.args.buildId)
|
||||||
.map(t => [
|
.map(t => ({
|
||||||
GoToPageAction.name,
|
name: '/build.php',
|
||||||
{ path: path('/build.php', { newdid: t.args.villageId, id: t.args.buildId }) },
|
query: { newdid: t.args.villageId, id: t.args.buildId },
|
||||||
]);
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
private walkImprovementTask(tasks: ImmutableTaskList): Array<ActionDefinition> {
|
private walkImprovementTask(tasks: ImmutableTaskList): PathList {
|
||||||
return tasks
|
return tasks
|
||||||
.filter(t => t.name === ForgeImprovementTask.name && t.args.villageId && t.args.buildId)
|
.filter(t => t.name === ForgeImprovementTask.name && t.args.villageId && t.args.buildId)
|
||||||
.map(t => [
|
.map(t => ({
|
||||||
GoToPageAction.name,
|
name: '/build.php',
|
||||||
{ path: path('/build.php', { newdid: t.args.villageId, id: t.args.buildId }) },
|
query: { newdid: t.args.villageId, id: t.args.buildId },
|
||||||
]);
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { UpgradeBuildingAction } from '../Action/UpgradeBuildingAction';
|
import { UpgradeBuildingAction } from '../Action/UpgradeBuildingAction';
|
||||||
import { TaskController, registerTask, ActionDefinition } from './TaskController';
|
import { TaskController, registerTask, ActionDefinition } from './TaskController';
|
||||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
import { GoToPageAction } from '../Action/GoToPageAction';
|
||||||
import { path } from '../utils';
|
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../Queue/TaskProvider';
|
||||||
|
import { path } from '../Helpers/Path';
|
||||||
|
|
||||||
@registerTask
|
@registerTask
|
||||||
export class UpgradeBuildingTask extends TaskController {
|
export class UpgradeBuildingTask extends TaskController {
|
||||||
|
14
src/utils.ts
14
src/utils.ts
@ -92,25 +92,11 @@ export function parseLocation(location?: string | undefined) {
|
|||||||
return new URLParse(location || window.location.href, true);
|
return new URLParse(location || window.location.href, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function path(p: string, query: { [key: string]: string | number | undefined } = {}) {
|
|
||||||
let parts: string[] = [];
|
|
||||||
for (let k in query) {
|
|
||||||
if (query[k] !== undefined) {
|
|
||||||
parts.push(`${k}=${query[k]}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return p + (parts.length ? '?' + parts.join('&') : '');
|
|
||||||
}
|
|
||||||
|
|
||||||
export function notify(msg: string): void {
|
export function notify(msg: string): void {
|
||||||
const n = new Notification(msg);
|
const n = new Notification(msg);
|
||||||
setTimeout(() => n && n.close(), 4000);
|
setTimeout(() => n && n.close(), 4000);
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NowTimeGenerator {
|
|
||||||
(): number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function markPage(text: string, version: string) {
|
export function markPage(text: string, version: string) {
|
||||||
jQuery('body').append(
|
jQuery('body').append(
|
||||||
'<div style="' +
|
'<div style="' +
|
||||||
|
32
tests/Helpers/PathTest.ts
Normal file
32
tests/Helpers/PathTest.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import { it, describe } from 'mocha';
|
||||||
|
import { expect } from 'chai';
|
||||||
|
import { path, uniqPaths } from '../../src/Helpers/Path';
|
||||||
|
|
||||||
|
describe('Path', function() {
|
||||||
|
it('Can build path with empty query', function() {
|
||||||
|
const p = path('/info.php');
|
||||||
|
expect(p).to.be.equals('/info.php');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Can build path with query', function() {
|
||||||
|
const p = path('/info.php', { foo: 'bar' });
|
||||||
|
expect(p).to.be.equals('/info.php?foo=bar');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Can build path with complex query', function() {
|
||||||
|
const p = path('/info.php', { a: 'x', b: 'y', c: 5 });
|
||||||
|
expect(p).to.be.equals('/info.php?a=x&b=y&c=5');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Can build path with query (undefined part)', function() {
|
||||||
|
const p = path('/info.php', { foo: 'bar', foobar: undefined });
|
||||||
|
expect(p).to.be.equals('/info.php?foo=bar');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Can keep uniq paths', function() {
|
||||||
|
const p1 = { name: '/info.php', query: { a: 'b' } };
|
||||||
|
const p2 = { name: '/info.php', query: { a: 'b' } };
|
||||||
|
const up = uniqPaths([p1, p2]);
|
||||||
|
expect(up).to.has.lengthOf(1);
|
||||||
|
});
|
||||||
|
});
|
@ -9,7 +9,7 @@
|
|||||||
"strictNullChecks": true,
|
"strictNullChecks": true,
|
||||||
"strictPropertyInitialization": true,
|
"strictPropertyInitialization": true,
|
||||||
"target": "es2018",
|
"target": "es2018",
|
||||||
"types": ["node", "url-parse", "jquery", "mocha", "chai", "debounce"]
|
"types": ["node", "url-parse", "jquery", "underscore", "mocha", "chai"]
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"./src/**/*"
|
"./src/**/*"
|
||||||
|
Loading…
Reference in New Issue
Block a user