Add village resources view to dashboard
This commit is contained in:
		| @@ -1,6 +1,6 @@ | ||||
| import { Args } from '../Common'; | ||||
| import { Task } from '../Storage/TaskQueue'; | ||||
| import { GameState } from '../Storage/GameState'; | ||||
| import { DataStorage } from '../Storage/DataStorage'; | ||||
| import { Scheduler } from '../Scheduler'; | ||||
|  | ||||
| const actionMap: { [name: string]: Function | undefined } = {}; | ||||
| @@ -9,20 +9,18 @@ export function registerAction(constructor: Function) { | ||||
|     actionMap[constructor.name] = constructor; | ||||
| } | ||||
|  | ||||
| export function createAction(name: string, state: GameState, scheduler: Scheduler): ActionController | undefined { | ||||
| export function createAction(name: string, scheduler: Scheduler): ActionController | undefined { | ||||
|     const storedFunction = actionMap[name]; | ||||
|     if (storedFunction === undefined) { | ||||
|         return undefined; | ||||
|     } | ||||
|     const constructor = (storedFunction as unknown) as typeof ActionController; | ||||
|     return new constructor(state, scheduler); | ||||
|     return new constructor(scheduler); | ||||
| } | ||||
|  | ||||
| export class ActionController { | ||||
|     protected state: GameState; | ||||
|     protected scheduler: Scheduler; | ||||
|     constructor(state: GameState, scheduler: Scheduler) { | ||||
|         this.state = state; | ||||
|     constructor(scheduler: Scheduler) { | ||||
|         this.scheduler = scheduler; | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -8,10 +8,10 @@ import { HeroAllResources } from '../Game'; | ||||
| @registerAction | ||||
| export class BalanceHeroResourcesAction extends ActionController { | ||||
|     async run(args: Args, task: Task): Promise<any> { | ||||
|         const resources = grabResources().asList(); | ||||
|         const resourcesAsList = grabResources().asList(); | ||||
|         const currentType = grabCurrentHeroResource(); | ||||
|  | ||||
|         const sorted = resources.sort((x, y) => x.value - y.value); | ||||
|         const sorted = resourcesAsList.sort((x, y) => x.value - y.value); | ||||
|         const min = sorted[0]; | ||||
|         const max = sorted[sorted.length - 1]; | ||||
|         const delta = max.value - min.value; | ||||
|   | ||||
| @@ -16,6 +16,6 @@ export class GrabHeroAttributesAction extends ActionController { | ||||
|         let normalized = text.replace(/[^0-9]/g, ''); | ||||
|  | ||||
|         const value = getNumber(normalized); | ||||
|         this.state.set('hero', { health: value }); | ||||
|         // this.state.set('hero', { health: value }); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -28,7 +28,7 @@ export class SendOnAdventureAction extends ActionController { | ||||
|         adventures.sort((x, y) => x.level - y.level); | ||||
|  | ||||
|         const easiest = adventures.shift(); | ||||
|         const hero = this.state.get('hero') || {}; | ||||
|         const hero = { health: 0 }; | ||||
|  | ||||
|         console.log('EASIEST', easiest); | ||||
|         console.log('HERO', hero); | ||||
|   | ||||
							
								
								
									
										16
									
								
								src/Action/StoreVillageState.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/Action/StoreVillageState.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,16 @@ | ||||
| import { ActionController, registerAction } from './ActionController'; | ||||
| import { Args } from '../Common'; | ||||
| import { Task } from '../Storage/TaskQueue'; | ||||
| import { grabResources } from '../Page/ResourcesBlock'; | ||||
| import { grabActiveVillageId } from '../Page/VillageBlock'; | ||||
| import { VillageState } from '../Storage/VillageState'; | ||||
|  | ||||
| @registerAction | ||||
| export class StoreVillageState extends ActionController { | ||||
|     async run(args: Args, task: Task): Promise<any> { | ||||
|         const villageId = grabActiveVillageId(); | ||||
|         const resources = grabResources(); | ||||
|         const state = new VillageState(villageId); | ||||
|         state.storeResources(resources); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user