UNPKG

dotup-ts-node-skills-game

Version:
83 lines (81 loc) 3.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const Enumerations_1 = require("./Enumerations"); // tslint:disable var ButtonColors; (function (ButtonColors) { function getAllColors() { const f = Object.getOwnPropertyNames(Enumerations_1.ButtonColor); const result = f.map(item => { const typedColorString = item; return Enumerations_1.ButtonColor[typedColorString]; }); return result; } ButtonColors.getAllColors = getAllColors; function getRandomColorName() { const f = Object.getOwnPropertyNames(ButtonColors); const key = f[Math.floor(Math.random() * f.length)]; const typedColorString = key; return Enumerations_1.ButtonColor[typedColorString]; } ButtonColors.getRandomColorName = getRandomColorName; function getRandomColorNames(count = 1) { const f = Object.getOwnPropertyNames(Enumerations_1.ButtonColor); const result = []; while (result.length < count) { const key = f[Math.floor(Math.random() * f.length)]; if (!result.find(item => item === key)) { result.push(key); } } return result; } ButtonColors.getRandomColorNames = getRandomColorNames; function getUniqueRandomColors(count = 1, excludedColors = []) { const f = Object.getOwnPropertyNames(Enumerations_1.ButtonColor); if (count > f.length) { throw new Error('not enough colors'); } const result = []; while (result.length < count) { const key = f[Math.floor(Math.random() * f.length)]; const typedColorString = key; const nextColor = Enumerations_1.ButtonColor[typedColorString]; if (!result.find(item => item === nextColor) && !excludedColors.find(item => item === nextColor)) { result.push(nextColor); } } return result; } ButtonColors.getUniqueRandomColors = getUniqueRandomColors; function getRandomColors(count = 1, excludedColors = []) { const f = Object.getOwnPropertyNames(Enumerations_1.ButtonColor); const result = []; while (result.length < count) { const key = f[Math.floor(Math.random() * f.length)]; const typedColorString = key; const nextColor = Enumerations_1.ButtonColor[typedColorString]; if (!excludedColors.find(item => item === nextColor)) { result.push(nextColor); } } return result; } ButtonColors.getRandomColors = getRandomColors; function getColorName(value) { const f = Object.getOwnPropertyNames(Enumerations_1.ButtonColor); const corecctKey = f.find(key => { return Enumerations_1.ButtonColor[key] === value; }); return corecctKey; } ButtonColors.getColorName = getColorName; function getTranslation(color) { const name = getColorName(color); const result = Enumerations_1.ColorTranslation[name]; return result; } ButtonColors.getTranslation = getTranslation; })(ButtonColors = exports.ButtonColors || (exports.ButtonColors = {})); //# sourceMappingURL=ButtonColors.js.map