var currentValue = {
clotheset: {min: 0, value: -1, max: 0}
}
var items = {}
var clotheSets = {}
var skinManager = null
var handsUpKey = null
var disabledValues = {}
var direction = ""
window.addEventListener('message', function(event){
var item = event.data;
if (item.action == "openCharacter") {
$('.categories').empty()
$("body").fadeIn(100)
$('.panel').empty()
document.getElementById("rotate-input").value = (item.currentRotate).toString()
document.getElementById("distance-input").value = (item.currentDistance).toString()
$('#headerName').text(translate.create_character);
$('#headerCategory').text(translate.select_category);
$('#height-text').text(translate.height);
$('#rotate-text').text(translate.rotate);
$('#distance-text').text(translate.distance);
$('#save').text(translate.save);
$('#cancel').text(translate.cancel);
if (item.clotheSets) {
clotheSets = item.clotheSets
}
if (item.items) {
items = item.items
}
skinManager = item.skinmanager
disabledValues = item.disabledValues
handsUpKey = item.handsUpKey
$('.hands-up').hide()
if (item.enableHandsUpButton) {
$('.hands-up').show()
}
$('.cancel-skin').hide()
if (item.enableCancelButtonUI && item.playerHasAlreadySkin) {
$('.cancel-skin').show()
}
if (item.categories) {
if (item.categories['parents']) {
$('.categories').append(`
`)
}
if (item.categories['face']) {
$('.categories').append(`
`)
}
if (item.categories['clothes']) {
$('.categories').append(`
`)
}
// if (item.categories['clothesets']) {
// $('.categories').append(`
//
//

//
// `)
// }
if (item.categories['hairs']) {
$('.categories').append(`
`)
}
if (item.categories['makeup']) {
$('.categories').append(`
`)
}
}
for (const [key, value] of Object.entries(item.data)) {
currentValue[key] = {
value: value.value,
min: value.min,
max: value.max,
excluded: []
}
}
for (const [k, v] of Object.entries(currentValue)) {
if (disabledValues[k]) {
for (const [_k, _v] of Object.entries(disabledValues[k])) {
v.excluded.push(_v)
}
}
}
}
if (item.action == 'updateSecondValue') {
document.getElementById(`${item.secondItem}-range`).max = item.secondValue
document.getElementById(`${item.secondItem}-range`).value = 0
$(`#${item.secondItem}-value`).html(0)
$(`#${item.secondItem}-max`).html(item.secondValue)
}
if (item.action == 'updateInputs') {
document.getElementById("distance-input").value = (item.fov).toString()
}
});
$(document).on('click', '.accept-skin', function(e){
$.post('https://hp_charcreator/closeCharacter');
$("body").css("display", "none")
})
$(document).on('click', '.cancel-skin', function(e) {
$.post('https://hp_charcreator/cancel');
$("body").css("display", "none")
})
$(document).on('click', '.hands-up', function(e) {
$.post('https://hp_charcreator/hands_up');
})
$(document).on('click', '.categoryBtn', function(e){
$('.panel').empty()
$('#headerCategory').html(translate.category[$(this).data("type")])
changeCamera($(this).data("type"))
var values = ``
switch ($(this).data("type")) {
case "parents":
if (items['parents'].sex) {
values = values + `
`
}
if (items['parents'].parents) {
values = values + `
${translate.title_parents}
${translate.sub_mom}
${translate.parentsNames['mom'][currentValue['mom'].value]}
${translate.sub_dad}
${translate.parentsNames['dad'][currentValue['dad'].value]}
`
}
if (items['parents'].face_md_weight) {
values = values + `
${translate.title_resemblance}
${translate.sub_face_md_weight}
`
}
if (items['parents'].skin_md_weight) {
values = values + `
${translate.title_skin_md_weight}
${translate.sub_skin_md_weight}
`
}
$('.panel').html(values)
break;
case "face":
if (items['face'].neck_thickness) {
values = values + `
${translate.title_neck_thickness}
${translate.sub_neck_thickness}
${currentValue['neck_thickness'].value}
`
}
if (items['face'].age) {
values = values + `
${translate.title_ageing}
${translate.sub_age_1}
${currentValue['age_1'].value}
${translate.sub_age_2}
${currentValue['age_2'].value}
`
}
if (items['face'].eyebrows) {
values = values + `
${translate.title_eyebrow}
${translate.sub_eyebrows_5}
${currentValue['eyebrows_5'].value}
${translate.sub_eyebrows_6}
${currentValue['eyebrows_6'].value}
`
}
if (items['face'].nose) {
values = values + `
${translate.title_nose}
${translate.sub_nose_1}
${currentValue['nose_1'].value}
${translate.sub_nose_2}
${currentValue['nose_2'].value}
${translate.sub_nose_3}
${currentValue['nose_3'].value}
${translate.sub_nose_4}
${currentValue['nose_4'].value}
${translate.sub_nose_5}
${currentValue['nose_5'].value}
${translate.sub_nose_6}
${currentValue['nose_6'].value}
`
}
if (items['face'].cheeks) {
values = values + `
${translate.title_cheekbones}
${translate.sub_cheeks_1}
${currentValue['cheeks_1'].value}
${translate.sub_cheeks_2}
${currentValue['cheeks_2'].value}
${translate.sub_cheeks_3}
${currentValue['cheeks_3'].value}
`
}
if (items['face'].lip_thickness) {
values = values + `
${translate.title_lips}
${translate.sub_lip_thickness}
${currentValue['lip_thickness'].value}
`
}
if (items['face'].jaw) {
values = values + `
${translate.title_jaw}
${translate.sub_jaw_1}
${currentValue['jaw_1'].value}
${translate.sub_jaw_2}
${currentValue['jaw_2'].value}
`
}
if (items['face'].chin) {
values = values + `
${translate.title_chin}
${translate.sub_chin_1}
${currentValue['chin_1'].value}
${translate.sub_chin_2}
${currentValue['chin_2'].value}
${translate.sub_chin_3}
${currentValue['chin_3'].value}
${translate.sub_chin_4}
${currentValue['chin_4'].value}
`
}
if (items['face'].eye_color) {
values = values + `
${translate.title_eye_color}
${translate.sub_eye_color}
`
}
if (items['face'].blemishes) {
values = values + `
${translate.title_blemishes}
${translate.sub_blemishes_1}
${currentValue['blemishes_1'].value}
${translate.sub_blemishes_2}
${currentValue['blemishes_2'].value}
`
}
if (items['face'].complexion) {
values = values + `
${translate.title_complexion}
${translate.sub_complexion_1}
${currentValue['complexion_1'].value}
${translate.sub_complexion_2}
${currentValue['complexion_2'].value}
`
}
if (items['face'].sun) {
values = values + `
${translate.title_sun}
${translate.sub_sun_1}
${currentValue['sun_1'].value}
${translate.sub_sun_2}
${currentValue['sun_2'].value}
`
}
if (items['face'].moles) {
values = values + `
${translate.title_moles}
${translate.sub_moles_1}
${currentValue['moles_1'].value}
${translate.sub_moles_2}
${currentValue['moles_2'].value}
`
}
$('.panel').html(values)
break;
case "clothes":
if (items['clothes'].tshirt) {
values = values + `
${translate.title_tshirt}
${translate.sub_tshirt_1}
${currentValue['tshirt_1'].value}
${translate.sub_tshirt_2}
${currentValue['tshirt_2'].value}
`
}
if (items['clothes'].torso) {
values = values + `
${translate.title_torso}
${translate.sub_torso_1}
${currentValue['torso_1'].value}
${translate.sub_torso_2}
${currentValue['torso_2'].value}
`
}
if (items['clothes'].arms) {
values = values + `
${translate.title_arms}
${translate.sub_arms}
${currentValue['arms'].value}
${translate.sub_arms_2}
${currentValue['arms_2'].value}
`
}
if (items['clothes'].pants) {
values = values + `
${translate.title_pants}
${translate.sub_pants_1}
${currentValue['pants_1'].value}
${translate.sub_pants_2}
${currentValue['pants_2'].value}
`
}
if (items['clothes'].shoes) {
values = values + `
${translate.title_shoes}
${translate.sub_shoes_1}
${currentValue['shoes_1'].value}
${translate.sub_shoes_2}
${currentValue['shoes_2'].value}
`
}
if (items['clothes'].decals) {
values = values + `
${translate.title_decals}
${translate.sub_decals_1}
${currentValue['decals_1'].value}
${translate.sub_decals_2}
${currentValue['decals_2'].value}
`
}
if (items['clothes'].mask) {
values = values + `
${translate.title_mask}
${translate.sub_mask_1}
${currentValue['mask_1'].value}
${translate.sub_mask_2}
${currentValue['mask_2'].value}
`
}
if (items['clothes'].bproof) {
values = values + `
${translate.title_bproof}
${translate.sub_bproof_1}
${currentValue['bproof_1'].value}
${translate.sub_bproof_2}
${currentValue['bproof_2'].value}
`
}
if (items['clothes'].chain) {
values = values + `
${translate.title_chain}
${translate.sub_chain_1}
${currentValue['chain_1'].value}
${translate.sub_chain_2}
${currentValue['chain_2'].value}
`
}
if (items['clothes'].helmet) {
values = values + `
${translate.title_helmet}
${translate.sub_helmet_1}
${currentValue['helmet_1'].value}
${translate.sub_helmet_2}
${currentValue['helmet_2'].value}
`
}
if (items['clothes'].glasses) {
values = values + `
${translate.title_glasses}
${translate.sub_glasses_1}
${currentValue['glasses_1'].value}
${translate.sub_glasses_2}
${currentValue['glasses_2'].value}
`
}
if (items['clothes'].watches) {
values = values + `
${translate.title_watches}
${translate.sub_watches_1}
${currentValue['watches_1'].value}
${translate.sub_watches_2}
${currentValue['watches_2'].value}
`
}
if (items['clothes'].bracelets) {
values = values + `
${translate.title_bracelets}
${translate.sub_bracelets_1}
${currentValue['bracelets_1'].value}
${translate.sub_bracelets_2}
${currentValue['bracelets_2'].value}
`
}
if (items['clothes'].bags) {
values = values + `
${translate.title_bags}
${translate.sub_bags_1}
${currentValue['bags_1'].value}
${translate.sub_bags_2}
${currentValue['bags_2'].value}
`
}
if (items['clothes'].ears) {
values = values + `
${translate.title_ears}
${translate.sub_ears_1}
${currentValue['ears_1'].value}
${translate.sub_ears_2}
${currentValue['ears_2'].value}
`
}
$('.panel').html(values)
break;
case "clothesets":
values = values + `
${translate.title_clothesets}
${translate.sub_clotheset}
${clotheSets[currentValue['clotheset'].value] && clotheSets[currentValue['clotheset'].value].name || 'NONE'}
`
$('.panel').html(values)
break;
case "hairs":
if (items['hairs'].hair) {
values = values + `
${translate.title_hair}
${translate.sub_hair_1}
${currentValue['hair_1'].value}
${translate.sub_hair_color_1}
${translate.sub_hair_color_2}
`
}
if (items['hairs'].beard) {
values = values + `
${translate.title_beard}
${translate.sub_beard_1}
${currentValue['beard_1'].value}
${translate.sub_beard_2}
${currentValue['beard_2'].value}
${translate.sub_beard_3}
`
}
if (items['hairs'].eyebrow) {
values = values + `
${translate.title_eyebrow}
${translate.sub_eyebrows_1}
${currentValue['eyebrows_1'].value}
${translate.sub_eyebrows_2}
${currentValue['eyebrows_2'].value}
${translate.sub_eyebrows_3}
`
}
if (items['hairs'].chesthair) {
values = values + `
${translate.title_chesthair}
${translate.sub_chest_1}
${currentValue['chest_1'].value}
${translate.sub_chest_2}
${currentValue['chest_2'].value}
${translate.sub_chest_3}
`
}
$('.panel').html(values)
break;
case "makeup":
if (items['makeup'].makeup) {
values = values + `
${translate.title_makeup}
${translate.sub_makeup_1}
${currentValue['makeup_1'].value}
${translate.sub_makeup_2}
${currentValue['makeup_2'].value}
${translate.sub_makeup_3}
`
}
if (items['makeup'].blush) {
values = values + `
${translate.title_blush}
${translate.sub_blush_1}
${currentValue['blush_1'].value}
${translate.sub_blush_2}
${currentValue['blush_2'].value}
${translate.sub_blush_3}
`
}
if (items['makeup'].lipstick) {
values = values + `
${translate.title_lipstick}
${translate.sub_lipstick_1}
${currentValue['lipstick_1'].value}
${translate.sub_lipstick_2}
${currentValue['lipstick_2'].value}
${translate.sub_lipstick_3}
`
}
$('.panel').html(values)
break;
}
});
function previousClotheSets() {
if (clotheSets[currentValue['clotheset'].value-1]) {
currentValue['clotheset'].value -= 1
$(`.item-label`).html(clotheSets[currentValue['clotheset'].value].name)
}
$.post('https://hp_charcreator/change', JSON.stringify({
type: 'clotheset',
new: currentValue['clotheset'].value
}));
}
function nextClotheSets() {
if (clotheSets[currentValue['clotheset'].value+1]) {
currentValue['clotheset'].value += 1
$(`.item-label`).html(clotheSets[currentValue['clotheset'].value].name)
}
$.post('https://hp_charcreator/change', JSON.stringify({
type: 'clotheset',
new: currentValue['clotheset'].value
}));
}
function previous(item) {
if (currentValue[item].value > currentValue[item].min) {
if (item == 'mom') {
if (currentValue[item].value === 45) {
currentValue[item].value = 41
} else {
currentValue[item].value -= 1
}
$(`#${item}-label`).text(translate.parentsNames[item][currentValue[item].value])
$(`#${item}-photo`).css(`background-image`, `url(./parents/${item}-${currentValue[item].value}.png)`)
} else if (item == 'dad') {
if (currentValue[item].value === 42) {
currentValue[item].value = 20
} else {
currentValue[item].value -= 1
}
$(`#${item}-label`).text(translate.parentsNames[item][currentValue[item].value])
$(`#${item}-photo`).css(`background-image`, `url(./parents/${item}-${currentValue[item].value}.png)`)
} else {
currentValue[item].value -= 1
$(`#${item}-label`).html(currentValue[item].value)
}
}
$.post('https://hp_charcreator/change', JSON.stringify({
type: item,
new: currentValue[item].value
}));
}
function next(item) {
if (currentValue[item].value < currentValue[item].max) {
if (item == 'mom') {
if (currentValue[item].value === 41) {
currentValue[item].value = 45
} else {
currentValue[item].value += 1
}
$(`#${item}-label`).text(translate.parentsNames[item][currentValue[item].value])
$(`#${item}-photo`).css(`background-image`, `url(./parents/${item}-${currentValue[item].value}.png)`)
} else if (item == 'dad') {
if (currentValue[item].value === 20) {
currentValue[item].value = 42
} else {
currentValue[item].value += 1
}
$(`#${item}-label`).text(translate.parentsNames[item][currentValue[item].value])
$(`#${item}-photo`).css(`background-image`, `url(./parents/${item}-${currentValue[item].value}.png)`)
} else {
currentValue[item].value = currentValue[item].value + 1
$(`#${item}-value`).html(currentValue[item].value)
}
}
$.post('https://hp_charcreator/change', JSON.stringify({
type: item,
new: currentValue[item].value
}));
}
function changeColor(item, dataId) {
$.post('https://hp_charcreator/change', JSON.stringify({
type: item,
new: dataId
}));
currentValue[item].value = dataId
}
function changeHeight() {
var changedHeight = document.getElementById('height-input').value
$.post('https://hp_charcreator/change_height', JSON.stringify({height: changedHeight}));
}
function changeRotate() {
var changedRotate = document.getElementById('rotate-input').value
$.post('https://hp_charcreator/change_rotate', JSON.stringify({rotate: changedRotate}));
}
function changeDistance() {
var changedDistance = document.getElementById('distance-input').value
$.post('https://hp_charcreator/change_distance', JSON.stringify({distance: changedDistance}));
}
function changeCamera(type) {
$.post('https://hp_charcreator/change_camera', JSON.stringify({type: type}));
}
function changeRange(item) {
let inputValue = parseInt($(`#${item}-range`).val())
let result = inputValue
if ($(`#${item}-range`).data('excluded')) {
var excludedValues = $(`#${item}-range`).data('excluded').split(',').map(Number)
if (excludedValues.includes(inputValue)) {
result = findClosestValue(inputValue, excludedValues);
$(`#${item}-range`).val(result);
}
}
if (result != currentValue[item].value) {
currentValue[item].value = result
$.post('https://hp_charcreator/change', JSON.stringify({
type: item,
new: Number(result)
}));
$(`#${item}-value`).html(currentValue[item].value)
}
}
function findClosestValue(value, excludedValues) {
var closestValue = value;
while (excludedValues.includes(closestValue)) {
if (direction == "left") {
closestValue--;
} else {
closestValue++;
}
}
return closestValue;
}
$(document).on("keydown", function (event) {
if (event.keyCode == 37) {
direction = "left"
} else if (event.keyCode == 39) {
direction = "right"
} else if (event.key == handsUpKey) {
$.post('https://hp_charcreator/hands_up')
}
});