Refactoring modules

This commit is contained in:
Anton Vakhrushev 2020-04-22 13:27:49 +03:00
parent 8ba3316388
commit 542bc353b0
14 changed files with 60 additions and 55 deletions

View File

@ -3,10 +3,10 @@ import { Args } from '../Command';
import { Task } from '../Queue/TaskQueue'; import { Task } from '../Queue/TaskQueue';
import { grabResources, grabResourceStorage } from '../Page/ResourcesBlock'; import { grabResources, grabResourceStorage } from '../Page/ResourcesBlock';
import { changeHeroResource, grabCurrentHeroResource } from '../Page/HeroPage'; import { changeHeroResource, grabCurrentHeroResource } from '../Page/HeroPage';
import { HeroAllResources } from '../Game';
import { grabActiveVillageId } from '../Page/VillageBlock'; import { grabActiveVillageId } from '../Page/VillageBlock';
import { HeroState } from '../State/HeroState'; import { HeroState } from '../State/HeroState';
import { calcHeroResource } from '../Core/HeroBalance'; import { calcHeroResource } from '../Core/HeroBalance';
import { HeroAllResources } from '../Core/Hero';
@registerAction @registerAction
export class BalanceHeroResourcesAction extends ActionController { export class BalanceHeroResourcesAction extends ActionController {

View File

@ -14,8 +14,8 @@ import DashboardApp from './DashboardView/Dashboard.vue';
import { ResourcesToLevel } from './Task/ResourcesToLevel'; import { ResourcesToLevel } from './Task/ResourcesToLevel';
import { ConsoleLogger, Logger } from './Logger'; import { ConsoleLogger, Logger } from './Logger';
import { VillageState } from './State/VillageState'; import { VillageState } from './State/VillageState';
import { Village } from './Game';
import { Resources } from './Core/Resources'; import { Resources } from './Core/Resources';
import { Village } from './Core/Village';
interface QuickAction { interface QuickAction {
label: string; label: string;

13
src/Core/Hero.ts Normal file
View File

@ -0,0 +1,13 @@
import { ResourceType } from './ResourceType';
export class HeroAttributes {
readonly health: number;
constructor(health: number) {
this.health = health;
}
}
export type HeroAllResourcesType = 'all';
export const HeroAllResources: HeroAllResourcesType = 'all';
export type HeroResourceType = ResourceType | HeroAllResourcesType;

View File

@ -1,5 +1,6 @@
import { Resources } from './Resources'; import { Resources } from './Resources';
import { HeroAllResources, HeroResourceType, ResourceStorage } from '../Game'; import { ResourceStorage } from './ResourceStorage';
import { HeroAllResources, HeroResourceType } from './Hero';
export function calcHeroResource( export function calcHeroResource(
current: Resources, current: Resources,

View File

@ -0,0 +1,9 @@
export class ResourceStorage {
readonly warehouse: number;
readonly granary: number;
constructor(warehouse: number, granary: number) {
this.warehouse = warehouse;
this.granary = granary;
}
}

View File

@ -1,5 +1,5 @@
import { ResourceStorage } from '../Game';
import { ResourceList, ResourceMapping, ResourceType } from './ResourceType'; import { ResourceList, ResourceMapping, ResourceType } from './ResourceType';
import { ResourceStorage } from './ResourceStorage';
export interface ResourcesInterface { export interface ResourcesInterface {
lumber: number; lumber: number;

25
src/Core/Village.ts Normal file
View File

@ -0,0 +1,25 @@
export class Coordinates {
readonly x: number;
readonly y: number;
constructor(x: number, y: number) {
this.x = x;
this.y = y;
}
}
export class Village {
readonly id: number;
readonly name: string;
readonly active: boolean;
readonly crd: Coordinates;
constructor(id: number, name: string, active: boolean, crd: Coordinates) {
this.id = id;
this.name = name;
this.active = active;
this.crd = crd;
}
}
export type VillageList = Array<Village>;

View File

@ -1,38 +1,5 @@
import { ResourceType } from './Core/ResourceType'; import { ResourceType } from './Core/ResourceType';
export class ResourceStorage {
readonly warehouse: number;
readonly granary: number;
constructor(warehouse: number, granary: number) {
this.warehouse = warehouse;
this.granary = granary;
}
}
export class Coordinates {
readonly x: number;
readonly y: number;
constructor(x: number, y: number) {
this.x = x;
this.y = y;
}
}
export class Village {
readonly id: number;
readonly name: string;
readonly active: boolean;
readonly crd: Coordinates;
constructor(id: number, name: string, active: boolean, crd: Coordinates) {
this.id = id;
this.name = name;
this.active = active;
this.crd = crd;
}
}
export type VillageList = Array<Village>;
export class BuildingQueueInfo { export class BuildingQueueInfo {
readonly seconds: number; readonly seconds: number;
constructor(seconds: number) { constructor(seconds: number) {
@ -40,18 +7,6 @@ export class BuildingQueueInfo {
} }
} }
export class HeroAttributes {
readonly health: number;
constructor(health: number) {
this.health = health;
}
}
export type HeroAllResourcesType = 'all';
export const HeroAllResources: HeroAllResourcesType = 'all';
export type HeroResourceType = ResourceType | HeroAllResourcesType;
export class ResourceDeposit { export class ResourceDeposit {
readonly buildId: number; readonly buildId: number;
readonly type: ResourceType; readonly type: ResourceType;

View File

@ -1,7 +1,7 @@
import { GrabError } from '../Errors'; import { GrabError } from '../Errors';
import { HeroAllResources, HeroAttributes, HeroResourceType } from '../Game';
import { getNumber } from '../utils'; import { getNumber } from '../utils';
import { ResourceMapping, ResourceType } from '../Core/ResourceType'; import { ResourceMapping, ResourceType } from '../Core/ResourceType';
import { HeroAllResources, HeroAttributes, HeroResourceType } from '../Core/Hero';
export function grabHeroAttributes(): HeroAttributes { export function grabHeroAttributes(): HeroAttributes {
const healthElement = jQuery('#attributes .attribute.health .powervalue .value'); const healthElement = jQuery('#attributes .attribute.health .powervalue .value');

View File

@ -1,8 +1,8 @@
import { ResourceStorage } from '../Game';
import { GrabError } from '../Errors'; import { GrabError } from '../Errors';
import { getNumber } from '../utils'; import { getNumber } from '../utils';
import { Resources } from '../Core/Resources'; import { Resources } from '../Core/Resources';
import { ResourceType } from '../Core/ResourceType'; import { ResourceType } from '../Core/ResourceType';
import { ResourceStorage } from '../Core/ResourceStorage';
export function grabResources(): Resources { export function grabResources(): Resources {
const lumber = grabResource(ResourceType.Lumber); const lumber = grabResource(ResourceType.Lumber);

View File

@ -1,7 +1,8 @@
import { BuildingQueueInfo, Coordinates, Village, VillageList } from '../Game'; import { BuildingQueueInfo } from '../Game';
import { GrabError } from '../Errors'; import { GrabError } from '../Errors';
import { getNumber, parseLocation } from '../utils'; import { getNumber, parseLocation } from '../utils';
import { Resources } from '../Core/Resources'; import { Resources } from '../Core/Resources';
import { Coordinates, Village, VillageList } from '../Core/Village';
function getVillageListItems() { function getVillageListItems() {
const $elements = jQuery('#sidebarBoxVillagelist ul li a'); const $elements = jQuery('#sidebarBoxVillagelist ul li a');

View File

@ -1,5 +1,5 @@
import { DataStorage } from '../DataStorage'; import { DataStorage } from '../DataStorage';
import { HeroAttributes } from '../Game'; import { HeroAttributes } from '../Core/Hero';
const VILLAGE_ID_KEY = 'village_id'; const VILLAGE_ID_KEY = 'village_id';
const ATTRIBUTES_KEY = 'attr'; const ATTRIBUTES_KEY = 'attr';

View File

@ -1,6 +1,7 @@
import { DataStorage } from '../DataStorage'; import { DataStorage } from '../DataStorage';
import { BuildingQueueInfo, ResourceStorage } from '../Game'; import { BuildingQueueInfo } from '../Game';
import { Resources } from '../Core/Resources'; import { Resources } from '../Core/Resources';
import { ResourceStorage } from '../Core/ResourceStorage';
const RESOURCES_KEY = 'res'; const RESOURCES_KEY = 'res';
const CAPACITY_KEY = 'cap'; const CAPACITY_KEY = 'cap';

View File

@ -1,10 +1,10 @@
import { it, describe } from 'mocha'; import { it, describe } from 'mocha';
import { expect } from 'chai'; import { expect } from 'chai';
import { ResourceStorage } from '../../src/Game';
import { calcHeroResource } from '../../src/Core/HeroBalance'; import { calcHeroResource } from '../../src/Core/HeroBalance';
import { Resources } from '../../src/Core/Resources'; import { Resources } from '../../src/Core/Resources';
import { ResourceType } from '../../src/Core/ResourceType'; import { ResourceType } from '../../src/Core/ResourceType';
import { ResourceStorage } from '../../src/Core/ResourceStorage';
describe('HeroBalance', function() { describe('HeroBalance', function() {
it('Get resource for requirement', function() { it('Get resource for requirement', function() {