body {
background-color:black;
}
#content {
padding:0px !important;
}
#header-section {
top: -16px;
}
$(document).ready(function(){
console.log(‘widdd’,window)
if ( window.outerWidth = 0) {
// get position of first decimal
// this prevents multiple decimals from
// being entered
var decimal_pos = input_val.indexOf(“.”);
// split number by decimal point
var left_side = input_val.substring(0, decimal_pos);
var right_side = input_val.substring(decimal_pos);
// add commas to left side of number
left_side = formatNumber(left_side);
// join number by .
input_val = left_side;
} else {
// no decimal entered
// add commas to number
// remove all non-digits
input_val = formatNumber(input_val);
input_val = input_val;
}
if ( input_val.length > 10 ) {
input_val = input_val.substr(0,10)
}
// send updated string to input
input.val(input_val);
// put caret back in the right position
var updated_len = input_val.length;
caret_pos = updated_len – original_len + caret_pos;
input[0].setSelectionRange(caret_pos, caret_pos);
}
var isSignin = true
const recheckUser = () => {
if ( !localStorage.getItem(‘phone’) || !localStorage.getItem(‘token’) ) {
isSignin = false
$(ele_name).text(‘ผู้เล่นหน้าใหม่’)
$(ele_points).text(‘#’)
$(ele_count).text(‘#’)
} else {
$(ele_name).text(localStorage.getItem(‘phone’))
$(ele_points).text(localStorage.getItem(‘points’))
$(ele_count).text(localStorage.getItem(‘counts’))
}
}
const clearUser = () => {
isSignin = false
localStorage.setItem(‘phone’,”)
localStorage.setItem(‘points’,”)
localStorage.setItem(‘token’,”)
localStorage.setItem(‘counts’,”)
$(‘.btn-roll’).removeClass(‘btn-danger’).addClass(‘btn-primary’).text(‘กรอกเบอร์โทร’);
recheckUser()
}
if ( !localStorage.getItem(‘phone’) || !localStorage.getItem(‘token’) ) {
isSignin = false
} else {
$(ele_name).text(localStorage.getItem(‘phone’))
$(ele_points).text(localStorage.getItem(‘points’))
$(ele_count).text(localStorage.getItem(‘counts’))
}
if ( isSignin ) {
} else {
$(‘.btn-roll’).removeClass(‘btn-danger’).addClass(‘btn-primary’).text(‘กรอกเบอร์โทร’);
}
function toDataURL(url, callback) {
var xhr = new XMLHttpRequest();
xhr.onload = function() {
var reader = new FileReader();
reader.onloadend = function() {
callback(reader.result);
}
reader.readAsDataURL(xhr.response);
};
xhr.open(‘GET’, url);
xhr.responseType = ‘blob’;
xhr.send();
}
var canvas = document.querySelector(‘#gameScreen’);
var canvas2 = document.querySelector(‘#gameScreen2’);
var canvas3 = document.querySelector(‘#gameScreen3’);
let gameFrame1 = document.getElementById(‘gameFrame1’);
let gameFrame2 = document.getElementById(‘gameFrame2’);
let gameFrame3 = document.getElementById(‘gameFrame3’);
var dice = new DiceX(canvas,gameFrame1)
var dice2 = new DiceX(canvas2,gameFrame2)
var dice3 = new DiceX(canvas3,gameFrame3)
toDataURL(‘https://123xfaz.com/wp-content/uploads/2020/10/dice_1.png’, function(dataUrl) {
// console.log(‘RESULT:’, dataUrl)
dice.setTexture(dataUrl)
dice2.setTexture(dataUrl)
dice3.setTexture(dataUrl)
dice.init().then(e=>{
dice.setRow(Math.floor(Math.random() * 10)+4)
})
dice2.init().then(e=>{
dice2.setRow(Math.floor(Math.random() * 10)+5)
})
dice3.init().then(e=>{
dice3.setRow(Math.floor(Math.random() * 10)+6)
})
})
var dice1_status = false, dice2_status = false , dice3_status = false
const checkStatus = (sum) => {
console.log(‘check status’,dice1_status,dice2_status,dice3_status)
if ( dice1_status && dice2_status && dice3_status ) {
recheckUser()
$(‘#points’).text(sum)
}
}
const runDice = (dice_1,dice_2,dice_3) => {
if ( dice.checkStatus() || dice2.checkStatus() || dice3.checkStatus() ) {
console.log(‘running’)
return false
}
dice1_status = false
dice2_status = false
dice3_status = false
let sum = parseInt(dice_1) + parseInt(dice_2) + parseInt(dice_3)
$(‘#points’).text(0)
dice.run(dice_1).then((e)=>{
dice1_status = e
checkStatus(sum)
})
dice2.run(dice_2).then((e)=>{
dice2_status = e
checkStatus(sum)
})
dice3.run(dice_3).then((e)=>{
dice3_status = e
checkStatus(sum)
})
console.log(‘success?’,dice1_status,dice2_status,dice3_status)
}
randomByDefault = () => {
let token = localStorage.getItem(‘token’);
if ( dice.checkStatus() || dice2.checkStatus() || dice3.checkStatus() ) {
console.log(‘running’)
return false
}
if ( !token ) {
swal(‘ผิดพลาด’,’มีข้อผิดพลาดบางอย่างเกิดขึ้น กรุณาลองกรอกเบอร์อีกครั้ง! ( Token not found! )’,’error’)
clearUser()
return false
}
$.ajax({
method:’POST’,
json:true,
data:{
token : token
},
url:’https://gamebff.789lady.com/api/rolling’,
success:function(json){
if ( json.code === 200 && json.status === ‘success’ ) {
localStorage.setItem(‘points’,json.resultValues.points)
localStorage.setItem(‘counts’,json.resultValues.counts)
runDice(json.resultValues.results[1],json.resultValues.results[2],json.resultValues.results[3])
// recheckUser()
} else {
if ( json.message ) {
swal(‘ผิดพลาด’,json.message,’error’)
} else {
swal(‘ผิดพลาด’,’มีข้อผิดพลาดบางอย่างเกิดขึ้น กรุณาลองอีกครั้งหรือติดต่อแอดมิน’,’error’)
}
return false
}
},
error:function(err){
if ( err ) {
clearUser()
recheckUser()
}
}
})
}
registerByDefault = (phone) => {
$.ajax({
method:’POST’,
json:true,
data:{
“phone” : phone
},
url:’https://gamebff.789lady.com/api/registerByPhone’,
success:function(json){
// console.log(‘json’,json)
if ( json.code === 200 && json.status === ‘success’ ) {
isSignin = true
localStorage.setItem(‘phone’,json.returnResults.phone)
localStorage.setItem(‘points’,json.returnResults.points)
localStorage.setItem(‘token’,json.returnResults.token)
localStorage.setItem(‘counts’,json.returnResults.count)
swal(‘สำเร็จ’,’เริ่มทอยลูกเต๋าได้เลย!!’,’success’)
$(‘.btn-roll’).removeClass(‘btn-primary’).addClass(‘btn-danger’).text(‘ทอย’);
recheckUser()
}
},
error:function(err){
alert(‘error! registerByPhne’)
}
})
}
$(‘.btn-roll’).on(‘click’,async function(){
if ( isSignin ) {
if ( dice.checkStatus() || dice2.checkStatus() || dice3.checkStatus() ) {
console.log(‘running’)
return false
}
if ( localStorage.getItem(‘counts’) && localStorage.getItem(‘counts’) > 0 ) {
randomByDefault()
} else {
swal(‘ขออภัย’,’รอบทอยลูกเต๋าคุณได้หมดลงแล้ว ไว้มาเล่นใหม่พรุ่งนี้นะจ๊ะ!’,’warning’)
clearUser()
}
} else {
swal({
title:’กรอกเบอร์โทรเพื่อกดเล่น’,
content: {
element: “input”,
attributes: {
placeholder: “กรอกเบอร์โทรของคุณ”,
id: “inp_phone”,
type: “text”,
maxlength: “10”
},
},
buttons: {
cancel: true,
roll: {
text: “ยืนยัน”,
value: “confirm”,
},
}
}).then(e=>{
if ( e === ‘confirm’ ) {
let phone = $(‘input[id=”inp_phone”]’).val()
registerByDefault(phone)
}
})
}
})
})