Refactoring modules
This commit is contained in:
parent
8ba3316388
commit
542bc353b0
@ -3,10 +3,10 @@ import { Args } from '../Command';
|
||||
import { Task } from '../Queue/TaskQueue';
|
||||
import { grabResources, grabResourceStorage } from '../Page/ResourcesBlock';
|
||||
import { changeHeroResource, grabCurrentHeroResource } from '../Page/HeroPage';
|
||||
import { HeroAllResources } from '../Game';
|
||||
import { grabActiveVillageId } from '../Page/VillageBlock';
|
||||
import { HeroState } from '../State/HeroState';
|
||||
import { calcHeroResource } from '../Core/HeroBalance';
|
||||
import { HeroAllResources } from '../Core/Hero';
|
||||
|
||||
@registerAction
|
||||
export class BalanceHeroResourcesAction extends ActionController {
|
||||
|
@ -14,8 +14,8 @@ import DashboardApp from './DashboardView/Dashboard.vue';
|
||||
import { ResourcesToLevel } from './Task/ResourcesToLevel';
|
||||
import { ConsoleLogger, Logger } from './Logger';
|
||||
import { VillageState } from './State/VillageState';
|
||||
import { Village } from './Game';
|
||||
import { Resources } from './Core/Resources';
|
||||
import { Village } from './Core/Village';
|
||||
|
||||
interface QuickAction {
|
||||
label: string;
|
||||
|
13
src/Core/Hero.ts
Normal file
13
src/Core/Hero.ts
Normal 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;
|
@ -1,5 +1,6 @@
|
||||
import { Resources } from './Resources';
|
||||
import { HeroAllResources, HeroResourceType, ResourceStorage } from '../Game';
|
||||
import { ResourceStorage } from './ResourceStorage';
|
||||
import { HeroAllResources, HeroResourceType } from './Hero';
|
||||
|
||||
export function calcHeroResource(
|
||||
current: Resources,
|
||||
|
9
src/Core/ResourceStorage.ts
Normal file
9
src/Core/ResourceStorage.ts
Normal 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;
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
import { ResourceStorage } from '../Game';
|
||||
import { ResourceList, ResourceMapping, ResourceType } from './ResourceType';
|
||||
import { ResourceStorage } from './ResourceStorage';
|
||||
|
||||
export interface ResourcesInterface {
|
||||
lumber: number;
|
||||
|
25
src/Core/Village.ts
Normal file
25
src/Core/Village.ts
Normal 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>;
|
45
src/Game.ts
45
src/Game.ts
@ -1,38 +1,5 @@
|
||||
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 {
|
||||
readonly 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 {
|
||||
readonly buildId: number;
|
||||
readonly type: ResourceType;
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { GrabError } from '../Errors';
|
||||
import { HeroAllResources, HeroAttributes, HeroResourceType } from '../Game';
|
||||
import { getNumber } from '../utils';
|
||||
import { ResourceMapping, ResourceType } from '../Core/ResourceType';
|
||||
import { HeroAllResources, HeroAttributes, HeroResourceType } from '../Core/Hero';
|
||||
|
||||
export function grabHeroAttributes(): HeroAttributes {
|
||||
const healthElement = jQuery('#attributes .attribute.health .powervalue .value');
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { ResourceStorage } from '../Game';
|
||||
import { GrabError } from '../Errors';
|
||||
import { getNumber } from '../utils';
|
||||
import { Resources } from '../Core/Resources';
|
||||
import { ResourceType } from '../Core/ResourceType';
|
||||
import { ResourceStorage } from '../Core/ResourceStorage';
|
||||
|
||||
export function grabResources(): Resources {
|
||||
const lumber = grabResource(ResourceType.Lumber);
|
||||
|
@ -1,7 +1,8 @@
|
||||
import { BuildingQueueInfo, Coordinates, Village, VillageList } from '../Game';
|
||||
import { BuildingQueueInfo } from '../Game';
|
||||
import { GrabError } from '../Errors';
|
||||
import { getNumber, parseLocation } from '../utils';
|
||||
import { Resources } from '../Core/Resources';
|
||||
import { Coordinates, Village, VillageList } from '../Core/Village';
|
||||
|
||||
function getVillageListItems() {
|
||||
const $elements = jQuery('#sidebarBoxVillagelist ul li a');
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { DataStorage } from '../DataStorage';
|
||||
import { HeroAttributes } from '../Game';
|
||||
import { HeroAttributes } from '../Core/Hero';
|
||||
|
||||
const VILLAGE_ID_KEY = 'village_id';
|
||||
const ATTRIBUTES_KEY = 'attr';
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { DataStorage } from '../DataStorage';
|
||||
import { BuildingQueueInfo, ResourceStorage } from '../Game';
|
||||
import { BuildingQueueInfo } from '../Game';
|
||||
import { Resources } from '../Core/Resources';
|
||||
import { ResourceStorage } from '../Core/ResourceStorage';
|
||||
|
||||
const RESOURCES_KEY = 'res';
|
||||
const CAPACITY_KEY = 'cap';
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { it, describe } from 'mocha';
|
||||
import { expect } from 'chai';
|
||||
|
||||
import { ResourceStorage } from '../../src/Game';
|
||||
import { calcHeroResource } from '../../src/Core/HeroBalance';
|
||||
import { Resources } from '../../src/Core/Resources';
|
||||
import { ResourceType } from '../../src/Core/ResourceType';
|
||||
import { ResourceStorage } from '../../src/Core/ResourceStorage';
|
||||
|
||||
describe('HeroBalance', function() {
|
||||
it('Get resource for requirement', function() {
|
||||
|
Loading…
Reference in New Issue
Block a user