@@ -176,83 +176,6 @@ function shuffle(array) {
176176 return array ;
177177}
178178
179- /**
180- * Returns first object in an array matching property:value or false if no match is found.
181- *
182- * @param property: The property name to search in, or an array of property names if multiple
183- * property:values pairs should be matched.
184- * @param value: The value to match, or an array of values if multiple property:value pairs
185- * should be matched.
186- * @param {boolean } remove: Whether to also remove the object from the array. Defaults to true.
187- */
188- function pickFromObjectArray ( objectArray , property , value , remove = true ) {
189- if ( objectArray . length == 0 )
190- return false ;
191- // Turn single-value search criteria into arrays.
192- if ( typeof property != 'object' )
193- property = [ property ] ;
194- if ( typeof value != 'object' )
195- value = [ value ] ;
196- if ( property . length != value . length )
197- throw ( 'The number of values to search for must match the number of properties.' ) ;
198-
199- // Find the first matching object.
200- for ( let i in objectArray ) {
201- let match = true ;
202- for ( let j in property ) {
203- if ( objectArray [ i ] [ property [ j ] ] != value [ j ] )
204- match = false ;
205- }
206- if ( match ) {
207- if ( remove )
208- return objectArray . splice ( i , 1 ) [ 0 ] ;
209- else
210- return objectArray [ i ] ;
211- }
212- }
213- return false ;
214- }
215-
216- /**
217- * Returns an array with all objects matching property:value in the search array.
218- *
219- * @param property: The property name to search in, or an array of property names if multiple
220- * property:values pairs should be matched.
221- * @param value: The value to match, or an array of values if multiple property:value pairs
222- * should be matched.
223- * @param {boolean } remove: Whether to also remove the objects from the array. Defaults to true.
224- */
225- function pickAllFromObjectArray ( objectArray , property , value , remove = true ) {
226- let result = [ ] ;
227- if ( objectArray . length == 0 )
228- return result ;
229- // Turn single-value search criteria into arrays.
230- if ( typeof property != 'object' )
231- property = [ property ] ;
232- if ( typeof value != 'object' )
233- value = [ value ] ;
234- if ( property . length != value . length )
235- throw ( 'The number of values to search for must match the number of properties.' ) ;
236-
237- // Find matching objects.
238- for ( let i = 0 ; i < objectArray . length ; i ++ ) {
239- let match = true ;
240- for ( let j in property ) {
241- if ( objectArray [ i ] [ property [ j ] ] != value [ j ] )
242- match = false ;
243- }
244- if ( match ) {
245- if ( remove ) {
246- result . push ( objectArray . splice ( i , 1 ) ) ;
247- i -- ; // The indices are shifted, so we move back one step.
248- }
249- else
250- result . push ( objectArray [ i ] ) ;
251- }
252- }
253- return result ;
254- }
255-
256179// Returns how many times 'value' occurs in 'array'.
257180function getFrequency ( array , value ) {
258181 let frequency = 0 ;
@@ -389,7 +312,7 @@ function isIterable(obj) {
389312function getAgentById ( id ) {
390313 if ( ! gameState . agents )
391314 return false ;
392- return pickFromObjectArray ( gameState . agents , 'id' , id , false ) ;
315+ return new ObjectFilter ( { id : id } ) . findFirstInArray ( gameState . agents ) ;
393316}
394317
395318// Selects a and returns a random element from an array. If the array consists of
@@ -532,22 +455,18 @@ function compareObjects(o1, o2) {
532455 * @param {string } type: The type of object: cards, spaces or goods.
533456 * @param {string } method: The name of the resolver method.
534457 */
535- function callResolver ( type , method ) {
458+ function callResolver ( method ) {
536459 if ( ! method )
537460 return false ;
538461
539462 if ( ! modules [ module ] . resolvers ) {
540463 log ( 'Active module does not have any resolvers.' , 'error' ) ;
541464 return false ;
542465 }
543- if ( ! modules [ module ] . resolvers [ type ] ) {
544- log ( 'Active module does not have any resolvers for ' + type + '.' , 'error' ) ;
545- return false ;
546- }
547- if ( ! modules [ module ] . resolvers [ type ] [ method ] ) {
548- log ( 'Active module does not have a resolver ' + method + ' for ' + type + '.' , 'error' ) ;
466+ if ( ! modules [ module ] . resolvers [ method ] ) {
467+ log ( 'Active module does not have a resolver ' + method + '.' , 'error' ) ;
549468 return false ;
550469 }
551470
552- return modules [ module ] . resolvers [ type ] [ method ] ( ...parseArguments ( arguments , 2 ) ) ;
471+ return modules [ module ] . resolvers [ type ] [ method ] ( ...parseArguments ( arguments , 1 ) ) ;
553472}
0 commit comments