UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

23 lines (22 loc) 977 B
"use strict"; import { ERROR_TILE_ID, UNRESOLVED_TILE_ID } from "./WFCConstant"; export const UNRESOLVED_TILE_CONFIG = { tileId: UNRESOLVED_TILE_ID, rotation: 0 }; export const ERRORED_TILE_CONFIG = { tileId: ERROR_TILE_ID, rotation: 0 }; const TILE_CONFIG_ELEMENT_SEPARATOR = ":"; const TILE_CONFIGS_SEPARATOR = ","; export function tileConfigToString(tileConfig) { return `${tileConfig.tileId}${TILE_CONFIG_ELEMENT_SEPARATOR}${tileConfig.rotation}`; } export function tileConfigsToString(tileConfigs) { return tileConfigs.map(tileConfigToString).join(TILE_CONFIGS_SEPARATOR); } export function stringToTileConfigs(tileConfigsString) { const tileConfigElements = tileConfigsString.split(TILE_CONFIGS_SEPARATOR); return tileConfigElements.map((tileConfigString) => { const tileConfigElements2 = tileConfigString.split(TILE_CONFIG_ELEMENT_SEPARATOR); return { tileId: tileConfigElements2[0], rotation: parseInt(tileConfigElements2[1]) }; }); }