All files / object-instance resolve-id.function.ts

100% Statements 4/4
100% Branches 1/1
100% Functions 1/1
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29                                  105x         117x 13x     104x    
/**
 * Exports object instance switch/variable access function.
 *
 * @module object-instance/resolve-id.function
 */
import type { AgtkObjectInstance } from '@agogpixel/pgmmv-ts/api/agtk/object-instance/object-instance';
 
import type { ObjectInstanceAccessorType } from './object-instance-accessor-type.enum';
 
/**
 * Resolve switch or variable ID.
 *
 * @param objectInstance Object instance.
 * @param type Accessor type.
 * @param idOrName ID or name of switch/variable.
 * @returns ID or -1 when name not found.
 */
export function resolveId(
  objectInstance: AgtkObjectInstance,
  type: ObjectInstanceAccessorType,
  idOrName: number | string
) {
  if (typeof idOrName === 'string') {
    return objectInstance[type].getIdByName(idOrName);
  }
 
  return idOrName;
}