Newer
Older
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
/************************************************************
* The player clicked the player tags button. Shows the player tags modal.
************************************************************/
function showPlayerTagsModal () {
if (document.forms['player-tags'].elements.length <= 6) {
/* maybe move this data to an external file if the hardcoded stuff changes often enough */
var playerOptions = {
'hair_length' : [
{value: 'bald', text: 'Bald - No Hair'},
{value: 'short_hair', text: 'Short Hair - Does Not Pass Jawline'},
{value: 'medium_hair', text: 'Medium Hair - Reaches Between Jawline and Shoulders'},
{value: 'long_hair', text: 'Long Hair - Reaches Beyond Shoulders'},
{value: 'very_long_hair long_hair', text: 'Very Long Hair - Reaches the Thighs or Beyond'}
],
'physical_build' : [
{value: 'chubby'},
{value: 'athletic'},
{value: 'muscular athletic'}
],
'height' : [
{value: 'tall'},
{value: 'average'},
{value: 'short'}
],
'pubic_hair_style' : [
{value: 'shaved'},
{value: 'trimmed'},
{value: 'hairy'}
],
'maleOnly_circumcision' : [
{value: 'circumcised'},
{value: 'uncircumcised'}
]
}
for (var choiceName in playerOptions) {
var parsedName = choiceName.match(/^([^_]+)Only_(.*$)/) || [,'',choiceName];
var choiceElem = '<label class="player-tag-select ' + parsedName[1] + '">Choose a' + ('aeiou'.includes(parsedName[2].charAt(0)) ? 'n ' : ' ');
choiceElem += parsedName[2].replace(/_/g, ' ') + ':';
choiceElem += '<select name="' + parsedName[2] + '"' + (parsedName[1] ? ' class="' + parsedName[1] + '"' : '') + '><option value=""></option>';
playerOptions[choiceName].forEach(function(choice) {
var choiceText = choice.text || choice.value.charAt(0).toUpperCase() + choice.value.split(' ')[0].slice(1);
choiceElem += '<option value="' + choice.value + '">' + choiceText + '</option>';
});
choiceElem += '</select></label>';
choiceElem = document.createRange().createContextualFragment(choiceElem);
document.forms['player-tags'].appendChild(choiceElem);
}
// Safari doesn't support color inputs properly!
var hairColorPicker = document.getElementById('hair_color_picker');
var selectionType;
try {
selectionType = typeof hairColorPicker.selectionStart;
} catch(e) {
selectionType = null;
}
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
var hairColors = ['black_hair', 'white_hair', 'brunette', 'ginger', 'blonde',
'green_hair exotic_hair', 'blue_hair exotic_hair', 'purple_hair exotic_hair', 'pink_hair exotic_hair'];
var eyeColors = ['dark_eyes', 'pale_eyes', 'red_eyes', 'amber_eyes', 'green_eyes', 'blue_eyes', 'violet_eyes'];
var hairColorOptions = '';
var eyeColorOptions = '';
hairColors.forEach(function(tag) {
hairColorOptions += '<option value="' + tag + '">' + tag.split(' ')[0] + '</option>';
});
eyeColors.forEach(function(tag) {
eyeColorOptions += '<option value="' + tag + '">' + tag + '</option>';
});
$(hairColorPicker.parentNode).replaceWith('<select name="hair_color"><option value=""></option>' + hairColorOptions + '</select>');
$(document.getElementById('eye_color_picker').parentNode).replaceWith('<select name="eye_color"><option value=""></option>' + eyeColorOptions + '</select>');
}
var rgb2hsv = function(rgb) {
var r = parseInt(rgb.slice(1,3), 16)/255;
var g = parseInt(rgb.slice(3,5), 16)/255;
var b = parseInt(rgb.slice(5), 16)/255;
var min = Math.min(r, Math.min(g,b));
var max = Math.max(r, Math.max(g,b));
if (max === 0) {
return [0,0,0];
}
var maxOffset = max === r ? 0 : (max === g ? 2 : 4);
var delta = max === r ? g-b : (max === g ? b-r : r-g);
var h = 60 * (maxOffset + delta / (max - min));
if (h < 0) {
h += 360;
}
return [h, (max - min) / max * 100, max * 100];
}
/* convert the raw colors to corresponding tags and display next to selector */
$('input[type=color]').on('input', function() {
var h, s, v;
[h,s,v] = rgb2hsv(this.value);
var tag;
color2tag:
if (this.id === 'hair_color_picker') {
delete this.previousElementSibling.dataset.exotic;
if (v < 10) {
tag = 'black_hair';
break color2tag;
}
if (s < 25) {
if (v < 30) {
tag = 'black_hair';
} else {
tag = 'white_hair';
}
break color2tag;
}
if (s < 50 && h > 20 && h < 50) {
tag = 'brunette';
break color2tag;
}
if (h < 50) {
tag = 'ginger';
} else if (h < 65) {
tag = 'blonde';
} else if (h < 325) {
this.previousElementSibling.dataset.exotic = 'exotic_hair';
if (h < 145) {
tag = 'green_hair';
} else if (h < 255) {
tag = 'blue_hair';
} else if (h < 290) {
tag = 'purple_hair';
} else {
tag = 'pink_hair';
}
} else {
tag = 'ginger';
}
} else if (this.id === 'eye_color_picker') {
if (v < 25) {
tag = 'dark_eyes';
break color2tag;
}
if (s < 20) {
tag = 'pale_eyes';
break color2tag;
}
if (h < 15) {
tag = 'red_eyes';
} else if (h < 65) {
tag = 'amber_eyes';
} else if (h < 145) {
tag = 'green_eyes';
} else if (h < 255) {
tag = 'blue_eyes';
} else if (h < 325) {
tag = 'violet_eyes';
} else {
tag = 'red_eyes';
}
}
this.previousElementSibling.value = tag || '';
});
$('input[name=skin_color_picker]').on('input', function() {
if (this.value < 25) {
}
this.previousElementSibling.value = tag || '';
});
$('.modal-button.clearSelections').click(function() {
var formElements = document.forms['player-tags'].elements;
for (var i = 0; i < formElements.length; i++) {
if (formElements[i].type !== 'color') {
formElements[i].value = '';
}
}
});
}
$playerTagsModal.modal('show');
}
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
/************************************************************
* The player clicked on a table opacity button.
************************************************************/
function toggleTableVisibility () {
if (tableOpacity > 0) {
$gameTable.fadeOut();
tableOpacity = 0;
} else {
$gameTable.fadeIn();
tableOpacity = 1;
}
}
function forceTableVisibility(state) {
if (!state) {
$gameTable.fadeOut();
tableOpacity = 0;
} else {
$gameTable.fadeIn();
tableOpacity = 1;
}
}
/**********************************************************************
***** Utility Functions *****
**********************************************************************/
/************************************************************
* Returns a random number in a range.
************************************************************/
function getRandomNumber (min, max) {
return Math.floor(Math.random() * (max - min) + min);
}
ReformCopyright
committed
/************************************************************
* Changes the first letter in a string to upper case.
************************************************************/
String.prototype.initCap = function() {
return this.substr(0, 1).toUpperCase() + this.substr(1);
}
ReformCopyright
committed
/************************************************************
* Counts the number of elements that evaluate as true, or,
ReformCopyright
committed
* if a function is provided, passes the test implemented by it.
************************************************************/
Array.prototype.countTrue = function(func) {
var count = 0;
for (var i = 0; i < this.length; i++) {
if (i in this
&& (func ? func(this[i], i, this) : this[i])) {
count++;
}
}
return count;
}
/************************************************************
* Generate a random alphanumeric ID.
************************************************************/
function generateRandomID() {
var ret = ''
for (let i=0;i<10;i++) {
ret += 'abcdefghijklmnopqrstuvwxyz1234567890'[getRandomNumber(0,36)]
}
/**********************************************************************
* Returns the width of the visible screen in pixels.
**/
{
/* fetch all game screens */
var screens = document.getElementsByClassName('screen');
/* figure out which screen is visible */
{
/* this screen is currently visible */
return screens[i].offsetWidth;
}
}
}
/**********************************************************************
* Automatically adjusts the size of all font based on screen width.
**/
{
/* resize font */
var screenWidth = getScreenWidth();
document.body.style.fontSize = (14*(screenWidth/1000))+'px';

ReformCopyright
committed
if (backgroundImage && backgroundImage.height && backgroundImage.width) {
var w = window.innerWidth, h = window.innerHeight;
if (h > (3/4) * w) {
h = (3/4) * w;
} else {

ReformCopyright
committed
}
var ar = backgroundImage.width / backgroundImage.height;
if (ar > 4/3) {
var scale = Math.sqrt(16/9 / ar);
$("body").css("background-size", "auto " + Math.round(scale * h) + "px");

ReformCopyright
committed
} else {
var scale = Math.sqrt(ar);
$("body").css("background-size", Math.round(scale * w) + "px auto");

ReformCopyright
committed
}
}
/* set up future resizing */
window.onresize = autoResizeFont;
/* Get the number of players loaded, including the human player.*/
function countLoadedOpponents() {
return players.reduce(function (a, v) { return a + (v ? 1 : 0); }, 0);
}