import rawData from '@data/data.json' ; import rawAprilData from '@data/aprilData.json' ; import { IJsonSchema } from '@src/Schema/IJsonSchema' ; import { Item } from '@src/Data/Item' ; import { Recipe } from '@src/Data/Recipe' ; import { IMinerSchema } from '@src/Schema/IMinerSchema' ; import { IItemSchema } from '@src/Schema/IItemSchema' ; import { Constants } from '@src/Constants' ; import { April } from '@src/Utils/April' ; export class Model { public items : { [ key ] : Item ; } = { } ; public recipes : { [ key ] : Recipe ; } = { } ; public constructor ( public readonly data ) { for ( const k in data . items ) { if ( data . items . hasOwnProperty ( k ) ) { try { this . items [ k ] = new Item ( this , data . items [ k ] ) ; } catch ( e ) { } } } for ( const k in data . recipes ) { if ( data . recipes . hasOwnProperty ( k ) ) { const recipe = data . recipes [ k ] ; if ( recipe . inHand || recipe . inMachine || recipe . inWorkshop ) { try { this . recipes [ k ] = new Recipe ( this , recipe ) ; } catch ( e ) { } } } } } public getItem ( className ) { if ( className in this . items ) { return this . items [ className ] ; } throw new Error ( 'Unknown item ' + className ) ; } public getAutomatableItems ( includeWaste = false ) { const items = [ ] ; itemLoop : for ( const k in this . items ) { if ( this . items . hasOwnProperty ( k ) ) { for ( const l in this . recipes ) { if ( this . recipes . hasOwnProperty ( l ) && this . recipes [ l ] . prototype . inMachine ) { for ( const product of this . recipes [ l ] . products ) { if ( product . item === this . items [ k ] || ( includeWaste && k === Constants . NUCLEAR_WASTE_CLASSNAME ) ) { items . push ( this . items [ k ] ) ; continue itemLoop ; } } } } } } return items . sort ( ( item1 , item2 ) => { return item1 . prototype . name . localeCompare ( item2 . prototype . name ) ; } ) . map ( ( item ) => { return item . prototype ; } ) ; } public getInputableItems ( ) { return this . getAutomatableItems ( true ) . filter ( ( item ) => { return ! ( item . className in this . data . resources ) || item . className === Constants . NUCLEAR_WASTE_CLASSNAME ; } ) ; } public isRawResource ( item ) { return item . prototype . className in this . data . resources ; } public getResourceMiners ( item ) { const result = [ ] ; for ( const k in this . data . miners ) { if ( this . data . miners . hasOwnProperty ( k ) ) { const miner = this . data . miners [ k ] ; if ( miner . allowedResources . length === 0 ) { if ( ( miner . allowLiquids && item . prototype . liquid ) || ( miner . allowSolids && ! item . prototype . liquid ) ) { result . push ( miner ) ; } } else if ( miner . allowedResources . indexOf ( item . prototype . className ) !== - 1 ) { result . push ( miner ) ; } } } return result ; } } export default new Model ( April . isApril ( ) ? rawAprilData as any : rawData as any ) ;