All files / src/converter/portal portalCode.ts

100% Statements 27/27
100% Branches 3/3
100% Functions 3/3
100% Lines 27/27

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 30 31 32 33 34 35 36 37 381x 1x 1x 1x         1x             1x 6x 6x 6x 6x 3x 3x 3x 3x 3x 3x 3x 6x 6x 6x 6x 6x 1x 1x 1x 6x 6x  
import { baseConverter } from '@/converter/baseConverter';
import { glyphs2Coords } from '@/functions/convertGlyphs/glyphs2Coords';
import { glyphs2XYZ } from '@/functions/convertGlyphs/glyphs2XYZ';
import { handleGlyphCode } from '@/helper/handleGlyphInput';
import type { IConverterMethods } from '@/types/converter';
import type { GalacticInput, GalacticOutput } from '@/types/galacticTypes';
import type { GlyphInput } from '@/types/glyphTypes';
import type { VoxelOutput } from '@/types/voxelTypes';
import { GlyphInputValidator } from '@/validation/glyphInputValidation';
 
/**
 * A converter that takes a Portal code and returns functions to convert to other portal types.
 * @param input multiple ways to input Portal code, see {@link GlyphInput| GlyphInput}
 * @returns functions defined in {@link IConverterMethods| IConverterMethods}
 */
export const PortalCode = (input: GlyphInput): Omit<IConverterMethods, 'toGlyph'> => ({
  toGalacticCoordinates: baseConverter<GlyphInput, GalacticOutput>({
    input,
    inputValidator: GlyphInputValidator,
    converter: (input: GalacticInput) => {
      const inputCoords = handleGlyphCode(input);
      const result = glyphs2Coords(inputCoords);
      return {
        code: result,
        groups: result.split(':'),
      };
    },
  }),
  toVoxel: baseConverter<GlyphInput, VoxelOutput>({
    input,
    inputValidator: GlyphInputValidator,
    converter: (input: GlyphInput) => {
      const inputCoords = handleGlyphCode(input);
      return glyphs2XYZ(inputCoords);
    },
  }),
});