All files / object-instance/switches get-switch-value.function.ts

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

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              12x 12x                 12x 14x   14x 1x     13x    
/**
 * Exports object instance get switch variable value function.
 *
 * @module object-instance/switches/get-switch-value.function
 */
import type { AgtkObjectInstance } from '@agogpixel/pgmmv-ts/api/agtk/object-instance/object-instance';
 
import { ObjectInstanceAccessorType } from '../object-instance-accessor-type.enum';
import { resolveId } from '../resolve-id.function';
 
/**
 * Get switch value in object instance.
 *
 * @param objectInstance Object instance.
 * @param key Switch ID or name.
 * @returns Resolved switch value or `undefined`.
 */
export function getSwitchValue(objectInstance: AgtkObjectInstance, key: number | string) {
  const id = resolveId(objectInstance, ObjectInstanceAccessorType.Switches, key);
 
  if (id === -1) {
    return;
  }
 
  return objectInstance.switches.get(id).getValue();
}