import { Strings } from '@src/Utils/Strings' ; import { IBuildingSchema } from '@src/Schema/IBuildingSchema' ; import { IBuildingMetadataSchema , IManufacturerAnyPowerMetadataSchema } from '@src/Schema/IBuildingMetadataSchema' ; export default function parseBuildings ( buildings , fixClassName = false ) { const ignored = [ 'Build_JumpPadTilted_C' , 'Build_JumpPad_C' , 'Build_Stair_1b_C' , 'Build_Snowman_C' , 'Build_WreathDecor_C' , 'Build_XmassLightsLine_C' , 'Build_XmassTree_C' , 'Build_CandyCaneDecor_C' , ] ; const wrongMapping = { Build_WalkwayTrun_C : 'Desc_WalkwayTurn_C' , Build_CatwalkCorner_C : 'Desc_CatwalkTurn_C' , Build_PowerPoleWall_Mk2_C : 'Desc_PowerPoleWallMk2_C' , Build_PowerPoleWall_Mk3_C : 'Desc_PowerPoleWallMk3_C' , Build_PowerPoleWallDouble_Mk2_C : 'Desc_PowerPoleWallDoubleMk2_C' , Build_PowerPoleWallDouble_Mk3_C : 'Desc_PowerPoleWallDoubleMk3_C' , } ; const result = [ ] ; for ( const building of buildings ) { if ( ignored . indexOf ( building . ClassName ) !== - 1 ) { continue ; } const metadata = { } ; if ( typeof building . mSpeed !== 'undefined' ) { metadata . beltSpeed = parseFloat ( building . mSpeed ) / 2 ; metadata . firstPieceCostMultiplier = 1 ; metadata . lengthPerCost = 200 ; metadata . maxLength = 4900 ; } if ( typeof building . mLengthPerCost !== 'undefined' ) { metadata . lengthPerCost = parseFloat ( building . mLengthPerCost ) ; metadata . firstPieceCostMultiplier = 1 ; } if ( typeof building . mMaxLength !== 'undefined' ) { metadata . maxLength = parseFloat ( building . mMaxLength ) ; } if ( typeof building . mPowerConsumption !== 'undefined' ) { metadata . powerConsumption = parseFloat ( building . mPowerConsumption ) ; } if ( typeof building . mPowerConsumptionExponent !== 'undefined' ) { metadata . powerConsumptionExponent = parseFloat ( building . mPowerConsumptionExponent ) ; } if ( typeof building . mEstimatedMininumPowerConsumption !== 'undefined' && typeof building . mEstimatedMaximumPowerConsumption !== 'undefined' ) { metadata . isVariablePower = true ; metadata . minPowerConsumption = parseFloat ( building . mEstimatedMininumPowerConsumption ) ; metadata . maxPowerConsumption = parseFloat ( building . mEstimatedMaximumPowerConsumption ) ; metadata . powerConsumption = ( metadata . minPowerConsumption + metadata . maxPowerConsumption ) / 2 ; } if ( typeof building . mManufacturingSpeed !== 'undefined' ) { metadata . manufacturingSpeed = parseFloat ( building . mManufacturingSpeed ) ; } if ( typeof building . mInventorySizeX !== 'undefined' && typeof building . mInventorySizeY !== 'undefined' ) { metadata . inventorySize = parseInt ( building . mInventorySizeX ) * parseInt ( building . mInventorySizeY ) ; } if ( typeof building . mFlowLimit !== 'undefined' ) { metadata . flowLimit = parseFloat ( building . mFlowLimit ) ; } if ( typeof building . mDesignPressure !== 'undefined' ) { metadata . maxPressure = parseFloat ( building . mDesignPressure ) ; } if ( typeof building . mStorageCapacity !== 'undefined' ) { metadata . storageCapacity = parseFloat ( building . mStorageCapacity ) ; } if ( building . ClassName === 'Desc_RailroadTrack_C' ) { metadata . firstPieceCostMultiplier = 2 ; metadata . lengthPerCost = 12 ; } else if ( building . ClassName in wrongMapping ) { building . ClassName = wrongMapping [ building . ClassName ] ; } let slug = Strings . webalize ( building . mDisplayName ) ; if ( building . ClassName . match ( /Steel/ ) || building . ClassName === 'Build_Wall_8x4_02_C' ) { slug += '-steel' ; } else if ( building . ClassName . match ( /Polished/ ) ) { slug += '-polished' ; } else if ( building . ClassName . match ( /Metal/ ) ) { slug += '-metal' ; } else if ( building . ClassName . match ( /Concrete/ ) ) { slug += '-concrete' ; } else if ( building . ClassName . match ( /Asphalt/ ) ) { slug += '-asphalt' ; } const size = { width : 0 , length : 0 , height : 0 , } ; if ( building . mSize ) { size . width = size . length = building . mSize / 100 ; } if ( building . mHeight ) { size . height = building . mHeight / 100 ; } if ( building . mWidth ) { size . width = building . mWidth / 100 ; } result . push ( { slug : slug , name : building . mDisplayName , description : building . mDescription . replace ( /\r\n/ig , '\n' ) , categories : [ ] , buildMenuPriority : 0 , className : fixClassName ? building . ClassName . replace ( 'Build_' , 'Desc_' ) : building . ClassName , metadata : metadata , size : size , } ) ; } return result ; }