Small refactoring
This commit is contained in:
		| @@ -8,8 +8,8 @@ import { VillageStorage } from './Storage/VillageStorage'; | ||||
| import { ReceiveResourcesMode } from './Core/Village'; | ||||
| import { ResourceType } from './Core/ResourceType'; | ||||
| import { UpgradeBuildingTask } from './Task/UpgradeBuildingTask'; | ||||
| import * as _ from 'underscore'; | ||||
| import { GARNER_ID, WAREHOUSE_ID } from './Core/Buildings'; | ||||
| import { first } from './utils'; | ||||
|  | ||||
| export class VillageController { | ||||
|     private readonly villageId: number; | ||||
| @@ -195,7 +195,7 @@ export class VillageController { | ||||
|         // Find ready for building slots and sort them by level | ||||
|         cropSlots.sort((s1, s2) => s1.level - s2.level); | ||||
|  | ||||
|         const targetCropBuildId = _.first(cropSlots)?.buildId; | ||||
|         const targetCropBuildId = first(cropSlots)?.buildId; | ||||
|         if (!targetCropBuildId) { | ||||
|             return; | ||||
|         } | ||||
| @@ -250,7 +250,7 @@ export class VillageController { | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         const firstSlot = _.first(storageSlots); | ||||
|         const firstSlot = first(storageSlots); | ||||
|         if (firstSlot) { | ||||
|             this.addTask(UpgradeBuildingTask.name, { buildId: firstSlot.buildId, buildTypeId }); | ||||
|         } | ||||
|   | ||||
| @@ -26,6 +26,18 @@ export interface TaskQueueState { | ||||
|     finishTs: number; | ||||
| } | ||||
|  | ||||
| interface VillageProductionQueueState { | ||||
|     queue: ProductionQueue; | ||||
|     tasks: ReadonlyArray<TaskState>; | ||||
|     isActive: boolean; | ||||
|     isWaiting: boolean; | ||||
|     currentTaskFinishTimestamp: number; | ||||
|     currentTaskFinishSeconds: number; | ||||
|     firstTask: ResourceLineState; | ||||
|     allTasks: ResourceLineState; | ||||
|     taskCount: number; | ||||
| } | ||||
|  | ||||
| interface VillageWarehouseState { | ||||
|     resources: Resources; | ||||
|     capacity: Resources; | ||||
| @@ -60,18 +72,6 @@ interface ResourceLineState { | ||||
|     active: boolean; | ||||
| } | ||||
|  | ||||
| interface VillageProductionQueueState { | ||||
|     queue: ProductionQueue; | ||||
|     tasks: ReadonlyArray<TaskState>; | ||||
|     isActive: boolean; | ||||
|     isWaiting: boolean; | ||||
|     currentTaskFinishTimestamp: number; | ||||
|     currentTaskFinishSeconds: number; | ||||
|     firstTask: ResourceLineState; | ||||
|     allTasks: ResourceLineState; | ||||
|     taskCount: number; | ||||
| } | ||||
|  | ||||
| interface VillageOwnState { | ||||
|     /** | ||||
|      * Village id | ||||
|   | ||||
							
								
								
									
										19
									
								
								src/utils.ts
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								src/utils.ts
									
									
									
									
									
								
							| @@ -1,4 +1,5 @@ | ||||
| import * as URLParse from 'url-parse'; | ||||
| import * as _ from 'underscore'; | ||||
|  | ||||
| export function sleep(ms: number) { | ||||
|     return new Promise(resolve => setTimeout(resolve, ms)); | ||||
| @@ -67,20 +68,6 @@ export function elClassId(classes: string | undefined, prefix: string): number | | ||||
|     return result; | ||||
| } | ||||
|  | ||||
| export function* split(n: number, from: number = 2, to: number = 6) { | ||||
|     let c = n; | ||||
|     while (c > 0) { | ||||
|         const next = from + Math.floor(Math.random() * (to - from)); | ||||
|         if (next < c) { | ||||
|             yield next; | ||||
|             c -= next; | ||||
|         } else { | ||||
|             yield c; | ||||
|             c = 0; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| export function toNumber(value: any): number | undefined { | ||||
|     const normalized = String(value) | ||||
|         .replace('\u2212', '\u002d') // minus to hyphen-minus | ||||
| @@ -119,3 +106,7 @@ export function markPage(text: string, version: string) { | ||||
|             '</div>' | ||||
|     ); | ||||
| } | ||||
|  | ||||
| export function first<T>(items: ReadonlyArray<T>): T | undefined { | ||||
|     return _.first(items); | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user